Interrupt do-afters when the user gets incapacitated. (#6059)
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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<DoAfterComponent, DamageChangedEvent>(HandleDamage);
|
||||
SubscribeLocalEvent<DoAfterComponent, MobStateChangedEvent>(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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user