Commit 2106d11a authored by Chunchi Che's avatar Chunchi Che

fix small

parent 870910b1
...@@ -19,7 +19,7 @@ export default async (chainSolved: ygopro.StocGameMessage.MsgChainSolved) => { ...@@ -19,7 +19,7 @@ export default async (chainSolved: ygopro.StocGameMessage.MsgChainSolved) => {
if (target) { if (target) {
target.chainIndex = undefined; target.chainIndex = undefined;
} else { } else {
console.log(`<ChainSolved>target from ${location} is null`); console.warn(`<ChainSolved>target from ${location} is null`);
} }
} else { } else {
console.warn( console.warn(
......
...@@ -8,21 +8,22 @@ export default async (draw: ygopro.StocGameMessage.MsgDraw) => { ...@@ -8,21 +8,22 @@ export default async (draw: ygopro.StocGameMessage.MsgDraw) => {
// 将卡从卡组移到手牌:设置zone、occupant、sequence // 将卡从卡组移到手牌:设置zone、occupant、sequence
const handsLength = cardStore.at(ygopro.CardZone.HAND, draw.player).length; const handsLength = cardStore.at(ygopro.CardZone.HAND, draw.player).length;
cardStore const newHands = cardStore
.at(ygopro.CardZone.DECK, draw.player) .at(ygopro.CardZone.DECK, draw.player)
.slice(-drawLength) .slice(-drawLength);
.forEach(async (card, idx) => {
for (const idx in newHands) {
const card = newHands[Number(idx)];
const code = draw.cards[idx]; const code = draw.cards[idx];
const meta = await fetchCard(code); const meta = await fetchCard(code);
card.code = code; card.code = code;
card.meta = meta; card.meta = meta;
card.zone = ygopro.CardZone.HAND; card.zone = ygopro.CardZone.HAND;
card.sequence = idx + handsLength; card.sequence = Number(idx) + handsLength;
}); }
// 抽卡动画 // 抽卡动画
cardStore cardStore
.at(ygopro.CardZone.HAND, draw.player) .at(ygopro.CardZone.HAND, draw.player)
.forEach((card) => eventBus.emit(Report.Move, card.uuid)); .forEach((card) => eventBus.emit(Report.Move, card.uuid));
// FIXME: `eventBus.emit`的方式能保证动画完成后才进行下一次msg的处理么
// 如果下一次msg来得很快,可能会有动画冲突?
}; };
...@@ -14,10 +14,20 @@ export default (shuffleHand: MsgShuffleHand) => { ...@@ -14,10 +14,20 @@ export default (shuffleHand: MsgShuffleHand) => {
t[code].push(sequence); t[code].push(sequence);
}); });
hands.forEach((hand) => { hands.forEach((hand) => {
const sequence = t[hand.code].shift(); const target = t[hand.code];
if (sequence === undefined) { if (target !== undefined) {
throw new Error("手牌数量和洗牌后的数量不一致"); const sequence = target.shift();
} if (sequence) {
hand.sequence = sequence; hand.sequence = sequence;
} else {
console.warn(
`<ShuffleHand>sequence shift from target is null, controller=${controller} hands=${hands}, codes=${codes}`
);
}
} else {
console.warn(
`<ShuffleHand>target from records is null, controller=${controller} hands=${hands}, 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