2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.CombatMode;
|
|
|
|
|
using Content.Shared.Targeting;
|
2020-03-25 11:16:57 +01:00
|
|
|
using JetBrains.Annotations;
|
2020-01-26 03:38:51 +01:00
|
|
|
using Robust.Client.Player;
|
2022-09-29 15:51:59 +10:00
|
|
|
using Robust.Shared.GameStates;
|
2020-05-31 14:32:05 -07:00
|
|
|
using Robust.Shared.Input.Binding;
|
2019-09-26 22:32:32 +02:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Client.CombatMode
|
2019-09-26 22:32:32 +02:00
|
|
|
{
|
2020-03-25 11:16:57 +01:00
|
|
|
[UsedImplicitly]
|
|
|
|
|
public sealed class CombatModeSystem : SharedCombatModeSystem
|
2019-09-26 22:32:32 +02:00
|
|
|
{
|
2020-08-24 14:10:28 +02:00
|
|
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
2019-09-26 22:32:32 +02:00
|
|
|
|
2023-04-08 13:16:48 -07:00
|
|
|
public event Action? LocalPlayerCombatModeUpdated;
|
|
|
|
|
|
2019-09-26 22:32:32 +02:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
2023-04-08 13:16:48 -07:00
|
|
|
SubscribeLocalEvent<CombatModeComponent, ComponentHandleState>(OnHandleState);
|
2022-09-29 15:51:59 +10:00
|
|
|
}
|
|
|
|
|
|
2023-04-08 13:16:48 -07:00
|
|
|
private void OnHandleState(EntityUid uid, CombatModeComponent component, ref ComponentHandleState args)
|
2022-09-29 15:51:59 +10:00
|
|
|
{
|
|
|
|
|
if (args.Current is not CombatModeComponentState state)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
component.IsInCombatMode = state.IsInCombatMode;
|
|
|
|
|
component.ActiveZone = state.TargetingZone;
|
2023-04-08 13:16:48 -07:00
|
|
|
UpdateHud(uid);
|
2020-05-31 14:32:05 -07:00
|
|
|
}
|
2023-04-08 13:16:48 -07:00
|
|
|
|
2020-05-31 14:32:05 -07:00
|
|
|
public override void Shutdown()
|
|
|
|
|
{
|
|
|
|
|
CommandBinds.Unregister<CombatModeSystem>();
|
|
|
|
|
base.Shutdown();
|
2020-01-26 03:38:51 +01:00
|
|
|
}
|
|
|
|
|
|
2023-04-08 13:16:48 -07:00
|
|
|
private void OnTargetingZoneChanged(TargetingZone obj)
|
|
|
|
|
{
|
|
|
|
|
EntityManager.RaisePredictiveEvent(new CombatModeSystemMessages.SetTargetZoneMessage(obj));
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-03 14:26:49 +02:00
|
|
|
public bool IsInCombatMode()
|
2020-01-26 03:38:51 +01:00
|
|
|
{
|
2022-09-29 15:51:59 +10:00
|
|
|
var entity = _playerManager.LocalPlayer?.ControlledEntity;
|
|
|
|
|
|
|
|
|
|
if (entity == null)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return IsInCombatMode(entity.Value);
|
2019-09-26 22:32:32 +02:00
|
|
|
}
|
|
|
|
|
|
2023-04-08 13:16:48 -07:00
|
|
|
public override void SetInCombatMode(EntityUid entity, bool inCombatMode, CombatModeComponent? component = null)
|
2019-09-26 22:32:32 +02:00
|
|
|
{
|
2023-04-08 13:16:48 -07:00
|
|
|
base.SetInCombatMode(entity, inCombatMode, component);
|
|
|
|
|
UpdateHud(entity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void SetActiveZone(EntityUid entity, TargetingZone zone, CombatModeComponent? component = null)
|
|
|
|
|
{
|
|
|
|
|
base.SetActiveZone(entity, zone, component);
|
|
|
|
|
UpdateHud(entity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateHud(EntityUid entity)
|
|
|
|
|
{
|
|
|
|
|
if (entity != _playerManager.LocalPlayer?.ControlledEntity)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LocalPlayerCombatModeUpdated?.Invoke();
|
2019-09-26 22:32:32 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|