add clan() function on playerinfo and Player

This commit is contained in:
Evan
2025-03-29 15:24:11 -07:00
parent 0891637eb2
commit 83eec17717
3 changed files with 120 additions and 1 deletions
+12 -1
View File
@@ -211,6 +211,8 @@ export interface MutableAlliance extends Alliance {
}
export class PlayerInfo {
public readonly clan: string | null;
constructor(
public readonly flag: string,
public readonly name: string,
@@ -220,7 +222,15 @@ export class PlayerInfo {
// TODO: make player id the small id
public readonly id: PlayerID,
public readonly nation?: Nation | null,
) {}
) {
// Compute clan from name
if (!name.startsWith("[") || !name.includes("]")) {
this.clan = null;
} else {
const clanMatch = name.match(/^\[([A-Z]{2,5})\]/);
this.clan = clanMatch ? clanMatch[1] : null;
}
}
}
// Some units have info specific to them
@@ -349,6 +359,7 @@ export interface Player {
// Either allied or on same team.
isFriendly(other: Player): boolean;
team(): Team | null;
clan(): string | null;
incomingAllianceRequests(): AllianceRequest[];
outgoingAllianceRequests(): AllianceRequest[];
alliances(): MutableAlliance[];
+4
View File
@@ -194,6 +194,10 @@ export class PlayerImpl implements Player {
return this.playerInfo.playerType;
}
clan(): string | null {
return this.playerInfo.clan;
}
units(...types: UnitType[]): UnitImpl[] {
if (types.length == 0) {
return this._units;