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;
///
/// true - refresh status effect time, 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();
switch (Type)
{
case StatusEffectMetabolismType.Add:
statusSys.TryAddStatusEffect(args.TargetEntity, EffectProto, TimeSpan.FromSeconds(time), Refresh);
break;
case StatusEffectMetabolismType.Remove:
statusSys.TryAddTime(args.TargetEntity, EffectProto, -TimeSpan.FromSeconds(time));
break;
case StatusEffectMetabolismType.Set:
statusSys.TrySetTime(args.TargetEntity, EffectProto, TimeSpan.FromSeconds(time));
break;
}
}
///
protected override string? ReagentEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys)
=> Loc.GetString(
"reagent-effect-guidebook-status-effect",
("chance", Probability),
("type", Type),
("time", Time),
("key", prototype.Index(EffectProto).Name)
);
}