返回游戏流程完善

This commit is contained in:
kron
2025-07-21 10:40:43 +08:00
parent 9e83bf89f7
commit 200c05a288
9 changed files with 185 additions and 207 deletions

View File

@@ -25,7 +25,6 @@ const store = useStore();
const { user } = storeToRefs(store);
const step = ref(1);
const seq = ref(0);
const timerSeq = ref(0);
const battleId = ref("");
const room = ref({});
const roomNumber = ref("");
@@ -80,56 +79,68 @@ onLoad(async (options) => {
battleId.value = battleInfo.id;
battleType.value = battleInfo.config.mode;
step.value = 2;
if (battleInfo.status === 0) {
const readyRemain = Date.now() / 1000 - battleInfo.startTime;
console.log(`当前局已进行${readyRemain}`);
if (readyRemain > 0) {
setTimeout(() => {
uni.$emit("update-timer", 15 - readyRemain);
}, 200);
}
return;
} else {
step.value = 3;
start.value = true;
}
if (battleInfo.config.mode === 1) {
redTeam.value = battleInfo.redTeam;
blueTeam.value = battleInfo.blueTeam;
currentRound.value = battleInfo.currentRound;
totalRounds.value = battleInfo.maxRound;
if (battleInfo.startTime < 0) return;
start.value = true;
step.value = 3;
battleInfo.roundResults.forEach((round) => {
if (round.blueTotal && round.redTotal) {
if (round.blueTotal === round.redTotal) {
bluePoints.value += 1;
redPoints.value += 1;
} else if (round.blueTotal > round.redTotal) {
bluePoints.value += 2;
} else {
redPoints.value += 2;
if (battleInfo.status !== 0) {
currentRound.value = battleInfo.currentRound;
totalRounds.value = battleInfo.maxRound;
roundResults.value = battleInfo.roundResults;
battleInfo.roundResults.forEach((round) => {
if (round.blueTotal && round.redTotal) {
if (round.blueTotal === round.redTotal) {
bluePoints.value += 1;
redPoints.value += 1;
} else if (round.blueTotal > round.redTotal) {
bluePoints.value += 2;
} else {
redPoints.value += 2;
}
}
}
});
roundResults.value = battleInfo.roundResults;
currentShooterId.value = battleInfo.firePlayerIndex;
setTimeout(() => {
if (battleInfo.roundResults[battleInfo.roundResults.length - 1]) {
scores.value = battleInfo.roundResults[
battleInfo.roundResults.length - 1
].redArrows.filter((item) => !!item.playerId);
blueScores.value = battleInfo.roundResults[
battleInfo.roundResults.length - 1
].blueArrows.filter((item) => !!item.playerId);
}
}, 300);
if (
battleInfo.redTeam[0].shotHistory[battleInfo.currentRound] ||
battleInfo.blueTeam[0].shotHistory[battleInfo.currentRound]
) {
roundResults.value.push({
redArrows: battleInfo.redTeam[0].shotHistory[
battleInfo.currentRound
].filter((item) => !!item.playerId),
blueArrows: battleInfo.blueTeam[0].shotHistory[
battleInfo.currentRound
].filter((item) => !!item.playerId),
});
} else if (battleInfo.currentRound < 5) {
roundResults.value.push({
redArrows: [],
blueArrows: [],
});
setTimeout(() => {
if (battleInfo.roundResults[battleInfo.roundResults.length - 1]) {
scores.value = battleInfo.roundResults[
battleInfo.roundResults.length - 1
].redArrows.filter((item) => !!item.playerId);
blueScores.value = battleInfo.roundResults[
battleInfo.roundResults.length - 1
].blueArrows.filter((item) => !!item.playerId);
}
}, 300);
if (
battleInfo.redTeam[0].shotHistory[battleInfo.currentRound] ||
battleInfo.blueTeam[0].shotHistory[battleInfo.currentRound]
) {
roundResults.value.push({
redArrows: battleInfo.redTeam[0].shotHistory[
battleInfo.currentRound
].filter((item) => !!item.playerId),
blueArrows: battleInfo.blueTeam[0].shotHistory[
battleInfo.currentRound
].filter((item) => !!item.playerId),
});
} else if (battleInfo.currentRound < 5) {
roundResults.value.push({
redArrows: [],
blueArrows: [],
});
}
}
if (battleInfo.status !== 11) return;
if (battleInfo.firePlayerIndex) {
currentShooterId.value = battleInfo.firePlayerIndex;
if (redTeam.value[0].id === currentShooterId.value) {
@@ -149,28 +160,29 @@ onLoad(async (options) => {
}
}
} else if (battleInfo.config.mode === 2) {
total.value = 90;
players.value = [...battleInfo.blueTeam, ...battleInfo.redTeam];
if (battleInfo.startTime < 0) return;
start.value = true;
step.value = 3;
players.value.forEach((p) => {
playersScores.value[p.id] = [...p.arrows];
if (p.id === user.value.id) {
scores.value = [...p.arrows];
}
});
const remain = Date.now() / 1000 - battleInfo.startTime;
console.log(`当前局已进行${remain}`);
if (battleInfo.status === 2) {
tips.value = `${
battleInfo.halfGame ? "下半场-" : "上半场-"
}请连续射6箭`;
const remain = Date.now() / 1000 - battleInfo.startTime;
console.log(`当前局已进行${remain}`);
tips.value = battleInfo.halfGame
? "下半场请再射6箭"
: "上半场请先射6箭";
setTimeout(() => {
uni.$emit("update-ramain", 90 - remain);
}, 300);
} else if (battleInfo.status === 9) {
startCount.value = false;
tips.value = "准备下半场";
setTimeout(() => {
uni.$emit("update-ramain", 0);
}, 300);
}
}
}
@@ -229,7 +241,6 @@ onLoad(async (options) => {
const startGame = async () => {
const result = await startRoomAPI(room.value.number);
timerSeq.value += 1;
step.value = 2;
};
@@ -244,7 +255,6 @@ async function onReceiveMessage(messages = []) {
}
if (msg.constructor === MESSAGETYPES.WaitForAllReady) {
// 这里会掉多次;
timerSeq.value += 1;
battleId.value = msg.id;
step.value = 2;
if (battleType.value === 1) {
@@ -323,8 +333,6 @@ async function onReceiveMessage(messages = []) {
if (msg.id === battleId.value) {
if (msg.constructor === MESSAGETYPES.AllReady) {
start.value = true;
timerSeq.value = 0;
scores.value = [];
totalRounds.value = msg.groupUserStatus.config.maxRounds;
step.value = 3;
roundResults.value.push({
@@ -338,18 +346,13 @@ async function onReceiveMessage(messages = []) {
startCount.value = true;
step.value = 3;
seq.value += 1;
timerSeq.value = 0;
tips.value = `${
scores.value.length ? "下半场-" : "上半场-"
}请连续射6箭`;
tips.value = scores.value.length
? "下半场请再射6箭"
: "上半场请先射6箭";
total.value = 90;
halfTimeTip.value = false;
}
if (msg.constructor === MESSAGETYPES.ToSomeoneShoot) {
if (!start.value) {
start.value = true;
step.value = 3;
}
if (battleType.value === 1) {
if (currentShooterId.value !== msg.userId) {
seq.value += 1;
@@ -571,6 +574,7 @@ onUnmounted(() => {
:players="players"
/>
<TestDistance :guide="false" />
<Timer />
</view>
<view v-if="step === 3" :style="{ width: '100%' }">
<ShootProgress
@@ -612,7 +616,6 @@ onUnmounted(() => {
:scores="playersScores[player.id] || []"
/>
</view>
<Timer :seq="timerSeq" />
<ScreenHint
:show="showRoundTip"
:onClose="() => (showRoundTip = false)"