Commit 53ffb94e authored by Chunchi Che's avatar Chunchi Che

Merge branch 'feat/toss' into 'main'

Feat/toss

See merge request !225
parents de05dbe7 277c93c4
Pipeline #22281 passed with stages
in 16 minutes and 1 second
neos-protobuf @ b67b483c
Subproject commit e6e23561a0f8e515a0168d87d72c281b7b9cca17 Subproject commit b67b483ce9db064611619a2e1a8b8767b100d035
This diff is collapsed.
...@@ -61,3 +61,5 @@ export const MSG_ANNOUNCE_RACE = 140; ...@@ -61,3 +61,5 @@ export const MSG_ANNOUNCE_RACE = 140;
export const MSG_ANNOUNCE_ATTRIB = 141; export const MSG_ANNOUNCE_ATTRIB = 141;
export const MSG_ANNOUNCE_CARD = 142; export const MSG_ANNOUNCE_CARD = 142;
export const MSG_ANNOUNCE_NUMBER = 143; export const MSG_ANNOUNCE_NUMBER = 143;
export const MSG_TOSS_COIN = 130;
export const MSG_TOSS_DICE = 131;
...@@ -35,6 +35,7 @@ import MsgSelectTributeAdapter from "./selectTribute"; ...@@ -35,6 +35,7 @@ import MsgSelectTributeAdapter from "./selectTribute";
import MsgSelectUnselectCardAdapter from "./selectUnselectCard"; import MsgSelectUnselectCardAdapter from "./selectUnselectCard";
import MsgSortCard from "./sortCard"; import MsgSortCard from "./sortCard";
import MsgStartAdapter from "./start"; import MsgStartAdapter from "./start";
import MsgTossAdapter from "./toss";
import MsgUpdateDataAdapter from "./updateData"; import MsgUpdateDataAdapter from "./updateData";
import MsgWaitAdapter from "./wait"; import MsgWaitAdapter from "./wait";
import MsgWin from "./win"; import MsgWin from "./win";
...@@ -220,6 +221,22 @@ export default class GameMsgAdapter implements StocAdapter { ...@@ -220,6 +221,22 @@ export default class GameMsgAdapter implements StocAdapter {
break; break;
} }
case GAME_MSG.MSG_TOSS_COIN: {
gameMsg.toss = MsgTossAdapter(
gameData,
ygopro.StocGameMessage.MsgToss.TossType.COIN
);
break;
}
case GAME_MSG.MSG_TOSS_DICE: {
gameMsg.toss = MsgTossAdapter(
gameData,
ygopro.StocGameMessage.MsgToss.TossType.DICE
);
break;
}
default: { default: {
gameMsg.unimplemented = new ygopro.StocGameMessage.MsgUnimplemented({ gameMsg.unimplemented = new ygopro.StocGameMessage.MsgUnimplemented({
command: func, command: func,
......
import { BufferReader } from "../../../../../../rust-src/pkg/rust_src";
import { ygopro } from "../../../idl/ocgcore";
import MsgToss = ygopro.StocGameMessage.MsgToss;
/*
* Msg Toss
* @param - TODO
*
* @usage 骰子/硬币结果
* */
export default (data: Uint8Array, toss_type: MsgToss.TossType) => {
const reader = new BufferReader(data);
const player = reader.readUint8();
const count = reader.readUint8();
const res = [];
for (let i = 0; i < count; i++) {
res.push(reader.readUint8());
}
return new MsgToss({
player,
toss_type,
res,
});
};
...@@ -42,6 +42,7 @@ import onMsgStart from "./start"; ...@@ -42,6 +42,7 @@ import onMsgStart from "./start";
import onMsgSummoned from "./summoned"; import onMsgSummoned from "./summoned";
import onMsgSummoning from "./summoning"; import onMsgSummoning from "./summoning";
import onMsgSwap from "./swap"; import onMsgSwap from "./swap";
import onMsgToss from "./toss";
import onUnimplemented from "./unimplemented"; import onUnimplemented from "./unimplemented";
import onMsgUpdateCounter from "./updateCounter"; import onMsgUpdateCounter from "./updateCounter";
import onMsgUpdateData from "./updateData"; import onMsgUpdateData from "./updateData";
...@@ -303,6 +304,11 @@ async function _handleGameMsg(pb: ygopro.YgoStocMsg) { ...@@ -303,6 +304,11 @@ async function _handleGameMsg(pb: ygopro.YgoStocMsg) {
break; break;
} }
case "toss": {
onMsgToss(msg.toss);
break;
}
case "unimplemented": { case "unimplemented": {
onUnimplemented(msg.unimplemented); onUnimplemented(msg.unimplemented);
......
import { fetchStrings, ygopro } from "@/api";
import { sleep } from "@/infra";
import { matStore } from "@/stores";
import MsgToss = ygopro.StocGameMessage.MsgToss;
export default async (toss: MsgToss) => {
const player = toss.player;
const tossType = toss.toss_type;
const prefix = fetchStrings("!system", matStore.isMe(player) ? 102 : 103);
for (const x of toss.res) {
if (tossType == MsgToss.TossType.DICE) {
matStore.tossResult = prefix + fetchStrings("!system", 1624) + x;
} else if (tossType == MsgToss.TossType.COIN) {
matStore.tossResult =
prefix +
fetchStrings("!system", 1623) +
fetchStrings("!system", 61 - x);
} else {
console.log(`Unknown tossType = ${tossType}`);
}
// 等待1s,不然多个结果刷新太快了
await sleep(1000);
}
};
...@@ -37,6 +37,8 @@ export interface MatState { ...@@ -37,6 +37,8 @@ export interface MatState {
unimplemented: number; // 未处理的`Message` unimplemented: number; // 未处理的`Message`
tossResult?: string; // 骰子/硬币结果
/** 根据自己的先后手判断是否是自己 */ /** 根据自己的先后手判断是否是自己 */
isMe: (player: number) => boolean; isMe: (player: number) => boolean;
} }
......
...@@ -17,6 +17,7 @@ const NeosConfig = useConfig(); ...@@ -17,6 +17,7 @@ const NeosConfig = useConfig();
export const HintNotification = () => { export const HintNotification = () => {
const snap = useSnapshot(matStore); const snap = useSnapshot(matStore);
const hintState = snap.hint; const hintState = snap.hint;
const toss = snap.tossResult;
const currentPhase = snap.phase.currentPhase; const currentPhase = snap.phase.currentPhase;
const waiting = snap.waiting; const waiting = snap.waiting;
...@@ -35,6 +36,16 @@ export const HintNotification = () => { ...@@ -35,6 +36,16 @@ export const HintNotification = () => {
} }
}, [hintState.msg]); }, [hintState.msg]);
useEffect(() => {
if (toss) {
api.open({
message: `${toss}`,
placement: "topLeft",
style: style,
});
}
}, [toss]);
useEffect(() => { useEffect(() => {
if (currentPhase) { if (currentPhase) {
const message = fetchStrings( const message = fetchStrings(
......
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