房间比赛流程同步

This commit is contained in:
kron
2025-06-26 22:54:17 +08:00
parent ad7f919d52
commit c730088764
6 changed files with 80 additions and 40 deletions

View File

@@ -35,8 +35,10 @@ const players = ref([]);
const currentRound = ref(1);
const totalRounds = ref(0);
const start = ref(false);
const startCount = ref(false);
const power = ref(0);
const scores = ref([]);
const blueScores = ref([]);
const tips = ref("即将开始...");
const roundResults = ref([]);
const redPoints = ref(0);
@@ -46,6 +48,9 @@ const currentBluePoint = ref(0);
const showRoundTip = ref(false);
const playersScores = ref({});
const showModal = ref(false);
const halfTimeTip = ref(false);
const total = ref(90);
onLoad(async (options) => {
if (options.roomNumber) {
roomNumber.value = options.roomNumber;
@@ -63,6 +68,7 @@ onLoad(async (options) => {
return false;
});
if (result.battleType === 1) {
total.value = 15;
if (user.value.id !== owner.value.id) {
opponent.value = {
id: user.value.id,
@@ -159,7 +165,7 @@ async function onReceiveMessage(messages = []) {
players.value = players.value.filter((p) => p.id !== msg.userId);
}
}
if (msg.constructor === MESSAGETYPES.RoomDestroy) {
if (msg.constructor === MESSAGETYPES.RoomDestroy && !battleId.value) {
uni.showToast({
title: "房间已解散",
icon: "none",
@@ -182,12 +188,21 @@ async function onReceiveMessage(messages = []) {
seq.value += 1;
}
}
if (msg.constructor === MESSAGETYPES.MeleeAllReady) {
start.value = true;
startCount.value = true;
seq.value += 1;
timerSeq.value = 0;
tips.value = "请连续射出6支箭";
scores.value = [];
}
if (msg.constructor === MESSAGETYPES.ToSomeoneShoot) {
if (room.value.battleType === 1) {
scores.value = [];
blueScores.value = [];
seq.value += 1;
currentShooterId.value = msg.userId;
if (owner.id !== currentShooterId.value) {
if (redTeam.value[0].id === currentShooterId.value) {
tips.value = `请红队射箭-第${roundsName[currentRound.value]}`;
} else {
tips.value = `请蓝队射箭-第${roundsName[currentRound.value]}`;
@@ -196,7 +211,12 @@ async function onReceiveMessage(messages = []) {
}
if (msg.constructor === MESSAGETYPES.ShootResult) {
if (room.value.battleType === 1) {
scores.value = [msg.target];
const isRed = redTeam.value.find((item) => item.id === msg.userId);
if (isRed) {
scores.value = [msg.target];
} else {
blueScores.value = [msg.target];
}
}
if (room.value.battleType === 2) {
scores.value.push(msg.target);
@@ -205,26 +225,32 @@ async function onReceiveMessage(messages = []) {
if (playersScores.value[msg.userId])
playersScores.value[msg.userId].push(msg.target);
}
if (msg.constructor === MESSAGETYPES.RoundPoint) {
bluePoints.value += msg.blueScore;
redPoints.value += msg.redScore;
}
if (msg.constructor === MESSAGETYPES.CurrentRoundEnded) {
const result = msg.preRoundResult;
scores.value = [];
currentShooterId.value = 0;
currentBluePoint.value = result.blueScore;
currentRedPoint.value = result.redScore;
showRoundTip.value = true;
if (
result.currentRound > 0 &&
result.currentRound < totalRounds.value
) {
// 开始下一轮;
roundResults.value = result.roundResults;
currentRound.value = result.currentRound + 1;
if (room.value.battleType === 1) {
const result = msg.preRoundResult;
scores.value = [];
blueScores.value = [];
currentShooterId.value = 0;
currentBluePoint.value = result.blueScore;
currentRedPoint.value = result.redScore;
bluePoints.value += result.blueScore;
redPoints.value += result.redScore;
showRoundTip.value = true;
if (
result.currentRound > 0 &&
result.currentRound < totalRounds.value
) {
// 开始下一轮;
roundResults.value = result.roundResults;
currentRound.value = result.currentRound + 1;
}
}
}
if (msg.constructor === MESSAGETYPES.HalfTimeOver) {
startCount.value = false;
halfTimeTip.value = true;
tips.value = "准备下半场";
}
if (msg.constructor === MESSAGETYPES.MatchOver) {
uni.redirectTo({
url: `/pages/battle-result?battleId=${msg.id}&winner=${msg.endStatus.winner}`,
@@ -341,7 +367,12 @@ onUnmounted(() => {
/>
</view>
<view v-if="step === 3">
<ShootProgress :tips="tips" :seq="seq" :start="start" />
<ShootProgress
:tips="tips"
:seq="seq"
:start="start && startCount"
:total="total"
/>
<PlayersRow
v-if="room.battleType === 1"
:blueTeam="blueTeam"
@@ -349,10 +380,13 @@ onUnmounted(() => {
:currentShooterId="currentShooterId"
/>
<BowTarget
:power="power"
:mode="room.battleType ? 'team' : 'solo'"
:showE="start && user.id === currentShooterId"
:power="start ? power : 0"
:currentRound="currentRound"
:totalRound="totalRounds"
:scores="scores"
:blueScores="blueScores"
/>
<BattleFooter
v-if="room.battleType === 1"
@@ -383,6 +417,16 @@ onUnmounted(() => {
</view>
</view>
</ScreenHint>
<ScreenHint
:show="halfTimeTip"
mode="small"
:onClose="() => (halfTimeTip = false)"
>
<view class="half-time-tip">
<text>上半场结束休息一下吧:</text>
<text>20秒后开始下半场</text>
</view>
</ScreenHint>
<SModal :show="showModal" :onClose="() => (showModal = false)">
<view class="btns">
<SButton :onClick="exitRoom" width="200px" :rounded="20">