fix: purchase of multiple booster packs (#671)
This commit is contained in:
parent
230c0303b1
commit
0e1ee0c669
@ -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];
|
||||
if (!pack) {
|
||||
throw new Error(`unknown booster pack: ${typeName}`);
|
||||
@ -273,6 +277,7 @@ const handleBoosterPackPurchase = async (typeName: string, accountId: string): P
|
||||
BoosterPackItems: "",
|
||||
InventoryChanges: {}
|
||||
};
|
||||
for (let i = 0; i != quantity; ++i) {
|
||||
for (const weights of pack.rarityWeightsPerRoll) {
|
||||
const result = getRandomWeightedReward(pack.components, weights);
|
||||
if (result) {
|
||||
@ -285,6 +290,7 @@ const handleBoosterPackPurchase = async (typeName: string, accountId: string): P
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user