feat: Implement solo draft mode with bot players and automated deck building.

This commit is contained in:
2025-12-20 14:48:06 +01:00
parent fd20c3cfb2
commit a3e45b13ce
7 changed files with 301 additions and 86 deletions

View File

@@ -7,6 +7,7 @@ interface Player {
deck?: any[];
socketId?: string; // Current or last known socket
isOffline?: boolean;
isBot?: boolean;
}
interface ChatMessage {
@@ -196,6 +197,45 @@ export class RoomManager {
return message;
}
addBot(roomId: string): Room | null {
const room = this.rooms.get(roomId);
if (!room) return null;
room.lastActive = Date.now();
// Check limits
if (room.players.length >= room.maxPlayers) return null;
const botNumber = room.players.filter(p => p.isBot).length + 1;
const botId = `bot-${Date.now()}-${Math.random().toString(36).substr(2, 5)}`;
const botPlayer: Player = {
id: botId,
name: `Bot ${botNumber}`,
isHost: false,
role: 'player',
ready: true, // Bots are always ready? Or host readies them? Let's say ready for now.
isOffline: false,
isBot: true
};
room.players.push(botPlayer);
return room;
}
removeBot(roomId: string, botId: string): Room | null {
const room = this.rooms.get(roomId);
if (!room) return null;
room.lastActive = Date.now();
const botIndex = room.players.findIndex(p => p.id === botId && p.isBot);
if (botIndex !== -1) {
room.players.splice(botIndex, 1);
return room;
}
return null;
}
getPlayerBySocket(socketId: string): { player: Player, room: Room } | null {
for (const room of this.rooms.values()) {
const player = room.players.find(p => p.socketId === socketId);