diff --git a/src/matchWebsocket.js b/src/matchWebsocket.js index cf6d9c3..3b4d84a 100644 --- a/src/matchWebsocket.js +++ b/src/matchWebsocket.js @@ -40,12 +40,22 @@ const BUSINESS_TYPE_BY_SERVER_TYPE = { [ServerMessageType.SERVER_MSG_NEW_ROUND]: MESSAGETYPESV2.NewRound, [ServerMessageType.SERVER_MSG_MATCH_END]: MESSAGETYPESV2.BattleEnd, [ServerMessageType.SERVER_MSG_TIMEOUT]: MESSAGETYPESV2.BattleEnd, - [ServerMessageType.SERVER_MSG_CHECK]: MESSAGETYPESV2.InvalidShot, + [ServerMessageType.SERVER_MSG_CHECK]: MESSAGETYPESV2.TestDistance, [ServerMessageType.SERVER_MSG_NOT_ENOUGH_DISTANCE]: MESSAGETYPESV2.InvalidShot, }; const MATCH_READY_SNAPSHOT_PREFIX = "match-ready-snapshot:"; export const MATCH_WS_AUDIO_ACK_EVENT = "match-ws-audio-ack"; + +function normalizeShootData(shootData) { + if (!shootData || typeof shootData !== "object") return shootData; + const normalized = { ...shootData }; + if (normalized.distance === undefined && normalized.dst !== undefined) { + normalized.distance = normalized.dst; + } + return normalized; +} + // 兼容普通接口通知的 camelCase 和 protobuf 解码后的 snake_case。 function buildBusinessMessage(message) { const businessType = BUSINESS_TYPE_BY_SERVER_TYPE[message.type]; @@ -57,9 +67,10 @@ function buildBusinessMessage(message) { matchInfo.matchId || currentContext?.matchId ); - const shootData = + const shootData = normalizeShootData( matchInfo.shootData || - (message.shoot_data ? normalizePlainObject(message.shoot_data) : undefined); + (message.shoot_data ? normalizePlainObject(message.shoot_data) : undefined) + ); return { ...matchInfo, @@ -203,6 +214,12 @@ function getShootResultAudioKeys(shootData) { return keys; } +function getTestDistanceAudioKeys(shootData) { + const distance = Number(shootData?.distance ?? shootData?.dst); + if (Number.isNaN(distance)) return []; + return [distance / 100 >= 5 ? "\u8ddd\u79bb\u5408\u683c" : "\u8ddd\u79bb\u4e0d\u8db3"]; +} + function getAckAudioKeys(message, businessMessage) { switch (message.type) { case ServerMessageType.SERVER_MSG_MATCH_START: @@ -215,6 +232,7 @@ function getAckAudioKeys(message, businessMessage) { case ServerMessageType.SERVER_MSG_TIMEOUT: return ["比赛结束"]; case ServerMessageType.SERVER_MSG_CHECK: + return getTestDistanceAudioKeys(businessMessage?.shootData); case ServerMessageType.SERVER_MSG_NOT_ENOUGH_DISTANCE: return ["射击无效"]; default: diff --git a/src/pages/team-battle/index.vue b/src/pages/team-battle/index.vue index e9a37e5..d455359 100644 --- a/src/pages/team-battle/index.vue +++ b/src/pages/team-battle/index.vue @@ -1103,8 +1103,15 @@ async function runBattleEndTask(task, runId) { url: `/pages/friend-battle-result?battleId=${battleId.value}`, }); } else if (matchStatus.value === 4) { + const roomNumber = battleInfo.roomId || store.game.roomNumber || store.game.roomID; setTimeout(() => { - uni.navigateBack(); + if (roomNumber) { + uni.redirectTo({ + url: `/pages/battle-room?roomNumber=${encodeURIComponent(roomNumber)}&fromResult=1`, + }); + } else { + uni.navigateBack(); + } }, BATTLE_CANCEL_RETURN_DELAY); } }