CatStation/Content.Shared/CombatMode/SharedCombatModeSystem.cs
Whatstone a88d2c5164
Cleanup: Resolve remaining PopupSystem warnings in Content.Shared (#44685)
* PopupClient to PopupEntity/Coordinates

* PopupPredictedX to PopupEntity/Cursor/Coordinates

* The rest of the damn owl

* nullability fixes

* Buckle cleanup

* cleanup, address PR comments

* ExecutionSystem: one popup method

* correct my filthy lies

* Apply most of ajcm's suggestions

* return user to SharedItemRecallSystem.cs

* Fix lingering Ensnarable broadcast popups

* targeted drain popups

* fix lingering untargeted Guardian popups

I read the comment on GuardianHostRecall.  Oops.

* target stethoscope popups

* fix the PDA vibration popup

* Fix target for encryption key removal popup

* anomaly scanner: args.User, not uid

* disposal unit comment, bcast pda vibration popup
2026-07-16 21:54:33 +00:00

105 lines
3.4 KiB
C#

using Content.Shared.Actions;
using Content.Shared.Mind;
using Content.Shared.MouseRotator;
using Content.Shared.Movement.Components;
using Content.Shared.NPC.Systems;
using Content.Shared.Popups;
using Robust.Shared.Timing;
namespace Content.Shared.CombatMode;
public abstract partial class SharedCombatModeSystem : EntitySystem
{
[Dependency] protected IGameTiming Timing = default!;
[Dependency] private SharedActionsSystem _actionsSystem = default!;
[Dependency] private SharedPopupSystem _popup = default!;
[Dependency] private SharedMindSystem _mind = default!;
[Dependency] private SharedNPCSystem _npc = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<CombatModeComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<CombatModeComponent, ComponentShutdown>(OnShutdown);
SubscribeLocalEvent<CombatModeComponent, ToggleCombatActionEvent>(OnActionPerform);
}
private void OnMapInit(EntityUid uid, CombatModeComponent component, MapInitEvent args)
{
_actionsSystem.AddAction(uid, ref component.CombatToggleActionEntity, component.CombatToggleAction);
Dirty(uid, component);
}
private void OnShutdown(EntityUid uid, CombatModeComponent component, ComponentShutdown args)
{
_actionsSystem.RemoveAction(uid, component.CombatToggleActionEntity);
SetMouseRotatorComponents(uid, false);
}
private void OnActionPerform(EntityUid uid, CombatModeComponent component, ToggleCombatActionEvent args)
{
if (args.Handled)
return;
args.Handled = true;
SetInCombatMode(uid, !component.IsInCombatMode, component);
var msg = component.IsInCombatMode ? "action-popup-combat-enabled" : "action-popup-combat-disabled";
_popup.PopupEntity(Loc.GetString(msg), args.Performer, args.Performer);
}
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 value, CombatModeComponent? component = null)
{
if (!Resolve(entity, ref component))
return;
if (component.IsInCombatMode == value)
return;
component.IsInCombatMode = value;
Dirty(entity, component);
if (component.CombatToggleActionEntity != null)
_actionsSystem.SetToggled(component.CombatToggleActionEntity, component.IsInCombatMode);
// Change mouse rotator comps if flag is set
if (!component.ToggleMouseRotator || _npc.IsNpc(entity) && !_mind.TryGetMind(entity, out _, out _))
return;
SetMouseRotatorComponents(entity, value);
}
private void SetMouseRotatorComponents(EntityUid uid, bool value)
{
if (value)
{
EnsureComp<MouseRotatorComponent>(uid);
EnsureComp<NoRotateOnMoveComponent>(uid);
}
else
{
RemComp<MouseRotatorComponent>(uid);
RemComp<NoRotateOnMoveComponent>(uid);
}
}
}
public sealed partial class ToggleCombatActionEvent : InstantActionEvent
{
}