mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 14:50:24 +00:00
42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
import {Cell, Execution, MutableGame, MutablePlayer, PlayerInfo} from "../Game"
|
|
import {BotExecution} from "./BotExecution"
|
|
import {PlayerExecution} from "./PlayerExecution"
|
|
import {getSpawnCells} from "./Util"
|
|
|
|
export class SpawnExecution implements Execution {
|
|
|
|
active: boolean = true
|
|
private gs: MutableGame
|
|
|
|
constructor(
|
|
private playerInfo: PlayerInfo,
|
|
private cell: Cell,
|
|
) { }
|
|
|
|
|
|
init(gs: MutableGame, ticks: number) {
|
|
this.gs = gs
|
|
}
|
|
|
|
tick(ticks: number) {
|
|
if (!this.isActive()) {
|
|
return
|
|
}
|
|
const player = this.gs.addPlayer(this.playerInfo)
|
|
getSpawnCells(this.gs, this.cell).forEach(c => {
|
|
console.log('conquering cell')
|
|
player.conquer(this.gs.tile(c))
|
|
})
|
|
this.gs.addExecution(new PlayerExecution(player.id()))
|
|
if (player.info().isBot) {
|
|
this.gs.addExecution(new BotExecution(player))
|
|
}
|
|
this.active = false
|
|
}
|
|
owner(): MutablePlayer {
|
|
return null
|
|
}
|
|
isActive(): boolean {
|
|
return this.active
|
|
}
|
|
} |