mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-14 18:46:06 +00:00
add clan() function on playerinfo and Player
This commit is contained in:
+12
-1
@@ -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[];
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user