public static bool canAttackJob(TowerJob towerJ, UnitJob unitJ) { if (unitJ == AI.WORKER) { return(false); } if (towerJ == AI.CASTLE) { return(true); } if (towerJ == AI.CLEANSING) { return(unitJ == AI.WRAITH || unitJ == AI.ABOMINATION); } return(unitJ != AI.WRAITH); }
/// <summary> /// This is automatically called when the game first starts, once the Game and all GameObjects have been initialized, but before any players do anything. /// </summary> /// <remarks> /// This is a good place to initialize any variables you add to your AI or start tracking game objects. /// </remarks> public override void Start() { // <<-- Creer-Merge: start -->> - Code you add between this comment and the end comment will be preserved between Creer re-runs. base.Start(); AI.GAME = this.Game; AI.US = this.Player; AI.THEM = this.Game.Players.First(p => p != AI.US); AI.CASTLE = this.Game.TowerJobs.First(t => t.Title == "castle"); AI.CLEANSING = this.Game.TowerJobs.First(t => t.Title == "cleansing"); AI.BALLISTA = this.Game.TowerJobs.First(t => t.Title == "ballista"); AI.ARROW = this.Game.TowerJobs.First(t => t.Title == "arrow"); AI.AOE = this.Game.TowerJobs.First(t => t.Title == "aoe"); AI.WORKER = this.Game.UnitJobs.First(t => t.Title == "worker"); AI.ZOMBIE = this.Game.UnitJobs.First(t => t.Title == "zombie"); AI.GHOUL = this.Game.UnitJobs.First(t => t.Title == "ghoul"); AI.HOUND = this.Game.UnitJobs.First(t => t.Title == "hound"); AI.ABOMINATION = this.Game.UnitJobs.First(t => t.Title == "abomination"); AI.WRAITH = this.Game.UnitJobs.First(t => t.Title == "wraith"); AI.HORSEMAN = this.Game.UnitJobs.First(t => t.Title == "horseman"); AI.UNIT_SPAWNER = this.Game.Tiles.First(t => t.IsUnitSpawn && t.Owner == AI.US); AI.WORKER_SPAWNER = this.Game.Tiles.First(t => t.IsWorkerSpawn && t.Owner == AI.US); AI.OUR_CASTLE = AI.US.Towers.First(t => t.Job == AI.CASTLE); AI.THEIR_CASTLE = AI.THEM.Towers.First(t => t.Job == AI.CASTLE); AI.GOLD_MINES = new HashSet <Tile>(AI.GAME.Tiles.Where(t => t.IsGoldMine && t.Owner == AI.US)); AI.ISLAND_GOLD_MINES = new HashSet <Tile>(AI.GAME.Tiles.Where(t => t.IsIslandGoldMine)); AI.RIVER_NEIGHBORS = new HashSet <Tile>(AI.GAME.Tiles.Where(t => t.IsRiver).SelectMany(t => t.GetNeighbors()).Where(t => t.IsGrass)); AI.CASTLE_TOWER = AI.US.Towers.First(t => t.Job == AI.CASTLE); var castleTile = AI.CASTLE_TOWER.Tile; if (castleTile.TileNorth.TileNorth.IsPath) { var leftX = castleTile.X - 1; var rightX = castleTile.X + 2; var startY = castleTile.Y - 3; AI.LEFT_TOWERS = Enumerable.Range(0, 15).Select(o => AI.GAME.GetTileAt(leftX, startY - o)).ToList(); AI.RIGHT_TOWERS = Enumerable.Range(0, 15).Select(o => AI.GAME.GetTileAt(rightX, startY - o)).ToList(); } else { var leftX = castleTile.X - 2; var rightX = castleTile.X + 1; var startY = castleTile.Y + 3; AI.LEFT_TOWERS = Enumerable.Range(0, 15).Select(o => AI.GAME.GetTileAt(leftX, startY + o)).ToList(); AI.RIGHT_TOWERS = Enumerable.Range(0, 15).Select(o => AI.GAME.GetTileAt(rightX, startY + o)).ToList(); } AI.TOWER_PATTERN = new List <TowerJob>() { AI.CLEANSING, AI.AOE, AI.ARROW }; string[][] patterns = new string[][] { new[] { "0110110", "1001001", "1000001", "0100010", "0010100", "0001000" }, // Heart new[] { "00111100", "01000010", "10100101", "10000001", "10100101", "10011001", "01000010", "00100100" }, // Smiley new[] { "01010", "10001", "11011", "01110", "00100", "00100", "00100" }, // Wrench new[] { "01100", "00010", "00101", "01001", "10000" }, // Pick axe new[] { "100010010", "100101010", "110010011" }, // L O L new[] { "00011000", "00100100", "01000010", "10000001", "01111110" }, // Delta new[] { "0001000", "0011100", "0000000", "0100010", "1110111" } // Triforce }; ; var pattern = patterns[new Random().Next(patterns.Length)]; Console.WriteLine(String.Join("\n", pattern)); AI.PATTERN = new HashSet <Tile>(); Tile patternAnchor; if (AI.CASTLE_TOWER.Tile.TileNorth.TileNorth.IsPath) { patternAnchor = AI.GAME.GetTileAt(36, 11); } else { patternAnchor = AI.GAME.GetTileAt(27 - pattern[0].Length, 11); } for (int x = 0; x < pattern[0].Length; x++) { for (int y = 0; y < pattern.Length; y++) { if (pattern[y][x] == '1') { AI.PATTERN.Add(AI.GAME.GetTileAt(patternAnchor.X + x, patternAnchor.Y + y)); } } } // <<-- /Creer-Merge: start -->> }
public static bool CanAfford(Player player, TowerJob job) { return(player.Gold >= job.GoldCost && player.Mana >= job.ManaCost); }