mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-23 18:40:29 +00:00
feat: stats system to see number of nukes sent by a player in PlayerPanel
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import { NukeType, Player, PlayerID, UnitType } from "./Game";
|
||||
import { PlayerStats, Stats } from "./Stats";
|
||||
|
||||
interface StatsInternalData {
|
||||
// player
|
||||
[key: PlayerID]: PlayerStats;
|
||||
}
|
||||
|
||||
export class StatsImpl implements Stats {
|
||||
data: StatsInternalData = {};
|
||||
|
||||
_createUserData(sender: PlayerID, target: PlayerID): void {
|
||||
if (!this.data[sender]) {
|
||||
this.data[sender] = { sentNukes: {} };
|
||||
}
|
||||
if (!this.data[sender].sentNukes[target]) {
|
||||
this.data[sender].sentNukes[target] = {
|
||||
[UnitType.MIRV]: 0,
|
||||
[UnitType.MIRVWarhead]: 0,
|
||||
[UnitType.AtomBomb]: 0,
|
||||
[UnitType.HydrogenBomb]: 0,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
increaseNukeCount(sender: PlayerID, target: PlayerID, type: NukeType): void {
|
||||
this._createUserData(sender, target);
|
||||
this.data[sender].sentNukes[target][type]++;
|
||||
}
|
||||
|
||||
getPlayerStats(player: PlayerID): PlayerStats {
|
||||
return this.data[player];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user