Exemplo n.º 1
0
    override public void OnEnter(PlayerState lastState)
    {
        base.OnEnter(lastState);

        bool bFromPrepareShoot = lastState.m_eState == State.ePrepareToShoot;

        m_skillArea = m_match.mCurScene.mGround.GetArea(m_player);

        if (!bFromPrepareShoot)
        {
            if (lastState.m_eState == State.eRun || lastState.m_eState == State.eRush)
            {
                PlaySoundManager.Instance.PlaySound(MatchSoundEvent.RunToShoot);
            }

            IM.RootMotion rootMotion = m_player.animMgr.GetRootMotion(m_curAction);
            rootMotion.Reset();
            IM.Vector3 dirPlayerToBasket = GameUtils.HorizonalNormalized(m_basket.m_vShootTarget, m_player.position);
            rootMotion.dirMove = dirPlayerToBasket;
        }

        if (m_curAction.Length == 0)
        {
            Debug.Log("no shoot animation.");
        }
        else
        {
            m_player.animMgr.Play(m_curAction, true);
        }

        m_ball.m_shootArea = (Area)m_curExecSkill.skill.area[0];
        m_ball.m_ballState = BallState.eUseBall_Shoot;

        m_player.mStatistics.ReadyToCountShoot();

        PlayerAnimAttribute.AnimAttr shootAttr = m_player.m_animAttributes.GetAnimAttrById(Command.Shoot, m_curAction);

        int iPrepareFrame = 0;

        PlayerAnimAttribute.KeyFrame prepareFrame = shootAttr.GetKeyFrame("OnPrepareToShoot");
        if (prepareFrame != null)
        {
            iPrepareFrame = prepareFrame.frame;
        }

        IM.Number frameRate = m_player.animMgr.GetFrameRate(m_curAction);
        m_player.m_blockable.Init(shootAttr, frameRate, iPrepareFrame);

        if (m_skillArea == Area.eFar)
        {
            ++m_player.mStatistics.data.far_shoot;
        }
        else if (m_skillArea == Area.eNear)
        {
            ++m_player.mStatistics.data.near_shoot;
        }
        else if (m_skillArea == Area.eMiddle)
        {
            ++m_player.mStatistics.data.mid_shoot;
        }
    }
    override public void OnEnter(PlayerState lastState)
    {
        base.OnEnter(lastState);

        tooLate = false;

        //Debug.Log("rebound action is: " + m_curAction );

        m_heightScale = IM.Number.one;
        m_success     = true;
        if (m_ball.m_bGoal)
        {
            m_success = false;
        }
        if (m_ball.m_picker != null)
        {
            m_success = false;
        }
        if (m_ball.m_ballState != BallState.eRebound)
        {
            m_success = false;
        }

        Dictionary <string, uint> skillAttr = m_player.GetSkillAttribute();
        Dictionary <string, uint> data      = m_player.m_finalAttrs;

        if (data == null)
        {
            Debug.LogError("Can not find data.");
            m_success = false;
        }
        if (!m_match.m_ruler.CanRebound() || m_ball.m_owner != null)
        {
            m_success = false;
            tooLate   = false;
            Debug.Log(m_player.m_name + " Rebound failed, ball haven't been reached the highest position or ball has owner");
        }

        //Debug.Log("Rebound distance:" + m_player.m_fReboundDist);
        IM.Number fDistPlayer2Ball = GameUtils.HorizonalDistance(m_player.position, m_ball.position);

        IM.Number reboundDist = PlayerState_Rebound.GetMaxDist(m_player);
        if (fDistPlayer2Ball > reboundDist)
        {
            m_success = false;
            Debug.Log("player to ball distance: " + fDistPlayer2Ball + " farther than rebound distance: " + reboundDist);
        }

        IM.Number minHeight, maxHeight;
        GetHeightRange(m_player, out minHeight, out maxHeight);

        IM.Number fEventTime = GetEventTime(m_player, m_curAction);

        if (m_success)
        {
            IM.Vector3 vBallPosRebound;
            IM.Number  fCurTime     = m_ball.m_fTime;
            IM.Number  fHighestTime = m_ball.CompleteLastCurve().GetHighestTime();
            if (fCurTime + fEventTime < fHighestTime)   //������
            {
                m_success = false;
                tooLate   = false;
                Debug.Log("Rebound failed, ball not in falling.");
            }
            else if (m_ball.GetPositionInAir((fCurTime + fEventTime), out vBallPosRebound))
            {
                if (vBallPosRebound.y > minHeight && vBallPosRebound.y < maxHeight)
                {
                    //Debugger.Instance.DrawSphere("Rebound", vBallPosRebound, Color.red);
                    m_player.FaceTo(vBallPosRebound);
                    IM.Vector3 reboundAnimBall;
                    m_player.GetNodePosition(SampleNode.Ball, m_curAction, fEventTime, out reboundAnimBall);
                    m_heightScale = vBallPosRebound.y / reboundAnimBall.y;

                    IM.Vector3 root;
                    m_player.GetNodePosition(SampleNode.Root, m_curAction, fEventTime, out root);
                    IM.Vector3 root2Ball = reboundAnimBall - root;

                    IM.Number fDistPlayerToReboundPos = GameUtils.HorizonalDistance(vBallPosRebound - root2Ball, m_player.position);
                    IM.Number fDistOrigReboundPos     = GameUtils.HorizonalDistance(root, m_player.position);
                    rootMotionScale = fDistPlayerToReboundPos / fDistOrigReboundPos;
                    //Debug.Log("root motion scale: " + m_player.m_rootMotion.m_scale);
                }
                else
                {
                    m_success = false;
                    tooLate   = vBallPosRebound.y <= minHeight;
                    Debug.Log("Rebound failed, ball height: " + m_ball.transform.position.y + " height range: min: " + minHeight + " ,max: " + maxHeight);
                }
            }
            else
            {
                m_success = false;
                tooLate   = true;
                Debug.Log("reboundTime out of the curve, too slow");
            }
        }
        else
        {
            m_player.FaceTo(m_ball.position);
        }

        //m_curAction = m_mapAnimType[m_animType];
        IM.Vector3 vRoundScale = new IM.Vector3(rootMotionScale, m_heightScale, rootMotionScale);

        uint skillValue = 0;

        m_player.m_skillSystem.HegdingToValue("addn_rebound", ref skillValue);
        if (m_success)
        {
            m_match.reboundHelper.AddRebounder(m_player, m_curExecSkill);
        }

        ++m_player.mStatistics.data.rebound_times;
        if (m_success)
        {
            ++m_player.mStatistics.data.valid_rebound_times;
        }

        GameSystem.Instance.mClient.mPlayerManager.IsolateCollision(m_player, true);
        m_fEventTime = GetEventTime(m_player, m_curAction);
        IM.RootMotion rootMotion = m_player.animMgr.Play(m_curAction, true).rootMotion;
        rootMotion.scale = rootMotionScale;
        rootMotion.Reset();
    }
