Re-add action prototypes (#7508)

Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>
This commit is contained in:
Leon Friedrich
2022-04-14 16:17:34 +12:00
committed by GitHub
parent c30b38a476
commit ba75934512
34 changed files with 291 additions and 189 deletions

View File

@@ -1,10 +1,13 @@
using Content.Shared.Actions;
using Content.Shared.Actions.ActionTypes;
using Robust.Shared.Prototypes;
namespace Content.Shared.CombatMode
{
public abstract class SharedCombatModeSystem : EntitySystem
{
[Dependency] private readonly SharedActionsSystem _actionsSystem = default!;
[Dependency] private readonly IPrototypeManager _protoMan = default!;
public override void Initialize()
{
@@ -20,14 +23,32 @@ namespace Content.Shared.CombatMode
private void OnStartup(EntityUid uid, SharedCombatModeComponent component, ComponentStartup args)
{
_actionsSystem.AddAction(uid, component.CombatToggleAction, null);
_actionsSystem.AddAction(uid, component.DisarmAction, null);
if (component.CombatToggleAction == null
&& _protoMan.TryIndex(component.CombatToggleActionId, out InstantActionPrototype? toggleProto))
{
component.CombatToggleAction = new(toggleProto);
}
if (component.CombatToggleAction != null)
_actionsSystem.AddAction(uid, component.CombatToggleAction, null);
if (component.DisarmAction == null
&& _protoMan.TryIndex(component.DisarmActionId, out EntityTargetActionPrototype? disarmProto))
{
component.DisarmAction = new(disarmProto);
}
if (component.DisarmAction != null)
_actionsSystem.AddAction(uid, component.DisarmAction, null);
}
private void OnShutdown(EntityUid uid, SharedCombatModeComponent component, ComponentShutdown args)
{
_actionsSystem.RemoveAction(uid, component.CombatToggleAction);
_actionsSystem.RemoveAction(uid, component.DisarmAction);
if (component.CombatToggleAction != null)
_actionsSystem.RemoveAction(uid, component.CombatToggleAction);
if (component.DisarmAction != null)
_actionsSystem.RemoveAction(uid, component.DisarmAction);
}
private void OnActionPerform(EntityUid uid, SharedCombatModeComponent component, ToggleCombatActionEvent args)
@@ -52,6 +73,6 @@ namespace Content.Shared.CombatMode
}
}
public sealed class ToggleCombatActionEvent : PerformActionEvent { }
public sealed class DisarmActionEvent : PerformEntityTargetActionEvent { }
public sealed class ToggleCombatActionEvent : InstantActionEvent { }
public sealed class DisarmActionEvent : EntityTargetActionEvent { }
}