MissileSiloExecution

This commit is contained in:
Scott Anderson
2025-04-14 19:51:40 -04:00
parent 6f63b63986
commit 544a291c14
+10 -6
View File
@@ -11,9 +11,9 @@ import { TileRef } from "../game/GameMap";
export class MissileSiloExecution implements Execution {
private active = true;
private mg: Game;
private player: Player;
private silo: Unit;
private mg: Game | null = null;
private player: Player | null = null;
private silo: Unit | null = null;
constructor(
private _owner: PlayerID,
@@ -32,7 +32,11 @@ export class MissileSiloExecution implements Execution {
}
tick(ticks: number): void {
if (this.silo == null) {
if (this.mg === null || this.player === null) {
throw new Error("Not initialized");
}
if (this.silo === null) {
if (!this.player.canBuild(UnitType.MissileSilo, this.tile)) {
consolex.warn(
`player ${this.player} cannot build missile silo at ${this.tile}`,
@@ -44,14 +48,14 @@ export class MissileSiloExecution implements Execution {
cooldownDuration: this.mg.config().SiloCooldown(),
});
if (this.player != this.silo.owner()) {
if (this.player !== this.silo.owner()) {
this.player = this.silo.owner();
}
}
if (
this.silo.isCooldown() &&
this.silo.ticksLeftInCooldown(this.mg.config().SiloCooldown()) == 0
this.silo.ticksLeftInCooldown(this.mg.config().SiloCooldown()) === 0
) {
this.silo.setCooldown(false);
}