Gun stuff (#132)

* Guns can now be fully automatic.

Take that BYOND.

* Improve delay handling

* Bullet spread

* Fix firing guns on pickup
This commit is contained in:
Pieter-Jan Briers
2018-12-13 14:49:57 +01:00
committed by GitHub
parent 69946c79d8
commit 7ca90d11b3
14 changed files with 309 additions and 29 deletions

View File

@@ -27,6 +27,8 @@ namespace Content.Client.GameObjects
[ViewVariables] private ISpriteComponent _sprite;
[ViewVariables] public IEntity ActiveHand => GetEntity(ActiveIndex);
public override void OnAdd()
{
base.OnAdd();

View File

@@ -0,0 +1,29 @@
using System;
using Content.Shared.GameObjects.Components.Weapons.Ranged;
using SS14.Shared.Interfaces.Timing;
using SS14.Shared.IoC;
using SS14.Shared.Log;
using SS14.Shared.Map;
namespace Content.Client.GameObjects.Components.Weapons.Ranged
{
public sealed class ClientRangedWeaponComponent : SharedRangedWeaponComponent
{
private TimeSpan _lastFireTime;
private int _tick;
public void TryFire(GridLocalCoordinates worldPos)
{
var curTime = IoCManager.Resolve<IGameTiming>().CurTime;
var span = curTime - _lastFireTime;
if (span.TotalSeconds < 1 / FireRate)
{
return;
}
Logger.Debug("Delay: {0}", span.TotalSeconds);
_lastFireTime = curTime;
SendNetworkMessage(new FireMessage(worldPos, _tick++));
}
}
}

View File

@@ -0,0 +1,76 @@
using Content.Client.GameObjects.Components.Weapons.Ranged;
using Content.Client.Interfaces.GameObjects;
using Content.Shared.Input;
using SS14.Client.GameObjects.EntitySystems;
using SS14.Client.Interfaces.Graphics.ClientEye;
using SS14.Client.Interfaces.Input;
using SS14.Client.Player;
using SS14.Shared.GameObjects.Systems;
using SS14.Shared.Input;
using SS14.Shared.IoC;
namespace Content.Client.GameObjects.EntitySystems
{
public class RangedWeaponSystem : EntitySystem
{
#pragma warning disable 649
[Dependency] private readonly IPlayerManager _playerManager;
[Dependency] private readonly IEyeManager _eyeManager;
[Dependency] private readonly IInputManager _inputManager;
#pragma warning restore 649
private InputSystem _inputSystem;
private bool _isFirstShot;
private bool _blocked;
public override void Initialize()
{
base.Initialize();
IoCManager.InjectDependencies(this);
_inputSystem = EntitySystemManager.GetEntitySystem<InputSystem>();
}
public override void Update(float frameTime)
{
base.Update(frameTime);
var canFireSemi = _isFirstShot;
var state = _inputSystem.CmdStates.GetState(ContentKeyFunctions.UseItemInHand);
if (state != BoundKeyState.Down)
{
_isFirstShot = true;
_blocked = false;
return;
}
_isFirstShot = false;
var entity = _playerManager.LocalPlayer.ControlledEntity;
if (entity == null || !entity.TryGetComponent(out IHandsComponent hands))
{
return;
}
var held = hands.ActiveHand;
if (held == null || !held.TryGetComponent(out ClientRangedWeaponComponent weapon))
{
_blocked = true;
return;
}
if (_blocked)
{
return;
}
var worldPos = _eyeManager.ScreenToWorld(_inputManager.MouseScreenPosition);
if (weapon.Automatic || canFireSemi)
{
weapon.TryFire(worldPos);
}
}
}
}