Exemplo n.º 3
0
    override public void OnEnter(PlayerState lastState)
    {
        UBasketball ball = m_ballToPickup;

        if (ball == null)
        {
            ball = m_match.mCurScene.mBall;
        }

        m_fSpeedRunWithoutBall = m_player.mMovements[(int)PlayerMovement.Type.eRunWithoutBall].mAttr.m_curSpeed;
        m_fSpeedRunWithBall    = m_player.mMovements[(int)PlayerMovement.Type.eRunWithBall].mAttr.m_curSpeed;
        m_turningSpeed         = m_player.mMovements[(int)PlayerMovement.Type.eRunWithBall].mAttr.m_TurningSpeed;

        IM.Number fBallHeight = ball.position.y;

        IM.Number fProb = new IM.Number(0, 800);
        if (m_player.m_position == fogs.proto.msg.PositionType.PT_C)
        {
            fProb = new IM.Number(0, 300);
        }
        else if (m_player.m_position == fogs.proto.msg.PositionType.PT_PF || m_player.m_position == fogs.proto.msg.PositionType.PT_SF)
        {
            fProb = IM.Number.half;
        }

        m_animType = AnimType.B_TYPE_0;
        if (fBallHeight < m_player.pelvisPos.y)
        {
            if (IM.Random.value < fProb)
            {
                m_animType = AnimType.B_TYPE_1;
            }
        }
        else
        {
            if (lastState.m_eState == PlayerState.State.eRun || lastState.m_eState == PlayerState.State.eRush)
            {
                m_animType = AnimType.B_TYPE_2;
            }
            else if (lastState.m_eState == PlayerState.State.eStand)
            {
                m_animType = AnimType.B_TYPE_3;
            }
        }
        m_bSuccess = true;
        m_player.GrabBall(m_ballToPickup);
        m_player.eventHandler.NotifyAllListeners(PlayerActionEventHandler.AnimEvent.ePickupBall);

        if (m_animType == AnimType.B_TYPE_1)
        {
            m_type = Type.eStoop;
            m_player.moveDirection = IM.Vector3.zero;
        }
        else if (m_animType == AnimType.B_TYPE_2)
        {
            m_type = Type.eRun;
        }
        else if (m_animType == AnimType.B_TYPE_3 || m_animType == AnimType.B_TYPE_0)
        {
            m_player.moveDirection = IM.Vector3.zero;
            m_type = Type.eStand;
        }

        m_curAction = m_mapAnimType[m_animType];

        m_speed = IM.Vector3.zero;
        IM.RootMotion rootMotion = m_player.animMgr.Play(m_curAction, true).rootMotion;
        rootMotion.Reset();
    }
