Merge branch 'new-race-mode' into test
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
export const audioFils = {
|
export const audioFils = {
|
||||||
|
tententen: "https://static.shelingxingqiu.com/shootmini/static/audio/tententen.mp3",
|
||||||
点击按钮: "https://static.shelingxingqiu.com/shootmini/static/audio/%E7%82%B9%E5%87%BB%E6%8C%89%E9%92%AE.mp3",
|
点击按钮: "https://static.shelingxingqiu.com/shootmini/static/audio/%E7%82%B9%E5%87%BB%E6%8C%89%E9%92%AE.mp3",
|
||||||
"20CM全环靶": "https://static.shelingxingqiu.com/shootmini/static/audio/20CM%E5%85%A8%E7%8E%AF%E9%9D%B6-%E6%97%A0%E6%95%88.mp3",
|
"20CM全环靶": "https://static.shelingxingqiu.com/shootmini/static/audio/20CM%E5%85%A8%E7%8E%AF%E9%9D%B6-%E6%97%A0%E6%95%88.mp3",
|
||||||
"40CM全环靶": "https://static.shelingxingqiu.com/shootmini/static/audio/40CM%E5%85%A8%E7%8E%AF%E9%9D%B6-%E6%97%A0%E6%95%88.mp3",
|
"40CM全环靶": "https://static.shelingxingqiu.com/shootmini/static/audio/40CM%E5%85%A8%E7%8E%AF%E9%9D%B6-%E6%97%A0%E6%95%88.mp3",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { ref, onMounted, onBeforeUnmount, watch } from "vue";
|
import { ref, onMounted, onBeforeUnmount, watch, nextTick } from "vue";
|
||||||
import { onLoad, onShow, onHide } from "@dcloudio/uni-app";
|
import { onLoad, onShow, onHide } from "@dcloudio/uni-app";
|
||||||
import Container from "@/components/Container.vue";
|
import Container from "@/components/Container.vue";
|
||||||
import BowTarget from "@/components/BowTarget.vue";
|
import BowTarget from "@/components/BowTarget.vue";
|
||||||
@@ -32,6 +32,8 @@ const halfTimeTip = ref(false);
|
|||||||
const halfRest = ref(false);
|
const halfRest = ref(false);
|
||||||
/** 控制设备离线提示弹窗的显示状态 */
|
/** 控制设备离线提示弹窗的显示状态 */
|
||||||
const showOfflineModal = ref(false);
|
const showOfflineModal = ref(false);
|
||||||
|
/** 记录每位玩家当前半场连续 X 环数,key 为 playerId,用于触发 tententen 音效 */
|
||||||
|
const xRingStreaks = ref({});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 监听设备在线状态,大乱斗比赛进行中设备离线时弹窗提示用户
|
* 监听设备在线状态,大乱斗比赛进行中设备离线时弹窗提示用户
|
||||||
@@ -120,6 +122,28 @@ onLoad(async (options) => {
|
|||||||
// });
|
// });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测指定玩家连续 X 环是否达到 3 箭,达到则在环数播报入队后追加 tententen 音效
|
||||||
|
* @param {number|string} playerId - 本次射手的 ID(大乱斗中 ShootResult 保留 playerId)
|
||||||
|
* @param {boolean} isXRing - 本次射击是否为 X 环
|
||||||
|
*/
|
||||||
|
function checkAndPlayTententen(playerId, isXRing) {
|
||||||
|
if (!playerId) return;
|
||||||
|
const id = parseInt(playerId);
|
||||||
|
if (isXRing) {
|
||||||
|
xRingStreaks.value[id] = (xRingStreaks.value[id] || 0) + 1;
|
||||||
|
// 同一玩家连续 3 箭均为 X 环,追加到环数音效队列尾部播放
|
||||||
|
if (xRingStreaks.value[id] >= 3) {
|
||||||
|
xRingStreaks.value[id] = 0;
|
||||||
|
// nextTick 确保 HeaderProgress 的环数播报已入队后再追加 tententen,避免播放顺序颠倒
|
||||||
|
nextTick(() => audioManager.play("tententen", false));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 非 X 环则重置该玩家的连续计数
|
||||||
|
xRingStreaks.value[id] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function onReceiveMessage(msg) {
|
async function onReceiveMessage(msg) {
|
||||||
if (Array.isArray(msg)) return;
|
if (Array.isArray(msg)) return;
|
||||||
if (msg.type === MESSAGETYPESV2.BattleStart) {
|
if (msg.type === MESSAGETYPESV2.BattleStart) {
|
||||||
@@ -127,7 +151,28 @@ async function onReceiveMessage(msg) {
|
|||||||
halfRest.value = false;
|
halfRest.value = false;
|
||||||
recoverData(msg);
|
recoverData(msg);
|
||||||
} else if (msg.type === MESSAGETYPESV2.ShootResult) {
|
} 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);
|
recoverData(msg);
|
||||||
|
// 对比更新后数据找出箭数增加的玩家(即本次射手),并读取其最新箭的 ring 数据
|
||||||
|
const newRound = playersScores.value[playersScores.value.length - 1] || {};
|
||||||
|
let shooterId = null;
|
||||||
|
let isXRing = 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];
|
||||||
|
isXRing = !!(shot?.ringX && shot?.ring);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 检测同一玩家三箭全 X 环,触发 tententen 音效
|
||||||
|
checkAndPlayTententen(shooterId, isXRing);
|
||||||
} else if (msg.type === MESSAGETYPESV2.HalfRest) {
|
} else if (msg.type === MESSAGETYPESV2.HalfRest) {
|
||||||
halfTimeTip.value = true;
|
halfTimeTip.value = true;
|
||||||
halfRest.value = true;
|
halfRest.value = true;
|
||||||
|
|||||||
@@ -49,6 +49,8 @@ const battleWay = ref(0);
|
|||||||
const lastToSomeoneShootKey = ref("");
|
const lastToSomeoneShootKey = ref("");
|
||||||
/** 控制设备离线提示弹窗的显示状态 */
|
/** 控制设备离线提示弹窗的显示状态 */
|
||||||
const showOfflineModal = ref(false);
|
const showOfflineModal = ref(false);
|
||||||
|
/** 记录每位玩家当前轮连续 X 环数,key 为 playerId,用于触发 tententen 音效 */
|
||||||
|
const xRingStreaks = ref({});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 监听设备在线状态,比赛进行中设备离线时弹窗提示用户
|
* 监听设备在线状态,比赛进行中设备离线时弹窗提示用户
|
||||||
@@ -231,6 +233,27 @@ function onNewRound(msg, prevRound) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测指定射手连续 X 环是否达到 3 箭,达到则在环数播报入队后追加 tententen 音效
|
||||||
|
* @param {number} shooterId - 本次射手的 ID(取自 currentShooterId.value)
|
||||||
|
* @param {boolean} isXRing - 本次射击是否为 X 环
|
||||||
|
*/
|
||||||
|
function checkAndPlayTententen(shooterId, isXRing) {
|
||||||
|
if (!shooterId) return;
|
||||||
|
if (isXRing) {
|
||||||
|
xRingStreaks.value[shooterId] = (xRingStreaks.value[shooterId] || 0) + 1;
|
||||||
|
// 同一玩家连续 3 箭均为 X 环,追加到环数音效队列尾部播放
|
||||||
|
if (xRingStreaks.value[shooterId] >= 3) {
|
||||||
|
xRingStreaks.value[shooterId] = 0;
|
||||||
|
// nextTick 确保 HeaderProgress 的环数播报已入队后再追加 tententen,避免播放顺序颠倒
|
||||||
|
nextTick(() => audioManager.play("tententen", false));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 非 X 环则重置该玩家的连续计数
|
||||||
|
xRingStreaks.value[shooterId] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function onReceiveMessage(msg) {
|
async function onReceiveMessage(msg) {
|
||||||
if (Array.isArray(msg)) return;
|
if (Array.isArray(msg)) return;
|
||||||
if (msg.type === MESSAGETYPESV2.BattleStart) {
|
if (msg.type === MESSAGETYPESV2.BattleStart) {
|
||||||
@@ -245,6 +268,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 音效
|
||||||
|
// currentShooterId 在 ToSomeoneShoot 时写入,ShootResult 不会覆盖,可靠识别本次射手
|
||||||
|
checkAndPlayTententen(currentShooterId.value, !!(msg.shootData?.ringX && msg.shootData?.ring));
|
||||||
} 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;
|
||||||
|
|||||||
Reference in New Issue
Block a user