feat: Implement resume match button, enhance card image loading, and improve server-side logging and deck handling.

This commit is contained in:
2025-12-22 22:15:32 +01:00
parent 325f82ff6b
commit c88c8ced15
6 changed files with 50 additions and 10 deletions

View File

@@ -615,7 +615,8 @@ export class RulesEngine {
console.log(`Player ${playerId} draws ${card.name}`);
} else {
// Empty library loss?
console.log(`Player ${playerId} attempts to draw from empty library.`);
// Empty library loss?
console.warn(`[RulesEngine] Player ${playerId} attempts to draw from empty library. (Deck size: 0)`);
}
}

View File

@@ -61,6 +61,8 @@ export class GameManager extends EventEmitter {
// Track rooms where a bot is currently "thinking" to avoid double-queuing
private thinkingRooms: Set<string> = new Set();
// Throttle logs
private lastBotLog: Record<string, number> = {};
// Helper to trigger bot actions if game is stuck or just started
public triggerBotCheck(roomId: string): StrictGameState | null {
@@ -86,7 +88,11 @@ export class GameManager extends EventEmitter {
// If it is a Bot's turn to have priority, and we aren't already processing
if (priorityPlayer?.isBot && !this.thinkingRooms.has(roomId)) {
console.log(`[Bot Loop] Bot ${priorityPlayer.name} is thinking...`);
const now = Date.now();
if (!this.lastBotLog[roomId] || now - this.lastBotLog[roomId] > 5000) {
console.log(`[Bot Loop] Bot ${priorityPlayer.name} is thinking...`);
this.lastBotLog[roomId] = now;
}
this.thinkingRooms.add(roomId);
setTimeout(() => {
@@ -206,8 +212,18 @@ export class GameManager extends EventEmitter {
if (!bot || !bot.isBot) return;
// 1. Mulligan: Always Keep
// 1. Mulligan: Always Keep (but check if we have cards?)
if (game.step === 'mulligan') {
const hand = Object.values(game.cards).filter(c => c.ownerId === botId && c.zone === 'hand');
if (hand.length === 0 && !bot.handKept) {
// We have NO cards to keep? Something is wrong (deck didn't load?).
// Don't loop infinitely trying to keep an empty hand if that's invalid,
// but technically "keeping" 0 cards is just accepting 0 cards.
// However, usually this means initialization failed.
// We'll log once and stop? Or just keep to unstuck the game?
// Let's try to keep.
// console.warn(`[Bot AI] ${bot.name} has 0 cards in hand during Mulligan. Initializing?`);
}
if (!bot.handKept) {
try { engine.resolveMulligan(botId, true, []); } catch (e) { }
}

View File

@@ -245,7 +245,12 @@ export class TournamentManager extends EventEmitter {
// Update Player Deck in Tournament Roster
const player = t.players.find(p => p.id === playerId);
if (player) {
player.deck = deck;
if (deck && deck.length > 0) {
player.deck = deck;
} else if (!player.deck || player.deck.length === 0) {
// Only warn if we are missing a deck entirely
console.warn(`[Tournament] received empty deck for ${playerId}, and no previous deck found.`);
}
}
// Add to Ready