2022-02-26 18:24:08 +13:00
|
|
|
using Content.Shared.Actions;
|
2022-04-14 16:17:34 +12:00
|
|
|
using Content.Shared.Actions.ActionTypes;
|
2023-04-26 16:04:44 +12:00
|
|
|
using Content.Shared.Popups;
|
2022-09-29 15:51:59 +10:00
|
|
|
using Content.Shared.Targeting;
|
2023-08-15 17:06:45 +12:00
|
|
|
using Robust.Shared.Network;
|
2022-04-14 16:17:34 +12:00
|
|
|
using Robust.Shared.Prototypes;
|
2022-09-29 15:51:59 +10:00
|
|
|
using Robust.Shared.Serialization;
|
2023-04-26 16:04:44 +12:00
|
|
|
using Robust.Shared.Timing;
|
2020-03-25 17:53:50 +01:00
|
|
|
|
2023-05-06 08:06:42 +03:00
|
|
|
namespace Content.Shared.CombatMode;
|
|
|
|
|
|
|
|
|
|
public abstract class SharedCombatModeSystem : EntitySystem
|
2020-03-25 17:53:50 +01:00
|
|
|
{
|
2023-09-03 06:16:34 +10:00
|
|
|
[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!;
|
2022-02-26 18:24:08 +13:00
|
|
|
|
2023-05-06 08:06:42 +03:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
2020-03-25 17:53:50 +01:00
|
|
|
|
2023-05-06 08:06:42 +03:00
|
|
|
SubscribeLocalEvent<CombatModeComponent, ComponentStartup>(OnStartup);
|
|
|
|
|
SubscribeLocalEvent<CombatModeComponent, ComponentShutdown>(OnShutdown);
|
|
|
|
|
SubscribeLocalEvent<CombatModeComponent, ToggleCombatActionEvent>(OnActionPerform);
|
|
|
|
|
}
|
2022-02-26 18:24:08 +13:00
|
|
|
|
2023-05-06 08:06:42 +03:00
|
|
|
private void OnStartup(EntityUid uid, CombatModeComponent component, ComponentStartup args)
|
|
|
|
|
{
|
|
|
|
|
if (component.CombatToggleAction == null
|
|
|
|
|
&& _protoMan.TryIndex(component.CombatToggleActionId, out InstantActionPrototype? toggleProto))
|
2022-02-26 18:24:08 +13:00
|
|
|
{
|
2023-05-06 08:06:42 +03:00
|
|
|
component.CombatToggleAction = new(toggleProto);
|
2022-02-26 18:24:08 +13:00
|
|
|
}
|
|
|
|
|
|
2023-05-06 08:06:42 +03:00
|
|
|
if (component.CombatToggleAction != null)
|
|
|
|
|
_actionsSystem.AddAction(uid, component.CombatToggleAction, null);
|
|
|
|
|
}
|
2022-02-26 18:24:08 +13:00
|
|
|
|
2023-05-06 08:06:42 +03:00
|
|
|
private void OnShutdown(EntityUid uid, CombatModeComponent component, ComponentShutdown args)
|
|
|
|
|
{
|
|
|
|
|
if (component.CombatToggleAction != null)
|
|
|
|
|
_actionsSystem.RemoveAction(uid, component.CombatToggleAction);
|
|
|
|
|
}
|
2023-04-08 13:16:48 -07:00
|
|
|
|
2023-05-06 08:06:42 +03:00
|
|
|
private void OnActionPerform(EntityUid uid, CombatModeComponent component, ToggleCombatActionEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (args.Handled)
|
|
|
|
|
return;
|
2023-04-26 16:04:44 +12:00
|
|
|
|
2023-05-06 08:06:42 +03:00
|
|
|
args.Handled = true;
|
|
|
|
|
SetInCombatMode(uid, !component.IsInCombatMode, component);
|
2023-04-26 16:04:44 +12:00
|
|
|
|
2023-08-15 17:06:45 +12:00
|
|
|
// TODO better handling of predicted pop-ups.
|
|
|
|
|
// This probably breaks if the client has prediction disabled.
|
|
|
|
|
|
2023-09-03 06:16:34 +10:00
|
|
|
if (!_netMan.IsClient || !Timing.IsFirstTimePredicted)
|
2023-05-06 08:06:42 +03:00
|
|
|
return;
|
2023-04-08 13:16:48 -07:00
|
|
|
|
2023-05-06 08:06:42 +03:00
|
|
|
var msg = component.IsInCombatMode ? "action-popup-combat-enabled" : "action-popup-combat-disabled";
|
|
|
|
|
_popup.PopupEntity(Loc.GetString(msg), args.Performer, args.Performer);
|
|
|
|
|
}
|
2023-04-08 13:16:48 -07:00
|
|
|
|
2023-05-06 08:06:42 +03:00
|
|
|
public void SetCanDisarm(EntityUid entity, bool canDisarm, CombatModeComponent? component = null)
|
|
|
|
|
{
|
|
|
|
|
if (!Resolve(entity, ref component))
|
|
|
|
|
return;
|
2023-04-08 13:16:48 -07:00
|
|
|
|
2023-05-06 08:06:42 +03:00
|
|
|
component.CanDisarm = canDisarm;
|
|
|
|
|
}
|
2022-06-01 19:59:58 +10:00
|
|
|
|
2023-05-06 08:06:42 +03:00
|
|
|
public bool IsInCombatMode(EntityUid? entity, CombatModeComponent? component = null)
|
|
|
|
|
{
|
|
|
|
|
return entity != null && Resolve(entity.Value, ref component, false) && component.IsInCombatMode;
|
|
|
|
|
}
|
2022-02-26 18:24:08 +13:00
|
|
|
|
2023-09-03 06:16:34 +10:00
|
|
|
public virtual void SetInCombatMode(EntityUid entity, bool value, CombatModeComponent? component = null)
|
2023-05-06 08:06:42 +03:00
|
|
|
{
|
|
|
|
|
if (!Resolve(entity, ref component))
|
|
|
|
|
return;
|
2023-04-08 13:16:48 -07:00
|
|
|
|
2023-09-03 06:16:34 +10:00
|
|
|
if (component.IsInCombatMode == value)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
component.IsInCombatMode = value;
|
|
|
|
|
Dirty(entity, component);
|
|
|
|
|
|
|
|
|
|
if (component.CombatToggleAction != null)
|
|
|
|
|
_actionsSystem.SetToggled(component.CombatToggleAction, component.IsInCombatMode);
|
2023-05-06 08:06:42 +03:00
|
|
|
}
|
2023-04-08 13:16:48 -07:00
|
|
|
|
2023-05-06 08:06:42 +03:00
|
|
|
public virtual void SetActiveZone(EntityUid entity, TargetingZone zone,
|
|
|
|
|
CombatModeComponent? component = null)
|
|
|
|
|
{
|
|
|
|
|
if (!Resolve(entity, ref component))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
component.ActiveZone = zone;
|
|
|
|
|
}
|
2020-03-25 17:53:50 +01:00
|
|
|
}
|
2023-05-06 08:06:42 +03:00
|
|
|
|
2023-08-22 18:14:33 -07:00
|
|
|
public sealed partial class ToggleCombatActionEvent : InstantActionEvent { }
|