StatusEffectsComponent.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using Robust.Shared.GameStates;
  2. using Robust.Shared.Serialization;
  3. namespace Content.Shared.StatusEffect
  4. {
  5. [RegisterComponent]
  6. [NetworkedComponent]
  7. [Access(typeof(StatusEffectsSystem))]
  8. public sealed partial class StatusEffectsComponent : Component
  9. {
  10. [ViewVariables]
  11. public Dictionary<string, StatusEffectState> ActiveEffects = new();
  12. /// <summary>
  13. /// A list of status effect IDs to be allowed
  14. /// </summary>
  15. [DataField("allowed", required: true), Access(typeof(StatusEffectsSystem), Other = AccessPermissions.ReadExecute)]
  16. public List<string> AllowedEffects = default!;
  17. }
  18. [RegisterComponent]
  19. public sealed partial class ActiveStatusEffectsComponent : Component {}
  20. /// <summary>
  21. /// Holds information about an active status effect.
  22. /// </summary>
  23. [Serializable, NetSerializable]
  24. public sealed class StatusEffectState
  25. {
  26. /// <summary>
  27. /// The start and end times of the status effect.
  28. /// </summary>
  29. [ViewVariables]
  30. public (TimeSpan, TimeSpan) Cooldown;
  31. /// <summary>
  32. /// Specifies whether to refresh or accumulate the cooldown of the status effect.
  33. /// true - refresh time, false - accumulate time.
  34. /// </summary>
  35. [ViewVariables]
  36. public bool CooldownRefresh = true;
  37. /// <summary>
  38. /// The name of the relevant component that
  39. /// was added alongside the effect, if any.
  40. /// </summary>
  41. [ViewVariables]
  42. public string? RelevantComponent;
  43. public StatusEffectState((TimeSpan, TimeSpan) cooldown, bool refresh, string? relevantComponent=null)
  44. {
  45. Cooldown = cooldown;
  46. CooldownRefresh = refresh;
  47. RelevantComponent = relevantComponent;
  48. }
  49. public StatusEffectState(StatusEffectState toCopy)
  50. {
  51. Cooldown = (toCopy.Cooldown.Item1, toCopy.Cooldown.Item2);
  52. CooldownRefresh = toCopy.CooldownRefresh;
  53. RelevantComponent = toCopy.RelevantComponent;
  54. }
  55. }
  56. [Serializable, NetSerializable]
  57. public sealed class StatusEffectsComponentState : ComponentState
  58. {
  59. public Dictionary<string, StatusEffectState> ActiveEffects;
  60. public List<string> AllowedEffects;
  61. public StatusEffectsComponentState(Dictionary<string, StatusEffectState> activeEffects, List<string> allowedEffects)
  62. {
  63. ActiveEffects = activeEffects;
  64. AllowedEffects = allowedEffects;
  65. }
  66. }
  67. }