Commit 44db29b2 authored by Chunchi Che's avatar Chunchi Che

add monster slice

parent cab7edda
......@@ -23,17 +23,25 @@ import {
setCardModalImgUrlImpl,
setCardModalInteractiviesImpl,
} from "./modalSlice";
import { MonsterState, initMonstersImpl } from "./monstersSlice";
export interface DuelState {
selfType?: number;
meInitInfo?: InitInfo; // 自己的初始状态
opInitInfo?: InitInfo; // 对手的初始状态
meHands?: Hands; // 自己的手牌
opHands?: Hands; // 对手的手牌
meMonsters?: MonsterState; // 自己的怪兽区状态
opMonsters?: MonsterState; // 对手的怪兽区状态
meTimeLimit?: TimeLimit; // 自己的计时
opTimeLimit?: TimeLimit; // 对手的计时
meHint?: HintState; // 自己的提示
opHint?: HintState; // 对手的提示
currentPlayer?: number; // 当前的操作方
currentPhase?: string; // 当前的阶段
......@@ -63,6 +71,9 @@ const duelSlice = createSlice({
clearHandsInteractivity: clearHandsInteractivityImpl,
addHandsInteractivity: addHandsInteractivityImpl,
// 怪兽区相关`Reducer`
initMonsters: initMonstersImpl,
// UI相关`Reducer`
setCardModalIsOpen: setCardModalIsOpenImpl,
setCardModalText: setCardModalTextImpl,
......@@ -87,6 +98,7 @@ export const {
setCardModalText,
setCardModalImgUrl,
setCardModalInteractivies,
initMonsters,
} = duelSlice.actions;
export const selectDuelHsStart = (state: RootState) => {
return state.duel.meInitInfo != null;
......
export interface MonsterState {}
import { judgeSelf, Monster } from "./util";
import { PayloadAction, CaseReducer } from "@reduxjs/toolkit";
import { DuelState } from "./mod";
export interface MonsterState {
monsters: Monster[];
}
// 初始化自己的怪兽区状态
export const initMonstersImpl: CaseReducer<DuelState, PayloadAction<number>> = (
state,
action
) => {
const player = action.payload;
let monsters = judgeSelf(player, state) ? state.meMonsters : state.opMonsters;
if (!monsters) {
monsters = {
monsters: [
{
sequence: 0,
},
{
sequence: 1,
},
{
sequence: 2,
},
{
sequence: 3,
},
{
sequence: 4,
},
],
};
}
};
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