Merge branch 'fix-bug' into test

This commit is contained in:
2026-06-15 09:30:24 +08:00
5 changed files with 67 additions and 46 deletions

View File

@@ -35,7 +35,7 @@ const halfRestRemain = ref(HALF_REST_SECONDS);
let halfRestTimer = null; let halfRestTimer = null;
/** 控制设备离线提示弹窗的显示状态 */ /** 控制设备离线提示弹窗的显示状态 */
const showOfflineModal = ref(false); const showOfflineModal = ref(false);
/** 记录每位玩家当前半场连续 X 环key 为 playerId用于触发 tententen 音效 */ /** 记录每位玩家当前半场连续 10 环及以上次key 为 playerId用于触发 tententen 音效 */
const xRingStreaks = ref({}); const xRingStreaks = ref({});
function clearHalfRestCountdown() { function clearHalfRestCountdown() {
@@ -176,23 +176,27 @@ onLoad(async (options) => {
}); });
/** /**
* 检测指定玩家连续 X 环是否达到 3 箭,达到则在环数播报入队后追加 tententen 音效 * 检测指定玩家连续 10 环及以上是否达到 3 箭,达到则在环数播报入队后追加 tententen 音效
* @param {number|string} playerId - 本次射手的 ID大乱斗中 ShootResult 保留 playerId * @param {number|string} playerId - 本次射手的 ID大乱斗中 ShootResult 保留 playerId
* @param {boolean} isXRing - 本次射击是否为 X 环 * @param {boolean} isTenPlusRingShot - 本次射击是否为 10 环及以上
*/ */
function checkAndPlayTententen(playerId, isXRing) { function isTenPlusRing(shot) {
return !!(shot?.ringX || Number(shot?.ring) >= 10);
}
function checkAndPlayTententen(playerId, isTenPlusRingShot) {
if (!playerId) return; if (!playerId) return;
const id = parseInt(playerId); const id = parseInt(playerId);
if (isXRing) { if (isTenPlusRingShot) {
xRingStreaks.value[id] = (xRingStreaks.value[id] || 0) + 1; xRingStreaks.value[id] = (xRingStreaks.value[id] || 0) + 1;
// 同一玩家连续 3 箭均为 X 环,追加到环数音效队列尾部播放 // 同一玩家连续 3 箭均为 10 环及以上,追加到环数音效队列尾部播放
if (xRingStreaks.value[id] >= 3) { if (xRingStreaks.value[id] >= 3) {
xRingStreaks.value[id] = 0; xRingStreaks.value[id] = 0;
// nextTick 确保 HeaderProgress 的环数播报已入队后再追加 tententen避免播放顺序颠倒 // nextTick 确保 HeaderProgress 的环数播报已入队后再追加 tententen避免播放顺序颠倒
nextTick(() => audioManager.play("tententen", false)); nextTick(() => audioManager.play("tententen", false));
} }
} else { } else {
// 非 X 环则重置该玩家的连续计数 // 低于 10 环或未上靶则重置该玩家的连续计数
xRingStreaks.value[id] = 0; xRingStreaks.value[id] = 0;
} }
} }
@@ -215,18 +219,18 @@ async function onReceiveMessage(msg) {
// 对比更新后数据找出箭数增加的玩家(即本次射手),并读取其最新箭的 ring 数据 // 对比更新后数据找出箭数增加的玩家(即本次射手),并读取其最新箭的 ring 数据
const newRound = playersScores.value[playersScores.value.length - 1] || {}; const newRound = playersScores.value[playersScores.value.length - 1] || {};
let shooterId = null; let shooterId = null;
let isXRing = false; let isTenPlusRingShot = false;
for (const pid of Object.keys(newRound)) { for (const pid of Object.keys(newRound)) {
const newLen = (newRound[pid] || []).length; const newLen = (newRound[pid] || []).length;
if (newLen > (prevCounts[pid] || 0)) { if (newLen > (prevCounts[pid] || 0)) {
shooterId = parseInt(pid); shooterId = parseInt(pid);
const shot = newRound[pid][newLen - 1]; const shot = newRound[pid][newLen - 1];
isXRing = !!(shot?.ringX && shot?.ring); isTenPlusRingShot = isTenPlusRing(shot);
break; break;
} }
} }
// 检测同一玩家三箭全 X 环,触发 tententen 音效 // 检测同一玩家连续三箭 10 环及以上,触发 tententen 音效
checkAndPlayTententen(shooterId, isXRing); checkAndPlayTententen(shooterId, isTenPlusRingShot);
} else if (msg.type === MESSAGETYPESV2.HalfRest) { } else if (msg.type === MESSAGETYPESV2.HalfRest) {
halfTimeTip.value = true; halfTimeTip.value = true;
halfRest.value = true; halfRest.value = true;

View File

@@ -31,7 +31,7 @@ const { user } = storeToRefs(store);
const start = ref(false); const start = ref(false);
const scores = ref([]); const scores = ref([]);
const total = 12; const total = 12;
/** 当前练习中连续 X 环计数,用于触发 tententen 音效 */ /** 当前练习中连续 10 环及以上计数,用于触发 tententen 音效 */
const xRingStreak = ref(0); const xRingStreak = ref(0);
const practiseResult = ref({}); const practiseResult = ref({});
const practiseId = ref(""); const practiseId = ref("");
@@ -48,7 +48,7 @@ onLoad((options) => {
const onReady = async () => { const onReady = async () => {
await startPractiseAPI(); await startPractiseAPI();
scores.value = []; scores.value = [];
xRingStreak.value = 0; // 新一局开始,重置 X 环连续计数 xRingStreak.value = 0; // 新一局开始,重置 10 环及以上连续计数
start.value = true; start.value = true;
audioManager.play("练习开始"); audioManager.play("练习开始");
}; };
@@ -59,19 +59,23 @@ const onOver = async () => {
}; };
/** /**
* 检测连续 X 环是否达到 3 箭,达到则播放 tententen 音效 * 检测连续 10 环及以上是否达到 3 箭,达到则播放 tententen 音效
* @param {boolean} isXRing - 本次射击是否为 X 环 * @param {boolean} isTenPlusRingShot - 本次射击是否为 10 环及以上
*/ */
function checkAndPlayTententen(isXRing) { function isTenPlusRing(shot) {
if (isXRing) { return !!(shot?.ringX || Number(shot?.ring) >= 10);
}
function checkAndPlayTententen(isTenPlusRingShot) {
if (isTenPlusRingShot) {
xRingStreak.value += 1; xRingStreak.value += 1;
// 连续 3 箭均为 X 环,在环数播报入队后追加 tententen避免播放顺序颠倒 // 连续 3 箭均为 10 环及以上,在环数播报入队后追加 tententen避免播放顺序颠倒
if (xRingStreak.value >= 3) { if (xRingStreak.value >= 3) {
xRingStreak.value = 0; xRingStreak.value = 0;
nextTick(() => audioManager.play("tententen", false)); nextTick(() => audioManager.play("tententen", false));
} }
} else { } else {
// 非 X 环则重置连续计数 // 低于 10 环或未上靶则重置连续计数
xRingStreak.value = 0; xRingStreak.value = 0;
} }
} }
@@ -80,10 +84,10 @@ async function onReceiveMessage(msg) {
if (msg.type === MESSAGETYPESV2.ShootResult) { if (msg.type === MESSAGETYPESV2.ShootResult) {
const prevLen = scores.value.length; const prevLen = scores.value.length;
scores.value = msg.details; scores.value = msg.details;
// 有新箭时取最后一箭判断是否 X 环并检测连续计数 // 有新箭时取最后一箭判断是否 10 环及以上并检测连续计数
if (scores.value.length > prevLen) { if (scores.value.length > prevLen) {
const latestArrow = scores.value[scores.value.length - 1]; const latestArrow = scores.value[scores.value.length - 1];
checkAndPlayTententen(!!(latestArrow?.ringX && latestArrow?.ring)); checkAndPlayTententen(isTenPlusRing(latestArrow));
} }
} else if (msg.type === MESSAGETYPESV2.BattleEnd) { } else if (msg.type === MESSAGETYPESV2.BattleEnd) {
// setTimeout(onOver, 1500); // setTimeout(onOver, 1500);
@@ -101,7 +105,7 @@ async function onComplete() {
practiseResult.value = {}; practiseResult.value = {};
start.value = false; start.value = false;
scores.value = []; scores.value = [];
xRingStreak.value = 0; // 重新开始练习,重置 X 环连续计数 xRingStreak.value = 0; // 重新开始练习,重置 10 环及以上连续计数
const result = await createPractiseAPI(total, 120); const result = await createPractiseAPI(total, 120);
if (result) practiseId.value = result.id; if (result) practiseId.value = result.id;
} }

View File

@@ -31,7 +31,7 @@ const { user } = storeToRefs(store);
const start = ref(false); const start = ref(false);
const scores = ref([]); const scores = ref([]);
const total = 36; const total = 36;
/** 当前练习中连续 X 环计数,用于触发 tententen 音效 */ /** 当前练习中连续 10 环及以上计数,用于触发 tententen 音效 */
const xRingStreak = ref(0); const xRingStreak = ref(0);
const practiseResult = ref({}); const practiseResult = ref({});
const practiseId = ref(""); const practiseId = ref("");
@@ -47,7 +47,7 @@ onLoad((options) => {
const onReady = async () => { const onReady = async () => {
await startPractiseAPI(); await startPractiseAPI();
scores.value = []; scores.value = [];
xRingStreak.value = 0; // 新一局开始,重置 X 环连续计数 xRingStreak.value = 0; // 新一局开始,重置 10 环及以上连续计数
start.value = true; start.value = true;
audioManager.play("练习开始"); audioManager.play("练习开始");
}; };
@@ -58,19 +58,23 @@ const onOver = async () => {
}; };
/** /**
* 检测连续 X 环是否达到 3 箭,达到则播放 tententen 音效 * 检测连续 10 环及以上是否达到 3 箭,达到则播放 tententen 音效
* @param {boolean} isXRing - 本次射击是否为 X 环 * @param {boolean} isTenPlusRingShot - 本次射击是否为 10 环及以上
*/ */
function checkAndPlayTententen(isXRing) { function isTenPlusRing(shot) {
if (isXRing) { return !!(shot?.ringX || Number(shot?.ring) >= 10);
}
function checkAndPlayTententen(isTenPlusRingShot) {
if (isTenPlusRingShot) {
xRingStreak.value += 1; xRingStreak.value += 1;
// 连续 3 箭均为 X 环,在环数播报入队后追加 tententen避免播放顺序颠倒 // 连续 3 箭均为 10 环及以上,在环数播报入队后追加 tententen避免播放顺序颠倒
if (xRingStreak.value >= 3) { if (xRingStreak.value >= 3) {
xRingStreak.value = 0; xRingStreak.value = 0;
nextTick(() => audioManager.play("tententen", false)); nextTick(() => audioManager.play("tententen", false));
} }
} else { } else {
// 非 X 环则重置连续计数 // 低于 10 环或未上靶则重置连续计数
xRingStreak.value = 0; xRingStreak.value = 0;
} }
} }
@@ -79,10 +83,10 @@ async function onReceiveMessage(msg) {
if (msg.type === MESSAGETYPESV2.ShootResult) { if (msg.type === MESSAGETYPESV2.ShootResult) {
const prevLen = scores.value.length; const prevLen = scores.value.length;
scores.value = msg.details; scores.value = msg.details;
// 有新箭时取最后一箭判断是否 X 环并检测连续计数 // 有新箭时取最后一箭判断是否 10 环及以上并检测连续计数
if (scores.value.length > prevLen) { if (scores.value.length > prevLen) {
const latestArrow = scores.value[scores.value.length - 1]; const latestArrow = scores.value[scores.value.length - 1];
checkAndPlayTententen(!!(latestArrow?.ringX && latestArrow?.ring)); checkAndPlayTententen(isTenPlusRing(latestArrow));
} }
} else if (msg.type === MESSAGETYPESV2.BattleEnd) { } else if (msg.type === MESSAGETYPESV2.BattleEnd) {
setTimeout(onOver, 1500); setTimeout(onOver, 1500);
@@ -116,7 +120,7 @@ async function onComplete() {
practiseResult.value = {}; practiseResult.value = {};
start.value = false; start.value = false;
scores.value = []; scores.value = [];
xRingStreak.value = 0; // 重新开始练习,重置 X 环连续计数 xRingStreak.value = 0; // 重新开始练习,重置 10 环及以上连续计数
const result = await createPractiseAPI(total, 3600); const result = await createPractiseAPI(total, 3600);
if (result) practiseId.value = result.id; if (result) practiseId.value = result.id;
} }

View File

@@ -49,7 +49,7 @@ const battleWay = ref(0);
const lastToSomeoneShootKey = ref(""); const lastToSomeoneShootKey = ref("");
/** 控制设备离线提示弹窗的显示状态 */ /** 控制设备离线提示弹窗的显示状态 */
const showOfflineModal = ref(false); const showOfflineModal = ref(false);
/** 记录每位玩家当前轮连续 X 环key 为 playerId用于触发 tententen 音效 */ /** 记录每位玩家当前轮连续 10 环及以上次key 为 playerId用于触发 tententen 音效 */
const xRingStreaks = ref({}); const xRingStreaks = ref({});
/** /**
@@ -234,22 +234,26 @@ function onNewRound(msg, prevRound) {
} }
/** /**
* 检测指定射手连续 X 环是否达到 3 箭,达到则在环数播报入队后追加 tententen 音效 * 检测指定射手连续 10 环及以上是否达到 3 箭,达到则在环数播报入队后追加 tententen 音效
* @param {number} shooterId - 本次射手的 ID取自 currentShooterId.value * @param {number} shooterId - 本次射手的 ID取自 currentShooterId.value
* @param {boolean} isXRing - 本次射击是否为 X 环 * @param {boolean} isTenPlusRingShot - 本次射击是否为 10 环及以上
*/ */
function checkAndPlayTententen(shooterId, isXRing) { function isTenPlusRing(shot) {
return !!(shot?.ringX || Number(shot?.ring) >= 10);
}
function checkAndPlayTententen(shooterId, isTenPlusRingShot) {
if (!shooterId) return; if (!shooterId) return;
if (isXRing) { if (isTenPlusRingShot) {
xRingStreaks.value[shooterId] = (xRingStreaks.value[shooterId] || 0) + 1; xRingStreaks.value[shooterId] = (xRingStreaks.value[shooterId] || 0) + 1;
// 同一玩家连续 3 箭均为 X 环,追加到环数音效队列尾部播放 // 同一玩家连续 3 箭均为 10 环及以上,追加到环数音效队列尾部播放
if (xRingStreaks.value[shooterId] >= 3) { if (xRingStreaks.value[shooterId] >= 3) {
xRingStreaks.value[shooterId] = 0; xRingStreaks.value[shooterId] = 0;
// nextTick 确保 HeaderProgress 的环数播报已入队后再追加 tententen避免播放顺序颠倒 // nextTick 确保 HeaderProgress 的环数播报已入队后再追加 tententen避免播放顺序颠倒
nextTick(() => audioManager.play("tententen", false)); nextTick(() => audioManager.play("tententen", false));
} }
} else { } else {
// 非 X 环则重置该玩家的连续计数 // 低于 10 环或未上靶则重置该玩家的连续计数
xRingStreaks.value[shooterId] = 0; xRingStreaks.value[shooterId] = 0;
} }
} }
@@ -268,9 +272,9 @@ async function onReceiveMessage(msg) {
} else if (msg.type === MESSAGETYPESV2.ShootResult) { } else if (msg.type === MESSAGETYPESV2.ShootResult) {
showRoundTip.value = false; showRoundTip.value = false;
recoverData(msg, {arrowOnly: true}); recoverData(msg, {arrowOnly: true});
// 检测同一玩家三箭全 X 环,触发 tententen 音效 // 检测同一玩家连续三箭 10 环及以上,触发 tententen 音效
// currentShooterId 在 ToSomeoneShoot 时写入ShootResult 不会覆盖,可靠识别本次射手 // currentShooterId 在 ToSomeoneShoot 时写入ShootResult 不会覆盖,可靠识别本次射手
checkAndPlayTententen(currentShooterId.value, !!(msg.shootData?.ringX && msg.shootData?.ring)); checkAndPlayTententen(currentShooterId.value, isTenPlusRing(msg.shootData));
} else if (msg.type === MESSAGETYPESV2.NewRound) { } else if (msg.type === MESSAGETYPESV2.NewRound) {
// 在进入延迟前先捕获当前轮次,供 onNewRound 使用,防止 800ms 内 ToSomeoneShoot 提前更新 currentRound 造成 Tip 展示错轮 // 在进入延迟前先捕获当前轮次,供 onNewRound 使用,防止 800ms 内 ToSomeoneShoot 提前更新 currentRound 造成 Tip 展示错轮
const prevRound = currentRound.value; const prevRound = currentRound.value;

View File

@@ -479,7 +479,8 @@ function updateGoldenRound(battleInfo) {
} }
const rounds = Array.isArray(battleInfo.rounds) ? battleInfo.rounds : []; const rounds = Array.isArray(battleInfo.rounds) ? battleInfo.rounds : [];
const finishedGoldCount = rounds.filter((round) => !!round?.ifGold).length; const finishedGoldCount = rounds.filter((round) => !!round?.ifGold).length;
goldenRound.value = Math.max(1, finishedGoldCount + (battleInfo.current?.playerId ? 1 : 0)); // goldenRound.value = Math.max(1, finishedGoldCount + (battleInfo.current?.playerId ? 1 : 0));
goldenRound.value = Math.max(1, finishedGoldCount);
} }
// Restore an info snapshot whose eventType points at the NewRound phase. // Restore an info snapshot whose eventType points at the NewRound phase.
@@ -857,10 +858,14 @@ async function runToSomeoneShootTask(task, runId) {
}); });
} }
function updateXRingStreak(shooterId, isXRing) { function isTenPlusRing(shot) {
return !!(shot?.ringX || Number(shot?.ring) >= 10);
}
function updateXRingStreak(shooterId, isTenPlusRingShot) {
if (!shooterId) return false; if (!shooterId) return false;
const id = String(shooterId); const id = String(shooterId);
if (!isXRing) { if (!isTenPlusRingShot) {
xRingStreaks.value[id] = 0; xRingStreaks.value[id] = 0;
saveXRingStreaks(); saveXRingStreaks();
return false; return false;
@@ -905,7 +910,7 @@ async function runShootResultTask(task) {
const isTententen = updateXRingStreak( const isTententen = updateXRingStreak(
currentShooterId.value, currentShooterId.value,
!!(battleInfo.shootData?.ringX && battleInfo.shootData?.ring) isTenPlusRing(battleInfo.shootData)
); );
const audioKeys = buildShootResultAudioKeys(battleInfo.shootData); const audioKeys = buildShootResultAudioKeys(battleInfo.shootData);
if (isTententen) audioKeys.push("tententen"); if (isTententen) audioKeys.push("tententen");