Commit 5220b672 authored by Chunchi Che's avatar Chunchi Che

fix shuffle hand

parent 42d4cf52
...@@ -8,20 +8,21 @@ export default (shuffleHand: MsgShuffleHand) => { ...@@ -8,20 +8,21 @@ 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 = [...codes].reduce( const hash = new Map(codes.map((code) => [code, new Array()]));
(hash, code, sequence) => hash.set(code, sequence), codes.forEach((code, sequence) => {
new Map() hash.get(code)?.push(sequence);
); });
hands.forEach((hand) => { hands.forEach((hand) => {
const sequence = hash.get(hand.code); const sequences = hash.get(hand.code);
if (sequence !== undefined) { if (sequences !== undefined) {
if (sequence >= 0) { const sequence = sequences.pop();
if (sequence !== undefined) {
hand.location.sequence = sequence; hand.location.sequence = sequence;
hash.set(hand.code, sequence - 1); hash.set(hand.code, sequences);
} else { } else {
console.warn( console.warn(
`<ShuffleHand>sequence less than zero, controller=${controller}, code=${hand.code}, sequence=${sequence}` `<ShuffleHand>sequence poped is none, controller=${controller}, code=${hand.code}, sequence=${sequence}`
); );
} }
} else { } else {
......
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