GenericStatusEffect.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using Content.Shared.Chemistry.Reagent;
  2. using Content.Shared.EntityEffects;
  3. using Content.Shared.StatusEffect;
  4. using JetBrains.Annotations;
  5. using Robust.Shared.Prototypes;
  6. namespace Content.Server.EntityEffects.Effects.StatusEffects;
  7. /// <summary>
  8. /// Adds a generic status effect to the entity,
  9. /// not worrying about things like how to affect the time it lasts for
  10. /// or component fields or anything. Just adds a component to an entity
  11. /// for a given time. Easy.
  12. /// </summary>
  13. /// <remarks>
  14. /// Can be used for things like adding accents or something. I don't know. Go wild.
  15. /// </remarks>
  16. [UsedImplicitly]
  17. public sealed partial class GenericStatusEffect : EntityEffect
  18. {
  19. [DataField(required: true)]
  20. public string Key = default!;
  21. [DataField]
  22. public string Component = String.Empty;
  23. [DataField]
  24. public float Time = 2.0f;
  25. /// <remarks>
  26. /// true - refresh status effect time, false - accumulate status effect time
  27. /// </remarks>
  28. [DataField]
  29. public bool Refresh = true;
  30. /// <summary>
  31. /// Should this effect add the status effect, remove time from it, or set its cooldown?
  32. /// </summary>
  33. [DataField]
  34. public StatusEffectMetabolismType Type = StatusEffectMetabolismType.Add;
  35. public override void Effect(EntityEffectBaseArgs args)
  36. {
  37. var statusSys = args.EntityManager.EntitySysManager.GetEntitySystem<StatusEffectsSystem>();
  38. var time = Time;
  39. if (args is EntityEffectReagentArgs reagentArgs)
  40. time *= reagentArgs.Scale.Float();
  41. if (Type == StatusEffectMetabolismType.Add && Component != String.Empty)
  42. {
  43. statusSys.TryAddStatusEffect(args.TargetEntity, Key, TimeSpan.FromSeconds(time), Refresh, Component);
  44. }
  45. else if (Type == StatusEffectMetabolismType.Remove)
  46. {
  47. statusSys.TryRemoveTime(args.TargetEntity, Key, TimeSpan.FromSeconds(time));
  48. }
  49. else if (Type == StatusEffectMetabolismType.Set)
  50. {
  51. statusSys.TrySetTime(args.TargetEntity, Key, TimeSpan.FromSeconds(time));
  52. }
  53. }
  54. protected override string? ReagentEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys) => Loc.GetString(
  55. "reagent-effect-guidebook-status-effect",
  56. ("chance", Probability),
  57. ("type", Type),
  58. ("time", Time),
  59. ("key", $"reagent-effect-status-effect-{Key}"));
  60. }
  61. public enum StatusEffectMetabolismType
  62. {
  63. Add,
  64. Remove,
  65. Set
  66. }