diff --git a/pages-game/game/minesweeper/play.vue b/pages-game/game/minesweeper/play.vue index 959c817..7400a31 100644 --- a/pages-game/game/minesweeper/play.vue +++ b/pages-game/game/minesweeper/play.vue @@ -615,7 +615,8 @@ export default { // 自动重连 try { console.log('[重连] 开始重新连接...'); - await nakamaManager.authenticateWithGameToken(this.gameToken); + const session = await nakamaManager.authenticateWithGameToken(this.gameToken, this.stableUserId); + this.myUserId = session.user_id; this.isConnected = true; console.log('[重连] 认证成功'); @@ -809,12 +810,42 @@ export default { this.addLog('system', '已切断匹配信号'); }, handleCellClick(idx) { - if (this.isSpectator) return; - // 增加 showResultModal || showSettlement 的拦截,防止结算后的“瞬时点击” - if (!this.gameState || !this.gameState.gameStarted || this.showResultModal || this.showSettlement) return; - if (!this.isMyTurn) return; - if (this.gameState.grid[idx].revealed) return; + console.log('[handleCellClick] 收到点击事件, 格子:', idx, 'isMyTurn:', this.isMyTurn); + if (this.isSpectator) { + console.warn('[点击拦截] 处于观众模式'); + return; + } + if (!this.gameState) { + console.warn('[点击拦截] 游戏数据未就绪'); + return; + } + if (!this.gameState.gameStarted) { + console.warn('[点击拦截] 游戏尚未开始'); + return; + } + if (this.showResultModal || this.showSettlement) { + console.warn('[点击拦截] 结算界面显示中'); + return; + } + if (!this.isMyTurn) { + const currentPlayerInTurn = this.gameState?.turnOrder?.[this.gameState?.currentTurnIndex]; + console.warn('[点击拦截] 非当前玩家回合', { + myUserId: this.myUserId, + currentTurnIndex: this.gameState?.currentTurnIndex, + turnOrder: this.gameState?.turnOrder, + currentPlayerInTurn, + isMyTurn: this.isMyTurn + }); + return; + } + if (this.gameState.grid[idx].revealed) { + console.warn('[点击拦截] 该格子已揭示', { idx, cell: this.gameState.grid[idx] }); + return; + } + + console.log(`[发送指令] 准备发送 - matchId: ${this.matchId}, OpCode: 3, 格子: ${idx}`); nakamaManager.sendMatchState(this.matchId, 3, JSON.stringify({ index: idx })); + console.log(`[发送指令] 已调用 sendMatchState`); }, refreshAndPlayAgain() { uni.removeStorageSync('minesweeper_last_match_id'); diff --git a/utils/nakamaManager.js b/utils/nakamaManager.js index 5074387..d26c336 100644 --- a/utils/nakamaManager.js +++ b/utils/nakamaManager.js @@ -356,10 +356,12 @@ class NakamaManager { */ sendMatchState(matchId, opCode, data) { const payload = typeof data === 'string' ? data : JSON.stringify(data); + const op = parseInt(opCode); + console.log(`[Nakama] Sending state: Match=${matchId}, OpCode=${op}`); this._sendNoResponse({ match_data_send: { match_id: matchId, - op_code: String(opCode), + op_code: op, data: this._base64Encode(payload) } });