Fix action state handling bug (#25395)

* Rejig action state handling

* Fix entity arg

* Fix deserialization
This commit is contained in:
Leon Friedrich
2024-02-19 21:08:41 -05:00
committed by GitHub
parent 2548b13abf
commit bd4597c5ca
7 changed files with 103 additions and 52 deletions

View File

@@ -8,7 +8,6 @@ using Content.Shared.Hands;
using Content.Shared.Interaction;
using Content.Shared.Inventory.Events;
using Content.Shared.Mind;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Containers;
using Robust.Shared.GameStates;
@@ -35,9 +34,13 @@ public abstract class SharedActionsSystem : EntitySystem
{
base.Initialize();
SubscribeLocalEvent<InstantActionComponent, MapInitEvent>(OnInit);
SubscribeLocalEvent<EntityTargetActionComponent, MapInitEvent>(OnInit);
SubscribeLocalEvent<WorldTargetActionComponent, MapInitEvent>(OnInit);
SubscribeLocalEvent<InstantActionComponent, MapInitEvent>(OnActionMapInit);
SubscribeLocalEvent<EntityTargetActionComponent, MapInitEvent>(OnActionMapInit);
SubscribeLocalEvent<WorldTargetActionComponent, MapInitEvent>(OnActionMapInit);
SubscribeLocalEvent<InstantActionComponent, ComponentShutdown>(OnActionShutdown);
SubscribeLocalEvent<EntityTargetActionComponent, ComponentShutdown>(OnActionShutdown);
SubscribeLocalEvent<WorldTargetActionComponent, ComponentShutdown>(OnActionShutdown);
SubscribeLocalEvent<ActionsComponent, DidEquipEvent>(OnDidEquip);
SubscribeLocalEvent<ActionsComponent, DidEquipHandEvent>(OnHandEquipped);
@@ -60,10 +63,19 @@ public abstract class SharedActionsSystem : EntitySystem
SubscribeAllEvent<RequestPerformActionEvent>(OnActionRequest);
}
private void OnInit(EntityUid uid, BaseActionComponent component, MapInitEvent args)
private void OnActionMapInit(EntityUid uid, BaseActionComponent component, MapInitEvent args)
{
if (component.Charges != null)
component.MaxCharges = component.Charges.Value;
if (component.Charges == null)
return;
component.MaxCharges ??= component.Charges.Value;
Dirty(uid, component);
}
private void OnActionShutdown(EntityUid uid, BaseActionComponent component, ComponentShutdown args)
{
if (component.AttachedEntity != null && !TerminatingOrDeleted(component.AttachedEntity.Value))
RemoveAction(component.AttachedEntity.Value, uid, action: component);
}
private void OnShutdown(EntityUid uid, ActionsComponent component, ComponentShutdown args)