Commit 2767c807 authored by chechunchi's avatar chechunchi

handle field

parent 33f51925
Pipeline #19567 passed with stages
in 4 minutes and 9 seconds
......@@ -3,7 +3,7 @@ import { DuelState } from "./mod";
import { RootState } from "../../store";
import { ygopro } from "../../api/ocgcore/idl/ocgcore";
import { PayloadAction, CaseReducer } from "@reduxjs/toolkit";
import { CardState, InteractType } from "./generic";
import { CardState, Interactivity, InteractType } from "./generic";
export interface FieldState {
inner?: CardState;
......@@ -69,5 +69,35 @@ export const clearFieldPlaceInteractivitiesImpl: CaseReducer<
}
};
export const addFieldIdleInteractivitiesImpl: CaseReducer<
DuelState,
PayloadAction<{
player: number;
sequence: number;
interactivity: Interactivity<number>;
}>
> = (state, action) => {
const field = judgeSelf(action.payload.player, state)
? state.meField
: state.opField;
if (field && field.inner) {
field.inner.idleInteractivities.push(action.payload.interactivity);
}
};
export const clearFieldIdleInteractivitiesImpl: CaseReducer<
DuelState,
PayloadAction<number>
> = (state, action) => {
const field = judgeSelf(action.payload, state)
? state.meField
: state.opField;
if (field && field.inner) {
field.inner.idleInteractivities = [];
}
};
export const selectMeField = (state: RootState) => state.duel.meField;
export const selectOpField = (state: RootState) => state.duel.opField;
......@@ -73,6 +73,8 @@ import {
initFieldImpl,
clearFieldPlaceInteractivitiesImpl,
addFieldPlaceInteractivitiesImpl,
addFieldIdleInteractivitiesImpl,
clearFieldIdleInteractivitiesImpl,
} from "./fieldSlice";
export interface DuelState {
......@@ -171,6 +173,8 @@ const duelSlice = createSlice({
initField: initFieldImpl,
clearFieldPlaceInteractivities: clearFieldPlaceInteractivitiesImpl,
addFieldPlaceInteractivities: addFieldPlaceInteractivitiesImpl,
addFieldIdleInteractivities: addFieldIdleInteractivitiesImpl,
clearFieldIdleInteractivities: clearFieldIdleInteractivitiesImpl,
// UI相关`Reducer`
setCardModalIsOpen: setCardModalIsOpenImpl,
......@@ -250,6 +254,8 @@ export const {
initField,
clearFieldPlaceInteractivities,
addFieldPlaceInteractivities,
addFieldIdleInteractivities,
clearFieldIdleInteractivities,
} = duelSlice.actions;
export const selectDuelHsStart = (state: RootState) => {
return state.duel.meInitInfo != null;
......
......@@ -8,6 +8,8 @@ import {
addMagicIdleInteractivities,
clearMonsterIdleInteractivities,
clearMagicIdleInteractivities,
clearFieldIdleInteractivities,
addFieldIdleInteractivities,
} from "../../reducers/duel/mod";
import MsgSelectIdleCmd = ygopro.StocGameMessage.MsgSelectIdleCmd;
import { ActionCreatorWithPayload } from "@reduxjs/toolkit";
......@@ -20,6 +22,7 @@ export default (selectIdleCmd: MsgSelectIdleCmd, dispatch: AppDispatch) => {
dispatch(clearHandsIdleInteractivity(player));
dispatch(clearMonsterIdleInteractivities(player));
dispatch(clearMagicIdleInteractivities(player));
dispatch(clearFieldIdleInteractivities(player));
const dispatcher = (
idleData: MsgSelectIdleCmd.IdleCmd.IdleData,
......@@ -81,6 +84,11 @@ export default (selectIdleCmd: MsgSelectIdleCmd, dispatch: AppDispatch) => {
break;
}
case ygopro.CardZone.ONFIELD: {
dispatcher(data, interactType, addFieldIdleInteractivities);
break;
}
default: {
}
}
......
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