Commit 93bd20cc authored by Chunchi Che's avatar Chunchi Che

Merge branch 'feat/duel_end' into 'main'

增加优雅退出机制

See merge request mycard/Neos!306
parents addbb292 d0a0a652
Pipeline #23426 passed with stages
in 12 minutes and 43 seconds
neos-protobuf @ 702feb50
Subproject commit a02a8caa38767bb06e1a9d5be97773af5a0fc4b2
Subproject commit 702feb507a3e5cd31fdc8ee7d9e4b80e68f89923
This diff is collapsed.
......@@ -4,6 +4,7 @@ import {
STOC_CHANGE_SIDE,
STOC_CHAT,
STOC_DECK_COUNT,
STOC_DUEL_END,
STOC_DUEL_START,
STOC_ERROR_MSG,
STOC_GAME_MSG,
......@@ -21,6 +22,7 @@ import {
import StocChangeSide from "./stoc/stocChangeSide";
import StocChat from "./stoc/stocChat";
import StocDeckCount from "./stoc/stocDeckCount";
import StocDuelEnd from "./stoc/stocDuelEnd";
import StocDuelStart from "./stoc/stocDuelStart";
import StocErrorMsg from "./stoc/stocErrorMsg";
import StocGameMsg from "./stoc/stocGameMsg/mod";
......@@ -89,6 +91,10 @@ export function adaptStoc(packet: YgoProPacket): ygopro.YgoStocMsg {
pb = new StocDuelStart(packet).upcast();
break;
}
case STOC_DUEL_END: {
pb = new StocDuelEnd(packet).upcast();
break;
}
case STOC_GAME_MSG: {
pb = new StocGameMsg(packet).upcast();
break;
......
......@@ -28,6 +28,7 @@ export const STOC_SELECT_TP = 4;
export const STOC_HAND_RESULT = 5;
export const STOC_DECK_COUNT = 9;
export const STOC_DUEL_START = 21;
export const STOC_DUEL_END = 22;
export const STOC_GAME_MSG = 1;
export const STOC_TIME_LIMIT = 24;
export const STOC_ERROR_MSG = 2;
......
import { ygopro } from "../../idl/ocgcore";
import { StocAdapter, YgoProPacket } from "../packet";
/*
* STOC DuelEnd
*
* @usage - 通知客户端决斗结束
* */
export default class DuelEnd implements StocAdapter {
packet: YgoProPacket;
constructor(packet: YgoProPacket) {
this.packet = packet;
}
upcast(): ygopro.YgoStocMsg {
return new ygopro.YgoStocMsg({
stoc_duel_end: new ygopro.StocDuelEnd({}),
});
}
}
......@@ -12,6 +12,7 @@ import handleDeckCount from "./mora/deckCount";
import handleSelectHand from "./mora/selectHand";
import handleSelectTp from "./mora/selectTp";
import handleChat from "./room/chat";
import handleDuelEnd from "./room/duelEnd";
import handleDuelStart from "./room/duelStart";
import handleErrorMsg from "./room/errorMsg";
import handleHandResult from "./room/handResult";
......@@ -85,6 +86,10 @@ async function _handle(e: MessageEvent) {
handleDuelStart(pb);
break;
}
case "stoc_duel_end": {
handleDuelEnd(pb);
break;
}
case "stoc_game_msg": {
await handleGameMsg(pb);
......
import { ygopro } from "@/api";
import { matStore } from "@/stores";
export default function handleDuelEnd(_pb: ygopro.YgoStocMsg) {
matStore.duelEnd = true;
}
......@@ -85,6 +85,7 @@ const initialState: Omit<MatState, "reset"> = {
},
tossResult: undefined,
chainSetting: ChainSetting.CHAIN_SMART,
duelEnd: false,
// methods
isMe,
};
......@@ -102,6 +103,7 @@ class MatStore implements MatState, NeosStore {
unimplemented = initialState.unimplemented;
handResults = initialState.handResults;
tossResult = initialState.tossResult;
duelEnd = initialState.duelEnd;
// methods
isMe = initialState.isMe;
reset(): void {
......@@ -123,6 +125,7 @@ class MatStore implements MatState, NeosStore {
this.unimplemented = 0;
this.handResults.me = 0;
this.handResults.op = 0;
this.duelEnd = false;
}
}
......
......@@ -40,6 +40,8 @@ export interface MatState {
set: (controller: number, result: HandResult) => void;
}; // 猜拳结果
duelEnd: boolean; // 决斗是否结束,包括单局模式和匹配模式
/** 根据自己的先后手判断是否是自己 */
isMe: (player: number) => boolean;
}
......
......@@ -2,7 +2,7 @@ import React, { useEffect } from "react";
import { useNavigate } from "react-router-dom";
import { useSnapshot } from "valtio";
import { SideStage, sideStore } from "@/stores";
import { matStore, SideStage, sideStore } from "@/stores";
import {
Alert,
......@@ -22,6 +22,7 @@ import { LifeBar, Mat, Menu, Underlying } from "./PlayMat";
export const Component: React.FC = () => {
const { stage } = useSnapshot(sideStore);
const { duelEnd } = useSnapshot(matStore);
const navigate = useNavigate();
useEffect(() => {
......@@ -31,6 +32,13 @@ export const Component: React.FC = () => {
}
}, [stage]);
useEffect(() => {
if (duelEnd) {
// 决斗结束,返回匹配页
navigate("/match");
}
}, [duelEnd]);
return (
<>
<Underlying />
......
......@@ -27,7 +27,6 @@ export const EndModal: React.FC = () => {
const onReturn = () => {
resetDuel();
rs();
// TODO: 这里暂时不自动跳转,决斗结束后让玩家自己手动选择回到主页
};
return (
......
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