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

fix shuffle hand

parent 42d4cf52
Pipeline #22083 passed with stages
in 16 minutes and 48 seconds
......@@ -8,20 +8,21 @@ export default (shuffleHand: MsgShuffleHand) => {
// 本质上是要将手卡的sequence变成和codes一样的顺序
const hands = cardStore.at(ygopro.CardZone.HAND, controller);
const hash = [...codes].reduce(
(hash, code, sequence) => hash.set(code, sequence),
new Map()
);
const hash = new Map(codes.map((code) => [code, new Array()]));
codes.forEach((code, sequence) => {
hash.get(code)?.push(sequence);
});
hands.forEach((hand) => {
const sequence = hash.get(hand.code);
if (sequence !== undefined) {
if (sequence >= 0) {
const sequences = hash.get(hand.code);
if (sequences !== undefined) {
const sequence = sequences.pop();
if (sequence !== undefined) {
hand.location.sequence = sequence;
hash.set(hand.code, sequence - 1);
hash.set(hand.code, sequences);
} else {
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 {
......
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