override public void OnEnter(PlayerState lastState)
    {
        base.OnEnter(lastState);

        if (m_player.m_eHandWithBall == Player.HandWithBall.eLeft)
        {
            m_animType = AnimType.B_TYPE_0;
        }
        else if (m_player.m_eHandWithBall == Player.HandWithBall.eRight)
        {
            m_animType = AnimType.B_TYPE_1;
        }

        m_curAction = m_mapAnimType[m_animType];

        m_dirPlayerToBasket = GameUtils.HorizonalNormalized(m_basket.m_vShootTarget, m_player.position);
        PlayerAnimAttribute.AnimAttr attr = m_player.m_animAttributes.GetAnimAttrById(Command.BackToBack, m_curAction);
        if (attr != null)
        {
            PlayerAnimAttribute.KeyFrame_RotateToBasketAngle keyFrame = attr.GetKeyFrame("RotateToBasketAngle") as PlayerAnimAttribute.KeyFrame_RotateToBasketAngle;
            IM.Number frameRate = m_player.animMgr.GetFrameRate(m_curAction);

            m_dirPlayerToBasket = GameUtils.HorizonalNormalized(m_basket.m_vShootTarget, m_player.position);
            IM.Vector3 dirFaceTo = IM.Quaternion.AngleAxis(keyFrame.angle, IM.Vector3.up) * m_dirPlayerToBasket;
            IM.Number  fAngle    = IM.Vector3.Angle(m_player.forward, dirFaceTo);
            m_relAngle     = keyFrame.angle;
            m_turningSpeed = IM.Math.Deg2Rad(fAngle) / (keyFrame.frame / frameRate);
            m_rotateTo     = RotateTo.eBasket;
            m_rotateType   = RotateType.eSmooth;
            m_bMoveForward = false;
        }

        m_player.animMgr.CrossFade(m_curAction, false);
        m_player.m_stamina.m_bEnableRecover = false;
    }
    override public void OnEnter(PlayerState lastState)
    {
        dirToBasket = GameUtils.HorizonalNormalized(m_match.mCurScene.mBasket.m_vShootTarget, m_player.position);

        IM.Number cross = IM.Vector3.Cross(dirToBasket, m_player.moveDirection).y;
        isTurnLeft = (cross < IM.Number.zero);
        if (m_player.m_eHandWithBall == Player.HandWithBall.eLeft)
        {
            m_animType = isTurnLeft ? AnimType.B_TYPE_0 : AnimType.B_TYPE_1;
        }
        else if (m_player.m_eHandWithBall == Player.HandWithBall.eRight)
        {
            m_animType = isTurnLeft ? AnimType.B_TYPE_2 : AnimType.B_TYPE_3;
        }

        m_curAction = m_mapAnimType[m_animType];
        PlayerAnimAttribute.AnimAttr attr = m_player.m_animAttributes.GetAnimAttrById(Command.BackToBack, m_curAction);
        PlayerAnimAttribute.KeyFrame_RotateToBasketAngle keyFrame = attr.GetKeyFrame("RotateToBasketAngle") as PlayerAnimAttribute.KeyFrame_RotateToBasketAngle;
        if (keyFrame != null)
        {
            IM.Vector3 dirFaceTo = IM.Quaternion.AngleAxis(keyFrame.angle, IM.Vector3.up) * dirToBasket;
            m_player.forward = dirFaceTo;
        }

        m_curAction = m_mapAnimType[m_animType];
        m_player.animMgr.Play(m_curAction, true).rootMotion.Reset();
    }
