Commit 4ca93111 authored by Chunchi Che's avatar Chunchi Che

fix shuffle hand

parent fffc0d7c
...@@ -63,6 +63,7 @@ export default async (move: MsgMove) => { ...@@ -63,6 +63,7 @@ export default async (move: MsgMove) => {
console.warn( console.warn(
`<Move>card from zone=${fromZone}, controller=${from.controler} sequence=${from.sequence} is null` `<Move>card from zone=${fromZone}, controller=${from.controler} sequence=${from.sequence} is null`
); );
console.info(cardStore.at(fromZone, from.controler));
return; return;
} }
} }
......
...@@ -8,17 +8,14 @@ export default (shuffleHand: MsgShuffleHand) => { ...@@ -8,17 +8,14 @@ export default (shuffleHand: MsgShuffleHand) => {
// 本质上是要将手卡的sequence变成和codes一样的顺序 // 本质上是要将手卡的sequence变成和codes一样的顺序
const hands = cardStore.at(ygopro.CardZone.HAND, controller); const hands = cardStore.at(ygopro.CardZone.HAND, controller);
const hash: Map<number, number> = new Map(); const hash = [...codes].reduce(
for (const idx in codes) { (hash, code, sequence) => hash.set(code, sequence),
const sequence = Number(idx); new Map()
const code = codes[sequence]; );
hash.set(code, (hash.get(code) || 0) + 1);
}
hands.forEach((hand) => { hands.forEach((hand) => {
const sequence = hash.get(hand.code); const sequence = hash.get(hand.code);
if (sequence) { if (sequence !== undefined) {
if (sequence >= 0) { if (sequence >= 0) {
hand.sequence = sequence; hand.sequence = sequence;
hash.set(hand.code, sequence - 1); hash.set(hand.code, sequence - 1);
......
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