mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-01 19:33:29 +00:00
51519b0b9d
## Description: Enable the tsconfig option `strictPropertyInitialization`. Fixes #1907 ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced
58 lines
1.4 KiB
TypeScript
58 lines
1.4 KiB
TypeScript
import { Execution, Game, Player, Unit, UnitType } from "../game/Game";
|
|
import { TileRef } from "../game/GameMap";
|
|
|
|
export class MissileSiloExecution implements Execution {
|
|
private active = true;
|
|
private mg: Game | undefined;
|
|
private silo: Unit | null = null;
|
|
|
|
constructor(
|
|
private player: Player,
|
|
private readonly tile: TileRef,
|
|
) {}
|
|
|
|
init(mg: Game, ticks: number): void {
|
|
this.mg = mg;
|
|
}
|
|
|
|
tick(ticks: number): void {
|
|
if (this.silo === null) {
|
|
const spawn = this.player.canBuild(UnitType.MissileSilo, this.tile);
|
|
if (spawn === false) {
|
|
console.warn(
|
|
`player ${this.player} cannot build missile silo at ${this.tile}`,
|
|
);
|
|
this.active = false;
|
|
return;
|
|
}
|
|
this.silo = this.player.buildUnit(UnitType.MissileSilo, spawn, {});
|
|
|
|
if (this.player !== this.silo.owner()) {
|
|
this.player = this.silo.owner();
|
|
}
|
|
}
|
|
|
|
// frontTime is the time the earliest missile fired.
|
|
const frontTime = this.silo.missileTimerQueue()[0];
|
|
if (frontTime === undefined) {
|
|
return;
|
|
}
|
|
|
|
if (this.mg === undefined) throw new Error("Not initialized");
|
|
const cooldown =
|
|
this.mg.config().SiloCooldown() - (this.mg.ticks() - frontTime);
|
|
|
|
if (cooldown <= 0) {
|
|
this.silo.reloadMissile();
|
|
}
|
|
}
|
|
|
|
isActive(): boolean {
|
|
return this.active;
|
|
}
|
|
|
|
activeDuringSpawnPhase(): boolean {
|
|
return false;
|
|
}
|
|
}
|