sistema de verguenza persistente
This commit is contained in:
@@ -229,6 +229,12 @@ export class GameRoom extends Room<GameState> {
|
||||
const p2 = this.state.p2Id ? this.state.players.get(this.state.p2Id) : undefined;
|
||||
if (p2) {
|
||||
p2.shameTokens += 1;
|
||||
// Persist sticky shame per UUID
|
||||
try {
|
||||
const { NameManager } = require("../utils/nameManager");
|
||||
const u = (p2 as any)?.uuid;
|
||||
if (u) NameManager.getInstance().setShameTokens(u, p2.shameTokens);
|
||||
} catch {}
|
||||
// Notify dashboard of token change
|
||||
broadcastDashboardUpdate();
|
||||
}
|
||||
@@ -320,11 +326,17 @@ export class GameRoom extends Room<GameState> {
|
||||
const playerColor = (options.playerColor && typeof options.playerColor === 'string') ? options.playerColor : "#667eea";
|
||||
|
||||
const player = this.state.addPlayer(client.sessionId, playerName);
|
||||
// Persist selected color
|
||||
// Persist selected color and restore sticky values
|
||||
const p = this.state.players.get(client.sessionId);
|
||||
if (p) {
|
||||
p.color = playerColor;
|
||||
if (uuid) (p as any).uuid = uuid;
|
||||
if (uuid) {
|
||||
(p as any).uuid = uuid;
|
||||
try {
|
||||
const { NameManager } = require("../utils/nameManager");
|
||||
p.shameTokens = NameManager.getInstance().getShameTokens(uuid);
|
||||
} catch {}
|
||||
}
|
||||
}
|
||||
|
||||
client.send("playerInfo", {
|
||||
@@ -781,6 +793,13 @@ export class GameRoom extends Room<GameState> {
|
||||
player.color = playerColor;
|
||||
(player as any).uuid = uuid;
|
||||
this.sessionToUuid.set(client.sessionId, uuid);
|
||||
// Restore sticky shame tokens for this UUID
|
||||
try {
|
||||
const { NameManager } = require("../utils/nameManager");
|
||||
const count = NameManager.getInstance().getShameTokens(uuid);
|
||||
const p = this.state.players.get(client.sessionId);
|
||||
if (p) p.shameTokens = count;
|
||||
} catch {}
|
||||
|
||||
// Set role IDs
|
||||
if (expectedRole === 'P1') {
|
||||
|
||||
@@ -55,10 +55,15 @@ export class GameState extends Schema {
|
||||
}
|
||||
|
||||
startGame(): void {
|
||||
// Preserve sticky values across new game start as well
|
||||
const shameSnapshot: Record<string, number> = {};
|
||||
this.players.forEach((p, key) => { shameSnapshot[key] = p.shameTokens; });
|
||||
|
||||
this.gameStatus = GameStatus.PLAYING;
|
||||
this.startTime = Date.now();
|
||||
this.timeRemaining = 0;
|
||||
this.resetAllPlayers();
|
||||
this.players.forEach((p, key) => { p.shameTokens = shameSnapshot[key] || 0; });
|
||||
// Initialize tokens by role
|
||||
if (this.p1Id) {
|
||||
const p1 = this.players.get(this.p1Id);
|
||||
@@ -88,6 +93,10 @@ export class GameState extends Schema {
|
||||
}
|
||||
|
||||
restartGame(): void {
|
||||
// Preserve sticky values (e.g., shameTokens) across restarts
|
||||
const shameSnapshot: Record<string, number> = {};
|
||||
this.players.forEach((p, key) => { shameSnapshot[key] = p.shameTokens; });
|
||||
|
||||
this.gameStatus = GameStatus.WAITING;
|
||||
this.timeRemaining = 0;
|
||||
this.winner = "";
|
||||
@@ -99,6 +108,9 @@ export class GameState extends Schema {
|
||||
this.requestPavo = this.requestElote = 0;
|
||||
this.offerActive = false;
|
||||
this.resetAllPlayers();
|
||||
|
||||
// Restore preserved sticky values
|
||||
this.players.forEach((p, key) => { p.shameTokens = shameSnapshot[key] || 0; });
|
||||
}
|
||||
|
||||
private resetAllPlayers(): void {
|
||||
|
||||
Reference in New Issue
Block a user