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,24 +14,56 @@ export default async ({ ...@@ -12,24 +14,56 @@ export default async ({
selectable_cards: selectableCards, selectable_cards: selectableCards,
selected_cards: selectedCards, selected_cards: selectedCards,
}: MsgSelectUnselectCard) => { }: MsgSelectUnselectCard) => {
const { if (
selecteds: selecteds1, selectableCards
mustSelects: mustSelect1, .concat(selectedCards)
selectables: selectable1, .find((info) => !isOnField(info.location)) === undefined
} = await fetchCheckCardMeta(selectableCards); ) {
const { // 所有可选卡和已选卡都是在场上或手牌
selecteds: selecteds2, // 通过让玩家点击场上的卡来进行选择
mustSelects: mustSelect2, for (const info of selectableCards) {
selectables: selectable2, const card = cardStore.find(info.location);
} = await fetchCheckCardMeta(selectedCards, true); if (card) {
await displaySelectActionsModal({ matStore.selectUnselectInfo.selectableList.push(info.location);
finishable, card.selectInfo.selectable = true;
cancelable, }
min: min, }
max: max, for (const info of selectedCards) {
single: true, const card = cardStore.find(info.location);
selecteds: [...selecteds1, ...selecteds2], if (card) {
mustSelects: [...mustSelect1, ...mustSelect2], matStore.selectUnselectInfo.selectedList.push(info.location);
selectables: [...selectable1, ...selectable2], card.selectInfo.selected = true;
}); }
}
matStore.selectUnselectInfo.finishable = finishable;
matStore.selectUnselectInfo.cancelable = cancelable;
} else {
// 有一些卡不在场上或手牌,因此无法通过点击卡片来选择
// 这里通过让玩家点击Modal中的卡来进行选择
const {
selecteds: selecteds1,
mustSelects: mustSelect1,
selectables: selectable1,
} = await fetchCheckCardMeta(selectableCards);
const {
selecteds: selecteds2,
mustSelects: mustSelect2,
selectables: selectable2,
} = await fetchCheckCardMeta(selectedCards, true);
await displaySelectActionsModal({
finishable,
cancelable,
min: min,
max: max,
single: true,
selecteds: [...selecteds1, ...selecteds2],
mustSelects: [...mustSelect1, ...mustSelect2],
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