Unstable 0.17.0.0

This commit is contained in:
Markus Isberg
2022-02-26 02:43:01 +09:00
parent a83f375681
commit 3974067915
913 changed files with 32472 additions and 32364 deletions
@@ -19,23 +19,23 @@ namespace Barotrauma
public Rectangle HighlightArea;
public readonly string Name;
public readonly LocalizedString Name;
//public readonly List<Affliction> Afflictions = new List<Affliction>();
public readonly Dictionary<string, float> VitalityMultipliers = new Dictionary<string, float>();
public readonly Dictionary<string, float> VitalityTypeMultipliers = new Dictionary<string, float>();
public readonly Dictionary<Identifier, float> VitalityMultipliers = new Dictionary<Identifier, float>();
public readonly Dictionary<Identifier, float> VitalityTypeMultipliers = new Dictionary<Identifier, float>();
public LimbHealth() { }
public LimbHealth(XElement element, CharacterHealth characterHealth)
public LimbHealth(ContentXElement element, CharacterHealth characterHealth)
{
string limbName = element.GetAttributeString("name", null) ?? "generic";
if (limbName != "generic")
{
Name = TextManager.Get("HealthLimbName." + limbName);
}
foreach (XElement subElement in element.Elements())
foreach (var subElement in element.Elements())
{
switch (subElement.Name.ToString().ToLowerInvariant())
{
@@ -53,16 +53,16 @@ namespace Barotrauma
continue;
}
string afflictionIdentifier = subElement.GetAttributeString("identifier", "");
string afflictionType = subElement.GetAttributeString("type", "");
Identifier afflictionIdentifier = subElement.GetAttributeIdentifier("identifier", "");
Identifier afflictionType = subElement.GetAttributeIdentifier("type", "");
float multiplier = subElement.GetAttributeFloat("multiplier", 1.0f);
if (!string.IsNullOrEmpty(afflictionIdentifier))
if (!afflictionIdentifier.IsEmpty)
{
VitalityMultipliers.Add(afflictionIdentifier.ToLowerInvariant(), multiplier);
VitalityMultipliers.Add(afflictionIdentifier, multiplier);
}
else
{
VitalityTypeMultipliers.Add(afflictionType.ToLowerInvariant(), multiplier);
VitalityTypeMultipliers.Add(afflictionType, multiplier);
}
break;
}
@@ -219,7 +219,7 @@ namespace Barotrauma
InitProjSpecific(null, character);
}
public CharacterHealth(XElement element, Character character, XElement limbHealthElement = null)
public CharacterHealth(ContentXElement element, Character character, ContentXElement limbHealthElement = null)
{
this.Character = character;
InitIrremovableAfflictions();
@@ -230,7 +230,7 @@ namespace Barotrauma
limbHealths.Clear();
limbHealthElement ??= element;
foreach (XElement subElement in limbHealthElement.Elements())
foreach (var subElement in limbHealthElement.Elements())
{
if (!subElement.Name.ToString().Equals("limb", StringComparison.OrdinalIgnoreCase)) { continue; }
limbHealths.Add(new LimbHealth(subElement, this));
@@ -255,7 +255,7 @@ namespace Barotrauma
}
}
partial void InitProjSpecific(XElement element, Character character);
partial void InitProjSpecific(ContentXElement element, Character character);
public IReadOnlyCollection<Affliction> GetAllAfflictions()
{
@@ -282,10 +282,13 @@ namespace Barotrauma
private LimbHealth GetMatchingLimbHealth(Limb limb) => limb == null ? null : limbHealths[limb.HealthIndex];
private LimbHealth GetMatchingLimbHealth(Affliction affliction) => GetMatchingLimbHealth(Character.AnimController.GetLimb(affliction.Prefab.IndicatorLimb, excludeSevered: false));
public Affliction GetAffliction(string identifier, bool allowLimbAfflictions = true)
public Affliction GetAffliction(string identifier, bool allowLimbAfflictions = true) =>
GetAffliction(identifier.ToIdentifier(), allowLimbAfflictions);
public Affliction GetAffliction(Identifier identifier, bool allowLimbAfflictions = true)
=> GetAffliction(a => a.Prefab.Identifier == identifier, allowLimbAfflictions);
public Affliction GetAfflictionOfType(string afflictionType, bool allowLimbAfflictions = true)
public Affliction GetAfflictionOfType(Identifier afflictionType, bool allowLimbAfflictions = true)
=> GetAffliction(a => a.Prefab.AfflictionType == afflictionType, allowLimbAfflictions);
private Affliction GetAffliction(Func<Affliction, bool> predicate, bool allowLimbAfflictions = true)
@@ -409,7 +412,7 @@ namespace Barotrauma
foreach (KeyValuePair<Affliction, LimbHealth> kvp in afflictions)
{
var affliction = kvp.Key;
resistance += affliction.GetResistance(afflictionPrefab);
resistance += affliction.GetResistance(afflictionPrefab.Identifier);
}
return 1 - ((1 - resistance) * Character.GetAbilityResistance(afflictionPrefab));
}
@@ -436,37 +439,58 @@ namespace Barotrauma
}
private readonly List<Affliction> matchingAfflictions = new List<Affliction>();
public void ReduceAffliction(Limb targetLimb, string afflictionIdentifier, float amount, ActionType? treatmentAction = null)
public void ReduceAllAfflictionsOnAllLimbs(float amount, ActionType? treatmentAction = null)
{
matchingAfflictions.Clear();
matchingAfflictions.AddRange(afflictions.Keys);
if (targetLimb == null)
{
matchingAfflictions.AddRange(afflictions.Keys);
}
else
{
foreach (KeyValuePair<Affliction, LimbHealth> kvp in afflictions)
{
var affliction = kvp.Key;
if (kvp.Value == null)
{
matchingAfflictions.Add(affliction);
}
else if (limbHealths[targetLimb.HealthIndex] == kvp.Value)
{
matchingAfflictions.Add(affliction);
}
}
}
ReduceMatchingAfflictions(amount, treatmentAction);
}
public void ReduceAfflictionOnAllLimbs(Identifier affliction, float amount, ActionType? treatmentAction = null)
{
if (affliction.IsEmpty) { throw new ArgumentException($"{nameof(affliction)} is empty"); }
matchingAfflictions.Clear();
matchingAfflictions.AddRange(afflictions.Keys);
matchingAfflictions.RemoveAll(a =>
a.Prefab.Identifier != affliction &&
a.Prefab.AfflictionType != affliction);
ReduceMatchingAfflictions(amount, treatmentAction);
}
if (!string.IsNullOrEmpty(afflictionIdentifier))
{
matchingAfflictions.RemoveAll(a =>
!a.Prefab.Identifier.Equals(afflictionIdentifier, StringComparison.OrdinalIgnoreCase) &&
!a.Prefab.AfflictionType.Equals(afflictionIdentifier, StringComparison.OrdinalIgnoreCase));
}
private IEnumerable<Affliction> GetAfflictionsForLimb(Limb targetLimb)
=> afflictions.Keys.Where(k => afflictions[k] == limbHealths[targetLimb.HealthIndex]);
public void ReduceAllAfflictionsOnLimb(Limb targetLimb, float amount, ActionType? treatmentAction = null)
{
if (targetLimb is null) { throw new ArgumentNullException(nameof(targetLimb)); }
matchingAfflictions.Clear();
matchingAfflictions.AddRange(GetAfflictionsForLimb(targetLimb));
ReduceMatchingAfflictions(amount, treatmentAction);
}
public void ReduceAfflictionOnLimb(Limb targetLimb, Identifier affliction, float amount, ActionType? treatmentAction = null)
{
if (affliction.IsEmpty) { throw new ArgumentException($"{nameof(affliction)} is empty"); }
if (targetLimb is null) { throw new ArgumentNullException(nameof(targetLimb)); }
matchingAfflictions.Clear();
matchingAfflictions.AddRange(GetAfflictionsForLimb(targetLimb));
matchingAfflictions.RemoveAll(a =>
a.Prefab.Identifier != affliction &&
a.Prefab.AfflictionType != affliction);
ReduceMatchingAfflictions(amount, treatmentAction);
}
private void ReduceMatchingAfflictions(float amount, ActionType? treatmentAction)
{
if (matchingAfflictions.Count == 0) { return; }
float reduceAmount = amount / matchingAfflictions.Count;
@@ -635,7 +659,7 @@ namespace Barotrauma
if (Character.Params.Health.StunImmunity && newAffliction.Prefab.AfflictionType == "stun") { return; }
if (newAffliction.Prefab is AfflictionPrefabHusk huskPrefab)
{
if (huskPrefab.TargetSpecies.None(s => s.Equals(Character.SpeciesName, StringComparison.OrdinalIgnoreCase)))
if (huskPrefab.TargetSpecies.None(s => s == Character.SpeciesName))
{
return;
}
@@ -953,7 +977,7 @@ namespace Barotrauma
/// <param name="treatmentSuitability">A dictionary where the key is the identifier of the item and the value the suitability</param>
/// <param name="normalize">If true, the suitability values are normalized between 0 and 1. If not, they're arbitrary values defined in the medical item XML, where negative values are unsuitable, and positive ones suitable.</param>
/// <param name="predictFutureDuration">If above 0, the method will take into account how much currently active status effects while affect the afflictions in the next x seconds.</param>
public void GetSuitableTreatments(Dictionary<string, float> treatmentSuitability, bool normalize, Limb limb = null, bool ignoreHiddenAfflictions = false, float predictFutureDuration = 0.0f)
public void GetSuitableTreatments(Dictionary<Identifier, float> treatmentSuitability, bool normalize, Limb limb = null, bool ignoreHiddenAfflictions = false, float predictFutureDuration = 0.0f)
{
//key = item identifier
//float = suitability
@@ -979,7 +1003,7 @@ namespace Barotrauma
if (strength <= affliction.Prefab.TreatmentThreshold) { continue; }
if (ignoreHiddenAfflictions && strength < affliction.Prefab.ShowIconThreshold) { continue; }
foreach (KeyValuePair<string, float> treatment in affliction.Prefab.TreatmentSuitability)
foreach (KeyValuePair<Identifier, float> treatment in affliction.Prefab.TreatmentSuitability)
{
if (!treatmentSuitability.ContainsKey(treatment.Key))
{
@@ -996,23 +1020,23 @@ namespace Barotrauma
//normalize the suitabilities to a range of 0 to 1
if (normalize)
{
foreach (string treatment in treatmentSuitability.Keys.ToList())
foreach (Identifier treatment in treatmentSuitability.Keys.ToList())
{
treatmentSuitability[treatment] = (treatmentSuitability[treatment] - minSuitability) / (maxSuitability - minSuitability);
}
}
}
public IEnumerable<string> GetActiveAfflictionTags() => GetActiveAfflictionTags(afflictions.Keys);
public IEnumerable<Identifier> GetActiveAfflictionTags() => GetActiveAfflictionTags(afflictions.Keys);
private readonly HashSet<string> afflictionTags = new HashSet<string>();
public IEnumerable<string> GetActiveAfflictionTags(IEnumerable<Affliction> afflictions)
private readonly HashSet<Identifier> afflictionTags = new HashSet<Identifier>();
public IEnumerable<Identifier> GetActiveAfflictionTags(IEnumerable<Affliction> afflictions)
{
afflictionTags.Clear();
foreach (Affliction affliction in afflictions)
{
var currentEffect = affliction.GetActiveEffect();
if (currentEffect != null && !string.IsNullOrEmpty(currentEffect.Tag))
if (currentEffect != null && !currentEffect.Tag.IsEmpty)
{
afflictionTags.Add(currentEffect.Tag);
}
@@ -1036,10 +1060,10 @@ namespace Barotrauma
}
foreach (var statusEffectAffliction in statusEffect.Parent.ReduceAffliction)
{
if (statusEffectAffliction.affliction.Equals(affliction.Identifier, StringComparison.OrdinalIgnoreCase) ||
statusEffectAffliction.affliction.Equals(affliction.Prefab.AfflictionType, StringComparison.OrdinalIgnoreCase))
if (statusEffectAffliction.AfflictionIdentifier == affliction.Identifier ||
statusEffectAffliction.AfflictionIdentifier == affliction.Prefab.AfflictionType)
{
strength -= statusEffectAffliction.amount * statusEffectDuration;
strength -= statusEffectAffliction.ReduceAmount * statusEffectDuration;
}
}
}
@@ -1064,7 +1088,7 @@ namespace Barotrauma
msg.Write((byte)activeAfflictions.Count);
foreach (Affliction affliction in activeAfflictions)
{
msg.Write(affliction.Prefab.UIntIdentifier);
msg.Write(affliction.Prefab.UintIdentifier);
msg.WriteRangedSingle(
MathHelper.Clamp(affliction.Strength, 0.0f, affliction.Prefab.MaxStrength),
0.0f, affliction.Prefab.MaxStrength, 8);
@@ -1089,7 +1113,7 @@ namespace Barotrauma
foreach (var (limbHealth, affliction) in limbAfflictions)
{
msg.WriteRangedInteger(limbHealths.IndexOf(limbHealth), 0, limbHealths.Count - 1);
msg.Write(affliction.Prefab.UIntIdentifier);
msg.Write(affliction.Prefab.UintIdentifier);
msg.WriteRangedSingle(
MathHelper.Clamp(affliction.Strength, 0.0f, affliction.Prefab.MaxStrength),
0.0f, affliction.Prefab.MaxStrength, 8);
@@ -1144,7 +1168,7 @@ namespace Barotrauma
public void Load(XElement element)
{
foreach (XElement subElement in element.Elements())
foreach (var subElement in element.Elements())
{
switch (subElement.Name.ToString().ToLowerInvariant())
{