新版房间1v1对战数据调试完成
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<script setup>
|
||||
import { ref, watch, onMounted, onBeforeUnmount } from "vue";
|
||||
import audioManager from "@/audioManager";
|
||||
import { MESSAGETYPES } from "@/constants";
|
||||
import { MESSAGETYPES, MESSAGETYPESV2 } from "@/constants";
|
||||
import { getDirectionText } from "@/util";
|
||||
|
||||
import useStore from "@/store";
|
||||
@@ -26,9 +26,8 @@ watch(
|
||||
let key = [];
|
||||
if (newVal.includes("重回")) return;
|
||||
if (currentRoundEnded.value) {
|
||||
currentRound.value += 1;
|
||||
// 播放当前轮次语音
|
||||
key.push(`第${["一", "二", "三", "四", "五"][currentRound.value - 1]}轮`);
|
||||
key.push(`第${["一", "二", "三", "四", "五"][currentRound.value]}轮`);
|
||||
}
|
||||
key.push(
|
||||
newVal.includes("你")
|
||||
@@ -47,80 +46,112 @@ const updateSound = () => {
|
||||
audioManager.setMuted(!sound.value);
|
||||
};
|
||||
|
||||
async function onReceiveMessage(messages = []) {
|
||||
async function onReceiveMessage(message) {
|
||||
if (ended.value) return;
|
||||
messages.forEach((msg) => {
|
||||
if (msg.constructor === MESSAGETYPES.ShootResult) {
|
||||
if (melee.value && msg.userId !== user.value.id) return;
|
||||
if (msg.userId === user.value.id) currentShot.value++;
|
||||
if (msg.battleInfo && msg.userId === user.value.id) {
|
||||
const players = [
|
||||
...(msg.battleInfo.blueTeam || []),
|
||||
...(msg.battleInfo.redTeam || []),
|
||||
];
|
||||
const currentPlayer = players.find((p) => p.id === msg.userId);
|
||||
currentShot.value = 0;
|
||||
try {
|
||||
if (
|
||||
currentPlayer &&
|
||||
currentPlayer.shotHistory &&
|
||||
currentPlayer.shotHistory[msg.battleInfo.currentRound]
|
||||
) {
|
||||
currentShot.value =
|
||||
currentPlayer.shotHistory[msg.battleInfo.currentRound].length;
|
||||
}
|
||||
} catch (_) {}
|
||||
}
|
||||
if (!halfTime.value && msg.target) {
|
||||
let key = [];
|
||||
key.push(msg.target.ring ? `${msg.target.ring}环` : "未上靶");
|
||||
if (!msg.target.ring)
|
||||
key.push(`向${getDirectionText(msg.target.angle)}调整`);
|
||||
audioManager.play(key);
|
||||
}
|
||||
} else if (msg.constructor === MESSAGETYPES.InvalidShot) {
|
||||
if (msg.userId === user.value.id) {
|
||||
uni.showToast({
|
||||
title: "距离不足,无效",
|
||||
icon: "none",
|
||||
});
|
||||
audioManager.play("射击无效");
|
||||
}
|
||||
} else if (msg.constructor === MESSAGETYPES.AllReady) {
|
||||
const { config } = msg.groupUserStatus;
|
||||
if (config && config.mode === 1) {
|
||||
totalShot.value = config.teamSize === 2 ? 3 : 2;
|
||||
}
|
||||
currentRoundEnded.value = true;
|
||||
audioManager.play("比赛开始");
|
||||
} else if (msg.constructor === MESSAGETYPES.MeleeAllReady) {
|
||||
melee.value = true;
|
||||
halfTime.value = false;
|
||||
audioManager.play("比赛开始");
|
||||
} else if (msg.constructor === MESSAGETYPES.CurrentRoundEnded) {
|
||||
currentShot.value = 0;
|
||||
if (msg.preRoundResult && msg.preRoundResult.currentRound) {
|
||||
currentRound.value = msg.preRoundResult.currentRound;
|
||||
currentRoundEnded.value = true;
|
||||
}
|
||||
} else if (msg.constructor === MESSAGETYPES.HalfTimeOver) {
|
||||
halfTime.value = true;
|
||||
audioManager.play("中场休息");
|
||||
} else if (msg.constructor === MESSAGETYPES.MatchOver) {
|
||||
audioManager.play("比赛结束");
|
||||
} else if (msg.constructor === MESSAGETYPES.FinalShoot) {
|
||||
totalShot.value = 0;
|
||||
audioManager.play("决金箭轮");
|
||||
tips.value = "即将开始...";
|
||||
currentRoundEnded.value = false;
|
||||
} else if (msg.constructor === MESSAGETYPES.MatchOver) {
|
||||
ended.value = true;
|
||||
} else if (msg.constructor === MESSAGETYPES.BackToGame) {
|
||||
if (msg.battleInfo) {
|
||||
melee.value = msg.battleInfo.config.mode === 2;
|
||||
}
|
||||
if (Array.isArray(message)) {
|
||||
message.forEach((msg) => {
|
||||
// if (msg.constructor === MESSAGETYPES.ShootResult) {
|
||||
// if (melee.value && msg.userId !== user.value.id) return;
|
||||
// if (msg.userId === user.value.id) currentShot.value++;
|
||||
// if (msg.battleInfo && msg.userId === user.value.id) {
|
||||
// const players = [
|
||||
// ...(msg.battleInfo.blueTeam || []),
|
||||
// ...(msg.battleInfo.redTeam || []),
|
||||
// ];
|
||||
// const currentPlayer = players.find((p) => p.id === msg.userId);
|
||||
// currentShot.value = 0;
|
||||
// try {
|
||||
// if (
|
||||
// currentPlayer &&
|
||||
// currentPlayer.shotHistory &&
|
||||
// currentPlayer.shotHistory[msg.battleInfo.currentRound]
|
||||
// ) {
|
||||
// currentShot.value =
|
||||
// currentPlayer.shotHistory[msg.battleInfo.currentRound].length;
|
||||
// }
|
||||
// } catch (_) {}
|
||||
// }
|
||||
// if (!halfTime.value && msg.target) {
|
||||
// let key = [];
|
||||
// key.push(msg.target.ring ? `${msg.target.ring}环` : "未上靶");
|
||||
// if (!msg.target.ring)
|
||||
// key.push(`向${getDirectionText(msg.target.angle)}调整`);
|
||||
// audioManager.play(key);
|
||||
// }
|
||||
// } else
|
||||
// if (msg.constructor === MESSAGETYPES.InvalidShot) {
|
||||
// if (msg.userId === user.value.id) {
|
||||
// uni.showToast({
|
||||
// title: "距离不足,无效",
|
||||
// icon: "none",
|
||||
// });
|
||||
// audioManager.play("射击无效");
|
||||
// }
|
||||
// }
|
||||
// else if (msg.constructor === MESSAGETYPES.AllReady) {
|
||||
// const { config } = msg.groupUserStatus;
|
||||
// if (config && config.mode === 1) {
|
||||
// totalShot.value = config.teamSize === 2 ? 3 : 2;
|
||||
// }
|
||||
// currentRoundEnded.value = true;
|
||||
// audioManager.play("比赛开始");
|
||||
// } else if (msg.constructor === MESSAGETYPES.MeleeAllReady) {
|
||||
// melee.value = true;
|
||||
// halfTime.value = false;
|
||||
// audioManager.play("比赛开始");
|
||||
// } else if (msg.constructor === MESSAGETYPES.CurrentRoundEnded) {
|
||||
// currentShot.value = 0;
|
||||
// if (msg.preRoundResult && msg.preRoundResult.currentRound) {
|
||||
// currentRound.value = msg.preRoundResult.currentRound;
|
||||
// currentRoundEnded.value = true;
|
||||
// }
|
||||
// } else if (msg.constructor === MESSAGETYPES.HalfTimeOver) {
|
||||
// halfTime.value = true;
|
||||
// audioManager.play("中场休息");
|
||||
// } else if (msg.constructor === MESSAGETYPES.MatchOver) {
|
||||
// audioManager.play("比赛结束");
|
||||
// } else if (msg.constructor === MESSAGETYPES.FinalShoot) {
|
||||
// totalShot.value = 0;
|
||||
// audioManager.play("决金箭轮");
|
||||
// tips.value = "即将开始...";
|
||||
// currentRoundEnded.value = false;
|
||||
// } else if (msg.constructor === MESSAGETYPES.MatchOver) {
|
||||
// ended.value = true;
|
||||
// } else if (msg.constructor === MESSAGETYPES.BackToGame) {
|
||||
// if (msg.battleInfo) {
|
||||
// melee.value = msg.battleInfo.config.mode === 2;
|
||||
// }
|
||||
// }
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (message.type === MESSAGETYPESV2.BattleStart) {
|
||||
melee.value = Boolean(message.mode);
|
||||
totalShot.value = message.mode === 1 ? 3 : 2;
|
||||
currentRoundEnded.value = true;
|
||||
audioManager.play("比赛开始");
|
||||
}
|
||||
if (message.type === MESSAGETYPESV2.BattleEnd) {
|
||||
audioManager.play("比赛结束");
|
||||
}
|
||||
if (message.type === MESSAGETYPESV2.ShootResult) {
|
||||
if (melee.value && message.current.playerId !== user.value.id) return;
|
||||
if (message.current.playerId === user.value.id) currentShot.value++;
|
||||
if (message.shootData) {
|
||||
let key = [];
|
||||
key.push(
|
||||
message.shootData.ring ? `${message.shootData.ring}环` : "未上靶"
|
||||
);
|
||||
if (!message.shootData.ring)
|
||||
key.push(`向${getDirectionText(message.shootData.angle)}调整`);
|
||||
audioManager.play(key, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (message.type === MESSAGETYPESV2.NewRound) {
|
||||
currentShot.value = 0;
|
||||
currentRound.value = message.current.round;
|
||||
currentRoundEnded.value = true;
|
||||
}
|
||||
}
|
||||
|
||||
const playSound = (key) => {
|
||||
|
||||
Reference in New Issue
Block a user