Commit 24a8038d authored by Chunchi Che's avatar Chunchi Che

fix shuffle hand

parent 2106d11a
Pipeline #21951 passed with stages
in 15 minutes and 13 seconds
......@@ -8,25 +8,33 @@ export default (shuffleHand: MsgShuffleHand) => {
// 本质上是要将手卡的sequence变成和codes一样的顺序
const hands = cardStore.at(ygopro.CardZone.HAND, controller);
const t: Record<number, number[]> = {};
const t: Map<number, number[]> = new Map([]);
codes.forEach((code, sequence) => {
t[code] = t[code] || [];
t[code].push(sequence);
const v = t.get(code);
if (v) {
v.push(sequence);
} else {
t.set(code, [sequence]);
}
});
console.log(t);
hands.forEach((hand) => {
const target = t[hand.code];
const target = t.get(hand.code);
if (target !== undefined) {
const sequence = target.shift();
if (sequence) {
hand.sequence = sequence;
} else {
console.warn(
`<ShuffleHand>sequence shift from target is null, controller=${controller} hands=${hands}, codes=${codes}`
`<ShuffleHand>sequence shift from target is null, controller=${controller}, target=${target}, codes=${codes}`
);
}
} else {
console.warn(
`<ShuffleHand>target from records is null, controller=${controller} hands=${hands}, codes=${codes}`
`<ShuffleHand>target from records is null, controller=${controller}, hands=${hands.map(
(hand) => hand.code
)}, 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