diff --git a/Content.Server/GameObjects/Components/Damage/DamageableComponent.cs b/Content.Server/GameObjects/Components/Damage/DamageableComponent.cs index b61f7d6608..dd378cfdee 100644 --- a/Content.Server/GameObjects/Components/Damage/DamageableComponent.cs +++ b/Content.Server/GameObjects/Components/Damage/DamageableComponent.cs @@ -34,7 +34,8 @@ namespace Content.Server.GameObjects public IReadOnlyDictionary CurrentDamage => _currentDamage; private Dictionary _currentDamage = new Dictionary(); - Dictionary> Thresholds = new Dictionary>(); + [ViewVariables] + public Dictionary> Thresholds = new Dictionary>(); public event EventHandler DamageThresholdPassed; public event EventHandler Damaged; @@ -47,12 +48,7 @@ namespace Content.Server.GameObjects public override void ExposeData(ObjectSerializer serializer) { base.ExposeData(serializer); - - // TODO: Writing. - serializer.DataReadFunction("resistanceset", "honk", name => - { - Resistances = ResistanceSet.GetResistanceSet(name); - }); + serializer.DataField(this, x => Resistances, "resistances", ResistanceSet.DefaultResistanceSet); } public bool IsDead() diff --git a/Content.Server/GameObjects/Components/Damage/ResistanceSet.cs b/Content.Server/GameObjects/Components/Damage/ResistanceSet.cs index 41616c7824..982e614a15 100644 --- a/Content.Server/GameObjects/Components/Damage/ResistanceSet.cs +++ b/Content.Server/GameObjects/Components/Damage/ResistanceSet.cs @@ -1,6 +1,9 @@ using System; using System.Collections.Generic; using Content.Shared.GameObjects; +using Robust.Shared.Interfaces.Serialization; +using Robust.Shared.Serialization; +using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects { @@ -8,49 +11,31 @@ namespace Content.Server.GameObjects /// Resistance set used by damageable objects. /// For each damage type, has a coefficient, damage reduction and "included in total" value. /// - public class ResistanceSet + public class ResistanceSet : IExposeData { - Dictionary _resistances = new Dictionary(); - static Dictionary _resistanceSets = new Dictionary(); + public static ResistanceSet DefaultResistanceSet = new ResistanceSet(); + + [ViewVariables] + private readonly Dictionary _resistances = new Dictionary(); - //TODO: make it load from YAML instead of hardcoded like this public ResistanceSet() { - _resistances.Add(DamageType.Total, new ResistanceSetSettings(1f, 0, true)); - _resistances.Add(DamageType.Acid, new ResistanceSetSettings(1f, 0, true)); - _resistances.Add(DamageType.Brute, new ResistanceSetSettings(1f, 0, true)); - _resistances.Add(DamageType.Heat, new ResistanceSetSettings(1f, 0, true)); - _resistances.Add(DamageType.Cold, new ResistanceSetSettings(1f, 0, true)); - _resistances.Add(DamageType.Toxic, new ResistanceSetSettings(1f, 0, true)); - _resistances.Add(DamageType.Electric, new ResistanceSetSettings(1f, 0, true)); - } - - /// - /// Loads a resistance set with the given name. - /// - /// Name of the resistance set. - /// Resistance set by given name - public static ResistanceSet GetResistanceSet(string setName) - { - ResistanceSet resistanceSet = null; - - if (!_resistanceSets.TryGetValue(setName, out resistanceSet)) + foreach (DamageType damageType in Enum.GetValues(typeof(DamageType))) { - resistanceSet = Load(setName); + _resistances[damageType] = new ResistanceSetSettings(); } - - return resistanceSet; } - static ResistanceSet Load(string setName) + public void ExposeData(ObjectSerializer serializer) { - //TODO: only creates a standard set RN, should be YAMLed - - ResistanceSet resistanceSet = new ResistanceSet(); - - _resistanceSets.Add(setName, resistanceSet); - - return resistanceSet; + foreach (DamageType damageType in Enum.GetValues(typeof(DamageType))) + { + var resistanceName = damageType.ToString().ToLower(); + serializer.DataReadFunction(resistanceName, new ResistanceSetSettings(), resistanceSetting => + { + _resistances[damageType] = resistanceSetting; + }); + } } /// @@ -78,23 +63,23 @@ namespace Content.Server.GameObjects { //Damage that goes straight to total (for whatever reason) never applies twice - return damageType == DamageType.Total ? false : _resistances[damageType].AppliesToTotal; + return damageType != DamageType.Total && _resistances[damageType].AppliesToTotal; } /// /// Settings for a specific damage type in a resistance set. /// - struct ResistanceSetSettings + public class ResistanceSetSettings : IExposeData { - public float Coefficient { get; private set; } - public int DamageReduction { get; private set; } - public bool AppliesToTotal { get; private set; } + public float Coefficient { get; private set; } = 1; + public int DamageReduction { get; private set; } = 0; + public bool AppliesToTotal { get; private set; } = true; - public ResistanceSetSettings(float coefficient, int damageReduction, bool appliesInTotal) + public void ExposeData(ObjectSerializer serializer) { - Coefficient = coefficient; - DamageReduction = damageReduction; - AppliesToTotal = appliesInTotal; + serializer.DataField(this, x => Coefficient, "coefficient", 1); + serializer.DataField(this, x => DamageReduction, "damageReduction", 0); + serializer.DataField(this, x => AppliesToTotal, "appliesToTotal", true); } } } diff --git a/Resources/Prototypes/Entities/Constructible/Walls/walls.yml b/Resources/Prototypes/Entities/Constructible/Walls/walls.yml index accf1fa169..5189ff9e12 100644 --- a/Resources/Prototypes/Entities/Constructible/Walls/walls.yml +++ b/Resources/Prototypes/Entities/Constructible/Walls/walls.yml @@ -1,4 +1,4 @@ -- type: entity +- type: entity id: base_wall name: basewall description: Keeps the air in and the greytide out.