Unstable 1.8.4.0

This commit is contained in:
Markus Isberg
2025-03-12 12:56:27 +00:00
parent a4c3e868e4
commit a4a3427e4e
627 changed files with 29860 additions and 10018 deletions
@@ -54,6 +54,11 @@ namespace Barotrauma
activeEffectDirty = true;
}
}
/// <summary>
/// Armor penetration for status effects. Normally defined per attack, but that doesn't work on status effects.
/// </summary>
public float Penetration { get; set; }
private float _nonClampedStrength = -1;
public float NonClampedStrength => _nonClampedStrength > 0 ? _nonClampedStrength : _strength;
@@ -64,7 +69,7 @@ namespace Barotrauma
[Serialize(1.0f, IsPropertySaveable.Yes, description: "The probability for the affliction to be applied."), Editable(minValue: 0f, maxValue: 1f)]
public float Probability { get; set; } = 1.0f;
[Serialize(true, IsPropertySaveable.Yes, description: "Explosion damage is applied per each affected limb. Should this affliction damage be divided by the count of affected limbs (1-15) or applied in full? Default: true. Only affects explosions."), Editable]
[Serialize(true, IsPropertySaveable.Yes, description: "Explosion damage is applied per each affected limb. Should this affliction damage be divided by the count of affected limbs (1-15) or applied in full? Default: true. Only affects status effects and explosions."), Editable]
public bool DivideByLimbCount { get; set; }
[Serialize(false, IsPropertySaveable.Yes, description: "Is the damage relative to the max vitality (percentage) or absolute (normal)"), Editable]
@@ -120,6 +125,7 @@ namespace Barotrauma
Probability = source.Probability;
DivideByLimbCount = source.DivideByLimbCount;
MultiplyByMaxVitality = source.MultiplyByMaxVitality;
Penetration = source.Penetration;
}
public void Serialize(XElement element)
@@ -337,18 +343,24 @@ namespace Barotrauma
}
}
public float GetResistance(Identifier afflictionId)
/// <summary>
/// How much resistance to the specified affliction does this affliction currently give?
/// </summary>
public float GetResistance(Identifier afflictionId, LimbType limbType)
{
if (Strength < Prefab.ActivationThreshold) { return 0.0f; }
var affliction = AfflictionPrefab.Prefabs[afflictionId];
AfflictionPrefab.Effect currentEffect = GetActiveEffect();
if (currentEffect == null) { return 0.0f; }
if (!currentEffect.ResistanceFor.Any(r =>
r == affliction.Identifier ||
r == affliction.AfflictionType))
{
return 0.0f;
}
bool hasResistanceForAffliction = currentEffect.ResistanceFor.Any(identifier =>
identifier == affliction.Identifier ||
identifier == affliction.AfflictionType);
if (!hasResistanceForAffliction) { return 0.0f; }
bool hasResistanceForLimb = limbType == LimbType.None || currentEffect.ResistanceLimbs.None() || currentEffect.ResistanceLimbs.Contains(limbType);
if (!hasResistanceForLimb) { return 0.0f; }
return MathHelper.Lerp(
currentEffect.MinResistance,
currentEffect.MaxResistance,
@@ -402,6 +414,8 @@ namespace Barotrauma
}
else
{
//force an update when a periodic effect triggers to get it to trigger client-side
characterHealth.Character.healthUpdateTimer = 0.0f;
foreach (StatusEffect statusEffect in periodicEffect.StatusEffects)
{
ApplyStatusEffect(ActionType.OnActive, statusEffect, 1.0f, characterHealth, targetLimb);
@@ -430,7 +444,7 @@ namespace Barotrauma
}
else if (currentEffect.StrengthChange > 0) // Reduce strengthening of afflictions if resistant
{
_strength += currentEffect.StrengthChange * deltaTime * (1f - characterHealth.GetResistance(Prefab));
_strength += currentEffect.StrengthChange * deltaTime * (1f - characterHealth.GetResistance(Prefab, targetLimb?.type ?? LimbType.None));
}
// Don't use the property, because it's virtual and some afflictions like husk overload it for external use.
_strength = MathHelper.Clamp(_strength, 0.0f, Prefab.MaxStrength);
@@ -441,6 +455,17 @@ namespace Barotrauma
ApplyStatusEffect(ActionType.OnActive, statusEffect, deltaTime, characterHealth, targetLimb);
}
if (currentEffect.ConvulseAmount > 0f)
{
foreach (Limb limb in characterHealth.Character.AnimController.Limbs)
{
if (limb.IsSevered) { continue; }
if (limb.Hidden) { continue; }
float force = Rand.Value() * limb.Mass * currentEffect.ConvulseAmount;
limb.body.ApplyLinearImpulse(Rand.Vector(force), maxVelocity: Networking.NetConfig.MaxPhysicsBodyVelocity * 0.5f);
}
}
float amount = deltaTime;
if (Prefab.GrainBurst > 0)
{
@@ -13,7 +13,7 @@
public override void Update(CharacterHealth characterHealth, Limb targetLimb, float deltaTime)
{
base.Update(characterHealth, targetLimb, deltaTime);
float bloodlossResistance = GetResistance(characterHealth.BloodlossAffliction.Identifier);
float bloodlossResistance = characterHealth.GetResistance(characterHealth.BloodlossAffliction.Prefab, targetLimb?.type ?? LimbType.None);
characterHealth.BloodlossAmount += Strength * (1.0f - bloodlossResistance) / 60.0f * deltaTime;
if (Source != null)
{
@@ -28,8 +28,6 @@ namespace Barotrauma
private bool stun = false;
private readonly List<Affliction> huskInfection = new List<Affliction>();
[Serialize(0f, IsPropertySaveable.Yes), Editable]
public override float Strength
{
@@ -62,7 +60,7 @@ namespace Barotrauma
}
}
private readonly AfflictionPrefabHusk HuskPrefab;
public readonly AfflictionPrefabHusk HuskPrefab;
private float DormantThreshold => HuskPrefab.DormantThreshold;
private float ActiveThreshold => HuskPrefab.ActiveThreshold;
@@ -129,7 +127,7 @@ namespace Barotrauma
{
State = InfectionState.Final;
ActivateHusk();
ApplyDamage(deltaTime, applyForce: true);
ApplyDamage(deltaTime);
character.SetStun(5);
}
}
@@ -192,27 +190,41 @@ namespace Barotrauma
prevDisplayedMessage = State;
}
private void ApplyDamage(float deltaTime, bool applyForce)
private const float DamageCooldown = 0.1f;
private float damageCooldownTimer;
private void ApplyDamage(float deltaTime)
{
int limbCount = character.AnimController.Limbs.Count(l => !l.IgnoreCollisions && !l.IsSevered && !l.Hidden);
if (damageCooldownTimer > 0)
{
damageCooldownTimer -= deltaTime;
return;
}
damageCooldownTimer = DamageCooldown;
int limbCount = character.AnimController.Limbs.Count(IsValidLimb);
foreach (Limb limb in character.AnimController.Limbs)
{
if (limb.IsSevered) { continue; }
if (limb.Hidden) { continue; }
if (!IsValidLimb(limb)) { continue; }
float random = Rand.Value();
huskInfection.Clear();
huskInfection.Add(AfflictionPrefab.InternalDamage.Instantiate(random * 10 * deltaTime / limbCount));
if (random == 0) { continue; }
const float damageRate = 2;
float dmg = random / limbCount * damageRate;
character.LastDamageSource = null;
float force = applyForce ? random * 0.5f * limb.Mass : 0;
character.DamageLimb(limb.WorldPosition, limb, huskInfection, 0, false, Rand.Vector(force));
var afflictions = AfflictionPrefab.InternalDamage.Instantiate(dmg).ToEnumerable();
const float forceMultiplier = 5;
float force = dmg * limb.Mass * forceMultiplier;
character.DamageLimb(limb.WorldPosition, limb, afflictions, stun: 0, playSound: false, Rand.Vector(force), ignoreDamageOverlay: true, recalculateVitality: false);
}
character.CharacterHealth.RecalculateVitality();
static bool IsValidLimb(Limb limb) => !limb.IgnoreCollisions && !limb.IsSevered && !limb.Hidden;
}
public void ActivateHusk()
{
if (huskAppendage == null && character.Params.UseHuskAppendage)
{
huskAppendage = AttachHuskAppendage(character, Prefab as AfflictionPrefabHusk);
var huskAffliction = Prefab as AfflictionPrefabHusk;
huskAppendage = AttachHuskAppendage(character, huskAffliction, GetHuskedSpeciesName(character.Params, huskAffliction));
}
if (Prefab is AfflictionPrefabHusk { NeedsAir: false })
@@ -287,7 +299,7 @@ namespace Barotrauma
Entity.Spawner.AddEntityToRemoveQueue(character);
UnsubscribeFromDeathEvent();
Identifier huskedSpeciesName = GetHuskedSpeciesName(character.SpeciesName, Prefab as AfflictionPrefabHusk);
Identifier huskedSpeciesName = GetHuskedSpeciesName(character.Params, Prefab as AfflictionPrefabHusk);
CharacterPrefab prefab = CharacterPrefab.FindBySpeciesName(huskedSpeciesName);
if (prefab == null)
@@ -309,11 +321,16 @@ namespace Barotrauma
}
var husk = Character.Create(huskedSpeciesName, character.WorldPosition, ToolBox.RandomSeed(8), huskCharacterInfo, isRemotePlayer: false, hasAi: true);
if (character.HasAbilityFlag(AbilityFlags.IgnoredByEnemyAI))
{
husk.AddAbilityFlag(AbilityFlags.IgnoredByEnemyAI);
}
if (husk.Info != null)
{
husk.Info.Character = husk;
husk.Info.TeamID = CharacterTeamType.None;
}
husk.AllowPlayDead = character.AllowPlayDead;
if (Prefab is AfflictionPrefabHusk huskPrefab)
{
@@ -379,17 +396,15 @@ namespace Barotrauma
yield return CoroutineStatus.Success;
}
public static List<Limb> AttachHuskAppendage(Character character, AfflictionPrefabHusk matchingAffliction, ContentXElement appendageDefinition = null, Ragdoll ragdoll = null)
public static List<Limb> AttachHuskAppendage(Character character, AfflictionPrefabHusk matchingAffliction, Identifier huskedSpeciesName, ContentXElement appendageDefinition = null, Ragdoll ragdoll = null)
{
var appendage = new List<Limb>();
Identifier nonhuskedSpeciesName = GetNonHuskedSpeciesName(character.SpeciesName, matchingAffliction);
Identifier huskedSpeciesName = GetHuskedSpeciesName(nonhuskedSpeciesName, matchingAffliction);
var appendageLimbs = new List<Limb>();
CharacterPrefab huskPrefab = CharacterPrefab.FindBySpeciesName(huskedSpeciesName);
if (huskPrefab?.ConfigElement == null)
{
DebugConsole.ThrowError($"Failed to find the config file for the husk infected species with the species name '{huskedSpeciesName}'!",
contentPackage: matchingAffliction.ContentPackage);
return appendage;
return appendageLimbs;
}
var mainElement = huskPrefab.ConfigElement;
var element = appendageDefinition;
@@ -401,28 +416,25 @@ namespace Barotrauma
{
DebugConsole.ThrowError($"Error in '{huskPrefab.FilePath}': Failed to find a huskappendage that matches the affliction with an identifier '{matchingAffliction.Identifier}'!",
contentPackage: matchingAffliction.ContentPackage);
return appendage;
return appendageLimbs;
}
ContentPath pathToAppendage = element.GetAttributeContentPath("path") ?? ContentPath.Empty;
XDocument doc = XMLExtensions.TryLoadXml(pathToAppendage);
if (doc == null) { return appendage; }
if (ragdoll == null)
{
ragdoll = character.AnimController;
}
if (doc == null) { return appendageLimbs; }
ragdoll ??= character.AnimController;
if (ragdoll.Dir < 1.0f)
{
ragdoll.Flip();
}
var root = doc.Root.FromPackage(pathToAppendage.ContentPackage);
var limbElements = root.GetChildElements("limb").ToDictionary(e => e.GetAttributeString("id", null), e => e);
var limbElements = root.GetChildElements("limb").ToDictionary(e => e.GetAttributeInt("id", -1), e => e);
//the IDs may need to be offset if the character has other extra appendages (e.g. from gene splicing)
//that take up the IDs of this appendage
int idOffset = 0;
int? idOffset = null;
foreach (var jointElement in root.GetChildElements("joint"))
{
if (!limbElements.TryGetValue(jointElement.GetAttributeString("limb2", null), out ContentXElement limbElement)) { continue; }
if (!limbElements.TryGetValue(jointElement.GetAttributeInt("limb2", -1), out ContentXElement limbElement)) { continue; }
var jointParams = new RagdollParams.JointParams(jointElement, ragdoll.RagdollParams);
Limb attachLimb = null;
@@ -444,38 +456,54 @@ namespace Barotrauma
}
if (attachLimb != null)
{
jointParams.Limb1 = attachLimb.Params.ID;
//the joint attaches to a limb outside the character's normal limb count = to another part of the appendage
// -> if the appendage's IDs have been offset, we need to take that into account to attach to the correct limb
if (jointParams.Limb1 >= ragdoll.RagdollParams.Limbs.Count)
{
jointParams.Limb1 += idOffset;
}
var appendageLimbParams = new RagdollParams.LimbParams(limbElement, ragdoll.RagdollParams);
if (idOffset == 0)
idOffset ??= ragdoll.Limbs.Length - appendageLimbParams.ID;
jointParams.Limb1 = attachLimb.Params.ID;
//the joint attaches to one of the limbs we're creating = to another part of the appendage
// -> if the appendage's IDs have been offset, we need to take that into account to attach to the correct limb
if (limbElements.ContainsKey(jointParams.Limb1))
{
idOffset = ragdoll.Limbs.Length - appendageLimbParams.ID;
jointParams.Limb1 += idOffset.Value;
}
jointParams.Limb2 = appendageLimbParams.ID = ragdoll.Limbs.Length;
Limb huskAppendage = new Limb(ragdoll, character, appendageLimbParams);
if (limbElements.ContainsKey(jointParams.Limb2))
{
jointParams.Limb2 += idOffset.Value;
}
Limb huskAppendage =
//check if this joint is supposed to attach to a limb we already created
appendageLimbs.Find(limb => limb.Params.ID == appendageLimbParams.ID) ??
//if not, create a new limb
new Limb(ragdoll, character, appendageLimbParams);
huskAppendage.body.Submarine = character.Submarine;
huskAppendage.body.SetTransform(attachLimb.SimPosition, attachLimb.Rotation);
ragdoll.AddLimb(huskAppendage);
ragdoll.AddJoint(jointParams);
appendage.Add(huskAppendage);
}
appendageLimbs.Add(huskAppendage);
}
}
return appendage;
return appendageLimbs;
}
public static Identifier GetHuskedSpeciesName(Identifier speciesName, AfflictionPrefabHusk prefab)
public static Identifier GetHuskedSpeciesName(CharacterParams character, AfflictionPrefabHusk prefab)
{
return new Identifier(speciesName.Value + prefab.HuskedSpeciesName.Value);
Identifier huskedSpecies = character.HuskedSpecies;
if (huskedSpecies.IsEmpty)
{
// Default pattern: Crawler -> Crawlerhusk, Human -> Humanhusk
return new Identifier(character.SpeciesName.Value + prefab.HuskedSpeciesName.Value);
}
return huskedSpecies;
}
public static Identifier GetNonHuskedSpeciesName(Identifier huskedSpeciesName, AfflictionPrefabHusk prefab)
public static Identifier GetNonHuskedSpeciesName(CharacterParams character, AfflictionPrefabHusk prefab)
{
return huskedSpeciesName.Remove(prefab.HuskedSpeciesName);
Identifier nonHuskedSpecies = character.NonHuskedSpecies;
if (nonHuskedSpecies.IsEmpty)
{
// Default pattern: Crawlerhusk -> Crawler, Humanhusk -> Human
return character.SpeciesName.Remove(prefab.HuskedSpeciesName);
}
return nonHuskedSpecies;
}
}
}
@@ -329,6 +329,11 @@ namespace Barotrauma
/// </summary>
public readonly ImmutableArray<Identifier> ResistanceFor;
/// <summary>
/// List of limb types that the resistance applies to. If empty, the resistance applies to the whole body.
/// </summary>
public readonly ImmutableArray<LimbType> ResistanceLimbs;
[Serialize(0.0f, IsPropertySaveable.No,
description: "The amount of resistance to the afflictions specified by ResistanceFor to apply at this effect's lowest strength.")]
public float MinResistance { get; private set; }
@@ -359,6 +364,18 @@ namespace Barotrauma
description: "Color to tint the affected character's entire body with at this effect's highest strength. The alpha channel is used to determine how much to tint the character.")]
public Color MaxBodyTint { get; private set; }
[Serialize(0.0f, IsPropertySaveable.No,
description: "Range of the \"thermal goggles overlay\" enabled by the affliction.")]
public float ThermalOverlayRange { get; private set; }
[Serialize("255,0,0,255", IsPropertySaveable.No,
description: $"Color of the \"thermal goggles overlay\" enabled by the affliction. Only has an effect if {nameof(ThermalOverlayRange)} is larger than 0.")]
public Color ThermalOverlayColor { get; private set; }
[Serialize(0f, IsPropertySaveable.No,
description: "Multiplier for the convulsion/seizure effect on the character's ragdoll when this effect is active.")]
public float ConvulseAmount { get; private set; }
/// <summary>
/// StatType that will be applied to the affected character when the effect is active that is proportional to the effect's strength.
/// </summary>
@@ -385,7 +402,7 @@ namespace Barotrauma
public readonly float MinValue;
/// <summary>
/// Minimum value to apply
/// Maximum value to apply
/// </summary>
public readonly float MaxValue;
@@ -423,6 +440,8 @@ namespace Barotrauma
SerializableProperty.DeserializeProperties(this, element);
ResistanceFor = element.GetAttributeIdentifierArray("resistancefor", Array.Empty<Identifier>())!.ToImmutableArray();
ResistanceLimbs = element.GetAttributeEnumArray<LimbType>("resistancelimbs", Array.Empty<LimbType>()).ToImmutableArray();
BlockTransformation = element.GetAttributeIdentifierArray("blocktransformation", Array.Empty<Identifier>())!.ToImmutableArray();
var afflictionStatValues = new Dictionary<StatTypes, AppliedStatValue>();
@@ -594,7 +613,7 @@ namespace Barotrauma
}
else
{
MinInterval = Math.Max(element.GetAttributeFloat(nameof(MinInterval), 1.0f), 1.0f);
MinInterval = Math.Max(element.GetAttributeFloat(nameof(MinInterval), 1.0f), 0.1f);
MaxInterval = Math.Max(element.GetAttributeFloat(nameof(MaxInterval), 1.0f), MinInterval);
MinStrength = Math.Max(element.GetAttributeFloat(nameof(MinStrength), 0f), 0f);
MaxStrength = Math.Max(element.GetAttributeFloat(nameof(MaxStrength), MinStrength), MinStrength);
@@ -612,6 +631,7 @@ namespace Barotrauma
public static readonly Identifier SpaceHerpesType = "spaceherpes".ToIdentifier();
public static readonly Identifier AlienInfectedType = "alieninfected".ToIdentifier();
public static readonly Identifier InvertControlsType = "invertcontrols".ToIdentifier();
public static readonly Identifier DisguisedAsHuskType = "disguiseashusk".ToIdentifier();
public static AfflictionPrefab InternalDamage => Prefabs["internaldamage"];
public static AfflictionPrefab BiteWounds => Prefabs["bitewounds"];
@@ -624,7 +644,8 @@ namespace Barotrauma
public static AfflictionPrefab OrganDamage => Prefabs["organdamage"];
public static AfflictionPrefab Stun => Prefabs[StunType];
public static AfflictionPrefab RadiationSickness => Prefabs["radiationsickness"];
public static AfflictionPrefab HuskInfection => Prefabs["huskinfection"];
public static AfflictionPrefab JovianRadiation => Prefabs["jovianradiation"];
public static readonly PrefabCollection<AfflictionPrefab> Prefabs = new PrefabCollection<AfflictionPrefab>();
@@ -641,6 +662,11 @@ namespace Barotrauma
private readonly LocalizedString defaultDescription;
public readonly ImmutableList<Description> Descriptions;
/// <summary>
/// Should the affliction's description be included in the tooltips on the affliction icons above the health bar?
/// </summary>
public readonly bool ShowDescriptionInTooltip;
/// <summary>
/// Arbitrary string that is used to identify the type of the affliction.
/// </summary>
@@ -748,6 +774,12 @@ namespace Barotrauma
/// </summary>
public readonly float TreatmentThreshold;
/// <summary>
/// How strong the affliction needs to be for treatment suggestions to be shown in the health interface.
/// Defaults to <see cref="TreatmentThreshold"/>.
/// </summary>
public readonly float TreatmentSuggestionThreshold;
/// <summary>
/// Bots will not try to treat the affliction if the character has any of these afflictions
/// </summary>
@@ -880,6 +912,8 @@ namespace Barotrauma
{
defaultDescription = defaultDescription.Fallback(fallbackDescription);
}
ShowDescriptionInTooltip = element.GetAttributeBool(nameof(ShowDescriptionInTooltip), true);
IsBuff = element.GetAttributeBool(nameof(IsBuff), false);
AffectMachines = element.GetAttributeBool(nameof(AffectMachines), true);
@@ -898,7 +932,10 @@ namespace Barotrauma
if (element.GetAttribute("nameidentifier") != null)
{
Name = TextManager.Get(element.GetAttributeString("nameidentifier", string.Empty)).Fallback(Name);
string nameIdentifier = element.GetAttributeString("nameidentifier", string.Empty);
Name = TextManager.Get(nameIdentifier)
.Fallback(TextManager.Get($"AfflictionName.{nameIdentifier}"))
.Fallback(Name);
}
LimbSpecific = element.GetAttributeBool("limbspecific", false);
@@ -914,6 +951,12 @@ namespace Barotrauma
HideIconAfterDelay = element.GetAttributeBool(nameof(HideIconAfterDelay), false);
ActivationThreshold = element.GetAttributeFloat(nameof(ActivationThreshold), 0.0f);
if (Identifier == StunType && ActivationThreshold > 0.0f)
{
ActivationThreshold = 0.0f;
DebugConsole.AddWarning($"Error in affliction prefab {Identifier}: activation threshold of the stun affliction must be 0, because the strength of the affliction represents the length of the stun and any amount of stun has an effect.");
}
ShowIconThreshold = element.GetAttributeFloat(nameof(ShowIconThreshold), Math.Max(ActivationThreshold, 0.05f));
ShowIconToOthersThreshold = element.GetAttributeFloat(nameof(ShowIconToOthersThreshold), ShowIconThreshold);
MaxStrength = element.GetAttributeFloat(nameof(MaxStrength), 100.0f);
@@ -922,6 +965,7 @@ namespace Barotrauma
ShowInHealthScannerThreshold = element.GetAttributeFloat(nameof(ShowInHealthScannerThreshold),
Math.Max(ActivationThreshold, AfflictionType == "talentbuff" ? float.MaxValue : ShowIconToOthersThreshold));
TreatmentThreshold = element.GetAttributeFloat(nameof(TreatmentThreshold), Math.Max(ActivationThreshold, 10.0f));
TreatmentSuggestionThreshold = element.GetAttributeFloat(nameof(TreatmentSuggestionThreshold), TreatmentThreshold);
DamageOverlayAlpha = element.GetAttributeFloat(nameof(DamageOverlayAlpha), 0.0f);
BurnOverlayAlpha = element.GetAttributeFloat(nameof(BurnOverlayAlpha), 0.0f);