using UnityEngine; using SanAndreasUnity.Utilities; using SanAndreasUnity.Importing.Animation; namespace SanAndreasUnity.Behaviours.Peds.States { /// /// Base class for all movement states. /// public abstract class BaseMovementState : BaseScriptState { public abstract AnimId movementAnim { get; } public abstract AnimId movementWeaponAnim { get; } public override void UpdateState() { base.UpdateState (); if (!this.IsActiveState) return; if (m_isServer) this.SwitchToMovementState (); if (!this.IsActiveState) return; if (m_isServer) this.SwitchToAimState (); } protected virtual void SwitchToMovementState() { BaseMovementState.SwitchToMovementStateBasedOnInput (m_ped); } public static void SwitchToMovementStateBasedOnInput (Ped ped) { if (ped.IsJumpOn && ped.GetStateOrLogError().CanJump()) { ped.GetState().Jump(); } else if (ped.IsWalkOn) { ped.SwitchState (); } else if (ped.IsRunOn) { ped.SwitchState (); } else if (ped.IsSprintOn) { if (ped.CurrentWeapon != null && !ped.CurrentWeapon.CanSprintWithIt) ped.SwitchState (); else ped.SwitchState (); } else { ped.SwitchState (); } } protected virtual void SwitchToAimState() { if (m_ped.IsAimOn && m_ped.IsHoldingWeapon) { BaseAimMovementState.SwitchToAimMovementStateBasedOnInput (m_ped); } } protected override void UpdateAnims () { if (m_ped.CurrentWeapon != null) { m_ped.PlayerModel.PlayAnim (this.movementWeaponAnim); } else { m_ped.PlayerModel.PlayAnim (this.movementAnim); } } public override void OnSubmitPressed() { // try to enter vehicle if (m_isServer) m_ped.TryEnterVehicleInRange (); else base.OnSubmitPressed(); } public override void OnCrouchButtonPressed () { if (m_isServer) m_ped.SwitchState(); else base.OnCrouchButtonPressed(); } public override void OnFlyButtonPressed () { if (m_isServer) m_ped.GetStateOrLogError ().EnterState (false); } public override void OnFlyThroughButtonPressed () { if (m_isServer) m_ped.GetStateOrLogError ().EnterState (true); } } }