using System.Data.Odbc; using BITFALL.Player.Equip; using BITFALL.Player.Movement; using BITKit; using BITKit.Entities; using UnityEngine.InputSystem; using BITKit.StateMachine; using UnityEngine; namespace BITFALL.Guns.States { [System.Serializable] public class Movement : GunState, ISelectableCallback { [SerializeField] private ExpectState _expectRun; public override void OnStateEntry(IState old) { switch (old) { case Aim: root.animator.CrossFade(BITGun._Movement, 0.32f); break; default: root.animator.CrossFade(BITGun._Movement, 0.16f); break; } root.Entity.RegisterCallback(this); } public override void OnStateExit(IState old, IState newState) { base.OnStateExit(old, newState); root.Entity.UnRegisterCallback(this); } public override void OnStateUpdate(float deltaTime) { if (root.animator[0].stateName is not BITGun._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(); } root.expectAiming.shouldBe = root.aimAction.action.IsPressed(); } public void OnHover(ISelectable selectable) { } public void OnActive(ISelectable selectable) { root.animator.Play(BITGun._Interactive); } public void OnInactive(ISelectable selectable) { } public override void OnMovementStateChanged(IEntityMovementState old, IEntityMovementState newState) { _expectRun = newState is IPlayerRunState or IPlayerSprintState; } } [System.Serializable] public class Run : GunState { private ExpectState _expectRun; private ExpectState _expectSprint; public override void OnStateEntry(IState old) { root.animator.CrossFade(BITGun._Run, 0.16f); root.actionGroup.RegisterCallback(root.aimAction, OnAim); } public override void OnStateExit(IState old, IState newState) { root.actionGroup.UnRegisterCallback(root.aimAction, OnAim); } public override void OnStateUpdate(float deltaTime) { if (root.animator[0].stateName == BITGun._Movement) { root.animator.CrossFade(BITGun._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 class Sprint : GunState { private ExpectState _expectSprint; public override void OnStateEntry(IState old) { root.animator.CrossFade(BITGun._Sprint, 0.32f); root.actionGroup.RegisterCallback(root.aimAction, OnAim); } public override void OnStateExit(IState old, IState newState) { root.actionGroup.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 class Aim : GunState { private IEntityMovement _entityMovement; private IEquipService _equipService; public override void Initialize() { base.Initialize(); _entityMovement = root.Entity.Get(); _equipService = root.Entity.Get(); } public override void OnStateEntry(IState old) { switch (old) { case IPlayerRunState: case IPlayerSprintState: root.animator.CrossFade(BITGun._Aim, 0.32f); break; default: root.animator.CrossFade(BITGun._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 class Equip : GunState { private IntervalUpdate interval = new(0.16f); public override void OnStateEntry(IState old) { interval.Reset(); root.animator.Play(BITGun._Equip); } public override void OnStateUpdate(float deltaTime) { var state = root.animator[0]; if (!interval.AllowUpdateWithoutReset) return; if (state.stateName == BITGun._Equip) { if (state.currentState.normalizedTime >= 1) { root.TransitionState(); } } else { root.animator.Play(BITGun._Equip); } } } [System.Serializable] public class Reload:GunState { private IEntityMovement _entityMovement; public override void Initialize() { base.Initialize(); _entityMovement = root.Entity.Get(); root.animator[0].onStateExit += OnAnimationStateExit; } private void OnAnimationStateExit(string obj) { if (Enabled is false) return; if(obj is BITGun._Reload) { root.TransitionState(); } } public override void OnStateEntry(IState old) { base.OnStateEntry(old); _entityMovement.ExecuteCommand(); root.animator.Play(BITGun._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 class Melee : GunState { private IEntityMovement _entityMovement; public override void Initialize() { base.Initialize(); _entityMovement = root.Entity.Get(); root.animator[0].onStateExit += OnAnimationStateExit; } private void OnAnimationStateExit(string obj) { if (Enabled is false) return; if (obj is BITGun._Melee) { root.TransitionState(); } } public override void OnStateEntry(IState old) { root.animator.Play(BITGun._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 class Climb:GunState { public override void OnStateEntry(IState old) { root.animator.Play(BITGun._Climb); } public override void OnMovementStateChanged(IEntityMovementState old, IEntityMovementState newState) { if(newState is IPlayerClimbState) { root.TransitionState(); }else if (Enabled) { root.TransitionState(); } } } }