Commit 9f145997 authored by Chunchi Che's avatar Chunchi Che

Merge branch 'feat/shuffle_extra' into 'main'

Feat/shuffle extra

See merge request mycard/Neos!239
parents b5e2cf80 338628fd
Pipeline #22503 passed with stages
in 11 minutes and 32 seconds
neos-protobuf @ 70d4b723
Subproject commit 759a1db5cbb32e84711f9a5fba3d19ee069fa635 Subproject commit 70d4b723250a24084b3fa5dcfb550431e29ea7e3
This diff is collapsed.
...@@ -67,3 +67,5 @@ export const MSG_TOSS_DICE = 131; ...@@ -67,3 +67,5 @@ export const MSG_TOSS_DICE = 131;
export const MSG_SHUFFLE_SET_CARD = 36; export const MSG_SHUFFLE_SET_CARD = 36;
export const MSG_FIELD_DISABLED = 56; export const MSG_FIELD_DISABLED = 56;
export const MSG_HAND_RES = 133; export const MSG_HAND_RES = 133;
export const MSG_SHUFFLE_HAND = 33;
export const MSG_SHUFFLE_EXTRA = 39;
...@@ -35,6 +35,7 @@ import MsgSelectPositionAdapter from "./selectPosition"; ...@@ -35,6 +35,7 @@ import MsgSelectPositionAdapter from "./selectPosition";
import MsgSelectSum from "./selectSum"; import MsgSelectSum from "./selectSum";
import MsgSelectTributeAdapter from "./selectTribute"; import MsgSelectTributeAdapter from "./selectTribute";
import MsgSelectUnselectCardAdapter from "./selectUnselectCard"; import MsgSelectUnselectCardAdapter from "./selectUnselectCard";
import MsgShuffleHandExtraAdapter from "./shuffleHandExtra";
import MsgShuffleSetCard from "./shuffleSetCard"; import MsgShuffleSetCard from "./shuffleSetCard";
import MsgSortCard from "./sortCard"; import MsgSortCard from "./sortCard";
import MsgStartAdapter from "./start"; import MsgStartAdapter from "./start";
...@@ -256,6 +257,22 @@ export default class GameMsgAdapter implements StocAdapter { ...@@ -256,6 +257,22 @@ export default class GameMsgAdapter implements StocAdapter {
break; break;
} }
case GAME_MSG.MSG_SHUFFLE_HAND: {
gameMsg.shuffle_hand_extra = MsgShuffleHandExtraAdapter(
gameData,
false
);
break;
}
case GAME_MSG.MSG_SHUFFLE_EXTRA: {
gameMsg.shuffle_hand_extra = MsgShuffleHandExtraAdapter(
gameData,
true
);
break;
}
default: { default: {
gameMsg.unimplemented = new ygopro.StocGameMessage.MsgUnimplemented({ gameMsg.unimplemented = new ygopro.StocGameMessage.MsgUnimplemented({
command: func, command: func,
......
...@@ -20,20 +20,6 @@ ...@@ -20,20 +20,6 @@
} }
] ]
}, },
"33": {
"protoType": "shuffle_hand",
"fields": [
{
"fieldName": "player",
"fieldType": "uint8"
},
{
"fieldName": "hands",
"fieldType": "repeated",
"repeatedType": "uint32"
}
]
},
"53": { "53": {
"protoType": "pos_change", "protoType": "pos_change",
"fields": [ "fields": [
......
...@@ -17,7 +17,6 @@ const ReadFieldHandlerMap: Map<string, readFieldHandler> = new Map([ ...@@ -17,7 +17,6 @@ const ReadFieldHandlerMap: Map<string, readFieldHandler> = new Map([
]); ]);
const MsgConstructorMap: Map<string, Constructor> = new Map([ const MsgConstructorMap: Map<string, Constructor> = new Map([
["move", ygopro.StocGameMessage.MsgMove as Constructor], ["move", ygopro.StocGameMessage.MsgMove as Constructor],
["shuffle_hand", ygopro.StocGameMessage.MsgShuffleHand],
["pos_change", ygopro.StocGameMessage.MsgPosChange], ["pos_change", ygopro.StocGameMessage.MsgPosChange],
["select_yes_no", ygopro.StocGameMessage.MsgSelectYesNo], ["select_yes_no", ygopro.StocGameMessage.MsgSelectYesNo],
["set", ygopro.StocGameMessage.MsgSet], ["set", ygopro.StocGameMessage.MsgSet],
......
import { ygopro } from "@/api/ocgcore/idl/ocgcore";
import { BufferReader } from "../../../../../../rust-src/pkg/rust_src";
import MsgShuffleHandExtra = ygopro.StocGameMessage.MsgShuffleHandExtra;
/*
* Msg Shuffle Hand or Extra
* @param - TODO
*
* @usage - 手牌/额外卡组切洗
* */
export default (data: Uint8Array, isExtra: boolean) => {
const reader = new BufferReader(data);
const zone = isExtra ? ygopro.CardZone.EXTRA : ygopro.CardZone.HAND;
const player = reader.readUint8();
const count = reader.readUint8();
const cards = [];
for (let i = 0; i < count; i++) {
cards.push(reader.readUint32());
}
return new MsgShuffleHandExtra({
player,
zone,
cards,
});
};
...@@ -38,7 +38,7 @@ import onMsgSelectUnselectCard from "./selectUnselectCard"; ...@@ -38,7 +38,7 @@ import onMsgSelectUnselectCard from "./selectUnselectCard";
import onMsgSelectYesNo from "./selectYesNo"; import onMsgSelectYesNo from "./selectYesNo";
import onMsgSet from "./set"; import onMsgSet from "./set";
import onMsgShuffleDeck from "./shuffleDeck"; import onMsgShuffleDeck from "./shuffleDeck";
import onMsgShuffleHand from "./shuffleHand"; import onMsgShuffleHandExtra from "./shuffleHandExtra";
import onMsgShuffleSetCard from "./shuffleSetCard"; import onMsgShuffleSetCard from "./shuffleSetCard";
import onMsgSortCard from "./sortCard"; import onMsgSortCard from "./sortCard";
import onMsgSpSummoned from "./spSummoned"; import onMsgSpSummoned from "./spSummoned";
...@@ -149,8 +149,8 @@ async function _handleGameMsg(pb: ygopro.YgoStocMsg) { ...@@ -149,8 +149,8 @@ async function _handleGameMsg(pb: ygopro.YgoStocMsg) {
break; break;
} }
case "shuffle_hand": { case "shuffle_hand_extra": {
await onMsgShuffleHand(msg.shuffle_hand); await onMsgShuffleHandExtra(msg.shuffle_hand_extra);
break; break;
} }
......
...@@ -2,37 +2,37 @@ import { ygopro } from "@/api"; ...@@ -2,37 +2,37 @@ import { ygopro } from "@/api";
import { eventbus, Task } from "@/infra"; import { eventbus, Task } from "@/infra";
import { cardStore } from "@/stores"; import { cardStore } from "@/stores";
type MsgShuffleHand = ygopro.StocGameMessage.MsgShuffleHand; type MsgShuffleHandExtra = ygopro.StocGameMessage.MsgShuffleHandExtra;
export default async (shuffleHand: MsgShuffleHand) => { export default async (shuffleHandExtra: MsgShuffleHandExtra) => {
const { hands: codes, player: controller } = shuffleHand; const { cards: codes, player: controller, zone } = shuffleHandExtra;
// 本质上是要将手卡的sequence变成和codes一样的顺序 // 本质上是要将手卡/额外卡组的sequence变成和codes一样的顺序
const hands = cardStore.at(ygopro.CardZone.HAND, controller); const cards = cardStore.at(zone, controller);
const hash = new Map(codes.map((code) => [code, new Array()])); const hash = new Map(codes.map((code) => [code, new Array()]));
codes.forEach((code, sequence) => { codes.forEach((code, sequence) => {
hash.get(code)?.push(sequence); hash.get(code)?.push(sequence);
}); });
for (const hand of hands) { for (const card of cards) {
const sequences = hash.get(hand.code); const sequences = hash.get(card.code);
if (sequences !== undefined) { if (sequences !== undefined) {
const sequence = sequences.pop(); const sequence = sequences.pop();
if (sequence !== undefined) { if (sequence !== undefined) {
hand.location.sequence = sequence; card.location.sequence = sequence;
hash.set(hand.code, sequences); hash.set(card.code, sequences);
// 触发动画 // 触发动画
await eventbus.call(Task.Move, hand.uuid); await eventbus.call(Task.Move, card.uuid);
} else { } else {
console.warn( console.warn(
`<ShuffleHand>sequence poped is none, controller=${controller}, code=${hand.code}, sequence=${sequence}` `<ShuffleHandExtra>sequence poped is none, controller=${controller}, code=${card.code}, sequence=${sequence}`
); );
} }
} else { } else {
console.warn( console.warn(
`<ShuffleHand>target from records is null, controller=${controller}, hands=${hands.map( `<ShuffleHandExtra>target from records is null, controller=${controller}, cards=${cards.map(
(hand) => hand.code (card) => card.code
)}, codes=${codes}` )}, codes=${codes}`
); );
} }
......
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