Commit a35b15b6 authored by Chunchi Che's avatar Chunchi Che

finish handleErrorMsg

parent 89cf7e40
Pipeline #23131 passed with stages
in 14 minutes and 25 seconds
......@@ -90,7 +90,7 @@ export default async function handleSocketMessage(e: MessageEvent) {
break;
}
case "stoc_error_msg": {
handleErrorMsg(pb.stoc_error_msg);
await handleErrorMsg(pb.stoc_error_msg);
break;
}
default: {
......
import { ygopro } from "@/api";
import { fetchCard, fetchStrings, Region, ygopro } from "@/api";
import { roomStore } from "@/stores";
import ErrorType = ygopro.StocErrorMsg.ErrorType;
export default function handleErrorMsg(errorMsg: ygopro.StocErrorMsg) {
console.log(errorMsg);
// TODO: 是时候需要一个统一管理国际化文案的模块了
const DECKERROR_LFLIST = 0x1;
const DECKERROR_OCGONLY = 0x2;
const DECKERROR_TCGONLY = 0x3;
const DECKERROR_UNKNOWNCARD = 0x4;
const DECKERROR_CARDCOUNT = 0x5;
const DECKERROR_MAINCOUNT = 0x6;
const DECKERROR_EXTRACOUNT = 0x7;
const DECKERROR_SIDECOUNT = 0x8;
const DECKERROR_NOTAVAIL = 0x9;
export default async function handleErrorMsg(errorMsg: ygopro.StocErrorMsg) {
const { error_type, error_code } = errorMsg;
switch (error_type) {
case ErrorType.JOINERROR: {
roomStore.errorMsg = fetchStrings(Region.System, 1403 + error_code);
break;
}
case ErrorType.DECKERROR: {
const flag = error_code >> 28;
const code = error_code && 0xfffffff;
const card = await fetchCard(code);
const baseMsg = `卡组非法,请检查:${card.text.name}`;
switch (flag) {
case DECKERROR_LFLIST: {
roomStore.errorMsg = baseMsg + "(数量不符合禁限卡表)";
break;
}
case DECKERROR_OCGONLY: {
roomStore.errorMsg = baseMsg + "(OCG独有卡,不能在当前设置使用)";
break;
}
case DECKERROR_TCGONLY: {
roomStore.errorMsg = baseMsg + "(TCG独有卡,不能在当前设置使用)";
break;
}
case DECKERROR_UNKNOWNCARD: {
if (code < 100000000) {
roomStore.errorMsg =
baseMsg + "(服务器无法识别此卡,可能是服务器未更新)";
} else {
roomStore.errorMsg =
baseMsg +
"(服务器无法识别此卡,可能是服务器不支持先行卡或此先行卡已正式更新)";
}
break;
}
case DECKERROR_CARDCOUNT: {
roomStore.errorMsg = baseMsg + "(数量过多)";
break;
}
case DECKERROR_MAINCOUNT: {
roomStore.errorMsg = "主卡组数量应为40-60张";
break;
}
case DECKERROR_EXTRACOUNT: {
roomStore.errorMsg = "额外卡组数量应为0-15张";
break;
}
case DECKERROR_SIDECOUNT: {
roomStore.errorMsg = "副卡组数量应为0-15张";
break;
}
case DECKERROR_NOTAVAIL: {
roomStore.errorMsg = `${card.text.name}不允许在当前设置下使用。`;
break;
}
default: {
roomStore.errorMsg = fetchStrings(Region.System, 1406);
break;
}
}
break;
}
case ErrorType.SIDEERROR: {
roomStore.errorMsg = "更换副卡组失败,请检查卡片张数是否一致。";
break;
}
case ErrorType.VERSIONERROR: {
roomStore.errorMsg = "版本不匹配,请联系技术人员解决";
break;
}
default:
break;
}
}
......@@ -41,8 +41,8 @@ class RoomStore implements NeosStore {
observerCount: number = 0; // 观战者数量
isHost: boolean = false; // 当前玩家是否是房主
selfType: SelfType = 0; // 当前玩家的类型
stage: RoomStage = RoomStage.WAITING;
errorMsg?: string = undefined; // 错误信息
getMePlayer() {
return this.players.find((player) => player?.isMe);
......@@ -57,6 +57,7 @@ class RoomStore implements NeosStore {
this.observerCount = 0;
this.isHost = false;
this.stage = RoomStage.WAITING;
this.errorMsg = undefined;
}
}
......
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