Add maxTilesOwned tracking

This commit is contained in:
Trajkov Dimitar
2025-10-20 14:56:35 +02:00
parent 4c6c6ba26c
commit ae81acd8e3
4 changed files with 30 additions and 0 deletions
+1
View File
@@ -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(),
+3
View File
@@ -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);
+3
View File
@@ -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,
+23
View File
@@ -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;