override public void Update(IM.Number fDeltaTime)
    {
        PlayerState state = m_player.m_StateMachine.m_curState;

        if (state.m_eState != PlayerState.State.eCrossOver)
        {
            PlayerState_CrossOver stateCross = m_player.m_StateMachine.GetState(PlayerState.State.eCrossOver) as PlayerState_CrossOver;
            if (stateCross.crossed)                          // Cross over succeed.
            {
                if (IM.Random.value < new IM.Number(0, 300)) // Attack unreasoningly
                {
                    AI_Positioning aiPositioning = m_system.GetState(Type.ePositioning) as AI_Positioning;
                    aiPositioning.unreasonable = true;
                    Debug.Log("Attack unreasonable.");
                }
                else
                {
                    Player defender = m_player.GetDefender();
                    if (defender != null)                       // Still being defended.
                    {
                        List <SkillInstance> basicSkills = m_player.m_skillSystem.GetBasicSkillsByCommand(Command.CrossOver);
                        uint uBasicSkillCost             = basicSkills[0].skill.levels[1].stama;
                        if (m_player.m_stamina.m_curStamina >= new IM.Number((int)uBasicSkillCost))                             // Has enough stamina to cross again.
                        {
                            IM.Number crossRate = PlayerState_CrossOver.CalcCrossRate(m_player, defender);                      // Cross over success rate.
                            if (crossRate > new IM.Number(0, 600))
                            {
                                m_system.SetTransaction(this, new IM.Number(100), true);
                                return;
                            }
                        }
                    }
                }
            }
            else                // Cross over failed.
            {
                if (state.m_eState == PlayerState.State.eStand ||
                    state.m_eState == PlayerState.State.eRun ||
                    state.m_eState == PlayerState.State.eRush ||
                    state.m_eState == PlayerState.State.eHold)
                {
                    Player defender = m_player.GetDefender();
                    if (defender != null)
                    {
                        IM.Number crossRate = PlayerState_CrossOver.CalcCrossRate(m_player, defender); // Cross over success rate.
                        if (crossRate < new IM.Number(0, 200))                                         // Success rate is too low. Pass to teammate.
                        {
                            List <Player> teammates = new List <Player>(m_player.m_team.members);
                            teammates.Remove(m_player);
                            Player target = AIUtils.GetMostPriorPassTarget(teammates, m_player);
                            if (target != null)
                            {
                                AI_Pass passState = m_system.GetState(Type.ePass) as AI_Pass;
                                passState.m_toPass = target;
                                m_system.SetTransaction(passState, new IM.Number(100), true);
                                return;
                            }
                        }
                    }
                }
                else if (state.m_eState == PlayerState.State.eKnocked)                  // Wait knocked state over to do passing
                {
                    return;
                }
            }
            m_system.SetTransaction(AIState.Type.ePositioning);
        }
    }
Beispiel #2
0
    protected override void OnTick()
    {
        GameMatch   match = GameSystem.Instance.mClient.mCurMatch;
        UBasketball ball  = match.mCurScene.mBall;

        bool inTakeOver = false;

        if (m_player.m_inputDispatcher != null)
        {
            inTakeOver = m_player.m_inputDispatcher.inTakeOver;
        }

        if (!inTakeOver)
        {
            //进攻时间快结束了,投球
            if (m_player.m_bWithBall && match.IsFinalTime(new IM.Number(3) - m_system.AI.devTime) && !m_match.m_ruler.m_bToCheckBall)
            {
                AIUtils.AttackByPosition(m_player, new IM.Number(100));
                return;
            }
        }

        //球在飞,追球
        if (m_ball.m_owner == null && m_ball.m_ballState != BallState.eUseBall_Pass)
        {
            if (AIUtils.ShouldTraceBall(m_ball, m_player))
            {
                m_system.SetTransaction(AIState.Type.eTraceBall);
            }
            else if (m_match.m_stateMachine.m_curState.m_eState != MatchState.State.eTipOff)
            {
                m_system.SetTransaction(AIState.Type.ePositioning);
            }
            return;
        }

        if (!inTakeOver)
        {
            //抱球时
            Area area = m_match.mCurScene.mGround.GetArea(m_player);
            if (m_player.m_StateMachine.m_curState.m_eState == PlayerState.State.eHold)
            {
                if (m_player.m_bMovedWithBall)                  //二次运球
                {
                    if (m_player.IsDefended())                  //被防守
                    {
                        if (!m_system.IsPvp)
                        {
                            AIUtils.AttackByPosition(m_player, new IM.Number(15));
                            m_system.SetTransaction(Type.eFakeShoot, new IM.Number(10));
                        }

                        List <Player> teammates = new List <Player>(m_player.m_team.members);
                        teammates.Remove(m_player);
                        Player passTarget = AIUtils.GetMostPriorPassTarget(teammates, m_player);
                        if (passTarget != null)
                        {
                            AI_Pass pass = m_system.GetState(Type.ePass) as AI_Pass;
                            pass.m_toPass = passTarget;
                            m_system.SetTransaction(Type.ePass, new IM.Number(75));
                        }
                    }
                    else                        //未被防守
                    {
                        AIUtils.AttackByPosition(m_player, new IM.Number(100));
                    }
                }
                else                    //非二次运球
                {
                    m_system.SetTransaction(Type.ePositioning);
                }

                return;
            }
        }

        //攻防转换
        if (m_player.m_team.m_role == GameMatch.MatchRole.eOffense)
        {
            if (makePolicyImmediately)
            {
                AI_Positioning aiPositioning = m_system.GetState(AIState.Type.ePositioning) as AI_Positioning;
                aiPositioning.makePolicyImmediately = true;
                makePolicyImmediately = false;
            }
            m_system.SetTransaction(AIState.Type.ePositioning);
        }
        else
        {
            m_system.SetTransaction(AIState.Type.eDefense);
        }
    }