mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-22 11:21:20 +00:00
Add maxTilesOwned tracking
This commit is contained in:
@@ -101,6 +101,7 @@ export const PlayerStatsSchema = z
|
||||
betrayals: BigIntStringSchema.optional(),
|
||||
killedAt: BigIntStringSchema.optional(),
|
||||
conquests: BigIntStringSchema.optional(),
|
||||
maxTilesOwned: BigIntStringSchema.optional(),
|
||||
boats: z.partialRecord(BoatUnitSchema, AtLeastOneNumberSchema).optional(),
|
||||
bombs: z.partialRecord(BombUnitSchema, AtLeastOneNumberSchema).optional(),
|
||||
gold: AtLeastOneNumberSchema.optional(),
|
||||
|
||||
@@ -561,10 +561,12 @@ export class GameImpl implements Game {
|
||||
previousOwner._lastTileChange = this._ticks;
|
||||
previousOwner._tiles.delete(tile);
|
||||
previousOwner._borderTiles.delete(tile);
|
||||
this._stats.updateMaxTiles(previousOwner);
|
||||
}
|
||||
this._map.setOwnerID(tile, owner.smallID());
|
||||
owner._tiles.add(tile);
|
||||
owner._lastTileChange = this._ticks;
|
||||
this._stats.updateMaxTiles(owner);
|
||||
this.updateBorders(tile);
|
||||
this._map.setFallout(tile, false);
|
||||
this.addUpdate({
|
||||
@@ -585,6 +587,7 @@ export class GameImpl implements Game {
|
||||
previousOwner._lastTileChange = this._ticks;
|
||||
previousOwner._tiles.delete(tile);
|
||||
previousOwner._borderTiles.delete(tile);
|
||||
this._stats.updateMaxTiles(previousOwner);
|
||||
|
||||
this._map.setOwnerID(tile, 0);
|
||||
this.updateBorders(tile);
|
||||
|
||||
@@ -8,6 +8,9 @@ export interface Stats {
|
||||
|
||||
numMirvsLaunched(): bigint;
|
||||
|
||||
// Update max tiles tracking for a player (called when tile ownership changes)
|
||||
updateMaxTiles(player: Player): void;
|
||||
|
||||
// Player attacks target
|
||||
attack(
|
||||
player: Player,
|
||||
|
||||
@@ -41,6 +41,7 @@ function _bigint(value: BigIntLike): bigint {
|
||||
|
||||
export class StatsImpl implements Stats {
|
||||
private readonly data: AllPlayersStats = {};
|
||||
private readonly maxTilesTracking: Map<string, bigint> = new Map();
|
||||
|
||||
private _numMirvLaunched: bigint = 0n;
|
||||
|
||||
@@ -58,6 +59,28 @@ export class StatsImpl implements Stats {
|
||||
return this.data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update max tiles tracking for a player
|
||||
* Called whenever player's tile count changes
|
||||
*/
|
||||
updateMaxTiles(player: Player): void {
|
||||
const clientID = player.clientID();
|
||||
if (clientID === null) return;
|
||||
|
||||
const currentTiles = _bigint(player.numTilesOwned());
|
||||
const maxTiles = this.maxTilesTracking.get(clientID) ?? 0n;
|
||||
|
||||
if (currentTiles > maxTiles) {
|
||||
this.maxTilesTracking.set(clientID, currentTiles);
|
||||
|
||||
// Update the player stats
|
||||
const p = this._makePlayerStats(player);
|
||||
if (p !== undefined) {
|
||||
p.maxTilesOwned = currentTiles;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private _makePlayerStats(player: Player): PlayerStats {
|
||||
const clientID = player.clientID();
|
||||
if (clientID === null) return undefined;
|
||||
|
||||
Reference in New Issue
Block a user