2025-05-16 15:56:54 +08:00
|
|
|
<script setup>
|
2025-06-05 21:32:51 +08:00
|
|
|
import { ref, onMounted, onUnmounted } from "vue";
|
|
|
|
|
import { onLoad } from "@dcloudio/uni-app";
|
|
|
|
|
import Container from "@/components/Container.vue";
|
2025-06-08 20:59:41 +08:00
|
|
|
import BattleHeader from "@/components/BattleHeader.vue";
|
|
|
|
|
import Guide from "@/components/Guide.vue";
|
2025-05-16 15:56:54 +08:00
|
|
|
import BowTarget from "@/components/BowTarget.vue";
|
|
|
|
|
import ShootProgress from "@/components/ShootProgress.vue";
|
|
|
|
|
import PlayersRow from "@/components/PlayersRow.vue";
|
2025-06-05 21:32:51 +08:00
|
|
|
import Timer from "@/components/Timer.vue";
|
2025-06-06 00:34:54 +08:00
|
|
|
import BattleFooter from "@/components/BattleFooter.vue";
|
2025-06-19 21:03:33 +08:00
|
|
|
import ScreenHint from "@/components/ScreenHint.vue";
|
2025-06-05 21:32:51 +08:00
|
|
|
import SButton from "@/components/SButton.vue";
|
2025-06-25 21:54:18 +08:00
|
|
|
import Matching from "@/components/Matching.vue";
|
2025-07-02 15:57:58 +08:00
|
|
|
import RoundEndTip from "@/components/RoundEndTip.vue";
|
2025-07-05 14:52:41 +08:00
|
|
|
import TestDistance from "@/components/TestDistance.vue";
|
2025-06-05 21:32:51 +08:00
|
|
|
import { matchGameAPI, readyGameAPI } from "@/apis";
|
2025-06-17 16:02:29 +08:00
|
|
|
import { MESSAGETYPES, roundsName, getMessageTypeName } from "@/constants";
|
2025-06-08 20:59:41 +08:00
|
|
|
import useStore from "@/store";
|
|
|
|
|
import { storeToRefs } from "pinia";
|
|
|
|
|
const store = useStore();
|
|
|
|
|
const { user } = storeToRefs(store);
|
2025-06-05 21:32:51 +08:00
|
|
|
const gameType = ref(0);
|
|
|
|
|
const teamSize = ref(0);
|
|
|
|
|
const start = ref(false);
|
|
|
|
|
const battleId = ref("");
|
|
|
|
|
const currentRound = ref(1);
|
2025-06-19 21:03:33 +08:00
|
|
|
const currentRedPoint = ref(0);
|
|
|
|
|
const currentBluePoint = ref(0);
|
2025-06-05 21:32:51 +08:00
|
|
|
const totalRounds = ref(0);
|
|
|
|
|
const power = ref(0);
|
|
|
|
|
const scores = ref([]);
|
2025-06-26 01:27:23 +08:00
|
|
|
const blueScores = ref([]);
|
2025-06-05 21:32:51 +08:00
|
|
|
const redTeam = ref([]);
|
|
|
|
|
const blueTeam = ref([]);
|
|
|
|
|
const currentShooterId = ref(0);
|
|
|
|
|
const tips = ref("即将开始...");
|
|
|
|
|
const seq = ref(0);
|
|
|
|
|
const timerSeq = ref(0);
|
2025-06-25 21:54:18 +08:00
|
|
|
const roundResults = ref([]);
|
2025-06-08 20:59:41 +08:00
|
|
|
const redPoints = ref(0);
|
|
|
|
|
const bluePoints = ref(0);
|
2025-06-19 21:03:33 +08:00
|
|
|
const showRoundTip = ref(false);
|
2025-06-25 21:54:18 +08:00
|
|
|
const onComplete = ref(null);
|
2025-07-06 00:42:10 +08:00
|
|
|
const isFinalShoot = ref(false);
|
2025-06-05 21:32:51 +08:00
|
|
|
|
2025-06-25 21:54:18 +08:00
|
|
|
onLoad(async (options) => {
|
2025-07-05 17:24:52 +08:00
|
|
|
if (options.battleId) {
|
2025-07-15 18:14:59 +08:00
|
|
|
const battleInfo = uni.getStorageSync("current-battle");
|
2025-07-13 21:06:48 +08:00
|
|
|
// console.log("----battleInfo", battleInfo);
|
2025-07-05 17:24:52 +08:00
|
|
|
if (battleInfo) {
|
|
|
|
|
battleId.value = battleInfo.id;
|
|
|
|
|
start.value = true;
|
|
|
|
|
redTeam.value = battleInfo.redTeam;
|
|
|
|
|
blueTeam.value = battleInfo.blueTeam;
|
|
|
|
|
currentRound.value = battleInfo.currentRound;
|
|
|
|
|
bluePoints.value = battleInfo.blueScore;
|
|
|
|
|
redPoints.value = battleInfo.redScore;
|
|
|
|
|
totalRounds.value = battleInfo.maxRound;
|
|
|
|
|
roundResults.value = battleInfo.roundResults;
|
2025-07-16 12:09:27 +08:00
|
|
|
setTimeout(() => {
|
|
|
|
|
if (battleInfo.roundResults[battleInfo.roundResults.length - 1]) {
|
|
|
|
|
scores.value =
|
|
|
|
|
battleInfo.roundResults[
|
|
|
|
|
battleInfo.roundResults.length - 1
|
|
|
|
|
].redArrows;
|
|
|
|
|
blueScores.value =
|
|
|
|
|
battleInfo.roundResults[
|
|
|
|
|
battleInfo.roundResults.length - 1
|
|
|
|
|
].blueArrows;
|
|
|
|
|
}
|
|
|
|
|
}, 300);
|
2025-07-13 21:06:48 +08:00
|
|
|
if (
|
|
|
|
|
battleInfo.redTeam[0].shotHistory[battleInfo.currentRound] ||
|
|
|
|
|
battleInfo.blueTeam[0].shotHistory[battleInfo.currentRound]
|
|
|
|
|
) {
|
|
|
|
|
roundResults.value.push({
|
|
|
|
|
redArrows: battleInfo.redTeam[0].shotHistory[battleInfo.currentRound],
|
|
|
|
|
blueArrows:
|
|
|
|
|
battleInfo.blueTeam[0].shotHistory[battleInfo.currentRound],
|
|
|
|
|
});
|
|
|
|
|
} else if (battleInfo.currentRound < 5) {
|
|
|
|
|
roundResults.value.push({
|
|
|
|
|
redArrows: [],
|
|
|
|
|
blueArrows: [],
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-07-05 17:24:52 +08:00
|
|
|
if (battleInfo.firePlayerIndex) {
|
|
|
|
|
currentShooterId.value = battleInfo.firePlayerIndex;
|
|
|
|
|
if (redTeam.value[0].id === currentShooterId.value) {
|
|
|
|
|
tips.value = `请红队射箭-第${roundsName[currentRound.value]}轮`;
|
|
|
|
|
} else {
|
|
|
|
|
tips.value = `请蓝队射箭-第${roundsName[currentRound.value]}轮`;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const remain = Date.now() / 1000 - battleInfo.fireTime;
|
|
|
|
|
if (remain > 0 && remain <= 15) {
|
|
|
|
|
// 等渲染好再通知
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
uni.$emit("update-ramain", remain);
|
|
|
|
|
}, 300);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
gameType.value = options.gameType;
|
|
|
|
|
teamSize.value = options.teamSize;
|
|
|
|
|
if (gameType.value && teamSize.value) {
|
|
|
|
|
await matchGameAPI(true, gameType.value, teamSize.value);
|
|
|
|
|
}
|
2025-06-05 21:32:51 +08:00
|
|
|
}
|
2025-06-25 21:54:18 +08:00
|
|
|
});
|
2025-06-05 21:32:51 +08:00
|
|
|
async function stopMatch() {
|
2025-07-13 14:57:16 +08:00
|
|
|
uni.$showHint(3);
|
2025-06-05 21:32:51 +08:00
|
|
|
}
|
|
|
|
|
async function readyToGo() {
|
|
|
|
|
if (battleId.value) {
|
|
|
|
|
await readyGameAPI(battleId.value);
|
|
|
|
|
start.value = true;
|
|
|
|
|
timerSeq.value = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-19 21:03:33 +08:00
|
|
|
async function onReceiveMessage(messages = []) {
|
2025-06-05 21:32:51 +08:00
|
|
|
messages.forEach((msg) => {
|
|
|
|
|
if (
|
|
|
|
|
!msg.id ||
|
|
|
|
|
(battleId.value && msg.id === battleId.value) ||
|
|
|
|
|
msg.constructor === MESSAGETYPES.WaitForAllReady
|
|
|
|
|
) {
|
2025-06-17 16:02:29 +08:00
|
|
|
console.log("收到消息:", getMessageTypeName(msg.constructor), msg);
|
2025-06-05 21:32:51 +08:00
|
|
|
}
|
|
|
|
|
if (msg.constructor === MESSAGETYPES.WaitForAllReady) {
|
|
|
|
|
// 这里会掉多次;
|
2025-06-25 21:54:18 +08:00
|
|
|
onComplete.value = () => {
|
|
|
|
|
timerSeq.value += 1;
|
|
|
|
|
battleId.value = msg.id;
|
|
|
|
|
redTeam.value = msg.groupUserStatus.redTeam;
|
|
|
|
|
blueTeam.value = msg.groupUserStatus.blueTeam;
|
2025-07-14 13:39:10 +08:00
|
|
|
uni.$hideHint();
|
2025-06-25 21:54:18 +08:00
|
|
|
};
|
2025-06-05 21:32:51 +08:00
|
|
|
}
|
|
|
|
|
if (msg.id !== battleId.value) return;
|
|
|
|
|
if (msg.constructor === MESSAGETYPES.AllReady) {
|
|
|
|
|
start.value = true;
|
|
|
|
|
timerSeq.value = 0;
|
2025-06-08 20:59:41 +08:00
|
|
|
scores.value = [];
|
2025-06-13 14:05:30 +08:00
|
|
|
totalRounds.value = msg.groupUserStatus.config.maxRounds;
|
2025-07-11 22:21:34 +08:00
|
|
|
roundResults.value.push({
|
|
|
|
|
redArrows: [],
|
|
|
|
|
blueArrows: [],
|
|
|
|
|
});
|
2025-06-05 21:32:51 +08:00
|
|
|
}
|
|
|
|
|
if (msg.constructor === MESSAGETYPES.ToSomeoneShoot) {
|
2025-06-28 12:03:33 +08:00
|
|
|
if (currentShooterId.value !== msg.userId) {
|
|
|
|
|
seq.value += 1;
|
|
|
|
|
currentShooterId.value = msg.userId;
|
|
|
|
|
if (redTeam.value[0].id === currentShooterId.value) {
|
2025-07-06 00:42:10 +08:00
|
|
|
tips.value = "请红队射箭-";
|
2025-06-28 12:03:33 +08:00
|
|
|
} else {
|
2025-07-06 00:42:10 +08:00
|
|
|
tips.value = "请蓝队射箭-";
|
|
|
|
|
}
|
|
|
|
|
if (isFinalShoot.value) {
|
|
|
|
|
tips.value += "决金箭";
|
|
|
|
|
} else {
|
|
|
|
|
tips.value += `第${roundsName[currentRound.value]}轮`;
|
2025-06-28 12:03:33 +08:00
|
|
|
}
|
2025-06-05 21:32:51 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (msg.constructor === MESSAGETYPES.ShootResult) {
|
2025-06-26 01:27:23 +08:00
|
|
|
const isRed = redTeam.value.find((item) => item.id === msg.userId);
|
2025-07-16 09:33:33 +08:00
|
|
|
if (isRed) scores.value.push(msg.target);
|
|
|
|
|
else blueScores.value.push(msg.target);
|
2025-07-11 12:03:55 +08:00
|
|
|
if (roundResults.value[currentRound.value - 1]) {
|
|
|
|
|
if (isRed && roundResults.value[currentRound.value - 1].redArrows) {
|
|
|
|
|
roundResults.value[currentRound.value - 1].redArrows.push(msg.target);
|
|
|
|
|
}
|
|
|
|
|
if (!isRed && roundResults.value[currentRound.value - 1].blueArrows) {
|
|
|
|
|
roundResults.value[currentRound.value - 1].blueArrows.push(
|
|
|
|
|
msg.target
|
|
|
|
|
);
|
|
|
|
|
}
|
2025-07-13 14:57:16 +08:00
|
|
|
} else {
|
|
|
|
|
roundResults.value.push({
|
|
|
|
|
redArrows: [],
|
|
|
|
|
blueArrows: [],
|
|
|
|
|
});
|
2025-07-11 12:03:55 +08:00
|
|
|
}
|
2025-06-05 21:32:51 +08:00
|
|
|
}
|
|
|
|
|
if (msg.constructor === MESSAGETYPES.CurrentRoundEnded) {
|
2025-06-06 00:34:54 +08:00
|
|
|
const result = msg.preRoundResult;
|
2025-06-05 21:32:51 +08:00
|
|
|
scores.value = [];
|
2025-06-26 22:54:17 +08:00
|
|
|
blueScores.value = [];
|
2025-06-05 21:32:51 +08:00
|
|
|
currentShooterId.value = 0;
|
2025-06-19 21:03:33 +08:00
|
|
|
currentBluePoint.value = result.blueScore;
|
|
|
|
|
currentRedPoint.value = result.redScore;
|
2025-06-26 01:27:23 +08:00
|
|
|
bluePoints.value += result.blueScore;
|
|
|
|
|
redPoints.value += result.redScore;
|
2025-07-11 12:03:55 +08:00
|
|
|
// roundResults.value = result.roundResults;
|
2025-06-19 21:03:33 +08:00
|
|
|
currentRound.value = result.currentRound + 1;
|
2025-07-11 22:21:34 +08:00
|
|
|
if (result.currentRound < 5) {
|
|
|
|
|
roundResults.value.push({
|
|
|
|
|
redArrows: [],
|
|
|
|
|
blueArrows: [],
|
|
|
|
|
});
|
|
|
|
|
showRoundTip.value = true;
|
|
|
|
|
}
|
2025-07-06 00:42:10 +08:00
|
|
|
}
|
|
|
|
|
if (msg.constructor === MESSAGETYPES.FinalShoot) {
|
2025-07-10 19:55:30 +08:00
|
|
|
if (!isFinalShoot.value) {
|
|
|
|
|
isFinalShoot.value = true;
|
|
|
|
|
showRoundTip.value = true;
|
|
|
|
|
tips.value = "准备开始决金箭";
|
|
|
|
|
}
|
2025-06-05 21:32:51 +08:00
|
|
|
}
|
|
|
|
|
if (msg.constructor === MESSAGETYPES.MatchOver) {
|
2025-07-15 18:14:59 +08:00
|
|
|
uni.setStorageSync("last-battle", msg.endStatus);
|
2025-07-16 16:09:10 +08:00
|
|
|
if (msg.endStatus.nosaved) {
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: "游戏结束",
|
|
|
|
|
icon: "none",
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
uni.redirectTo({
|
|
|
|
|
url: `/pages/battle-result?battleId=${msg.id}`,
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-06-05 21:32:51 +08:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-07-01 00:25:17 +08:00
|
|
|
const onBack = () => {
|
|
|
|
|
if (battleId.value) {
|
2025-07-11 00:47:34 +08:00
|
|
|
uni.$showHint(2);
|
2025-07-01 00:25:17 +08:00
|
|
|
} else {
|
2025-07-11 01:00:54 +08:00
|
|
|
uni.$showHint(3);
|
2025-07-01 00:25:17 +08:00
|
|
|
}
|
|
|
|
|
};
|
2025-06-05 21:32:51 +08:00
|
|
|
onMounted(() => {
|
2025-07-13 11:21:19 +08:00
|
|
|
uni.setKeepScreenOn({
|
|
|
|
|
keepScreenOn: true,
|
|
|
|
|
});
|
2025-06-05 21:32:51 +08:00
|
|
|
uni.$on("socket-inbox", onReceiveMessage);
|
|
|
|
|
});
|
|
|
|
|
onUnmounted(() => {
|
2025-07-13 11:21:19 +08:00
|
|
|
uni.setKeepScreenOn({
|
|
|
|
|
keepScreenOn: false,
|
|
|
|
|
});
|
2025-06-05 21:32:51 +08:00
|
|
|
uni.$off("socket-inbox", onReceiveMessage);
|
2025-07-01 00:25:17 +08:00
|
|
|
if (gameType.value && teamSize.value && !battleId.value) {
|
|
|
|
|
matchGameAPI(false, gameType.value, teamSize.value);
|
2025-06-05 21:32:51 +08:00
|
|
|
}
|
|
|
|
|
});
|
2025-05-16 15:56:54 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
2025-07-01 00:25:17 +08:00
|
|
|
<Container
|
|
|
|
|
:title="battleId ? '1V1排位赛' : '搜索对手...'"
|
|
|
|
|
:bgType="1"
|
|
|
|
|
:onBack="onBack"
|
|
|
|
|
>
|
2025-06-05 21:32:51 +08:00
|
|
|
<view class="container">
|
2025-06-25 21:54:18 +08:00
|
|
|
<block v-if="battleId">
|
|
|
|
|
<BattleHeader
|
|
|
|
|
v-if="!start && redTeam.length && blueTeam.length"
|
|
|
|
|
:redTeam="redTeam"
|
|
|
|
|
:blueTeam="blueTeam"
|
|
|
|
|
/>
|
2025-07-05 14:52:41 +08:00
|
|
|
<TestDistance v-if="!start" :guide="false" />
|
2025-07-14 22:39:53 +08:00
|
|
|
<ShootProgress
|
|
|
|
|
v-if="start"
|
|
|
|
|
:tips="tips"
|
|
|
|
|
:seq="seq"
|
|
|
|
|
:total="15"
|
|
|
|
|
:currentRound="currentRound"
|
|
|
|
|
:battleId="battleId"
|
|
|
|
|
/>
|
2025-06-25 21:54:18 +08:00
|
|
|
<PlayersRow
|
|
|
|
|
v-if="start"
|
|
|
|
|
:currentShooterId="currentShooterId"
|
|
|
|
|
:blueTeam="blueTeam"
|
|
|
|
|
:redTeam="redTeam"
|
|
|
|
|
/>
|
|
|
|
|
<BowTarget
|
2025-07-05 14:52:41 +08:00
|
|
|
v-if="start"
|
2025-06-26 01:27:23 +08:00
|
|
|
mode="team"
|
2025-06-25 21:54:18 +08:00
|
|
|
:power="start ? power : 0"
|
|
|
|
|
:currentRound="currentRound"
|
|
|
|
|
:totalRound="totalRounds"
|
|
|
|
|
:scores="scores"
|
2025-06-26 01:27:23 +08:00
|
|
|
:blueScores="blueScores"
|
2025-06-25 21:54:18 +08:00
|
|
|
/>
|
|
|
|
|
<BattleFooter
|
|
|
|
|
v-if="start"
|
|
|
|
|
:roundResults="roundResults"
|
|
|
|
|
:redPoints="redPoints"
|
|
|
|
|
:bluePoints="bluePoints"
|
|
|
|
|
/>
|
|
|
|
|
<Timer :seq="timerSeq" :callBack="readyToGo" />
|
|
|
|
|
<ScreenHint
|
|
|
|
|
:show="showRoundTip"
|
|
|
|
|
:onClose="() => (showRoundTip = false)"
|
2025-07-06 00:42:10 +08:00
|
|
|
:mode="isFinalShoot ? 'tall' : 'normal'"
|
2025-06-25 21:54:18 +08:00
|
|
|
>
|
2025-07-02 15:57:58 +08:00
|
|
|
<RoundEndTip
|
2025-07-06 00:42:10 +08:00
|
|
|
:isFinal="isFinalShoot"
|
2025-07-02 15:57:58 +08:00
|
|
|
:round="currentRound - 1"
|
|
|
|
|
:bluePoint="currentBluePoint"
|
|
|
|
|
:redPoint="currentRedPoint"
|
2025-07-13 14:57:16 +08:00
|
|
|
:roundData="
|
|
|
|
|
roundResults[roundResults.length - 2]
|
|
|
|
|
? roundResults[roundResults.length - 2]
|
|
|
|
|
: []
|
|
|
|
|
"
|
2025-07-06 00:42:10 +08:00
|
|
|
:onAutoClose="() => (showRoundTip = false)"
|
2025-07-02 15:57:58 +08:00
|
|
|
/>
|
2025-06-25 21:54:18 +08:00
|
|
|
</ScreenHint>
|
|
|
|
|
</block>
|
|
|
|
|
<block v-else>
|
|
|
|
|
<Matching
|
|
|
|
|
v-if="!battleId"
|
|
|
|
|
:stopMatch="stopMatch"
|
|
|
|
|
:onComplete="onComplete"
|
|
|
|
|
/>
|
|
|
|
|
</block>
|
2025-06-05 21:32:51 +08:00
|
|
|
</view>
|
2025-06-18 21:30:54 +08:00
|
|
|
<view :style="{ marginBottom: '20px' }">
|
2025-06-15 15:53:57 +08:00
|
|
|
<SButton v-if="battleId && !start" :onClick="readyToGo">准备完毕</SButton>
|
|
|
|
|
</view>
|
2025-06-05 21:32:51 +08:00
|
|
|
</Container>
|
2025-05-16 15:56:54 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
.container {
|
|
|
|
|
width: 100%;
|
2025-06-25 21:54:18 +08:00
|
|
|
height: 100%;
|
2025-05-16 15:56:54 +08:00
|
|
|
}
|
|
|
|
|
</style>
|