update:新增房间重连逻辑,优化tententen语音,修复mvp斩获环

This commit is contained in:
2026-07-16 16:40:32 +08:00
parent 621397e25d
commit f64a6b5c95
13 changed files with 328 additions and 255 deletions
+1 -33
View File
@@ -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();
}
}