Commit 654155bd authored by Chunchi Che's avatar Chunchi Che

remove field

parent 7c0401ad
Pipeline #19757 passed with stages
in 4 minutes and 9 seconds
import { judgeSelf } from "./util";
import { DuelState } from "./mod";
import { RootState } from "../../store";
import { ygopro } from "../../api/ocgcore/idl/ocgcore";
import {
PayloadAction,
CaseReducer,
ActionReducerMapBuilder,
} from "@reduxjs/toolkit";
import {
CardState,
createAsyncMetaThunk,
DuelReducer,
Interactivity,
InteractType,
} from "./generic";
export interface FieldState {
inner: CardState;
}
// 初始化场地区状态
export const initFieldImpl: CaseReducer<DuelState, PayloadAction<number>> = (
state,
action
) => {
const player = action.payload;
if (judgeSelf(player, state)) {
state.meField = {
inner: {
location: {
controler: player,
location: ygopro.CardZone.ONFIELD,
},
idleInteractivities: [],
},
};
} else {
state.opField = {
inner: {
location: {
controler: player,
location: ygopro.CardZone.ONFIELD,
},
idleInteractivities: [],
},
};
}
};
export const addFieldPlaceInteractivitiesImpl: CaseReducer<
DuelState,
PayloadAction<number>
> = (state, action) => {
const controler = action.payload;
const field = judgeSelf(controler, state) ? state.meField : state.opField;
if (field && field.inner) {
field.inner.placeInteractivities = {
interactType: InteractType.PLACE_SELECTABLE,
response: {
controler,
zone: ygopro.CardZone.ONFIELD,
sequence: 0,
},
};
}
};
export const clearFieldPlaceInteractivitiesImpl: CaseReducer<
DuelState,
PayloadAction<number>
> = (state, action) => {
const player = action.payload;
const field = judgeSelf(player, state) ? state.meField : state.opField;
if (field) {
field.inner.placeInteractivities = undefined;
}
};
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.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.idleInteractivities = [];
}
};
// 增加场地区
export const fetchFieldMeta = createAsyncMetaThunk("duel/fetchFieldMeta");
export const fieldCase = (builder: ActionReducerMapBuilder<DuelState>) => {
builder.addCase(fetchFieldMeta.pending, (state, action) => {
const controler = action.meta.arg.controler;
const sequence = action.meta.arg.sequence;
const code = action.meta.arg.code;
if (sequence == 0) {
const meta = { id: code, data: {}, text: {} };
const field = judgeSelf(controler, state) ? state.meField : state.opField;
if (field) {
field.inner.occupant = meta;
}
}
});
builder.addCase(fetchFieldMeta.fulfilled, (state, action) => {
const controler = action.payload.controler;
const meta = action.payload.meta;
const field = judgeSelf(controler, state) ? state.meField : state.opField;
if (field) {
field.inner.occupant = meta;
}
});
};
// 删除场地区
export const removeFieldImpl: DuelReducer<{ controler: number }> = (
state,
action
) => {
const controler = action.payload.controler;
const field = judgeSelf(controler, state) ? state.meField : state.opField;
if (field) {
field.inner.occupant = undefined;
}
};
export const selectMeField = (state: RootState) => state.duel.meField;
export const selectOpField = (state: RootState) => state.duel.opField;
......@@ -70,6 +70,15 @@ export const initMagicsImpl: CaseReducer<DuelState, PayloadAction<number>> = (
},
idleInteractivities: [],
},
{
// 场地区
location: {
controler: player,
location: ygopro.CardZone.SZONE,
sequence: 5,
},
idleInteractivities: [],
},
],
};
......
......@@ -89,16 +89,6 @@ import {
exclusionCase,
} from "./exclusionSlice";
import { DeckState, initDeckImpl } from "./deckSlice";
import {
FieldState,
initFieldImpl,
clearFieldPlaceInteractivitiesImpl,
addFieldPlaceInteractivitiesImpl,
addFieldIdleInteractivitiesImpl,
clearFieldIdleInteractivitiesImpl,
removeFieldImpl,
fieldCase,
} from "./fieldSlice";
export interface DuelState {
selfType?: number;
......@@ -123,9 +113,6 @@ export interface DuelState {
meDeck?: DeckState; // 自己的卡组状态
opDeck?: DeckState; // 对手的卡组状态
meField?: FieldState; // 自己的场地区状态
opField?: FieldState; // 对手的场地区状态
meTimeLimit?: TimeLimit; // 自己的计时
opTimeLimit?: TimeLimit; // 对手的计时
......@@ -204,14 +191,6 @@ const duelSlice = createSlice({
// 卡组相关`Reducer`
initDeck: initDeckImpl,
// 场地区相关`Reducer`
initField: initFieldImpl,
clearFieldPlaceInteractivities: clearFieldPlaceInteractivitiesImpl,
addFieldPlaceInteractivities: addFieldPlaceInteractivitiesImpl,
addFieldIdleInteractivities: addFieldIdleInteractivitiesImpl,
clearFieldIdleInteractivities: clearFieldIdleInteractivitiesImpl,
removeField: removeFieldImpl,
// 阶段相关
updatePhase: newPhaseImpl,
setEnableBp: setEnableBpImpl,
......@@ -255,7 +234,6 @@ const duelSlice = createSlice({
YesNoModalCase(builder);
optionModalCase(builder);
checkCardModalV2Case(builder);
fieldCase(builder);
},
});
......@@ -308,12 +286,6 @@ export const {
initDeck,
initExclusion,
removeExclusion,
initField,
removeField,
clearFieldPlaceInteractivities,
addFieldPlaceInteractivities,
addFieldIdleInteractivities,
clearFieldIdleInteractivities,
setCheckCardModalV2IsOpen,
setCheckCardModalV2MinMax,
setCheckCardModalV2CancelAble,
......
......@@ -64,14 +64,6 @@ export function findCardByLocation(
: 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;
}
......
......@@ -5,7 +5,6 @@ import { fetchMonsterMeta } from "../../reducers/duel/monstersSlice";
import {
removeCemetery,
removeExclusion,
removeField,
removeHand,
removeMagic,
removeMonster,
......@@ -14,7 +13,6 @@ import { fetchMagicMeta } from "../../reducers/duel/magicSlice";
import { fetchCemeteryMeta } from "../../reducers/duel/cemeretySlice";
import { insertHandMeta } from "../../reducers/duel/handsSlice";
import { fetchExclusionMeta } from "../../reducers/duel/exclusionSlice";
import { fetchFieldMeta } from "../../reducers/duel/fieldSlice";
export default (move: MsgMove, dispatch: AppDispatch) => {
const code = move.code;
......@@ -36,13 +34,9 @@ export default (move: MsgMove, dispatch: AppDispatch) => {
break;
}
case ygopro.CardZone.SZONE: {
if (from.sequence < 5) {
dispatch(
removeMagic({ controler: from.controler, sequence: from.sequence })
);
} else {
dispatch(removeField({ controler: from.controler }));
}
dispatch(
removeMagic({ controler: from.controler, sequence: from.sequence })
);
break;
}
......@@ -80,24 +74,14 @@ export default (move: MsgMove, dispatch: AppDispatch) => {
break;
}
case ygopro.CardZone.SZONE: {
if (to.sequence < 5) {
dispatch(
fetchMagicMeta({
controler: to.controler,
sequence: to.sequence,
position: to.position,
code,
})
);
} else {
dispatch(
fetchFieldMeta({
controler: to.controler,
sequence: to.sequence,
code,
})
);
}
dispatch(
fetchMagicMeta({
controler: to.controler,
sequence: to.sequence,
position: to.position,
code,
})
);
break;
}
......
......@@ -2,11 +2,9 @@ import { ActionCreatorWithPayload } from "@reduxjs/toolkit";
import { ygopro } from "../../api/ocgcore/idl/ocgcore";
import { Interactivity, InteractType } from "../../reducers/duel/generic";
import {
addFieldIdleInteractivities,
addHandsIdleInteractivity,
addMagicIdleInteractivities,
addMonsterIdleInteractivities,
clearFieldIdleInteractivities,
clearHandsIdleInteractivity,
clearMagicIdleInteractivities,
clearMonsterIdleInteractivities,
......@@ -24,7 +22,6 @@ export default (selectBattleCmd: MsgSelectBattleCmd, dispatch: AppDispatch) => {
dispatch(clearHandsIdleInteractivity(player));
dispatch(clearMonsterIdleInteractivities(player));
dispatch(clearMagicIdleInteractivities(player));
dispatch(clearFieldIdleInteractivities(player));
const dispatcher = (
battleData: MsgSelectBattleCmd.BattleCmd.BattleData,
......@@ -89,11 +86,6 @@ export default (selectBattleCmd: MsgSelectBattleCmd, dispatch: AppDispatch) => {
break;
}
case ygopro.CardZone.ONFIELD: {
dispatcher(data, interactType, addFieldIdleInteractivities);
break;
}
default: {
}
}
......
......@@ -8,8 +8,6 @@ import {
addMagicIdleInteractivities,
clearMonsterIdleInteractivities,
clearMagicIdleInteractivities,
clearFieldIdleInteractivities,
addFieldIdleInteractivities,
setEnableBp,
setEnableEp,
} from "../../reducers/duel/mod";
......@@ -24,7 +22,6 @@ export default (selectIdleCmd: MsgSelectIdleCmd, dispatch: AppDispatch) => {
dispatch(clearHandsIdleInteractivity(player));
dispatch(clearMonsterIdleInteractivities(player));
dispatch(clearMagicIdleInteractivities(player));
dispatch(clearFieldIdleInteractivities(player));
const dispatcher = (
idleData: MsgSelectIdleCmd.IdleCmd.IdleData,
......@@ -86,11 +83,6 @@ export default (selectIdleCmd: MsgSelectIdleCmd, dispatch: AppDispatch) => {
break;
}
case ygopro.CardZone.ONFIELD: {
dispatcher(data, interactType, addFieldIdleInteractivities);
break;
}
default: {
}
}
......
......@@ -4,7 +4,6 @@ import MsgSelectPlace = ygopro.StocGameMessage.MsgSelectPlace;
import {
addMonsterPlaceInteractivities,
addMagicPlaceInteractivities,
addFieldPlaceInteractivities,
} from "../../reducers/duel/mod";
export default (selectPlace: MsgSelectPlace, dispatch: AppDispatch) => {
......@@ -30,11 +29,6 @@ export default (selectPlace: MsgSelectPlace, dispatch: AppDispatch) => {
break;
}
case ygopro.CardZone.ONFIELD: {
dispatch(addFieldPlaceInteractivities(place.controler));
break;
}
default: {
console.warn(`Unhandled zoneType: ${place.zone}`);
}
......
......@@ -8,7 +8,6 @@ import {
initCemetery,
initDeck,
initExclusion,
initField,
} from "../../reducers/duel/mod";
export default (
......@@ -46,6 +45,4 @@ export default (
dispatch(initDeck({ player: 1, deskSize: start.deckSize2 }));
dispatch(initExclusion(0));
dispatch(initExclusion(1));
dispatch(initField(0));
dispatch(initField(1));
};
import * as BABYLON from "@babylonjs/core";
import * as CONFIG from "../../config/ui";
import { useAppSelector } from "../../hook";
import { selectMeField, selectOpField } from "../../reducers/duel/fieldSlice";
import { clearFieldPlaceInteractivities } from "../../reducers/duel/mod";
import { selectMeMagics, selectOpMagics } from "../../reducers/duel/magicSlice";
import { clearMagicPlaceInteractivities } from "../../reducers/duel/mod";
import FixedSlot from "./fixedSlot";
import { Depth } from "./singleSlot";
const Field = () => {
const meField = useAppSelector(selectMeField)?.inner;
const opField = useAppSelector(selectOpField)?.inner;
const meField = useAppSelector(selectMeMagics).inner.find(
(_, sequence) => sequence == 5
);
const opField = useAppSelector(selectOpMagics).inner.find(
(_, sequence) => sequence == 5
);
return (
<>
......@@ -18,7 +22,7 @@ const Field = () => {
sequence={0}
position={fieldPosition(0)}
rotation={CONFIG.CardSlotRotation(false)}
clearPlaceInteractivitiesAction={clearFieldPlaceInteractivities}
clearPlaceInteractivitiesAction={clearMagicPlaceInteractivities}
/>
) : (
<></>
......@@ -29,7 +33,7 @@ const Field = () => {
sequence={0}
position={fieldPosition(1)}
rotation={CONFIG.CardSlotRotation(true)}
clearPlaceInteractivitiesAction={clearFieldPlaceInteractivities}
clearPlaceInteractivitiesAction={clearMagicPlaceInteractivities}
/>
) : (
<></>
......
......@@ -12,7 +12,6 @@ import {
sendSelectIdleCmdResponse,
} from "../../api/ocgcore/ocgHelper";
import {
clearFieldIdleInteractivities,
clearHandsIdleInteractivity,
clearMagicIdleInteractivities,
clearMonsterIdleInteractivities,
......@@ -33,8 +32,6 @@ const Bp = () => {
dispatch(clearMonsterIdleInteractivities(1));
dispatch(clearMagicIdleInteractivities(0));
dispatch(clearMagicIdleInteractivities(1));
dispatch(clearFieldIdleInteractivities(0));
dispatch(clearFieldIdleInteractivities(1));
sendSelectIdleCmdResponse(6);
dispatch(setEnableBp(false));
......@@ -54,8 +51,6 @@ const M2 = () => {
dispatch(clearMonsterIdleInteractivities(1));
dispatch(clearMagicIdleInteractivities(0));
dispatch(clearMagicIdleInteractivities(1));
dispatch(clearFieldIdleInteractivities(0));
dispatch(clearFieldIdleInteractivities(1));
sendSelectBattleCmdResponse(2);
dispatch(setEnableM2(false));
......@@ -86,8 +81,6 @@ const Ep = () => {
dispatch(clearMonsterIdleInteractivities(1));
dispatch(clearMagicIdleInteractivities(0));
dispatch(clearMagicIdleInteractivities(1));
dispatch(clearFieldIdleInteractivities(0));
dispatch(clearFieldIdleInteractivities(1));
sendSelectIdleCmdResponse(response);
dispatch(setEnableEp(false));
......
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