Remove combat mode component reference (#15206)
This commit is contained in:
@@ -1,17 +1,20 @@
|
||||
using Content.Shared.Actions;
|
||||
using Content.Shared.Actions.ActionTypes;
|
||||
using Content.Shared.Targeting;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Shared.CombatMode
|
||||
{
|
||||
[NetworkedComponent()]
|
||||
public abstract class SharedCombatModeComponent : Component
|
||||
/// <summary>
|
||||
/// Stores whether an entity is in "combat mode"
|
||||
/// This is used to differentiate between regular item interactions or
|
||||
/// using *everything* as a weapon.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
[Access(typeof(SharedCombatModeSystem))]
|
||||
public sealed class CombatModeComponent : Component
|
||||
{
|
||||
#region Disarm
|
||||
|
||||
@@ -40,7 +43,7 @@ namespace Content.Shared.CombatMode
|
||||
public InstantAction? CombatToggleAction;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public virtual bool IsInCombatMode
|
||||
public bool IsInCombatMode
|
||||
{
|
||||
get => _isInCombatMode;
|
||||
set
|
||||
@@ -55,7 +58,7 @@ namespace Content.Shared.CombatMode
|
||||
}
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public virtual TargetingZone ActiveZone
|
||||
public TargetingZone ActiveZone
|
||||
{
|
||||
get => _activeZone;
|
||||
set
|
||||
@@ -6,6 +6,7 @@ namespace Content.Shared.CombatMode.Pacification
|
||||
public sealed class PacificationSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SharedActionsSystem _actionsSystem = default!;
|
||||
[Dependency] private readonly SharedCombatModeSystem _combatSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -22,13 +23,13 @@ namespace Content.Shared.CombatMode.Pacification
|
||||
|
||||
private void OnStartup(EntityUid uid, PacifiedComponent component, ComponentStartup args)
|
||||
{
|
||||
if (!TryComp<SharedCombatModeComponent>(uid, out var combatMode))
|
||||
if (!TryComp<CombatModeComponent>(uid, out var combatMode))
|
||||
return;
|
||||
|
||||
if (combatMode.CanDisarm != null)
|
||||
combatMode.CanDisarm = false;
|
||||
_combatSystem.SetCanDisarm(uid, false, combatMode);
|
||||
|
||||
combatMode.IsInCombatMode = false;
|
||||
_combatSystem.SetInCombatMode(uid, false, combatMode);
|
||||
|
||||
if (combatMode.CombatToggleAction != null)
|
||||
{
|
||||
@@ -38,11 +39,11 @@ namespace Content.Shared.CombatMode.Pacification
|
||||
|
||||
private void OnShutdown(EntityUid uid, PacifiedComponent component, ComponentShutdown args)
|
||||
{
|
||||
if (!TryComp<SharedCombatModeComponent>(uid, out var combatMode))
|
||||
if (!TryComp<CombatModeComponent>(uid, out var combatMode))
|
||||
return;
|
||||
|
||||
if (combatMode.CanDisarm != null)
|
||||
combatMode.CanDisarm = true;
|
||||
_combatSystem.SetCanDisarm(uid, true, combatMode);
|
||||
|
||||
if (combatMode.CombatToggleAction != null)
|
||||
_actionsSystem.SetEnabled(combatMode.CombatToggleAction, true);
|
||||
|
||||
@@ -15,12 +15,12 @@ namespace Content.Shared.CombatMode
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<SharedCombatModeComponent, ComponentStartup>(OnStartup);
|
||||
SubscribeLocalEvent<SharedCombatModeComponent, ComponentShutdown>(OnShutdown);
|
||||
SubscribeLocalEvent<SharedCombatModeComponent, ToggleCombatActionEvent>(OnActionPerform);
|
||||
SubscribeLocalEvent<CombatModeComponent, ComponentStartup>(OnStartup);
|
||||
SubscribeLocalEvent<CombatModeComponent, ComponentShutdown>(OnShutdown);
|
||||
SubscribeLocalEvent<CombatModeComponent, ToggleCombatActionEvent>(OnActionPerform);
|
||||
}
|
||||
|
||||
private void OnStartup(EntityUid uid, SharedCombatModeComponent component, ComponentStartup args)
|
||||
private void OnStartup(EntityUid uid, CombatModeComponent component, ComponentStartup args)
|
||||
{
|
||||
if (component.CombatToggleAction == null
|
||||
&& _protoMan.TryIndex(component.CombatToggleActionId, out InstantActionPrototype? toggleProto))
|
||||
@@ -32,26 +32,52 @@ namespace Content.Shared.CombatMode
|
||||
_actionsSystem.AddAction(uid, component.CombatToggleAction, null);
|
||||
}
|
||||
|
||||
private void OnShutdown(EntityUid uid, SharedCombatModeComponent component, ComponentShutdown args)
|
||||
private void OnShutdown(EntityUid uid, CombatModeComponent component, ComponentShutdown args)
|
||||
{
|
||||
if (component.CombatToggleAction != null)
|
||||
_actionsSystem.RemoveAction(uid, component.CombatToggleAction);
|
||||
}
|
||||
|
||||
public bool IsInCombatMode(EntityUid? entity, SharedCombatModeComponent? component = null)
|
||||
{
|
||||
return entity != null && Resolve(entity.Value, ref component, false) && component.IsInCombatMode;
|
||||
}
|
||||
|
||||
private void OnActionPerform(EntityUid uid, SharedCombatModeComponent component, ToggleCombatActionEvent args)
|
||||
private void OnActionPerform(EntityUid uid, CombatModeComponent component, ToggleCombatActionEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
component.IsInCombatMode = !component.IsInCombatMode;
|
||||
SetInCombatMode(uid, !component.IsInCombatMode, component);
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
public void SetCanDisarm(EntityUid entity, bool canDisarm, CombatModeComponent? component = null)
|
||||
{
|
||||
if (!Resolve(entity, ref component))
|
||||
return;
|
||||
|
||||
component.CanDisarm = canDisarm;
|
||||
}
|
||||
|
||||
public bool IsInCombatMode(EntityUid? entity, CombatModeComponent? component = null)
|
||||
{
|
||||
return entity != null && Resolve(entity.Value, ref component, false) && component.IsInCombatMode;
|
||||
}
|
||||
|
||||
public virtual void SetInCombatMode(EntityUid entity, bool inCombatMode,
|
||||
CombatModeComponent? component = null)
|
||||
{
|
||||
if (!Resolve(entity, ref component))
|
||||
return;
|
||||
|
||||
component.IsInCombatMode = inCombatMode;
|
||||
}
|
||||
|
||||
public virtual void SetActiveZone(EntityUid entity, TargetingZone zone,
|
||||
CombatModeComponent? component = null)
|
||||
{
|
||||
if (!Resolve(entity, ref component))
|
||||
return;
|
||||
|
||||
component.ActiveZone = zone;
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
protected sealed class CombatModeComponentState : ComponentState
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user