房间比赛流程同步

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

@@ -57,6 +57,7 @@ defineProps({
.container { .container {
width: 100%; width: 100%;
margin-top: 20px; margin-top: 20px;
overflow: hidden;
} }
.container > view:first-child { .container > view:first-child {
position: relative; position: relative;

View File

@@ -49,10 +49,6 @@ const props = defineProps({
type: Boolean, type: Boolean,
default: true, default: true,
}, },
start: {
type: Boolean,
default: false,
},
mode: { mode: {
type: String, type: String,
default: "solo", // solo 单排team 双排 default: "solo", // solo 单排team 双排
@@ -201,7 +197,6 @@ const simulShoot = async () => {
.container { .container {
width: calc(100% - 30px); width: calc(100% - 30px);
padding: 15px; padding: 15px;
/* overflow: hidden; */
position: relative; position: relative;
} }
.target { .target {

View File

@@ -10,6 +10,7 @@ export const MESSAGETYPES = {
SomeGuyIsReady: parseInt("0xAEE8C236"), // 2934489654 SomeGuyIsReady: parseInt("0xAEE8C236"), // 2934489654
MatchOver: parseInt("0xB7815EEF"), // 3078708975 MatchOver: parseInt("0xB7815EEF"), // 3078708975
StartCount: parseInt("0xD7B0DD2F"), // 3618692399 StartCount: parseInt("0xD7B0DD2F"), // 3618692399
FinalShoot: parseInt("0x5953C8A1"), // 1498663073
RoundPoint: 4061248646, RoundPoint: 4061248646,
UserEnterRoom: 2133805521, UserEnterRoom: 2133805521,
UserExitRoom: 3896523333, UserExitRoom: 3896523333,

View File

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

View File

@@ -151,6 +151,7 @@ onUnmounted(() => {
:totalRound="start ? 12 : 0" :totalRound="start ? 12 : 0"
:scores="scores" :scores="scores"
/> />
<view :style="{ paddingBottom: '20px' }">
<PlayerScore <PlayerScore
v-if="start" v-if="start"
v-for="(player, index) in players" v-for="(player, index) in players"
@@ -160,6 +161,7 @@ onUnmounted(() => {
:scores="playersScores[player.id]" :scores="playersScores[player.id]"
:done="playersScores[player.id].length === 12" :done="playersScores[player.id].length === 12"
/> />
</view>
<Timer :seq="timerSeq" :callBack="readyToGo" /> <Timer :seq="timerSeq" :callBack="readyToGo" />
<ScreenHint <ScreenHint
:show="halfTimeTip" :show="halfTimeTip"

View File

@@ -107,13 +107,10 @@ async function onReceiveMessage(messages = []) {
blueScores.value = [msg.target]; blueScores.value = [msg.target];
} }
} }
if (msg.constructor === MESSAGETYPES.RoundPoint) {
// bluePoints.value += msg.blueScore;
// redPoints.value += msg.redScore;
}
if (msg.constructor === MESSAGETYPES.CurrentRoundEnded) { if (msg.constructor === MESSAGETYPES.CurrentRoundEnded) {
const result = msg.preRoundResult; const result = msg.preRoundResult;
scores.value = []; scores.value = [];
blueScores.value = [];
currentShooterId.value = 0; currentShooterId.value = 0;
currentBluePoint.value = result.blueScore; currentBluePoint.value = result.blueScore;
currentRedPoint.value = result.redScore; currentRedPoint.value = result.redScore;