2021-06-21 02:21:20 -07:00
|
|
|
using System;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Client.CombatMode;
|
2021-06-21 02:21:20 -07:00
|
|
|
using Content.Shared.Hands.Components;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Weapons.Ranged.Components;
|
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
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Client.Weapons.Ranged
|
2018-12-13 14:49:57 +01:00
|
|
|
{
|
2020-12-08 11:56:10 +01:00
|
|
|
[UsedImplicitly]
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class RangedWeaponSystem : EntitySystem
|
2018-12-13 14:49:57 +01:00
|
|
|
{
|
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!;
|
2021-07-26 12:58:17 +02:00
|
|
|
[Dependency] private readonly InputSystem _inputSystem = default!;
|
|
|
|
|
[Dependency] private readonly 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
|
|
|
|
2021-12-30 03:12:04 +01:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
UpdatesOutsidePrediction = true;
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
2021-12-06 14:00:39 +01:00
|
|
|
if (!EntityManager.TryGetComponent(entity, out SharedHandsComponent? hands))
|
2018-12-13 14:49:57 +01:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-17 20:13:31 +13:00
|
|
|
if (hands.ActiveHandEntity is not EntityUid held || !EntityManager.TryGetComponent(held, 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;
|
|
|
|
|
|
2022-01-30 17:39:46 +11:00
|
|
|
var mapCoordinates = _eyeManager.ScreenToMap(_inputManager.MouseScreenPosition);
|
|
|
|
|
EntityCoordinates coordinates;
|
2020-06-12 17:36:25 +01:00
|
|
|
|
2022-01-30 17:39:46 +11:00
|
|
|
if (_mapManager.TryFindGridAt(mapCoordinates, out var grid))
|
2020-08-11 16:44:15 -07:00
|
|
|
{
|
2022-01-30 17:39:46 +11:00
|
|
|
coordinates = EntityCoordinates.FromMap(grid.GridEntityId, mapCoordinates);
|
2020-08-11 16:44:15 -07:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-01-30 17:39:46 +11:00
|
|
|
coordinates = EntityCoordinates.FromMap(_mapManager.GetMapEntityId(mapCoordinates.MapId), mapCoordinates);
|
2020-08-11 16:44:15 -07:00
|
|
|
}
|
2022-01-30 17:39:46 +11:00
|
|
|
|
|
|
|
|
SyncFirePos(coordinates);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SyncFirePos(EntityCoordinates coordinates)
|
|
|
|
|
{
|
|
|
|
|
RaiseNetworkEvent(new FirePosEvent(coordinates));
|
2018-12-13 14:49:57 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|