2020-06-22 05:47:15 +10:00
|
|
|
|
using System;
|
2020-07-25 15:11:16 +02:00
|
|
|
|
using Content.Client.GameObjects.Components.Items;
|
2020-06-22 05:47:15 +10:00
|
|
|
|
using Content.Client.GameObjects.Components.Weapons.Ranged;
|
|
|
|
|
|
using Content.Shared.GameObjects.Components.Weapons.Ranged;
|
2019-04-15 21:11:38 -06:00
|
|
|
|
using Robust.Client.GameObjects.EntitySystems;
|
|
|
|
|
|
using Robust.Client.Interfaces.Graphics.ClientEye;
|
|
|
|
|
|
using Robust.Client.Interfaces.Input;
|
|
|
|
|
|
using Robust.Client.Player;
|
|
|
|
|
|
using Robust.Shared.GameObjects.Systems;
|
|
|
|
|
|
using Robust.Shared.Input;
|
2020-06-12 17:36:25 +01:00
|
|
|
|
using Robust.Shared.Interfaces.Map;
|
2020-05-28 14:32:36 +02:00
|
|
|
|
using Robust.Shared.Interfaces.Timing;
|
2019-04-15 21:11:38 -06:00
|
|
|
|
using Robust.Shared.IoC;
|
2020-08-11 16:44:15 -07:00
|
|
|
|
using Robust.Shared.Map;
|
2018-12-13 14:49:57 +01:00
|
|
|
|
|
|
|
|
|
|
namespace Content.Client.GameObjects.EntitySystems
|
|
|
|
|
|
{
|
|
|
|
|
|
public class RangedWeaponSystem : EntitySystem
|
|
|
|
|
|
{
|
2020-08-24 14:10:28 +02:00
|
|
|
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
|
|
|
|
|
[Dependency] private readonly IEyeManager _eyeManager = default!;
|
|
|
|
|
|
[Dependency] private readonly IMapManager _mapManager = default!;
|
|
|
|
|
|
[Dependency] private readonly IInputManager _inputManager = default!;
|
|
|
|
|
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
2018-12-13 14:49:57 +01:00
|
|
|
|
|
|
|
|
|
|
private InputSystem _inputSystem;
|
2020-01-26 03:38:51 +01:00
|
|
|
|
private CombatModeSystem _combatModeSystem;
|
2018-12-13 14:49:57 +01:00
|
|
|
|
private bool _blocked;
|
2020-06-22 05:47:15 +10:00
|
|
|
|
private int _shotCounter;
|
2018-12-13 14:49:57 +01:00
|
|
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
|
|
IoCManager.InjectDependencies(this);
|
|
|
|
|
|
_inputSystem = EntitySystemManager.GetEntitySystem<InputSystem>();
|
2020-01-26 03:38:51 +01:00
|
|
|
|
_combatModeSystem = EntitySystemManager.GetEntitySystem<CombatModeSystem>();
|
2018-12-13 14:49:57 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void Update(float frameTime)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Update(frameTime);
|
|
|
|
|
|
|
2020-05-28 14:32:36 +02:00
|
|
|
|
if (!_gameTiming.IsFirstTimePredicted)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2020-07-25 15:11:16 +02:00
|
|
|
|
|
2020-05-03 14:26:49 +02:00
|
|
|
|
var state = _inputSystem.CmdStates.GetState(EngineKeyFunctions.Use);
|
2020-05-08 11:55:19 +02:00
|
|
|
|
if (!_combatModeSystem.IsInCombatMode() || state != BoundKeyState.Down)
|
2018-12-13 14:49:57 +01:00
|
|
|
|
{
|
2020-06-22 05:47:15 +10:00
|
|
|
|
_shotCounter = 0;
|
2018-12-13 14:49:57 +01:00
|
|
|
|
_blocked = false;
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var entity = _playerManager.LocalPlayer.ControlledEntity;
|
2020-07-25 15:11:16 +02:00
|
|
|
|
if (entity == null || !entity.TryGetComponent(out HandsComponent hands))
|
2018-12-13 14:49:57 +01:00
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var held = hands.ActiveHand;
|
|
|
|
|
|
if (held == null || !held.TryGetComponent(out ClientRangedWeaponComponent weapon))
|
|
|
|
|
|
{
|
|
|
|
|
|
_blocked = true;
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-22 05:47:15 +10:00
|
|
|
|
switch (weapon.FireRateSelector)
|
|
|
|
|
|
{
|
|
|
|
|
|
case FireRateSelector.Safety:
|
|
|
|
|
|
_blocked = true;
|
|
|
|
|
|
return;
|
|
|
|
|
|
case FireRateSelector.Single:
|
|
|
|
|
|
if (_shotCounter >= 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
_blocked = true;
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
case FireRateSelector.Automatic:
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
throw new ArgumentOutOfRangeException();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-13 14:49:57 +01:00
|
|
|
|
if (_blocked)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-12 17:36:25 +01:00
|
|
|
|
var worldPos = _eyeManager.ScreenToMap(_inputManager.MouseScreenPosition);
|
|
|
|
|
|
|
|
|
|
|
|
if (!_mapManager.TryFindGridAt(worldPos, out var grid))
|
2020-08-11 16:44:15 -07:00
|
|
|
|
{
|
|
|
|
|
|
weapon.SyncFirePos(GridId.Invalid, worldPos.Position);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
weapon.SyncFirePos(grid.Index, grid.MapToGrid(worldPos).Position);
|
|
|
|
|
|
}
|
2018-12-13 14:49:57 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|