Commit a6668f06 authored by Chunchi Che's avatar Chunchi Che

update hint

parent 359b0289
...@@ -4,13 +4,38 @@ import { RootState } from "../../store"; ...@@ -4,13 +4,38 @@ import { RootState } from "../../store";
import { DESCRIPTION_LIMIT, fetchStrings, getStrings } from "../../api/strings"; import { DESCRIPTION_LIMIT, fetchStrings, getStrings } from "../../api/strings";
import { judgeSelf } from "./util"; import { judgeSelf } from "./util";
import { fetchCard } from "../../api/cards"; import { fetchCard } from "../../api/cards";
import { DuelReducer } from "./generic";
export interface HintState { export interface HintState {
code: number; code: number;
msg?: string; msg?: string;
esHint?: string;
esSelectHint?: string; esSelectHint?: string;
} }
export const initHintImpl: DuelReducer<number> = (state, action) => {
const player = action.payload;
if (judgeSelf(player, state)) {
state.meHint = { code: 0 };
} else {
state.opHint = { code: 0 };
}
};
export const setEsHintImpl: DuelReducer<{ player: number; esHint: string }> = (
state,
action
) => {
const player = action.payload.player;
const esHint = action.payload.esHint;
const hint = judgeSelf(player, state) ? state.meHint : state.opHint;
if (hint) {
hint.esHint = esHint;
}
};
export const fetchCommonHintMeta = createAsyncThunk( export const fetchCommonHintMeta = createAsyncThunk(
"duel/fetchCommonHintMeta", "duel/fetchCommonHintMeta",
async (param: [number, number]) => { async (param: [number, number]) => {
...@@ -26,24 +51,31 @@ export const fetchCommonHintMeta = createAsyncThunk( ...@@ -26,24 +51,31 @@ export const fetchCommonHintMeta = createAsyncThunk(
export const fetchSelectHintMeta = createAsyncThunk( export const fetchSelectHintMeta = createAsyncThunk(
"duel/fetchSelectHintMeta", "duel/fetchSelectHintMeta",
async (param: [number, number]) => { async (param: {
const player = param[0]; player: number;
const hintData = param[1]; selectHintData: number;
esHint?: string;
}) => {
const player = param.player;
const selectHintData = param.selectHintData;
let hintMeta = ""; let selectHintMeta = "";
if (hintData > DESCRIPTION_LIMIT) { if (selectHintData > DESCRIPTION_LIMIT) {
// 针对`MSG_SELECT_PLACE`的特化逻辑 // 针对`MSG_SELECT_PLACE`的特化逻辑
const cardMeta = await fetchCard(hintData, true); const cardMeta = await fetchCard(selectHintData, true);
hintMeta = fetchStrings("!system", 569).replace( selectHintMeta = fetchStrings("!system", 569).replace(
"[%ls]", "[%ls]",
cardMeta.text.name || "[?]" cardMeta.text.name || "[?]"
); );
} else { } else {
hintMeta = await getStrings(hintData); selectHintMeta = await getStrings(selectHintData);
} }
const response: [number, string] = [player, hintMeta]; return {
return response; player,
selectHintMeta,
esHint: param.esHint,
};
} }
); );
...@@ -69,26 +101,27 @@ export const hintCase = (builder: ActionReducerMapBuilder<DuelState>) => { ...@@ -69,26 +101,27 @@ export const hintCase = (builder: ActionReducerMapBuilder<DuelState>) => {
}); });
builder.addCase(fetchSelectHintMeta.pending, (state, action) => { builder.addCase(fetchSelectHintMeta.pending, (state, action) => {
const player = action.meta.arg[0]; const player = action.meta.arg.player;
const code = action.meta.arg[1]; const code = action.meta.arg.selectHintData;
if (judgeSelf(player, state)) { const hint = judgeSelf(player, state) ? state.meHint : state.opHint;
state.meHint = { code }; if (hint) {
} else { hint.code = code;
state.opHint = { code };
} }
}); });
builder.addCase(fetchSelectHintMeta.fulfilled, (state, action) => { builder.addCase(fetchSelectHintMeta.fulfilled, (state, action) => {
const player = action.payload[0]; const player = action.payload.player;
let hintMsg = action.payload[1]; const selectHintMsg = action.payload.selectHintMeta;
const esHint = action.payload.esHint;
const hint = judgeSelf(player, state) ? state.meHint : state.opHint; const hint = judgeSelf(player, state) ? state.meHint : state.opHint;
if (hint) { if (hint) {
if (hint.code > DESCRIPTION_LIMIT) { if (hint.code > DESCRIPTION_LIMIT) {
// 针对`MSG_SELECT_PLACE`的特化逻辑 // 针对`MSG_SELECT_PLACE`的特化逻辑
hint.msg = hintMsg; hint.msg = selectHintMsg;
} else { } else {
hint.esSelectHint = hintMsg; hint.esSelectHint = selectHintMsg;
if (esHint) hint.esHint = esHint;
} }
} }
}); });
......
...@@ -23,7 +23,7 @@ import { ...@@ -23,7 +23,7 @@ import {
setEnableEpImpl, setEnableEpImpl,
} from "./phaseSlice"; } from "./phaseSlice";
import { RootState } from "../../store"; import { RootState } from "../../store";
import { HintState, hintCase } from "./hintSlice"; import { HintState, hintCase, initHintImpl, setEsHintImpl } from "./hintSlice";
import { import {
ModalState, ModalState,
setCardModalIsOpenImpl, setCardModalIsOpenImpl,
...@@ -296,6 +296,10 @@ const duelSlice = createSlice({ ...@@ -296,6 +296,10 @@ const duelSlice = createSlice({
setSortCardModalIsOpen: setSortCardModalIsOpenImpl, setSortCardModalIsOpen: setSortCardModalIsOpenImpl,
resetSortCardModal: resetSortCardModalImpl, resetSortCardModal: resetSortCardModalImpl,
// 提示相关`Reducer`
initHint: initHintImpl,
setEsHint: setEsHintImpl,
// 通用的`Reducer` // 通用的`Reducer`
clearAllIdleInteractivities: clearAllIdleInteractivitiesImpl, clearAllIdleInteractivities: clearAllIdleInteractivitiesImpl,
clearAllPlaceInteractivities: clearAllPlaceInteractivitiesImpl, clearAllPlaceInteractivities: clearAllPlaceInteractivitiesImpl,
...@@ -413,6 +417,8 @@ export const { ...@@ -413,6 +417,8 @@ export const {
clearCheckCounter, clearCheckCounter,
setSortCardModalIsOpen, setSortCardModalIsOpen,
resetSortCardModal, resetSortCardModal,
initHint,
setEsHint,
} = duelSlice.actions; } = duelSlice.actions;
export const selectDuelHsStart = (state: RootState) => { export const selectDuelHsStart = (state: RootState) => {
return state.duel.meInitInfo != null; return state.duel.meInitInfo != null;
......
...@@ -15,7 +15,7 @@ export default (hint: MsgHint, dispatch: AppDispatch) => { ...@@ -15,7 +15,7 @@ export default (hint: MsgHint, dispatch: AppDispatch) => {
break; break;
} }
case MsgHint.HintType.HINT_SELECTMSG: { case MsgHint.HintType.HINT_SELECTMSG: {
dispatch(fetchSelectHintMeta([player, hint.hint_data])); dispatch(fetchSelectHintMeta({ player, selectHintData: hint.hint_data }));
break; break;
} }
default: { default: {
......
...@@ -84,7 +84,12 @@ export default (selectChain: MsgSelectChain, dispatch: AppDispatch) => { ...@@ -84,7 +84,12 @@ export default (selectChain: MsgSelectChain, dispatch: AppDispatch) => {
}) })
); );
} }
dispatch(fetchSelectHintMeta([player, 203])); dispatch(
fetchSelectHintMeta({
player,
selectHintData: 203,
})
);
dispatch(setCheckCardModalIsOpen(true)); dispatch(setCheckCardModalIsOpen(true));
......
...@@ -8,6 +8,7 @@ import { ...@@ -8,6 +8,7 @@ import {
initCemetery, initCemetery,
initDeck, initDeck,
initExclusion, initExclusion,
initHint,
} from "../../reducers/duel/mod"; } from "../../reducers/duel/mod";
export default ( export default (
...@@ -45,4 +46,6 @@ export default ( ...@@ -45,4 +46,6 @@ 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(1));
}; };
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