update;优化比赛服
This commit is contained in:
+21
-3
@@ -40,12 +40,22 @@ const BUSINESS_TYPE_BY_SERVER_TYPE = {
|
|||||||
[ServerMessageType.SERVER_MSG_NEW_ROUND]: MESSAGETYPESV2.NewRound,
|
[ServerMessageType.SERVER_MSG_NEW_ROUND]: MESSAGETYPESV2.NewRound,
|
||||||
[ServerMessageType.SERVER_MSG_MATCH_END]: MESSAGETYPESV2.BattleEnd,
|
[ServerMessageType.SERVER_MSG_MATCH_END]: MESSAGETYPESV2.BattleEnd,
|
||||||
[ServerMessageType.SERVER_MSG_TIMEOUT]: 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,
|
[ServerMessageType.SERVER_MSG_NOT_ENOUGH_DISTANCE]: MESSAGETYPESV2.InvalidShot,
|
||||||
};
|
};
|
||||||
|
|
||||||
const MATCH_READY_SNAPSHOT_PREFIX = "match-ready-snapshot:";
|
const MATCH_READY_SNAPSHOT_PREFIX = "match-ready-snapshot:";
|
||||||
export const MATCH_WS_AUDIO_ACK_EVENT = "match-ws-audio-ack";
|
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。
|
// 兼容普通接口通知的 camelCase 和 protobuf 解码后的 snake_case。
|
||||||
function buildBusinessMessage(message) {
|
function buildBusinessMessage(message) {
|
||||||
const businessType = BUSINESS_TYPE_BY_SERVER_TYPE[message.type];
|
const businessType = BUSINESS_TYPE_BY_SERVER_TYPE[message.type];
|
||||||
@@ -57,9 +67,10 @@ function buildBusinessMessage(message) {
|
|||||||
matchInfo.matchId ||
|
matchInfo.matchId ||
|
||||||
currentContext?.matchId
|
currentContext?.matchId
|
||||||
);
|
);
|
||||||
const shootData =
|
const shootData = normalizeShootData(
|
||||||
matchInfo.shootData ||
|
matchInfo.shootData ||
|
||||||
(message.shoot_data ? normalizePlainObject(message.shoot_data) : undefined);
|
(message.shoot_data ? normalizePlainObject(message.shoot_data) : undefined)
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...matchInfo,
|
...matchInfo,
|
||||||
@@ -203,6 +214,12 @@ function getShootResultAudioKeys(shootData) {
|
|||||||
return keys;
|
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) {
|
function getAckAudioKeys(message, businessMessage) {
|
||||||
switch (message.type) {
|
switch (message.type) {
|
||||||
case ServerMessageType.SERVER_MSG_MATCH_START:
|
case ServerMessageType.SERVER_MSG_MATCH_START:
|
||||||
@@ -215,6 +232,7 @@ function getAckAudioKeys(message, businessMessage) {
|
|||||||
case ServerMessageType.SERVER_MSG_TIMEOUT:
|
case ServerMessageType.SERVER_MSG_TIMEOUT:
|
||||||
return ["比赛结束"];
|
return ["比赛结束"];
|
||||||
case ServerMessageType.SERVER_MSG_CHECK:
|
case ServerMessageType.SERVER_MSG_CHECK:
|
||||||
|
return getTestDistanceAudioKeys(businessMessage?.shootData);
|
||||||
case ServerMessageType.SERVER_MSG_NOT_ENOUGH_DISTANCE:
|
case ServerMessageType.SERVER_MSG_NOT_ENOUGH_DISTANCE:
|
||||||
return ["射击无效"];
|
return ["射击无效"];
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -1103,8 +1103,15 @@ async function runBattleEndTask(task, runId) {
|
|||||||
url: `/pages/friend-battle-result?battleId=${battleId.value}`,
|
url: `/pages/friend-battle-result?battleId=${battleId.value}`,
|
||||||
});
|
});
|
||||||
} else if (matchStatus.value === 4) {
|
} else if (matchStatus.value === 4) {
|
||||||
|
const roomNumber = battleInfo.roomId || store.game.roomNumber || store.game.roomID;
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
if (roomNumber) {
|
||||||
|
uni.redirectTo({
|
||||||
|
url: `/pages/battle-room?roomNumber=${encodeURIComponent(roomNumber)}&fromResult=1`,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
uni.navigateBack();
|
uni.navigateBack();
|
||||||
|
}
|
||||||
}, BATTLE_CANCEL_RETURN_DELAY);
|
}, BATTLE_CANCEL_RETURN_DELAY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user