新版房间1v1对战数据调试完成

This commit is contained in:
kron
2026-02-04 17:45:57 +08:00
parent a2674aae5b
commit 7f73f3ebb3
18 changed files with 524 additions and 843 deletions

View File

@@ -2,7 +2,7 @@
import { ref, watch, onMounted, onBeforeUnmount } from "vue";
import { onShow } from "@dcloudio/uni-app";
import { getCurrentGameAPI, getUserGameState } from "@/apis";
import { getBattleAPI, getUserGameState } from "@/apis";
import { debounce } from "@/util";
import useStore from "@/store";
@@ -44,10 +44,21 @@ const onClick = debounce(async () => {
if (loading.value) return;
try {
loading.value = true;
if (game.value.inBattle) {
await uni.$checkAudio();
const result = await getCurrentGameAPI();
} else if (game.value.roomID) {
const result = await getBattleAPI();
if (result && result.matchId) {
// await uni.$checkAudio();
if (result.way === 1) {
uni.navigateTo({
url: `/pages/team-battle?battleId=${result.matchId}`,
});
} else if (result.way === 2) {
uni.navigateTo({
url: `/pages/melee-match?battleId=${result.matchId}`,
});
}
return;
}
if (game.value.roomID) {
uni.navigateTo({
url: "/pages/battle-room?roomNumber=" + game.value.roomID,
});

View File

@@ -22,9 +22,10 @@ const props = defineProps({
},
});
const normalRounds = computed(
() => props.roundResults.length - props.goldenRound
);
const normalRounds = computed(() => {
const count = props.roundResults.findIndex((item) => !!item.ifGold);
return count > 0 ? count : props.roundResults.length;
});
</script>
<template>
@@ -59,8 +60,8 @@ const normalRounds = computed(
</block>
<view>
<text>{{
result.blueArrows.length
? result.blueArrows
result.shoots[1] && result.shoots[1].length
? result.shoots[1]
.map((item) => item.ring)
.reduce((last, next) => last + next, 0)
: ""
@@ -94,8 +95,8 @@ const normalRounds = computed(
</block>
<view>
<text>{{
result.redArrows.length
? result.redArrows
result.shoots[2] && result.shoots[2].length
? result.shoots[2]
.map((item) => item.ring)
.reduce((last, next) => last + next, 0)
: ""

View File

@@ -2,7 +2,7 @@
import { ref, watch, onMounted, onBeforeUnmount, computed } from "vue";
import PointSwitcher from "@/components/PointSwitcher.vue";
import { MESSAGETYPES } from "@/constants";
import { MESSAGETYPES, MESSAGETYPESV2 } from "@/constants";
import { simulShootAPI } from "@/apis";
import useStore from "@/store";
import { storeToRefs } from "pinia";
@@ -108,28 +108,26 @@ const arrowStyle = computed(() => {
};
});
async function onReceiveMessage(messages = []) {
messages.forEach((msg) => {
async function onReceiveMessage(message) {
if (Array.isArray(message)) return;
if (message.type === MESSAGETYPESV2.ShootResult && message.shootData) {
if (
msg.constructor === MESSAGETYPES.ShootSyncMeArrowID ||
msg.constructor === MESSAGETYPES.ShootResult
message.shootData.playerId === user.value.id &&
!message.shootData.ring &&
message.shootData.angle >= 0
) {
if (
msg.userId === user.value.id &&
!msg.target.ring &&
msg.target.angle >= 0
) {
angle.value = null;
setTimeout(() => {
if (props.scores[0]) {
circleColor.value =
msg.userId === props.scores[0].playerId ? "#ff4444" : "#1840FF";
}
angle.value = msg.target.angle;
}, 200);
}
angle.value = null;
setTimeout(() => {
if (props.scores[0]) {
circleColor.value =
message.shootData.playerId === props.scores[0].playerId
? "#ff4444"
: "#1840FF";
}
angle.value = message.shootData.angle;
}, 200);
}
});
}
}
onMounted(() => {

View File

@@ -32,18 +32,21 @@ const createRoom = debounce(async () => {
if (battleMode.value === 2) size = 10;
if (battleMode.value === 3) size = 4;
if (battleMode.value === 4) size = 6;
const result = await createRoomAPI(
battleMode.value === 2 ? 2 : 1,
battleMode.value === 2 ? 10 : size
);
if (result.number) {
props.onConfirm();
await joinRoomAPI(result.number);
uni.navigateTo({
url: "/pages/battle-room?roomNumber=" + result.number,
});
try {
const result = await createRoomAPI(
battleMode.value === 2 ? 2 : 1,
battleMode.value === 2 ? 10 : size
);
if (result.number) {
props.onConfirm();
await joinRoomAPI(result.number);
uni.navigateTo({
url: "/pages/battle-room?roomNumber=" + result.number,
});
}
} finally {
loading.value = false;
}
loading.value = false;
});
</script>
<template>

View File

@@ -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) => {

View File

@@ -52,14 +52,14 @@ onBeforeUnmount(() => {
<view class="point-view1" v-if="bluePoint !== 0 || redPoint !== 0">
<text>本轮蓝队</text>
<text>{{
(roundData.blueArrows || []).reduce(
(roundData.shoots[1] || []).reduce(
(last, next) => last + next.ring,
0
)
}}</text>
<text>红队</text>
<text>{{
(roundData.redArrows || []).reduce(
(roundData.shoots[2] || []).reduce(
(last, next) => last + next.ring,
0
)

View File

@@ -179,13 +179,13 @@ const playSound = (key) => {
};
onMounted(() => {
uni.$on("update-ramain", resetTimer);
uni.$on("update-remain", resetTimer);
uni.$on("socket-inbox", onReceiveMessage);
uni.$on("play-sound", playSound);
});
onBeforeUnmount(() => {
uni.$off("update-ramain", resetTimer);
uni.$off("update-remain", resetTimer);
uni.$off("socket-inbox", onReceiveMessage);
uni.$off("play-sound", playSound);
if (timer.value) clearInterval(timer.value);

View File

@@ -19,6 +19,18 @@ const props = defineProps({
const barColor = ref("");
const remain = ref(15);
const timer = ref(null);
const laoding = ref(false);
const updateRemain = (value) => {
// if (Math.ceil(value) === remain.value || Math.floor(value) === remain.value)
// return;
if (timer.value) clearInterval(timer.value);
remain.value = Math.round(value);
timer.value = setInterval(() => {
laoding.value = remain.value === 0;
if (remain.value > 0) remain.value--;
}, 1000);
};
watch(
() => props.tips,
@@ -29,11 +41,7 @@ watch(
barColor.value = "linear-gradient( 180deg, #9AB3FF 0%, #4288FF 100%)";
if (newVal.includes("重回")) return;
if (newVal.includes("红队") || newVal.includes("蓝队")) {
if (timer.value) clearInterval(timer.value);
remain.value = props.total;
timer.value = setInterval(() => {
if (remain.value > 0) remain.value--;
}, 1000);
updateRemain(props.total);
}
},
{
@@ -41,22 +49,12 @@ watch(
}
);
const updateRemain = (value) => {
if (Math.ceil(value) === remain.value || Math.floor(value) === remain.value)
return;
if (timer.value) clearInterval(timer.value);
remain.value = Math.round(value);
timer.value = setInterval(() => {
if (remain.value > 0) remain.value--;
}, 1000);
};
onMounted(() => {
uni.$on("update-ramain", updateRemain);
uni.$on("update-remain", updateRemain);
});
onBeforeUnmount(() => {
uni.$off("update-ramain", updateRemain);
uni.$off("update-remain", updateRemain);
if (timer.value) clearInterval(timer.value);
});
</script>
@@ -76,7 +74,8 @@ onBeforeUnmount(() => {
right: tips.includes('红队') ? 0 : 'unset',
}"
/>
<text>剩余{{ remain }}</text>
<text v-if="!laoding">剩余{{ remain }}</text>
<text v-else>···</text>
</view>
</view>
</template>

View File

@@ -19,12 +19,16 @@ const props = defineProps({
type: Boolean,
default: false,
},
count: {
type: Number,
default: 15,
},
});
const arrow = ref({});
const distance = ref(0);
const debugInfo = ref("");
const showsimul = ref(false);
const count = ref(15);
const count = ref(props.count);
const timer = ref(null);
const updateTimer = (value) => {
@@ -44,6 +48,7 @@ onBeforeUnmount(() => {
});
async function onReceiveMessage(messages = []) {
if (!Array.isArray(messages)) return;
messages.forEach((msg) => {
if (msg.constructor === MESSAGETYPES.ShootSyncMeArrowID) {
arrow.value = msg.target;