Commit d02078d1 authored by Chunchi Che's avatar Chunchi Che

update monster slice

parent 49652094
Pipeline #20932 passed with stages
in 18 minutes and 59 seconds
......@@ -72,6 +72,7 @@ import {
removeMonsterImpl,
setMonsterPositionImpl,
removeOverlayImpl,
updateMonsterCountersImpl,
monsterCase,
} from "./monstersSlice";
import {
......@@ -213,6 +214,7 @@ const duelSlice = createSlice({
setMonsterPosition: setMonsterPositionImpl,
removeMonster: removeMonsterImpl,
removeOverlay: removeOverlayImpl,
updateMonsterCounters: updateMonsterCountersImpl,
// 魔法陷阱区相关`Reducer`
initMagics: initMagicsImpl,
......@@ -337,6 +339,7 @@ export const {
clearMonsterIdleInteractivities,
setMonsterPosition,
removeMonster,
updateMonsterCounters,
removeOverlay,
initMagics,
addMagicPlaceInteractivities,
......
......@@ -22,6 +22,9 @@ import {
removeOverlay,
} from "./generic";
import { fetchCard } from "../../api/cards";
type MsgUpdateCounter = ReturnType<
typeof ygopro.StocGameMessage.MsgUpdateCounter.prototype.toObject
>;
export interface MonsterState extends DuelFieldState {}
......@@ -155,6 +158,44 @@ export const addMonsterIdleInteractivitiesImpl: CaseReducer<
);
};
export const updateMonsterCountersImpl: CaseReducer<
DuelState,
PayloadAction<MsgUpdateCounter>
> = (state, action) => {
const monsters = judgeSelf(action.payload.location?.controler!, state)
? state.meMonsters
: state.opMonsters;
if (monsters) {
const target = monsters.inner.find(
(_, idx) => idx == action.payload.location?.sequence!
);
if (target) {
const count = action.payload.count!;
const counterType = action.payload.action_type!;
switch (action.payload.action_type!) {
case ygopro.StocGameMessage.MsgUpdateCounter.ActionType.ADD: {
if (counterType in target.counters) {
target.counters[counterType] += count;
} else {
target.counters[counterType] = count;
}
break;
}
case ygopro.StocGameMessage.MsgUpdateCounter.ActionType.REMOVE: {
if (counterType in target.counters) {
target.counters[counterType] -= count;
}
break;
}
default: {
break;
}
}
}
}
};
export const clearMonsterIdleInteractivitiesImpl: CaseReducer<
DuelState,
PayloadAction<number>
......
import { ygopro } from "../../api/ocgcore/idl/ocgcore";
import { updateMonsterCounters } from "../../reducers/duel/mod";
import { AppDispatch } from "../../store";
import MsgUpdateCounter = ygopro.StocGameMessage.MsgUpdateCounter;
export default (updateCounter: MsgUpdateCounter, dispatch: AppDispatch) => {
console.log(updateCounter);
dispatch(updateMonsterCounters(updateCounter.toObject()));
};
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