fix: purchase of multiple booster packs

This commit is contained in:
Sainan 2024-12-30 23:30:25 +01:00
parent 7ea02d142f
commit e8c397eee3

View File

@ -264,7 +264,11 @@ const handleSlotPurchase = async (
}; };
}; };
const handleBoosterPackPurchase = async (typeName: string, accountId: string): Promise<IPurchaseResponse> => { const handleBoosterPackPurchase = async (
typeName: string,
accountId: string,
quantity: number
): Promise<IPurchaseResponse> => {
const pack = ExportBoosterPacks[typeName]; const pack = ExportBoosterPacks[typeName];
if (!pack) { if (!pack) {
throw new Error(`unknown booster pack: ${typeName}`); throw new Error(`unknown booster pack: ${typeName}`);
@ -273,16 +277,18 @@ const handleBoosterPackPurchase = async (typeName: string, accountId: string): P
BoosterPackItems: "", BoosterPackItems: "",
InventoryChanges: {} InventoryChanges: {}
}; };
for (const weights of pack.rarityWeightsPerRoll) { for (let i = 0; i != quantity; ++i) {
const result = getRandomWeightedReward(pack.components, weights); for (const weights of pack.rarityWeightsPerRoll) {
if (result) { const result = getRandomWeightedReward(pack.components, weights);
logger.debug(`booster pack rolled`, result); if (result) {
purchaseResponse.BoosterPackItems += logger.debug(`booster pack rolled`, result);
result.type.split("/Lotus/").join("/Lotus/StoreItems/") + ',{"lvl":0};'; purchaseResponse.BoosterPackItems +=
combineInventoryChanges( result.type.split("/Lotus/").join("/Lotus/StoreItems/") + ',{"lvl":0};';
purchaseResponse.InventoryChanges, combineInventoryChanges(
(await addItem(accountId, result.type, result.itemCount)).InventoryChanges purchaseResponse.InventoryChanges,
); (await addItem(accountId, result.type, result.itemCount)).InventoryChanges
);
}
} }
} }
return purchaseResponse; return purchaseResponse;
@ -300,7 +306,7 @@ const handleTypesPurchase = async (
default: default:
return await addItem(accountId, typesName, quantity); return await addItem(accountId, typesName, quantity);
case "BoosterPacks": case "BoosterPacks":
return await handleBoosterPackPurchase(typesName, accountId); return await handleBoosterPackPurchase(typesName, accountId, quantity);
case "SlotItems": case "SlotItems":
return await handleSlotPurchase(typesName, accountId); return await handleSlotPurchase(typesName, accountId);
} }