Refactor actions to be entities with components (#19900)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
using Content.Shared.Actions.ActionTypes;
|
||||
using Content.Shared.Targeting;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Shared.CombatMode
|
||||
@@ -32,11 +32,11 @@ namespace Content.Shared.CombatMode
|
||||
|
||||
#endregion
|
||||
|
||||
[DataField("combatToggleActionId", customTypeSerializer: typeof(PrototypeIdSerializer<InstantActionPrototype>))]
|
||||
public string CombatToggleActionId = "CombatModeToggle";
|
||||
[DataField("combatToggleAction", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
|
||||
public string CombatToggleAction = "ActionCombatModeToggle";
|
||||
|
||||
[DataField("combatToggleAction")]
|
||||
public InstantAction? CombatToggleAction;
|
||||
[DataField("combatToggleActionEntity")]
|
||||
public EntityUid? CombatToggleActionEntity;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("isInCombatMode"), AutoNetworkedField]
|
||||
public bool IsInCombatMode;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using Content.Shared.Actions;
|
||||
using Content.Shared.Alert;
|
||||
using Content.Shared.Interaction.Events;
|
||||
using Content.Shared.Popups;
|
||||
|
||||
namespace Content.Shared.CombatMode.Pacification;
|
||||
|
||||
@@ -33,10 +32,7 @@ public sealed class PacificationSystem : EntitySystem
|
||||
_combatSystem.SetCanDisarm(uid, false, combatMode);
|
||||
|
||||
_combatSystem.SetInCombatMode(uid, false, combatMode);
|
||||
|
||||
if (combatMode.CombatToggleAction != null)
|
||||
_actionsSystem.SetEnabled(combatMode.CombatToggleAction, false);
|
||||
|
||||
_actionsSystem.SetEnabled(combatMode.CombatToggleActionEntity, false);
|
||||
_alertsSystem.ShowAlert(uid, AlertType.Pacified);
|
||||
}
|
||||
|
||||
@@ -48,9 +44,7 @@ public sealed class PacificationSystem : EntitySystem
|
||||
if (combatMode.CanDisarm != null)
|
||||
_combatSystem.SetCanDisarm(uid, true, combatMode);
|
||||
|
||||
if (combatMode.CombatToggleAction != null)
|
||||
_actionsSystem.SetEnabled(combatMode.CombatToggleAction, true);
|
||||
|
||||
_actionsSystem.SetEnabled(combatMode.CombatToggleActionEntity, true);
|
||||
_alertsSystem.ClearAlert(uid, AlertType.Pacified);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
using Content.Shared.Actions;
|
||||
using Content.Shared.Actions.ActionTypes;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Targeting;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Shared.CombatMode;
|
||||
@@ -13,7 +10,6 @@ public abstract class SharedCombatModeSystem : EntitySystem
|
||||
{
|
||||
[Dependency] protected readonly IGameTiming Timing = default!;
|
||||
[Dependency] private readonly INetManager _netMan = default!;
|
||||
[Dependency] private readonly IPrototypeManager _protoMan = default!;
|
||||
[Dependency] private readonly SharedActionsSystem _actionsSystem = default!;
|
||||
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
||||
|
||||
@@ -21,27 +17,19 @@ public abstract class SharedCombatModeSystem : EntitySystem
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<CombatModeComponent, ComponentStartup>(OnStartup);
|
||||
SubscribeLocalEvent<CombatModeComponent, MapInitEvent>(OnStartup);
|
||||
SubscribeLocalEvent<CombatModeComponent, ComponentShutdown>(OnShutdown);
|
||||
SubscribeLocalEvent<CombatModeComponent, ToggleCombatActionEvent>(OnActionPerform);
|
||||
}
|
||||
|
||||
private void OnStartup(EntityUid uid, CombatModeComponent component, ComponentStartup args)
|
||||
private void OnStartup(EntityUid uid, CombatModeComponent component, MapInitEvent args)
|
||||
{
|
||||
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);
|
||||
_actionsSystem.AddAction(uid, ref component.CombatToggleActionEntity, component.CombatToggleAction);
|
||||
}
|
||||
|
||||
private void OnShutdown(EntityUid uid, CombatModeComponent component, ComponentShutdown args)
|
||||
{
|
||||
if (component.CombatToggleAction != null)
|
||||
_actionsSystem.RemoveAction(uid, component.CombatToggleAction);
|
||||
_actionsSystem.RemoveAction(uid, component.CombatToggleActionEntity);
|
||||
}
|
||||
|
||||
private void OnActionPerform(EntityUid uid, CombatModeComponent component, ToggleCombatActionEvent args)
|
||||
@@ -86,8 +74,8 @@ public abstract class SharedCombatModeSystem : EntitySystem
|
||||
component.IsInCombatMode = value;
|
||||
Dirty(entity, component);
|
||||
|
||||
if (component.CombatToggleAction != null)
|
||||
_actionsSystem.SetToggled(component.CombatToggleAction, component.IsInCombatMode);
|
||||
if (component.CombatToggleActionEntity != null)
|
||||
_actionsSystem.SetToggled(component.CombatToggleActionEntity, component.IsInCombatMode);
|
||||
}
|
||||
|
||||
public virtual void SetActiveZone(EntityUid entity, TargetingZone zone,
|
||||
|
||||
Reference in New Issue
Block a user