Commit f0dd5248 authored by chechunchi's avatar chechunchi

handle RockPaperScissors

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