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; this.SwitchToMovementState (); if (!this.IsActiveState) return; 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 m_ped.TryEnterVehicleInRange (); } public override void OnCrouchButtonPressed () { m_ped.SwitchState(); } public override void OnFlyButtonPressed () { m_ped.GetStateOrLogError ().EnterState (false); } public override void OnFlyThroughButtonPressed () { m_ped.GetStateOrLogError ().EnterState (true); } } }