返回提交历史
Modified
src/services/purchaseService.ts
+18
-12
XFEstudio/SpaceNinjaServer
fix: purchase of multiple booster packs (#671)
0e1ee0c6
代码差异
1 个文件
+18
-12
@@ -264,7 +264,11 @@ const handleSlotPurchase = async (
264
264
};
265
265
};
266
266
267
const handleBoosterPackPurchase = async (typeName: string, accountId: string): Promise<IPurchaseResponse> => {
267
const handleBoosterPackPurchase = async (
268
typeName: string,
269
accountId: string,
270
quantity: number
271
): Promise<IPurchaseResponse> => {
268
272
const pack = ExportBoosterPacks[typeName];
269
273
if (!pack) {
270
274
throw new Error(`unknown booster pack: ${typeName}`);
@@ -273,16 +277,18 @@ const handleBoosterPackPurchase = async (typeName: string, accountId: string): P
273
277
BoosterPackItems: "",
274
278
InventoryChanges: {}
275
279
};
276
for (const weights of pack.rarityWeightsPerRoll) {
277
const result = getRandomWeightedReward(pack.components, weights);
278
if (result) {
279
logger.debug(`booster pack rolled`, result);
280
purchaseResponse.BoosterPackItems +=
281
result.type.split("/Lotus/").join("/Lotus/StoreItems/") + ',{"lvl":0};';
282
combineInventoryChanges(
283
purchaseResponse.InventoryChanges,
284
(await addItem(accountId, result.type, result.itemCount)).InventoryChanges
285
);
280
for (let i = 0; i != quantity; ++i) {
281
for (const weights of pack.rarityWeightsPerRoll) {
282
const result = getRandomWeightedReward(pack.components, weights);
283
if (result) {
284
logger.debug(`booster pack rolled`, result);
285
purchaseResponse.BoosterPackItems +=
286
result.type.split("/Lotus/").join("/Lotus/StoreItems/") + ',{"lvl":0};';
287
combineInventoryChanges(
288
purchaseResponse.InventoryChanges,
289
(await addItem(accountId, result.type, result.itemCount)).InventoryChanges
290
);
291
}
286
292
}
287
293
}
288
294
return purchaseResponse;
@@ -300,7 +306,7 @@ const handleTypesPurchase = async (
300
306
default:
301
307
return await addItem(accountId, typesName, quantity);
302
308
case "BoosterPacks":
303
return await handleBoosterPackPurchase(typesName, accountId);
309
return await handleBoosterPackPurchase(typesName, accountId, quantity);
304
310
case "SlotItems":
305
311
return await handleSlotPurchase(typesName, accountId);
306
312
}