Commit 83f4f98e authored by Chunchi Che's avatar Chunchi Che

update selectUnselectCard service

parent 43439502
Pipeline #26999 passed with stages
in 10 minutes and 43 seconds
import { ygopro } from "@/api"; import { ygopro } from "@/api";
import { cardStore, matStore } from "@/stores";
import { displaySelectActionsModal } from "@/ui/Duel/Message/SelectActionsModal"; import { displaySelectActionsModal } from "@/ui/Duel/Message/SelectActionsModal";
import { fetchCheckCardMeta } from "../utils"; import { fetchCheckCardMeta } from "../utils";
type MsgSelectUnselectCard = ygopro.StocGameMessage.MsgSelectUnselectCard; type MsgSelectUnselectCard = ygopro.StocGameMessage.MsgSelectUnselectCard;
const { MZONE, SZONE, HAND } = ygopro.CardZone;
export default async ({ export default async ({
finishable, finishable,
...@@ -12,6 +14,33 @@ export default async ({ ...@@ -12,6 +14,33 @@ export default async ({
selectable_cards: selectableCards, selectable_cards: selectableCards,
selected_cards: selectedCards, selected_cards: selectedCards,
}: MsgSelectUnselectCard) => { }: MsgSelectUnselectCard) => {
if (
selectableCards
.concat(selectedCards)
.find((info) => !isOnField(info.location)) === undefined
) {
// 所有可选卡和已选卡都是在场上或手牌
// 通过让玩家点击场上的卡来进行选择
for (const info of selectableCards) {
const card = cardStore.find(info.location);
if (card) {
matStore.selectUnselectInfo.selectableList.push(info.location);
card.selectInfo.selectable = true;
}
}
for (const info of selectedCards) {
const card = cardStore.find(info.location);
if (card) {
matStore.selectUnselectInfo.selectedList.push(info.location);
card.selectInfo.selected = true;
}
}
matStore.selectUnselectInfo.finishable = finishable;
matStore.selectUnselectInfo.cancelable = cancelable;
} else {
// 有一些卡不在场上或手牌,因此无法通过点击卡片来选择
// 这里通过让玩家点击Modal中的卡来进行选择
const { const {
selecteds: selecteds1, selecteds: selecteds1,
mustSelects: mustSelect1, mustSelects: mustSelect1,
...@@ -32,4 +61,9 @@ export default async ({ ...@@ -32,4 +61,9 @@ export default async ({
mustSelects: [...mustSelect1, ...mustSelect2], mustSelects: [...mustSelect1, ...mustSelect2],
selectables: [...selectable1, ...selectable2], selectables: [...selectable1, ...selectable2],
}); });
}
}; };
function isOnField(location: ygopro.CardLocation): boolean {
return [MZONE, SZONE, HAND].includes(location.zone);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment