Commit 1a5e0584 authored by Chunchi Che's avatar Chunchi Che

Merge branch 'fix/select_card' into 'main'

Fix/select card

See merge request mycard/Neos!89
parents b8eca8c7 e1585af1
Pipeline #19752 passed with stages
in 4 minutes and 47 seconds
......@@ -6,8 +6,9 @@ import {
} from "@reduxjs/toolkit";
import { RootState } from "../../../store";
import { DuelState } from "../mod";
import { judgeSelf } from "../util";
import { findCardByLocation, judgeSelf } from "../util";
import { fetchCard, getCardStr } from "../../../api/cards";
import { ygopro } from "../../../api/ocgcore/idl/ocgcore";
// 更新卡牌选择弹窗打开状态
export const setCheckCardModalIsOpenImpl: CaseReducer<
......@@ -56,7 +57,13 @@ export const fetchCheckCardMeta = createAsyncThunk(
async (param: {
controler: number;
tagName: string;
option: { code: number; response: number; effectDescCode?: number };
option: {
code: number;
zone?: ygopro.CardZone;
sequence?: number;
response: number;
effectDescCode?: number;
};
}) => {
const meta = await fetchCard(param.option.code, true);
const effectDesc = param.option.effectDescCode
......@@ -84,23 +91,34 @@ export const checkCardModalCase = (
const controler = action.meta.arg.controler;
const tagName = action.meta.arg.tagName;
const code = action.meta.arg.option.code;
const zone = action.meta.arg.option.zone;
const sequence = action.meta.arg.option.sequence;
const response = action.meta.arg.option.response;
const combinedTagName = judgeSelf(controler, state)
? `我方的${tagName}`
: `对方的${tagName}`;
for (const tag of state.modalState.checkCardModal.tags) {
if (tag.tagName === combinedTagName) {
tag.options.push({ code, response });
return;
const newID =
code != 0
? code
: zone && sequence
? findCardByLocation(state, controler, zone, sequence)?.occupant?.id
: undefined;
if (newID) {
for (const tag of state.modalState.checkCardModal.tags) {
if (tag.tagName === combinedTagName) {
tag.options.push({ code: newID, response });
return;
}
}
}
state.modalState.checkCardModal.tags.push({
tagName: combinedTagName,
options: [{ code, response }],
});
state.modalState.checkCardModal.tags.push({
tagName: combinedTagName,
options: [{ code: newID, response }],
});
}
});
builder.addCase(fetchCheckCardMeta.fulfilled, (state, action) => {
const controler = action.payload.controler;
......
......@@ -5,6 +5,8 @@
import { DuelState } from "./mod";
import { Draft } from "@reduxjs/toolkit";
import { ygopro } from "../../api/ocgcore/idl/ocgcore";
import { CardState } from "./generic";
/*
* 通过`player`和`selfType`判断是应该处理自己还是对手
......@@ -22,3 +24,56 @@ export function judgeSelf(player: number, state: Draft<DuelState>): boolean {
return false;
}
}
/*
* 通过`controler`,`zone`和`sequence`获取卡牌状态*/
export function findCardByLocation(
state: Draft<DuelState>,
controler: number,
zone: ygopro.CardZone,
sequence: number
): CardState | undefined {
const finder = (_: any, idx: number) => idx == sequence;
switch (zone) {
case ygopro.CardZone.HAND: {
const hands = judgeSelf(controler, state) ? state.meHands : state.opHands;
return hands?.inner.find(finder);
}
case ygopro.CardZone.MZONE: {
const monsters = judgeSelf(controler, state)
? state.meMonsters
: state.opMonsters;
return monsters?.inner.find(finder);
}
case ygopro.CardZone.SZONE: {
const magics = judgeSelf(controler, state)
? state.meMagics
: state.opMagics;
return magics?.inner.find(finder);
}
case ygopro.CardZone.REMOVED: {
const exclusions = judgeSelf(controler, state)
? state.meExclusion
: state.opExclusion;
return exclusions?.inner.find(finder);
}
case ygopro.CardZone.GRAVE: {
const cemerety = judgeSelf(controler, state)
? state.meCemetery
: state.opCemetery;
return cemerety?.inner.find(finder);
}
case ygopro.CardZone.ONFIELD: {
const field = judgeSelf(controler, state) ? state.meField : state.opField;
if (sequence == 0) {
return field?.inner;
} else {
return undefined;
}
}
default: {
return undefined;
}
}
}
......@@ -25,7 +25,12 @@ export default (selectCard: MsgSelectCard, dispatch: AppDispatch) => {
fetchCheckCardMeta({
controler: card.location.controler,
tagName,
option: { code: card.code, response: card.response },
option: {
code: card.code,
zone: card.location.location,
sequence: card.location.sequence,
response: card.response,
},
})
);
}
......
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