1
0

DamageableComponent.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using Content.Shared.Damage.Prototypes;
  2. using Content.Shared.FixedPoint;
  3. using Content.Shared.Mobs;
  4. using Content.Shared.StatusIcon;
  5. using Robust.Shared.GameStates;
  6. using Robust.Shared.Prototypes;
  7. using Robust.Shared.Serialization;
  8. namespace Content.Shared.Damage
  9. {
  10. /// <summary>
  11. /// Component that allows entities to take damage.
  12. /// </summary>
  13. /// <remarks>
  14. /// The supported damage types are specified using a <see cref="DamageContainerPrototype"/>s. DamageContainers
  15. /// may also have resistances to certain damage types, defined via a <see cref="DamageModifierSetPrototype"/>.
  16. /// </remarks>
  17. [RegisterComponent]
  18. [NetworkedComponent]
  19. [Access(typeof(DamageableSystem), Other = AccessPermissions.ReadExecute)]
  20. public sealed partial class DamageableComponent : Component
  21. {
  22. /// <summary>
  23. /// This <see cref="DamageContainerPrototype"/> specifies what damage types are supported by this component.
  24. /// If null, all damage types will be supported.
  25. /// </summary>
  26. [DataField("damageContainer")]
  27. public ProtoId<DamageContainerPrototype>? DamageContainerID;
  28. /// <summary>
  29. /// This <see cref="DamageModifierSetPrototype"/> will be applied to any damage that is dealt to this container,
  30. /// unless the damage explicitly ignores resistances.
  31. /// </summary>
  32. /// <remarks>
  33. /// Though DamageModifierSets can be deserialized directly, we only want to use the prototype version here
  34. /// to reduce duplication.
  35. /// </remarks>
  36. [DataField("damageModifierSet")]
  37. public ProtoId<DamageModifierSetPrototype>? DamageModifierSetId;
  38. /// <summary>
  39. /// All the damage information is stored in this <see cref="DamageSpecifier"/>.
  40. /// </summary>
  41. /// <remarks>
  42. /// If this data-field is specified, this allows damageable components to be initialized with non-zero damage.
  43. /// </remarks>
  44. [DataField(readOnly: true)] //todo remove this readonly when implementing writing to damagespecifier
  45. public DamageSpecifier Damage = new();
  46. /// <summary>
  47. /// Damage, indexed by <see cref="DamageGroupPrototype"/> ID keys.
  48. /// </summary>
  49. /// <remarks>
  50. /// Groups which have no members that are supported by this component will not be present in this
  51. /// dictionary.
  52. /// </remarks>
  53. [ViewVariables] public Dictionary<string, FixedPoint2> DamagePerGroup = new();
  54. /// <summary>
  55. /// The sum of all damages in the DamageableComponent.
  56. /// </summary>
  57. [ViewVariables]
  58. public FixedPoint2 TotalDamage;
  59. [DataField("radiationDamageTypes")]
  60. public List<ProtoId<DamageTypePrototype>> RadiationDamageTypeIDs = new() { "Radiation" };
  61. /// <summary>
  62. /// Group types that affect the pain overlay.
  63. /// </summary>
  64. /// TODO: Add support for adding damage types specifically rather than whole damage groups
  65. [DataField]
  66. public List<ProtoId<DamageGroupPrototype>> PainDamageGroups = new() { "Brute", "Burn" };
  67. [DataField]
  68. public Dictionary<MobState, ProtoId<HealthIconPrototype>> HealthIcons = new()
  69. {
  70. { MobState.Alive, "HealthIconFine" },
  71. { MobState.Critical, "HealthIconCritical" },
  72. { MobState.Dead, "HealthIconDead" },
  73. };
  74. [DataField]
  75. public ProtoId<HealthIconPrototype> RottingIcon = "HealthIconRotting";
  76. [DataField]
  77. public FixedPoint2? HealthBarThreshold;
  78. }
  79. [Serializable, NetSerializable]
  80. public sealed class DamageableComponentState : ComponentState
  81. {
  82. public readonly Dictionary<string, FixedPoint2> DamageDict;
  83. public readonly string? DamageContainerId;
  84. public readonly string? ModifierSetId;
  85. public readonly FixedPoint2? HealthBarThreshold;
  86. public DamageableComponentState(
  87. Dictionary<string, FixedPoint2> damageDict,
  88. string? damageContainerId,
  89. string? modifierSetId,
  90. FixedPoint2? healthBarThreshold)
  91. {
  92. DamageDict = damageDict;
  93. DamageContainerId = damageContainerId;
  94. ModifierSetId = modifierSetId;
  95. HealthBarThreshold = healthBarThreshold;
  96. }
  97. }
  98. }