public override void Update() { var ballMap = Game.GameManager.Navigation.PotentialMaps["BallMap"]; if (PlayerAI.Player.Ball != null) { var target = Game.GameManager.Players[0]; var dir = target.Position - PlayerAI.Position; PlayerAI.AimAtPosition(target.Position); if (!PlayerAI.Player.IsShotCharging) { PlayerAI.StartShotCharge(); } if (PlayerAI.Player.IsShotCharged) { PlayerAI.ShootCharged(dir); } } else if (Game.GameManager.Ball != null && Game.GameManager.Ball.Player == null) { PlayerAI.NavigateToBall(); } }
private void AimAndPass(Vector2 position) { PlayerAI.AimAtPosition(position); if (PlayerAI.IsAimingAtPosition(position)) { PlayerAI.Pass(PlayerAI.GetAim()); } }
private void AttackMode() { Engine.Log.Debug("State " + PlayerAI.Player.PlayerIndex, "Attack"); //Compute a tactical value based on the distance to opponents float tacticalDistance = 300; float tacticalValue = Math.Min( 1 - LBE.MathHelper.WeightDistance(PlayerAI.Player.Position, tacticalDistance, PlayerAI.Player.Opponents[0].Position), 1 - LBE.MathHelper.WeightDistance(PlayerAI.Player.Position, tacticalDistance, PlayerAI.Player.Opponents[1].Position)); float mateTacticalValue = Math.Min( 1 - LBE.MathHelper.WeightDistance(PlayerAI.Player.TeamMate.Position, tacticalDistance, PlayerAI.Player.Opponents[0].Position), 1 - LBE.MathHelper.WeightDistance(PlayerAI.Player.TeamMate.Position, tacticalDistance, PlayerAI.Player.Opponents[1].Position)); //Check if the player can shoot from its current position bool canShoot; bool mateCanShoot; CheckShootPossible(out canShoot, out mateCanShoot); float shootValue = GetShootValue(PlayerAI.Player.Team, PlayerAI.Player.Position); float mateShootValue = GetShootValue(PlayerAI.Player.Team, PlayerAI.Player.TeamMate.Position); float passTacticalValue = 0.75f; float dangerTacticalValue = 0.40f; //Get distance to goal Goal goal = Game.Arena.LeftGoal.Team == PlayerAI.Player.Team ? Game.Arena.RightGoal : Game.Arena.LeftGoal; float distFromGoal = Vector2.Distance(goal.Position, PlayerAI.Position); MoveToShootPosition(); if (distFromGoal < 250 && canShoot) { PlayerAI.AimAtPosition(goal.Position); } //Set a delay before shooting or passing the ball when we just got it float shootDelayMin = Engine.Debug.EditSingle("AIShootDelayMin", 80); float shootDelayDistanceBase = Engine.Debug.EditSingle("AIShootDelayDistanceBase", 400); float shootDelayDistanceCoefMax = Engine.Debug.EditSingle("AIShootDelayDistanceCoefMax", 5); float shootDelaySkillBase = Engine.Debug.EditSingle("AIShootDelaySkillBase", 400); float shootDelaySkillCoefMin = Engine.Debug.EditSingle("AIShootDelaySkillCoefMin", 0.5f); //Shoot faster if closer to goal float distanceCoef = LBE.MathHelper.LinearStep(100, 600, distFromGoal); //More agressive AI will shoot faster float agresssivnessCoef = LBE.MathHelper.Lerp(shootDelaySkillCoefMin, 1.0f, (1 - PlayerAI.AiState.AgressivenessCoef)); float shootDelay = shootDelayMin + shootDelayDistanceBase * distanceCoef + shootDelaySkillBase * agresssivnessCoef; if (Engine.GameTime.TimeMS - PlayerAI.Info.BallTakenTime < shootDelay) { return; } //If possible, shoot if (canShoot) { PlayerAI.ShootIfPossible(); } //If mate can shoot has good tactical value, pass the ball else if (PlayerAI.AiState.Pass && mateCanShoot && mateTacticalValue > passTacticalValue) { AimAndPass(PlayerAI.Player.TeamMate.Position); } //If personal tactical value is bad, do an emergency pass else if (PlayerAI.AiState.Pass && tacticalValue < dangerTacticalValue && mateTacticalValue > tacticalValue) { AimAndPass(PlayerAI.Player.TeamMate.Position); } //If mate has better tactical value, pass the ball else if (PlayerAI.AiState.Pass && mateTacticalValue > tacticalValue && mateShootValue > shootValue) { AimAndPass(PlayerAI.Player.TeamMate.Position); } }