diff --git a/Content.Server/DoAfter/DoAfter.cs b/Content.Server/DoAfter/DoAfter.cs index 5c847e41b0..dc85e95dca 100644 --- a/Content.Server/DoAfter/DoAfter.cs +++ b/Content.Server/DoAfter/DoAfter.cs @@ -26,8 +26,6 @@ namespace Content.Server.DoAfter public EntityCoordinates TargetGrid { get; } - public bool TookDamage { get; set; } - public DoAfterStatus Status => AsTask.IsCompletedSuccessfully ? AsTask.Result : DoAfterStatus.Running; // NeedHand @@ -62,6 +60,12 @@ namespace Content.Server.DoAfter AsTask = Tcs.Task; } + public void Cancel() + { + if (Status == DoAfterStatus.Running) + Tcs.SetResult(DoAfterStatus.Cancelled); + } + public void Run(float frameTime, IEntityManager entityManager) { switch (Status) @@ -124,11 +128,6 @@ namespace Content.Server.DoAfter return true; } - if (EventArgs.BreakOnDamage && TookDamage) - { - return true; - } - if (EventArgs.ExtraCheck != null && !EventArgs.ExtraCheck.Invoke()) { return true; diff --git a/Content.Server/DoAfter/DoAfterSystem.cs b/Content.Server/DoAfter/DoAfterSystem.cs index ea301b9743..f878adaed6 100644 --- a/Content.Server/DoAfter/DoAfterSystem.cs +++ b/Content.Server/DoAfter/DoAfterSystem.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Content.Shared.Damage; +using Content.Shared.MobState; using JetBrains.Annotations; using Robust.Shared.GameObjects; @@ -19,20 +20,30 @@ namespace Content.Server.DoAfter { base.Initialize(); SubscribeLocalEvent(HandleDamage); + SubscribeLocalEvent(HandleStateChanged); + } + + private void HandleStateChanged(EntityUid uid, DoAfterComponent component, MobStateChangedEvent args) + { + if (!args.CurrentMobState.IsIncapacitated()) + return; + + foreach (var doAfter in component.DoAfters) + { + doAfter.Cancel(); + } } public void HandleDamage(EntityUid _, DoAfterComponent component, DamageChangedEvent args) { - if (component.DoAfters.Count == 0 || !args.InterruptsDoAfters) - { + if (!args.InterruptsDoAfters || !args.DamageIncreased) return; - } foreach (var doAfter in component.DoAfters) { if (doAfter.EventArgs.BreakOnDamage) { - doAfter.TookDamage = true; + doAfter.Cancel(); } } }