create defense post

This commit is contained in:
Evan
2024-12-01 19:54:04 -08:00
parent e479c15ef9
commit d133092317
12 changed files with 127 additions and 29 deletions
+14 -1
View File
@@ -1,4 +1,5 @@
import { Cell, Execution, MutableGame, MutablePlayer, MutableUnit, PlayerID, Tile, UnitType } from "../game/Game";
import { Cell, DefenseBonus, Execution, MutableGame, MutablePlayer, MutableUnit, PlayerID, Tile, UnitType } from "../game/Game";
import { bfs, dist } from "../Util";
export class DefensePostExecution implements Execution {
@@ -8,6 +9,8 @@ export class DefensePostExecution implements Execution {
private tile: Tile
private active: boolean = true
private defenseBonuses: DefenseBonus[] = []
constructor(private ownerId: PlayerID, private cell: Cell) { }
init(mg: MutableGame, ticks: number): void {
@@ -25,6 +28,16 @@ export class DefensePostExecution implements Execution {
return
}
this.post = this.player.buildUnit(UnitType.DefensePost, 0, spawnTile)
bfs(spawnTile, dist(spawnTile, this.mg.config().defensePostRange())).forEach(t => {
if (t.isLand()) {
this.defenseBonuses.push(this.mg.addTileDefenseBonus(t, this.post, this.mg.config().defensePostDefenseBonus()))
}
})
}
if (!this.post.isActive()) {
this.defenseBonuses.forEach(df => this.mg.removeTileDefenseBonus(df))
this.active = false
return
}
}