using Content.Shared.StatusEffectNew; using JetBrains.Annotations; using Robust.Shared.Prototypes; namespace Content.Shared.EntityEffects.Effects.StatusEffects; /// /// Changes status effects on entities: Adds, removes or sets time. /// [UsedImplicitly] public sealed partial class ModifyStatusEffect : EntityEffect { [DataField(required: true)] public EntProtoId EffectProto; /// /// Time for which status effect should be applied. Behaviour changes according to . /// [DataField] public float Time = 2.0f; /// /// Delay before the effect starts. If another effect is added with a shorter delay, it takes precedence. /// [DataField] public float Delay = 0f; /// /// true - refresh status effect time (update to greater value), false - accumulate status effect time. /// [DataField] public bool Refresh = true; /// /// Should this effect add the status effect, remove time from it, or set its cooldown? /// [DataField] public StatusEffectMetabolismType Type = StatusEffectMetabolismType.Add; /// public override void Effect(EntityEffectBaseArgs args) { var statusSys = args.EntityManager.EntitySysManager.GetEntitySystem(); var time = Time; if (args is EntityEffectReagentArgs reagentArgs) time *= reagentArgs.Scale.Float(); var duration = TimeSpan.FromSeconds(time); switch (Type) { case StatusEffectMetabolismType.Add: if (Refresh) statusSys.TryUpdateStatusEffectDuration(args.TargetEntity, EffectProto, duration, Delay > 0 ? TimeSpan.FromSeconds(Delay) : null); else statusSys.TryAddStatusEffectDuration(args.TargetEntity, EffectProto, duration, Delay > 0 ? TimeSpan.FromSeconds(Delay) : null); break; case StatusEffectMetabolismType.Remove: statusSys.TryAddTime(args.TargetEntity, EffectProto, -duration); break; case StatusEffectMetabolismType.Set: statusSys.TrySetStatusEffectDuration(args.TargetEntity, EffectProto, duration, TimeSpan.FromSeconds(Delay)); break; } } /// protected override string? ReagentEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys) => Delay > 0 ? Loc.GetString( "reagent-effect-guidebook-status-effect-delay", ("chance", Probability), ("type", Type), ("time", Time), ("key", prototype.Index(EffectProto).Name), ("delay", Delay)) : Loc.GetString( "reagent-effect-guidebook-status-effect", ("chance", Probability), ("type", Type), ("time", Time), ("key", prototype.Index(EffectProto).Name) ); }