bool Pass() { IM.Number passWeight = m_player.IsDefended(m_system.AI.devAngleAttacker, m_system.AI.devDistAOD) ? new IM.Number(30) : IM.Number.zero; Player target = AIUtils.GetMostPriorPassTarget(m_player.m_team.members, m_player); if (target != null && target != m_player) { //目标要球,权重提高 if (target.m_StateMachine.m_curState.m_eState == PlayerState.State.eRequireBall) { IM.Number weightAdj = IM.Number.zero; switch (m_player.m_position) { case PositionType.PT_C: case PositionType.PT_PG: weightAdj = new IM.Number(200); break; case PositionType.PT_PF: weightAdj = new IM.Number(50); break; case PositionType.PT_SF: case PositionType.PT_SG: weightAdj = new IM.Number(20); break; } passWeight += weightAdj; } if (passWeight > IM.Number.zero) { AI_Pass pass = m_system.GetState(Type.ePass) as AI_Pass; pass.m_toPass = target; m_system.SetTransaction(pass, passWeight); return(true); } } return(false); }
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); } }
public static Player ChoosePassTargetCheckBall(Player player, GameMatch match) { List <Player> teammates = new List <Player>(player.m_team.members); teammates.Remove(player); if (teammates.Count == 0) { return(null); } // Teammates in far area. List <Player> matesFar = new List <Player>(); foreach (Player mate in teammates) { if (match.mCurScene.mGround.GetArea(mate) == Area.eFar) { matesFar.Add(mate); } } if (matesFar.Count > 0) // There are teammates in far area, pass to most prior mate. { return(AIUtils.GetMostPriorPassTarget(matesFar, player)); } else // No teammates in far area. { // Teammates in PG or SG's favor area. List <Player> matesOutSide = new List <Player>(); RoadPathManager.SectorArea areaPG = Player.positionFavorSectors[PositionType.PT_PG]; RoadPathManager.SectorArea areaSG = Player.positionFavorSectors[PositionType.PT_SG]; foreach (Player mate in player.m_team.members) { if (RoadPathManager.Instance.InSectors(areaPG, mate.position) || RoadPathManager.Instance.InSectors(areaSG, mate.position)) { matesOutSide.Add(mate); } } if (matesOutSide.Count > 0) // There are teammates in PG or SG's favor area, pass to most prior mate if its not myself. { Player passTarget = AIUtils.GetMostPriorPassTarget(matesOutSide, player); return(passTarget == player ? null : passTarget); } else // No teammates in PG or SG's favor area. { List <Player> teammatesPGSG = new List <Player>(); foreach (Player mate in teammates) { if (mate.m_matchPosition == PositionType.PT_PG || mate.m_matchPosition == PositionType.PT_SG) { teammatesPGSG.Add(mate); } } if (player.m_matchPosition == PositionType.PT_C) { if (teammatesPGSG.Count > 0) // Pass to most prior PG or SG. { return(AIUtils.GetMostPriorPassTarget(teammatesPGSG, player)); } else // Pass to nearest non-C teammate. { Player nearestNonC = null; IM.Number minDist = IM.Number.max; foreach (Player mate in teammates) { if (mate.m_matchPosition != PositionType.PT_C) { IM.Number curDist = GameUtils.HorizonalDistance(mate.position, player.position); if (curDist < minDist) { minDist = curDist; nearestNonC = mate; } } } return(nearestNonC); } } else if (player.m_matchPosition == PositionType.PT_PF) { if (teammatesPGSG.Count > 0) // Pass to most prior PG or SG. { return(AIUtils.GetMostPriorPassTarget(teammatesPGSG, player)); } else // Pass to nearest non-PF teammate. { Player nearestNonPF = null; IM.Number minDist = IM.Number.max; foreach (Player mate in teammates) { if (mate.m_matchPosition != PositionType.PT_PF) { IM.Number curDist = GameUtils.HorizonalDistance(mate.position, player.position); if (curDist < minDist) { minDist = curDist; nearestNonPF = mate; } } } return(nearestNonPF); } } else { return(null); } } } }
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); } }