Commit bc23ca62 authored by Chunchi Che's avatar Chunchi Che

udpate hintSlice

parent c3751b96
...@@ -2,7 +2,7 @@ import { createAsyncThunk, ActionReducerMapBuilder } from "@reduxjs/toolkit"; ...@@ -2,7 +2,7 @@ import { createAsyncThunk, ActionReducerMapBuilder } from "@reduxjs/toolkit";
import { DuelState } from "./mod"; import { DuelState } from "./mod";
import { RootState } from "../../store"; import { RootState } from "../../store";
import { DESCRIPTION_LIMIT, fetchStrings, getStrings } from "../../api/strings"; import { DESCRIPTION_LIMIT, fetchStrings, getStrings } from "../../api/strings";
import { findCardByLocation, judgeSelf } from "./util"; import { findCardByLocation } from "./util";
import { fetchCard } from "../../api/cards"; import { fetchCard } from "../../api/cards";
import { DuelReducer } from "./generic"; import { DuelReducer } from "./generic";
import { ygopro } from "../../api/ocgcore/idl/ocgcore"; import { ygopro } from "../../api/ocgcore/idl/ocgcore";
...@@ -14,37 +14,20 @@ export interface HintState { ...@@ -14,37 +14,20 @@ export interface HintState {
esSelectHint?: string; esSelectHint?: string;
} }
export const initHintImpl: DuelReducer<number> = (state, action) => { export const initHintImpl: DuelReducer<void> = (state) => {
const player = action.payload; state.hint = { code: 0 };
if (judgeSelf(player, state)) {
state.meHint = { code: 0 };
} else {
state.opHint = { code: 0 };
}
}; };
export const fetchCommonHintMeta = createAsyncThunk( export const fetchCommonHintMeta = createAsyncThunk(
"duel/fetchCommonHintMeta", "duel/fetchCommonHintMeta",
async (param: [number, number]) => { async (hintData: number) => {
const player = param[0]; return fetchStrings("!system", hintData);
const hintData = param[1];
const hintMeta = fetchStrings("!system", hintData);
const response: [number, string] = [player, hintMeta];
return response;
} }
); );
export const fetchSelectHintMeta = createAsyncThunk( export const fetchSelectHintMeta = createAsyncThunk(
"duel/fetchSelectHintMeta", "duel/fetchSelectHintMeta",
async (param: { async (param: { selectHintData: number; esHint?: string }) => {
player: number;
selectHintData: number;
esHint?: string;
}) => {
const player = param.player;
const selectHintData = param.selectHintData; const selectHintData = param.selectHintData;
let selectHintMeta = ""; let selectHintMeta = "";
...@@ -60,7 +43,6 @@ export const fetchSelectHintMeta = createAsyncThunk( ...@@ -60,7 +43,6 @@ export const fetchSelectHintMeta = createAsyncThunk(
} }
return { return {
player,
selectHintMeta, selectHintMeta,
esHint: param.esHint, esHint: param.esHint,
}; };
...@@ -70,12 +52,10 @@ export const fetchSelectHintMeta = createAsyncThunk( ...@@ -70,12 +52,10 @@ export const fetchSelectHintMeta = createAsyncThunk(
export const fetchEsHintMeta = createAsyncThunk( export const fetchEsHintMeta = createAsyncThunk(
"duel/fetchEsHintMeta", "duel/fetchEsHintMeta",
async (param: { async (param: {
player: number;
originMsg: string | number; originMsg: string | number;
location?: ygopro.CardLocation; location?: ygopro.CardLocation;
cardID?: number; cardID?: number;
}) => { }) => {
const player = param.player;
const originMsg = const originMsg =
typeof param.originMsg === "string" typeof param.originMsg === "string"
? param.originMsg ? param.originMsg
...@@ -86,49 +66,41 @@ export const fetchEsHintMeta = createAsyncThunk( ...@@ -86,49 +66,41 @@ export const fetchEsHintMeta = createAsyncThunk(
if (param.cardID) { if (param.cardID) {
const cardMeta = await fetchCard(param.cardID); const cardMeta = await fetchCard(param.cardID);
return { player, originMsg, cardMeta, location }; return { originMsg, cardMeta, location };
} else { } else {
return { player, originMsg, location }; return { originMsg, location };
} }
} }
); );
export const hintCase = (builder: ActionReducerMapBuilder<DuelState>) => { export const hintCase = (builder: ActionReducerMapBuilder<DuelState>) => {
builder.addCase(fetchCommonHintMeta.pending, (state, action) => { builder.addCase(fetchCommonHintMeta.pending, (state, action) => {
const player = action.meta.arg[0]; const code = action.meta.arg;
const code = action.meta.arg[1];
if (judgeSelf(player, state)) { if (state.hint) {
state.meHint = { code }; state.hint.code = code;
} else {
state.opHint = { code };
} }
}); });
builder.addCase(fetchCommonHintMeta.fulfilled, (state, action) => { builder.addCase(fetchCommonHintMeta.fulfilled, (state, action) => {
const player = action.payload[0]; const hintMeta = action.payload;
const hintMeta = action.payload[1];
const hint = judgeSelf(player, state) ? state.meHint : state.opHint; if (state.hint) {
if (hint) { state.hint.msg = hintMeta;
hint.msg = hintMeta;
} }
}); });
builder.addCase(fetchSelectHintMeta.pending, (state, action) => { builder.addCase(fetchSelectHintMeta.pending, (state, action) => {
const player = action.meta.arg.player;
const code = action.meta.arg.selectHintData; const code = action.meta.arg.selectHintData;
const hint = judgeSelf(player, state) ? state.meHint : state.opHint; if (state.hint) {
if (hint) { state.hint.code = code;
hint.code = code;
} }
}); });
builder.addCase(fetchSelectHintMeta.fulfilled, (state, action) => { builder.addCase(fetchSelectHintMeta.fulfilled, (state, action) => {
const player = action.payload.player;
const selectHintMsg = action.payload.selectHintMeta; const selectHintMsg = action.payload.selectHintMeta;
const esHint = action.payload.esHint; const esHint = action.payload.esHint;
const hint = judgeSelf(player, state) ? state.meHint : state.opHint; const hint = state.hint;
if (hint) { if (hint) {
if (hint.code > DESCRIPTION_LIMIT) { if (hint.code > DESCRIPTION_LIMIT) {
// 针对`MSG_SELECT_PLACE`的特化逻辑 // 针对`MSG_SELECT_PLACE`的特化逻辑
...@@ -140,12 +112,11 @@ export const hintCase = (builder: ActionReducerMapBuilder<DuelState>) => { ...@@ -140,12 +112,11 @@ export const hintCase = (builder: ActionReducerMapBuilder<DuelState>) => {
} }
}); });
builder.addCase(fetchEsHintMeta.fulfilled, (state, action) => { builder.addCase(fetchEsHintMeta.fulfilled, (state, action) => {
const player = action.payload.player;
const originMsg = action.payload.originMsg; const originMsg = action.payload.originMsg;
const cardMeta = action.payload.cardMeta; const cardMeta = action.payload.cardMeta;
const location = action.payload.location; const location = action.payload.location;
const hint = judgeSelf(player, state) ? state.meHint : state.opHint; const hint = state.hint;
if (hint) { if (hint) {
let esHint = originMsg; let esHint = originMsg;
...@@ -165,5 +136,4 @@ export const hintCase = (builder: ActionReducerMapBuilder<DuelState>) => { ...@@ -165,5 +136,4 @@ export const hintCase = (builder: ActionReducerMapBuilder<DuelState>) => {
}); });
}; };
export const selectMeHint = (state: RootState) => state.duel.meHint; export const selectHint = (state: RootState) => state.duel.hint;
export const selectOpHint = (state: RootState) => state.duel.opHint;
...@@ -149,8 +149,7 @@ export interface DuelState { ...@@ -149,8 +149,7 @@ export interface DuelState {
meTimeLimit?: TimeLimit; // 自己的计时 meTimeLimit?: TimeLimit; // 自己的计时
opTimeLimit?: TimeLimit; // 对手的计时 opTimeLimit?: TimeLimit; // 对手的计时
meHint?: HintState; // 自己的提示 hint?: HintState;
opHint?: HintState; // 对手的提示
currentPlayer?: number; // 当前的操作方 currentPlayer?: number; // 当前的操作方
......
...@@ -7,15 +7,14 @@ import { ...@@ -7,15 +7,14 @@ import {
import MsgHint = ygopro.StocGameMessage.MsgHint; import MsgHint = ygopro.StocGameMessage.MsgHint;
export default (hint: MsgHint, dispatch: AppDispatch) => { export default (hint: MsgHint, dispatch: AppDispatch) => {
const player = hint.player;
switch (hint.hint_type) { switch (hint.hint_type) {
case MsgHint.HintType.HINT_EVENT: case MsgHint.HintType.HINT_EVENT:
case MsgHint.HintType.HINT_MESSAGE: { case MsgHint.HintType.HINT_MESSAGE: {
dispatch(fetchCommonHintMeta([player, hint.hint_data])); dispatch(fetchCommonHintMeta(hint.hint_data));
break; break;
} }
case MsgHint.HintType.HINT_SELECTMSG: { case MsgHint.HintType.HINT_SELECTMSG: {
dispatch(fetchSelectHintMeta({ player, selectHintData: hint.hint_data })); dispatch(fetchSelectHintMeta({ selectHintData: hint.hint_data }));
break; break;
} }
default: { default: {
......
...@@ -86,7 +86,6 @@ export default (selectChain: MsgSelectChain, dispatch: AppDispatch) => { ...@@ -86,7 +86,6 @@ export default (selectChain: MsgSelectChain, dispatch: AppDispatch) => {
} }
dispatch( dispatch(
fetchSelectHintMeta({ fetchSelectHintMeta({
player,
selectHintData: 203, selectHintData: 203,
}) })
); );
......
...@@ -46,6 +46,5 @@ export default ( ...@@ -46,6 +46,5 @@ export default (
dispatch(initDeck({ player: 1, deskSize: start.deckSize2 })); dispatch(initDeck({ player: 1, deskSize: start.deckSize2 }));
dispatch(initExclusion(0)); dispatch(initExclusion(0));
dispatch(initExclusion(1)); dispatch(initExclusion(1));
dispatch(initHint(0)); dispatch(initHint());
dispatch(initHint(1));
}; };
...@@ -22,7 +22,7 @@ import { ...@@ -22,7 +22,7 @@ import {
import { ThunderboltOutlined } from "@ant-design/icons"; import { ThunderboltOutlined } from "@ant-design/icons";
import NeosConfig from "../../../neos.config.json"; import NeosConfig from "../../../neos.config.json";
import DragModal from "./dragModal"; import DragModal from "./dragModal";
import { selectMeHint } from "../../reducers/duel/hintSlice"; import { selectHint } from "../../reducers/duel/hintSlice";
const CheckCardModal = () => { const CheckCardModal = () => {
const dispatch = store.dispatch; const dispatch = store.dispatch;
...@@ -34,7 +34,7 @@ const CheckCardModal = () => { ...@@ -34,7 +34,7 @@ const CheckCardModal = () => {
const cancelResponse = useAppSelector(selectCheckCardModalCacnelResponse); const cancelResponse = useAppSelector(selectCheckCardModalCacnelResponse);
const [response, setResponse] = useState<number[]>([]); const [response, setResponse] = useState<number[]>([]);
const defaultValue: number[] = []; const defaultValue: number[] = [];
const selectHint = useAppSelector(selectMeHint)?.esSelectHint || "请选择卡片"; const selectHintMsg = useAppSelector(selectHint)?.esSelectHint || "请选择卡片";
// TODO: 这里可以考虑更好地封装 // TODO: 这里可以考虑更好地封装
const sendResponseHandler = ( const sendResponseHandler = (
...@@ -57,7 +57,7 @@ const CheckCardModal = () => { ...@@ -57,7 +57,7 @@ const CheckCardModal = () => {
return ( return (
<DragModal <DragModal
title={`${selectHint} ${min}-${max}`} title={`${selectHintMsg} ${min}-${max}`}
open={isOpen} open={isOpen}
closable={false} closable={false}
footer={ footer={
......
...@@ -20,7 +20,7 @@ import { ...@@ -20,7 +20,7 @@ import {
} from "../../reducers/duel/mod"; } from "../../reducers/duel/mod";
import NeosConfig from "../../../neos.config.json"; import NeosConfig from "../../../neos.config.json";
import DragModal from "./dragModal"; import DragModal from "./dragModal";
import { selectMeHint } from "../../reducers/duel/hintSlice"; import { selectHint } from "../../reducers/duel/hintSlice";
const CheckCardModalV2 = () => { const CheckCardModalV2 = () => {
const dispatch = store.dispatch; const dispatch = store.dispatch;
...@@ -33,7 +33,7 @@ const CheckCardModalV2 = () => { ...@@ -33,7 +33,7 @@ const CheckCardModalV2 = () => {
); );
const selectedOptions = useAppSelector(selectCheckCardModalV2SelectedOptions); const selectedOptions = useAppSelector(selectCheckCardModalV2SelectedOptions);
const responseable = useAppSelector(selectCheckCardModalV2ResponseAble); const responseable = useAppSelector(selectCheckCardModalV2ResponseAble);
const selectHint = useAppSelector(selectMeHint)?.esSelectHint || "请选择卡片"; const selectHintMsg = useAppSelector(selectHint)?.esSelectHint || "请选择卡片";
const onFinishOrCancel = () => { const onFinishOrCancel = () => {
sendSelectUnselectCardResponse({ cancel_or_finish: true }); sendSelectUnselectCardResponse({ cancel_or_finish: true });
...@@ -44,7 +44,7 @@ const CheckCardModalV2 = () => { ...@@ -44,7 +44,7 @@ const CheckCardModalV2 = () => {
return ( return (
<DragModal <DragModal
title={`${selectHint} ${min}-${max}`} title={`${selectHintMsg} ${min}-${max}`}
open={isOpen} open={isOpen}
closable={false} closable={false}
footer={ footer={
......
...@@ -12,7 +12,7 @@ import { ...@@ -12,7 +12,7 @@ import {
import NeosConfig from "../../../neos.config.json"; import NeosConfig from "../../../neos.config.json";
import { selectCheckCardModalV3 } from "../../reducers/duel/modal/checkCardModalV3Slice"; import { selectCheckCardModalV3 } from "../../reducers/duel/modal/checkCardModalV3Slice";
import DragModal from "./dragModal"; import DragModal from "./dragModal";
import { selectMeHint } from "../../reducers/duel/hintSlice"; import { selectHint } from "../../reducers/duel/hintSlice";
const CheckCardModalV3 = () => { const CheckCardModalV3 = () => {
const dispatch = store.dispatch; const dispatch = store.dispatch;
...@@ -33,7 +33,7 @@ const CheckCardModalV3 = () => { ...@@ -33,7 +33,7 @@ const CheckCardModalV3 = () => {
.concat(selectedOptions) .concat(selectedOptions)
.map((option) => option.level2) .map((option) => option.level2)
.reduce((sum, current) => sum + current, 0); .reduce((sum, current) => sum + current, 0);
const selectHint = useAppSelector(selectMeHint)?.esSelectHint || "请选择卡片"; const selectHintMsg = useAppSelector(selectHint)?.esSelectHint || "请选择卡片";
const responseable = const responseable =
(overflow (overflow
...@@ -52,7 +52,7 @@ const CheckCardModalV3 = () => { ...@@ -52,7 +52,7 @@ const CheckCardModalV3 = () => {
return ( return (
<DragModal <DragModal
title={`${selectHint} ${min}-${max}`} title={`${selectHintMsg} ${min}-${max}`}
open={isOpen} open={isOpen}
closable={false} closable={false}
footer={ footer={
......
import React, { useEffect } from "react"; import React, { useEffect } from "react";
import { useAppSelector } from "../../hook"; import { useAppSelector } from "../../hook";
import { selectMeHint, selectOpHint } from "../../reducers/duel/hintSlice"; import { selectHint } from "../../reducers/duel/hintSlice";
import { selectCurrentPhase } from "../../reducers/duel/phaseSlice"; import { selectCurrentPhase } from "../../reducers/duel/phaseSlice";
import { notification } from "antd"; import { notification } from "antd";
import { selectDuelResult, selectWaiting } from "../../reducers/duel/mod"; import { selectDuelResult, selectWaiting } from "../../reducers/duel/mod";
...@@ -10,8 +10,7 @@ import MsgWin = ygopro.StocGameMessage.MsgWin; ...@@ -10,8 +10,7 @@ import MsgWin = ygopro.StocGameMessage.MsgWin;
import NeosConfig from "../../../neos.config.json"; import NeosConfig from "../../../neos.config.json";
const HintNotification = () => { const HintNotification = () => {
const meHint = useAppSelector(selectMeHint); const hint = useAppSelector(selectHint);
const opHint = useAppSelector(selectOpHint);
const currentPhase = useAppSelector(selectCurrentPhase); const currentPhase = useAppSelector(selectCurrentPhase);
const waiting = useAppSelector(selectWaiting); const waiting = useAppSelector(selectWaiting);
const result = useAppSelector(selectDuelResult); const result = useAppSelector(selectDuelResult);
...@@ -21,22 +20,13 @@ const HintNotification = () => { ...@@ -21,22 +20,13 @@ const HintNotification = () => {
maxCount: NeosConfig.ui.hint.maxCount, maxCount: NeosConfig.ui.hint.maxCount,
}); });
useEffect(() => { useEffect(() => {
if (meHint && meHint.msg) { if (hint && hint.msg) {
api.info({ api.info({
message: `<我方>${meHint.msg}`, message: `${hint.msg}`,
placement: "bottom",
});
}
}, [meHint?.msg]);
useEffect(() => {
if (opHint && opHint.msg) {
api.info({
message: `<对方>${opHint.msg}`,
placement: "top", placement: "top",
}); });
} }
}, [opHint?.msg]); }, [hint?.msg]);
useEffect(() => { useEffect(() => {
if (currentPhase) { if (currentPhase) {
......
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