using System.Data.Odbc; using BITFALL.Player.Equip; using BITFALL.Player.Movement; using BITKit; using BITKit.Entities; using BITKit.Selection; using UnityEngine.InputSystem; using BITKit.StateMachine; using UnityEngine; namespace BITFALL.Guns.States { [System.Serializable] public sealed class None:GunState { } [System.Serializable] public class Movement : GunState { [SerializeField] private ExpectState _expectRun; [Inject] protected ISelector _selector; public override void OnStateEntry(IState old) { switch (old) { case Aim: root.animator.CrossFade(BITConstant.Player.Movement, 0.32f); break; default: root.animator.CrossFade(BITConstant.Player.Movement, 0.16f); break; } _selector.OnActive += OnActive; } public override void OnStateExit(IState old, IState newState) { base.OnStateExit(old, newState); _selector.OnActive -= OnActive; } public override void OnStateUpdate(float deltaTime) { if (root.animator[0].stateName is not BITConstant.Player.Movement) return; if (root.expectFiring.shouldBe && root.fireInterval.AllowUpdate) { root.Fire(); } if (root.expectAiming.shouldBe && BITAppForUnity.AllowCursor == false) { root.TransitionState(); }else if (_expectRun) { root.TransitionState(); } } public void OnActive(ISelectable selectable) { root.animator.Play(BITConstant.Player.Interactive); } public override void OnMovementStateChanged(IEntityMovementState old, IEntityMovementState newState) { _expectRun = newState is IPlayerRunState or IPlayerSprintState; if (newState is IPlayerSlideState) { root.TransitionState(); root.animator.CrossFade(BITConstant.Player.Slide, 0.32f); } } } [System.Serializable] public sealed class Run : GunState { private ExpectState _expectRun; private ExpectState _expectSprint; public override void OnStateEntry(IState old) { root.animator.CrossFade(BITConstant.Player.Run, 0.16f); root.inputActionGroup.RegisterCallback(root.aimAction, OnAim); } public override void OnStateExit(IState old, IState newState) { root.inputActionGroup.UnRegisterCallback(root.aimAction, OnAim); } public override void OnStateUpdate(float deltaTime) { if (root.animator[0].stateName == BITConstant.Player.Movement) { root.animator.CrossFade(BITConstant.Player.Run, 0.32f); } if(_expectSprint) { root.TransitionState(); } else if(_expectRun == false) { root.TransitionState(); } } private void OnAim(InputAction.CallbackContext context) { if (context.started && BITAppForUnity.AllowCursor == false) { root.TransitionState(); } } public override void OnMovementStateChanged(IEntityMovementState old, IEntityMovementState newState) { _expectRun = newState is IPlayerRunState or IPlayerSprintState; _expectSprint = newState is IPlayerSprintState; } } [System.Serializable] public sealed class Sprint : GunState { private ExpectState _expectSprint; public override void OnStateEntry(IState old) { root.animator.CrossFade(BITConstant.Player.Sprint, 0.32f); root.inputActionGroup.RegisterCallback(root.aimAction, OnAim); } public override void OnStateExit(IState old, IState newState) { root.inputActionGroup.UnRegisterCallback(root.aimAction, OnAim); } public override void OnStateUpdate(float deltaTime) { if(_expectSprint == false) { root.TransitionState(); } } private void OnAim(InputAction.CallbackContext context) { if (context.started && BITAppForUnity.AllowCursor == false) { root.TransitionState(); } } public override void OnMovementStateChanged(IEntityMovementState old, IEntityMovementState newState) { _expectSprint = newState is IPlayerSprintState; } } [System.Serializable] public sealed class Aim : GunState { [Inject] private IEquipService _equipService; public override void OnStateEntry(IState old) { switch (old) { case IPlayerRunState: case IPlayerSprintState: root.animator.CrossFade(BITConstant.Player.Aim, 0.32f); break; default: root.animator.CrossFade(BITConstant.Player.Aim, 0.16f); break; } _equipService.Zoom.Allow = true; _entityMovement.ExecuteCommand(); } public override void OnStateUpdate(float deltaTime) { if (root.expectFiring.shouldBe && root.fireInterval.AllowUpdate) { root.Fire(); } if (BITAppForUnity.AllowCursor) { root.TransitionState(); } else if (root.expectAiming.shouldBe) { } else { root.TransitionState(); } _equipService.Zoom.Value = root.aimAction.action.ReadValue(); } public override void OnStateExit(IState old, IState newState) { base.OnStateExit(old, newState); _equipService.Zoom.Allow = false; } public override void OnMovementStateChanged(IEntityMovementState old, IEntityMovementState newState) { if (Enabled is false) return; if (newState is not (IPlayerRunState or IPlayerSprintState)) return; root.expectAiming.Reset(); root.TransitionState(); } } [System.Serializable] public sealed class Equip : GunState { private bool completed; public override void Initialize() { base.Initialize(); root.animator[0].onStateExit += OnAnimationStateExit; } private void OnAnimationStateExit(string obj) { if (obj is BITConstant.Player.Equip) completed = true; } public override void OnStateEntry(IState old) { completed = false; root.animator.Play(BITConstant.Player.Equip,-1,0); root.animator.animator.Update(0); } public override void OnStateUpdate(float deltaTime) { var state = root.animator[0]; if (state.stateName == BITConstant.Player.Equip) { if (completed) { root.TransitionState(); } } else { root.animator.Play(BITConstant.Player.Equip); } } } [System.Serializable] public sealed class Reload:GunState { public override void Initialize() { base.Initialize(); root.animator[0].onStateExit += OnAnimationStateExit; } private void OnAnimationStateExit(string obj) { if (Enabled is false) return; if(obj is BITConstant.Player.Reload) { root.TransitionState(); } } public override void OnStateEntry(IState old) { base.OnStateEntry(old); _entityMovement.ExecuteCommand(); root.UnityEntity.Invoke(Constant.Animation.Play, BITConstant.Player.Reload); } public override void OnMovementStateChanged(IEntityMovementState old, IEntityMovementState newState) { if (Enabled is false) return; if (newState is IPlayerRunState or IPlayerSprintState) { root.TransitionState(); } } } [System.Serializable] public sealed class Melee : GunState { public override void Initialize() { base.Initialize(); root.animator[0].onStateExit += OnAnimationStateExit; } private void OnAnimationStateExit(string obj) { if (Enabled is false) return; if (obj is BITConstant.Player.Melee) { root.TransitionState(); } } public override void OnStateEntry(IState old) { root.animator.Play(BITConstant.Player.Melee); _entityMovement.ExecuteCommand(new PlayerDisableRunCommand(this)); } public override void OnStateExit(IState old, IState newState) { _entityMovement.ExecuteCommand(new PlayerEnableRunCommand(this)); } public override void OnStateUpdate(float deltaTime) { _entityMovement.ExecuteCommand(); } public override void OnMovementStateChanged(IEntityMovementState old, IEntityMovementState newState) { if (Enabled is false) return; if (newState is IPlayerRunState or IPlayerSprintState) { root.TransitionState(); } } } [System.Serializable] public sealed class Climb:GunState { public override void OnStateEntry(IState old) { root.animator.Play(BITConstant.Player.Climb); } public override void OnMovementStateChanged(IEntityMovementState old, IEntityMovementState newState) { if(newState is IPlayerClimbState || (newState is IPlayerLinkState linkState && linkState.LinkArea == 4) ) { root.TransitionState(); }else if (Enabled) { root.TransitionState(); } } } [System.Serializable] public sealed class Holster : GunState { public override void OnStateEntry(IState old) { root.animator.CrossFade(BITConstant.Player.Holster,0.16f); } } }