Commit f0dd5248 authored by chechunchi's avatar chechunchi

handle RockPaperScissors

parent 8988e67a
......@@ -330,7 +330,7 @@ async function _handleGameMsg(pb: ygopro.YgoStocMsg) {
break;
}
case "rock_paper_scissors": {
onMsgRockPaperScissors(msg.rock_paper_scissors);
await onMsgRockPaperScissors(msg.rock_paper_scissors);
break;
}
......
import { ygopro } from "@/api";
import { displayOptionModal } from "@/ui/Duel/Message";
export default (mora: ygopro.StocGameMessage.MsgRockPaperScissors) => {
console.log(mora);
// TODO
export default async (mora: ygopro.StocGameMessage.MsgRockPaperScissors) => {
const _player = mora.player;
// TODO: I18n
await displayOptionModal("请选择猜拳", [
{ msg: "剪刀", response: 1 },
{ msg: "石头", response: 2 },
{ msg: "", response: 3 },
]);
};
import { fetchCard, getCardStr, ygopro } from "@/api";
import { fetchCard, fetchStrings, getCardStr, ygopro } from "@/api";
import MsgSelectOption = ygopro.StocGameMessage.MsgSelectOption;
import { displayOptionModal } from "@/ui/Duel/Message";
export default async (selectOption: MsgSelectOption) => {
const options = selectOption.options;
await displayOptionModal(
fetchStrings("!system", 556),
await Promise.all(
options.map(async ({ code, response }) => {
const meta = await fetchCard(code >> 4);
......
......@@ -5,6 +5,7 @@ import { proxy, useSnapshot } from "valtio";
import {
type CardMeta,
fetchStrings,
getCardStr,
sendSelectIdleCmdResponse,
sendSelectOptionResponse,
......@@ -15,6 +16,7 @@ import { NeosModal } from "./NeosModal";
type Options = { msg: string; response: number }[];
const defaultStore = {
title: "",
isOpen: false,
options: [] satisfies Options as Options,
};
......@@ -23,7 +25,7 @@ const store = proxy(defaultStore);
export const OptionModal = () => {
const snap = useSnapshot(store);
const { isOpen, options } = snap;
const { title, isOpen, options } = snap;
const [selected, setSelected] = useState<number | undefined>(undefined);
......@@ -36,7 +38,7 @@ export const OptionModal = () => {
return (
<NeosModal
title="请选择需要发动的效果"
title={title}
open={isOpen}
footer={
<Button disabled={selected === undefined} onClick={onClick}>
......@@ -54,9 +56,10 @@ export const OptionModal = () => {
};
let rs: (v?: any) => void = () => {};
export const displayOptionModal = async (options: Options) => {
store.isOpen = true;
export const displayOptionModal = async (title: string, options: Options) => {
store.title = title;
store.options = options;
store.isOpen = true;
await new Promise((resolve) => (rs = resolve));
store.isOpen = false;
};
......@@ -87,6 +90,6 @@ export const handleEffectActivation = async (
response: effect.response,
};
});
await displayOptionModal(options); // 主动发动效果,所以不需要await,但是以后可能要留心
await displayOptionModal(fetchStrings("!system", 556), options); // 主动发动效果,所以不需要await,但是以后可能要留心
}
};
......@@ -6,7 +6,12 @@ import classnames from "classnames";
import React, { type CSSProperties, useEffect, useState } from "react";
import { proxy, useSnapshot } from "valtio";
import { getCardStr, sendSelectIdleCmdResponse, ygopro } from "@/api";
import {
fetchStrings,
getCardStr,
sendSelectIdleCmdResponse,
ygopro,
} from "@/api";
import { eventbus, Task } from "@/infra";
import { cardStore, CardType, Interactivity, InteractType } from "@/stores";
import { showCardModal as displayCardModal } from "@/ui/Duel/Message/CardModal";
......@@ -250,7 +255,7 @@ const handleEffectActivation = (
response: effect.response,
};
});
displayOptionModal(options); // 主动发动效果,所以不需要await,但是以后可能要留心
displayOptionModal(fetchStrings("!system", 556), options); // 主动发动效果,所以不需要await,但是以后可能要留心
}
};
......
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