using NBC;
using UnityEngine;

namespace NBF
{
    /// <summary>
    /// 准备抛竿中
    /// </summary>
    public class PlayerStatePrepare : PlayerStateBase
    {
        public override uint StateId => (uint)PlayerState.Prepare;

        public enum Phase
        {
            /// <summary>
            /// 蓄力
            /// </summary>
            Charged,

            /// <summary>
            /// 确认蓄力结果
            /// </summary>
            Confirm,
        }

        public Phase Stage = Phase.Charged;
        public float ChargedProgress;

        protected override void onEnter()
        {
            Log.Info("enter PlayerStatePrepare");
            Stage = Phase.Charged;
            Player.ModelAsset.PlayerAnimator.PrepareThrow = true;
            Player.ModelAsset.PlayerAnimator.FishingUp = 0;
        }

        protected override uint onUpdate()
        {
            if (Stage == Phase.Charged)
            {
                ThrowPowerCharged();
            }
            else if (Stage == Phase.Confirm)
            {
                //确认蓄力结果，
                Debug.Log($"确认蓄力结果,ChargedProgress={ChargedProgress}");
                Params.Add(ChargedProgress);
                return (uint)PlayerState.Throw;
            }

            return base.onUpdate();
        }


        #region 蓄力中

        private void ThrowPowerCharged()
        {
            if (ChargedProgress < 1)
            {
                ChargedProgress += Time.deltaTime;
            }
            else if (ChargedProgress > 1)
            {
                ChargedProgress = 1;
            }
            
            if (!InputManager.IsOp1)
            {
                Stage = Phase.Confirm;
            }
        }

        #endregion
    }
}