Commit e4a8fd43 authored by Chunchi Che's avatar Chunchi Che

fix win

parent 1b7350d2
......@@ -12,18 +12,11 @@ import MsgWin = ygopro.StocGameMessage.MsgWin;
export default (data: Uint8Array) => {
const reader = new BufferReader(data);
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;
const win_player = reader.readUint8();
const reason = reader.readUint8();
return new MsgWin({
player,
type_,
win_player,
reason,
});
};
import { ygopro } from "@/api";
import { fetchStrings, ygopro } from "@/api";
import { matStore } from "@/stores";
import MsgWin = ygopro.StocGameMessage.MsgWin;
export default (win: MsgWin) => {
const player = win.player;
if (matStore.isMe(player)) {
matStore.result = win.type_;
} else {
matStore.result =
win.type_ == MsgWin.ActionType.Win
? MsgWin.ActionType.Defeated
: MsgWin.ActionType.Win;
}
const { win_player, reason } = win;
matStore.result = {
isWin: matStore.isMe(win_player),
reason: fetchStrings("!victory", reason),
};
};
......@@ -80,7 +80,6 @@ export const matStore: MatState = proxy<MatState>({
enableM2: false, // 允许进入M2阶段
enableEp: false, // 允许回合结束
},
result: ygopro.StocGameMessage.MsgWin.ActionType.UNKNOWN,
waiting: false,
unimplemented: 0,
// methods
......
......@@ -28,7 +28,10 @@ export interface MatState {
phase: PhaseState;
result: ygopro.StocGameMessage.MsgWin.ActionType;
result?: {
isWin: boolean;
reason: string;
};
waiting: boolean;
......
......@@ -2,7 +2,7 @@ import { notification } from "antd";
import React, { useEffect } from "react";
import { useSnapshot } from "valtio";
import { fetchStrings, ygopro } from "@/api";
import { fetchStrings } from "@/api";
import { Phase2StringCodeMap } from "@/common";
import { useConfig } from "@/config";
import { matStore } from "@/stores";
......@@ -13,8 +13,6 @@ const style = {
backgroundColor: "#303030",
};
const MsgWin = ygopro.StocGameMessage.MsgWin;
const NeosConfig = useConfig();
export const HintNotification = () => {
const snap = useSnapshot(matStore);
......@@ -67,12 +65,7 @@ export const HintNotification = () => {
useEffect(() => {
if (result) {
const message =
result == MsgWin.ActionType.Win
? "胜利"
: MsgWin.ActionType.Defeated
? "失败"
: "未知结果";
const message = result.isWin ? "胜利" : "失败" + " " + result.reason;
api.open({
message,
placement: "bottom",
......
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