Commit 3c556ab0 authored by Chunchi Che's avatar Chunchi Che

Merge branch 'feat/win' into 'main'

Feat/win

See merge request !124
parents b8cdf42f cb5d129e
Pipeline #20563 passed with stages
in 6 minutes and 56 seconds
Subproject commit 43cd7f197670493f58f648e52fb49f918e12803a Subproject commit 6434c30b91cc28627fff3a7266c69b5b4e83d3aa
This diff is collapsed.
...@@ -45,3 +45,4 @@ export const MSG_SELECT_UNSELECT_CARD = 26; ...@@ -45,3 +45,4 @@ export const MSG_SELECT_UNSELECT_CARD = 26;
export const MSG_DAMAGE = 91; export const MSG_DAMAGE = 91;
export const MSG_RECOVER = 92; export const MSG_RECOVER = 92;
export const MSG_PAY_LP_COST = 100; export const MSG_PAY_LP_COST = 100;
export const MSG_WIN = 5;
...@@ -22,6 +22,7 @@ import MsgSelectBattleCmdAdapter from "./selectBattleCmd"; ...@@ -22,6 +22,7 @@ import MsgSelectBattleCmdAdapter from "./selectBattleCmd";
import MsgSelectUnselectCardAdapter from "./selectUnselectCard"; import MsgSelectUnselectCardAdapter from "./selectUnselectCard";
import MsgDamage from "./damage"; import MsgDamage from "./damage";
import MsgRecover from "./recover"; import MsgRecover from "./recover";
import MsgWin from "./win";
import PENETRATE from "./penetrate"; import PENETRATE from "./penetrate";
/* /*
...@@ -130,6 +131,11 @@ export default class GameMsgAdapter implements StocAdapter { ...@@ -130,6 +131,11 @@ export default class GameMsgAdapter implements StocAdapter {
break; break;
} }
case GAME_MSG.MSG_WIN: {
gameMsg.win = MsgWin(gameData);
break;
}
default: { default: {
console.log("Unhandled GameMessage function=", func); console.log("Unhandled GameMessage function=", func);
......
import { ygopro } from "../../../idl/ocgcore";
import { BufferReader } from "../../bufferIO";
import MsgWin = ygopro.StocGameMessage.MsgWin;
/*
* Msg Win
*
* @param player - 玩家编号
* @param winType - 结果类型
* */
export default (data: Uint8Array) => {
const reader = new BufferReader(data, true);
const player = reader.readUint8();
const winType = reader.readUint8();
const type_ =
player == 0 || winType == 4
? MsgWin.ActionType.Win
: player == 1
? MsgWin.ActionType.Defeated
: MsgWin.ActionType.UNKNOWN;
return new MsgWin({
player,
type_,
});
};
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
* *
* */ * */
import { ygopro } from "../../api/ocgcore/idl/ocgcore";
import { createSlice, PayloadAction } from "@reduxjs/toolkit"; import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { InitInfo, infoInitImpl, updateHpImpl } from "./initInfoSlice"; import { InitInfo, infoInitImpl, updateHpImpl } from "./initInfoSlice";
import { TimeLimit, updateTimeLimitImpl } from "./timeLimit"; import { TimeLimit, updateTimeLimitImpl } from "./timeLimit";
...@@ -102,6 +103,7 @@ import { ...@@ -102,6 +103,7 @@ import {
removeExtraDeckImpl, removeExtraDeckImpl,
addExtraDeckIdleInteractivitiesImpl, addExtraDeckIdleInteractivitiesImpl,
} from "./extraDeckSlice"; } from "./extraDeckSlice";
import MsgWin = ygopro.StocGameMessage.MsgWin;
export interface DuelState { export interface DuelState {
selfType?: number; selfType?: number;
...@@ -139,6 +141,8 @@ export interface DuelState { ...@@ -139,6 +141,8 @@ export interface DuelState {
phase?: PhaseState; phase?: PhaseState;
result?: MsgWin.ActionType;
// UI相关 // UI相关
modalState: ModalState; modalState: ModalState;
} }
...@@ -250,6 +254,11 @@ const duelSlice = createSlice({ ...@@ -250,6 +254,11 @@ const duelSlice = createSlice({
// 通用的`Reducer` // 通用的`Reducer`
clearAllIdleInteractivities: clearAllIdleInteractivitiesImpl, clearAllIdleInteractivities: clearAllIdleInteractivitiesImpl,
clearAllPlaceInteractivities: clearAllPlaceInteractivitiesImpl, clearAllPlaceInteractivities: clearAllPlaceInteractivitiesImpl,
// 对局结果`Reducer`
setResult: (state, action: PayloadAction<MsgWin.ActionType>) => {
state.result = action.payload;
},
}, },
extraReducers(builder) { extraReducers(builder) {
handsCase(builder); handsCase(builder);
...@@ -329,8 +338,12 @@ export const { ...@@ -329,8 +338,12 @@ export const {
setCheckCardModalV2ResponseAble, setCheckCardModalV2ResponseAble,
clearAllIdleInteractivities, clearAllIdleInteractivities,
clearAllPlaceInteractivities, clearAllPlaceInteractivities,
setResult,
} = duelSlice.actions; } = duelSlice.actions;
export const selectDuelHsStart = (state: RootState) => { export const selectDuelHsStart = (state: RootState) => {
return state.duel.meInitInfo != null; return state.duel.meInitInfo != null;
}; };
export const selectDuelResult = (state: RootState) => {
return state.duel.result;
};
export default duelSlice.reducer; export default duelSlice.reducer;
...@@ -19,6 +19,7 @@ import onMsgPosChange from "./posChange"; ...@@ -19,6 +19,7 @@ import onMsgPosChange from "./posChange";
import onMsgSelectUnselectCard from "./selectUnselectCard"; import onMsgSelectUnselectCard from "./selectUnselectCard";
import onMsgSelectYesNo from "./selectYesNo"; import onMsgSelectYesNo from "./selectYesNo";
import onMsgUpdateHp from "./updateHp"; import onMsgUpdateHp from "./updateHp";
import onMsgWin from "./win";
export default function handleGameMsg(pb: ygopro.YgoStocMsg) { export default function handleGameMsg(pb: ygopro.YgoStocMsg) {
const dispatch = store.dispatch; const dispatch = store.dispatch;
...@@ -120,6 +121,11 @@ export default function handleGameMsg(pb: ygopro.YgoStocMsg) { ...@@ -120,6 +121,11 @@ export default function handleGameMsg(pb: ygopro.YgoStocMsg) {
break; break;
} }
case "win": {
onMsgWin(msg.win, dispatch);
break;
}
default: { default: {
break; break;
} }
......
import { ygopro } from "../../api/ocgcore/idl/ocgcore";
import { setResult } from "../../reducers/duel/mod";
import { AppDispatch } from "../../store";
export default (win: ygopro.StocGameMessage.MsgWin, dispatch: AppDispatch) => {
dispatch(setResult(win.type_));
};
...@@ -3,11 +3,17 @@ import { useAppSelector } from "../../hook"; ...@@ -3,11 +3,17 @@ import { useAppSelector } from "../../hook";
import { selectMeHint, selectOpHint } from "../../reducers/duel/hintSlice"; import { selectMeHint, selectOpHint } 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 } from "../../reducers/duel/mod";
import { useNavigate } from "react-router-dom";
import { ygopro } from "../../api/ocgcore/idl/ocgcore";
import MsgWin = ygopro.StocGameMessage.MsgWin;
const HintNotification = () => { const HintNotification = () => {
const meHint = useAppSelector(selectMeHint); const meHint = useAppSelector(selectMeHint);
const opHint = useAppSelector(selectOpHint); const opHint = useAppSelector(selectOpHint);
const currentPhase = useAppSelector(selectCurrentPhase); const currentPhase = useAppSelector(selectCurrentPhase);
const result = useAppSelector(selectDuelResult);
const navigate = useNavigate();
const [api, contextHolder] = notification.useNotification(); const [api, contextHolder] = notification.useNotification();
useEffect(() => { useEffect(() => {
...@@ -37,6 +43,24 @@ const HintNotification = () => { ...@@ -37,6 +43,24 @@ const HintNotification = () => {
} }
}, [currentPhase]); }, [currentPhase]);
useEffect(() => {
if (result) {
const message =
result == MsgWin.ActionType.Win
? "胜利"
: MsgWin.ActionType.Defeated
? "失败"
: "未知结果";
api.info({
message,
placement: "bottom",
onClose() {
navigate("/");
},
});
}
}, [result]);
return <>{contextHolder}</>; return <>{contextHolder}</>;
}; };
......
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