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