From 1b2315b4eaf7171fcd774b5bc54cb2c458b58bb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=96=B9=E6=88=90?= Date: Sun, 4 Jan 2026 13:25:24 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E6=89=AB=E9=9B=B7?= =?UTF-8?q?=E6=B8=B8=E6=88=8F=E9=87=8D=E8=BF=9E=E8=AE=A4=E8=AF=81=E6=B5=81?= =?UTF-8?q?=E7=A8=8B=EF=BC=8C=E5=A2=9E=E5=BC=BA=E7=82=B9=E5=87=BB=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E6=8B=A6=E6=88=AA=E6=97=A5=E5=BF=97=EF=BC=8C=E5=B9=B6?= =?UTF-8?q?=E8=A7=84=E8=8C=83=20Nakama=20=E6=B6=88=E6=81=AF=E5=8F=91?= =?UTF-8?q?=E9=80=81=E7=9A=84=20op=5Fcode=20=E7=B1=BB=E5=9E=8B=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages-game/game/minesweeper/play.vue | 43 ++++++++++++++++++++++++---- utils/nakamaManager.js | 4 ++- 2 files changed, 40 insertions(+), 7 deletions(-) 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) } });