Files
OpenFrontIO/src/core/execution/MissileSiloExecution.ts
T
2024-11-17 10:33:13 -08:00

55 lines
1.4 KiB
TypeScript

import { Cell, Execution, MutableGame, MutablePlayer, MutableUnit, Player, PlayerID, Tile, Unit, UnitType } from "../game/Game";
export class MissileSiloExecution implements Execution {
private active = true
private mg: MutableGame
private player: MutablePlayer
private silo: MutableUnit
constructor(
private _owner: PlayerID,
private cell: Cell
) { }
init(mg: MutableGame, ticks: number): void {
this.mg = mg
this.player = mg.player(this._owner)
}
tick(ticks: number): void {
if (this.silo == null) {
const tile = this.mg.tile(this.cell)
if (!this.player.canBuild(UnitType.MissileSilo, tile)) {
console.warn(`player ${this.player} cannot build port at ${this.cell}`)
this.active = false
return
}
this.silo = this.player.buildUnit(UnitType.MissileSilo, 0, tile)
}
if (!this.silo.tile().hasOwner()) {
this.silo.delete()
this.active = false
return
}
if (this.silo.tile().owner() != this.silo.owner()) {
this.silo.setOwner(this.silo.tile().owner() as Player)
this.player = this.silo.owner()
}
}
owner(): MutablePlayer {
return null
}
isActive(): boolean {
return this.active
}
activeDuringSpawnPhase(): boolean {
return false
}
}