bugfix: SpawnExecution couldn't find existing player because Game.Players() only returns alive players. This caused SpawnExecution to respawn each human player.

This commit is contained in:
Evan
2025-04-03 19:31:42 -07:00
parent e1a299c8c5
commit 9fa3691c5c
4 changed files with 10 additions and 18 deletions
+5 -1
View File
@@ -25,6 +25,8 @@ import {
} from "./game/GameUpdates";
import { loadTerrainMap as loadGameMap } from "./game/TerrainMapLoader";
import { ClientID, GameStartInfo, Turn } from "./Schemas";
import { sanitize } from "./Util";
import { fixProfaneUsername } from "./validations/username";
export async function createGameRunner(
gameStart: GameStartInfo,
@@ -38,7 +40,9 @@ export async function createGameRunner(
(p) =>
new PlayerInfo(
p.flag,
p.username,
p.clientID == clientID
? sanitize(p.username)
: fixProfaneUsername(sanitize(p.username)),
PlayerType.Human,
p.clientID,
p.playerID,
+2 -12
View File
@@ -1,8 +1,7 @@
import { Execution, Game, PlayerInfo, PlayerType } from "../game/Game";
import { PseudoRandom } from "../PseudoRandom";
import { ClientID, GameID, Intent, Turn } from "../Schemas";
import { sanitize, simpleHash } from "../Util";
import { fixProfaneUsername } from "../validations/username";
import { simpleHash } from "../Util";
import { AllianceRequestExecution } from "./alliance/AllianceRequestExecution";
import { AllianceRequestReplyExecution } from "./alliance/AllianceRequestReplyExecution";
import { BreakAllianceExecution } from "./alliance/BreakAllianceExecution";
@@ -62,16 +61,7 @@ export class Executor {
return new MoveWarshipExecution(intent.unitId, intent.tile);
case "spawn":
return new SpawnExecution(
new PlayerInfo(
intent.flag,
// Players see their original name, others see a sanitized version
intent.clientID == this.clientID
? sanitize(intent.name)
: fixProfaneUsername(sanitize(intent.name)),
PlayerType.Human,
intent.clientID,
playerID,
),
player.info(),
this.mg.ref(intent.x, intent.y),
);
case "boat":
+2 -4
View File
@@ -25,10 +25,8 @@ export class SpawnExecution implements Execution {
return;
}
const existing = this.mg
.players()
.find((p) => p.id() == this.playerInfo.id);
if (existing) {
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);
+1 -1
View File
@@ -99,7 +99,7 @@ export class PlayerImpl implements Player {
private _smallID: number,
private readonly playerInfo: PlayerInfo,
startTroops: number,
private _team: Team | null,
private readonly _team: Team | null,
) {
this._flag = playerInfo.flag;
this._name = sanitizeUsername(playerInfo.name);