Exemplo n.º 4
0
    override public void OnEnter(PlayerState lastState)
    {
        base.OnEnter(lastState);

        m_skillArea = m_match.mCurScene.mGround.GetArea(m_player);

        m_bLeaveGround  = false;
        m_movingTime    = IM.Number.zero;
        m_bMoving       = false;
        m_fFlyTimeOnAir = IM.Number.zero;

        PlayerAnimAttribute.AnimAttr dunkAttr = m_player.m_animAttributes.GetAnimAttrById(Command.Dunk, m_curAction);
        if (dunkAttr == null)
        {
            Debug.LogError("Current action: " + m_curAction + " in dunk id: " + m_curExecSkill.skill.id);
        }

        IM.Number frameRate = m_player.animMgr.GetFrameRate(m_curAction);
        m_player.m_blockable.Init(dunkAttr, frameRate);

        IM.RootMotion rootMotion = m_player.animMgr.GetRootMotion(m_curAction);
        rootMotion.Reset();

        IM.Vector3 vPlayer2Basket = m_basket.m_vShootTarget - m_player.position;
        vPlayer2Basket.y = IM.Number.zero;
        IM.Vector3 dirPlayerToBasket = vPlayer2Basket.normalized;
        rootMotion.dirMove = dirPlayerToBasket;

        PlayerAnimAttribute.KeyFrame rotKeyFrame = dunkAttr.GetKeyFrame("RotateToBasket");
        if (rotKeyFrame != null)
        {
            IM.Number fTimeFromRotateToBasket = rotKeyFrame.frame / frameRate;
            IM.Number fAngle = IM.Vector3.Angle(m_player.forward, dirPlayerToBasket);
            m_turningSpeed = IM.Math.Deg2Rad(fAngle) / fTimeFromRotateToBasket;
            m_rotateTo     = RotateTo.eBasket;
            m_rotateType   = RotateType.eSmooth;
            m_bMoveForward = false;
        }

        PlayerAnimAttribute.KeyFrame_MoveToStartPos kf_mts = dunkAttr.GetKeyFrame("MoveToStartPos") as PlayerAnimAttribute.KeyFrame_MoveToStartPos;
        IM.Vector3 vToBasketOffset = kf_mts.toBasketOffset;
        IM.Vector3 vRimHPos        = m_basket.m_vShootTarget;
        vRimHPos.y = IM.Number.zero;

        m_movingTimeThreshold = kf_mts.frame / frameRate;

        m_vMovePos = -dirPlayerToBasket * vToBasketOffset.x + vRimHPos;
        IM.Vector3 vMovePos2Bakset = m_vMovePos - m_player.position;
        IM.Number  fSameDir        = IM.Vector3.Dot(vMovePos2Bakset, vPlayer2Basket);
        bool       bRush           = false;

        if (vPlayer2Basket.magnitude < vMovePos2Bakset.magnitude || fSameDir < IM.Number.zero || kf_mts.frame == 0)
        {
            m_speed = IM.Vector3.zero;
            bRush   = false;
        }
        else
        {
            m_speed = (m_vMovePos - m_player.position) / (kf_mts.frame / frameRate);
            bRush   = true;
        }

        /////
        PlayerAnimAttribute.KeyFrame kf_dunk        = dunkAttr.GetKeyFrame("OnDunk");
        PlayerAnimAttribute.KeyFrame kf_leaveGround = dunkAttr.GetKeyFrame("OnLeaveGround");

        IM.Vector3 vPosDunk, vPosLeaveGround;
        m_player.GetNodePosition(SampleNode.Root, m_curAction, kf_dunk.frame / frameRate, out vPosDunk);

        m_leaveGroundTime = kf_leaveGround.frame / frameRate;
        m_fFlyTimeOnAir   = AnimationSampleManager.Instance.GetAnimData(m_curAction).duration - m_leaveGroundTime;

        m_player.GetNodePosition(SampleNode.Root, m_curAction, m_leaveGroundTime, out vPosLeaveGround);

        vPosLeaveGround = m_player.position + IM.Vector3.Dot(vPosLeaveGround, dirPlayerToBasket) * dirPlayerToBasket;
        vPosDunk        = m_player.position + IM.Vector3.Dot(vPosDunk, dirPlayerToBasket) * dirPlayerToBasket;

        IM.Vector3 deltaDistance   = vPosDunk - vPosLeaveGround;
        IM.Number  fOrigDunkOffset = vToBasketOffset.x - deltaDistance.magnitude;
        IM.Number  fPlayer2Basket  = vPlayer2Basket.magnitude;
        IM.Number  fDunkDist       = fPlayer2Basket - fOrigDunkOffset;

        if (bRush)
        {
            rootMotion.scale = IM.Number.one;
        }
        else
        {
            if (fDunkDist > IM.Number.zero)
            {
                rootMotion.scale = IM.Math.Max(fDunkDist / deltaDistance.magnitude, new IM.Number(0, 200));
            }
            else
            {
                rootMotion.scale = fPlayer2Basket / vToBasketOffset.x;
            }

            Debug.Log("scale: " + rootMotion.scale);
        }

        m_bRateFixed = false;
        _CalcDunkRate();

        m_ball.OnBeginDunk(m_player);

        m_stateMachine.m_listeners.ForEach((PlayerStateMachine.Listener lsn) => { lsn.OnBeginDunk(m_player, kf_dunk.frame / frameRate); });

        m_player.mStatistics.ReadyToCountShoot();

        if (m_speed != IM.Vector3.zero)
        {
            m_bMoving = true;
        }

        GameSystem.Instance.mClient.mPlayerManager.IsolateCollision(m_player, true);

        m_player.animMgr.Play(m_curAction, !m_bMoving);

        bool defended = m_player.IsDefended();

        if (m_skillArea == Area.eNear)
        {
            ++m_player.mStatistics.data.dunk_near_shoot;
            if (defended)
            {
                ++m_player.mStatistics.data.dunk_near_open_shoot;
            }
        }
        else if (m_skillArea == Area.eMiddle)
        {
            ++m_player.mStatistics.data.dunk_mid_shoot;
            if (defended)
            {
                ++m_player.mStatistics.data.dunk_mid_open_shoot;
            }
        }
    }
