From 4aaed2ced5ed7cf638b00816ca902968892e736b Mon Sep 17 00:00:00 2001 From: Dimava Date: Mon, 18 Aug 2025 12:11:47 +0300 Subject: [PATCH] upgrade one card at a time for more cost-efficient upgrading --- js/logic.js | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/js/logic.js b/js/logic.js index 6806104..96e5f32 100644 --- a/js/logic.js +++ b/js/logic.js @@ -64,26 +64,18 @@ function onFrame() { } if (effects.autobuySpeed) { autobuyTime += delta / 1000 * effects.autobuySpeed; - let autobuyCount = Math.floor(autobuyTime); - autobuyTime -= autobuyCount; - let upgradedAny = false; - for (let elm of tabs.collection.cardList) { - let [pack, rarity, id] = elm; - let canBought = getCardLevelMax(pack, rarity, id); - console.log("Buying", canBought, "of", pack, rarity, id); - if (canBought > 0) { - canBought = Math.min(canBought, autobuyCount); - autobuyCount -= canBought; - game.stats.autobuyBought += canBought; - levelUpCard(pack, rarity, id, canBought, false, false); - upgradedAny = true; + while (autobuyTime >= 1) { + autobuyTime -= 1; + const boughtCard = tabs.collection.cardList.find(x => getCardLevelMax(x[0], x[1], x[2]) > 0); + if (boughtCard) { + const [pack, rarity, id] = boughtCard; + levelUpCard(pack, rarity, id, 1, true, false); + // re-sort cards + tabs.collection.updateCards(); + } + else { + autobuyTime = 0; } - if (autobuyCount <= 0) break; - } - if (upgradedAny) { - updateEffects(); - updateUnlocks(); - emit("card-upgrade"); } } }