diff --git a/src/apis.js b/src/apis.js
index 144adc2..b017577 100644
--- a/src/apis.js
+++ b/src/apis.js
@@ -6,7 +6,7 @@ try {
switch (envVersion) {
case "develop": // 开发版
- // BASE_URL = "http://192.168.1.242:8000/api/shoot";
+ // BASE_URL = "http://192.168.1.30:8000/api/shoot";
BASE_URL = "https://apitest.shelingxingqiu.com/api/shoot";
break;
case "trial": // 体验版
@@ -418,9 +418,9 @@ export const getUserGameState = () => {
};
export const getCurrentGameAPI = async () => {
- uni.$emit("update-header-loading", true);
- const result = await request("GET", "/user/join/battle");
- return result.currentGame || {};
+ // uni.$emit("update-header-loading", true);
+ // const result = await request("GET", "/user/join/battle");
+ // return result.currentGame || {};
};
export const getPointBookConfigAPI = async () => {
@@ -552,3 +552,10 @@ export const getReadyAPI = (roomId) => {
roomId,
});
};
+
+export const getBattleAPI = async (battleId) => {
+ const result = await request("POST", "/user/match/info", {
+ id: battleId,
+ });
+ return result;
+};
diff --git a/src/components/BackToGame.vue b/src/components/BackToGame.vue
index 31167fb..703612e 100644
--- a/src/components/BackToGame.vue
+++ b/src/components/BackToGame.vue
@@ -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,
});
diff --git a/src/components/BattleFooter.vue b/src/components/BattleFooter.vue
index 3186b2f..cfed39f 100644
--- a/src/components/BattleFooter.vue
+++ b/src/components/BattleFooter.vue
@@ -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;
+});
@@ -59,8 +60,8 @@ const normalRounds = computed(
{{
- 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(
{{
- 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)
: ""
diff --git a/src/components/BowTarget.vue b/src/components/BowTarget.vue
index 9541a49..c74da13 100644
--- a/src/components/BowTarget.vue
+++ b/src/components/BowTarget.vue
@@ -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(() => {
diff --git a/src/components/CreateRoom.vue b/src/components/CreateRoom.vue
index 965dd46..6a54b9a 100644
--- a/src/components/CreateRoom.vue
+++ b/src/components/CreateRoom.vue
@@ -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;
});
diff --git a/src/components/HeaderProgress.vue b/src/components/HeaderProgress.vue
index 1579ffc..305d2f7 100644
--- a/src/components/HeaderProgress.vue
+++ b/src/components/HeaderProgress.vue
@@ -1,7 +1,7 @@
@@ -76,7 +74,8 @@ onBeforeUnmount(() => {
right: tips.includes('红队') ? 0 : 'unset',
}"
/>
- 剩余{{ remain }}秒
+ 剩余{{ remain }}秒
+ ···
diff --git a/src/components/TestDistance.vue b/src/components/TestDistance.vue
index f3edfea..9de5fd3 100644
--- a/src/components/TestDistance.vue
+++ b/src/components/TestDistance.vue
@@ -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;
diff --git a/src/constants.js b/src/constants.js
index 7410841..a5cda6b 100644
--- a/src/constants.js
+++ b/src/constants.js
@@ -30,12 +30,24 @@ export const MESSAGETYPES = {
SomeoneIsReady: 4168086628,
};
+export const MESSAGETYPESV2 = {
+ AboutToStart: 1,
+ BattleStart: 2,
+ ToSomeoneShoot: 3,
+ ShootResult: 4,
+ NewRound: 5,
+ BattleEnd: 6,
+};
+
export const topThreeColors = ["#FFD947", "#D2D2D2", "#FFA515"];
export const getMessageTypeName = (id) => {
for (let key in MESSAGETYPES) {
if (MESSAGETYPES[key] === id) return key;
}
+ for (let key in MESSAGETYPESV2) {
+ if (MESSAGETYPESV2[key] === id) return key;
+ }
return null;
};
diff --git a/src/pages/battle-result.vue b/src/pages/battle-result.vue
index 5086a67..e19956e 100644
--- a/src/pages/battle-result.vue
+++ b/src/pages/battle-result.vue
@@ -1,9 +1,9 @@
-
+
-
+
蓝队
红队
-
+
你的经验 {{ totalPoints > 0 ? "+" + totalPoints : totalPoints }}
-
+
你的积分 {{ totalPoints > 0 ? "+" + totalPoints : totalPoints }}
-
+
{{
- getBattleResultTips(data.battleMode, data.mode, {
+ getBattleResultTips(data.way, data.mode, {
win: ifWin,
score: totalPoints,
rank,
diff --git a/src/pages/battle-room.vue b/src/pages/battle-room.vue
index 0d41816..87007f2 100644
--- a/src/pages/battle-room.vue
+++ b/src/pages/battle-room.vue
@@ -1,6 +1,6 @@
-
-
+
+
{
+ round.shoots[1].forEach((arrow) => {
+ blueScores.value.push(arrow);
+ });
+ round.shoots[2].forEach((arrow) => {
+ redScores.value.push(arrow);
+ });
+};
onLoad(async (options) => {
- if (options.battleId) {
- const result = await getGameAPI(
- options.battleId || "BATTLE-1756453741433684760-512"
- );
- data.value = result;
- Object.values(result.bluePlayers).forEach((p, index) => {
- players.value.push(p);
- if (
- Object.values(result.redPlayers) &&
- Object.values(result.redPlayers)[index]
- ) {
- players.value.push(Object.values(result.redPlayers)[index]);
- }
- });
- if (result.goldenRounds) {
- result.goldenRounds.forEach(() => {
- tabs.value.push("决金箭");
- });
- }
- Object.keys(result.roundsData).forEach((key, index) => {
- if (
- index <
- Object.keys(result.roundsData).length - result.goldenRounds.length
- ) {
- tabs.value.push(`第${roundsName[key]}轮`);
- }
- });
- onClickTab(0);
- }
+ if (!options.battleId) return;
+ const result = await getBattleAPI(options.battleId || "57943107462893568");
+ data.value = result;
+ data.value.teams[1].players.forEach((p, index) => {
+ players.value.push(p);
+ players.value.push(data.value.teams[2].players[index]);
+ });
+ Object.values(data.value.rounds).forEach((round, index) => {
+ if (round.ifGold) tabs.value.push(`决金箭`);
+ else tabs.value.push(`第${roundsName[index + 1]}轮`);
+ });
+ selected.value = Number(options.selected || 0);
+ onClickTab(selected.value);
});
const onClickTab = (index) => {
selected.value = index;
redScores.value = [];
blueScores.value = [];
- const { bluePlayers, redPlayers, roundsData, goldenRounds } = data.value;
- let maxArrowLength = 0;
- if (index === 0) {
- Object.keys(bluePlayers).forEach((p) => {
- allRoundsScore.value[p] = [];
- Object.values(roundsData).forEach((round) => {
- if (!round[p]) return;
- allRoundsScore.value[p].push(
- round[p].reduce((last, next) => last + next.ring, 0)
- );
- round[p].forEach((arrow) => {
- blueScores.value.push(arrow);
- });
- });
- });
- Object.keys(redPlayers).forEach((p) => {
- allRoundsScore.value[p] = [];
- Object.values(roundsData).forEach((round) => {
- if (!round[p]) return;
- allRoundsScore.value[p].push(
- round[p].reduce((last, next) => last + next.ring, 0)
- );
- round[p].forEach((arrow) => {
- redScores.value.push(arrow);
- });
- });
- });
- } else if (index <= goldenRounds.length) {
- const dataIndex =
- Object.keys(roundsData).length - goldenRounds.length + index;
- Object.keys(bluePlayers).forEach((p) => {
- if (!roundsData[dataIndex][p]) return;
- roundsData[dataIndex][p].forEach((arrow) => {
- blueScores.value.push(arrow);
- });
- });
- Object.keys(redPlayers).forEach((p) => {
- if (!roundsData[dataIndex][p]) return;
- roundsData[dataIndex][p].forEach((arrow) => {
- redScores.value.push(arrow);
- });
- });
- } else {
- Object.keys(bluePlayers).forEach((p) => {
- roundsData[index - goldenRounds.length][p].forEach((arrow) => {
- blueScores.value.push(arrow);
- });
- });
- Object.keys(redPlayers).forEach((p) => {
- roundsData[index - goldenRounds.length][p].forEach((arrow) => {
- redScores.value.push(arrow);
- });
- });
- }
+ loadArrows(data.value.rounds[index]);
};
@@ -134,41 +71,14 @@ const onClickTab = (index) => {
>
- {{ ring }}
-
-
- {{ score.ring }}
-
-