Exemplo n.º 5
0
    override public void OnEnter(PlayerState lastState)
    {
        base.OnEnter(lastState);

        m_skillArea = m_match.mCurScene.mGround.GetArea(m_player);

        m_movingTime = IM.Number.zero;
        m_bMoving    = false;

        m_player.mStatistics.ReadyToCountShoot();
        IM.RootMotion rootMotion = m_player.animMgr.Play(m_curAction, !m_bMoving).rootMotion;
        rootMotion.Reset();

        PlayerAnimAttribute.AnimAttr layupAttr = m_player.m_animAttributes.GetAnimAttrById(Command.Layup, m_curAction);
        if (layupAttr == null)
        {
            Debug.LogError("Current action: " + m_curAction + " in layup, skill id: " + m_curExecSkill.skill.id);
        }

        IM.Number frameRate = m_player.animMgr.GetFrameRate(m_curAction);
        m_player.m_blockable.Init(layupAttr, frameRate);

        IM.Number  fTimeFromRotateToBasket = new IM.Number(layupAttr.GetKeyFrame("RotateToBasket").frame) / frameRate;
        IM.Vector3 vPlayer2Basket          = m_basket.m_vShootTarget - m_player.position;
        vPlayer2Basket.y = IM.Number.zero;
        IM.Vector3 dirPlayerToBasket = vPlayer2Basket.normalized;
        rootMotion.dirMove = dirPlayerToBasket;

        IM.Number fAngle = IM.Vector3.Angle(m_player.forward, dirPlayerToBasket);
        m_turningSpeed = IM.Math.Deg2Rad(fAngle) / fTimeFromRotateToBasket;
        m_rotateTo     = RotateTo.eBasket;
        m_rotateType   = RotateType.eSmooth;
        m_bMoveForward = false;

        PlayerAnimAttribute.KeyFrame_MoveToStartPos kf_mts = layupAttr.GetKeyFrame("MoveToStartPos") as PlayerAnimAttribute.KeyFrame_MoveToStartPos;
        IM.Vector3 vToBasketOffset = kf_mts.toBasketOffset;
        IM.Vector3 vRimHPos        = m_basket.m_vShootTarget;
        vRimHPos.y = IM.Number.zero;

        m_vMovePos = -dirPlayerToBasket * vToBasketOffset.x + vRimHPos;
        //Debugger.Instance.DrawSphere("layup", m_vMovePos, 0.1f);
        m_movingTimeThreshold = kf_mts.frame / frameRate;

        IM.Vector3 vMovePos2Bakset = m_vMovePos - m_player.position;
        IM.Number  fSameDir        = IM.Vector3.Dot(vMovePos2Bakset, vPlayer2Basket);
        bool       bRush           = false;

        if (vPlayer2Basket.magnitude < vMovePos2Bakset.magnitude || fSameDir < 0 || kf_mts.frame == 0)
        {
            m_speed = IM.Vector3.zero;
        }
        else
        {
            m_speed = (m_vMovePos - m_player.position) / (kf_mts.frame / frameRate);
            bRush   = true;
        }

        PlayerAnimAttribute.KeyFrame_LayupShootPos kf_layup = layupAttr.GetKeyFrame("OnLayupShot") as PlayerAnimAttribute.KeyFrame_LayupShootPos;
        PlayerAnimAttribute.KeyFrame kf_leaveGround         = layupAttr.GetKeyFrame("OnLeaveGround") as PlayerAnimAttribute.KeyFrame;

        IM.Vector3 vPosLayup, vPosLeaveGround;
        m_player.GetNodePosition(SampleNode.Root, m_curAction, kf_layup.frame / frameRate, out vPosLayup);
        m_player.GetNodePosition(SampleNode.Root, m_curAction, kf_leaveGround.frame / frameRate, out vPosLeaveGround);
        if (vPosLayup == vPosLeaveGround)
        {
            Debug.LogError("PlayerState_Layup, vPosLayup equals vPosLeaveGround");
        }

        //TODO 这段代码不知道什么意思,待探讨
        //IM.Vector3 posLeaveGround = m_player.position + IM.Vector3.DotForNumber(vPosLeaveGround, dirPlayerToBasket) * dirPlayerToBasket;
        //IM.Vector3 posLayup = m_player.position + IM.Vector3.DotForNumber(vPosLayup, dirPlayerToBasket) * dirPlayerToBasket;

        IM.Number deltaDistance = (vPosLayup - vPosLeaveGround).magnitude;
        if (deltaDistance == IM.Number.zero)
        {
            Debug.LogError("PlayerState_Layup, DeltaDistance is 0.");
        }
        IM.Number fOrigLayupOffset = vToBasketOffset.x - deltaDistance;
        IM.Number fPlayer2Basket   = vPlayer2Basket.magnitude;
        IM.Number fLayupDist       = fPlayer2Basket - fOrigLayupOffset;

        if (bRush)
        {
            rootMotion.scale = IM.Number.one;
        }
        else
        {
            rootMotion.scale = IM.Math.Max(fLayupDist / deltaDistance, IM.Number.zero);
        }

        m_bRateFixed = false;
        _CalcLayupRate();

        if (m_speed != IM.Vector3.zero)
        {
            m_bMoving = true;
            m_player.animMgr.GetPlayInfo(m_curAction).enableRootMotion = false;
        }

        GameSystem.Instance.mClient.mPlayerManager.IsolateCollision(m_player, true);

        if (m_skillArea == Area.eNear)
        {
            ++m_player.mStatistics.data.layup_near_shoot;
        }
        else if (m_skillArea == Area.eMiddle)
        {
            ++m_player.mStatistics.data.layup_mid_shoot;
        }
    }