add sniper

This commit is contained in:
CortexCore
2023-10-31 18:07:15 +08:00
parent 18f664a545
commit f0f348c246
47 changed files with 4568 additions and 389 deletions

View File

@@ -7,6 +7,7 @@ using BITKit.Selection;
using UnityEngine.InputSystem;
using BITKit.StateMachine;
using UnityEngine;
// ReSharper disable UnassignedField.Local
namespace BITFALL.Guns.States
{
@@ -19,6 +20,8 @@ namespace BITFALL.Guns.States
{
[SerializeField] private ExpectState<bool> _expectRun;
[Inject] protected ISelector _selector;
private float elapsedTime;
private bool boltActionImmediately;
public override void OnStateEntry(IState old)
{
switch (old)
@@ -31,14 +34,17 @@ namespace BITFALL.Guns.States
break;
}
_selector.OnActive += OnActive;
boltActionImmediately = root.RequireBolt;
}
public override void OnStateExit(IState old, IState newState)
{
elapsedTime = 0;
base.OnStateExit(old, newState);
_selector.OnActive -= OnActive;
}
public override void OnStateUpdate(float deltaTime)
{
elapsedTime += deltaTime;
if (root.animator[0].stateName is not BITConstant.Player.Movement) return;
if (root.expectFiring.shouldBe && root.fireInterval.AllowUpdate)
{
@@ -50,6 +56,9 @@ namespace BITFALL.Guns.States
}else if (_expectRun)
{
root.TransitionState<Run>();
}else if (root.RequireBolt && elapsedTime > 0.5f || boltActionImmediately)
{
root.TransitionState<Reload>();
}
}
public void OnActive(ISelectable selectable)
@@ -146,8 +155,6 @@ namespace BITFALL.Guns.States
[System.Serializable]
public sealed class Aim : GunState
{
[Inject]
private IEquipService _equipService;
public override void OnStateEntry(IState old)
{
switch (old)
@@ -160,7 +167,6 @@ namespace BITFALL.Guns.States
root.animator.CrossFade(BITConstant.Player.Aim, 0.16f);
break;
}
_equipService.Zoom.Allow = true;
_entityMovement.ExecuteCommand<PlayerCancelRunCommand>();
}
@@ -183,13 +189,6 @@ namespace BITFALL.Guns.States
{
root.TransitionState<Movement>();
}
_equipService.Zoom.Value = root.aimAction.action.ReadValue<float>();
}
public override void OnStateExit(IState old, IState newState)
{
base.OnStateExit(old, newState);
_equipService.Zoom.Allow = false;
}
public override void OnMovementStateChanged(IEntityMovementState old, IEntityMovementState newState)
@@ -260,8 +259,16 @@ namespace BITFALL.Guns.States
base.OnStateEntry(old);
_entityMovement.ExecuteCommand<PlayerCancelRunCommand>();
root.UnityEntity.Invoke(Constant.Animation.Play, BITConstant.Player.Reload);
if (root.RequireBolt)
{
root.UnityEntity.Invoke(Constant.Animation.Play, BITConstant.Player.BoltAction);
}
else
{
root.UnityEntity.Invoke(Constant.Animation.Play, BITConstant.Player.Reload);
}
}
public override void OnMovementStateChanged(IEntityMovementState old, IEntityMovementState newState)
{
@@ -271,8 +278,13 @@ namespace BITFALL.Guns.States
root.TransitionState<Movement>();
}
}
}
public override void OnStateExit(IState old, IState newState)
{
root.RequireBolt = false;
base.OnStateExit(old, newState);
}
}
[System.Serializable]
public sealed class Melee : GunState
{