Commit fffc0d7c authored by Chunchi Che's avatar Chunchi Che

fix shuffle hand

parent 24a8038d
......@@ -8,26 +8,23 @@ export default (shuffleHand: MsgShuffleHand) => {
// 本质上是要将手卡的sequence变成和codes一样的顺序
const hands = cardStore.at(ygopro.CardZone.HAND, controller);
const t: Map<number, number[]> = new Map([]);
codes.forEach((code, sequence) => {
const v = t.get(code);
if (v) {
v.push(sequence);
} else {
t.set(code, [sequence]);
}
});
const hash: Map<number, number> = new Map();
for (const idx in codes) {
const sequence = Number(idx);
const code = codes[sequence];
hash.set(code, (hash.get(code) || 0) + 1);
}
console.log(t);
hands.forEach((hand) => {
const target = t.get(hand.code);
if (target !== undefined) {
const sequence = target.shift();
if (sequence) {
const sequence = hash.get(hand.code);
if (sequence) {
if (sequence >= 0) {
hand.sequence = sequence;
hash.set(hand.code, sequence - 1);
} else {
console.warn(
`<ShuffleHand>sequence shift from target is null, controller=${controller}, target=${target}, codes=${codes}`
`<ShuffleHand>sequence less than zero, controller=${controller}, code=${hand.code}, sequence=${sequence}`
);
}
} 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