Files
OpenFrontIO/src/core/execution/MissileSiloExecution.ts
T
evanpelle 1d0732d3d9 Refactor UnitSpecific info => AllUnitParams type union (#701)
## Description:

By using a type union we get better type safety, enforcing each unit
type have the appropriate params when initializing

## Please complete the following:

- [x] I have added screenshots for all UI updates
- [x] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced
- [x] I understand that submitting code with bugs that could have been
caught through manual testing blocks releases and new features for all
contributors

## Please put your Discord username so you can be contacted if a bug or
regression is found:
evan

---------

Co-authored-by: evan <openfrontio@gmail.com>
2025-05-10 11:40:47 -07:00

69 lines
1.5 KiB
TypeScript

import { consolex } from "../Consolex";
import {
Execution,
Game,
Player,
PlayerID,
Unit,
UnitType,
} from "../game/Game";
import { TileRef } from "../game/GameMap";
export class MissileSiloExecution implements Execution {
private active = true;
private mg: Game;
private player: Player;
private silo: Unit;
constructor(
private _owner: PlayerID,
private tile: TileRef,
) {}
init(mg: Game, ticks: number): void {
if (!mg.hasPlayer(this._owner)) {
console.warn(`MissileSiloExecution: owner ${this._owner} not found`);
this.active = false;
return;
}
this.mg = mg;
this.player = mg.player(this._owner);
}
tick(ticks: number): void {
if (this.silo == null) {
const spawn = this.player.canBuild(UnitType.MissileSilo, this.tile);
if (spawn === false) {
consolex.warn(
`player ${this.player} cannot build missile silo at ${this.tile}`,
);
this.active = false;
return;
}
this.silo = this.player.buildUnit(UnitType.MissileSilo, spawn, {
cooldownDuration: this.mg.config().SiloCooldown(),
});
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.setCooldown(false);
}
}
isActive(): boolean {
return this.active;
}
activeDuringSpawnPhase(): boolean {
return false;
}
}