Interrupt do-afters when the user gets incapacitated. (#6059)
This commit is contained in:
@@ -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