Commit 85203ea0 authored by Chunchi Che's avatar Chunchi Che

Merge branch 'fix/zero' into 'main'

Fix/zero

See merge request mycard/Neos!153
parents 8fb09d50 8aca524f
Pipeline #20921 passed with stages
in 21 minutes and 19 seconds
......@@ -55,22 +55,21 @@ export const setCheckCardModalCancelResponseImpl: CaseReducer<
export const fetchCheckCardMeta = createAsyncThunk(
"duel/fetchCheckCardMeta",
async (param: {
controler: number;
tagName: string;
option: {
code: number;
zone?: ygopro.CardZone;
sequence?: number;
location: ygopro.CardLocation;
response: number;
effectDescCode?: number;
};
}) => {
// FIXME: 这里如果传的`controler`如果是对手,对应的`code`会为零,这时候就无法更新对应的`Meta`信息了,后续需要修复。`fetchCheckCardMetaV2`和`fetchCheckCardMetaV3`同理
const meta = await fetchCard(param.option.code, true);
const effectDesc = param.option.effectDescCode
? getCardStr(meta, param.option.effectDescCode & 0xf)
: undefined;
const response = {
controler: param.controler,
controler: param.option.location.controler,
tagName: param.tagName,
meta: {
code: meta.id,
......@@ -88,11 +87,10 @@ export const checkCardModalCase = (
builder: ActionReducerMapBuilder<DuelState>
) => {
builder.addCase(fetchCheckCardMeta.pending, (state, action) => {
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 location = action.meta.arg.option.location;
const controler = location.controler;
const response = action.meta.arg.option.response;
const combinedTagName = judgeSelf(controler, state)
......@@ -100,11 +98,7 @@ export const checkCardModalCase = (
: `对方的${tagName}`;
const newID =
code != 0
? code
: zone && sequence
? findCardByLocation(state, controler, zone, sequence)?.occupant?.id
: undefined;
code != 0 ? code : findCardByLocation(state, location)?.occupant?.id || 0;
if (newID) {
for (const tag of state.modalState.checkCardModal.tags) {
......
......@@ -7,6 +7,8 @@ import {
} from "@reduxjs/toolkit";
import { fetchCard } from "../../../api/cards";
import { RootState } from "../../../store";
import { ygopro } from "../../../api/ocgcore/idl/ocgcore";
import { findCardByLocation } from "../util";
// 更新打开状态
export const setCheckCardModalV2IsOpenImpl: DuelReducer<boolean> = (
......@@ -53,9 +55,12 @@ export const setCheckCardModalV2ResponseAbleImpl: DuelReducer<boolean> = (
export const fetchCheckCardMetasV2 = createAsyncThunk(
"duel/fetchCheckCardMetaV2",
async (param: {
controler: number;
selected: boolean;
options: { code: number; response: number }[];
options: {
code: number;
location: ygopro.CardLocation;
response: number;
}[];
}) => {
const metas = await Promise.all(
param.options.map(async (option) => {
......@@ -63,7 +68,6 @@ export const fetchCheckCardMetasV2 = createAsyncThunk(
})
);
const response = {
controler: param.controler,
selected: param.selected,
metas,
};
......@@ -79,6 +83,14 @@ export const checkCardModalV2Case = (
const selected = action.meta.arg.selected;
const options = action.meta.arg.options;
for (const option of options) {
if (option.code == 0) {
const newCode =
findCardByLocation(state, option.location)?.occupant?.id || 0;
option.code = newCode;
}
}
if (selected) {
state.modalState.checkCardModalV2.selectedOptions = options;
} else {
......
......@@ -7,6 +7,8 @@ import {
} from "@reduxjs/toolkit";
import { CardMeta, fetchCard } from "../../../api/cards";
import { RootState } from "../../../store";
import { ygopro } from "../../../api/ocgcore/idl/ocgcore";
import { findCardByLocation } from "../util";
// 更新打开状态
export const setCheckCardModalV3IsOpenImpl: DuelReducer<boolean> = (
......@@ -64,6 +66,7 @@ export const fetchCheckCardMetasV3 = createAsyncThunk(
mustSelect: boolean;
options: {
code: number;
location: ygopro.CardLocation;
level1: number;
level2: number;
response: number;
......@@ -89,6 +92,12 @@ export const checkCardModalV3Case = (
builder.addCase(fetchCheckCardMetasV3.pending, (state, action) => {
const mustSelect = action.meta.arg.mustSelect;
const options = action.meta.arg.options.map((option) => {
if (option.code == 0) {
const newCode =
findCardByLocation(state, option.location)?.occupant?.id || 0;
option.code = newCode;
}
return {
meta: { id: option.code, data: {}, text: {} },
level1: option.level1,
......
......@@ -29,10 +29,12 @@ export function judgeSelf(player: number, state: Draft<DuelState>): boolean {
* 通过`controler`,`zone`和`sequence`获取卡牌状态*/
export function findCardByLocation(
state: Draft<DuelState>,
controler: number,
zone: ygopro.CardZone,
sequence: number
location: ygopro.CardLocation
): CardState | undefined {
const controler = location.controler;
const zone = location.location;
const sequence = location.sequence;
const finder = (_: any, idx: number) => idx == sequence;
switch (zone) {
......
......@@ -25,12 +25,10 @@ export default (selectCard: MsgSelectCard, dispatch: AppDispatch) => {
const tagName = CardZoneToChinese(card.location.location);
dispatch(
fetchCheckCardMeta({
controler: card.location.controler,
tagName,
option: {
code: card.code,
zone: card.location.location,
sequence: card.location.sequence,
location: card.location,
response: card.response,
},
})
......
......@@ -73,10 +73,10 @@ export default (selectChain: MsgSelectChain, dispatch: AppDispatch) => {
const tagName = CardZoneToChinese(chain.location.location);
dispatch(
fetchCheckCardMeta({
controler: chain.location.controler,
tagName,
option: {
code: chain.code,
location: chain.location,
response: chain.response,
effectDescCode: chain.effect_description,
},
......
......@@ -25,6 +25,7 @@ export default (selectTribute: MsgSelectTribute, dispatch: AppDispatch) => {
options: selectTribute.selectable_cards.map((card) => {
return {
code: card.code,
location: card.location,
level1: card.level,
level2: card.level,
response: card.response,
......
......@@ -14,7 +14,6 @@ export default (
selectUnselectCard: MsgSelectUnselectCard,
dispatch: AppDispatch
) => {
const controler = selectUnselectCard.player;
const finishable = selectUnselectCard.finishable;
const cancelable = selectUnselectCard.cancelable;
const min = selectUnselectCard.min;
......@@ -29,20 +28,26 @@ export default (
dispatch(
fetchCheckCardMetasV2({
controler,
selected: false,
options: selectableCards.map((card) => {
return { code: card.code, response: card.response };
return {
code: card.code,
location: card.location,
response: card.response,
};
}),
})
);
dispatch(
fetchCheckCardMetasV2({
controler,
selected: true,
options: selectedCards.map((card) => {
return { code: card.code, response: card.response };
return {
code: card.code,
location: card.location,
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