2023-11-30 00:23:23 +08:00
|
|
|
using System;
|
2023-11-21 18:05:18 +08:00
|
|
|
using System.Collections.Generic;
|
2023-09-01 14:33:54 +08:00
|
|
|
using System.Data.Odbc;
|
2023-11-21 18:05:18 +08:00
|
|
|
using System.Linq;
|
2024-03-23 18:07:54 +08:00
|
|
|
using Animancer;
|
2023-10-02 23:24:56 +08:00
|
|
|
using BITFALL.Player.Equip;
|
2023-08-23 01:59:40 +08:00
|
|
|
using BITFALL.Player.Movement;
|
2023-06-08 14:09:50 +08:00
|
|
|
using BITKit;
|
2024-03-23 18:07:54 +08:00
|
|
|
using BITKit.Animations;
|
2023-06-08 14:09:50 +08:00
|
|
|
using BITKit.Entities;
|
2023-10-20 19:31:12 +08:00
|
|
|
using BITKit.Selection;
|
2023-06-08 14:09:50 +08:00
|
|
|
using UnityEngine.InputSystem;
|
|
|
|
using BITKit.StateMachine;
|
2024-03-29 00:58:24 +08:00
|
|
|
using Cysharp.Threading.Tasks;
|
2023-08-23 01:59:40 +08:00
|
|
|
using UnityEngine;
|
2023-10-31 18:07:15 +08:00
|
|
|
// ReSharper disable UnassignedField.Local
|
2023-08-23 01:59:40 +08:00
|
|
|
|
|
|
|
namespace BITFALL.Guns.States
|
2023-06-08 14:09:50 +08:00
|
|
|
{
|
|
|
|
[System.Serializable]
|
2023-10-20 19:31:12 +08:00
|
|
|
public sealed class None:GunState
|
|
|
|
{
|
|
|
|
}
|
|
|
|
[System.Serializable]
|
2023-12-26 20:07:19 +08:00
|
|
|
public sealed class Movement : GunState
|
2023-06-08 14:09:50 +08:00
|
|
|
{
|
2023-08-23 01:59:40 +08:00
|
|
|
[SerializeField] private ExpectState<bool> _expectRun;
|
2023-12-26 20:07:19 +08:00
|
|
|
[Inject] private ISelector _selector;
|
2023-11-15 23:54:54 +08:00
|
|
|
private float requestBoltActionElapsedTime;
|
2023-10-31 18:07:15 +08:00
|
|
|
private bool boltActionImmediately;
|
2024-03-23 18:07:54 +08:00
|
|
|
|
|
|
|
private AnimancerState inspectState;
|
2024-03-24 02:05:16 +08:00
|
|
|
|
|
|
|
private AnimancerState crouchState;
|
2023-08-23 01:59:40 +08:00
|
|
|
public override void OnStateEntry(IState old)
|
2023-06-08 14:09:50 +08:00
|
|
|
{
|
2023-08-23 01:59:40 +08:00
|
|
|
switch (old)
|
|
|
|
{
|
2023-11-15 23:54:54 +08:00
|
|
|
case Movement:
|
|
|
|
break;
|
2023-08-23 01:59:40 +08:00
|
|
|
default:
|
2024-04-06 16:33:57 +08:00
|
|
|
if (_entityMovement.CurrentState is IPlayerWalkState or IPlayerCrouchState or IPlayerKnockdownState)
|
2024-03-25 16:08:26 +08:00
|
|
|
PlayAnimation();
|
|
|
|
else
|
|
|
|
OnMovementStateChanged(null, _entityMovement.CurrentState);
|
2023-08-23 01:59:40 +08:00
|
|
|
break;
|
|
|
|
}
|
2024-03-25 16:08:26 +08:00
|
|
|
|
2023-10-20 19:31:12 +08:00
|
|
|
_selector.OnActive += OnActive;
|
2023-10-31 18:07:15 +08:00
|
|
|
boltActionImmediately = root.RequireBolt;
|
2024-03-23 18:07:54 +08:00
|
|
|
|
|
|
|
root.inputActionGroup.RegisterCallback(root.inspectAction, OnInspect);
|
2023-06-08 14:09:50 +08:00
|
|
|
}
|
2024-03-23 18:07:54 +08:00
|
|
|
|
|
|
|
private void OnInspect(InputAction.CallbackContext obj)
|
|
|
|
{
|
2024-03-29 00:58:24 +08:00
|
|
|
PlayAnimation(0,PlayAnimationVoid,nameof(BITConstant.Player.Inspect));
|
2024-03-23 18:07:54 +08:00
|
|
|
}
|
|
|
|
|
2023-06-08 14:09:50 +08:00
|
|
|
public override void OnStateExit(IState old, IState newState)
|
|
|
|
{
|
2023-11-15 23:54:54 +08:00
|
|
|
requestBoltActionElapsedTime = 0;
|
2023-06-08 14:09:50 +08:00
|
|
|
base.OnStateExit(old, newState);
|
2023-10-20 19:31:12 +08:00
|
|
|
_selector.OnActive -= OnActive;
|
2024-03-23 18:07:54 +08:00
|
|
|
|
|
|
|
root.inputActionGroup.UnRegisterCallback(root.inspectAction, OnInspect);
|
|
|
|
|
|
|
|
if (inspectState != null)
|
|
|
|
{
|
|
|
|
inspectState.Events.OnEnd = null;
|
|
|
|
inspectState.Stop();
|
|
|
|
}
|
|
|
|
|
2023-06-08 14:09:50 +08:00
|
|
|
}
|
2023-11-15 23:54:54 +08:00
|
|
|
|
2023-08-27 02:58:19 +08:00
|
|
|
public override void OnStateUpdate(float deltaTime)
|
2023-06-08 14:09:50 +08:00
|
|
|
{
|
2023-11-15 23:54:54 +08:00
|
|
|
if (root.RequireBolt)
|
|
|
|
requestBoltActionElapsedTime += deltaTime;
|
2024-03-23 18:07:54 +08:00
|
|
|
//if (root.animator[0].stateName is not BITConstant.Player.Movement) return;
|
2023-08-23 01:59:40 +08:00
|
|
|
if (root.expectFiring.shouldBe && root.fireInterval.AllowUpdate)
|
2023-06-08 14:09:50 +08:00
|
|
|
{
|
2023-08-23 01:59:40 +08:00
|
|
|
root.Fire();
|
2023-06-08 14:09:50 +08:00
|
|
|
}
|
2023-08-23 01:59:40 +08:00
|
|
|
if (root.expectAiming.shouldBe && BITAppForUnity.AllowCursor == false)
|
2023-06-08 14:09:50 +08:00
|
|
|
{
|
2023-08-23 01:59:40 +08:00
|
|
|
root.TransitionState<Aim>();
|
2023-11-15 23:54:54 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (_expectRun)
|
2023-08-23 01:59:40 +08:00
|
|
|
{
|
|
|
|
root.TransitionState<Run>();
|
2023-11-15 23:54:54 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (root.RequireBolt)
|
2023-10-31 18:07:15 +08:00
|
|
|
{
|
2023-11-15 23:54:54 +08:00
|
|
|
case var _ when boltActionImmediately:
|
|
|
|
case var _ when requestBoltActionElapsedTime > 1f:
|
2024-03-23 18:07:54 +08:00
|
|
|
//case var _ when root.animator[4].stateName == BITConstant.Player.Empty && requestBoltActionElapsedTime>0.32f:
|
2023-11-15 23:54:54 +08:00
|
|
|
root.TransitionState<Reload>();
|
|
|
|
break;
|
2023-06-08 14:09:50 +08:00
|
|
|
}
|
|
|
|
}
|
2023-11-15 23:54:54 +08:00
|
|
|
|
2024-03-29 00:58:24 +08:00
|
|
|
public async void OnActive(ISelectable selectable)
|
2023-06-08 14:09:50 +08:00
|
|
|
{
|
2024-03-29 00:58:24 +08:00
|
|
|
await UniTask.DelayFrame(8);
|
|
|
|
if (root.destroyCancellationToken.IsCancellationRequested) return;
|
|
|
|
if (root.IsEntered && Enabled)
|
2024-03-31 23:34:22 +08:00
|
|
|
await PlayAnimation(0, PlayAnimationVoid,BITConstant.Player.Interactive);
|
2023-06-08 14:09:50 +08:00
|
|
|
}
|
2024-03-29 00:58:24 +08:00
|
|
|
|
2023-08-23 01:59:40 +08:00
|
|
|
public override void OnMovementStateChanged(IEntityMovementState old, IEntityMovementState newState)
|
|
|
|
{
|
|
|
|
_expectRun = newState is IPlayerRunState or IPlayerSprintState;
|
2023-10-20 19:31:12 +08:00
|
|
|
if (newState is IPlayerSlideState)
|
|
|
|
{
|
2024-03-25 16:08:26 +08:00
|
|
|
if (root.CurrentState != this)
|
|
|
|
root.TransitionState<Movement>();
|
|
|
|
PlayAnimation(BITConstant.Player.Slide);
|
2024-03-23 18:07:54 +08:00
|
|
|
//root.animator.CrossFade(BITConstant.Player.Slide, 0.32f);
|
2024-03-25 16:08:26 +08:00
|
|
|
}
|
|
|
|
else if (newState is IPlayerDodgeState)
|
2023-12-26 20:07:19 +08:00
|
|
|
{
|
2024-03-25 16:08:26 +08:00
|
|
|
if (root.CurrentState != this)
|
|
|
|
root.TransitionState<Movement>();
|
|
|
|
PlayAnimation(BITConstant.Player.Dodge);
|
|
|
|
}
|
|
|
|
else if (Enabled)
|
2024-03-24 02:05:16 +08:00
|
|
|
{
|
|
|
|
switch (newState)
|
|
|
|
{
|
|
|
|
case IPlayerCrouchState:
|
|
|
|
PlayAnimation(root.SearchKey.Append(nameof(BITConstant.Player.Crouch)).ToArray());
|
|
|
|
break;
|
|
|
|
case IPlayerMovementState:
|
|
|
|
PlayAnimation();
|
|
|
|
break;
|
|
|
|
}
|
2023-10-20 19:31:12 +08:00
|
|
|
}
|
2023-08-23 01:59:40 +08:00
|
|
|
}
|
2023-06-08 14:09:50 +08:00
|
|
|
}
|
|
|
|
[System.Serializable]
|
2023-10-20 19:31:12 +08:00
|
|
|
public sealed class Run : GunState
|
2023-06-08 14:09:50 +08:00
|
|
|
{
|
2023-08-23 01:59:40 +08:00
|
|
|
private ExpectState<bool> _expectRun;
|
|
|
|
private ExpectState<bool> _expectSprint;
|
|
|
|
public override void OnStateEntry(IState old)
|
2023-06-08 14:09:50 +08:00
|
|
|
{
|
2024-03-24 02:05:16 +08:00
|
|
|
PlayAnimation(root.SearchKey.Append(nameof(BITConstant.Player.Run)).ToArray());
|
2023-06-08 14:09:50 +08:00
|
|
|
|
2023-10-20 19:31:12 +08:00
|
|
|
root.inputActionGroup.RegisterCallback(root.aimAction, OnAim);
|
2023-06-08 14:09:50 +08:00
|
|
|
}
|
|
|
|
public override void OnStateExit(IState old, IState newState)
|
|
|
|
{
|
2023-10-20 19:31:12 +08:00
|
|
|
root.inputActionGroup.UnRegisterCallback(root.aimAction, OnAim);
|
2023-06-08 14:09:50 +08:00
|
|
|
}
|
2023-08-27 02:58:19 +08:00
|
|
|
public override void OnStateUpdate(float deltaTime)
|
2023-06-08 14:09:50 +08:00
|
|
|
{
|
2024-03-23 18:07:54 +08:00
|
|
|
// if (root.animator[0].stateName == BITConstant.Player.Movement)
|
|
|
|
// {
|
|
|
|
// root.animator.CrossFade(BITConstant.Player.Run, 0.32f);
|
|
|
|
// PlayAnimation(SearchKey.Append(nameof(BITConstant.Player.Run)).ToArray());
|
|
|
|
// }
|
2023-08-23 01:59:40 +08:00
|
|
|
if(_expectSprint)
|
|
|
|
{
|
|
|
|
root.TransitionState<Sprint>();
|
|
|
|
}
|
|
|
|
else if(_expectRun == false)
|
|
|
|
{
|
|
|
|
root.TransitionState<Movement>();
|
2024-03-25 16:08:26 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
currentState.Speed = _entityMovement.LocomotionBasedVelocity.GetLength() / _entityMovement.ReferenceSpeed;
|
|
|
|
}
|
2023-06-08 14:09:50 +08:00
|
|
|
}
|
2023-08-23 01:59:40 +08:00
|
|
|
private void OnAim(InputAction.CallbackContext context)
|
2023-06-08 14:09:50 +08:00
|
|
|
{
|
2023-08-23 01:59:40 +08:00
|
|
|
if (context.started && BITAppForUnity.AllowCursor == false)
|
2023-06-08 14:09:50 +08:00
|
|
|
{
|
2023-08-23 01:59:40 +08:00
|
|
|
root.TransitionState<Aim>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void OnMovementStateChanged(IEntityMovementState old, IEntityMovementState newState)
|
|
|
|
{
|
|
|
|
_expectRun = newState is IPlayerRunState or IPlayerSprintState;
|
|
|
|
_expectSprint = newState is IPlayerSprintState;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
[System.Serializable]
|
2023-10-20 19:31:12 +08:00
|
|
|
public sealed class Sprint : GunState
|
2023-08-23 01:59:40 +08:00
|
|
|
{
|
|
|
|
private ExpectState<bool> _expectSprint;
|
|
|
|
public override void OnStateEntry(IState old)
|
|
|
|
{
|
2024-03-25 16:08:26 +08:00
|
|
|
base.OnStateEntry(old);
|
2024-03-23 18:07:54 +08:00
|
|
|
//root.animator.CrossFade(BITConstant.Player.Sprint, 0.32f);
|
2024-03-25 16:08:26 +08:00
|
|
|
//PlayAnimation(root.SearchKey.Append(nameof(BITConstant.Player.Sprint)).ToArray());
|
2024-03-23 18:07:54 +08:00
|
|
|
|
2023-10-20 19:31:12 +08:00
|
|
|
root.inputActionGroup.RegisterCallback(root.aimAction, OnAim);
|
2023-08-23 01:59:40 +08:00
|
|
|
}
|
|
|
|
public override void OnStateExit(IState old, IState newState)
|
|
|
|
{
|
2023-10-20 19:31:12 +08:00
|
|
|
root.inputActionGroup.UnRegisterCallback(root.aimAction, OnAim);
|
2023-08-23 01:59:40 +08:00
|
|
|
}
|
2023-08-27 02:58:19 +08:00
|
|
|
public override void OnStateUpdate(float deltaTime)
|
2023-08-23 01:59:40 +08:00
|
|
|
{
|
|
|
|
if(_expectSprint == false)
|
|
|
|
{
|
|
|
|
root.TransitionState<Movement>();
|
2023-06-08 14:09:50 +08:00
|
|
|
}
|
2024-03-25 16:08:26 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
currentState.Speed = _entityMovement.LocomotionBasedVelocity.GetLength() / _entityMovement.ReferenceSpeed;
|
|
|
|
}
|
2023-06-08 14:09:50 +08:00
|
|
|
}
|
2023-08-23 01:59:40 +08:00
|
|
|
private void OnAim(InputAction.CallbackContext context)
|
2023-06-08 14:09:50 +08:00
|
|
|
{
|
|
|
|
if (context.started && BITAppForUnity.AllowCursor == false)
|
|
|
|
{
|
2023-08-23 01:59:40 +08:00
|
|
|
root.TransitionState<Aim>();
|
2023-06-08 14:09:50 +08:00
|
|
|
}
|
|
|
|
}
|
2023-08-23 01:59:40 +08:00
|
|
|
public override void OnMovementStateChanged(IEntityMovementState old, IEntityMovementState newState)
|
|
|
|
{
|
|
|
|
_expectSprint = newState is IPlayerSprintState;
|
|
|
|
}
|
2023-06-08 14:09:50 +08:00
|
|
|
}
|
|
|
|
[System.Serializable]
|
2023-10-20 19:31:12 +08:00
|
|
|
public sealed class Aim : GunState
|
2023-06-08 14:09:50 +08:00
|
|
|
{
|
2023-08-23 01:59:40 +08:00
|
|
|
public override void OnStateEntry(IState old)
|
2023-06-08 14:09:50 +08:00
|
|
|
{
|
2024-03-25 16:08:26 +08:00
|
|
|
// switch (old)
|
|
|
|
// {
|
|
|
|
// case IPlayerRunState:
|
|
|
|
// case IPlayerSprintState:
|
|
|
|
// //root.animator.CrossFade(BITConstant.Player.Aim, 0.32f);
|
|
|
|
// PlayAnimation(root.SearchKey.Append(nameof(BITConstant.Player.Aim)).ToArray());
|
|
|
|
// break;
|
|
|
|
// default:
|
|
|
|
// PlayAnimation(root.SearchKey.Append(nameof(BITConstant.Player.Aim)).ToArray());
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
base.OnStateEntry(old);
|
|
|
|
|
2023-11-15 23:54:54 +08:00
|
|
|
_entityMovement.ExecuteCommand<PlayerPauseRunCommand>(new(this,true));
|
2023-11-30 00:23:23 +08:00
|
|
|
|
|
|
|
_entityMovement.ExecuteCommand(new PlayerLimitMoveSpeedCommand()
|
|
|
|
{
|
|
|
|
Id = BITHash.Player.Aim,
|
|
|
|
Limit =true,
|
|
|
|
Speed = root._gun.InitialAimMovementSpeed,
|
|
|
|
});
|
2023-11-02 20:58:55 +08:00
|
|
|
}
|
|
|
|
public override void OnStateExit(IState old, IState newState)
|
|
|
|
{
|
|
|
|
base.OnStateExit(old, newState);
|
2023-11-15 23:54:54 +08:00
|
|
|
_entityMovement.ExecuteCommand<PlayerPauseRunCommand>(new(this,false));
|
2023-11-30 00:23:23 +08:00
|
|
|
|
|
|
|
_entityMovement.ExecuteCommand(new PlayerLimitMoveSpeedCommand()
|
|
|
|
{
|
|
|
|
Id = BITHash.Player.Aim,
|
|
|
|
Limit =false,
|
|
|
|
Speed = root._gun.InitialAimMovementSpeed,
|
|
|
|
});
|
2024-03-29 00:58:24 +08:00
|
|
|
|
|
|
|
equipService.Aim = 0;
|
2023-06-08 14:09:50 +08:00
|
|
|
}
|
2023-08-23 01:59:40 +08:00
|
|
|
|
2023-08-27 02:58:19 +08:00
|
|
|
public override void OnStateUpdate(float deltaTime)
|
2023-06-08 14:09:50 +08:00
|
|
|
{
|
2023-08-23 01:59:40 +08:00
|
|
|
if (root.expectFiring.shouldBe && root.fireInterval.AllowUpdate)
|
2023-06-08 14:09:50 +08:00
|
|
|
{
|
|
|
|
root.Fire();
|
|
|
|
}
|
|
|
|
|
2024-03-25 16:08:26 +08:00
|
|
|
equipService.Aim = currentState.Weight;
|
|
|
|
|
2023-06-08 14:09:50 +08:00
|
|
|
if (BITAppForUnity.AllowCursor)
|
|
|
|
{
|
2023-08-23 01:59:40 +08:00
|
|
|
root.TransitionState<Movement>();
|
2023-06-08 14:09:50 +08:00
|
|
|
}
|
2023-08-23 01:59:40 +08:00
|
|
|
else if (root.expectAiming.shouldBe)
|
2023-06-08 14:09:50 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-08-23 01:59:40 +08:00
|
|
|
root.TransitionState<Movement>();
|
2023-06-08 14:09:50 +08:00
|
|
|
}
|
|
|
|
}
|
2023-08-23 01:59:40 +08:00
|
|
|
|
|
|
|
public override void OnMovementStateChanged(IEntityMovementState old, IEntityMovementState newState)
|
2023-06-08 14:09:50 +08:00
|
|
|
{
|
2023-08-23 01:59:40 +08:00
|
|
|
if (Enabled is false) return;
|
2023-09-01 14:33:54 +08:00
|
|
|
if (newState is not (IPlayerRunState or IPlayerSprintState)) return;
|
|
|
|
root.expectAiming.Reset();
|
|
|
|
root.TransitionState<Movement>();
|
2023-06-08 14:09:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
[System.Serializable]
|
2024-03-29 00:58:24 +08:00
|
|
|
public sealed class Draw : GunState
|
2023-06-08 14:09:50 +08:00
|
|
|
{
|
2023-11-21 18:05:18 +08:00
|
|
|
[Inject]
|
|
|
|
private IPlayerEquipSelector _equipSelector;
|
|
|
|
|
2023-10-20 19:31:12 +08:00
|
|
|
public override void Initialize()
|
|
|
|
{
|
|
|
|
base.Initialize();
|
2023-11-21 18:05:18 +08:00
|
|
|
_equipSelector.OnUpdateEquip += OnUpdateEquip;
|
2023-10-20 19:31:12 +08:00
|
|
|
}
|
2023-11-21 18:05:18 +08:00
|
|
|
private readonly List<int> _drawed = new();
|
|
|
|
private void OnUpdateEquip(IDictionary<int, IBasicItem> obj)
|
|
|
|
{
|
|
|
|
foreach (var x in _drawed.ToArray())
|
|
|
|
{
|
|
|
|
if (obj.Any(pair => _drawed.Contains(pair.Value.Id)) is false)
|
|
|
|
{
|
|
|
|
_drawed.Remove(x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-23 18:07:54 +08:00
|
|
|
protected override void OnEnd()
|
2023-10-20 19:31:12 +08:00
|
|
|
{
|
2024-03-23 18:07:54 +08:00
|
|
|
root.TransitionState<Movement>();
|
2023-10-20 19:31:12 +08:00
|
|
|
}
|
|
|
|
|
2023-08-23 01:59:40 +08:00
|
|
|
public override void OnStateEntry(IState old)
|
2023-06-08 14:09:50 +08:00
|
|
|
{
|
2023-11-21 18:05:18 +08:00
|
|
|
base.OnStateEntry(old);
|
|
|
|
if (_drawed.TryAdd(root.Item.Id))
|
|
|
|
{
|
2024-03-29 00:58:24 +08:00
|
|
|
PlayAnimation(nameof(BITConstant.Player.Draw));
|
2023-11-30 00:23:23 +08:00
|
|
|
root.UnityEntity.Invoke(Constant.Animation.Play, BITConstant.Player.Draw);
|
2023-11-21 18:05:18 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-03-29 00:58:24 +08:00
|
|
|
PlayAnimation(nameof(BITConstant.Player.QuickDraw));
|
2023-11-30 00:23:23 +08:00
|
|
|
root.UnityEntity.Invoke(Constant.Animation.Play, BITConstant.Player.QuickDraw);
|
2023-11-21 18:05:18 +08:00
|
|
|
}
|
2023-11-15 23:54:54 +08:00
|
|
|
_entityMovement.ExecuteCommand<PlayerPauseRunCommand>(new(this,true));
|
2023-06-08 14:09:50 +08:00
|
|
|
}
|
2023-11-15 23:54:54 +08:00
|
|
|
public override void OnStateExit(IState old, IState newState)
|
|
|
|
{
|
|
|
|
base.OnStateExit(old, newState);
|
|
|
|
_entityMovement.ExecuteCommand<PlayerPauseRunCommand>(new(this,false));
|
|
|
|
}
|
2023-08-23 01:59:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[System.Serializable]
|
2023-10-20 19:31:12 +08:00
|
|
|
public sealed class Reload:GunState
|
2023-08-23 01:59:40 +08:00
|
|
|
{
|
2024-03-31 23:34:22 +08:00
|
|
|
[SerializeField] private GameObject reserveMagazine;
|
|
|
|
public override void Initialize()
|
|
|
|
{
|
|
|
|
base.Initialize();
|
|
|
|
if(reserveMagazine)
|
|
|
|
reserveMagazine.SetActive(false);
|
|
|
|
}
|
|
|
|
|
2024-03-23 18:07:54 +08:00
|
|
|
protected override void OnEnd()
|
2023-08-23 01:59:40 +08:00
|
|
|
{
|
2024-03-23 18:07:54 +08:00
|
|
|
root.TransitionState<Movement>();
|
2023-08-23 01:59:40 +08:00
|
|
|
}
|
|
|
|
public override void OnStateEntry(IState old)
|
|
|
|
{
|
2024-03-31 23:34:22 +08:00
|
|
|
if(reserveMagazine)
|
|
|
|
reserveMagazine.SetActive(true);
|
2023-08-23 01:59:40 +08:00
|
|
|
base.OnStateEntry(old);
|
2024-03-25 16:08:26 +08:00
|
|
|
|
2023-11-15 23:54:54 +08:00
|
|
|
_entityMovement.ExecuteCommand<PlayerPauseRunCommand>(new(this,true));
|
2023-10-31 18:07:15 +08:00
|
|
|
|
|
|
|
if (root.RequireBolt)
|
|
|
|
{
|
|
|
|
root.UnityEntity.Invoke(Constant.Animation.Play, BITConstant.Player.BoltAction);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
root.UnityEntity.Invoke(Constant.Animation.Play, BITConstant.Player.Reload);
|
|
|
|
}
|
|
|
|
|
2023-08-23 01:59:40 +08:00
|
|
|
}
|
|
|
|
public override void OnMovementStateChanged(IEntityMovementState old, IEntityMovementState newState)
|
|
|
|
{
|
|
|
|
if (Enabled is false) return;
|
|
|
|
if (newState is IPlayerRunState or IPlayerSprintState)
|
|
|
|
{
|
|
|
|
root.TransitionState<Movement>();
|
|
|
|
}
|
2023-06-08 14:09:50 +08:00
|
|
|
}
|
2023-08-27 02:58:19 +08:00
|
|
|
|
2023-10-31 18:07:15 +08:00
|
|
|
public override void OnStateExit(IState old, IState newState)
|
|
|
|
{
|
|
|
|
root.RequireBolt = false;
|
|
|
|
base.OnStateExit(old, newState);
|
2023-11-15 23:54:54 +08:00
|
|
|
_entityMovement.ExecuteCommand<PlayerPauseRunCommand>(new(this,false));
|
2024-03-31 23:34:22 +08:00
|
|
|
if(reserveMagazine)
|
|
|
|
reserveMagazine.SetActive(false);
|
2023-10-31 18:07:15 +08:00
|
|
|
}
|
|
|
|
}
|
2023-08-27 02:58:19 +08:00
|
|
|
[System.Serializable]
|
2023-10-20 19:31:12 +08:00
|
|
|
public sealed class Melee : GunState
|
2023-08-27 02:58:19 +08:00
|
|
|
{
|
2024-03-31 23:34:22 +08:00
|
|
|
[SerializeField] private GameObject knife;
|
|
|
|
private bool isKnife;
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
{
|
|
|
|
base.Initialize();
|
|
|
|
if (knife)
|
|
|
|
knife.gameObject.SetActive(false);
|
|
|
|
}
|
|
|
|
|
2024-03-23 18:07:54 +08:00
|
|
|
protected override void OnEnd()
|
2023-08-27 02:58:19 +08:00
|
|
|
{
|
2024-03-23 18:07:54 +08:00
|
|
|
root.TransitionState<Movement>();
|
2023-08-27 02:58:19 +08:00
|
|
|
}
|
2024-03-31 23:34:22 +08:00
|
|
|
|
2023-08-27 02:58:19 +08:00
|
|
|
public override void OnStateEntry(IState old)
|
|
|
|
{
|
2024-03-31 23:34:22 +08:00
|
|
|
if (root._equipmentContainer.Equipment.TryGetValue(new EquipmentAsThrow(), out var throwItem))
|
|
|
|
{
|
|
|
|
isKnife = throwItem.GetAssetable().TryGetProperty<AllowQuickKnife>(out _);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
isKnife = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isKnife)
|
|
|
|
{
|
|
|
|
PlayAnimation("QuickKnife");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PlayAnimation();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (knife && isKnife)
|
|
|
|
knife.gameObject.SetActive(true);
|
|
|
|
//base.OnStateEntry(old);
|
|
|
|
|
|
|
|
|
2023-10-30 01:25:53 +08:00
|
|
|
root.UnityEntity.Invoke(Constant.Animation.Play, BITConstant.Player.Melee);
|
2024-03-31 23:34:22 +08:00
|
|
|
_entityMovement.ExecuteCommand<PlayerPauseRunCommand>(new(this, true));
|
|
|
|
|
2023-11-30 00:23:23 +08:00
|
|
|
_entityMovement.ExecuteCommand(new PlayerFocusCommand()
|
|
|
|
{
|
|
|
|
Focus = true,
|
|
|
|
Sender = this
|
|
|
|
});
|
2024-03-29 00:58:24 +08:00
|
|
|
|
|
|
|
root.inputActionGroup.RegisterCallback(root.meleeAction, OnMelee);
|
2023-08-27 02:58:19 +08:00
|
|
|
}
|
2023-09-01 14:33:54 +08:00
|
|
|
|
|
|
|
public override void OnStateExit(IState old, IState newState)
|
|
|
|
{
|
2024-04-19 00:40:34 +08:00
|
|
|
base.OnStateExit(old, newState);
|
|
|
|
_entityMovement.ExecuteCommand<PlayerPauseRunCommand>(new(this, false));
|
|
|
|
|
2024-03-29 00:58:24 +08:00
|
|
|
root.inputActionGroup.UnRegisterCallback(root.meleeAction, OnMelee);
|
2024-04-19 00:40:34 +08:00
|
|
|
|
2023-11-30 00:23:23 +08:00
|
|
|
_entityMovement.ExecuteCommand(new PlayerFocusCommand()
|
|
|
|
{
|
|
|
|
Focus = false,
|
|
|
|
Sender = this
|
|
|
|
});
|
2024-04-19 00:40:34 +08:00
|
|
|
if (knife)
|
|
|
|
knife.gameObject.SetActive(false);
|
2023-09-01 14:33:54 +08:00
|
|
|
}
|
2024-04-19 00:40:34 +08:00
|
|
|
|
2024-03-29 00:58:24 +08:00
|
|
|
private void OnMelee(InputAction.CallbackContext obj)
|
2023-08-27 02:58:19 +08:00
|
|
|
{
|
2024-03-29 00:58:24 +08:00
|
|
|
if (obj.performed is false) return;
|
|
|
|
if (!(currentState.NormalizedTime > 0.5f)) return;
|
|
|
|
currentState.Events.OnEnd = null;
|
|
|
|
currentState.Stop();
|
|
|
|
PlayAnimation();
|
2023-08-27 02:58:19 +08:00
|
|
|
}
|
|
|
|
public override void OnMovementStateChanged(IEntityMovementState old, IEntityMovementState newState)
|
|
|
|
{
|
|
|
|
if (Enabled is false) return;
|
|
|
|
if (newState is IPlayerRunState or IPlayerSprintState)
|
|
|
|
{
|
|
|
|
root.TransitionState<Movement>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[System.Serializable]
|
2023-10-20 19:31:12 +08:00
|
|
|
public sealed class Climb:GunState
|
2023-08-27 02:58:19 +08:00
|
|
|
{
|
|
|
|
public override void OnStateEntry(IState old)
|
|
|
|
{
|
2023-11-15 23:54:54 +08:00
|
|
|
base.OnStateEntry(old);
|
|
|
|
_entityMovement.ExecuteCommand<PlayerPauseRunCommand>(new(this,true));
|
|
|
|
}
|
|
|
|
public override void OnStateExit(IState old, IState newState)
|
|
|
|
{
|
|
|
|
base.OnStateExit(old, newState);
|
|
|
|
_entityMovement.ExecuteCommand<PlayerPauseRunCommand>(new(this,false));
|
2024-04-19 00:40:34 +08:00
|
|
|
currentState = null;
|
2023-08-27 02:58:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void OnMovementStateChanged(IEntityMovementState old, IEntityMovementState newState)
|
|
|
|
{
|
2024-02-21 01:40:53 +08:00
|
|
|
switch (newState)
|
|
|
|
{
|
|
|
|
case IPlayerClimbState:
|
|
|
|
case IPlayerLinkState { LinkArea: 44 }:
|
|
|
|
case IPlayerVaultState:
|
2024-04-19 00:40:34 +08:00
|
|
|
if (Enabled || currentState is not null)
|
2024-03-29 00:58:24 +08:00
|
|
|
{
|
2024-04-19 00:40:34 +08:00
|
|
|
currentState.Time = 0;
|
|
|
|
//currentState.Stop();
|
|
|
|
//PlayAnimation();
|
2024-03-29 00:58:24 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
root.TransitionState<Climb>();
|
|
|
|
}
|
2024-02-21 01:40:53 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (Enabled)
|
|
|
|
{
|
|
|
|
root.TransitionState<Movement>();
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
2023-08-27 02:58:19 +08:00
|
|
|
}
|
|
|
|
}
|
2023-10-20 19:31:12 +08:00
|
|
|
|
|
|
|
[System.Serializable]
|
|
|
|
public sealed class Holster : GunState
|
|
|
|
{
|
2024-03-23 18:07:54 +08:00
|
|
|
protected override void OnEnd()
|
2023-10-20 19:31:12 +08:00
|
|
|
{
|
2024-03-23 18:07:54 +08:00
|
|
|
animancerComponent.Stop();
|
2023-10-20 19:31:12 +08:00
|
|
|
}
|
|
|
|
}
|
2024-03-29 00:58:24 +08:00
|
|
|
[Serializable]
|
|
|
|
public sealed class Tactics : GunState
|
|
|
|
{
|
|
|
|
public override void OnStateEntry(IState old)
|
|
|
|
{
|
|
|
|
base.OnStateEntry(old);
|
|
|
|
_entityMovement.ExecuteCommand<PlayerPauseRunCommand>(new(this,true));
|
|
|
|
}
|
|
|
|
public override void OnStateExit(IState old, IState newState)
|
|
|
|
{
|
|
|
|
base.OnStateExit(old, newState);
|
|
|
|
_entityMovement.ExecuteCommand<PlayerPauseRunCommand>(new(this,false));
|
|
|
|
}
|
|
|
|
protected override void OnEnd()
|
|
|
|
{
|
|
|
|
base.OnEnd();
|
|
|
|
root.TransitionState<Movement>();
|
|
|
|
}
|
|
|
|
}
|
2023-06-08 14:09:50 +08:00
|
|
|
}
|