mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-22 22:05:21 +00:00
9c7e0ce32f
## Description: Answering issue: #1017 [Cleanup] Pass Player into the execution constructor instead of PlayerID I have tested the changes running and playing a full game. I do not know other way to test the changes, please inform me ❤️ ## 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 - [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: Lele --------- Co-authored-by: lva <lva@rovsing.dk>
57 lines
1.3 KiB
TypeScript
57 lines
1.3 KiB
TypeScript
import { Execution, Game, Player, PlayerInfo, PlayerType } from "../game/Game";
|
|
import { TileRef } from "../game/GameMap";
|
|
import { BotExecution } from "./BotExecution";
|
|
import { PlayerExecution } from "./PlayerExecution";
|
|
import { getSpawnTiles } from "./Util";
|
|
|
|
export class SpawnExecution implements Execution {
|
|
active: boolean = true;
|
|
private mg: Game;
|
|
|
|
constructor(
|
|
private playerInfo: PlayerInfo,
|
|
public readonly tile: TileRef,
|
|
) {}
|
|
|
|
init(mg: Game, ticks: number) {
|
|
this.mg = mg;
|
|
}
|
|
|
|
tick(ticks: number) {
|
|
this.active = false;
|
|
|
|
if (!this.mg.inSpawnPhase()) {
|
|
this.active = false;
|
|
return;
|
|
}
|
|
|
|
let player: Player | null = null;
|
|
if (this.mg.hasPlayer(this.playerInfo.id)) {
|
|
player = this.mg.player(this.playerInfo.id);
|
|
} else {
|
|
player = this.mg.addPlayer(this.playerInfo);
|
|
}
|
|
|
|
player.tiles().forEach((t) => player.relinquish(t));
|
|
getSpawnTiles(this.mg, this.tile).forEach((t) => {
|
|
player.conquer(t);
|
|
});
|
|
|
|
if (!player.hasSpawned()) {
|
|
this.mg.addExecution(new PlayerExecution(player));
|
|
if (player.type() === PlayerType.Bot) {
|
|
this.mg.addExecution(new BotExecution(player));
|
|
}
|
|
}
|
|
player.setHasSpawned(true);
|
|
}
|
|
|
|
isActive(): boolean {
|
|
return this.active;
|
|
}
|
|
|
|
activeDuringSpawnPhase(): boolean {
|
|
return true;
|
|
}
|
|
}
|