Cache CanMove (#7480)

This commit is contained in:
Leon Friedrich
2022-04-10 16:48:11 +12:00
committed by GitHub
parent 4135d9813b
commit 87eede8785
26 changed files with 218 additions and 109 deletions

View File

@@ -1,3 +1,4 @@
using Content.Shared.ActionBlocker;
using Content.Shared.Damage;
using Content.Shared.DragDrop;
using Content.Shared.Emoting;
@@ -17,6 +18,8 @@ namespace Content.Shared.MobState.EntitySystems
{
public sealed class MobStateSystem : EntitySystem
{
[Dependency] private readonly ActionBlockerSystem _blocker = default!;
public override void Initialize()
{
base.Initialize();
@@ -33,12 +36,17 @@ namespace Content.Shared.MobState.EntitySystems
SubscribeLocalEvent<MobStateComponent, PickupAttemptEvent>(OnPickupAttempt);
SubscribeLocalEvent<MobStateComponent, StartPullAttemptEvent>(OnStartPullAttempt);
SubscribeLocalEvent<MobStateComponent, DamageChangedEvent>(UpdateState);
SubscribeLocalEvent<MobStateComponent, MovementAttemptEvent>(OnMoveAttempt);
SubscribeLocalEvent<MobStateComponent, UpdateCanMoveEvent>(OnMoveAttempt);
SubscribeLocalEvent<MobStateComponent, StandAttemptEvent>(OnStandAttempt);
SubscribeLocalEvent<MobStateChangedEvent>(OnStateChanged);
// Note that there's no check for Down attempts because if a mob's in crit or dead, they can be downed...
}
#region ActionBlocker
private void OnStateChanged(MobStateChangedEvent ev)
{
_blocker.UpdateCanMove(ev.Entity);
}
private void CheckAct(EntityUid uid, MobStateComponent component, CancellableEntityEventArgs args)
{
@@ -118,7 +126,7 @@ namespace Content.Shared.MobState.EntitySystems
component.UpdateState(args.Damageable.TotalDamage);
}
private void OnMoveAttempt(EntityUid uid, MobStateComponent component, MovementAttemptEvent args)
private void OnMoveAttempt(EntityUid uid, MobStateComponent component, UpdateCanMoveEvent args)
{
switch (component.CurrentState)
{