Compare commits
4
Commits
b8c5f3dd91
...
970a9874b4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
970a9874b4 | ||
|
|
f64a6b5c95 | ||
|
|
621397e25d | ||
|
|
fa7ad8f538 |
@@ -157,6 +157,10 @@ async function onReceiveMessage(msg) {
|
||||
key.push(arrow.ring ? `${arrow.ringX ? "X" : arrow.ring}环` : "未上靶");
|
||||
if (arrow.angle)
|
||||
key.push(`向${getDirectionText(arrow.angle)}调整`);
|
||||
const shouldPlayTententen =
|
||||
arrow.threeConsecutive10Rings === true ||
|
||||
msg.shootData?.threeConsecutive10Rings === true;
|
||||
if (!props.melee && shouldPlayTententen) key.push("tententen");
|
||||
audioManager.play(key, false);
|
||||
} else if (msg.type === MESSAGETYPESV2.HalfRest) {
|
||||
halfTime.value = true;
|
||||
|
||||
@@ -310,6 +310,9 @@ function getShootResultAudioKeys(shootData) {
|
||||
if (shootData.angle !== null && shootData.angle !== undefined) {
|
||||
keys.push(`向${getDirectionText(shootData.angle)}调整`);
|
||||
}
|
||||
if (shootData.threeConsecutive10Rings === true) {
|
||||
keys.push("tententen");
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
|
||||
+169
-10
@@ -1,6 +1,6 @@
|
||||
<script setup>
|
||||
import { ref, onMounted, computed, onBeforeUnmount } from "vue";
|
||||
import { onShow, onLoad, onShareAppMessage } from "@dcloudio/uni-app";
|
||||
import { onShow, onHide, onLoad, onShareAppMessage } from "@dcloudio/uni-app";
|
||||
import Container from "@/components/Container.vue";
|
||||
import PlayerSeats from "@/components/PlayerSeats.vue";
|
||||
import GuideTwo from "@/components/GuideTwo.vue";
|
||||
@@ -14,12 +14,14 @@ import {
|
||||
chooseTeamAPI,
|
||||
getReadyAPI,
|
||||
kickPlayerAPI,
|
||||
getBattleAPI,
|
||||
} from "@/apis";
|
||||
import { debounce, isLimitError } from "@/util";
|
||||
import { MESSAGETYPES, MESSAGETYPESV2 } from "@/constants";
|
||||
import useStore from "@/store";
|
||||
import { storeToRefs } from "pinia";
|
||||
import audioManager from "@/audioManager";
|
||||
import { returnToBattle } from "@/utils/matchReturn";
|
||||
const store = useStore();
|
||||
const { user } = storeToRefs(store);
|
||||
|
||||
@@ -74,17 +76,151 @@ const timer = ref(null);
|
||||
const goBattle = ref(false);
|
||||
const showLimitModal = ref(false);
|
||||
const readySubmitting = ref(false);
|
||||
const navigationPending = ref(false);
|
||||
let pageMounted = false;
|
||||
let pageVisible = false;
|
||||
let foregroundGeneration = 0;
|
||||
const MATCH_INFO_RETRY_DELAY_MS = 500;
|
||||
/** 从结算页返回时为 true,跳过进场靶纸语音 */
|
||||
const skipTargetAudio = ref(false);
|
||||
|
||||
const wait = (delay) =>
|
||||
new Promise((resolve) => {
|
||||
setTimeout(resolve, delay);
|
||||
});
|
||||
|
||||
const isCurrentForeground = (generation) =>
|
||||
pageMounted &&
|
||||
pageVisible &&
|
||||
generation === foregroundGeneration &&
|
||||
!navigationPending.value;
|
||||
|
||||
const redirectOnce = (url) =>
|
||||
new Promise((resolve, reject) => {
|
||||
if (navigationPending.value) {
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
|
||||
navigationPending.value = true;
|
||||
uni.redirectTo({
|
||||
url,
|
||||
success: resolve,
|
||||
fail: (error) => {
|
||||
navigationPending.value = false;
|
||||
goBattle.value = false;
|
||||
reject(error);
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
async function queryCurrentBattle(generation) {
|
||||
try {
|
||||
return await getBattleAPI();
|
||||
} catch (error) {
|
||||
await wait(MATCH_INFO_RETRY_DELAY_MS);
|
||||
if (!isCurrentForeground(generation)) throw error;
|
||||
return getBattleAPI();
|
||||
}
|
||||
}
|
||||
|
||||
async function returnToCurrentBattle(battle) {
|
||||
if (!battle?.matchId || navigationPending.value) return false;
|
||||
|
||||
goBattle.value = true;
|
||||
try {
|
||||
const returned = await returnToBattle(battle, redirectOnce);
|
||||
if (!returned) goBattle.value = false;
|
||||
return returned;
|
||||
} catch (error) {
|
||||
goBattle.value = false;
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async function reconcileBattleRoom(generation) {
|
||||
let battle = null;
|
||||
try {
|
||||
battle = await queryCurrentBattle(generation);
|
||||
} catch (error) {
|
||||
if (!isCurrentForeground(generation)) return;
|
||||
console.log("resume room match info error", error);
|
||||
uni.showToast({
|
||||
title: "比赛状态查询失败,请重试",
|
||||
icon: "none",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isCurrentForeground(generation)) return;
|
||||
if (battle?.matchId) {
|
||||
try {
|
||||
await returnToCurrentBattle(battle);
|
||||
} catch (error) {
|
||||
console.log("return to room battle error", error);
|
||||
uni.showToast({
|
||||
title: "进入比赛失败,请重试",
|
||||
icon: "none",
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
let roomStarted = false;
|
||||
try {
|
||||
roomStarted = await refreshRoomData();
|
||||
} catch (error) {
|
||||
if (isCurrentForeground(generation)) {
|
||||
console.log("refresh room data error", error);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isCurrentForeground(generation) || !roomStarted) return;
|
||||
|
||||
await wait(MATCH_INFO_RETRY_DELAY_MS);
|
||||
if (!isCurrentForeground(generation)) return;
|
||||
|
||||
try {
|
||||
battle = await queryCurrentBattle(generation);
|
||||
} catch (error) {
|
||||
if (!isCurrentForeground(generation)) return;
|
||||
console.log("retry room match info error", error);
|
||||
uni.showToast({
|
||||
title: "比赛状态查询失败,请重试",
|
||||
icon: "none",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isCurrentForeground(generation)) return;
|
||||
if (battle?.matchId) {
|
||||
try {
|
||||
await returnToCurrentBattle(battle);
|
||||
} catch (error) {
|
||||
console.log("return to room battle error", error);
|
||||
uni.showToast({
|
||||
title: "进入比赛失败,请重试",
|
||||
icon: "none",
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
uni.showToast({
|
||||
title: "比赛正在创建,请稍候",
|
||||
icon: "none",
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 从服务端刷新当前房间数据,更新成员列表、准备状态等信息
|
||||
* 仅在 roomNumber 有效且房间未开始时执行
|
||||
*/
|
||||
async function refreshRoomData() {
|
||||
if (!roomNumber.value) return;
|
||||
if (!roomNumber.value) return false;
|
||||
const result = await getRoomAPI(roomNumber.value);
|
||||
if (result.started) return;
|
||||
if (result.started) return true;
|
||||
room.value = result;
|
||||
// 加入者通过 API 返回的 targetType 字段同步靶纸尺寸,并持久化到本地缓存
|
||||
if (result.targetType) {
|
||||
@@ -158,6 +294,7 @@ async function refreshRoomData() {
|
||||
}
|
||||
if (timer.value) clearInterval(timer.value);
|
||||
// timer.value = setTimeout(refreshRoomData, 2000);
|
||||
return false;
|
||||
}
|
||||
|
||||
const getReady = debounce(async () => {
|
||||
@@ -239,17 +376,22 @@ async function onReceiveMessage(message) {
|
||||
}
|
||||
});
|
||||
} else if (message.type === MESSAGETYPESV2.AboutToStart) {
|
||||
if (navigationPending.value) return;
|
||||
const matchId = message.matchId || message.id;
|
||||
if (!matchId) return;
|
||||
goBattle.value = true;
|
||||
let url = "";
|
||||
if (message.mode <= 3) {
|
||||
uni.setStorageSync("blue-team", message.teams[1].players || []);
|
||||
uni.setStorageSync("red-team", message.teams[2].players || []);
|
||||
uni.redirectTo({
|
||||
url: "/pages/team-battle/index?battleId=" + message.matchId,
|
||||
});
|
||||
url = "/pages/team-battle/index?battleId=" + matchId;
|
||||
} else {
|
||||
uni.redirectTo({
|
||||
url: "/pages/melee-battle?battleId=" + message.matchId,
|
||||
});
|
||||
url = "/pages/melee-battle?battleId=" + matchId;
|
||||
}
|
||||
try {
|
||||
await redirectOnce(url);
|
||||
} catch (error) {
|
||||
console.log("redirect to room battle error", error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -344,7 +486,15 @@ onShareAppMessage(() => {
|
||||
*/
|
||||
onShow(() => {
|
||||
goBattle.value = false;
|
||||
refreshRoomData();
|
||||
navigationPending.value = false;
|
||||
pageVisible = true;
|
||||
const generation = ++foregroundGeneration;
|
||||
if (pageMounted) void reconcileBattleRoom(generation);
|
||||
});
|
||||
|
||||
onHide(() => {
|
||||
pageVisible = false;
|
||||
foregroundGeneration += 1;
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -368,6 +518,10 @@ onLoad(async (options) => {
|
||||
const stored = uni.getStorageSync(`targetSize_${roomNumber.value}`);
|
||||
if (stored) targetSize.value = stored;
|
||||
}
|
||||
if (pageMounted && pageVisible) {
|
||||
const generation = ++foregroundGeneration;
|
||||
void reconcileBattleRoom(generation);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -379,6 +533,8 @@ onMounted(() => {
|
||||
keepScreenOn: true,
|
||||
});
|
||||
uni.$on("socket-inbox", onReceiveMessage);
|
||||
pageMounted = true;
|
||||
if (pageVisible) void reconcileBattleRoom(foregroundGeneration);
|
||||
// 页面加载完成 1 秒后根据靶纸尺寸播报对应语音;从结算页返回时跳过
|
||||
setTimeout(() => {
|
||||
if (!skipTargetAudio.value) {
|
||||
@@ -389,6 +545,9 @@ onMounted(() => {
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
pageMounted = false;
|
||||
pageVisible = false;
|
||||
foregroundGeneration += 1;
|
||||
uni.setKeepScreenOn({
|
||||
keepScreenOn: false,
|
||||
});
|
||||
|
||||
@@ -27,6 +27,8 @@ const data = ref({});
|
||||
const showOverlay = ref(false);
|
||||
/** 自动关闭覆盖层的计时器 */
|
||||
const overlayTimer = ref(null);
|
||||
const overlayDelayTimer = ref(null);
|
||||
let loadGeneration = 0;
|
||||
/** 控制经验条是否执行进场动画(弹窗关闭后才置 true,避免动画被遮挡) */
|
||||
const showExpAnim = ref(false);
|
||||
|
||||
@@ -83,6 +85,13 @@ const mvpPlayer = computed(() => {
|
||||
return null;
|
||||
});
|
||||
|
||||
const mvpTotalRing = computed(
|
||||
() =>
|
||||
mvpPlayer.value?.playerMatchResult?.totalRing ??
|
||||
mvpPlayer.value?.totalRing ??
|
||||
0
|
||||
);
|
||||
|
||||
/**
|
||||
* MVP 玩家所在队伍编号(1=蓝队,2=红队)
|
||||
* 通过比对 mvpPlayer.id 与 blueTeamPlayers 确定,用于选择背景图(mvp-blue / mvp-red)
|
||||
@@ -175,9 +184,11 @@ function getMeleeAvatarBorderColor(rank) {
|
||||
// ---- 生命周期 ----
|
||||
|
||||
onLoad(async (options) => {
|
||||
const currentLoadId = ++loadGeneration;
|
||||
if (!options.battleId) return;
|
||||
|
||||
const result = await getBattleAPI(options.battleId);
|
||||
if (currentLoadId !== loadGeneration) return;
|
||||
data.value = result;
|
||||
|
||||
// 从 teams 各队伍的 players 中找到当前用户,解析经验进度条所需字段
|
||||
@@ -219,7 +230,8 @@ onLoad(async (options) => {
|
||||
}
|
||||
|
||||
// 数据加载完成后延迟 1 秒再显示激励弹窗,避免进场时画面太杂
|
||||
setTimeout(() => {
|
||||
overlayDelayTimer.value = setTimeout(() => {
|
||||
overlayDelayTimer.value = null;
|
||||
showOverlay.value = true;
|
||||
// 弹窗显示后 2.5 秒自动关闭
|
||||
overlayTimer.value = setTimeout(() => {
|
||||
@@ -229,7 +241,15 @@ onLoad(async (options) => {
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
if (overlayTimer.value) clearTimeout(overlayTimer.value);
|
||||
loadGeneration += 1;
|
||||
if (overlayDelayTimer.value) {
|
||||
clearTimeout(overlayDelayTimer.value);
|
||||
overlayDelayTimer.value = null;
|
||||
}
|
||||
if (overlayTimer.value) {
|
||||
clearTimeout(overlayTimer.value);
|
||||
overlayTimer.value = null;
|
||||
}
|
||||
});
|
||||
|
||||
// ---- 方法 ----
|
||||
@@ -411,7 +431,7 @@ function goBack() {
|
||||
<view class="mvp-info">
|
||||
<image class="mvp-badge" src="https://static.shelingxingqiu.com/shootmini/static/mvp-tip.png" mode="widthFix" />
|
||||
<view class="mvp-rings">
|
||||
斩获<text class="mvp-rings-num">{{ mvpPlayer.totalRing }}</text>环
|
||||
斩获<text class="mvp-rings-num">{{ mvpTotalRing }}</text>环
|
||||
</view>
|
||||
</view>
|
||||
<!-- 右:MVP 头像 + 名字,边框颜色跟随 MVP 所在队伍 -->
|
||||
|
||||
+130
-46
@@ -8,18 +8,23 @@ import audioManager from "@/audioManager";
|
||||
import { matchGameAPI, getBattleAPI } from "@/apis";
|
||||
import { MESSAGETYPESV2 } from "@/constants";
|
||||
import { isLimitError } from "@/util";
|
||||
import { returnToBattle } from "@/utils/matchReturn";
|
||||
|
||||
const gameType = ref(0);
|
||||
const teamSize = ref(0);
|
||||
const onComplete = ref(null);
|
||||
const showLimitModal = ref(false);
|
||||
const MATCH_READY_SNAPSHOT_PREFIX = "match-ready-snapshot:";
|
||||
const navigationPending = ref(false);
|
||||
let pageMounted = false;
|
||||
let pageVisible = false;
|
||||
let foregroundGeneration = 0;
|
||||
|
||||
/** 匹配超时计时器,用于检测 WS 消息丢失或真正超时 */
|
||||
const matchTimeoutTimer = ref(null);
|
||||
|
||||
/** 匹配超时阈值(ms),后端设置 15s 匹配,前端预留 5s 冗余 */
|
||||
const MATCH_TIMEOUT_MS = 20 * 1000;
|
||||
const MATCH_INFO_RETRY_DELAY_MS = 500;
|
||||
|
||||
/** 清除超时计时器 */
|
||||
const clearMatchTimeout = () => {
|
||||
@@ -29,16 +34,97 @@ const clearMatchTimeout = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const cacheReadyBattle = (battle) => {
|
||||
const matchId = String(battle?.matchId || "");
|
||||
if (!matchId) return;
|
||||
|
||||
uni.setStorageSync(`${MATCH_READY_SNAPSHOT_PREFIX}${matchId}`, {
|
||||
...battle,
|
||||
status: battle.status == null ? 0 : Number(battle.status),
|
||||
savedAt: Date.now(),
|
||||
const wait = (delay) =>
|
||||
new Promise((resolve) => {
|
||||
setTimeout(resolve, delay);
|
||||
});
|
||||
};
|
||||
|
||||
const isCurrentForeground = (generation) =>
|
||||
pageMounted &&
|
||||
pageVisible &&
|
||||
generation === foregroundGeneration &&
|
||||
!navigationPending.value;
|
||||
|
||||
const redirectOnce = (url) =>
|
||||
new Promise((resolve, reject) => {
|
||||
if (navigationPending.value) {
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
|
||||
navigationPending.value = true;
|
||||
clearMatchTimeout();
|
||||
uni.redirectTo({
|
||||
url,
|
||||
success: resolve,
|
||||
fail: (error) => {
|
||||
navigationPending.value = false;
|
||||
reject(error);
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
async function queryCurrentBattle(generation) {
|
||||
try {
|
||||
return await getBattleAPI();
|
||||
} catch (error) {
|
||||
await wait(MATCH_INFO_RETRY_DELAY_MS);
|
||||
if (!isCurrentForeground(generation)) throw error;
|
||||
return getBattleAPI();
|
||||
}
|
||||
}
|
||||
|
||||
async function returnToCurrentBattle(battle) {
|
||||
if (!battle?.matchId || navigationPending.value) return false;
|
||||
return returnToBattle(battle, redirectOnce);
|
||||
}
|
||||
|
||||
async function reconcileMatchingPage(generation) {
|
||||
clearMatchTimeout();
|
||||
|
||||
let battle = null;
|
||||
try {
|
||||
battle = await queryCurrentBattle(generation);
|
||||
} catch (error) {
|
||||
if (!isCurrentForeground(generation)) return;
|
||||
console.log("resume match info error", error);
|
||||
uni.showToast({
|
||||
title: "比赛状态查询失败,请重试",
|
||||
icon: "none",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isCurrentForeground(generation)) return;
|
||||
if (battle?.matchId) {
|
||||
try {
|
||||
await returnToCurrentBattle(battle);
|
||||
} catch (error) {
|
||||
console.log("return to current match error", error);
|
||||
uni.showToast({
|
||||
title: "进入比赛失败,请重试",
|
||||
icon: "none",
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!gameType.value || !teamSize.value) return;
|
||||
|
||||
try {
|
||||
await matchGameAPI(true, gameType.value, teamSize.value);
|
||||
if (!isCurrentForeground(generation)) return;
|
||||
matchTimeoutTimer.value = setTimeout(handleMatchTimeout, MATCH_TIMEOUT_MS);
|
||||
} catch (error) {
|
||||
if (!isCurrentForeground(generation)) return;
|
||||
clearMatchTimeout();
|
||||
if (isLimitError(error)) {
|
||||
showLimitModal.value = true;
|
||||
return;
|
||||
}
|
||||
uni.navigateBack();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 超时处理:查询后端是否已分配对局
|
||||
@@ -46,16 +132,12 @@ const cacheReadyBattle = (battle) => {
|
||||
* - 无对局 → 真正超时,提示用户并返回大厅
|
||||
*/
|
||||
const handleMatchTimeout = async () => {
|
||||
if (!pageVisible || navigationPending.value) return;
|
||||
try {
|
||||
const battle = await getBattleAPI();
|
||||
if (battle && battle.matchId) {
|
||||
cacheReadyBattle(battle);
|
||||
uni.showToast({ title: "匹配成功,正在进入...", icon: "none" });
|
||||
if (battle.mode <= 3) {
|
||||
uni.redirectTo({ url: `/pages/team-battle/index?battleId=${battle.matchId}` });
|
||||
} else {
|
||||
uni.redirectTo({ url: `/pages/melee-battle?battleId=${battle.matchId}` });
|
||||
}
|
||||
await returnToCurrentBattle(battle);
|
||||
} else {
|
||||
uni.showToast({ title: "匹配超时,请重试", icon: "none" });
|
||||
try {
|
||||
@@ -93,6 +175,8 @@ const goVipPage = () => {
|
||||
* - 取消失败(后端已分配对局但 WS 未到达)→ 查询并跳入当前对局
|
||||
*/
|
||||
async function cancelMatch() {
|
||||
if (navigationPending.value) return;
|
||||
foregroundGeneration += 1;
|
||||
clearMatchTimeout();
|
||||
try {
|
||||
if (gameType.value && teamSize.value) {
|
||||
@@ -104,11 +188,7 @@ async function cancelMatch() {
|
||||
try {
|
||||
const battle = await getBattleAPI();
|
||||
if (battle && battle.matchId) {
|
||||
if (battle.mode <= 3) {
|
||||
uni.redirectTo({ url: `/pages/team-battle/index?battleId=${battle.matchId}` });
|
||||
} else {
|
||||
uni.redirectTo({ url: `/pages/melee-battle?battleId=${battle.matchId}` });
|
||||
}
|
||||
await returnToCurrentBattle(battle);
|
||||
} else {
|
||||
uni.navigateBack();
|
||||
}
|
||||
@@ -123,18 +203,21 @@ async function onReceiveMessage(msg) {
|
||||
onComplete.value = () => {}
|
||||
}
|
||||
if (msg.type === MESSAGETYPESV2.AboutToStart) {
|
||||
if (navigationPending.value) return;
|
||||
// 收到开始消息,清除超时计时器
|
||||
clearMatchTimeout();
|
||||
// 使用后端下发的 mode 字段判断跳转目标,与好友约战(battle-room.vue)保持一致
|
||||
// mode <= 3 为团队对抗,mode > 3 为大乱斗,覆盖全部 gameType(1~5),不再遗漏
|
||||
if (msg.mode <= 3) {
|
||||
uni.redirectTo({
|
||||
url: `/pages/team-battle/index?battleId=${msg.id}`,
|
||||
});
|
||||
} else {
|
||||
uni.redirectTo({
|
||||
url: `/pages/melee-battle?battleId=${msg.id}`,
|
||||
});
|
||||
const matchId = msg.matchId || msg.id;
|
||||
if (!matchId) return;
|
||||
const url =
|
||||
msg.mode <= 3
|
||||
? `/pages/team-battle/index?battleId=${matchId}`
|
||||
: `/pages/melee-battle?battleId=${matchId}`;
|
||||
try {
|
||||
await redirectOnce(url);
|
||||
} catch (error) {
|
||||
console.log("redirect to matched battle error", error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -144,6 +227,10 @@ onLoad(async (options) => {
|
||||
gameType.value = options.gameType;
|
||||
teamSize.value = options.teamSize;
|
||||
}
|
||||
if (pageMounted && pageVisible) {
|
||||
const generation = ++foregroundGeneration;
|
||||
void reconcileMatchingPage(generation);
|
||||
}
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
@@ -153,9 +240,14 @@ onMounted(() => {
|
||||
});
|
||||
uni.$on("socket-inbox", onReceiveMessage);
|
||||
uni.$on("cancelMatching", cancelMatch);
|
||||
pageMounted = true;
|
||||
if (pageVisible) void reconcileMatchingPage(foregroundGeneration);
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
pageMounted = false;
|
||||
pageVisible = false;
|
||||
foregroundGeneration += 1;
|
||||
clearMatchTimeout();
|
||||
uni.setKeepScreenOn({
|
||||
keepScreenOn: false,
|
||||
@@ -164,26 +256,18 @@ onBeforeUnmount(() => {
|
||||
uni.$off("cancelMatching", cancelMatch);
|
||||
});
|
||||
|
||||
onShow(async () => {
|
||||
if (gameType.value && teamSize.value) {
|
||||
try {
|
||||
await matchGameAPI(true, gameType.value, teamSize.value);
|
||||
// 启动超时计时器,防止 WS 消息丢失或长时间无对手导致用户卡死
|
||||
clearMatchTimeout();
|
||||
matchTimeoutTimer.value = setTimeout(handleMatchTimeout, MATCH_TIMEOUT_MS);
|
||||
} catch (error) {
|
||||
clearMatchTimeout();
|
||||
if (isLimitError(error)) {
|
||||
showLimitModal.value = true;
|
||||
return;
|
||||
}
|
||||
uni.navigateBack();
|
||||
}
|
||||
}
|
||||
onShow(() => {
|
||||
pageVisible = true;
|
||||
navigationPending.value = false;
|
||||
const generation = ++foregroundGeneration;
|
||||
clearMatchTimeout();
|
||||
if (pageMounted) void reconcileMatchingPage(generation);
|
||||
});
|
||||
|
||||
onHide(() => {
|
||||
|
||||
pageVisible = false;
|
||||
foregroundGeneration += 1;
|
||||
clearMatchTimeout();
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
@@ -52,8 +52,6 @@ const readyTime = ref(DEFAULT_READY_TIME);
|
||||
let halfRestTimer = null;
|
||||
/** 控制设备离线提示弹窗的显示状态 */
|
||||
const showOfflineModal = ref(false);
|
||||
/** 记录每位玩家当前半场连续 10 环及以上次数,key 为 playerId,用于触发 tententen 音效 */
|
||||
const xRingStreaks = ref({});
|
||||
let battleEnded = false;
|
||||
let skipNextRestoreOnShow = false;
|
||||
let restoreGeneration = 0;
|
||||
@@ -319,7 +317,8 @@ function recoverData(battleInfo, { force = false } = {}) {
|
||||
}
|
||||
leaveHalfRest();
|
||||
if (force) {
|
||||
const remain = (Date.now() - (battleInfo.current?.startTime || Date.now())) / 1000;
|
||||
const ackTime = normalizeTimestamp(battleInfo.current?.ackTime);
|
||||
const remain = ackTime ? Math.max(0, (Date.now() - ackTime) / 1000) : 0;
|
||||
console.log(`当前轮已进行${remain}秒`);
|
||||
if (remain > 0 && remain < 90) {
|
||||
setTimeout(() => {
|
||||
@@ -398,32 +397,6 @@ onLoad(async (options) => {
|
||||
// });
|
||||
});
|
||||
|
||||
/**
|
||||
* 检测指定玩家连续 10 环及以上是否达到 3 箭,达到则在环数播报入队后追加 tententen 音效
|
||||
* @param {number|string} playerId - 本次射手的 ID(大乱斗中 ShootResult 保留 playerId)
|
||||
* @param {boolean} isTenPlusRingShot - 本次射击是否为 10 环及以上
|
||||
*/
|
||||
function isTenPlusRing(shot) {
|
||||
return !!(shot?.ringX || Number(shot?.ring) >= 10);
|
||||
}
|
||||
|
||||
function checkAndPlayTententen(playerId, isTenPlusRingShot) {
|
||||
if (!playerId) return;
|
||||
const id = parseInt(playerId);
|
||||
if (isTenPlusRingShot) {
|
||||
xRingStreaks.value[id] = (xRingStreaks.value[id] || 0) + 1;
|
||||
// 同一玩家连续 3 箭均为 10 环及以上,追加到环数音效队列尾部播放
|
||||
if (xRingStreaks.value[id] >= 3) {
|
||||
xRingStreaks.value[id] = 0;
|
||||
// nextTick 确保 HeaderProgress 的环数播报已入队后再追加 tententen,避免播放顺序颠倒
|
||||
nextTick(() => audioManager.play("tententen", false));
|
||||
}
|
||||
} else {
|
||||
// 低于 10 环或未上靶则重置该玩家的连续计数
|
||||
xRingStreaks.value[id] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
async function onReceiveMessage(msg) {
|
||||
if (Array.isArray(msg)) return;
|
||||
if (msg.type === MESSAGETYPESV2.AboutToStart) {
|
||||
@@ -432,28 +405,10 @@ async function onReceiveMessage(msg) {
|
||||
leaveHalfRest();
|
||||
recoverData(msg);
|
||||
} else if (msg.type === MESSAGETYPESV2.ShootResult) {
|
||||
// 更新前快照各玩家本轮已射箭数,用于事后识别本次射手
|
||||
const curRound = playersScores.value[playersScores.value.length - 1] || {};
|
||||
const prevCounts = {};
|
||||
for (const pid of Object.keys(curRound)) {
|
||||
prevCounts[pid] = (curRound[pid] || []).length;
|
||||
}
|
||||
recoverData(msg);
|
||||
// 对比更新后数据找出箭数增加的玩家(即本次射手),并读取其最新箭的 ring 数据
|
||||
const newRound = playersScores.value[playersScores.value.length - 1] || {};
|
||||
let shooterId = null;
|
||||
let isTenPlusRingShot = false;
|
||||
for (const pid of Object.keys(newRound)) {
|
||||
const newLen = (newRound[pid] || []).length;
|
||||
if (newLen > (prevCounts[pid] || 0)) {
|
||||
shooterId = parseInt(pid);
|
||||
const shot = newRound[pid][newLen - 1];
|
||||
isTenPlusRingShot = isTenPlusRing(shot);
|
||||
break;
|
||||
}
|
||||
if (msg.shootData?.threeConsecutive10Rings === true) {
|
||||
nextTick(() => audioManager.play("tententen", false));
|
||||
}
|
||||
// 检测同一玩家连续三箭 10 环及以上,触发 tententen 音效
|
||||
checkAndPlayTententen(shooterId, isTenPlusRingShot);
|
||||
} else if (msg.type === MESSAGETYPESV2.HalfRest) {
|
||||
halfTimeTip.value = true;
|
||||
halfRest.value = true;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup>
|
||||
import { ref, onMounted, onBeforeUnmount, nextTick } from "vue";
|
||||
import { ref, onMounted, onBeforeUnmount } from "vue";
|
||||
import { onLoad } from "@dcloudio/uni-app";
|
||||
import Container from "@/components/Container.vue";
|
||||
import ShootProgress from "@/components/ShootProgress.vue";
|
||||
@@ -33,8 +33,6 @@ const start = ref(false);
|
||||
const scores = ref([]);
|
||||
const isSvip = ref(false);
|
||||
const total = 12;
|
||||
/** 当前练习中连续 10 环及以上计数,用于触发 tententen 音效 */
|
||||
const xRingStreak = ref(0);
|
||||
const practiseResult = ref({});
|
||||
const practiseId = ref("");
|
||||
const showGuide = ref(false);
|
||||
@@ -91,7 +89,6 @@ const onReady = async () => {
|
||||
if (!result) return;
|
||||
scores.value = [];
|
||||
isSvip.value = false;
|
||||
xRingStreak.value = 0; // 新一局开始,重置 X 环连续计数
|
||||
start.value = true;
|
||||
audioManager.play("练习开始");
|
||||
};
|
||||
@@ -103,38 +100,10 @@ const onOver = async (message) => {
|
||||
start.value = false;
|
||||
};
|
||||
|
||||
/**
|
||||
* 检测连续 10 环及以上是否达到 3 箭,达到则播放 tententen 音效
|
||||
* @param {boolean} isTenPlusRingShot - 本次射击是否为 10 环及以上
|
||||
*/
|
||||
function isTenPlusRing(shot) {
|
||||
return !!(shot?.ringX || Number(shot?.ring) >= 10);
|
||||
}
|
||||
|
||||
function checkAndPlayTententen(isTenPlusRingShot) {
|
||||
if (isTenPlusRingShot) {
|
||||
xRingStreak.value += 1;
|
||||
// 连续 3 箭均为 10 环及以上,在环数播报入队后追加 tententen,避免播放顺序颠倒
|
||||
if (xRingStreak.value >= 3) {
|
||||
xRingStreak.value = 0;
|
||||
nextTick(() => audioManager.play("tententen", false));
|
||||
}
|
||||
} else {
|
||||
// 低于 10 环或未上靶则重置连续计数
|
||||
xRingStreak.value = 0;
|
||||
}
|
||||
}
|
||||
|
||||
async function onReceiveMessage(msg) {
|
||||
if (msg.type === MESSAGETYPESV2.ShootResult) {
|
||||
const prevLen = scores.value.length;
|
||||
isSvip.value = msg.sVip === true;
|
||||
scores.value = Array.isArray(msg.details) ? msg.details : scores.value;
|
||||
// 有新箭时取最后一箭判断是否 10 环及以上并检测连续计数
|
||||
if (scores.value.length > prevLen) {
|
||||
const latestArrow = scores.value[scores.value.length - 1];
|
||||
checkAndPlayTententen(isTenPlusRing(latestArrow));
|
||||
}
|
||||
} else if (msg.type === MESSAGETYPESV2.BattleEnd) {
|
||||
setTimeout(() => onOver(msg), 1500);
|
||||
}
|
||||
@@ -152,7 +121,6 @@ async function onComplete() {
|
||||
start.value = false;
|
||||
scores.value = [];
|
||||
isSvip.value = false;
|
||||
xRingStreak.value = 0; // 重新开始练习,重置 X 环连续计数
|
||||
await createPractise();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup>
|
||||
import { ref, onMounted, onBeforeUnmount, nextTick } from "vue";
|
||||
import { ref, onMounted, onBeforeUnmount } from "vue";
|
||||
import Container from "@/components/Container.vue";
|
||||
import ShootProgress from "@/components/ShootProgress.vue";
|
||||
import BowTarget from "@/components/BowTarget.vue";
|
||||
@@ -33,8 +33,6 @@ const start = ref(false);
|
||||
const scores = ref([]);
|
||||
const isSvip = ref(false);
|
||||
const total = 36;
|
||||
/** 当前练习中连续 10 环及以上计数,用于触发 tententen 音效 */
|
||||
const xRingStreak = ref(0);
|
||||
const practiseResult = ref({});
|
||||
const practiseId = ref("");
|
||||
const showGuide = ref(false);
|
||||
@@ -90,7 +88,6 @@ const onReady = async () => {
|
||||
if (!result) return;
|
||||
scores.value = [];
|
||||
isSvip.value = false;
|
||||
xRingStreak.value = 0; // 新一局开始,重置 X 环连续计数
|
||||
start.value = true;
|
||||
audioManager.play("练习开始");
|
||||
};
|
||||
@@ -102,38 +99,10 @@ const onOver = async (message) => {
|
||||
start.value = false;
|
||||
};
|
||||
|
||||
/**
|
||||
* 检测连续 10 环及以上是否达到 3 箭,达到则播放 tententen 音效
|
||||
* @param {boolean} isTenPlusRingShot - 本次射击是否为 10 环及以上
|
||||
*/
|
||||
function isTenPlusRing(shot) {
|
||||
return !!(shot?.ringX || Number(shot?.ring) >= 10);
|
||||
}
|
||||
|
||||
function checkAndPlayTententen(isTenPlusRingShot) {
|
||||
if (isTenPlusRingShot) {
|
||||
xRingStreak.value += 1;
|
||||
// 连续 3 箭均为 10 环及以上,在环数播报入队后追加 tententen,避免播放顺序颠倒
|
||||
if (xRingStreak.value >= 3) {
|
||||
xRingStreak.value = 0;
|
||||
nextTick(() => audioManager.play("tententen", false));
|
||||
}
|
||||
} else {
|
||||
// 低于 10 环或未上靶则重置连续计数
|
||||
xRingStreak.value = 0;
|
||||
}
|
||||
}
|
||||
|
||||
async function onReceiveMessage(msg) {
|
||||
if (msg.type === MESSAGETYPESV2.ShootResult) {
|
||||
const prevLen = scores.value.length;
|
||||
isSvip.value = msg.sVip === true;
|
||||
scores.value = Array.isArray(msg.details) ? msg.details : scores.value;
|
||||
// 有新箭时取最后一箭判断是否 10 环及以上并检测连续计数
|
||||
if (scores.value.length > prevLen) {
|
||||
const latestArrow = scores.value[scores.value.length - 1];
|
||||
checkAndPlayTententen(isTenPlusRing(latestArrow));
|
||||
}
|
||||
} else if (msg.type === MESSAGETYPESV2.BattleEnd) {
|
||||
setTimeout(() => onOver(msg), 1500);
|
||||
}
|
||||
@@ -167,7 +136,6 @@ async function onComplete() {
|
||||
start.value = false;
|
||||
scores.value = [];
|
||||
isSvip.value = false;
|
||||
xRingStreak.value = 0; // 重新开始练习,重置 X 环连续计数
|
||||
await createPractise();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,8 +49,6 @@ const battleWay = ref(0);
|
||||
const lastToSomeoneShootKey = ref("");
|
||||
/** 控制设备离线提示弹窗的显示状态 */
|
||||
const showOfflineModal = ref(false);
|
||||
/** 记录每位玩家当前轮连续 10 环及以上次数,key 为 playerId,用于触发 tententen 音效 */
|
||||
const xRingStreaks = ref({});
|
||||
|
||||
/**
|
||||
* 监听设备在线状态,比赛进行中设备离线时弹窗提示用户
|
||||
@@ -233,31 +231,6 @@ function onNewRound(msg, prevRound) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测指定射手连续 10 环及以上是否达到 3 箭,达到则在环数播报入队后追加 tententen 音效
|
||||
* @param {number} shooterId - 本次射手的 ID(取自 currentShooterId.value)
|
||||
* @param {boolean} isTenPlusRingShot - 本次射击是否为 10 环及以上
|
||||
*/
|
||||
function isTenPlusRing(shot) {
|
||||
return !!(shot?.ringX || Number(shot?.ring) >= 10);
|
||||
}
|
||||
|
||||
function checkAndPlayTententen(shooterId, isTenPlusRingShot) {
|
||||
if (!shooterId) return;
|
||||
if (isTenPlusRingShot) {
|
||||
xRingStreaks.value[shooterId] = (xRingStreaks.value[shooterId] || 0) + 1;
|
||||
// 同一玩家连续 3 箭均为 10 环及以上,追加到环数音效队列尾部播放
|
||||
if (xRingStreaks.value[shooterId] >= 3) {
|
||||
xRingStreaks.value[shooterId] = 0;
|
||||
// nextTick 确保 HeaderProgress 的环数播报已入队后再追加 tententen,避免播放顺序颠倒
|
||||
nextTick(() => audioManager.play("tententen", false));
|
||||
}
|
||||
} else {
|
||||
// 低于 10 环或未上靶则重置该玩家的连续计数
|
||||
xRingStreaks.value[shooterId] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
async function onReceiveMessage(msg) {
|
||||
if (Array.isArray(msg)) return;
|
||||
if (msg.type === MESSAGETYPESV2.BattleStart) {
|
||||
@@ -272,9 +245,9 @@ async function onReceiveMessage(msg) {
|
||||
} else if (msg.type === MESSAGETYPESV2.ShootResult) {
|
||||
showRoundTip.value = false;
|
||||
recoverData(msg, {arrowOnly: true});
|
||||
// 检测同一玩家连续三箭 10 环及以上,触发 tententen 音效
|
||||
// currentShooterId 在 ToSomeoneShoot 时写入,ShootResult 不会覆盖,可靠识别本次射手
|
||||
checkAndPlayTententen(currentShooterId.value, isTenPlusRing(msg.shootData));
|
||||
if (msg.shootData?.threeConsecutive10Rings === true) {
|
||||
nextTick(() => audioManager.play("tententen", false));
|
||||
}
|
||||
} else if (msg.type === MESSAGETYPESV2.NewRound) {
|
||||
// 在进入延迟前先捕获当前轮次,供 onNewRound 使用,防止 800ms 内 ToSomeoneShoot 提前更新 currentRound 造成 Tip 展示错轮
|
||||
const prevRound = currentRound.value;
|
||||
|
||||
@@ -48,7 +48,6 @@ const AUDIO_TIMEOUT_PER_KEY = 2600;
|
||||
const AUDIO_TIMEOUT_MAX = 12000;
|
||||
const BATTLE_CANCEL_RETURN_DELAY = 2000;
|
||||
const ROUND_AUDIO_NAMES = ["一", "二", "三", "四", "五"];
|
||||
const X_RING_STREAKS_KEY = "team-battle-x-ring-streaks";
|
||||
const MATCH_READY_SNAPSHOT_PREFIX = "match-ready-snapshot:";
|
||||
const MATCH_STATUS_BY_TEXT = {
|
||||
MATCH_STATUS_READY: 0,
|
||||
@@ -85,7 +84,6 @@ const shootTimeTotal = ref(DEFAULT_SHOOT_TIME);
|
||||
const readyTime = ref(DEFAULT_READY_TIME);
|
||||
const showOfflineModal = ref(false);
|
||||
const restoreLoading = ref(false);
|
||||
const xRingStreaks = ref({});
|
||||
|
||||
// 消息队列:只保存“待执行”的战况消息,页面展示统一由队列串行驱动。
|
||||
const battleQueue = ref([]);
|
||||
@@ -105,6 +103,8 @@ let restoreLoadingTimer = null;
|
||||
let pendingRoundAudio = false;
|
||||
// 一旦收到 BattleEnd,后续普通消息就不再进入队列。
|
||||
let battleEnded = false;
|
||||
let battleEndTaskRunning = false;
|
||||
let resultNavigationPending = false;
|
||||
let skipNextRestoreOnShow = false;
|
||||
let pendingReturnSnapshot = null;
|
||||
const handledMessageKeys = new Set();
|
||||
@@ -126,21 +126,6 @@ watch(online, (newVal, oldVal) => {
|
||||
});
|
||||
|
||||
// 统一把秒级或毫秒级时间戳转成毫秒,方便和本机时间比较。
|
||||
function loadXRingStreaks() {
|
||||
const cached = uni.getStorageSync(X_RING_STREAKS_KEY);
|
||||
xRingStreaks.value =
|
||||
cached && typeof cached === "object" && !Array.isArray(cached) ? cached : {};
|
||||
}
|
||||
|
||||
function saveXRingStreaks() {
|
||||
uni.setStorageSync(X_RING_STREAKS_KEY, xRingStreaks.value);
|
||||
}
|
||||
|
||||
function clearXRingStreaks() {
|
||||
xRingStreaks.value = {};
|
||||
uni.removeStorageSync(X_RING_STREAKS_KEY);
|
||||
}
|
||||
|
||||
function normalizeTimestamp(value) {
|
||||
const numberValue = Number(value || 0);
|
||||
if (!numberValue) return 0;
|
||||
@@ -395,6 +380,16 @@ function showRestoreLoading() {
|
||||
}, RESTORE_LOADING_TIMEOUT);
|
||||
}
|
||||
|
||||
// 终局开始后作废恢复请求,避免恢复遮罩与结算跳转抢占画面。
|
||||
function cancelPendingBattleRestore() {
|
||||
restoreGeneration += 1;
|
||||
if (pendingRestoreTimer) {
|
||||
clearTimeout(pendingRestoreTimer);
|
||||
pendingRestoreTimer = null;
|
||||
}
|
||||
hideRestoreLoading();
|
||||
}
|
||||
|
||||
// 页面重置、离开或恢复快照时调用,统一清理队列、等待器、音频和进度条。
|
||||
function invalidateBattleQueue({ stopAudio = false, stopProgress = false } = {}) {
|
||||
// 提升队列代际并清空待执行消息,确保恢复快照时不会继续跑旧战况。
|
||||
@@ -414,7 +409,10 @@ function invalidateBattleQueue({ stopAudio = false, stopProgress = false } = {})
|
||||
function enqueueBattleMessage(message) {
|
||||
if (Array.isArray(message) || !message?.type) return;
|
||||
if (battleEnded && message.type !== MESSAGETYPESV2.BattleEnd) return;
|
||||
if (message.type === MESSAGETYPESV2.BattleEnd) battleEnded = true;
|
||||
if (message.type === MESSAGETYPESV2.BattleEnd) {
|
||||
battleEnded = true;
|
||||
cancelPendingBattleRestore();
|
||||
}
|
||||
|
||||
if (message.type === MESSAGETYPESV2.InvalidShot) {
|
||||
const receivedAt = Date.now();
|
||||
@@ -780,7 +778,7 @@ function getBackendRemainingSeconds(battleInfo, total) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 计算当前倒计时剩余秒数:后端字段优先,其次按开始时间和当前时间补算。
|
||||
// 计算当前倒计时剩余秒数:后端字段优先,其次按 ACK 时间和当前时间补算。
|
||||
function getRemainingSeconds(battleInfo, task, options = {}) {
|
||||
const total = getShootTimeSeconds(battleInfo);
|
||||
const backendRemain = getBackendRemainingSeconds(battleInfo, total);
|
||||
@@ -788,8 +786,9 @@ function getRemainingSeconds(battleInfo, task, options = {}) {
|
||||
// 新轮首箭由后端 shootTime 定完整时长;没有明确剩余时间时,不扣前端轮次弹窗/语音耗时。
|
||||
if (options.fullDurationIfNoBackendRemain) return total;
|
||||
|
||||
const startTime = normalizeTimestamp(battleInfo?.current?.startTime);
|
||||
if (!startTime) return total;
|
||||
const ackTime = normalizeTimestamp(battleInfo?.current?.ackTime);
|
||||
console.log(11111111111111111111111111,ackTime)
|
||||
if (!ackTime) return total;
|
||||
|
||||
// 后端时间是准的,前端只根据语音耗时和接收延迟做近似补偿。
|
||||
// 但回前台的 API 快照不一定带“当前后端时间”,恢复场景优先用本机当前时间计算最新剩余秒数。
|
||||
@@ -798,7 +797,8 @@ function getRemainingSeconds(battleInfo, task, options = {}) {
|
||||
: task?.serverTime || getServerTime(battleInfo) || Date.now();
|
||||
const waitAfterReceive = task?.serverTime ? Date.now() - task.receivedAt : 0;
|
||||
const effectiveNow = anchorTime + waitAfterReceive;
|
||||
const elapsed = Math.max(0, (effectiveNow - startTime) / 1000);
|
||||
const elapsed = Math.max(0, (effectiveNow - ackTime) / 1000);
|
||||
console.log('剩余:', elapsed, waitAfterReceive, Math.max(0, Math.min(total, total - elapsed)))
|
||||
return Math.max(0, Math.min(total, total - elapsed));
|
||||
}
|
||||
|
||||
@@ -916,7 +916,6 @@ function applyBattleSnapshot(battleInfo, { restore = false, restoreEventType = 0
|
||||
// 开局任务:切换到正式比赛态,并播报“比赛开始”。
|
||||
async function runBattleStartTask(task, runId) {
|
||||
// 开赛任务只负责切换正式态并播“比赛开始”,后续进入队列顺序。
|
||||
clearXRingStreaks();
|
||||
applyBattleBase(task.message);
|
||||
start.value = true;
|
||||
pendingRoundAudio = true;
|
||||
@@ -992,29 +991,6 @@ async function runToSomeoneShootTask(task, runId) {
|
||||
});
|
||||
}
|
||||
|
||||
function isTenPlusRing(shot) {
|
||||
return !!(shot?.ringX || Number(shot?.ring) >= 10);
|
||||
}
|
||||
|
||||
function updateXRingStreak(shooterId, isTenPlusRingShot) {
|
||||
if (!shooterId) return false;
|
||||
const id = String(shooterId);
|
||||
if (!isTenPlusRingShot) {
|
||||
xRingStreaks.value[id] = 0;
|
||||
saveXRingStreaks();
|
||||
return false;
|
||||
}
|
||||
|
||||
xRingStreaks.value[id] = (xRingStreaks.value[id] || 0) + 1;
|
||||
if (xRingStreaks.value[id] < 3) {
|
||||
saveXRingStreaks();
|
||||
return false;
|
||||
}
|
||||
xRingStreaks.value[id] = 0;
|
||||
saveXRingStreaks();
|
||||
return true;
|
||||
}
|
||||
|
||||
function buildShootResultAudioKeys(shootData) {
|
||||
if (!shootData) return [];
|
||||
const audioKeys = [
|
||||
@@ -1023,6 +999,9 @@ function buildShootResultAudioKeys(shootData) {
|
||||
if (shootData.angle !== null && shootData.angle !== undefined) {
|
||||
audioKeys.push(`向${getDirectionText(shootData.angle)}调整`);
|
||||
}
|
||||
if (shootData.threeConsecutive10Rings === true) {
|
||||
audioKeys.push("tententen");
|
||||
}
|
||||
return audioKeys;
|
||||
}
|
||||
|
||||
@@ -1042,12 +1021,7 @@ async function runShootResultTask(task) {
|
||||
};
|
||||
}
|
||||
|
||||
const isTententen = updateXRingStreak(
|
||||
currentShooterId.value,
|
||||
isTenPlusRing(battleInfo.shootData)
|
||||
);
|
||||
const audioKeys = buildShootResultAudioKeys(battleInfo.shootData);
|
||||
if (isTententen) audioKeys.push("tententen");
|
||||
await playAudioKeys(audioKeys, { interrupt: false });
|
||||
notifyMatchAudioAck(task);
|
||||
}
|
||||
@@ -1094,39 +1068,64 @@ async function runNewRoundTask(task, runId) {
|
||||
pendingRoundAudio = true;
|
||||
}
|
||||
|
||||
function navigateToBattleResultOnce(matchId) {
|
||||
const targetMatchId = matchId || battleId.value;
|
||||
if (!targetMatchId || resultNavigationPending) return false;
|
||||
|
||||
resultNavigationPending = true;
|
||||
battleEnded = true;
|
||||
cancelPendingBattleRestore();
|
||||
|
||||
uni.redirectTo({
|
||||
url: `/pages/friend-battle-result?battleId=${targetMatchId}`,
|
||||
fail: (err) => {
|
||||
resultNavigationPending = false;
|
||||
console.log("navigate to battle result failed:", err);
|
||||
},
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
// 终局任务:播放结束语音后,根据状态跳结果页或返回上一页。
|
||||
async function runBattleEndTask(task, runId) {
|
||||
const battleInfo = task.message;
|
||||
applyBattleBase(battleInfo);
|
||||
battleEnded = true;
|
||||
clearXRingStreaks();
|
||||
matchStatus.value = battleInfo.status;
|
||||
if (battleInfo.status === 4) {
|
||||
showRoundTip.value = true;
|
||||
currentBluePoint.value = 0;
|
||||
currentRedPoint.value = 0;
|
||||
if (resultNavigationPending) {
|
||||
notifyMatchAudioAck(task);
|
||||
return;
|
||||
}
|
||||
|
||||
// 终局语音必须完整播完,再决定跳转或返回。
|
||||
await playAudioKeys("比赛结束", { interrupt: false, timeout: AUDIO_TIMEOUT_MAX });
|
||||
notifyMatchAudioAck(task);
|
||||
if (!isQueueAlive(runId)) return;
|
||||
battleEndTaskRunning = true;
|
||||
try {
|
||||
const battleInfo = task.message;
|
||||
applyBattleBase(battleInfo);
|
||||
battleEnded = true;
|
||||
matchStatus.value = battleInfo.status;
|
||||
if (battleInfo.status === 4) {
|
||||
showRoundTip.value = true;
|
||||
currentBluePoint.value = 0;
|
||||
currentRedPoint.value = 0;
|
||||
}
|
||||
|
||||
if (matchStatus.value === 2) {
|
||||
uni.redirectTo({
|
||||
url: `/pages/friend-battle-result?battleId=${battleId.value}`,
|
||||
});
|
||||
} else if (matchStatus.value === 4) {
|
||||
const roomNumber = battleInfo.roomId || store.game.roomNumber || store.game.roomID;
|
||||
setTimeout(() => {
|
||||
if (roomNumber) {
|
||||
uni.redirectTo({
|
||||
url: `/pages/battle-room?roomNumber=${encodeURIComponent(roomNumber)}&fromResult=1`,
|
||||
});
|
||||
} else {
|
||||
uni.navigateBack();
|
||||
}
|
||||
}, BATTLE_CANCEL_RETURN_DELAY);
|
||||
// 终局语音必须完整播完,再决定跳转或返回。
|
||||
await playAudioKeys("比赛结束", { interrupt: false, timeout: AUDIO_TIMEOUT_MAX });
|
||||
notifyMatchAudioAck(task);
|
||||
if (!isQueueAlive(runId)) return;
|
||||
|
||||
if (matchStatus.value === 2) {
|
||||
navigateToBattleResultOnce(battleId.value);
|
||||
} else if (matchStatus.value === 4) {
|
||||
const roomNumber = battleInfo.roomId || store.game.roomNumber || store.game.roomID;
|
||||
setTimeout(() => {
|
||||
if (roomNumber) {
|
||||
uni.redirectTo({
|
||||
url: `/pages/battle-room?roomNumber=${encodeURIComponent(roomNumber)}&fromResult=1`,
|
||||
});
|
||||
} else {
|
||||
uni.navigateBack();
|
||||
}
|
||||
}, BATTLE_CANCEL_RETURN_DELAY);
|
||||
}
|
||||
} finally {
|
||||
battleEndTaskRunning = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1143,7 +1142,14 @@ async function runInvalidShotTask(task, runId) {
|
||||
|
||||
// 回前台恢复入口:拉取服务端快照,处理结束态,然后继续消费增量队列。
|
||||
async function restoreLatestBattle() {
|
||||
if (!battleId.value) return;
|
||||
if (
|
||||
!battleId.value ||
|
||||
battleEnded ||
|
||||
battleEndTaskRunning ||
|
||||
resultNavigationPending
|
||||
) {
|
||||
return;
|
||||
}
|
||||
const currentRestoreId = ++restoreGeneration;
|
||||
showRestoreLoading();
|
||||
|
||||
@@ -1173,16 +1179,11 @@ async function restoreLatestBattle() {
|
||||
const restoreEventType = Number(result?.eventType || 0);
|
||||
|
||||
if (result.status === 2) {
|
||||
clearXRingStreaks();
|
||||
hideRestoreLoading();
|
||||
uni.redirectTo({
|
||||
url: `/pages/friend-battle-result?battleId=${result.matchId}`,
|
||||
});
|
||||
battleEnded = true;
|
||||
if (!battleEndTaskRunning) navigateToBattleResultOnce(result.matchId);
|
||||
return;
|
||||
}
|
||||
if (result.status === 4) {
|
||||
clearXRingStreaks();
|
||||
}
|
||||
reconnectMatchServer(result);
|
||||
|
||||
if (restoreEventType === MESSAGETYPESV2.NewRound) {
|
||||
@@ -1213,6 +1214,8 @@ async function restoreLatestBattle() {
|
||||
}
|
||||
|
||||
function scheduleRestoreLatestBattle() {
|
||||
if (battleEnded || battleEndTaskRunning || resultNavigationPending) return;
|
||||
|
||||
if (pendingRestoreTimer) {
|
||||
clearTimeout(pendingRestoreTimer);
|
||||
pendingRestoreTimer = null;
|
||||
@@ -1275,7 +1278,6 @@ onLoad((options) => {
|
||||
shootTimeTotal.value = DEFAULT_SHOOT_TIME;
|
||||
showOfflineModal.value = false;
|
||||
hideRestoreLoading();
|
||||
loadXRingStreaks();
|
||||
queueGeneration += 1;
|
||||
battleQueue.value = [];
|
||||
queueRunning.value = false;
|
||||
@@ -1284,6 +1286,8 @@ onLoad((options) => {
|
||||
restoreGeneration += 1;
|
||||
pendingRoundAudio = false;
|
||||
battleEnded = false;
|
||||
battleEndTaskRunning = false;
|
||||
resultNavigationPending = false;
|
||||
handledMessageKeys.clear();
|
||||
handledMessageKeyOrder.length = 0;
|
||||
queuedMessageKeys.clear();
|
||||
@@ -1328,6 +1332,8 @@ onMounted(async () => {
|
||||
|
||||
// 离开页面时清理监听、停止音频,并让当前队列整体失效。
|
||||
onBeforeUnmount(() => {
|
||||
restoreGeneration += 1;
|
||||
battleEndTaskRunning = false;
|
||||
uni.setKeepScreenOn({
|
||||
keepScreenOn: false,
|
||||
});
|
||||
|
||||
Vendored
+1
-1
@@ -1,4 +1,4 @@
|
||||
/* eslint-disable */
|
||||
import * as $protobuf from "protobufjs";
|
||||
const $root=$protobuf.Root.create({nested:{rpc:{ServerMessageType:{SERVER_MSG_UNKNOWN:0,SERVER_MSG_MATCH_READY:1,SERVER_MSG_MATCH_START:2,SERVER_MSG_NOW_YOU:3,SERVER_MSG_SHOT:4,SERVER_MSG_NEW_ROUND:5,SERVER_MSG_MATCH_END:6,SERVER_MSG_TIMEOUT:7,SERVER_MSG_CHECK:8,SERVER_MSG_RAND:9,SERVER_MSG_NOT_ENOUGH_DISTANCE:10,SERVER_MSG_PLAYER_LEFT:11,SERVER_MSG_HEARTBEAT:12,SERVER_MSG_PRACTICE_END:13},ClientMessageType:{CLIENT_MSG_UNKNOWN:0,CLIENT_MSG_HEARTBEAT_ACK:1,CLIENT_MSG_SHOOT_DATA:2,CLIENT_MSG_ACK:3,CLIENT_MSG_LEAVE:4},MatchStatus:{MATCH_STATUS_READY:0,MATCH_STATUS_STARTED:1,MATCH_STATUS_END:2,MATCH_STATUS_TIMEOUT:3,MATCH_STATUS_UNEXPECTEDLY:4},MatchPlayerStatus:{MATCH_PLAYER_STATUS_READY:0,MATCH_PLAYER_STATUS_STARTED:1,MATCH_PLAYER_STATUS_END:2},MatchShoot:{fields:{player_id:{type:"int64",id:1},status:{type:"int32",id:2},x:{type:"float",id:3},y:{type:"float",id:4},ring:{type:"int32",id:5},ring_x:{type:"bool",id:6},angle:{type:"float",id:7},distance:{type:"float",id:8}}},MatchShootList:{fields:{items:{rule:"repeated",type:"MatchShoot",id:1}}},RoundScore:{fields:{total_ring:{type:"int32",id:1},score:{type:"int32",id:2},if_win:{type:"bool",id:3}}},MatchRound:{fields:{shoots:{rule:"map",type:"MatchShootList",id:1,keytype:"int64"},scores:{rule:"map",type:"RoundScore",id:2,keytype:"int32"},round:{type:"int32",id:3},if_gold:{type:"bool",id:4},status:{type:"int32",id:5},gold_round:{type:"int32",id:6}}},PlayerMatchResult:{fields:{total_ring:{type:"int32",id:1},user_id:{type:"int64",id:2},ten_ring_count:{type:"int32",id:3},average_ring:{type:"float",id:4}}},PlayerFull:{fields:{id:{type:"int64",id:1},name:{type:"string",id:2},avatar:{type:"string",id:3},exp:{type:"int32",id:4},score:{type:"int32",id:5},level:{type:"int32",id:6},before_level:{type:"int32",id:7},before_exp:{type:"int32",id:8},current_exp:{type:"int32",id:9},upgrade_exp:{type:"int32",id:10},active:{type:"int32",id:11},device_id:{type:"string",id:12},s_vip:{type:"bool",id:13},vip:{type:"bool",id:14},player_match_result:{type:"PlayerMatchResult",id:15}}},TeamInfo:{fields:{players:{rule:"repeated",type:"PlayerFull",id:1},id:{type:"int32",id:2},name:{type:"string",id:3},score:{type:"int32",id:4}}},CurrentShoot:{fields:{round:{type:"int32",id:1},round_id:{type:"int64",id:2},index:{type:"int32",id:3},start_time:{type:"int64",id:4},player_id:{type:"int64",id:5},gold_round:{type:"bool",id:6},start_time_text:{type:"string",id:7},my_index:{type:"int32",id:8},index_map:{rule:"map",type:"int32",id:9,keytype:"int64"}}},ShootData:{fields:{x:{type:"float",id:1},y:{type:"float",id:2},r:{type:"float",id:3},dst:{type:"float",id:4},m:{type:"string",id:5},adc:{type:"float",id:6},device_id:{type:"string",id:7},shoot_id:{type:"string",id:8}}},PracticeInfo:{fields:{id:{type:"int64",id:1},user_id:{type:"int64",id:2},status:{type:"int32",id:3},status_text:{type:"string",id:4},start_time:{type:"int64",id:5},target_type:{type:"int32",id:6},vip:{type:"bool",id:7},s_vip:{type:"bool",id:8},device_id:{type:"string",id:9},shoot_data:{type:"MatchShoot",id:10},details:{rule:"repeated",type:"MatchShoot",id:11}}},MatchInfo:{fields:{match_id:{type:"string",id:1},create_time:{type:"int64",id:2},start_time:{type:"int64",id:3},server_time:{type:"int64",id:4},shoot_time:{type:"int32",id:5},shoot_number:{type:"int32",id:6},ready_time:{type:"int32",id:7},way:{type:"int32",id:8},mode:{type:"int32",id:9},status:{type:"MatchStatus",id:10},status_text:{type:"string",id:11},rounds:{rule:"repeated",type:"MatchRound",id:12},teams:{rule:"map",type:"TeamInfo",id:13,keytype:"int32"},current:{type:"CurrentShoot",id:14},next:{type:"CurrentShoot",id:15},shoot_data:{type:"MatchShoot",id:16},win_team:{type:"int32",id:17},mvp:{type:"PlayerFull",id:18},room_id:{type:"string",id:19},result_list:{rule:"repeated",type:"PlayerMatchResult",id:20},timeout_time:{type:"int64",id:21},target_type:{type:"int32",id:22},event_type:{type:"int32",id:23},timeout:{type:"int32",id:24},server_addr:{type:"string",id:25},countdown_start_time:{type:"int64",id:26}}},ServerMessage:{fields:{type:{type:"ServerMessageType",id:1},match_id:{type:"string",id:2},timestamp:{type:"int64",id:3},match_info:{type:"MatchInfo",id:4,oneof:"payload"},shoot_data:{type:"ShootData",id:5,oneof:"payload"},practice_info:{type:"PracticeInfo",id:6,oneof:"payload"},sequence:{type:"int64",id:7}}},ClientMessage:{fields:{type:{type:"ClientMessageType",id:1},match_id:{type:"string",id:2},user_id:{type:"int64",id:3},sequence:{type:"int64",id:4},data:{type:"bytes",id:5}}}}}});
|
||||
const $root=$protobuf.Root.create({nested:{rpc:{ServerMessageType:{SERVER_MSG_UNKNOWN:0,SERVER_MSG_MATCH_READY:1,SERVER_MSG_MATCH_START:2,SERVER_MSG_NOW_YOU:3,SERVER_MSG_SHOT:4,SERVER_MSG_NEW_ROUND:5,SERVER_MSG_MATCH_END:6,SERVER_MSG_TIMEOUT:7,SERVER_MSG_CHECK:8,SERVER_MSG_RAND:9,SERVER_MSG_NOT_ENOUGH_DISTANCE:10,SERVER_MSG_PLAYER_LEFT:11,SERVER_MSG_HEARTBEAT:12,SERVER_MSG_PRACTICE_END:13},ClientMessageType:{CLIENT_MSG_UNKNOWN:0,CLIENT_MSG_HEARTBEAT_ACK:1,CLIENT_MSG_SHOOT_DATA:2,CLIENT_MSG_ACK:3,CLIENT_MSG_LEAVE:4},MatchStatus:{MATCH_STATUS_READY:0,MATCH_STATUS_STARTED:1,MATCH_STATUS_END:2,MATCH_STATUS_TIMEOUT:3,MATCH_STATUS_UNEXPECTEDLY:4},MatchPlayerStatus:{MATCH_PLAYER_STATUS_READY:0,MATCH_PLAYER_STATUS_STARTED:1,MATCH_PLAYER_STATUS_END:2},MatchShoot:{fields:{player_id:{type:"int64",id:1},status:{type:"int32",id:2},x:{type:"float",id:3},y:{type:"float",id:4},ring:{type:"int32",id:5},ring_x:{type:"bool",id:6},angle:{type:"float",id:7},distance:{type:"float",id:8},three_consecutive_10_rings:{type:"bool",id:9}}},MatchShootList:{fields:{items:{rule:"repeated",type:"MatchShoot",id:1}}},RoundScore:{fields:{total_ring:{type:"int32",id:1},score:{type:"int32",id:2},if_win:{type:"bool",id:3}}},MatchRound:{fields:{shoots:{rule:"map",type:"MatchShootList",id:1,keytype:"int64"},scores:{rule:"map",type:"RoundScore",id:2,keytype:"int32"},round:{type:"int32",id:3},if_gold:{type:"bool",id:4},status:{type:"int32",id:5},gold_round:{type:"int32",id:6}}},PlayerMatchResult:{fields:{total_ring:{type:"int32",id:1},user_id:{type:"int64",id:2},ten_ring_count:{type:"int32",id:3},average_ring:{type:"float",id:4}}},PlayerFull:{fields:{id:{type:"int64",id:1},name:{type:"string",id:2},avatar:{type:"string",id:3},exp:{type:"int32",id:4},score:{type:"int32",id:5},level:{type:"int32",id:6},before_level:{type:"int32",id:7},before_exp:{type:"int32",id:8},current_exp:{type:"int32",id:9},upgrade_exp:{type:"int32",id:10},active:{type:"int32",id:11},device_id:{type:"string",id:12},s_vip:{type:"bool",id:13},vip:{type:"bool",id:14},player_match_result:{type:"PlayerMatchResult",id:15}}},TeamInfo:{fields:{players:{rule:"repeated",type:"PlayerFull",id:1},id:{type:"int32",id:2},name:{type:"string",id:3},score:{type:"int32",id:4}}},CurrentShoot:{fields:{round:{type:"int32",id:1},round_id:{type:"int64",id:2},index:{type:"int32",id:3},start_time:{type:"int64",id:4},player_id:{type:"int64",id:5},gold_round:{type:"bool",id:6},start_time_text:{type:"string",id:7},my_index:{type:"int32",id:8},index_map:{rule:"map",type:"int32",id:9,keytype:"int64"},ack_time:{type:"int64",id:10}}},ShootData:{fields:{x:{type:"float",id:1},y:{type:"float",id:2},r:{type:"float",id:3},dst:{type:"float",id:4},m:{type:"string",id:5},adc:{type:"float",id:6},device_id:{type:"string",id:7},shoot_id:{type:"string",id:8},three_consecutive_10_rings:{type:"bool",id:9}}},PracticeInfo:{fields:{id:{type:"int64",id:1},user_id:{type:"int64",id:2},status:{type:"int32",id:3},status_text:{type:"string",id:4},start_time:{type:"int64",id:5},target_type:{type:"int32",id:6},vip:{type:"bool",id:7},s_vip:{type:"bool",id:8},device_id:{type:"string",id:9},shoot_data:{type:"MatchShoot",id:10},details:{rule:"repeated",type:"MatchShoot",id:11}}},MatchInfo:{fields:{match_id:{type:"string",id:1},create_time:{type:"int64",id:2},start_time:{type:"int64",id:3},server_time:{type:"int64",id:4},shoot_time:{type:"int32",id:5},shoot_number:{type:"int32",id:6},ready_time:{type:"int32",id:7},way:{type:"int32",id:8},mode:{type:"int32",id:9},status:{type:"MatchStatus",id:10},status_text:{type:"string",id:11},rounds:{rule:"repeated",type:"MatchRound",id:12},teams:{rule:"map",type:"TeamInfo",id:13,keytype:"int32"},current:{type:"CurrentShoot",id:14},next:{type:"CurrentShoot",id:15},shoot_data:{type:"MatchShoot",id:16},win_team:{type:"int32",id:17},mvp:{type:"PlayerFull",id:18},room_id:{type:"string",id:19},result_list:{rule:"repeated",type:"PlayerMatchResult",id:20},timeout_time:{type:"int64",id:21},target_type:{type:"int32",id:22},event_type:{type:"int32",id:23},timeout:{type:"int32",id:24},server_addr:{type:"string",id:25},countdown_start_time:{type:"int64",id:26}}},ServerMessage:{fields:{type:{type:"ServerMessageType",id:1},match_id:{type:"string",id:2},timestamp:{type:"int64",id:3},match_info:{type:"MatchInfo",id:4,oneof:"payload"},shoot_data:{type:"ShootData",id:5,oneof:"payload"},practice_info:{type:"PracticeInfo",id:6,oneof:"payload"},sequence:{type:"int64",id:7}}},ClientMessage:{fields:{type:{type:"ClientMessageType",id:1},match_id:{type:"string",id:2},user_id:{type:"int64",id:3},sequence:{type:"int64",id:4},data:{type:"bytes",id:5}}}}}});
|
||||
export default $root;
|
||||
|
||||
@@ -18,7 +18,7 @@ export function normalizeId(value) {
|
||||
}
|
||||
|
||||
function toCamelKey(key) {
|
||||
return key.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
|
||||
return key.replace(/_([a-z0-9])/g, (_, character) => character.toUpperCase());
|
||||
}
|
||||
|
||||
export function normalizePlainObject(value) {
|
||||
|
||||
@@ -50,6 +50,7 @@ const SCHEMAS = {
|
||||
6: { name: "ring_x", kind: "bool" },
|
||||
7: { name: "angle", kind: "float" },
|
||||
8: { name: "distance", kind: "float" },
|
||||
9: { name: "three_consecutive_10_rings", kind: "bool" },
|
||||
},
|
||||
MatchShootList: {
|
||||
1: { name: "items", kind: "message", type: "MatchShoot", repeated: true },
|
||||
@@ -123,6 +124,7 @@ const SCHEMAS = {
|
||||
keyKind: "int64",
|
||||
valueKind: "int32",
|
||||
},
|
||||
10: { name: "ack_time", kind: "int64" },
|
||||
},
|
||||
ShootData: {
|
||||
1: { name: "x", kind: "float" },
|
||||
@@ -133,6 +135,7 @@ const SCHEMAS = {
|
||||
6: { name: "adc", kind: "float" },
|
||||
7: { name: "device_id", kind: "string" },
|
||||
8: { name: "shoot_id", kind: "string" },
|
||||
9: { name: "three_consecutive_10_rings", kind: "bool" },
|
||||
},
|
||||
PracticeInfo: {
|
||||
1: { name: "id", kind: "int64" },
|
||||
|
||||
Reference in New Issue
Block a user