Exemplo n.º 3
0
    bool _BeginBlockDunk(Player dunker, out IM.Vector3 vBallPos)
    {
        vBallPos = IM.Vector3.zero;
        SkillInstance dunkSkill = dunker.m_StateMachine.m_curState.m_curExecSkill;

        Dictionary <string, PlayerAnimAttribute.AnimAttr> blocks = m_player.m_animAttributes.m_block;
        int blockKey = blocks[m_curAction].GetKeyFrame("OnBlock").frame;

        IM.Number fEventBlockTime = blockKey / m_player.animMgr.GetFrameRate(m_curAction);
        string    dunk_id         = dunker.m_skillSystem.ParseAction(dunkSkill.curAction.action_id, dunkSkill.matchedKeyIdx, Command.Dunk);

        PlayerAnimAttribute.AnimAttr dunkAnims = dunker.m_animAttributes.GetAnimAttrById(Command.Dunk, dunk_id);
        int dunkInKey = dunkAnims.GetKeyFrame("OnDunk").frame;

        IM.Number fEventDunkInTime = dunkInKey / dunker.animMgr.GetFrameRate(dunk_id);

        IM.Number fDunkEclipseTime = dunker.animMgr.curPlayInfo.time;
        IM.Number fDunkFlyTime     = fEventDunkInTime - fDunkEclipseTime;
        if (fDunkFlyTime < fEventBlockTime)
        {
            Debugger.Instance.m_steamer.message = "block too late, dunk goal!";
            return(false);
        }

        IM.Vector3 vRootBegin, vRootBlock;
        m_player.GetNodePosition(SampleNode.Root, dunk_id, fDunkEclipseTime, out vRootBegin);
        m_player.GetNodePosition(SampleNode.Root, dunk_id, fDunkEclipseTime + fEventBlockTime, out vRootBlock);

        IM.Vector3 dunkPosBlocked = dunker.position + vRootBlock - vRootBegin;
        //Vector3 dunkPosBlocked = dunker.m_StateMachine.m_curState.m_speed * fDunkFlyTime + dunker.position;
        IM.Vector3 dunkAnimBall;
        if (!m_player.GetNodePosition(SampleNode.Ball, dunk_id, fDunkEclipseTime + fEventBlockTime, out dunkAnimBall))
        {
            return(false);
        }
        dunkAnimBall.y  /= dunker.scale.y;
        dunkPosBlocked.y = dunkAnimBall.y;
        vBallPos         = dunkAnimBall;

        IM.Vector3 dirPlayer2Ball = GameUtils.HorizonalNormalized(dunkPosBlocked, m_player.position);
        if (IM.Vector3.Angle(dirPlayer2Ball, m_player.forward) > new IM.Number(90))
        {
            m_player.FaceTo(dunker.position);
            m_speed = IM.Vector3.zero;
        }
        else
        {
            m_player.FaceTo(dunkPosBlocked);
            m_speed   = (dunkPosBlocked - m_player.position) / fEventBlockTime;
            m_speed.y = IM.Number.zero;
        }

        m_heightScale = dunkPosBlocked.y / (dunkAnimBall.y * m_player.scale.y);

        return(true);
    }
Exemplo n.º 4
0
    public void Init(PlayerAnimAttribute.AnimAttr animAttr, IM.Number framerate, int beginFrameOffset = 0)
    {
        m_fBlockableBeginTime = IM.Number.zero;
        m_fBlockableEndTime   = IM.Number.zero;

        PlayerAnimAttribute.KeyFrame_Blockable blockableFrame = animAttr.GetKeyFrame("blockable") as PlayerAnimAttribute.KeyFrame_Blockable;
        if (blockableFrame != null)
        {
            m_fBlockableBeginTime = (blockableFrame.frame - beginFrameOffset) / framerate;
            m_fBlockableEndTime   = m_fBlockableBeginTime + blockableFrame.blockFrame / framerate;
        }
    }
