bugfix: SpawnExecution was not attaching PlayerExecution to humans

bugfix: WinModal was saying player died even if they hadn't spawned

added hasSpawned() method to player
This commit is contained in:
Evan
2025-04-03 20:12:36 -07:00
parent a3a05f9ed2
commit 9d1b4f35e4
6 changed files with 35 additions and 14 deletions
+2 -1
View File
@@ -215,7 +215,8 @@ export class WinModal extends LitElement implements Layer {
!this.hasShownDeathModal &&
myPlayer &&
!myPlayer.isAlive() &&
!this.game.inSpawnPhase()
!this.game.inSpawnPhase() &&
myPlayer.hasSpawned()
) {
this.hasShownDeathModal = true;
this._title = "You died";
+15 -13
View File
@@ -25,26 +25,28 @@ export class SpawnExecution implements Execution {
return;
}
let player: Player = null;
if (this.mg.hasPlayer(this.playerInfo.id)) {
const existing = this.mg.player(this.playerInfo.id);
existing.tiles().forEach((t) => existing.relinquish(t));
getSpawnTiles(this.mg, this.tile).forEach((t) => {
existing.conquer(t);
});
return;
player = this.mg.player(this.playerInfo.id);
} else {
player = this.mg.addPlayer(
this.playerInfo,
this.mg.config().startManpower(this.playerInfo),
);
}
const player = this.mg.addPlayer(
this.playerInfo,
this.mg.config().startManpower(this.playerInfo),
);
player.tiles().forEach((t) => player.relinquish(t));
getSpawnTiles(this.mg, this.tile).forEach((t) => {
player.conquer(t);
});
this.mg.addExecution(new PlayerExecution(player.id()));
if (player.type() == PlayerType.Bot) {
this.mg.addExecution(new BotExecution(player));
if (!player.hasSpawned()) {
this.mg.addExecution(new PlayerExecution(player.id()));
if (player.type() == PlayerType.Bot) {
this.mg.addExecution(new BotExecution(player));
}
}
player.setHasSpawned(true);
}
owner(): Player {
+3
View File
@@ -316,6 +316,9 @@ export interface Player {
largestClusterBoundingBox: { min: Cell; max: Cell } | null;
lastTileChange(): Tick;
hasSpawned(): boolean;
setHasSpawned(hasSpawned: boolean): void;
// Territory
tiles(): ReadonlySet<TileRef>;
borderTiles(): ReadonlySet<TileRef>;
+1
View File
@@ -111,6 +111,7 @@ export interface PlayerUpdate {
incomingAttacks: AttackUpdate[];
outgoingAllianceRequests: PlayerID[];
stats: PlayerStats;
hasSpawned: boolean;
}
export interface AllianceRequestUpdate {
+3
View File
@@ -266,6 +266,9 @@ export class PlayerView {
stats(): PlayerStats {
return this.data.stats;
}
hasSpawned(): boolean {
return this.data.hasSpawned;
}
}
export class GameView implements GameMap {
+11
View File
@@ -94,6 +94,8 @@ export class PlayerImpl implements Player {
public _outgoingAttacks: Attack[] = [];
public _outgoingLandAttacks: Attack[] = [];
private _hasSpawned = false;
constructor(
private mg: GameImpl,
private _smallID: number,
@@ -162,6 +164,7 @@ export class PlayerImpl implements Player {
),
outgoingAllianceRequests: outgoingAllianceRequests,
stats: this.mg.stats().getPlayerStats(this.id()),
hasSpawned: this.hasSpawned(),
};
}
@@ -291,6 +294,14 @@ export class PlayerImpl implements Player {
return this._tiles.size > 0;
}
hasSpawned(): boolean {
return this._hasSpawned;
}
setHasSpawned(hasSpawned: boolean): void {
this._hasSpawned = hasSpawned;
}
incomingAllianceRequests(): AllianceRequest[] {
return this.mg.allianceRequests.filter((ar) => ar.recipient() == this);
}