Faction Test 100.6.0.0

This commit is contained in:
Markus Isberg
2022-11-25 19:55:45 +02:00
parent c44fb0ad3a
commit 0057f5bfce
130 changed files with 2771 additions and 1509 deletions
@@ -27,13 +27,14 @@ namespace Barotrauma
private readonly bool applyFireEffects;
private readonly string[] ignoreFireEffectsForTags;
private readonly bool ignoreCover;
private readonly bool onlyInside,onlyOutside;
private readonly float flashDuration;
private readonly float? flashRange;
private readonly string decal;
private readonly float decalSize;
private readonly bool applyToSelf;
public bool OnlyInside, OnlyOutside;
private readonly float itemRepairStrength;
public readonly HashSet<Submarine> IgnoredSubmarines = new HashSet<Submarine>();
@@ -81,8 +82,8 @@ namespace Barotrauma
ignoreFireEffectsForTags = element.GetAttributeStringArray("ignorefireeffectsfortags", Array.Empty<string>(), convertToLowerInvariant: true);
ignoreCover = element.GetAttributeBool("ignorecover", false);
onlyInside = element.GetAttributeBool("onlyinside", false);
onlyOutside = element.GetAttributeBool("onlyoutside", false);
OnlyInside = element.GetAttributeBool("onlyinside", false);
OnlyOutside = element.GetAttributeBool("onlyoutside", false);
flash = element.GetAttributeBool("flash", showEffects);
flashDuration = element.GetAttributeFloat("flashduration", 0.05f);
@@ -181,8 +182,7 @@ namespace Barotrauma
{
float distSqr = Vector2.DistanceSquared(item.WorldPosition, worldPosition);
if (distSqr > displayRangeSqr) { continue; }
float distFactor = 1.0f - (float)Math.Sqrt(distSqr) / displayRange;
float distFactor = CalculateDistanceFactor(distSqr, displayRange);
//damage repairable power-consuming items
var powered = item.GetComponent<Powered>();
@@ -199,6 +199,7 @@ namespace Barotrauma
powerContainer.Charge -= powerContainer.GetCapacity() * EmpStrength * distFactor;
}
}
static float CalculateDistanceFactor(float distSqr, float displayRange) => 1.0f - MathF.Sqrt(distSqr) / displayRange;
}
if (itemRepairStrength > 0.0f)
@@ -292,10 +293,16 @@ namespace Barotrauma
{
continue;
}
if (c == attacker && !applyToSelf) { continue; }
//if (c == attacker && !applyToSelf) { continue; }
if (onlyInside && c.Submarine == null) { continue; }
else if (onlyOutside && c.Submarine != null) { continue; }
if (OnlyInside && c.Submarine == null)
{
continue;
}
else if (OnlyOutside && c.Submarine != null)
{
continue;
}
Vector2 explosionPos = worldPosition;
if (c.Submarine != null) { explosionPos -= c.Submarine.Position; }
@@ -341,15 +348,19 @@ namespace Barotrauma
modifiedAfflictions.Clear();
foreach (Affliction affliction in attack.Afflictions.Keys)
{
// Shouldn't go above 15, or the damage can be unexpectedly low -> doesn't break armor
// Effectively this makes large explosions more effective against large creatures (because more limbs are affected), but I don't think that's necessarily a bad thing.
float limbCountFactor = Math.Min(distFactors.Count, 15);
float dmgMultiplier = distFactor;
if (affliction.DivideByLimbCount)
{
float limbCountFactor = distFactors.Count;
if (affliction.Prefab.LimbSpecific && affliction.Prefab.AfflictionType == "damage")
{
// Shouldn't go above 15, or the damage can be unexpectedly low -> doesn't break armor
// Effectively this makes large explosions more effective against large creatures (because more limbs are affected), but I don't think that's necessarily a bad thing.
limbCountFactor = Math.Min(distFactors.Count, 15);
}
dmgMultiplier /= limbCountFactor;
}
modifiedAfflictions.Add(affliction.CreateMultiplied(dmgMultiplier, affliction.Probability));
modifiedAfflictions.Add(affliction.CreateMultiplied(dmgMultiplier, affliction));
}
c.LastDamageSource = damageSource;
if (attacker == null)
@@ -357,29 +368,29 @@ namespace Barotrauma
if (damageSource is Item item)
{
attacker = item.GetComponent<Projectile>()?.User;
if (attacker == null)
{
attacker = item.GetComponent<MeleeWeapon>()?.User;
}
attacker ??= item.GetComponent<MeleeWeapon>()?.User;
}
}
if (attack.Afflictions.Any() || attack.Stun > 0.0f)
{
AbilityAttackData attackData = new AbilityAttackData(Attack, c, attacker);
if (attackData.Afflictions != null)
if (!attack.OnlyHumans || c.IsHuman)
{
modifiedAfflictions.AddRange(attackData.Afflictions);
}
AbilityAttackData attackData = new AbilityAttackData(Attack, c, attacker);
if (attackData.Afflictions != null)
{
modifiedAfflictions.AddRange(attackData.Afflictions);
}
//use a position slightly from the limb's position towards the explosion
//ensures that the attack hits the correct limb and that the direction of the hit can be determined correctly in the AddDamage methods
Vector2 dir = worldPosition - limb.WorldPosition;
Vector2 hitPos = limb.WorldPosition + (dir.LengthSquared() <= 0.001f ? Rand.Vector(1.0f) : Vector2.Normalize(dir)) * 0.01f;
AttackResult attackResult = c.AddDamage(hitPos, modifiedAfflictions, attack.Stun * distFactor, false, attacker: attacker, damageMultiplier: attack.DamageMultiplier * attackData.DamageMultiplier);
damages.Add(limb, attackResult.Damage);
//use a position slightly from the limb's position towards the explosion
//ensures that the attack hits the correct limb and that the direction of the hit can be determined correctly in the AddDamage methods
Vector2 dir = worldPosition - limb.WorldPosition;
Vector2 hitPos = limb.WorldPosition + (dir.LengthSquared() <= 0.001f ? Rand.Vector(1.0f) : Vector2.Normalize(dir)) * 0.01f;
AttackResult attackResult = c.AddDamage(hitPos, modifiedAfflictions, attack.Stun * distFactor, false, attacker: attacker, damageMultiplier: attack.DamageMultiplier * attackData.DamageMultiplier);
damages.Add(limb, attackResult.Damage);
}
}
if (attack.StatusEffects != null && attack.StatusEffects.Any())
{
attack.SetUser(attacker);
@@ -549,21 +549,24 @@ namespace Barotrauma
if (hull1.WaterVolume < hull1.Volume / Hull.MaxCompress &&
hull1.Surface < rect.Y)
{
//create a wave from the side of the hull the water is leaking from
if (rect.X > hull1.Rect.X + hull1.Rect.Width / 2.0f)
{
float vel = ((rect.Y - rect.Height / 2) - (hull1.Surface + hull1.WaveY[hull1.WaveY.Length - 1])) * 6.0f;
vel *= Math.Min(Math.Abs(flowForce.X) / 200.0f, 1.0f);
hull1.WaveVel[hull1.WaveY.Length - 1] += vel * deltaTime;
hull1.WaveVel[hull1.WaveY.Length - 2] += vel * deltaTime;
CreateWave(rect, hull1, hull1.WaveY.Length - 1, hull1.WaveY.Length - 2, flowForce, deltaTime);
}
else
{
float vel = ((rect.Y - rect.Height / 2) - (hull1.Surface + hull1.WaveY[0])) * 6.0f;
CreateWave(rect, hull1, 0, 1, flowForce, deltaTime);
}
static void CreateWave(Rectangle rect, Hull hull1, int index1, int index2, Vector2 flowForce, float deltaTime)
{
float vel = (rect.Y - rect.Height / 2) - (hull1.Surface + hull1.WaveY[index1]);
vel *= Math.Min(Math.Abs(flowForce.X) / 200.0f, 1.0f);
hull1.WaveVel[0] += vel * deltaTime;
hull1.WaveVel[1] += vel * deltaTime;
if (vel > 0.0f)
{
hull1.WaveVel[index1] += vel * deltaTime;
hull1.WaveVel[index2] += vel * deltaTime;
}
}
}
else
@@ -4397,7 +4397,7 @@ namespace Barotrauma
corpse.AnimController.FindHull(worldPos, setSubmarine: true);
corpse.TeamID = CharacterTeamType.None;
corpse.EnableDespawn = false;
selectedPrefab.GiveItems(corpse, wreck);
selectedPrefab.GiveItems(corpse, wreck, sp);
corpse.Kill(CauseOfDeathType.Unknown, causeOfDeathAffliction: null, log: false);
corpse.CharacterHealth.ApplyAffliction(corpse.AnimController.MainLimb, AfflictionPrefab.OxygenLow.Instantiate(200));
bool applyBurns = Rand.Value() < 0.1f;
@@ -4428,7 +4428,6 @@ namespace Barotrauma
}
}
corpse.CharacterHealth.ForceUpdateVisuals();
corpse.GiveIdCardTags(sp);
bool isServerOrSingleplayer = GameMain.IsSingleplayer || GameMain.NetworkMember is { IsServer: true };
if (isServerOrSingleplayer && selectedPrefab.MinMoney >= 0 && selectedPrefab.MaxMoney > 0)
@@ -405,7 +405,7 @@ namespace Barotrauma
if (wall.Submarine != sub) { continue; }
for (int i = 0; i < wall.SectionCount; i++)
{
wall.SetDamage(i, 0, createNetworkEvent: false);
wall.SetDamage(i, 0, createNetworkEvent: false, createExplosionEffect: false);
}
}
foreach (Hull hull in Hull.HullList)
@@ -323,7 +323,7 @@ namespace Barotrauma
var characters = GameSession.GetSessionCrewCharacters(CharacterType.Both);
if (characters.Any())
{
price *= 1f + characters.Max(static c => c.GetStatValue(StatTypes.StoreSellMultiplier));
price *= 1f + characters.Max(static c => c.GetStatValue(StatTypes.StoreSellMultiplier, includeSaved: false));
price *= 1f + characters.Max(c => item.Tags.Sum(tag => c.Info.GetSavedStatValue(StatTypes.StoreSellMultiplier, tag)));
}
@@ -675,7 +675,7 @@ namespace Barotrauma
return new Location(position, zone, rand, requireOutpost, forceLocationType, existingLocations);
}
public void ChangeType(CampaignMode campaign, LocationType newType)
public void ChangeType(CampaignMode campaign, LocationType newType, bool createStores = true)
{
if (newType == Type) { return; }
@@ -709,7 +709,10 @@ namespace Barotrauma
UnlockInitialMissions(Rand.RandSync.Unsynced);
CreateStores(force: true);
if (createStores)
{
CreateStores(force: true);
}
}
public void UnlockInitialMissions(Rand.RandSync randSync = Rand.RandSync.ServerAndClient)
@@ -13,8 +13,8 @@ namespace Barotrauma
{
public static readonly PrefabCollection<LocationType> Prefabs = new PrefabCollection<LocationType>();
private readonly List<string> names;
private readonly List<Sprite> portraits = new List<Sprite>();
private readonly ImmutableArray<string> names;
private readonly ImmutableArray<Sprite> portraits;
//<name, commonness>
private readonly ImmutableArray<(Identifier Name, float Commonness)> hireableJobs;
@@ -41,12 +41,6 @@ namespace Barotrauma
public bool IsEnterable { get; private set; }
public bool UsePortraitInMainMenu
{
get;
private set;
}
public bool UsePortraitInRandomLoadingScreens
{
get;
@@ -118,7 +112,6 @@ namespace Barotrauma
BeaconStationChance = element.GetAttributeFloat("beaconstationchance", 0.0f);
UsePortraitInMainMenu = element.GetAttributeBool(nameof(UsePortraitInMainMenu), element.GetAttributeBool("useinmainmenu", false));
UsePortraitInRandomLoadingScreens = element.GetAttributeBool(nameof(UsePortraitInRandomLoadingScreens), true);
HasOutpost = element.GetAttributeBool("hasoutpost", true);
IsEnterable = element.GetAttributeBool("isenterable", HasOutpost);
@@ -146,7 +139,7 @@ namespace Barotrauma
else
{
string[] rawNamePaths = element.GetAttributeStringArray("namefile", new string[] { "Content/Map/locationNames.txt" });
names = new List<string>();
var names = new List<string>();
foreach (string rawPath in rawNamePaths)
{
try
@@ -163,6 +156,7 @@ namespace Barotrauma
{
names.Add("ERROR: No names found");
}
this.names = names.ToImmutableArray();
}
string[] commonnessPerZoneStrs = element.GetAttributeStringArray("commonnessperzone", Array.Empty<string>());
@@ -192,7 +186,7 @@ namespace Barotrauma
}
MinCountPerZone[zoneIndex] = minCount;
}
var portraits = new List<Sprite>();
var hireableJobs = new List<(Identifier, float)>();
foreach (var subElement in element.Elements())
{
@@ -233,6 +227,7 @@ namespace Barotrauma
break;
}
}
this.portraits = portraits.ToImmutableArray();
this.hireableJobs = hireableJobs.ToImmutableArray();
}
@@ -249,10 +244,10 @@ namespace Barotrauma
return null;
}
public Sprite GetPortrait(int portraitId)
public Sprite GetPortrait(int randomSeed)
{
if (portraits.Count == 0) { return null; }
return portraits[Math.Abs(portraitId) % portraits.Count];
if (portraits.Length == 0) { return null; }
return portraits[Math.Abs(randomSeed) % portraits.Length];
}
public string GetRandomName(Random rand, IEnumerable<Location> existingLocations)
@@ -265,7 +260,7 @@ namespace Barotrauma
return unusedNames[rand.Next() % unusedNames.Count];
}
}
return names[rand.Next() % names.Count];
return names[rand.Next() % names.Length];
}
public static LocationType Random(Random rand, int? zone = null, bool requireOutpost = false)
@@ -622,7 +622,8 @@ namespace Barotrauma
{
leftMostLocation.ChangeType(
campaign,
LocationType.Prefabs.OrderBy(lt => lt.Identifier).First(lt => lt.HasOutpost && lt.Identifier != "abandoned"));
LocationType.Prefabs.OrderBy(lt => lt.Identifier).First(lt => lt.HasOutpost && lt.Identifier != "abandoned"),
createStores: false);
}
leftMostLocation.IsGateBetweenBiomes = true;
Connections[i].Locked = true;
@@ -706,6 +707,7 @@ namespace Barotrauma
location.Faction ??= campaign.GetRandomFaction(Rand.RandSync.ServerAndClient);
location.SecondaryFaction ??= campaign.GetRandomSecondaryFaction(Rand.RandSync.ServerAndClient);
}
location.CreateStores(force: true);
}
foreach (LocationConnection connection in Connections)
@@ -837,7 +839,7 @@ namespace Barotrauma
if (LocationType.Prefabs.TryGet("none", out LocationType locationType))
{
previousToEndLocation.ChangeType(campaign, locationType);
previousToEndLocation.ChangeType(campaign, locationType, createStores: false);
}
//remove all locations from the end biome except the end location
@@ -1691,13 +1691,12 @@ namespace Barotrauma
{
npc.CharacterHealth.Unkillable = true;
}
humanPrefab.GiveItems(npc, outpost, Rand.RandSync.ServerAndClient);
humanPrefab.GiveItems(npc, outpost, gotoTarget as WayPoint, Rand.RandSync.ServerAndClient);
foreach (Item item in npc.Inventory.FindAllItems(it => it != null, recursive: true))
{
item.AllowStealing = outpost.Info.OutpostGenerationParams.AllowStealing;
item.SpawnedInCurrentOutpost = true;
}
npc.GiveIdCardTags(gotoTarget as WayPoint);
humanPrefab.InitializeCharacter(npc, gotoTarget);
}
}
@@ -56,6 +56,8 @@ namespace Barotrauma
//dimensions of the wall sections' physics bodies (only used for debug rendering)
private readonly List<Vector2> bodyDebugDimensions = new List<Vector2>();
private static Explosion explosionOnBroken;
#if DEBUG
[Serialize(false, IsPropertySaveable.Yes), Editable]
#else
@@ -1083,7 +1085,7 @@ namespace Barotrauma
return new AttackResult(damageAmount, null);
}
public void SetDamage(int sectionIndex, float damage, Character attacker = null, bool createNetworkEvent = true)
public void SetDamage(int sectionIndex, float damage, Character attacker = null, bool createNetworkEvent = true, bool createExplosionEffect = true)
{
if (Submarine != null && Submarine.GodMode || Indestructible) { return; }
if (!Prefab.Body) { return; }
@@ -1128,6 +1130,7 @@ namespace Barotrauma
}
else
{
float prevGapOpenState = Sections[sectionIndex].gap?.Open ?? 0.0f;
if (Sections[sectionIndex].gap == null)
{
Rectangle gapRect = Sections[sectionIndex].rect;
@@ -1204,8 +1207,15 @@ namespace Barotrauma
#endif
}
var gap = Sections[sectionIndex].gap;
float gapOpen = MaxHealth <= 0.0f ? 0.0f : (damage / MaxHealth - LeakThreshold) * (1.0f / (1.0f - LeakThreshold));
Sections[sectionIndex].gap.Open = gapOpen;
gap.Open = gapOpen;
//gap appeared or became much larger -> explosion effect
if (gapOpen - prevGapOpenState > 0.25f && createExplosionEffect && !gap.IsRoomToRoom)
{
CreateWallDamageExplosion(gap, attacker);
}
}
float damageDiff = damage - Sections[sectionIndex].damage;
@@ -1234,6 +1244,59 @@ namespace Barotrauma
UpdateSections();
}
private void CreateWallDamageExplosion(Gap gap, Character attacker)
{
const float explosionRange = 750.0f;
float explosionStrength = gap.Open;
var linkedHull = gap.linkedTo.FirstOrDefault() as Hull;
if (linkedHull != null)
{
//existing, nearby gaps leading to the same hull reduce the strength of the explosion
// -> the first breached section does most (or all) of the damage, making it more consistent
// (otherwise the damage would depend on how many structures and sections happen to be breached)
foreach (var otherGap in linkedHull.ConnectedGaps)
{
if (otherGap == gap || otherGap.IsRoomToRoom || otherGap.Open < 0.25f) { continue; }
explosionStrength -= Math.Max(0, explosionRange - Vector2.Distance(otherGap.WorldPosition, gap.WorldPosition)) / explosionRange;
if (explosionStrength <= 0.0f) { return; }
}
}
if (explosionOnBroken == null)
{
explosionOnBroken = new Explosion(explosionRange * gap.Open, force: 10.0f, damage: 0.0f, structureDamage: 0.0f, itemDamage: 0.0f);
if (AfflictionPrefab.Prefabs.TryGet("lacerations".ToIdentifier(), out AfflictionPrefab lacerations))
{
explosionOnBroken.Attack.Afflictions.Add(lacerations.Instantiate(50.0f), null);
}
else
{
explosionOnBroken.Attack.Afflictions.Add(AfflictionPrefab.InternalDamage.Instantiate(5.0f), null);
}
explosionOnBroken.OnlyInside = true;
explosionOnBroken.DisableParticles();
}
explosionOnBroken.Attack.DamageMultiplier = explosionStrength;
explosionOnBroken?.Explode(gap.WorldPosition, damageSource: null, attacker: attacker);
#if CLIENT
if (linkedHull != null)
{
for (int i = 0; i <= 50; i++)
{
Vector2 particlePos = new Vector2(Rand.Range(gap.WorldRect.X, gap.WorldRect.Right), Rand.Range(gap.WorldRect.Y - gap.WorldRect.Height, gap.WorldRect.Y));
var velocity = gap.IsHorizontal ?
gap.linkedTo[0].WorldPosition.X < gap.WorldPosition.X ? -Vector2.UnitX : Vector2.UnitX :
gap.linkedTo[0].WorldPosition.Y < gap.WorldPosition.Y ? -Vector2.UnitY : Vector2.UnitY;
velocity = new Vector2(velocity.X + Rand.Range(-0.2f, 0.2f), velocity.Y + Rand.Range(-0.2f, 0.2f));
var particle = GameMain.ParticleManager.CreateParticle("shrapnel", particlePos, velocity * Rand.Range(100.0f, 3000.0f), collisionIgnoreTimer: 0.1f);
if (particle == null) { break; }
}
}
#endif
}
partial void OnHealthChangedProjSpecific(Character attacker, float damageAmount);
public void SetCollisionCategory(Category collisionCategory)
@@ -1570,7 +1633,7 @@ namespace Barotrauma
{
for (int i = 0; i < Sections.Length; i++)
{
SetDamage(i, Sections[i].damage, createNetworkEvent: false);
SetDamage(i, Sections[i].damage, createNetworkEvent: false, createExplosionEffect: false);
}
}
@@ -738,7 +738,7 @@ namespace Barotrauma
private void HandleLevelCollision(Impact impact, VoronoiCell cell = null)
{
if (GameMain.GameSession != null && Timing.TotalTime < GameMain.GameSession.RoundStartTime + 10)
if (GameMain.GameSession != null && GameMain.GameSession.RoundDuration > 10)
{
//ignore level collisions for the first 10 seconds of the round in case the sub spawns in a way that causes it to hit a wall
//(e.g. level without outposts to dock to and an incorrectly configured ballast that makes the sub go up)