From 0e1ee0c669a208d09aaa1cda096bee09a142f542 Mon Sep 17 00:00:00 2001 From: Sainan Date: Tue, 31 Dec 2024 01:39:45 +0100 Subject: [PATCH] fix: purchase of multiple booster packs (#671) --- src/services/purchaseService.ts | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/services/purchaseService.ts b/src/services/purchaseService.ts index cc09d0f7..c3a16cf0 100644 --- a/src/services/purchaseService.ts +++ b/src/services/purchaseService.ts @@ -264,7 +264,11 @@ const handleSlotPurchase = async ( }; }; -const handleBoosterPackPurchase = async (typeName: string, accountId: string): Promise => { +const handleBoosterPackPurchase = async ( + typeName: string, + accountId: string, + quantity: number +): Promise => { const pack = ExportBoosterPacks[typeName]; if (!pack) { throw new Error(`unknown booster pack: ${typeName}`); @@ -273,16 +277,18 @@ const handleBoosterPackPurchase = async (typeName: string, accountId: string): P BoosterPackItems: "", InventoryChanges: {} }; - for (const weights of pack.rarityWeightsPerRoll) { - const result = getRandomWeightedReward(pack.components, weights); - if (result) { - logger.debug(`booster pack rolled`, result); - purchaseResponse.BoosterPackItems += - result.type.split("/Lotus/").join("/Lotus/StoreItems/") + ',{"lvl":0};'; - combineInventoryChanges( - purchaseResponse.InventoryChanges, - (await addItem(accountId, result.type, result.itemCount)).InventoryChanges - ); + for (let i = 0; i != quantity; ++i) { + for (const weights of pack.rarityWeightsPerRoll) { + const result = getRandomWeightedReward(pack.components, weights); + if (result) { + logger.debug(`booster pack rolled`, result); + purchaseResponse.BoosterPackItems += + result.type.split("/Lotus/").join("/Lotus/StoreItems/") + ',{"lvl":0};'; + combineInventoryChanges( + purchaseResponse.InventoryChanges, + (await addItem(accountId, result.type, result.itemCount)).InventoryChanges + ); + } } } return purchaseResponse; @@ -300,7 +306,7 @@ const handleTypesPurchase = async ( default: return await addItem(accountId, typesName, quantity); case "BoosterPacks": - return await handleBoosterPackPurchase(typesName, accountId); + return await handleBoosterPackPurchase(typesName, accountId, quantity); case "SlotItems": return await handleSlotPurchase(typesName, accountId); }