public SoccerAIwithBall(AIController owner, PlayerController controller) : base(owner, controller) { aiState = SoccerAIState.nothing; PlayerAnimatorEvents animatorEvents = Player.GetComponent <PlayerAnimatorEvents>(); animatorEvents.OnPassFinish += OnPassFinish; }
private void Handle_GoToDefaultState() { //Vou para a minha posição de marcação origem //Marcação de dfesa caso meu time nao tenha a bola, marcação de ataque caso tenha. //Vou finalizar quando: //> Eu estiver com a bola //> Eu chegar ao destino //> Time estiver com bola //> Eu estiver perto da bola if (Player.IsSelected() || BallController.HasOwner() == false) { Stop(); aiState = SoccerAIState.nothing; return; } bool isBallNear = Player.IsBallNear(); if (isBallNear == true && BallController.IsFromTeam(Player) == false) { Speed = 0; aiState = SoccerAIState.nothing; return; } Transform defPos = Player.GetMarcationPosition(CampPlaceType.defense); Transform attkPos = Player.GetMarcationPosition(CampPlaceType.attack); bool myTeamHasBall = Player.IsBallfromMyTeam(); Vector2 move = Locomotion.GetDirectionAI(); Speed = move.y; Direction = move.x; Vector3 destination = myTeamHasBall ? attkPos.position : defPos.position; Agent.SetDestination(destination); //Eu cheguei ao destino if (Locomotion.IsAgentDone) { Stop(); aiState = SoccerAIState.nothing; return; } }
private void Handlle_NothingState() { //Indo para a origem //Se eu estiver proximo do jogador que possui a bola vou correr atraz da bola //Se eu estiver longe Vou passar a seleção para o jogador mais proximo da bola e se não houver vou atraz //da bola procurando um novo jogador if (!Player.IsMyBall() && Player.IsSelected()) { aiState = SoccerAIState.followBall; return; } timeToSelect = 0; Stop(); }
private void Handle_HelpTugState() { PlayerController playerToHelp = Player.GetCampTeam().GetSelectedPlayer(); if (playerToHelp == null) { aiState = SoccerAIState.nothing; return; } if (playerToHelp.Locomotion.isJoint == false || Player.IsBallMostNearUnselectedWithSkillTwo() == false) { aiState = SoccerAIState.nothing; return; } Vector2 move = Locomotion.GetDirectionAI(); Direction = move.x; Speed = move.y; //Seta destino bola ou jogador agarrado PlayerController joitedPlayer = playerToHelp.Locomotion.JoitedPlayer; if (joitedPlayer.IsMyBall() == false) { Agent.SetDestination(joitedPlayer.transform.position); } else { Agent.SetDestination(BallController.GetPosition()); } //Rasteira quando estiver peto if (joitedPlayer.Distance(Player) <= 1.5f) { if (Player.GetSkill_BasicActionTwo().IsReady) { motionType = LocomotionType.normal; if (Player.Locomotion.TriggerActionTwo()) { Player.GetSkill_BasicActionTwo().TriggerCooldown(); } } } }
private void Handle_FollowBallState() { //Indo atraz da bola se estiver perto bool isBallNear = Player.IsBallMostNear(); bool teamHasBall = Player.IsBallfromMyTeam(); if (isBallNear == false || teamHasBall == true || Player.IsMyBall() || Player.IsSelected()) { Stop(); aiState = SoccerAIState.nothing; return; } Vector3 ballPosition = BallController.GetPosition(); ballPosition.y = Player.transform.position.y; //Rasteira ou acao secundaria PlayerController enemyforward; SkillVar skill = Player.GetSkill_BasicActionTwo(); if (Player.IsHitForwad(0.5f, out enemyforward, Player.GetCampTeam().Enemy())) { if (skill.IsReady) { motionType = LocomotionType.normal; if (Locomotion.TriggerPass()) { skill.TriggerCooldown(); } } } Vector2 move = Locomotion.GetDirectionAI(); Direction = move.x; Speed = move.y; Agent.SetDestination(ballPosition); }
public override bool UpdateHandleStates() { if (base.UpdateHandleStates() == false) { return(false); } if (!Agent.isActiveAndEnabled || !Agent.isOnNavMesh) { return(false); } aiState = SoccerAIState.followBall; switch (aiState) { case SoccerAIState.nothing: Handlle_NothingState(); break; case SoccerAIState.followBall: Handle_FollowBallState(); break; default: Handlle_NothingState(); break; } return(true); }
private void Handlle_NothingState() { if (Player.IsMyBall() == false) { aiState = SoccerAIState.nothing; return; } Transform goalPosition = Player.GetEnemyGoalPosition(); PlayerController playerBtw = null; PlayerController enemyNear = Player.GetEnemyNear(); timeToDrible += Time.deltaTime; timeToGoal += Time.deltaTime; if (toPass != null) { motionType = LocomotionType.normal; Debug.DrawLine(Player.transform.position, toPass.transform.position, Color.red); toGo = toPass.transform.position; if (Player.IsLookAt(toGo) == true) { if (Player.IsHitBetween(toPass) == false && Player.IsMyBall()) { if (Owner.TriggerPass(toPass)) { Player.GetSkill_BasicPass().TriggerCooldown(); toPass = null; } } else { toPass = null; } } Move(toGo); return; } //Ativação de movimento soccer e uso de stamina if (enemyNear != null) { if (enemyNear.Distance(Player) <= 5.5f && enemyNear.IsSelected() && Player.isOk) { if (Player.GetSkill_Stamina().IsCritical == false) { motionType = LocomotionType.soccer; } else if (Player.GetSkill_Stamina().IsMin) { motionType = LocomotionType.normal; } } else { motionType = LocomotionType.normal; } } //Vou passar a bola se existir um cara livre entre e o gol. Esta e a prioridade ja q ele tem caminho livre if (Player.IsHitForwad(checkDistanceToPass, out playerBtw)) { inGoalDir = false; timeToDrible = 0.0f; if (playerBtw.IsMyTeaM(Player)) //Player e meu amigo, vou pedir para ele sair do caminho { if (playerBtw.IsLookAt(Player)) { Vector3 origim = playerBtw.transform.position + (-playerBtw.transform.forward * 4.5f); Vector3 freePos = Locomotion.GetRandomNavCircle(origim, 4.5f); playerBtw.GetComponent <AIController>().GoToPosition(freePos, BallController.instance.transform); } } else if (playerBtw.Distance(Player) <= checkDistanceToDrible) //Player inimigo e perto de mais. Drible { if (Player.IsLookAt(toGo)) { Vector3 positionToDrible = Vector3.zero; if (GetPositionToDrible(playerBtw, out positionToDrible)) { toGo = positionToDrible; } else { //Se posição boa para o drible. toGo = positionToDrible; } } } else //Player inimigo mas longe de mais vou tentar um passe de bola { SkillVar skillpass = Player.GetSkill_BasicPass(); PlayerController topass = null; if (GetToPass(out topass)) { if (Player.IsHitBetween(topass) == false && skillpass.IsReady) { toPass = topass; toGo = Player.transform.position; } else { inGoalDir = true; } } else { inGoalDir = true; } } } else { inGoalDir = true; if (enemyNear != null) { //Inimigo perto demais para ir pro gol. a probalidade de perder a bola e muito grande //Vou tentar um passe de bola SkillVar skillpass = Player.GetSkill_BasicPass(); PlayerController topass = null; if (GetToPass(out topass) && skillpass.IsReady && enemyNear.IsSelected()) { if (!Player.IsHitBetween(topass)) { toPass = topass; toGo = Player.transform.position; inGoalDir = false; } } else { //Nenhum player para tocar Assim sendo vou tentar driblar if (enemyNear.Distance(Player) <= 1.0f && enemyNear.IsSelected()) { if (timeToDrible >= 1.0f || Locomotion.IsAgentDone) { toGo = Locomotion.GetRandomNavCircle(Player, 3.5f); timeToDrible = 0; } inGoalDir = false; } } } } if (inGoalDir) //Tudo livre para ir para o GOL { if (Locomotion.IsAgentDone || timeToGoal >= 1.5f) { toGo = goalPosition.position; timeToGoal = 0; } } Move(toGo); }
private void Handle_FollowBallState() { //Corre atraz da bola se ela estiver a uma distancia aceitavel ou procura um jogador mais proximo //enquanto continua indo atraz da bola. //Ação finalizada se: Jogador deixar de estar selecionado ou pegar a bola if (Player.IsMyBall() || !Player.IsSelected()) { Stop(); aiState = SoccerAIState.nothing; return; } Vector3 goTotarget = BallController.GetPosition(); BallController ball = BallController.instance; float balldistance = ball.transform.Distance(Player.transform); //Ativa movimento soccer se tiver stamina e estiver muito longe da bola if (balldistance > 5.0f && Player.isOk) { if (Player.GetSkill_Stamina().IsCritical == false) { motionType = LocomotionType.soccer; } else if (Player.GetSkill_Stamina().IsMin) { motionType = LocomotionType.normal; } } else { motionType = LocomotionType.normal; } SkillVar skillTug = Player.GetSkill_BasicActionOne(); SkillVar skillTrak = Player.GetSkill_BasicActionTwo(); //Ação Rasteira if (skillTrak.IsReady && Player.Locomotion.isJoint == false) { //Rasteira ou acao secundaria de poce de bola PlayerController enemyforward; if (Player.IsHitForwad(0.2f, out enemyforward, Player.GetCampTeam().Enemy())) { motionType = LocomotionType.normal; if (Locomotion.TriggerActionTwo()) { skillTrak.TriggerCooldown(); } } } //Ação TugOfWar if (!skillTrak.IsReady && skillTug.IsReady && Player.Locomotion.isJoint == false) { PlayerController enemy = Player.GetEnemyNear(); if (enemy != null) { if (enemy.Distance(Player) <= 1.5f && enemy.IsMyBall()) { Player.Locomotion.SetHoldTugAnimator(); } else { Player.Locomotion.ResetHoldTugAnimator(); } } } else if (Player.Locomotion.isJoint) { Player.Locomotion.ResetHoldTugAnimator(); goTotarget = Player.GetEnemyGoalPosition().position; if (skillTug.IsMax || Locomotion.JoitedPlayer.IsMyBall() == false) { skillTug.TriggerCooldown(); skillTug.SetCurrentValue(0); Player.GetTugOfWar().RemoveJoint(); } } //Verifica a distancia da bola, se estiver muito longe procuro outor jogador mais proximo para selecionar if (Player.GetCampTeam().GetSelectionMode() == GameOptionMode.automatric && Player.GetCampTeam().HasPlayerOk() && !Player.Locomotion.isJoint) { timeToSelect += Time.deltaTime; if (timeToSelect > 1.5f) { if (balldistance > 3.5f || Player.isOk == false) //Procurando jogador mais proximo { PlayerController nearBall = GameManager.instance.GetPlayerNearBall(Player.GetCampTeam()); if (nearBall != Player) { nearBall.SelectME(); timeToSelect = 0.0f; } } } } //Corre atraz do trajeto Agent.SetDestination(goTotarget); Vector2 move = Locomotion.GetDirectionAI(); Speed = move.y; Direction = move.x; }
public SoccerAISelected(AIController owner, PlayerController controller) : base(owner, controller) { aiState = SoccerAIState.nothing; }
private void Handlle_NothingState() { if (Agent.isOnNavMesh == false || Agent.enabled == false) { return; } //Se o jogador selecionado do meu time estive segurando um adversário //a prioridade é ir ajudar, pegando a bola do adversário if (Player.GetCampTeam().GetSelectedPlayer() != null) { if (Player.GetCampTeam().GetSelectedPlayer().Locomotion.isJoint&& Player.IsBallMostNearUnselected()) { aiState = SoccerAIState.helpTug; return; } } //Indo para a origem //Se eu não estiver no ponto de origem vou ir para ele. //Se a bola estiver com o time o ponto de marcao é o de ataque //se a bola não estiver a marcação é o de desefesa //Se eu ja estiver na origem entao vou marcar o jogador mais proximo caso a bola esteja muito longe de mim //Se a bola estiver perto entao vou ir atraz dela //Indo atraz da bola se estiver perto e nao estiver no pe do meu time bool isBallNear = Player.IsBallMostNear(); bool teamHasBall = Player.IsBallfromMyTeam(); if (isBallNear == true && !teamHasBall) { aiState = SoccerAIState.followBall; return; } //Indo para posição padrão bool inMarcation = Player.InMarcation(1.5f); bool inSelection = Player.IsSelected(); bool ballHasOwner = BallController.HasOwner(); if (!inMarcation && !inSelection && ballHasOwner) { Stop(); aiState = SoccerAIState.goToDefaultPosition; return; } //Marcando jogador mais proximo //... //Olhando para a bola Agent.destination = Player.transform.position; Lookat(BallController.GetPosition()); /* * //Indo atraz da bola se estiver perto * bool isBallNear = player.IsBallNear(); * if (!isBallNear) * { * aiState = AIState.followBall; * return; * } * * //Se eu estiver na defesa, vou marcar o jogador da minha posição no time adversario mas se eu esiver no ataque * //por hora vou ficar parado. * bool teamHasBall = player.IsBallfromMyTeam(); * if (!teamHasBall) * { * PlayerController enemy = player.GetEnemyInMarcation(); * if (enemy != null) * { * aiState = AIState.marcando; * return; * } * } */ }