Interrupt do-afters when the user gets incapacitated. (#6059)

This commit is contained in:
Leon Friedrich
2022-01-07 19:07:06 +13:00
committed by GitHub
parent 5d1c6a1867
commit 106f176d13
2 changed files with 21 additions and 11 deletions

View File

@@ -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();
}
}
}