Merge branch 'dev' of https://github.com/Regalis11/Barotrauma.git into unstable-tests
This commit is contained in:
+10
-9
@@ -12,7 +12,7 @@ namespace Barotrauma
|
||||
|
||||
public string Name => ToString();
|
||||
|
||||
public Dictionary<string, SerializableProperty> SerializableProperties { get; set; }
|
||||
public Dictionary<Identifier, SerializableProperty> SerializableProperties { get; set; }
|
||||
|
||||
public float PendingAdditionStrength { get; set; }
|
||||
public float AdditionStrength { get; set; }
|
||||
@@ -21,7 +21,7 @@ namespace Barotrauma
|
||||
|
||||
protected float _strength;
|
||||
|
||||
[Serialize(0f, true), Editable]
|
||||
[Serialize(0f, IsPropertySaveable.Yes), Editable]
|
||||
public virtual float Strength
|
||||
{
|
||||
get { return _strength; }
|
||||
@@ -43,10 +43,10 @@ namespace Barotrauma
|
||||
private float _nonClampedStrength = -1;
|
||||
public float NonClampedStrength => _nonClampedStrength > 0 ? _nonClampedStrength : _strength;
|
||||
|
||||
[Serialize("", true), Editable]
|
||||
public string Identifier { get; private set; }
|
||||
[Serialize("", IsPropertySaveable.Yes), Editable]
|
||||
public Identifier Identifier { get; private set; }
|
||||
|
||||
[Serialize(1.0f, true, description: "The probability for the affliction to be applied."), Editable(minValue: 0f, maxValue: 1f)]
|
||||
[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;
|
||||
|
||||
public float DamagePerSecond;
|
||||
@@ -73,7 +73,7 @@ namespace Barotrauma
|
||||
Prefab = prefab;
|
||||
PendingAdditionStrength = Prefab.GrainBurst;
|
||||
_strength = strength;
|
||||
Identifier = prefab?.Identifier;
|
||||
Identifier = prefab.Identifier;
|
||||
|
||||
foreach (var periodicEffect in prefab.PeriodicEffects)
|
||||
{
|
||||
@@ -269,14 +269,15 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
public float GetResistance(AfflictionPrefab affliction)
|
||||
public float GetResistance(Identifier afflictionId)
|
||||
{
|
||||
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.Equals(affliction.Identifier, StringComparison.OrdinalIgnoreCase) ||
|
||||
r.Equals(affliction.AfflictionType, StringComparison.OrdinalIgnoreCase)))
|
||||
r == affliction.Identifier ||
|
||||
r == affliction.AfflictionType))
|
||||
{
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
+83
-23
@@ -26,7 +26,7 @@ namespace Barotrauma
|
||||
|
||||
private readonly List<Affliction> huskInfection = new List<Affliction>();
|
||||
|
||||
[Serialize(0f, true), Editable]
|
||||
[Serialize(0f, IsPropertySaveable.Yes), Editable]
|
||||
public override float Strength
|
||||
{
|
||||
get { return _strength; }
|
||||
@@ -41,9 +41,11 @@ namespace Barotrauma
|
||||
if (previousValue > 0.0f && value <= 0.0f)
|
||||
{
|
||||
DeactivateHusk();
|
||||
highestStrength = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
private float highestStrength;
|
||||
|
||||
public InfectionState State
|
||||
{
|
||||
@@ -75,6 +77,7 @@ namespace Barotrauma
|
||||
{
|
||||
if (HuskPrefab == null) { return; }
|
||||
base.Update(characterHealth, targetLimb, deltaTime);
|
||||
highestStrength = Math.Max(_strength, highestStrength);
|
||||
character = characterHealth.Character;
|
||||
if (character == null) { return; }
|
||||
|
||||
@@ -98,7 +101,7 @@ namespace Barotrauma
|
||||
DeactivateHusk();
|
||||
if (Prefab is AfflictionPrefabHusk { CauseSpeechImpediment: true })
|
||||
{
|
||||
character.SpeechImpediment = 100;
|
||||
character.SpeechImpediment = 30;
|
||||
}
|
||||
State = InfectionState.Transition;
|
||||
}
|
||||
@@ -108,6 +111,10 @@ namespace Barotrauma
|
||||
{
|
||||
character.SetStun(Rand.Range(2f, 3f));
|
||||
}
|
||||
if (Prefab is AfflictionPrefabHusk { CauseSpeechImpediment: true })
|
||||
{
|
||||
character.SpeechImpediment = 100;
|
||||
}
|
||||
State = InfectionState.Active;
|
||||
ActivateHusk();
|
||||
}
|
||||
@@ -120,7 +127,57 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
partial void UpdateMessages();
|
||||
private InfectionState? prevDisplayedMessage;
|
||||
private void UpdateMessages()
|
||||
{
|
||||
if (Prefab is AfflictionPrefabHusk { SendMessages: false }) { return; }
|
||||
if (prevDisplayedMessage.HasValue && prevDisplayedMessage.Value == State) { return; }
|
||||
if (highestStrength > Strength) { return; }
|
||||
|
||||
switch (State)
|
||||
{
|
||||
case InfectionState.Dormant:
|
||||
if (Strength < DormantThreshold * 0.5f)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (character == Character.Controlled)
|
||||
{
|
||||
#if CLIENT
|
||||
GUI.AddMessage(TextManager.Get("HuskDormant"), GUIStyle.Red);
|
||||
#endif
|
||||
}
|
||||
else if (character.IsBot)
|
||||
{
|
||||
character.Speak(TextManager.Get("dialoghuskdormant").Value, delay: Rand.Range(0.5f, 5.0f), identifier: "huskdormant".ToIdentifier());
|
||||
}
|
||||
break;
|
||||
case InfectionState.Transition:
|
||||
if (character == Character.Controlled)
|
||||
{
|
||||
#if CLIENT
|
||||
GUI.AddMessage(TextManager.Get("HuskCantSpeak"), GUIStyle.Red);
|
||||
#endif
|
||||
}
|
||||
else if (character.IsBot)
|
||||
{
|
||||
character.Speak(TextManager.Get("dialoghuskcantspeak").Value, delay: Rand.Range(0.5f, 5.0f), identifier: "huskcantspeak".ToIdentifier());
|
||||
}
|
||||
break;
|
||||
case InfectionState.Active:
|
||||
#if CLIENT
|
||||
if (character == Character.Controlled && character.Params.UseHuskAppendage)
|
||||
{
|
||||
GUI.AddMessage(TextManager.GetWithVariable("HuskActivate", "[Attack]", GameSettings.CurrentConfig.KeyMap.KeyBindText(InputType.Attack)), GUIStyle.Red);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
case InfectionState.Final:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
prevDisplayedMessage = State;
|
||||
}
|
||||
|
||||
private void ApplyDamage(float deltaTime, bool applyForce)
|
||||
{
|
||||
@@ -209,12 +266,14 @@ namespace Barotrauma
|
||||
{
|
||||
yield return CoroutineStatus.Success;
|
||||
}
|
||||
|
||||
#if SERVER
|
||||
var client = GameMain.Server?.ConnectedClients.FirstOrDefault(c => c.Character == character);
|
||||
#endif
|
||||
character.Enabled = false;
|
||||
Entity.Spawner.AddToRemoveQueue(character);
|
||||
Entity.Spawner.AddEntityToRemoveQueue(character);
|
||||
UnsubscribeFromDeathEvent();
|
||||
|
||||
string huskedSpeciesName = GetHuskedSpeciesName(character.SpeciesName, Prefab as AfflictionPrefabHusk);
|
||||
Identifier huskedSpeciesName = GetHuskedSpeciesName(character.SpeciesName, Prefab as AfflictionPrefabHusk);
|
||||
CharacterPrefab prefab = CharacterPrefab.FindBySpeciesName(huskedSpeciesName);
|
||||
|
||||
if (prefab == null)
|
||||
@@ -230,8 +289,8 @@ namespace Barotrauma
|
||||
if (huskCharacterInfo != null)
|
||||
{
|
||||
var bodyTint = GetBodyTint();
|
||||
huskCharacterInfo.SkinColor =
|
||||
Color.Lerp(huskCharacterInfo.SkinColor, bodyTint.Opaque(), bodyTint.A / 255.0f);
|
||||
huskCharacterInfo.Head.SkinColor =
|
||||
Color.Lerp(huskCharacterInfo.Head.SkinColor, bodyTint.Opaque(), bodyTint.A / 255.0f);
|
||||
}
|
||||
|
||||
var husk = Character.Create(huskedSpeciesName, character.WorldPosition, ToolBox.RandomSeed(8), huskCharacterInfo, isRemotePlayer: false, hasAi: true);
|
||||
@@ -246,7 +305,6 @@ namespace Barotrauma
|
||||
if (huskPrefab.ControlHusk || GameMain.Lua.game.enableControlHusk)
|
||||
{
|
||||
#if SERVER
|
||||
var client = GameMain.Server?.ConnectedClients.FirstOrDefault(c => c.Character == character);
|
||||
if (client != null)
|
||||
{
|
||||
GameMain.Server.SetClientCharacter(client, husk);
|
||||
@@ -307,7 +365,7 @@ namespace Barotrauma
|
||||
yield return CoroutineStatus.Success;
|
||||
}
|
||||
|
||||
public static List<Limb> AttachHuskAppendage(Character character, string afflictionIdentifier, XElement appendageDefinition = null, Ragdoll ragdoll = null)
|
||||
public static List<Limb> AttachHuskAppendage(Character character, Identifier afflictionIdentifier, ContentXElement appendageDefinition = null, Ragdoll ragdoll = null)
|
||||
{
|
||||
var appendage = new List<Limb>();
|
||||
if (!(AfflictionPrefab.List.FirstOrDefault(ap => ap.Identifier == afflictionIdentifier) is AfflictionPrefabHusk matchingAffliction))
|
||||
@@ -315,26 +373,26 @@ namespace Barotrauma
|
||||
DebugConsole.ThrowError($"Could not find an affliction of type 'huskinfection' that matches the affliction '{afflictionIdentifier}'!");
|
||||
return appendage;
|
||||
}
|
||||
string nonhuskedSpeciesName = GetNonHuskedSpeciesName(character.SpeciesName, matchingAffliction);
|
||||
string huskedSpeciesName = GetHuskedSpeciesName(nonhuskedSpeciesName, matchingAffliction);
|
||||
Identifier nonhuskedSpeciesName = GetNonHuskedSpeciesName(character.SpeciesName, matchingAffliction);
|
||||
Identifier huskedSpeciesName = GetHuskedSpeciesName(nonhuskedSpeciesName, matchingAffliction);
|
||||
CharacterPrefab huskPrefab = CharacterPrefab.FindBySpeciesName(huskedSpeciesName);
|
||||
if (huskPrefab?.XDocument == null)
|
||||
if (huskPrefab?.ConfigElement == null)
|
||||
{
|
||||
DebugConsole.ThrowError($"Failed to find the config file for the husk infected species with the species name '{huskedSpeciesName}'!");
|
||||
return appendage;
|
||||
}
|
||||
var mainElement = huskPrefab.XDocument.Root.IsOverride() ? huskPrefab.XDocument.Root.FirstElement() : huskPrefab.XDocument.Root;
|
||||
var mainElement = huskPrefab.ConfigElement;
|
||||
var element = appendageDefinition;
|
||||
if (element == null)
|
||||
{
|
||||
element = mainElement.GetChildElements("huskappendage").FirstOrDefault(e => e.GetAttributeString("affliction", string.Empty).Equals(afflictionIdentifier));
|
||||
element = mainElement.GetChildElements("huskappendage").FirstOrDefault(e => e.GetAttributeIdentifier("affliction", Identifier.Empty) == afflictionIdentifier);
|
||||
}
|
||||
if (element == null)
|
||||
{
|
||||
DebugConsole.ThrowError($"Error in '{huskPrefab.FilePath}': Failed to find a huskappendage that matches the affliction with an identifier '{afflictionIdentifier}'!");
|
||||
return appendage;
|
||||
}
|
||||
string pathToAppendage = element.GetAttributeString("path", string.Empty);
|
||||
ContentPath pathToAppendage = element.GetAttributeContentPath("path") ?? ContentPath.Empty;
|
||||
XDocument doc = XMLExtensions.TryLoadXml(pathToAppendage);
|
||||
if (doc == null) { return appendage; }
|
||||
if (ragdoll == null)
|
||||
@@ -345,10 +403,12 @@ namespace Barotrauma
|
||||
{
|
||||
ragdoll.Flip();
|
||||
}
|
||||
var limbElements = doc.Root.Elements("limb").ToDictionary(e => e.GetAttributeString("id", null), e => e);
|
||||
foreach (var jointElement in doc.Root.Elements("joint"))
|
||||
|
||||
var root = doc.Root.FromPackage(pathToAppendage.ContentPackage);
|
||||
var limbElements = root.GetChildElements("limb").ToDictionary(e => e.GetAttributeString("id", null), e => e);
|
||||
foreach (var jointElement in root.GetChildElements("joint"))
|
||||
{
|
||||
if (limbElements.TryGetValue(jointElement.GetAttributeString("limb2", null), out XElement limbElement))
|
||||
if (limbElements.TryGetValue(jointElement.GetAttributeString("limb2", null), out ContentXElement limbElement))
|
||||
{
|
||||
var jointParams = new RagdollParams.JointParams(jointElement, ragdoll.RagdollParams);
|
||||
Limb attachLimb = null;
|
||||
@@ -389,15 +449,15 @@ namespace Barotrauma
|
||||
return appendage;
|
||||
}
|
||||
|
||||
public static string GetHuskedSpeciesName(string speciesName, AfflictionPrefabHusk prefab)
|
||||
public static Identifier GetHuskedSpeciesName(Identifier speciesName, AfflictionPrefabHusk prefab)
|
||||
{
|
||||
return prefab.HuskedSpeciesName.Replace(AfflictionPrefabHusk.Tag, speciesName);
|
||||
}
|
||||
|
||||
public static string GetNonHuskedSpeciesName(string huskedSpeciesName, AfflictionPrefabHusk prefab)
|
||||
public static Identifier GetNonHuskedSpeciesName(Identifier huskedSpeciesName, AfflictionPrefabHusk prefab)
|
||||
{
|
||||
string nonTag = prefab.HuskedSpeciesName.Remove(AfflictionPrefabHusk.Tag);
|
||||
return huskedSpeciesName.ToLowerInvariant().Remove(nonTag);
|
||||
Identifier nonTag = prefab.HuskedSpeciesName.Remove(AfflictionPrefabHusk.Tag);
|
||||
return huskedSpeciesName.Remove(nonTag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+139
-396
@@ -2,28 +2,29 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Xml.Linq;
|
||||
using Barotrauma.Extensions;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
static class CPRSettings
|
||||
class CPRSettings : Prefab
|
||||
{
|
||||
public static string FilePath { get; private set; }
|
||||
public static bool IsLoaded { get; private set; }
|
||||
public static float ReviveChancePerSkill { get; private set; }
|
||||
public static float ReviveChanceExponent { get; private set; }
|
||||
public static float ReviveChanceMin { get; private set; }
|
||||
public static float ReviveChanceMax { get; private set; }
|
||||
public static float StabilizationPerSkill { get; private set; }
|
||||
public static float StabilizationMin { get; private set; }
|
||||
public static float StabilizationMax { get; private set; }
|
||||
public static float DamageSkillThreshold { get; private set; }
|
||||
public static float DamageSkillMultiplier { get; private set; }
|
||||
public readonly static PrefabSelector<CPRSettings> Prefabs = new PrefabSelector<CPRSettings>();
|
||||
public static CPRSettings Active => Prefabs.ActivePrefab;
|
||||
|
||||
private static string insufficientSkillAfflictionIdentifier { get; set; }
|
||||
public static AfflictionPrefab InsufficientSkillAffliction
|
||||
public readonly float ReviveChancePerSkill;
|
||||
public readonly float ReviveChanceExponent;
|
||||
public readonly float ReviveChanceMin;
|
||||
public readonly float ReviveChanceMax;
|
||||
public readonly float StabilizationPerSkill;
|
||||
public readonly float StabilizationMin;
|
||||
public readonly float StabilizationMax;
|
||||
public readonly float DamageSkillThreshold;
|
||||
public readonly float DamageSkillMultiplier;
|
||||
|
||||
private readonly string insufficientSkillAfflictionIdentifier;
|
||||
public AfflictionPrefab InsufficientSkillAffliction
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -34,7 +35,7 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
public static void Load(XElement element, string filePath)
|
||||
public CPRSettings(XElement element, AfflictionsFile file) : base(file, file.Path.Value.ToIdentifier())
|
||||
{
|
||||
ReviveChancePerSkill = Math.Max(element.GetAttributeFloat("revivechanceperskill", 0.01f), 0.0f);
|
||||
ReviveChanceExponent = Math.Max(element.GetAttributeFloat("revivechanceexponent", 2.0f), 0.0f);
|
||||
@@ -49,33 +50,26 @@ namespace Barotrauma
|
||||
DamageSkillMultiplier = MathHelper.Clamp(element.GetAttributeFloat("damageskillmultiplier", 0.1f), 0.0f, 100.0f);
|
||||
|
||||
insufficientSkillAfflictionIdentifier = element.GetAttributeString("insufficientskillaffliction", "");
|
||||
|
||||
IsLoaded = true;
|
||||
FilePath = filePath;
|
||||
}
|
||||
|
||||
public static void Unload()
|
||||
{
|
||||
IsLoaded = false;
|
||||
FilePath = null;
|
||||
}
|
||||
public override void Dispose() { }
|
||||
}
|
||||
|
||||
class AfflictionPrefabHusk : AfflictionPrefab
|
||||
{
|
||||
public AfflictionPrefabHusk(XElement element, string filePath, Type type = null) : base(element, filePath, type)
|
||||
public AfflictionPrefabHusk(ContentXElement element, AfflictionsFile file, Type type = null) : base(element, file, type)
|
||||
{
|
||||
HuskedSpeciesName = element.GetAttributeString("huskedspeciesname", null).ToLowerInvariant();
|
||||
if (HuskedSpeciesName == null)
|
||||
HuskedSpeciesName = element.GetAttributeIdentifier("huskedspeciesname", Identifier.Empty);
|
||||
if (HuskedSpeciesName.IsEmpty)
|
||||
{
|
||||
DebugConsole.NewMessage($"No 'huskedspeciesname' defined for the husk affliction ({Identifier}) in {element}", Color.Orange);
|
||||
HuskedSpeciesName = "[speciesname]husk";
|
||||
HuskedSpeciesName = "[speciesname]husk".ToIdentifier();
|
||||
}
|
||||
TargetSpecies = element.GetAttributeStringArray("targets", new string[0] { }, trim: true, convertToLowerInvariant: true);
|
||||
TargetSpecies = element.GetAttributeIdentifierArray("targets", Array.Empty<Identifier>(), trim: true);
|
||||
if (TargetSpecies.Length == 0)
|
||||
{
|
||||
DebugConsole.NewMessage($"No 'targets' defined for the husk affliction ({Identifier}) in {element}", Color.Orange);
|
||||
TargetSpecies = new string[] { "human" };
|
||||
TargetSpecies = new Identifier[] { CharacterPrefab.HumanSpeciesName };
|
||||
}
|
||||
var attachElement = element.GetChildElement("attachlimb");
|
||||
if (attachElement != null)
|
||||
@@ -112,9 +106,9 @@ namespace Barotrauma
|
||||
public float ActiveThreshold, DormantThreshold, TransitionThreshold;
|
||||
public float TransformThresholdOnDeath;
|
||||
|
||||
public readonly string HuskedSpeciesName;
|
||||
public readonly string[] TargetSpecies;
|
||||
public const string Tag = "[speciesname]";
|
||||
public readonly Identifier HuskedSpeciesName;
|
||||
public readonly Identifier[] TargetSpecies;
|
||||
public static readonly Identifier Tag = "[speciesname]".ToIdentifier();
|
||||
|
||||
public readonly bool TransferBuffs;
|
||||
public readonly bool SendMessages;
|
||||
@@ -123,124 +117,122 @@ namespace Barotrauma
|
||||
public readonly bool ControlHusk;
|
||||
}
|
||||
|
||||
partial class AfflictionPrefab : IPrefab, IDisposable, IHasUintIdentifier
|
||||
class AfflictionPrefab : PrefabWithUintIdentifier
|
||||
{
|
||||
public class Effect
|
||||
{
|
||||
//this effect is applied when the strength is within this range
|
||||
[Serialize(0.0f, false)]
|
||||
[Serialize(0.0f, IsPropertySaveable.No)]
|
||||
public float MinStrength { get; private set; }
|
||||
|
||||
[Serialize(0.0f, false)]
|
||||
[Serialize(0.0f, IsPropertySaveable.No)]
|
||||
public float MaxStrength { get; private set; }
|
||||
|
||||
[Serialize(0.0f, false)]
|
||||
[Serialize(0.0f, IsPropertySaveable.No)]
|
||||
public float MinVitalityDecrease { get; private set; }
|
||||
|
||||
[Serialize(0.0f, false)]
|
||||
[Serialize(0.0f, IsPropertySaveable.No)]
|
||||
public float MaxVitalityDecrease { get; private set; }
|
||||
|
||||
//how much the strength of the affliction changes per second
|
||||
[Serialize(0.0f, false)]
|
||||
[Serialize(0.0f, IsPropertySaveable.No)]
|
||||
public float StrengthChange { get; private set; }
|
||||
|
||||
[Serialize(false, false)]
|
||||
[Serialize(false, IsPropertySaveable.No)]
|
||||
public bool MultiplyByMaxVitality { get; private set; }
|
||||
|
||||
[Serialize(0.0f, false)]
|
||||
[Serialize(0.0f, IsPropertySaveable.No)]
|
||||
public float MinScreenBlur { get; private set; }
|
||||
|
||||
[Serialize(0.0f, false)]
|
||||
[Serialize(0.0f, IsPropertySaveable.No)]
|
||||
public float MaxScreenBlur { get; private set; }
|
||||
|
||||
[Serialize(0.0f, false)]
|
||||
[Serialize(0.0f, IsPropertySaveable.No)]
|
||||
public float MinScreenDistort { get; private set; }
|
||||
|
||||
[Serialize(0.0f, false)]
|
||||
[Serialize(0.0f, IsPropertySaveable.No)]
|
||||
public float MaxScreenDistort { get; private set; }
|
||||
|
||||
[Serialize(0.0f, false)]
|
||||
[Serialize(0.0f, IsPropertySaveable.No)]
|
||||
public float MinRadialDistort { get; private set; }
|
||||
|
||||
[Serialize(0.0f, false)]
|
||||
[Serialize(0.0f, IsPropertySaveable.No)]
|
||||
public float MaxRadialDistort { get; private set; }
|
||||
|
||||
[Serialize(0.0f, false)]
|
||||
[Serialize(0.0f, IsPropertySaveable.No)]
|
||||
public float MinChromaticAberration { get; private set; }
|
||||
|
||||
[Serialize(0.0f, false)]
|
||||
[Serialize(0.0f, IsPropertySaveable.No)]
|
||||
public float MaxChromaticAberration { get; private set; }
|
||||
|
||||
[Serialize("255,255,255,255", false)]
|
||||
[Serialize("255,255,255,255", IsPropertySaveable.No)]
|
||||
public Color GrainColor { get; private set; }
|
||||
|
||||
[Serialize(0.0f, false)]
|
||||
[Serialize(0.0f, IsPropertySaveable.No)]
|
||||
public float MinGrainStrength { get; private set; }
|
||||
|
||||
[Serialize(0.0f, false)]
|
||||
[Serialize(0.0f, IsPropertySaveable.No)]
|
||||
public float MaxGrainStrength { get; private set; }
|
||||
|
||||
[Serialize(0.0f, false)]
|
||||
[Serialize(0.0f, IsPropertySaveable.No)]
|
||||
public float ScreenEffectFluctuationFrequency { get; private set; }
|
||||
|
||||
[Serialize(1.0f, false)]
|
||||
|
||||
[Serialize(1.0f, IsPropertySaveable.No)]
|
||||
public float MinAfflictionOverlayAlphaMultiplier { get; private set; }
|
||||
|
||||
[Serialize(1.0f, false)]
|
||||
[Serialize(1.0f, IsPropertySaveable.No)]
|
||||
public float MaxAfflictionOverlayAlphaMultiplier { get; private set; }
|
||||
|
||||
[Serialize(1.0f, false)]
|
||||
[Serialize(1.0f, IsPropertySaveable.No)]
|
||||
public float MinBuffMultiplier { get; private set; }
|
||||
|
||||
[Serialize(1.0f, false)]
|
||||
[Serialize(1.0f, IsPropertySaveable.No)]
|
||||
public float MaxBuffMultiplier { get; private set; }
|
||||
|
||||
[Serialize(1.0f, false)]
|
||||
[Serialize(1.0f, IsPropertySaveable.No)]
|
||||
public float MinSpeedMultiplier { get; private set; }
|
||||
|
||||
[Serialize(1.0f, false)]
|
||||
[Serialize(1.0f, IsPropertySaveable.No)]
|
||||
public float MaxSpeedMultiplier { get; private set; }
|
||||
|
||||
[Serialize(1.0f, false)]
|
||||
|
||||
[Serialize(1.0f, IsPropertySaveable.No)]
|
||||
public float MinSkillMultiplier { get; private set; }
|
||||
|
||||
[Serialize(1.0f, false)]
|
||||
[Serialize(1.0f, IsPropertySaveable.No)]
|
||||
public float MaxSkillMultiplier { get; private set; }
|
||||
|
||||
private readonly Identifier[] resistanceFor;
|
||||
public IReadOnlyList<Identifier> ResistanceFor => resistanceFor;
|
||||
|
||||
private readonly string[] resistanceFor;
|
||||
public IEnumerable<string> ResistanceFor
|
||||
{
|
||||
get { return resistanceFor; }
|
||||
}
|
||||
|
||||
[Serialize(0.0f, false)]
|
||||
[Serialize(0.0f, IsPropertySaveable.No)]
|
||||
public float MinResistance { get; private set; }
|
||||
|
||||
[Serialize(0.0f, false)]
|
||||
[Serialize(0.0f, IsPropertySaveable.No)]
|
||||
public float MaxResistance { get; private set; }
|
||||
|
||||
[Serialize("", false)]
|
||||
public string DialogFlag { get; private set; }
|
||||
[Serialize("", IsPropertySaveable.No)]
|
||||
public Identifier DialogFlag { get; private set; }
|
||||
|
||||
[Serialize("", false)]
|
||||
public string Tag { get; private set; }
|
||||
|
||||
[Serialize("0,0,0,0", false)]
|
||||
[Serialize("", IsPropertySaveable.No)]
|
||||
public Identifier Tag { get; private set; }
|
||||
|
||||
[Serialize("0,0,0,0", IsPropertySaveable.No)]
|
||||
public Color MinFaceTint { get; private set; }
|
||||
|
||||
[Serialize("0,0,0,0", false)]
|
||||
[Serialize("0,0,0,0", IsPropertySaveable.No)]
|
||||
public Color MaxFaceTint { get; private set; }
|
||||
|
||||
[Serialize("0,0,0,0", false)]
|
||||
[Serialize("0,0,0,0", IsPropertySaveable.No)]
|
||||
public Color MinBodyTint { get; private set; }
|
||||
|
||||
[Serialize("0,0,0,0", false)]
|
||||
[Serialize("0,0,0,0", IsPropertySaveable.No)]
|
||||
public Color MaxBodyTint { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Prevents AfflictionHusks with the specified identifier(s) from transforming the character into an AI-controlled character
|
||||
/// </summary>
|
||||
public string[] BlockTransformation { get; private set; }
|
||||
public Identifier[] BlockTransformation { get; private set; }
|
||||
|
||||
public readonly Dictionary<StatTypes, (float minValue, float maxValue)> AfflictionStatValues = new Dictionary<StatTypes, (float minValue, float maxValue)>();
|
||||
public readonly HashSet<AbilityFlags> AfflictionAbilityFlags = new HashSet<AbilityFlags>();
|
||||
@@ -248,14 +240,14 @@ namespace Barotrauma
|
||||
//statuseffects applied on the character when the affliction is active
|
||||
public readonly List<StatusEffect> StatusEffects = new List<StatusEffect>();
|
||||
|
||||
public Effect(XElement element, string parentDebugName)
|
||||
public Effect(ContentXElement element, string parentDebugName)
|
||||
{
|
||||
SerializableProperty.DeserializeProperties(this, element);
|
||||
|
||||
resistanceFor = element.GetAttributeStringArray("resistancefor", new string[0], convertToLowerInvariant: true);
|
||||
BlockTransformation = element.GetAttributeStringArray("blocktransformation", new string[0], convertToLowerInvariant: true);
|
||||
resistanceFor = element.GetAttributeIdentifierArray("resistancefor", Array.Empty<Identifier>());
|
||||
BlockTransformation = element.GetAttributeIdentifierArray("blocktransformation", Array.Empty<Identifier>());
|
||||
|
||||
foreach (XElement subElement in element.Elements())
|
||||
foreach (var subElement in element.Elements())
|
||||
{
|
||||
switch (subElement.Name.ToString().ToLowerInvariant())
|
||||
{
|
||||
@@ -288,14 +280,14 @@ namespace Barotrauma
|
||||
public readonly List<StatusEffect> StatusEffects = new List<StatusEffect>();
|
||||
public readonly float MinInterval, MaxInterval;
|
||||
|
||||
public PeriodicEffect(XElement element, string parentDebugName)
|
||||
public PeriodicEffect(ContentXElement element, string parentDebugName)
|
||||
{
|
||||
foreach (XElement subElement in element.Elements())
|
||||
foreach (var subElement in element.Elements())
|
||||
{
|
||||
StatusEffects.Add(StatusEffect.Load(subElement, parentDebugName));
|
||||
}
|
||||
|
||||
if (element.Attribute("interval") != null)
|
||||
if (element.GetAttribute("interval") != null)
|
||||
{
|
||||
MinInterval = MaxInterval = Math.Max(element.GetAttributeFloat("interval", 1.0f), 1.0f);
|
||||
}
|
||||
@@ -307,48 +299,28 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
public static AfflictionPrefab InternalDamage;
|
||||
public static AfflictionPrefab ImpactDamage;
|
||||
public static AfflictionPrefab Bleeding;
|
||||
public static AfflictionPrefab Burn;
|
||||
public static AfflictionPrefab OxygenLow;
|
||||
public static AfflictionPrefab Bloodloss;
|
||||
public static AfflictionPrefab Pressure;
|
||||
public static AfflictionPrefab Stun;
|
||||
public static AfflictionPrefab RadiationSickness;
|
||||
public static AfflictionPrefab InternalDamage => Prefabs["internaldamage"];
|
||||
public static AfflictionPrefab ImpactDamage => Prefabs["blunttrauma"];
|
||||
public static AfflictionPrefab Bleeding => Prefabs["bleeding"];
|
||||
public static AfflictionPrefab Burn => Prefabs["burn"];
|
||||
public static AfflictionPrefab OxygenLow => Prefabs["oxygenlow"];
|
||||
public static AfflictionPrefab Bloodloss => Prefabs["bloodloss"];
|
||||
public static AfflictionPrefab Pressure => Prefabs["pressure"];
|
||||
public static AfflictionPrefab Stun => Prefabs["stun"];
|
||||
public static AfflictionPrefab RadiationSickness => Prefabs["radiationsickness"];
|
||||
|
||||
public static readonly PrefabCollection<AfflictionPrefab> Prefabs = new PrefabCollection<AfflictionPrefab>();
|
||||
|
||||
private bool disposed = false;
|
||||
public void Dispose()
|
||||
{
|
||||
if (disposed) { return; }
|
||||
disposed = true;
|
||||
Prefabs.Remove(this);
|
||||
}
|
||||
public override void Dispose() { }
|
||||
|
||||
public static IEnumerable<AfflictionPrefab> List
|
||||
{
|
||||
get
|
||||
{
|
||||
foreach (var prefab in Prefabs)
|
||||
{
|
||||
yield return prefab;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string FilePath { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Unique identifier that's generated by hashing the prefab's string identifier.
|
||||
/// Used to reduce the amount of bytes needed to write affliction data into network messages in multiplayer.
|
||||
/// </summary>
|
||||
public uint UIntIdentifier { get; set; }
|
||||
public static IEnumerable<AfflictionPrefab> List => Prefabs;
|
||||
|
||||
// Arbitrary string that is used to identify the type of the affliction.
|
||||
public readonly string AfflictionType;
|
||||
public readonly Identifier AfflictionType;
|
||||
|
||||
private readonly ContentXElement configElement;
|
||||
|
||||
//Does the affliction affect a specific limb or the whole character
|
||||
public readonly bool LimbSpecific;
|
||||
|
||||
@@ -356,18 +328,14 @@ namespace Barotrauma
|
||||
//(e.g. mental health problems on head, lack of oxygen on torso...)
|
||||
public readonly LimbType IndicatorLimb;
|
||||
|
||||
public string Identifier { get; private set; }
|
||||
public string OriginalName { get { return Identifier; } }
|
||||
public ContentPackage ContentPackage { get; private set; }
|
||||
|
||||
public readonly string Name, Description;
|
||||
public readonly string TranslationOverride;
|
||||
public readonly LocalizedString Name, Description;
|
||||
public readonly Identifier TranslationIdentifier;
|
||||
public readonly bool IsBuff;
|
||||
public readonly bool HealableInMedicalClinic;
|
||||
public readonly float HealCostMultiplier;
|
||||
public readonly int BaseHealCost;
|
||||
|
||||
public readonly string CauseOfDeathDescription, SelfCauseOfDeathDescription;
|
||||
public readonly LocalizedString CauseOfDeathDescription, SelfCauseOfDeathDescription;
|
||||
|
||||
//how high the strength has to be for the affliction to take affect
|
||||
public readonly float ActivationThreshold = 0.0f;
|
||||
@@ -392,7 +360,7 @@ namespace Barotrauma
|
||||
public float DamageOverlayAlpha;
|
||||
|
||||
//steam achievement given when the affliction is removed from the controlled character
|
||||
public readonly string AchievementOnRemoved;
|
||||
public readonly Identifier AchievementOnRemoved;
|
||||
|
||||
public readonly Sprite Icon;
|
||||
public readonly Color[] IconColors;
|
||||
@@ -407,11 +375,9 @@ namespace Barotrauma
|
||||
|
||||
public IList<PeriodicEffect> PeriodicEffects => periodicEffects;
|
||||
|
||||
private readonly string typeName;
|
||||
|
||||
private readonly ConstructorInfo constructor;
|
||||
|
||||
public IEnumerable<KeyValuePair<string, float>> TreatmentSuitability
|
||||
public IEnumerable<KeyValuePair<Identifier, float>> TreatmentSuitability
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -420,255 +386,32 @@ namespace Barotrauma
|
||||
float suitability = Math.Max(itemPrefab.GetTreatmentSuitability(Identifier), itemPrefab.GetTreatmentSuitability(AfflictionType));
|
||||
if (suitability > 0.0f)
|
||||
{
|
||||
yield return new KeyValuePair<string, float>(itemPrefab.Identifier, suitability);
|
||||
yield return new KeyValuePair<Identifier, float>(itemPrefab.Identifier, suitability);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void LoadAll(IEnumerable<ContentFile> files)
|
||||
public AfflictionPrefab(ContentXElement element, AfflictionsFile file, Type type) : base(file, element.GetAttributeIdentifier("identifier", ""))
|
||||
{
|
||||
CPRSettings.Unload();
|
||||
InternalDamage = null;
|
||||
ImpactDamage = null;
|
||||
Bleeding = null;
|
||||
Burn = null;
|
||||
OxygenLow = null;
|
||||
Bloodloss = null;
|
||||
Pressure = null;
|
||||
Stun = null;
|
||||
RadiationSickness = null;
|
||||
#if CLIENT
|
||||
CharacterHealth.DamageOverlay?.Remove();
|
||||
CharacterHealth.DamageOverlay = null;
|
||||
CharacterHealth.DamageOverlayFile = string.Empty;
|
||||
#endif
|
||||
var prevPrefabs = Prefabs.AllPrefabs.SelectMany(kvp => kvp.Value).ToList();
|
||||
foreach (var prefab in prevPrefabs)
|
||||
{
|
||||
prefab?.Dispose();
|
||||
}
|
||||
System.Diagnostics.Debug.Assert(Prefabs.Count() == 0, "All previous AfflictionPrefabs were not removed in AfflictionPrefab.LoadAll");
|
||||
|
||||
foreach (ContentFile file in files)
|
||||
{
|
||||
LoadFromFile(file);
|
||||
}
|
||||
|
||||
if (InternalDamage == null) { DebugConsole.ThrowError("Affliction \"Internal Damage\" not defined in the affliction prefabs."); }
|
||||
if (Bleeding == null) { DebugConsole.ThrowError("Affliction \"Bleeding\" not defined in the affliction prefabs."); }
|
||||
if (Burn == null) { DebugConsole.ThrowError("Affliction \"Burn\" not defined in the affliction prefabs."); }
|
||||
if (OxygenLow == null) { DebugConsole.ThrowError("Affliction \"OxygenLow\" not defined in the affliction prefabs."); }
|
||||
if (Bloodloss == null) { DebugConsole.ThrowError("Affliction \"Bloodloss\" not defined in the affliction prefabs."); }
|
||||
if (Pressure == null) { DebugConsole.ThrowError("Affliction \"Pressure\" not defined in the affliction prefabs."); }
|
||||
if (Stun == null) { DebugConsole.ThrowError("Affliction \"Stun\" not defined in the affliction prefabs."); }
|
||||
if (RadiationSickness == null) { DebugConsole.ThrowError("Affliction \"RadiationSickness\" not defined in the affliction prefabs."); }
|
||||
}
|
||||
|
||||
public static void LoadFromFile(ContentFile file)
|
||||
{
|
||||
XDocument doc = XMLExtensions.TryLoadXml(file.Path);
|
||||
if (doc == null) { return; }
|
||||
var mainElement = doc.Root.IsOverride() ? doc.Root.FirstElement() : doc.Root;
|
||||
if (doc.Root.IsOverride())
|
||||
{
|
||||
DebugConsole.ThrowError("Cannot override all afflictions, because many of them are required by the main game! Please try overriding them one by one.");
|
||||
}
|
||||
|
||||
List<(AfflictionPrefab prefab, XElement element)> loadedAfflictions = new List<(AfflictionPrefab prefab, XElement element)>();
|
||||
|
||||
foreach (XElement element in mainElement.Elements())
|
||||
{
|
||||
bool isOverride = element.IsOverride();
|
||||
XElement sourceElement = isOverride ? element.FirstElement() : element;
|
||||
string elementName = sourceElement.Name.ToString().ToLowerInvariant();
|
||||
string identifier = sourceElement.GetAttributeString("identifier", null);
|
||||
if (!elementName.Equals("cprsettings", StringComparison.OrdinalIgnoreCase) &&
|
||||
!elementName.Equals("damageoverlay", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(identifier))
|
||||
{
|
||||
DebugConsole.ThrowError($"No identifier defined for the affliction '{elementName}' in file '{file.Path}'");
|
||||
continue;
|
||||
}
|
||||
if (Prefabs.ContainsKey(identifier))
|
||||
{
|
||||
if (isOverride)
|
||||
{
|
||||
DebugConsole.NewMessage($"Overriding an affliction or a buff with the identifier '{identifier}' using the file '{file.Path}'", Color.Yellow);
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugConsole.ThrowError($"Duplicate affliction: '{identifier}' defined in {elementName} of '{file.Path}'");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
string type = sourceElement.GetAttributeString("type", "");
|
||||
switch (sourceElement.Name.ToString().ToLowerInvariant())
|
||||
{
|
||||
case "cprsettings":
|
||||
type = "cprsettings";
|
||||
break;
|
||||
case "damageoverlay":
|
||||
type = "damageoverlay";
|
||||
break;
|
||||
}
|
||||
|
||||
AfflictionPrefab prefab = null;
|
||||
switch (type)
|
||||
{
|
||||
case "damageoverlay":
|
||||
#if CLIENT
|
||||
if (CharacterHealth.DamageOverlay != null)
|
||||
{
|
||||
if (isOverride)
|
||||
{
|
||||
DebugConsole.NewMessage($"Overriding damage overlay with '{file.Path}'", Color.Yellow);
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugConsole.ThrowError($"Error in '{file.Path}': damage overlay already loaded. Add <override></override> tags as the parent of the custom damage overlay sprite to allow overriding the vanilla one.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
CharacterHealth.DamageOverlay?.Remove();
|
||||
CharacterHealth.DamageOverlay = new Sprite(element);
|
||||
CharacterHealth.DamageOverlayFile = file.Path;
|
||||
#endif
|
||||
break;
|
||||
case "bleeding":
|
||||
prefab = new AfflictionPrefab(sourceElement, file.Path, typeof(AfflictionBleeding));
|
||||
break;
|
||||
case "huskinfection":
|
||||
case "alieninfection":
|
||||
prefab = new AfflictionPrefabHusk(sourceElement, file.Path, typeof(AfflictionHusk));
|
||||
break;
|
||||
case "cprsettings":
|
||||
if (CPRSettings.IsLoaded)
|
||||
{
|
||||
if (isOverride)
|
||||
{
|
||||
DebugConsole.NewMessage($"Overriding the CPR settings with '{file.Path}'", Color.Yellow);
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugConsole.ThrowError($"Error in '{file.Path}': CPR settings already loaded. Add <override></override> tags as the parent of the custom CPRSettings to allow overriding the vanilla values.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
CPRSettings.Load(sourceElement, file.Path);
|
||||
break;
|
||||
case "damage":
|
||||
case "burn":
|
||||
case "oxygenlow":
|
||||
case "bloodloss":
|
||||
case "stun":
|
||||
case "pressure":
|
||||
case "internaldamage":
|
||||
prefab = new AfflictionPrefab(sourceElement, file.Path, typeof(Affliction))
|
||||
{
|
||||
ContentPackage = file.ContentPackage
|
||||
};
|
||||
break;
|
||||
default:
|
||||
prefab = new AfflictionPrefab(sourceElement, file.Path)
|
||||
{
|
||||
ContentPackage = file.ContentPackage
|
||||
};
|
||||
break;
|
||||
}
|
||||
switch (identifier)
|
||||
{
|
||||
case "internaldamage":
|
||||
InternalDamage = prefab;
|
||||
break;
|
||||
case "blunttrauma":
|
||||
ImpactDamage = prefab;
|
||||
break;
|
||||
case "bleeding":
|
||||
Bleeding = prefab;
|
||||
break;
|
||||
case "burn":
|
||||
Burn = prefab;
|
||||
break;
|
||||
case "oxygenlow":
|
||||
OxygenLow = prefab;
|
||||
break;
|
||||
case "bloodloss":
|
||||
Bloodloss = prefab;
|
||||
break;
|
||||
case "pressure":
|
||||
Pressure = prefab;
|
||||
break;
|
||||
case "stun":
|
||||
Stun = prefab;
|
||||
break;
|
||||
case "radiationsickness":
|
||||
RadiationSickness = prefab;
|
||||
break;
|
||||
}
|
||||
if (ImpactDamage == null) { ImpactDamage = InternalDamage; }
|
||||
|
||||
if (prefab != null)
|
||||
{
|
||||
loadedAfflictions.Add((prefab, sourceElement));
|
||||
Prefabs.Add(prefab, isOverride);
|
||||
prefab.CalculatePrefabUIntIdentifier(Prefabs);
|
||||
}
|
||||
}
|
||||
|
||||
//load the effects after all the afflictions in the file have been instantiated
|
||||
//otherwise afflictions can't inflict other afflictions that are defined at a later point in the file
|
||||
foreach ((AfflictionPrefab prefab, XElement element) in loadedAfflictions)
|
||||
{
|
||||
prefab.LoadEffects(element);
|
||||
}
|
||||
}
|
||||
|
||||
public static void RemoveByFile(string filePath)
|
||||
{
|
||||
if (CPRSettings.FilePath == filePath) { CPRSettings.Unload(); }
|
||||
#if CLIENT
|
||||
if (CharacterHealth.DamageOverlayFile == filePath)
|
||||
{
|
||||
CharacterHealth.DamageOverlay?.Remove();
|
||||
CharacterHealth.DamageOverlay = null;
|
||||
}
|
||||
#endif
|
||||
|
||||
Prefabs.RemoveByFile(filePath);
|
||||
}
|
||||
|
||||
public AfflictionPrefab(XElement element, string filePath, Type type = null)
|
||||
{
|
||||
FilePath = filePath;
|
||||
|
||||
typeName = type == null ? element.Name.ToString() : type.Name;
|
||||
if (typeName == "InternalDamage" && type == null)
|
||||
{
|
||||
type = typeof(Affliction);
|
||||
}
|
||||
|
||||
Identifier = element.GetAttributeString("identifier", "");
|
||||
|
||||
AfflictionType = element.GetAttributeString("type", "");
|
||||
TranslationOverride = element.GetAttributeString("translationoverride", null);
|
||||
string translationId = TranslationOverride ?? Identifier;
|
||||
Name = TextManager.Get("AfflictionName." + translationId, true) ?? element.GetAttributeString("name", "");
|
||||
Description = TextManager.Get("AfflictionDescription." + translationId, true) ?? element.GetAttributeString("description", "");
|
||||
configElement = element;
|
||||
|
||||
AfflictionType = element.GetAttributeIdentifier("type", "");
|
||||
TranslationIdentifier = element.GetAttributeIdentifier("translationoverride", Identifier);
|
||||
Name = TextManager.Get($"AfflictionName.{TranslationIdentifier}").Fallback(element.GetAttributeString("name", ""));
|
||||
Description = TextManager.Get($"AfflictionDescription.{TranslationIdentifier}").Fallback(element.GetAttributeString("description", ""));
|
||||
IsBuff = element.GetAttributeBool("isbuff", false);
|
||||
|
||||
HealableInMedicalClinic = element.GetAttributeBool("healableinmedicalclinic",
|
||||
!IsBuff &&
|
||||
!AfflictionType.Equals("geneticmaterialbuff", StringComparison.OrdinalIgnoreCase) &&
|
||||
!AfflictionType.Equals("geneticmaterialdebuff", StringComparison.OrdinalIgnoreCase));
|
||||
AfflictionType != "geneticmaterialbuff" &&
|
||||
AfflictionType != "geneticmaterialdebuff");
|
||||
HealCostMultiplier = element.GetAttributeFloat(nameof(HealCostMultiplier).ToLowerInvariant(), 1f);
|
||||
BaseHealCost = element.GetAttributeInt(nameof(BaseHealCost).ToLowerInvariant(), 0);
|
||||
|
||||
if (element.Attribute("nameidentifier") != null)
|
||||
if (element.GetAttribute("nameidentifier") != null)
|
||||
{
|
||||
Name = TextManager.Get(element.GetAttributeString("nameidentifier", string.Empty), returnNull: true) ?? Name;
|
||||
Name = TextManager.Get(element.GetAttributeString("nameidentifier", string.Empty)).Fallback(Name);
|
||||
}
|
||||
|
||||
LimbSpecific = element.GetAttributeBool("limbspecific", false);
|
||||
@@ -687,7 +430,8 @@ namespace Barotrauma
|
||||
MaxStrength = element.GetAttributeFloat("maxstrength", 100.0f);
|
||||
GrainBurst = element.GetAttributeFloat(nameof(GrainBurst).ToLowerInvariant(), 0.0f);
|
||||
|
||||
ShowInHealthScannerThreshold = element.GetAttributeFloat("showinhealthscannerthreshold", Math.Max(ActivationThreshold, AfflictionType == "talentbuff" ? float.MaxValue : 0.05f));
|
||||
ShowInHealthScannerThreshold = element.GetAttributeFloat("showinhealthscannerthreshold",
|
||||
Math.Max(ActivationThreshold, AfflictionType == "talentbuff" ? float.MaxValue : ShowIconToOthersThreshold));
|
||||
TreatmentThreshold = element.GetAttributeFloat("treatmentthreshold", Math.Max(ActivationThreshold, 5.0f));
|
||||
|
||||
DamageOverlayAlpha = element.GetAttributeFloat("damageoverlayalpha", 0.0f);
|
||||
@@ -695,14 +439,14 @@ namespace Barotrauma
|
||||
|
||||
KarmaChangeOnApplied = element.GetAttributeFloat("karmachangeonapplied", 0.0f);
|
||||
|
||||
CauseOfDeathDescription = TextManager.Get("AfflictionCauseOfDeath." + translationId, true) ?? element.GetAttributeString("causeofdeathdescription", "");
|
||||
SelfCauseOfDeathDescription = TextManager.Get("AfflictionCauseOfDeathSelf." + translationId, true) ?? element.GetAttributeString("selfcauseofdeathdescription", "");
|
||||
CauseOfDeathDescription = TextManager.Get($"AfflictionCauseOfDeath.{TranslationIdentifier}").Fallback(element.GetAttributeString("causeofdeathdescription", ""));
|
||||
SelfCauseOfDeathDescription = TextManager.Get($"AfflictionCauseOfDeathSelf.{TranslationIdentifier}").Fallback(element.GetAttributeString("selfcauseofdeathdescription", ""));
|
||||
|
||||
IconColors = element.GetAttributeColorArray("iconcolors", null);
|
||||
AfflictionOverlayAlphaIsLinear = element.GetAttributeBool("afflictionoverlayalphaislinear", false);
|
||||
AchievementOnRemoved = element.GetAttributeString("achievementonremoved", "");
|
||||
AchievementOnRemoved = element.GetAttributeIdentifier("achievementonremoved", "");
|
||||
|
||||
foreach (XElement subElement in element.Elements())
|
||||
foreach (var subElement in element.Elements())
|
||||
{
|
||||
switch (subElement.Name.ToString().ToLowerInvariant())
|
||||
{
|
||||
@@ -724,43 +468,42 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (type == null)
|
||||
{
|
||||
type = Type.GetType("Barotrauma." + typeName, true, true);
|
||||
if (type == null)
|
||||
{
|
||||
DebugConsole.ThrowError("Could not find an affliction class of the type \"" + typeName + "\".");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
DebugConsole.ThrowError("Could not find an affliction class of the type \"" + typeName + "\".");
|
||||
type = typeof(Affliction);
|
||||
}
|
||||
|
||||
constructor = type.GetConstructor(new[] { typeof(AfflictionPrefab), typeof(float) });
|
||||
}
|
||||
|
||||
private void LoadEffects(XElement element)
|
||||
public static void LoadAllEffects()
|
||||
{
|
||||
foreach (XElement subElement in element.Elements())
|
||||
Prefabs.ForEach(p => p.LoadEffects());
|
||||
}
|
||||
|
||||
public static void ClearAllEffects()
|
||||
{
|
||||
Prefabs.ForEach(p => p.ClearEffects());
|
||||
}
|
||||
|
||||
public void LoadEffects()
|
||||
{
|
||||
ClearEffects();
|
||||
foreach (var subElement in configElement.Elements())
|
||||
{
|
||||
switch (subElement.Name.ToString().ToLowerInvariant())
|
||||
{
|
||||
case "effect":
|
||||
effects.Add(new Effect(subElement, Name));
|
||||
effects.Add(new Effect(subElement, Name.Value));
|
||||
break;
|
||||
case "periodiceffect":
|
||||
periodicEffects.Add(new PeriodicEffect(subElement, Name));
|
||||
periodicEffects.Add(new PeriodicEffect(subElement, Name.Value));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearEffects()
|
||||
{
|
||||
effects.Clear();
|
||||
periodicEffects.Clear();
|
||||
}
|
||||
|
||||
#if CLIENT
|
||||
public void ReloadSoundsIfNeeded()
|
||||
{
|
||||
@@ -770,7 +513,7 @@ namespace Barotrauma
|
||||
{
|
||||
foreach (var sound in statusEffect.Sounds)
|
||||
{
|
||||
if (sound.Sound == null) { Submarine.ReloadRoundSound(sound); }
|
||||
if (sound.Sound == null) { RoundSound.Reload(sound); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -780,7 +523,7 @@ namespace Barotrauma
|
||||
{
|
||||
foreach (var sound in statusEffect.Sounds)
|
||||
{
|
||||
if (sound.Sound == null) { Submarine.ReloadRoundSound(sound); }
|
||||
if (sound.Sound == null) { RoundSound.Reload(sound); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -789,7 +532,7 @@ namespace Barotrauma
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "AfflictionPrefab (" + Name + ")";
|
||||
return $"AfflictionPrefab ({Name})";
|
||||
}
|
||||
|
||||
public Affliction Instantiate(float strength, Character source = null)
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ namespace Barotrauma
|
||||
invertControlsToggleTimer = 5.0f;
|
||||
if (Rand.Range(0.0f, 1.0f) < 0.5f)
|
||||
{
|
||||
characterHealth.ReduceAffliction(null, "invertcontrols", 100);
|
||||
characterHealth.ReduceAfflictionOnAllLimbs("invertcontrols".ToIdentifier(), 100);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -20,23 +20,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())
|
||||
{
|
||||
@@ -48,22 +48,26 @@ namespace Barotrauma
|
||||
HighlightSprite = new Sprite(subElement);
|
||||
break;
|
||||
case "vitalitymultiplier":
|
||||
if (subElement.Attribute("name") != null)
|
||||
if (subElement.GetAttribute("name") != null)
|
||||
{
|
||||
DebugConsole.ThrowError("Error in character health config (" + characterHealth.Character.Name + ") - define vitality multipliers using affliction identifiers or types instead of names.");
|
||||
continue;
|
||||
}
|
||||
|
||||
string afflictionIdentifier = subElement.GetAttributeString("identifier", "");
|
||||
string afflictionType = subElement.GetAttributeString("type", "");
|
||||
float multiplier = subElement.GetAttributeFloat("multiplier", 1.0f);
|
||||
if (!string.IsNullOrEmpty(afflictionIdentifier))
|
||||
var vitalityMultipliers = subElement.GetAttributeIdentifierArray("identifier", null) ?? subElement.GetAttributeIdentifierArray("identifiers", null);
|
||||
if (vitalityMultipliers != null)
|
||||
{
|
||||
VitalityMultipliers.Add(afflictionIdentifier.ToLowerInvariant(), multiplier);
|
||||
float multiplier = subElement.GetAttributeFloat("multiplier", 1.0f);
|
||||
vitalityMultipliers.ForEach(i => VitalityMultipliers.Add(i, multiplier));
|
||||
}
|
||||
else
|
||||
var vitalityTypeMultipliers = subElement.GetAttributeIdentifierArray("type", null) ?? subElement.GetAttributeIdentifierArray("types", null);
|
||||
if (vitalityTypeMultipliers != null)
|
||||
{
|
||||
VitalityTypeMultipliers.Add(afflictionType.ToLowerInvariant(), multiplier);
|
||||
float multiplier = subElement.GetAttributeFloat("multiplier", 1.0f);
|
||||
vitalityTypeMultipliers.ForEach(i => VitalityTypeMultipliers.Add(i, multiplier));
|
||||
}
|
||||
if (vitalityMultipliers == null && VitalityTypeMultipliers == null)
|
||||
{
|
||||
DebugConsole.ThrowError($"Error in character health config {characterHealth.Character.Name}: affliction identifier(s) or type(s) not defined in the \"VitalityMultiplier\" elements!");
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -220,7 +224,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();
|
||||
@@ -231,7 +235,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));
|
||||
@@ -256,7 +260,7 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
partial void InitProjSpecific(XElement element, Character character);
|
||||
partial void InitProjSpecific(ContentXElement element, Character character);
|
||||
|
||||
public IReadOnlyCollection<Affliction> GetAllAfflictions()
|
||||
{
|
||||
@@ -283,10 +287,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)
|
||||
@@ -411,7 +418,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));
|
||||
}
|
||||
@@ -438,37 +445,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;
|
||||
@@ -640,9 +668,10 @@ namespace Barotrauma
|
||||
if (!DoesBleed && newAffliction is AfflictionBleeding) { return; }
|
||||
if (!Character.NeedsOxygen && newAffliction.Prefab == AfflictionPrefab.OxygenLow) { return; }
|
||||
if (Character.Params.Health.StunImmunity && newAffliction.Prefab.AfflictionType == "stun") { return; }
|
||||
if (Character.Params.Health.PoisonImmunity && newAffliction.Prefab.AfflictionType == "poison") { 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;
|
||||
}
|
||||
@@ -719,48 +748,47 @@ namespace Barotrauma
|
||||
|
||||
StunTimer = Stun > 0 ? StunTimer + deltaTime : 0;
|
||||
|
||||
if (Character.GodMode) { return; }
|
||||
|
||||
afflictionsToRemove.Clear();
|
||||
afflictionsToUpdate.Clear();
|
||||
foreach (KeyValuePair<Affliction, LimbHealth> kvp in afflictions)
|
||||
if (!Character.GodMode)
|
||||
{
|
||||
var affliction = kvp.Key;
|
||||
if (affliction.Strength <= 0.0f)
|
||||
afflictionsToRemove.Clear();
|
||||
afflictionsToUpdate.Clear();
|
||||
foreach (KeyValuePair<Affliction, LimbHealth> kvp in afflictions)
|
||||
{
|
||||
SteamAchievementManager.OnAfflictionRemoved(affliction, Character);
|
||||
if (!irremovableAfflictions.Contains(affliction)) { afflictionsToRemove.Add(affliction); }
|
||||
continue;
|
||||
var affliction = kvp.Key;
|
||||
if (affliction.Strength <= 0.0f)
|
||||
{
|
||||
SteamAchievementManager.OnAfflictionRemoved(affliction, Character);
|
||||
if (!irremovableAfflictions.Contains(affliction)) { afflictionsToRemove.Add(affliction); }
|
||||
continue;
|
||||
}
|
||||
afflictionsToUpdate.Add(kvp);
|
||||
}
|
||||
afflictionsToUpdate.Add(kvp);
|
||||
}
|
||||
foreach (KeyValuePair<Affliction, LimbHealth> kvp in afflictionsToUpdate)
|
||||
{
|
||||
var affliction = kvp.Key;
|
||||
Limb targetLimb = null;
|
||||
if (kvp.Value != null)
|
||||
foreach (KeyValuePair<Affliction, LimbHealth> kvp in afflictionsToUpdate)
|
||||
{
|
||||
int healthIndex = limbHealths.IndexOf(kvp.Value);
|
||||
targetLimb =
|
||||
Character.AnimController.Limbs.LastOrDefault(l => !l.IsSevered && !l.Hidden && l.HealthIndex == healthIndex) ??
|
||||
Character.AnimController.MainLimb;
|
||||
var affliction = kvp.Key;
|
||||
Limb targetLimb = null;
|
||||
if (kvp.Value != null)
|
||||
{
|
||||
int healthIndex = limbHealths.IndexOf(kvp.Value);
|
||||
targetLimb =
|
||||
Character.AnimController.Limbs.LastOrDefault(l => !l.IsSevered && !l.Hidden && l.HealthIndex == healthIndex) ??
|
||||
Character.AnimController.MainLimb;
|
||||
}
|
||||
affliction.Update(this, targetLimb, deltaTime);
|
||||
affliction.DamagePerSecondTimer += deltaTime;
|
||||
if (affliction is AfflictionBleeding bleeding)
|
||||
{
|
||||
UpdateBleedingProjSpecific(bleeding, targetLimb, deltaTime);
|
||||
}
|
||||
Character.StackSpeedMultiplier(affliction.GetSpeedMultiplier());
|
||||
}
|
||||
affliction.Update(this, targetLimb, deltaTime);
|
||||
affliction.DamagePerSecondTimer += deltaTime;
|
||||
if (affliction is AfflictionBleeding bleeding)
|
||||
foreach (var affliction in afflictionsToRemove)
|
||||
{
|
||||
UpdateBleedingProjSpecific(bleeding, targetLimb, deltaTime);
|
||||
}
|
||||
Character.StackSpeedMultiplier(affliction.GetSpeedMultiplier());
|
||||
}
|
||||
|
||||
foreach (var affliction in afflictionsToRemove)
|
||||
{
|
||||
afflictions.Remove(affliction);
|
||||
afflictions.Remove(affliction);
|
||||
}
|
||||
}
|
||||
|
||||
Character.StackSpeedMultiplier(1f + Character.GetStatValue(StatTypes.MovementSpeed));
|
||||
|
||||
if (Character.InWater)
|
||||
{
|
||||
Character.StackSpeedMultiplier(1f + Character.GetStatValue(StatTypes.SwimmingSpeed));
|
||||
@@ -770,13 +798,16 @@ namespace Barotrauma
|
||||
Character.StackSpeedMultiplier(1f + Character.GetStatValue(StatTypes.WalkingSpeed));
|
||||
}
|
||||
|
||||
UpdateLimbAfflictionOverlays();
|
||||
UpdateSkinTint();
|
||||
CalculateVitality();
|
||||
|
||||
if (Vitality <= MinVitality)
|
||||
if (!Character.GodMode)
|
||||
{
|
||||
Kill();
|
||||
UpdateLimbAfflictionOverlays();
|
||||
UpdateSkinTint();
|
||||
CalculateVitality();
|
||||
|
||||
if (Vitality <= MinVitality)
|
||||
{
|
||||
Kill();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -965,7 +996,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
|
||||
@@ -991,7 +1022,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))
|
||||
{
|
||||
@@ -1008,23 +1039,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);
|
||||
}
|
||||
@@ -1048,10 +1079,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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1076,7 +1107,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);
|
||||
@@ -1101,7 +1132,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);
|
||||
@@ -1156,7 +1187,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())
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System;
|
||||
using System.Xml.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
|
||||
namespace Barotrauma
|
||||
@@ -10,23 +11,23 @@ namespace Barotrauma
|
||||
{
|
||||
public string Name => "Damage Modifier";
|
||||
|
||||
public Dictionary<string, SerializableProperty> SerializableProperties { get; private set; }
|
||||
public Dictionary<Identifier, SerializableProperty> SerializableProperties { get; private set; }
|
||||
|
||||
[Serialize(1.0f, false), Editable(DecimalCount = 2)]
|
||||
[Serialize(1.0f, IsPropertySaveable.No), Editable(DecimalCount = 2)]
|
||||
public float DamageMultiplier
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
[Serialize(1.0f, false), Editable(DecimalCount = 2, MinValueFloat = 0, MaxValueFloat = 1)]
|
||||
[Serialize(1.0f, IsPropertySaveable.No), Editable(DecimalCount = 2, MinValueFloat = 0, MaxValueFloat = 1)]
|
||||
public float ProbabilityMultiplier
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
[Serialize("0.0,360", false), Editable]
|
||||
[Serialize("0.0,360", IsPropertySaveable.No), Editable]
|
||||
public Vector2 ArmorSector
|
||||
{
|
||||
get;
|
||||
@@ -35,14 +36,14 @@ namespace Barotrauma
|
||||
|
||||
public Vector2 ArmorSectorInRadians => new Vector2(MathHelper.ToRadians(ArmorSector.X), MathHelper.ToRadians(ArmorSector.Y));
|
||||
|
||||
[Serialize(false, false), Editable]
|
||||
[Serialize(false, IsPropertySaveable.No), Editable]
|
||||
public bool DeflectProjectiles
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
[Serialize("", true), Editable]
|
||||
[Serialize("", IsPropertySaveable.Yes), Editable]
|
||||
public string AfflictionIdentifiers
|
||||
{
|
||||
get
|
||||
@@ -56,7 +57,7 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
[Serialize("", true), Editable]
|
||||
[Serialize("", IsPropertySaveable.Yes), Editable]
|
||||
public string AfflictionTypes
|
||||
{
|
||||
get
|
||||
@@ -72,22 +73,11 @@ namespace Barotrauma
|
||||
|
||||
private string rawAfflictionIdentifierString;
|
||||
private string rawAfflictionTypeString;
|
||||
private string[] parsedAfflictionIdentifiers;
|
||||
private string[] parsedAfflictionTypes;
|
||||
public string[] ParsedAfflictionIdentifiers
|
||||
{
|
||||
get
|
||||
{
|
||||
return parsedAfflictionIdentifiers;
|
||||
}
|
||||
}
|
||||
public string[] ParsedAfflictionTypes
|
||||
{
|
||||
get
|
||||
{
|
||||
return parsedAfflictionTypes;
|
||||
}
|
||||
}
|
||||
private ImmutableArray<Identifier> parsedAfflictionIdentifiers;
|
||||
private ImmutableArray<Identifier> parsedAfflictionTypes;
|
||||
public ref readonly ImmutableArray<Identifier> ParsedAfflictionIdentifiers => ref parsedAfflictionIdentifiers;
|
||||
|
||||
public ref readonly ImmutableArray<Identifier> ParsedAfflictionTypes => ref parsedAfflictionTypes;
|
||||
|
||||
public DamageModifier(XElement element, string parentDebugName)
|
||||
{
|
||||
@@ -102,55 +92,58 @@ namespace Barotrauma
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(rawAfflictionTypeString))
|
||||
{
|
||||
parsedAfflictionTypes = new string[0];
|
||||
parsedAfflictionTypes = Enumerable.Empty<Identifier>().ToImmutableArray();
|
||||
return;
|
||||
}
|
||||
string[] splitValue = rawAfflictionTypeString.Split(',', ',');
|
||||
for (int i = 0; i < splitValue.Length; i++)
|
||||
{
|
||||
splitValue[i] = splitValue[i].ToLowerInvariant().Trim();
|
||||
}
|
||||
parsedAfflictionTypes = splitValue;
|
||||
|
||||
parsedAfflictionTypes = rawAfflictionTypeString.Split(',', ',')
|
||||
.Select(s => s.Trim()).ToIdentifiers().ToImmutableArray();
|
||||
}
|
||||
|
||||
private void ParseAfflictionIdentifiers()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(rawAfflictionIdentifierString))
|
||||
{
|
||||
parsedAfflictionIdentifiers = new string[0];
|
||||
parsedAfflictionIdentifiers = Enumerable.Empty<Identifier>().ToImmutableArray();
|
||||
return;
|
||||
}
|
||||
string[] splitValue = rawAfflictionIdentifierString.Split(',', ',');
|
||||
for (int i = 0; i < splitValue.Length; i++)
|
||||
{
|
||||
splitValue[i] = splitValue[i].ToLowerInvariant().Trim();
|
||||
}
|
||||
parsedAfflictionIdentifiers = splitValue;
|
||||
|
||||
parsedAfflictionIdentifiers = rawAfflictionIdentifierString.Split(',', ',')
|
||||
.Select(s => s.Trim()).ToIdentifiers().ToImmutableArray();
|
||||
}
|
||||
|
||||
public bool MatchesAfflictionIdentifier(string identifier)
|
||||
public bool MatchesAfflictionIdentifier(string identifier) =>
|
||||
MatchesAfflictionIdentifier(identifier.ToIdentifier());
|
||||
|
||||
public bool MatchesAfflictionIdentifier(Identifier identifier)
|
||||
{
|
||||
//if no identifiers have been defined, the damage modifier affects all afflictions
|
||||
if (AfflictionIdentifiers.Length == 0) { return true; }
|
||||
return parsedAfflictionIdentifiers.Any(id => id.Equals(identifier, StringComparison.OrdinalIgnoreCase));
|
||||
return parsedAfflictionIdentifiers.Any(id => id == identifier);
|
||||
}
|
||||
|
||||
public bool MatchesAfflictionType(string type)
|
||||
public bool MatchesAfflictionType(string type) =>
|
||||
MatchesAfflictionType(type.ToIdentifier());
|
||||
|
||||
public bool MatchesAfflictionType(Identifier type)
|
||||
{
|
||||
//if no types have been defined, the damage modifier affects all afflictions
|
||||
if (AfflictionTypes.Length == 0) { return true; }
|
||||
return parsedAfflictionTypes.Any(t => t.Equals(type, StringComparison.OrdinalIgnoreCase));
|
||||
return parsedAfflictionTypes.Any(t => t == type);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the type or the identifier matches the defined types/identifiers.
|
||||
/// </summary>
|
||||
public bool MatchesAffliction(string identifier, string type)
|
||||
public bool MatchesAffliction(string identifier, string type) =>
|
||||
MatchesAffliction(identifier.ToIdentifier(), type.ToIdentifier());
|
||||
|
||||
public bool MatchesAffliction(Identifier identifier, Identifier type)
|
||||
{
|
||||
//if no identifiers or types have been defined, the damage modifier affects all afflictions
|
||||
if (AfflictionIdentifiers.Length == 0 && AfflictionTypes.Length == 0) { return true; }
|
||||
return parsedAfflictionIdentifiers.Any(id => id.Equals(identifier, StringComparison.OrdinalIgnoreCase))
|
||||
|| parsedAfflictionTypes.Any(t => t.Equals(type, StringComparison.OrdinalIgnoreCase));
|
||||
return parsedAfflictionIdentifiers.Any(id => id == identifier)
|
||||
|| parsedAfflictionTypes.Any(t => t == type);
|
||||
}
|
||||
|
||||
public bool MatchesAffliction(Affliction affliction) => MatchesAffliction(affliction.Identifier, affliction.Prefab.AfflictionType);
|
||||
|
||||
Reference in New Issue
Block a user