Commit 5c298ffe authored by Chunchi Che's avatar Chunchi Che

update select card service

parent c6bdbcaa
...@@ -7,6 +7,7 @@ import { ...@@ -7,6 +7,7 @@ import {
import { fetchCard } from "../../api/cards"; import { fetchCard } from "../../api/cards";
import { RootState } from "../../store"; import { RootState } from "../../store";
import { DuelState } from "./mod"; import { DuelState } from "./mod";
import { judgeSelf } from "./util";
export interface ModalState { export interface ModalState {
// 卡牌弹窗 // 卡牌弹窗
...@@ -118,11 +119,13 @@ export const setCheckCardModalMinMaxImpl: CaseReducer< ...@@ -118,11 +119,13 @@ export const setCheckCardModalMinMaxImpl: CaseReducer<
export const fetchCheckCardMeta = createAsyncThunk( export const fetchCheckCardMeta = createAsyncThunk(
"duel/fetchCheckCardMeta", "duel/fetchCheckCardMeta",
async (param: { async (param: {
controler: number;
tagName: string; tagName: string;
option: { code: number; response: number }; option: { code: number; response: number };
}) => { }) => {
const meta = await fetchCard(param.option.code); const meta = await fetchCard(param.option.code);
const response = { const response = {
controler: param.controler,
tagName: param.tagName, tagName: param.tagName,
meta: { meta: {
code: meta.id, code: meta.id,
...@@ -139,12 +142,17 @@ export const checkCardModalCase = ( ...@@ -139,12 +142,17 @@ export const checkCardModalCase = (
builder: ActionReducerMapBuilder<DuelState> builder: ActionReducerMapBuilder<DuelState>
) => { ) => {
builder.addCase(fetchCheckCardMeta.pending, (state, action) => { builder.addCase(fetchCheckCardMeta.pending, (state, action) => {
const controler = action.meta.arg.controler;
const tagName = action.meta.arg.tagName; const tagName = action.meta.arg.tagName;
const code = action.meta.arg.option.code; const code = action.meta.arg.option.code;
const response = action.meta.arg.option.response; const response = action.meta.arg.option.response;
const combinedTagName = judgeSelf(controler, state)
? `我方的${tagName}`
: `对方的${tagName}`;
for (const tag of state.modalState.checkCardModal.tags) { for (const tag of state.modalState.checkCardModal.tags) {
if (tag.tagName === tagName) { if (tag.tagName === combinedTagName) {
tag.options.push({ code, response }); tag.options.push({ code, response });
return; return;
} }
...@@ -156,11 +164,16 @@ export const checkCardModalCase = ( ...@@ -156,11 +164,16 @@ export const checkCardModalCase = (
}); });
}); });
builder.addCase(fetchCheckCardMeta.fulfilled, (state, action) => { builder.addCase(fetchCheckCardMeta.fulfilled, (state, action) => {
const controler = action.payload.controler;
const tagName = action.payload.tagName; const tagName = action.payload.tagName;
const meta = action.payload.meta; const meta = action.payload.meta;
const combinedTagName = judgeSelf(controler, state)
? `我方的${tagName}`
: `对方的${tagName}`;
for (const tag of state.modalState.checkCardModal.tags) { for (const tag of state.modalState.checkCardModal.tags) {
if (tag.tagName === tagName) { if (tag.tagName === combinedTagName) {
for (const option of tag.options) { for (const option of tag.options) {
if (option.code == meta.code) { if (option.code == meta.code) {
option.name = meta.name; option.name = meta.name;
......
import { ygopro } from "../../api/ocgcore/idl/ocgcore"; import { ygopro } from "../../api/ocgcore/idl/ocgcore";
import { AppDispatch } from "../../store"; import { AppDispatch } from "../../store";
import {
setCheckCardModalIsOpen,
setCheckCardModalMinMax,
} from "../../reducers/duel/mod";
import { fetchCheckCardMeta } from "../../reducers/duel/modalSlice";
import MsgSelectCard = ygopro.StocGameMessage.MsgSelectCard; import MsgSelectCard = ygopro.StocGameMessage.MsgSelectCard;
import { CardZoneToChinese } from "./util";
export default (selectCard: MsgSelectCard, dispatch: AppDispatch) => { export default (selectCard: MsgSelectCard, dispatch: AppDispatch) => {
console.log(selectCard); const _player = selectCard.player;
// TODO const _cancelable = selectCard.cancelable; // TODO: 处理可取消逻辑
const min = selectCard.min;
const max = selectCard.max;
const cards = selectCard.cards;
dispatch(setCheckCardModalMinMax({ min, max }));
for (const card of cards) {
const tagName = CardZoneToChinese(card.location.location);
dispatch(
fetchCheckCardMeta({
controler: card.location.controler,
tagName,
option: { code: card.code, response: card.response },
})
);
}
dispatch(setCheckCardModalIsOpen(true));
}; };
import { ygopro } from "../../api/ocgcore/idl/ocgcore";
export function CardZoneToChinese(zone: ygopro.CardZone): string {
switch (zone) {
case ygopro.CardZone.DECK: {
return "卡组";
}
case ygopro.CardZone.HAND: {
return "手牌";
}
case ygopro.CardZone.EXTRA: {
return "额外卡组";
}
case ygopro.CardZone.GRAVE: {
return "墓地";
}
case ygopro.CardZone.FZONE: {
return "FZONE";
}
case ygopro.CardZone.MZONE: {
return "怪兽区";
}
case ygopro.CardZone.SZONE: {
return "魔法陷阱区";
}
case ygopro.CardZone.REMOVED: {
return "除外区";
}
case ygopro.CardZone.OVERLAY: {
return "超量区";
}
case ygopro.CardZone.PZONE: {
return "灵摆区";
}
case ygopro.CardZone.ONFIELD: {
return "场地区";
}
default: {
return "未知区域";
}
}
}
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