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 { ...@@ -72,6 +72,7 @@ import {
removeMonsterImpl, removeMonsterImpl,
setMonsterPositionImpl, setMonsterPositionImpl,
removeOverlayImpl, removeOverlayImpl,
updateMonsterCountersImpl,
monsterCase, monsterCase,
} from "./monstersSlice"; } from "./monstersSlice";
import { import {
...@@ -213,6 +214,7 @@ const duelSlice = createSlice({ ...@@ -213,6 +214,7 @@ const duelSlice = createSlice({
setMonsterPosition: setMonsterPositionImpl, setMonsterPosition: setMonsterPositionImpl,
removeMonster: removeMonsterImpl, removeMonster: removeMonsterImpl,
removeOverlay: removeOverlayImpl, removeOverlay: removeOverlayImpl,
updateMonsterCounters: updateMonsterCountersImpl,
// 魔法陷阱区相关`Reducer` // 魔法陷阱区相关`Reducer`
initMagics: initMagicsImpl, initMagics: initMagicsImpl,
...@@ -337,6 +339,7 @@ export const { ...@@ -337,6 +339,7 @@ export const {
clearMonsterIdleInteractivities, clearMonsterIdleInteractivities,
setMonsterPosition, setMonsterPosition,
removeMonster, removeMonster,
updateMonsterCounters,
removeOverlay, removeOverlay,
initMagics, initMagics,
addMagicPlaceInteractivities, addMagicPlaceInteractivities,
......
...@@ -22,6 +22,9 @@ import { ...@@ -22,6 +22,9 @@ import {
removeOverlay, removeOverlay,
} from "./generic"; } from "./generic";
import { fetchCard } from "../../api/cards"; import { fetchCard } from "../../api/cards";
type MsgUpdateCounter = ReturnType<
typeof ygopro.StocGameMessage.MsgUpdateCounter.prototype.toObject
>;
export interface MonsterState extends DuelFieldState {} export interface MonsterState extends DuelFieldState {}
...@@ -155,6 +158,44 @@ export const addMonsterIdleInteractivitiesImpl: CaseReducer< ...@@ -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< export const clearMonsterIdleInteractivitiesImpl: CaseReducer<
DuelState, DuelState,
PayloadAction<number> PayloadAction<number>
......
import { ygopro } from "../../api/ocgcore/idl/ocgcore"; import { ygopro } from "../../api/ocgcore/idl/ocgcore";
import { updateMonsterCounters } from "../../reducers/duel/mod";
import { AppDispatch } from "../../store"; import { AppDispatch } from "../../store";
import MsgUpdateCounter = ygopro.StocGameMessage.MsgUpdateCounter; import MsgUpdateCounter = ygopro.StocGameMessage.MsgUpdateCounter;
export default (updateCounter: MsgUpdateCounter, dispatch: AppDispatch) => { 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