Exemplo n.º 5
0
    override public void OnEnter(PlayerState lastState)
    {
        base.OnEnter(lastState);

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

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

        if (shootAttr.GetKeyFrame("RotateToBasket") != null)
        {
            IM.Number  frameRate = m_player.animMgr.GetFrameRate(m_curAction);
            IM.Number  fTimeFromRotateToBasket = shootAttr.GetKeyFrame("RotateToBasket").frame / frameRate;
            IM.Vector3 dirPlayerToBasket       = GameUtils.HorizonalNormalized(m_basket.m_vShootTarget, m_player.position);
            //m_player.m_rootMotion.m_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_player.animMgr.Play(m_curAction, true).rootMotion.Reset();

        mCanShoot = true;

        mCachedShootSkill = m_curExecSkill;

        m_skillArea = m_match.mCurScene.mGround.GetArea(m_player);
    }
Exemplo n.º 6
0
    override public void OnEnter(PlayerState lastState)
    {
        base.OnEnter(lastState);

        IM.Vector3 dirPasserToCatcher = GameUtils.HorizonalNormalized(m_catcher.position, m_passer.position);
        if (m_bSendMsg)
        {
            m_player.forward = -dirPasserToCatcher;
        }

        m_player.m_enablePickupDetector = false;
        m_player.animMgr.GetRootMotion(m_curAction).Reset();

        m_player.m_enableMovement = false;
        m_player.m_enableAction   = false;

        PlayerAnimAttribute.AnimAttr animAttr = m_player.m_animAttributes.GetAnimAttrById(Command.Interception, m_curAction);
        if (animAttr == null)
        {
            Debug.LogError("Can not find animAttr: " + m_curAction);
        }

        PlayerAnimAttribute.KeyFrame keyFrame = animAttr.GetKeyFrame("OnBlock");
        IM.Number frameRate = m_player.animMgr.GetFrameRate(m_curAction);
        m_fEventTime = keyFrame.frame / frameRate;

        IM.Vector3 ballPosWhenBlocked;
        if (!m_player.GetNodePosition(SampleNode.Ball, m_curAction, m_fEventTime, out ballPosWhenBlocked))
        {
            Debug.LogError("Can not get bone position");
        }

        Debugger.Instance.DrawSphere("block", (Vector3)ballPosWhenBlocked, Color.yellow);

        m_fActDistance = m_passer.m_speedPassBall * m_fEventTime;
        m_bOnEvent     = false;
        m_bActing      = false;

        m_cachedAction = m_curAction;
        m_curAction    = "";

        Debug.Log("animType: " + m_animType);
        ++m_player.mStatistics.data.interception;
    }
Exemplo n.º 7
0
    public bool CanIntercept(SkillInstance intercept, Player passer, Player catcher, out IM.Vector3 ballPosWhenIntercepted)
    {
        ballPosWhenIntercepted = IM.Vector3.zero;

        PlayerState.State curState = m_player.m_StateMachine.m_curState.m_eState;
        if (curState != State.eRun && curState != State.eStand && curState != State.eDefense && curState != State.eRush)
        {
            return(false);
        }

        IM.Vector3 dirPasserToCatcher = GameUtils.HorizonalNormalized(catcher.position, passer.position);
        IM.Vector3 dirOriginFace      = m_player.forward;

        m_player.forward = -dirPasserToCatcher;

        string action = _ParseAction(intercept.curAction.action_id, intercept.matchedKeyIdx);

        PlayerAnimAttribute.AnimAttr animAttr = m_player.m_animAttributes.GetAnimAttrById(Command.Interception, action);
        if (animAttr == null)
        {
            Debug.LogError("Can not find animAttr: " + m_curAction);
        }

        PlayerAnimAttribute.KeyFrame keyFrame = animAttr.GetKeyFrame("OnBlock");
        IM.Number frameRate          = m_player.animMgr.GetFrameRate(action);
        IM.Number fEventTime         = keyFrame.frame / frameRate;
        IM.Number fBallFlyDistance   = passer.m_speedPassBall * fEventTime;
        IM.Number fDistPlayer2Passer = GameUtils.HorizonalDistance(passer.position, m_player.position);
        if (fDistPlayer2Passer < fBallFlyDistance)
        {
            m_player.forward = dirOriginFace;
            return(false);
        }

        if (!m_player.GetNodePosition(SampleNode.Ball, action, fEventTime, out ballPosWhenIntercepted))
        {
            m_player.forward = dirOriginFace;
            return(false);
        }

        m_player.forward = dirOriginFace;
        return(true);
    }
Exemplo n.º 8
0
    override public void OnEnter(PlayerState lastState)
    {
        base.OnEnter(lastState);

        m_dirPlayerToBasket = GameUtils.HorizonalNormalized(m_basket.m_vShootTarget, m_player.position);

        if (curAnimStep == 1)
        {
            Player target = m_player.m_defenseTarget;
            if (target != null)
            {
                isCompeteWin = _Competing(m_player, target);
                m_match.m_context.m_backToBackWinnerId = isCompeteWin ? m_player.m_roomPosId : target.m_roomPosId;
            }
            if (m_player.m_eHandWithBall == Player.HandWithBall.eLeft)
            {
                m_animType = AnimType.B_TYPE_0;
            }
            else
            {
                m_animType = AnimType.B_TYPE_1;
            }
        }

        isCompeteWin = (m_match.m_context.m_backToBackWinnerId == m_player.m_roomPosId);
        Debug.Log("BackCompete: " + isCompeteWin + " m_match.m_context.m_backToBackWinnerId: " + m_match.m_context.m_backToBackWinnerId);

        m_curAction = m_mapAnimType[m_animType];
        PlayerAnimAttribute.AnimAttr attr = m_player.m_animAttributes.GetAnimAttrById(Command.BackToBack, m_curAction);
        if (attr != null)
        {
            PlayerAnimAttribute.KeyFrame_RotateToBasketAngle keyFrame = attr.GetKeyFrame("RotateToBasketAngle") as PlayerAnimAttribute.KeyFrame_RotateToBasketAngle;
            IM.Vector3 dirFaceTo = IM.Quaternion.AngleAxis(keyFrame.angle, IM.Vector3.up) * m_dirPlayerToBasket;
            m_player.forward = dirFaceTo;
        }

        m_player.animMgr.CrossFade(m_curAction, false);
        m_player.m_stamina.m_bEnableRecover = false;
    }
    public static IM.Number GetEventTime(Player player, string action)
    {
        string originAction = player.animMgr.GetOriginName(action);
        Dictionary <string, PlayerAnimAttribute.AnimAttr> rebounds = player.m_animAttributes.m_rebound;

        PlayerAnimAttribute.AnimAttr attr = null;
        if (!rebounds.TryGetValue(originAction, out attr))
        {
            Debug.LogError("Can not find AnimAttr in clip: " + originAction);
            return(IM.Number.zero);
        }

        PlayerAnimAttribute.KeyFrame reboundFrame = attr.GetKeyFrame("OnRebound");
        if (reboundFrame == null)
        {
            Debug.LogError("Can not find OnRebound key in clip: " + originAction);
            return(IM.Number.zero);
        }
        int reboundKey = reboundFrame.frame;

        return(reboundKey / player.animMgr.GetFrameRate(action));
    }
Exemplo n.º 10
0
    bool _CalcBlockDunk(Player shooter, out bool bBlockable, out bool bBlockInRange, out IM.Number fBlockRate, out IM.Number fBlockValue, out IM.Vector3 attackerPos, out IM.Vector3 vBallDir, out bool bValid)
    {
        bBlockable    = false;
        attackerPos   = IM.Vector3.zero;
        fBlockRate    = IM.Number.zero;
        fBlockValue   = IM.Number.zero;
        bBlockInRange = false;
        bValid        = false;
        //vBallDir = GameUtils.HorizonalNormalized( shooter.position, m_player.position );
        vBallDir = GetBallVelocity();

        Player dunker = m_ball.m_owner;

        IM.Vector3 dirDunker2Player = m_player.position - dunker.position;
        dirDunker2Player.y = IM.Number.zero;

        if (!dunker.m_blockable.blockable)
        {
            Debugger.Instance.m_steamer.message = "Out of block range.";
            if (dunker.m_blockable.tooEarly)
            {
                m_failReason = FailReason.TooEarly;
            }
            else if (dunker.m_blockable.tooLate)
            {
                m_failReason = FailReason.TooLate;
            }
            return(false);
        }

        /*
         * AOD.Zone zone = shooter.m_AOD.GetStateByPos(m_player.position);
         * if( zone == AOD.Zone.eInvalid )
         * {
         *      bBlockInRange = false;
         *      Debugger.Instance.m_steamer.message = "Block failed, not in AOD";
         *      return false;
         * }
         */
        if (!InBlockArea(shooter, m_player, m_basket.m_vShootTarget))
        {
            Debugger.Instance.m_steamer.message = "Block failed, not in AOD";
            m_failReason = FailReason.InvalidArea;
            return(false);
        }
        bBlockInRange = true;

        Dictionary <string, PlayerAnimAttribute.AnimAttr> blocks = m_player.m_animAttributes.m_block;
        int blockKey = blocks[m_curAction].GetKeyFrame("OnBlock").frame;

        IM.Number     fEventBlockTime = blockKey / m_player.animMgr.GetFrameRate(m_curAction);
        SkillInstance dunkSkill       = dunker.m_StateMachine.m_curState.m_curExecSkill;
        string        dunk_id         = dunker.m_skillSystem.ParseAction(dunkSkill.curAction.action_id, dunkSkill.matchedKeyIdx, Command.Dunk);

        PlayerAnimAttribute.AnimAttr dunkAnims = dunker.m_animAttributes.GetAnimAttrById(Command.Dunk, dunk_id);
        int dunkInKey = dunkAnims.GetKeyFrame("OnDunk").frame;

        IM.Number fEventDunkInTime = dunkInKey / dunker.animMgr.GetFrameRate(dunk_id);

        IM.Number fDunkEclipseTime = dunker.animMgr.curPlayInfo.time;
        IM.Number fDunkFlyTime     = fEventDunkInTime - fDunkEclipseTime;
        if (fDunkFlyTime < fEventBlockTime)
        {
            Debugger.Instance.m_steamer.message = "block too late, dunk goal!";
            m_failReason = FailReason.InvalidBallShotState;
            return(false);
        }

        IM.Number       fSideEffect = IM.Number.zero;
        SkillSideEffect effect;

        if (!m_curExecSkill.skill.side_effects.TryGetValue((int)SkillSideEffect.Type.eBlockRate, out effect))
        {
            Debug.Log("No side effect data.");
        }
        else
        {
            fSideEffect = effect.value;
        }

        Dictionary <string, uint> data            = dunker.m_finalAttrs;
        Dictionary <string, uint> dunkerSkillAttr = dunker.GetSkillAttribute();

        IM.Number blockAttr   = new IM.Number((int)(m_player.m_finalAttrs["block"]));
        IM.Number reduceScale = m_match.GetAttrReduceScale("block", m_player);
        blockAttr *= reduceScale;

        if ((Command)dunkSkill.skill.action_type == Command.Dunk)
        {
            uint anti_block = 0;
            shooter.m_skillSystem.HegdingToValue("addn_anti_block", ref anti_block);

            IM.Number fAntiBlock = new IM.Number((int)(data["anti_block"] + anti_block));
            switch (dunkSkill.skill.area[0])
            {
            case 3:             //near
                fBlockRate = dunkNearHedging.Calc(blockAttr, fAntiBlock);
                break;

            case 2:             //middle
                fBlockRate = dunkMiddleHedging.Calc(blockAttr, fAntiBlock);
                break;
            }

            fBlockRate += fSideEffect;
        }

        SkillSpec skillSpc = shooter.GetSkillSpecialAttribute(SkillSpecParam.eDunk_antiBlock);

        if (skillSpc.paramOp == SkillSpecParamOp.eAdd)
        {
            fBlockRate += skillSpc.value;
        }
        else if (skillSpc.paramOp == SkillSpecParamOp.eMulti)
        {
            fBlockRate *= skillSpc.value;
        }

        skillSpc = m_player.GetSkillSpecialAttribute(SkillSpecParam.eBlock_rate);
        if (skillSpc.paramOp == SkillSpecParamOp.eAdd)
        {
            fBlockRate += skillSpc.value;
        }
        else if (skillSpc.paramOp == SkillSpecParamOp.eMulti)
        {
            fBlockRate *= skillSpc.value;
        }

        fBlockRate = m_match.AdjustBlockRate(shooter, m_player, fBlockRate);

        bool sumValue = random[shooter].AdjustRate(ref fBlockRate);

        fBlockValue = IM.Random.value;

        Debugger.Instance.m_steamer.message  = "block rate: " + fBlockRate;
        Debugger.Instance.m_steamer.message += "probability: " + fBlockValue;

        bValid = true;

        m_ball.m_bBlockSuccess = fBlockValue < fBlockRate;
        if (!m_ball.m_bBlockSuccess)
        {
            m_failReason = FailReason.Random;
        }

        if (m_ball.m_bBlockSuccess && sumValue)
        {
            random[shooter].SumValue();
        }

        return(m_ball.m_bBlockSuccess);
    }
Exemplo n.º 11
0
    bool _BeginBlockLayup(ShootSolution failedShootSolution, Player shooter, out IM.Vector3 ballPos)
    {
        m_ball.m_shootSolution = failedShootSolution;
        ballPos = IM.Vector3.zero;

        Dictionary <string, PlayerAnimAttribute.AnimAttr> blocks = m_player.m_animAttributes.m_block;
        int blockKey = blocks[m_player.animMgr.GetOriginName(m_curAction)].GetKeyFrame("OnBlock").frame;

        IM.Number fEventBlockTime = blockKey / m_player.animMgr.GetFrameRate(m_curAction);

        SkillInstance shooterSkill = shooter.m_StateMachine.m_curState.m_curExecSkill;
        string        shoot_id     = shooter.m_skillSystem.ParseAction(shooterSkill.curAction.action_id, shooterSkill.matchedKeyIdx, Command.Layup);

        PlayerAnimAttribute.AnimAttr shootAnims = shooter.m_animAttributes.GetAnimAttrById(Command.Layup, shoot_id);
        int shootOutKey = shootAnims.GetKeyFrame("OnLayupShot").frame;

        IM.Number fEventShootOutTime = shootOutKey / shooter.animMgr.GetFrameRate(shoot_id);
        IM.Number fShootEclipseTime  = shooter.animMgr.curPlayInfo.time;
        IM.Number fPlayerMovingTime  = fEventShootOutTime - fShootEclipseTime;
        IM.Number fBallFlyTime       = fEventBlockTime - fPlayerMovingTime;

        IM.Vector3 vRootBegin, vRootBlock, vRootShoot;
        m_player.GetNodePosition(SampleNode.Root, shoot_id, fShootEclipseTime, out vRootBegin);
        m_player.GetNodePosition(SampleNode.Root, shoot_id, fShootEclipseTime + fEventBlockTime, out vRootBlock);
        m_player.GetNodePosition(SampleNode.Root, shoot_id, fEventShootOutTime, out vRootShoot);

        IM.Vector3 playerPosWhenLayup = shooter.position + vRootShoot - vRootBegin;
        IM.Vector3 playerPosWhenBlock = shooter.position + vRootBlock - vRootBegin;
        //ball still in player hand
        if (fBallFlyTime < IM.Number.zero)
        {
            IM.Vector3 dirJump = (playerPosWhenBlock - m_player.position) / fEventBlockTime;
            dirJump.y = IM.Number.zero;
            m_speed   = dirJump;

            IM.Vector3 vBallPosWhenLayup;
            m_player.GetNodePosition(SampleNode.Ball, shoot_id, fShootEclipseTime + fEventBlockTime, out vBallPosWhenLayup);
            ballPos = vBallPosWhenLayup;
        }
        else
        {
            IM.Vector3 vBallPosWhenLayup;
            m_player.GetNodePosition(SampleNode.Ball, shoot_id, fEventShootOutTime, out vBallPosWhenLayup);
            IM.Vector3 delta = vBallPosWhenLayup - vRootShoot;
            vBallPosWhenLayup = playerPosWhenLayup + delta;
            //Debugger.Instance.DrawSphere("vBallPosWhenLayup", vBallPosWhenLayup, Color.red);

            m_ball.m_shootSolution             = GameSystem.Instance.shootSolutionManager.GetShootSolution(m_basket.m_rim.center, playerPosWhenLayup, false);
            m_ball.m_shootSolution.m_vStartPos = vBallPosWhenLayup;

            IM.Vector3 vBallPosBlock;
            if (!m_ball.GetPositionInAir(fBallFlyTime, out vBallPosBlock))
            {
                Debugger.Instance.m_steamer.message = "can not block, not shoot curve info.";
                return(false);
            }
            ballPos = vBallPosBlock;

            IM.Vector3 blockAnimBall;
            m_player.GetNodePosition(SampleNode.Ball, m_curAction, fEventBlockTime, out blockAnimBall);
            IM.Vector3 root;
            m_player.GetNodePosition(SampleNode.Root, m_curAction, fEventBlockTime, out root);

            m_heightScale = vBallPosBlock.y / (blockAnimBall.y * m_player.scale.y);
            IM.Vector3 deltaPos2Root = blockAnimBall - root;
            deltaPos2Root.y = IM.Number.zero;
            IM.Vector3 rootPosWhenBlock = vBallPosBlock - deltaPos2Root;
            rootPosWhenBlock.y = IM.Number.zero;

            IM.Vector3 dirJump = (rootPosWhenBlock - m_player.position) / fEventBlockTime;
            m_speed = dirJump;
        }

        m_ball.m_bBlockSuccess = true;

        return(true);
    }
Exemplo n.º 12
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;
        }
    }
Exemplo n.º 13
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.º 14
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;
        }
    }