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;
export const MSG_DAMAGE = 91;
export const MSG_RECOVER = 92;
export const MSG_PAY_LP_COST = 100;
export const MSG_WIN = 5;
......@@ -22,6 +22,7 @@ import MsgSelectBattleCmdAdapter from "./selectBattleCmd";
import MsgSelectUnselectCardAdapter from "./selectUnselectCard";
import MsgDamage from "./damage";
import MsgRecover from "./recover";
import MsgWin from "./win";
import PENETRATE from "./penetrate";
/*
......@@ -130,6 +131,11 @@ export default class GameMsgAdapter implements StocAdapter {
break;
}
case GAME_MSG.MSG_WIN: {
gameMsg.win = MsgWin(gameData);
break;
}
default: {
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 @@
*
* */
import { ygopro } from "../../api/ocgcore/idl/ocgcore";
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { InitInfo, infoInitImpl, updateHpImpl } from "./initInfoSlice";
import { TimeLimit, updateTimeLimitImpl } from "./timeLimit";
......@@ -102,6 +103,7 @@ import {
removeExtraDeckImpl,
addExtraDeckIdleInteractivitiesImpl,
} from "./extraDeckSlice";
import MsgWin = ygopro.StocGameMessage.MsgWin;
export interface DuelState {
selfType?: number;
......@@ -139,6 +141,8 @@ export interface DuelState {
phase?: PhaseState;
result?: MsgWin.ActionType;
// UI相关
modalState: ModalState;
}
......@@ -250,6 +254,11 @@ const duelSlice = createSlice({
// 通用的`Reducer`
clearAllIdleInteractivities: clearAllIdleInteractivitiesImpl,
clearAllPlaceInteractivities: clearAllPlaceInteractivitiesImpl,
// 对局结果`Reducer`
setResult: (state, action: PayloadAction<MsgWin.ActionType>) => {
state.result = action.payload;
},
},
extraReducers(builder) {
handsCase(builder);
......@@ -329,8 +338,12 @@ export const {
setCheckCardModalV2ResponseAble,
clearAllIdleInteractivities,
clearAllPlaceInteractivities,
setResult,
} = duelSlice.actions;
export const selectDuelHsStart = (state: RootState) => {
return state.duel.meInitInfo != null;
};
export const selectDuelResult = (state: RootState) => {
return state.duel.result;
};
export default duelSlice.reducer;
......@@ -19,6 +19,7 @@ import onMsgPosChange from "./posChange";
import onMsgSelectUnselectCard from "./selectUnselectCard";
import onMsgSelectYesNo from "./selectYesNo";
import onMsgUpdateHp from "./updateHp";
import onMsgWin from "./win";
export default function handleGameMsg(pb: ygopro.YgoStocMsg) {
const dispatch = store.dispatch;
......@@ -120,6 +121,11 @@ export default function handleGameMsg(pb: ygopro.YgoStocMsg) {
break;
}
case "win": {
onMsgWin(msg.win, dispatch);
break;
}
default: {
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";
import { selectMeHint, selectOpHint } from "../../reducers/duel/hintSlice";
import { selectCurrentPhase } from "../../reducers/duel/phaseSlice";
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 meHint = useAppSelector(selectMeHint);
const opHint = useAppSelector(selectOpHint);
const currentPhase = useAppSelector(selectCurrentPhase);
const result = useAppSelector(selectDuelResult);
const navigate = useNavigate();
const [api, contextHolder] = notification.useNotification();
useEffect(() => {
......@@ -37,6 +43,24 @@ const HintNotification = () => {
}
}, [currentPhase]);
useEffect(() => {
if (result) {
const message =
result == MsgWin.ActionType.Win
? "胜利"
: MsgWin.ActionType.Defeated
? "失败"
: "未知结果";
api.info({
message,
placement: "bottom",
onClose() {
navigate("/");
},
});
}
}, [result]);
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