fix boss tank cross brick

This commit is contained in:
jakciehan
2026-06-07 22:08:00 +08:00
parent c3a4aa8f15
commit e4140f073f
29 changed files with 2689 additions and 1240 deletions
+20 -4
View File
@@ -169,6 +169,7 @@ const TEAM_RECONNECT_TIMEOUT = 60000; // 60s to reconnect
// ============================================================
const BATTLE_CONFIG = {
'1v1': { teamSize: 1, baseHp: 5, fillWithBots: false },
'2v2': { teamSize: 2, baseHp: 8, fillWithBots: true },
'3v3': { teamSize: 3, baseHp: 10, fillWithBots: true },
};
@@ -321,6 +322,11 @@ class TeamRoom {
return this.teamA.length >= this.teamSize;
}
/** Check if team B is full */
isTeamBFull() {
return this.teamB.length >= this.teamSize;
}
/** Check if both teams are full */
isFull() {
return this.teamA.length >= this.teamSize && this.teamB.length >= this.teamSize;
@@ -678,12 +684,15 @@ function handleCreateTeam(ws, data) {
handleLeaveTeam(ws, {});
}
// Read battleMode from client data, fall back to '3v3' if not provided
const battleMode = (data && data.battleMode) || '3v3';
const teamId = generateTeamId();
const teamRoom = new TeamRoom(teamId, ws, playerInfo.playerId, '3v3', playerInfo.nickname || '', playerInfo.avatarUrl || '', playerInfo.skinId || '');
const teamRoom = new TeamRoom(teamId, ws, playerInfo.playerId, battleMode, playerInfo.nickname || '', playerInfo.avatarUrl || '', playerInfo.skinId || '');
teamRooms.set(teamId, teamRoom);
playerInfo.teamId = teamId;
console.log(`[Server] Team ${teamId} created by ${playerInfo.playerId}`);
console.log(`[Server] Team ${teamId} created by ${playerInfo.playerId} (mode: ${battleMode})`);
sendMessage(ws, NET_MSG.TEAM_STATE, teamRoom.getTeamState());
}
@@ -703,7 +712,7 @@ function handleJoinTeam(ws, data) {
// Team was cleaned up (e.g. leader disconnected during dev-tool reload).
// Auto-create a new room with the same ID so the invite link still works.
console.log(`[Server] Team ${teamId} not found, auto-creating for ${playerInfo.playerId}`);
teamRoom = new TeamRoom(teamId, ws, playerInfo.playerId, '3v3', playerInfo.nickname || '', playerInfo.avatarUrl || '', playerInfo.skinId || '');
teamRoom = new TeamRoom(teamId, ws, playerInfo.playerId, (data && data.battleMode) || '3v3', playerInfo.nickname || '', playerInfo.avatarUrl || '', playerInfo.skinId || '');
teamRooms.set(teamId, teamRoom);
playerInfo.teamId = teamId;
sendMessage(ws, NET_MSG.TEAM_STATE, teamRoom.getTeamState());
@@ -926,9 +935,12 @@ function handleSoloMatch(ws, data) {
handleLeaveTeam(ws, {});
}
// Read battleMode from client data, fall back to '3v3' if not provided
const battleMode = (data && data.battleMode) || '3v3';
// Create a solo team room for this player
const teamId = generateTeamId();
const teamRoom = new TeamRoom(teamId, ws, playerInfo.playerId, '3v3', playerInfo.nickname || '', playerInfo.avatarUrl || '', playerInfo.skinId || '');
const teamRoom = new TeamRoom(teamId, ws, playerInfo.playerId, battleMode, playerInfo.nickname || '', playerInfo.avatarUrl || '', playerInfo.skinId || '');
teamRoom.state = 'matching';
teamRoom.matchStartTime = Date.now();
teamRooms.set(teamId, teamRoom);
@@ -1093,6 +1105,10 @@ function tryMatchTeams() {
gameRoom.fillWithBots();
console.log(`[Server] Solo players matched into team ${gameRoom.id}`);
// Send MATCH_FOUND to all players before starting the game
gameRoom.broadcast(NET_MSG.MATCH_FOUND, {});
startTeamGame(gameRoom);
}
}