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;
|
2020-12-08 11:56:10 +01:00
|
|
|
|
using JetBrains.Annotations;
|
2021-02-11 01:13:03 -08:00
|
|
|
|
using Robust.Client.GameObjects;
|
|
|
|
|
|
using Robust.Client.Graphics;
|
|
|
|
|
|
using Robust.Client.Input;
|
2019-04-15 21:11:38 -06:00
|
|
|
|
using Robust.Client.Player;
|
2021-02-11 01:13:03 -08:00
|
|
|
|
using Robust.Shared.GameObjects;
|
2019-04-15 21:11:38 -06:00
|
|
|
|
using Robust.Shared.Input;
|
|
|
|
|
|
using Robust.Shared.IoC;
|
2020-08-11 16:44:15 -07:00
|
|
|
|
using Robust.Shared.Map;
|
2021-02-11 01:13:03 -08:00
|
|
|
|
using Robust.Shared.Timing;
|
2018-12-13 14:49:57 +01:00
|
|
|
|
|
|
|
|
|
|
namespace Content.Client.GameObjects.EntitySystems
|
|
|
|
|
|
{
|
2020-12-08 11:56:10 +01:00
|
|
|
|
[UsedImplicitly]
|
2018-12-13 14:49:57 +01:00
|
|
|
|
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
|
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
|
private InputSystem _inputSystem = default!;
|
|
|
|
|
|
private CombatModeSystem _combatModeSystem = default!;
|
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);
|
2021-03-10 14:48:29 +01:00
|
|
|
|
_inputSystem = Get<InputSystem>();
|
|
|
|
|
|
_combatModeSystem = Get<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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
|
var entity = _playerManager.LocalPlayer?.ControlledEntity;
|
|
|
|
|
|
if (entity == null || !entity.TryGetComponent(out HandsComponent? hands))
|
2018-12-13 14:49:57 +01:00
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var held = hands.ActiveHand;
|
2021-03-10 14:48:29 +01:00
|
|
|
|
if (held == null || !held.TryGetComponent(out ClientRangedWeaponComponent? weapon))
|
2018-12-13 14:49:57 +01:00
|
|
|
|
{
|
|
|
|
|
|
_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
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|