2023-05-06 08:06:42 +03:00
|
|
|
using Content.Client.Hands.Systems;
|
2023-10-14 03:15:20 -04:00
|
|
|
using Content.Client.NPC.HTN;
|
2023-09-09 16:14:17 -07:00
|
|
|
using Content.Shared.CCVar;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.CombatMode;
|
2023-05-06 08:06:42 +03:00
|
|
|
using Robust.Client.Graphics;
|
2023-09-09 16:14:17 -07:00
|
|
|
using Robust.Client.Input;
|
|
|
|
|
using Robust.Client.Player;
|
2023-05-06 08:06:42 +03:00
|
|
|
using Robust.Shared.Configuration;
|
2019-09-26 22:32:32 +02:00
|
|
|
|
2023-05-06 08:06:42 +03:00
|
|
|
namespace Content.Client.CombatMode;
|
|
|
|
|
|
|
|
|
|
public sealed class CombatModeSystem : SharedCombatModeSystem
|
2019-09-26 22:32:32 +02:00
|
|
|
{
|
2023-05-06 08:06:42 +03:00
|
|
|
[Dependency] private readonly IOverlayManager _overlayManager = default!;
|
|
|
|
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
|
|
|
|
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
|
|
|
|
[Dependency] private readonly IInputManager _inputManager = default!;
|
|
|
|
|
[Dependency] private readonly IEyeManager _eye = default!;
|
2023-09-03 06:16:34 +10:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Raised whenever combat mode changes.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public event Action<bool>? LocalPlayerCombatModeUpdated;
|
2023-05-06 08:06:42 +03:00
|
|
|
|
|
|
|
|
public override void Initialize()
|
2019-09-26 22:32:32 +02:00
|
|
|
{
|
2023-05-06 08:06:42 +03:00
|
|
|
base.Initialize();
|
2019-09-26 22:32:32 +02:00
|
|
|
|
2023-09-03 06:16:34 +10:00
|
|
|
SubscribeLocalEvent<CombatModeComponent, AfterAutoHandleStateEvent>(OnHandleState);
|
2023-04-08 13:16:48 -07:00
|
|
|
|
2023-05-06 08:06:42 +03:00
|
|
|
_cfg.OnValueChanged(CCVars.CombatModeIndicatorsPointShow, OnShowCombatIndicatorsChanged, true);
|
|
|
|
|
}
|
2019-09-26 22:32:32 +02:00
|
|
|
|
2023-09-03 06:16:34 +10:00
|
|
|
private void OnHandleState(EntityUid uid, CombatModeComponent component, ref AfterAutoHandleStateEvent args)
|
2023-05-06 08:06:42 +03:00
|
|
|
{
|
|
|
|
|
UpdateHud(uid);
|
|
|
|
|
}
|
2022-09-29 15:51:59 +10:00
|
|
|
|
2023-05-06 08:06:42 +03:00
|
|
|
public override void Shutdown()
|
|
|
|
|
{
|
2023-09-03 06:16:34 +10:00
|
|
|
_cfg.UnsubValueChanged(CCVars.CombatModeIndicatorsPointShow, OnShowCombatIndicatorsChanged);
|
2023-05-06 08:06:42 +03:00
|
|
|
_overlayManager.RemoveOverlay<CombatModeIndicatorsOverlay>();
|
2023-04-08 13:16:48 -07:00
|
|
|
|
2023-05-06 08:06:42 +03:00
|
|
|
base.Shutdown();
|
|
|
|
|
}
|
2020-01-26 03:38:51 +01:00
|
|
|
|
2023-05-06 08:06:42 +03:00
|
|
|
public bool IsInCombatMode()
|
|
|
|
|
{
|
|
|
|
|
var entity = _playerManager.LocalPlayer?.ControlledEntity;
|
2022-09-29 15:51:59 +10:00
|
|
|
|
2023-05-06 08:06:42 +03:00
|
|
|
if (entity == null)
|
|
|
|
|
return false;
|
2022-09-29 15:51:59 +10:00
|
|
|
|
2023-05-06 08:06:42 +03:00
|
|
|
return IsInCombatMode(entity.Value);
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-03 06:16:34 +10:00
|
|
|
public override void SetInCombatMode(EntityUid entity, bool value, CombatModeComponent? component = null)
|
2023-05-06 08:06:42 +03:00
|
|
|
{
|
2023-09-03 06:16:34 +10:00
|
|
|
base.SetInCombatMode(entity, value, component);
|
2023-05-06 08:06:42 +03:00
|
|
|
UpdateHud(entity);
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-14 03:15:20 -04:00
|
|
|
protected override bool IsNpc(EntityUid uid)
|
|
|
|
|
{
|
|
|
|
|
return HasComp<HTNComponent>(uid);
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-06 08:06:42 +03:00
|
|
|
private void UpdateHud(EntityUid entity)
|
|
|
|
|
{
|
2023-09-03 06:16:34 +10:00
|
|
|
if (entity != _playerManager.LocalPlayer?.ControlledEntity || !Timing.IsFirstTimePredicted)
|
2019-09-26 22:32:32 +02:00
|
|
|
{
|
2023-05-06 08:06:42 +03:00
|
|
|
return;
|
2023-04-08 13:16:48 -07:00
|
|
|
}
|
|
|
|
|
|
2023-09-03 06:16:34 +10:00
|
|
|
var inCombatMode = IsInCombatMode();
|
|
|
|
|
LocalPlayerCombatModeUpdated?.Invoke(inCombatMode);
|
2023-05-06 08:06:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnShowCombatIndicatorsChanged(bool isShow)
|
|
|
|
|
{
|
|
|
|
|
if (isShow)
|
2023-04-08 13:16:48 -07:00
|
|
|
{
|
2023-05-06 08:06:42 +03:00
|
|
|
_overlayManager.AddOverlay(new CombatModeIndicatorsOverlay(
|
|
|
|
|
_inputManager,
|
|
|
|
|
EntityManager,
|
|
|
|
|
_eye,
|
|
|
|
|
this,
|
|
|
|
|
EntityManager.System<HandsSystem>()));
|
2023-04-08 13:16:48 -07:00
|
|
|
}
|
2023-05-06 08:06:42 +03:00
|
|
|
else
|
2023-04-08 13:16:48 -07:00
|
|
|
{
|
2023-05-06 08:06:42 +03:00
|
|
|
_overlayManager.RemoveOverlay<CombatModeIndicatorsOverlay>();
|
2019-09-26 22:32:32 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|