using Robust.Shared.Serialization; using Robust.Shared.ViewVariables; using System; using System.Collections.Generic; using System.Linq; namespace Content.Shared.BodySystem { public enum DamageClass { Brute, Burn, Toxin, Airloss } public enum DamageType { Blunt, Piercing, Heat, Disintegration, Cellular, DNA, Airloss } public static class DamageContainerValues { public static readonly Dictionary> DamageClassToType = new Dictionary> { { DamageClass.Brute, new List{ DamageType.Blunt, DamageType.Piercing }}, { DamageClass.Burn, new List{ DamageType.Heat, DamageType.Disintegration }}, { DamageClass.Toxin, new List{ DamageType.Cellular, DamageType.DNA}}, { DamageClass.Airloss, new List{ DamageType.Airloss }} }; public static readonly Dictionary DamageTypeToClass = new Dictionary { { DamageType.Blunt, DamageClass.Brute }, { DamageType.Piercing, DamageClass.Brute }, { DamageType.Heat, DamageClass.Burn }, { DamageType.Disintegration, DamageClass.Burn }, { DamageType.Cellular, DamageClass.Toxin }, { DamageType.DNA, DamageClass.Toxin }, { DamageType.Airloss, DamageClass.Airloss } }; } /// /// Abstract class for all damage container classes. /// [NetSerializable, Serializable] public abstract class AbstractDamageContainer { [ViewVariables] abstract public List SupportedDamageClasses { get; } private Dictionary _damageList = new Dictionary(); [ViewVariables] public Dictionary DamageList => _damageList; /// /// Sum of all damages kept on record. /// [ViewVariables] public int Damage { get { return _damageList.Sum(x => x.Value); } } public AbstractDamageContainer() { foreach(DamageClass damageClass in SupportedDamageClasses){ DamageContainerValues.DamageClassToType.TryGetValue(damageClass, out List childrenDamageTypes); foreach (DamageType damageType in childrenDamageTypes) { _damageList.Add(damageType, 0); } } } /// /// Attempts to grab the damage value for the given DamageType - returns false if the container does not support that type. /// public bool TryGetDamageValue(DamageType type, out int damage) { return _damageList.TryGetValue(type, out damage); } /// /// Attempts to set the damage value for the given DamageType - returns false if the container does not support that type. /// public bool TrySetDamageValue(DamageType type, int target) { DamageContainerValues.DamageTypeToClass.TryGetValue(type, out DamageClass classType); if (SupportedDamageClasses.Contains(classType)) { _damageList[type] = target; return true; } return false; } /// /// Attempts to change the damage value for the given DamageType - returns false if the container does not support that type. /// public bool TryChangeDamageValue(DamageType type, int delta) { DamageContainerValues.DamageTypeToClass.TryGetValue(type, out DamageClass classType); if (SupportedDamageClasses.Contains(classType)) { _damageList[type] = _damageList[type] + delta; return true; } return false; } } }