新版房间1v1对战数据调试完成
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
<script setup>
|
||||
import { ref, onMounted } from "vue";
|
||||
import { ref, computed, onMounted } from "vue";
|
||||
import { onLoad } from "@dcloudio/uni-app";
|
||||
import Avatar from "@/components/Avatar.vue";
|
||||
import UserUpgrade from "@/components/UserUpgrade.vue";
|
||||
import { getGameAPI } from "@/apis";
|
||||
import { getBattleAPI } from "@/apis";
|
||||
import { topThreeColors, getBattleResultTips } from "@/constants";
|
||||
import audioManager from "@/audioManager";
|
||||
import useStore from "@/store";
|
||||
@@ -18,12 +18,7 @@ const totalPoints = ref(0);
|
||||
const rank = ref(0);
|
||||
|
||||
function exit() {
|
||||
const battleInfo = uni.getStorageSync("last-battle");
|
||||
if (battleInfo && battleInfo.roomId) {
|
||||
uni.redirectTo({
|
||||
url: `/pages/battle-room?roomNumber=${battleInfo.roomId}`,
|
||||
});
|
||||
} else if (data.value.roomId) {
|
||||
if (data.value.roomId) {
|
||||
uni.redirectTo({
|
||||
url: `/pages/battle-room?roomNumber=${data.value.roomId}`,
|
||||
});
|
||||
@@ -33,128 +28,87 @@ function exit() {
|
||||
}
|
||||
|
||||
onLoad(async (options) => {
|
||||
if (!options.battleId) return;
|
||||
const myId = user.value.id;
|
||||
if (options.battleId) {
|
||||
const result = await getGameAPI(
|
||||
options.battleId || "BATTLE-1758270367040321900-868"
|
||||
const result = await getBattleAPI(options.battleId || "58351917302157312");
|
||||
data.value = result;
|
||||
if (result.winTeam) {
|
||||
ifWin.value = result.teams[result.winTeam].players.some(
|
||||
(p) => p.id === myId
|
||||
);
|
||||
data.value = {
|
||||
...result,
|
||||
battleMode: result.gameMode,
|
||||
};
|
||||
if (result.mode === 1) {
|
||||
data.value.redPlayers = Object.values(result.redPlayers);
|
||||
data.value.bluePlayers = Object.values(result.bluePlayers);
|
||||
if (result.redPlayers[myId]) {
|
||||
totalPoints.value = result.redPlayers[myId].totalScore;
|
||||
data.value.myTeam = result.redPlayers[myId].team;
|
||||
ifWin.value = result.winner === 0;
|
||||
}
|
||||
if (result.bluePlayers[myId]) {
|
||||
totalPoints.value = result.bluePlayers[myId].totalScore;
|
||||
data.value.myTeam = result.bluePlayers[myId].team;
|
||||
ifWin.value = result.winner === 1;
|
||||
}
|
||||
}
|
||||
if (result.mode === 2) {
|
||||
data.value.playerStats = result.players.map((p) => ({
|
||||
...p,
|
||||
id: p.playerId,
|
||||
}));
|
||||
const mine = result.players.find((p) => p.playerId === myId);
|
||||
if (mine) totalPoints.value = mine.totalScore;
|
||||
rank.value = result.players.findIndex((p) => p.playerId === myId) + 1;
|
||||
}
|
||||
} else {
|
||||
const battleInfo = uni.getStorageSync("last-battle");
|
||||
if (!battleInfo) return;
|
||||
data.value = {
|
||||
mvps: [],
|
||||
...battleInfo,
|
||||
};
|
||||
if (battleInfo.mode === 1) {
|
||||
battleInfo.playerStats.forEach((p) => {
|
||||
if (p.team === 1) data.value.bluePlayers = [p];
|
||||
if (p.team === 0) data.value.redPlayers = [p];
|
||||
if (p.mvp) data.value.mvps.push(p);
|
||||
});
|
||||
data.value.mvps.sort((a, b) => b.totalRings - a.totalRings);
|
||||
}
|
||||
rank.value = 0;
|
||||
const mine = battleInfo.playerStats.find((p, index) => {
|
||||
rank.value = index + 1;
|
||||
return p.id === myId;
|
||||
});
|
||||
if (mine) {
|
||||
data.value.myTeam = mine.team;
|
||||
totalPoints.value = mine.totalScore;
|
||||
if (battleInfo.mode === 1) {
|
||||
ifWin.value = mine.team === battleInfo.winner;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (data.value.mode === 1) {
|
||||
if (result.way === 1) {
|
||||
audioManager.play(ifWin.value ? "胜利" : "失败");
|
||||
} else if (data.value.mode === 2) {
|
||||
if (data.value.battleMode === 1) {
|
||||
if (rank.value <= data.value.playerStats.length * 0.3) {
|
||||
audioManager.play("胜利");
|
||||
}
|
||||
} else if (data.value.battleMode === 2) {
|
||||
if (totalPoints.value > 0) {
|
||||
audioManager.play("胜利");
|
||||
} else if (totalPoints.value < 0) {
|
||||
audioManager.play("失败");
|
||||
}
|
||||
}
|
||||
} else if (result.way === 2) {
|
||||
// if (data.value.battleMode === 1) {
|
||||
// if (rank.value <= data.value.playerStats.length * 0.3) {
|
||||
// audioManager.play("胜利");
|
||||
// }
|
||||
// } else if (data.value.battleMode === 2) {
|
||||
// if (totalPoints.value > 0) {
|
||||
// audioManager.play("胜利");
|
||||
// } else if (totalPoints.value < 0) {
|
||||
// audioManager.play("失败");
|
||||
// }
|
||||
// }
|
||||
}
|
||||
});
|
||||
|
||||
const myTeam = computed(() => {
|
||||
const teams = data.value.teams;
|
||||
if (teams && teams.length) {
|
||||
if (teams[1].players.some((p) => p.id === user.value.id)) return 1;
|
||||
}
|
||||
return 2;
|
||||
});
|
||||
|
||||
const checkBowData = () => {
|
||||
uni.navigateTo({
|
||||
url: `/pages/match-detail?id=${data.value.id}`,
|
||||
url: `/pages/match-detail?id=${data.value.matchId}`,
|
||||
});
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<view class="container">
|
||||
<block v-if="data.mode === 1">
|
||||
<block v-if="data.way === 1">
|
||||
<view class="header-team" :style="{ marginTop: '25%' }">
|
||||
<image src="../static/battle-result.png" mode="widthFix" />
|
||||
<view class="header-solo" v-if="data.teamSize === 2">
|
||||
<view class="header-solo" v-if="data.mode === 1">
|
||||
<text
|
||||
:style="{
|
||||
background:
|
||||
data.winner === 1
|
||||
data.winTeam === 1
|
||||
? 'linear-gradient(270deg, #3597ff 0%, rgba(0,0,0,0) 100%);'
|
||||
: 'linear-gradient(270deg, #fd4444 0%, rgba(0, 0, 0, 0) 100%)',
|
||||
}"
|
||||
>{{ data.winner === 1 ? "蓝队" : "红队" }}获胜</text
|
||||
>{{ data.winTeam === 1 ? "蓝队" : "红队" }}获胜</text
|
||||
>
|
||||
<Avatar
|
||||
:size="32"
|
||||
:src="
|
||||
data.winner === 1
|
||||
? data.bluePlayers[0].avatar
|
||||
: data.redPlayers[0].avatar
|
||||
data.winTeam === 1
|
||||
? data.teams[1].players[0].avatar
|
||||
: data.teams[2].players[0].avatar
|
||||
"
|
||||
:borderColor="data.winner === 1 ? '#5FADFF' : '#FF5656'"
|
||||
:borderColor="data.winTeam === 1 ? '#5FADFF' : '#FF5656'"
|
||||
mode="widthFix"
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
<view class="header-mvp" v-if="data.teamSize !== 2">
|
||||
<view class="header-mvp" v-if="data.mode === 2 || data.mode === 3">
|
||||
<image
|
||||
:src="`../static/${data.winner === 1 ? 'blue' : 'red'}-team-win.png`"
|
||||
:src="`../static/${data.winTeam === 1 ? 'blue' : 'red'}-team-win.png`"
|
||||
mode="widthFix"
|
||||
/>
|
||||
<view
|
||||
:style="{
|
||||
transform: `translateY(50px) rotate(-${5 + data.mvps.length}deg)`,
|
||||
transform: `translateY(50px) rotate(-${
|
||||
5 + (data.mvp || []).length
|
||||
}deg)`,
|
||||
}"
|
||||
>
|
||||
<view v-if="data.mvps && data.mvps[0].totalRings">
|
||||
<view v-if="data.mvp && data.mvp[0].totalRings">
|
||||
<image src="../static/title-mvp.png" mode="widthFix" />
|
||||
<text
|
||||
>斩获<text
|
||||
@@ -164,22 +118,22 @@ const checkBowData = () => {
|
||||
margin: '0 3px',
|
||||
fontWeight: '600',
|
||||
}"
|
||||
>{{ data.mvps[0].totalRings }}</text
|
||||
>{{ data.mvp[0].totalRings }}</text
|
||||
>环</text
|
||||
>
|
||||
</view>
|
||||
<view v-if="data.mvps && data.mvps.length">
|
||||
<view v-for="(player, index) in data.mvps" :key="index">
|
||||
<view v-if="data.mvp && data.mvp.length">
|
||||
<view v-for="(player, index) in data.mvp" :key="index">
|
||||
<view class="team-avatar">
|
||||
<Avatar
|
||||
:src="player.avatar"
|
||||
:size="40"
|
||||
:borderColor="data.myTeam === 1 ? '#5fadff' : '#ff6060'"
|
||||
:borderColor="myTeam === 1 ? '#5fadff' : '#ff6060'"
|
||||
/>
|
||||
<text
|
||||
v-if="player.id === user.id"
|
||||
:style="{
|
||||
backgroundColor: data.myTeam === 1 ? '#5fadff' : '#ff6060',
|
||||
backgroundColor: myTeam === 1 ? '#5fadff' : '#ff6060',
|
||||
}"
|
||||
>自己</text
|
||||
>
|
||||
@@ -198,7 +152,7 @@ const checkBowData = () => {
|
||||
/>
|
||||
<image
|
||||
:src="
|
||||
getBattleResultTips(data.battleMode, data.mode, {
|
||||
getBattleResultTips(data.way, data.mode, {
|
||||
win: ifWin,
|
||||
})
|
||||
"
|
||||
@@ -207,7 +161,7 @@ const checkBowData = () => {
|
||||
/>
|
||||
</view>
|
||||
</block>
|
||||
<block v-if="data.mode === 2">
|
||||
<block v-if="data.way === 2">
|
||||
<view class="header-melee">
|
||||
<view />
|
||||
<image src="../static/battle-result.png" mode="widthFix" />
|
||||
@@ -283,36 +237,36 @@ const checkBowData = () => {
|
||||
</block>
|
||||
<view
|
||||
class="battle-e"
|
||||
:style="{ marginTop: data.mode === 2 ? '20px' : '20vw' }"
|
||||
:style="{ marginTop: data.way === 2 ? '20px' : '20vw' }"
|
||||
>
|
||||
<image src="../static/row-yellow-bg.png" mode="widthFix" />
|
||||
<view class="team-avatar">
|
||||
<Avatar
|
||||
:src="user.avatar"
|
||||
:size="40"
|
||||
:borderColor="data.myTeam === 1 ? '#5fadff' : '#ff6060'"
|
||||
:borderColor="myTeam === 1 ? '#5fadff' : '#ff6060'"
|
||||
/>
|
||||
<text
|
||||
:style="{ backgroundColor: '#5fadff' }"
|
||||
v-if="data.mode === 1 && data.myTeam === 1"
|
||||
v-if="data.way === 1 && myTeam === 1"
|
||||
>蓝队</text
|
||||
>
|
||||
<text
|
||||
:style="{ backgroundColor: '#ff6060' }"
|
||||
v-if="data.mode === 1 && data.myTeam === 0"
|
||||
v-if="data.way === 1 && myTeam === 2"
|
||||
>红队</text
|
||||
>
|
||||
</view>
|
||||
<text v-if="data.battleMode === 1">
|
||||
<text v-if="data.way === 1">
|
||||
你的经验 {{ totalPoints > 0 ? "+" + totalPoints : totalPoints }}
|
||||
</text>
|
||||
<text v-if="data.battleMode === 2">
|
||||
<text v-if="data.way === 2">
|
||||
你的积分 {{ totalPoints > 0 ? "+" + totalPoints : totalPoints }}
|
||||
</text>
|
||||
</view>
|
||||
<text v-if="data.mode === 2" class="description">
|
||||
<text v-if="data.way === 2" class="description">
|
||||
{{
|
||||
getBattleResultTips(data.battleMode, data.mode, {
|
||||
getBattleResultTips(data.way, data.mode, {
|
||||
win: ifWin,
|
||||
score: totalPoints,
|
||||
rank,
|
||||
|
||||
Reference in New Issue
Block a user