Unstable 1.1.14.0

This commit is contained in:
Markus Isberg
2023-10-02 16:43:54 +03:00
parent 94f5a93a0c
commit cf8f0de659
606 changed files with 21906 additions and 11456 deletions
@@ -7,6 +7,7 @@ using System.Xml.Linq;
using Barotrauma.Extensions;
using System.Collections.Immutable;
using Barotrauma.Items.Components;
using System.Linq;
namespace Barotrauma
{
@@ -602,7 +603,6 @@ 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 HuskInfectionType = "huskinfection".ToIdentifier();
public static AfflictionPrefab InternalDamage => Prefabs["internaldamage"];
public static AfflictionPrefab BiteWounds => Prefabs["bitewounds"];
@@ -612,6 +612,7 @@ namespace Barotrauma
public static AfflictionPrefab OxygenLow => Prefabs["oxygenlow"];
public static AfflictionPrefab Bloodloss => Prefabs["bloodloss"];
public static AfflictionPrefab Pressure => Prefabs["pressure"];
public static AfflictionPrefab OrganDamage => Prefabs["organdamage"];
public static AfflictionPrefab Stun => Prefabs[StunType];
public static AfflictionPrefab RadiationSickness => Prefabs["radiationsickness"];
@@ -841,20 +842,16 @@ namespace Barotrauma
/// </summary>
public readonly Sprite AfflictionOverlay;
public IEnumerable<KeyValuePair<Identifier, float>> TreatmentSuitability
public ImmutableDictionary<Identifier, float> TreatmentSuitabilities
{
get
{
foreach (var itemPrefab in ItemPrefab.Prefabs)
{
float suitability = itemPrefab.GetTreatmentSuitability(Identifier) + itemPrefab.GetTreatmentSuitability(AfflictionType);
if (!MathUtils.NearlyEqual(suitability, 0.0f))
{
yield return new KeyValuePair<Identifier, float>(itemPrefab.Identifier, suitability);
}
}
}
}
get;
private set;
} = new Dictionary<Identifier, float>().ToImmutableDictionary();
/// <summary>
/// Can this affliction be treated with some item?
/// </summary>
public bool HasTreatments { get; private set; }
public AfflictionPrefab(ContentXElement element, AfflictionsFile file, Type type) : base(file, element.GetAttributeIdentifier("identifier", ""))
{
@@ -974,6 +971,22 @@ namespace Barotrauma
constructor = type.GetConstructor(new[] { typeof(AfflictionPrefab), typeof(float) });
}
private void RefreshTreatmentSuitabilities()
{
var newTreatmentSuitabilities = new Dictionary<Identifier, float>();
foreach (var itemPrefab in ItemPrefab.Prefabs)
{
float suitability = itemPrefab.GetTreatmentSuitability(Identifier) + itemPrefab.GetTreatmentSuitability(AfflictionType);
if (!MathUtils.NearlyEqual(suitability, 0.0f))
{
newTreatmentSuitabilities.TryAdd(itemPrefab.Identifier, suitability);
}
}
HasTreatments = newTreatmentSuitabilities.Any(kvp => kvp.Value > 0);
TreatmentSuitabilities = newTreatmentSuitabilities.ToImmutableDictionary();
}
public LocalizedString GetDescription(float strength, Description.TargetType targetType)
{
foreach (var description in Descriptions)
@@ -993,9 +1006,16 @@ namespace Barotrauma
return defaultDescription;
}
public static void LoadAllEffects()
/// <summary>
/// Should be called before each round: loads all StatusEffects and refreshes treatment suitabilities.
/// </summary>
public static void LoadAllEffectsAndTreatmentSuitabilities()
{
Prefabs.ForEach(p => p.LoadEffects());
foreach (var prefab in Prefabs)
{
prefab.RefreshTreatmentSuitabilities();
prefab.LoadEffects();
}
}
public static void ClearAllEffects()
@@ -1003,7 +1023,7 @@ namespace Barotrauma
Prefabs.ForEach(p => p.ClearEffects());
}
public void LoadEffects()
private void LoadEffects()
{
ClearEffects();
foreach (var subElement in configElement.Elements())
@@ -1032,7 +1052,7 @@ namespace Barotrauma
}
}
public void ClearEffects()
private void ClearEffects()
{
effects.Clear();
periodicEffects.Clear();
@@ -156,6 +156,12 @@ namespace Barotrauma
}
}
/// <summary>
/// How much vitality the character would have if it was alive?
/// E.g. a character killed by disconnection or with console commands may not have any vitality-reducing afflictions despite being dead
/// </summary>
public float VitalityDisregardingDeath => vitality;
public float HealthPercentage => MathUtils.Percentage(Vitality, MaxVitality);
public float MaxVitality
@@ -229,6 +235,8 @@ namespace Barotrauma
}
}
public bool IsParalyzed { get; private set; }
public float StunTimer { get; private set; }
/// <summary>
@@ -402,7 +410,17 @@ namespace Barotrauma
return strength;
}
public float GetAfflictionStrength(Identifier afflictionType, bool allowLimbAfflictions = true)
public float GetAfflictionStrengthByType(Identifier afflictionType, bool allowLimbAfflictions = true)
{
return GetAfflictionStrength(afflictionType, afflictionidentifier: Identifier.Empty, allowLimbAfflictions);
}
public float GetAfflictionStrengthByIdentifier(Identifier afflictionIdentifier, bool allowLimbAfflictions = true)
{
return GetAfflictionStrength(afflictionType: Identifier.Empty, afflictionIdentifier, allowLimbAfflictions);
}
public float GetAfflictionStrength(Identifier afflictionType, Identifier afflictionidentifier, bool allowLimbAfflictions = true)
{
float strength = 0.0f;
foreach (KeyValuePair<Affliction, LimbHealth> kvp in afflictions)
@@ -410,7 +428,8 @@ namespace Barotrauma
if (!allowLimbAfflictions && kvp.Value != null) { continue; }
var affliction = kvp.Key;
if (affliction.Strength < affliction.Prefab.ActivationThreshold) { continue; }
if (affliction.Prefab.AfflictionType == afflictionType)
if ((affliction.Prefab.AfflictionType == afflictionType || afflictionType.IsEmpty) &&
(affliction.Prefab.Identifier == afflictionidentifier || afflictionidentifier.IsEmpty))
{
strength += affliction.Strength;
}
@@ -714,7 +733,7 @@ namespace Barotrauma
if (!Character.NeedsOxygen && newAffliction.Prefab == AfflictionPrefab.OxygenLow) { return; }
if (Character.Params.Health.StunImmunity && newAffliction.Prefab.AfflictionType == AfflictionPrefab.StunType)
{
if (Character.EmpVulnerability <= 0 || GetAfflictionStrength(AfflictionPrefab.EMPType, allowLimbAfflictions: false) <= 0)
if (Character.EmpVulnerability <= 0 || GetAfflictionStrengthByType(AfflictionPrefab.EMPType, allowLimbAfflictions: false) <= 0)
{
return;
}
@@ -953,6 +972,7 @@ namespace Barotrauma
public void CalculateVitality()
{
Vitality = MaxVitality;
IsParalyzed = false;
if (Unkillable || Character.GodMode) { return; }
foreach (KeyValuePair<Affliction, LimbHealth> kvp in afflictions)
@@ -966,6 +986,12 @@ namespace Barotrauma
}
Vitality -= vitalityDecrease;
affliction.CalculateDamagePerSecond(vitalityDecrease);
if (affliction.Strength >= affliction.Prefab.MaxStrength &&
affliction.Prefab.AfflictionType == AfflictionPrefab.ParalysisType)
{
IsParalyzed = true;
}
}
#if CLIENT
if (IsUnconscious)
@@ -1136,7 +1162,7 @@ namespace Barotrauma
}
}
foreach (KeyValuePair<Identifier, float> treatment in affliction.Prefab.TreatmentSuitability)
foreach (KeyValuePair<Identifier, float> treatment in affliction.Prefab.TreatmentSuitabilities)
{
float suitability = treatment.Value * strength;
if (treatment.Value > strength)