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