diff --git a/src/services/inventoryService.ts b/src/services/inventoryService.ts index 8b8f5167..c17fec37 100644 --- a/src/services/inventoryService.ts +++ b/src/services/inventoryService.ts @@ -28,12 +28,10 @@ import { } from "../types/requestTypes"; import { logger } from "@/src/utils/logger"; import { getWeaponType, getExalted } from "@/src/services/itemDataService"; -import { getRandomWeightedReward } from "@/src/services/rngService"; import { ISyndicateSacrifice, ISyndicateSacrificeResponse } from "../types/syndicateTypes"; import { IEquipmentClient, IItemConfig } from "../types/inventoryTypes/commonInventoryTypes"; import { ExportArcanes, - ExportBoosterPacks, ExportCustoms, ExportFlavour, ExportGear, @@ -181,21 +179,6 @@ export const addItem = async ( } }; } - if (typeName in ExportBoosterPacks) { - const pack = ExportBoosterPacks[typeName]; - const InventoryChanges = {}; - for (const weights of pack.rarityWeightsPerRoll) { - const result = getRandomWeightedReward(pack.components, weights); - if (result) { - logger.debug(`booster pack rolled`, result); - combineInventoryChanges( - InventoryChanges, - (await addItem(accountId, result.type, result.itemCount)).InventoryChanges - ); - } - } - return { InventoryChanges }; - } if (typeName in ExportUpgrades || typeName in ExportArcanes) { const inventory = await getInventory(accountId); const changes = [ diff --git a/src/services/purchaseService.ts b/src/services/purchaseService.ts index e0104ca2..e7aa26d5 100644 --- a/src/services/purchaseService.ts +++ b/src/services/purchaseService.ts @@ -9,12 +9,14 @@ import { updateCurrency, updateSlots } from "@/src/services/inventoryService"; +import { getRandomWeightedReward } from "@/src/services/rngService"; import { getVendorManifestByOid } from "@/src/services/serversideVendorsService"; import { IMiscItem } from "@/src/types/inventoryTypes/inventoryTypes"; import { IPurchaseRequest, IPurchaseResponse, SlotPurchase, IInventoryChanges } from "@/src/types/purchaseTypes"; import { logger } from "@/src/utils/logger"; import worldState from "@/static/fixed_responses/worldState.json"; import { + ExportBoosterPacks, ExportBundles, ExportGear, ExportResources, @@ -38,7 +40,10 @@ export const getStoreItemTypesCategory = (typesItem: string) => { return typeElements[1]; }; -export const handlePurchase = async (purchaseRequest: IPurchaseRequest, accountId: string) => { +export const handlePurchase = async ( + purchaseRequest: IPurchaseRequest, + accountId: string +): Promise => { logger.debug("purchase request", purchaseRequest); if (purchaseRequest.PurchaseParams.Source == 7) { @@ -260,17 +265,43 @@ const handleSlotPurchase = async ( }; }; +const handleBoosterPackPurchase = async (typeName: string, accountId: string): Promise => { + const pack = ExportBoosterPacks[typeName]; + if (!pack) { + throw new Error(`unknown booster pack: ${typeName}`); + } + const purchaseResponse: IPurchaseResponse = { + 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 + ); + } + } + return purchaseResponse; +}; + //TODO: change to getInventory, apply changes then save at the end const handleTypesPurchase = async ( typesName: string, accountId: string, quantity: number -): Promise<{ InventoryChanges: IInventoryChanges }> => { +): Promise => { const typeCategory = getStoreItemTypesCategory(typesName); logger.debug(`type category ${typeCategory}`); switch (typeCategory) { default: return await addItem(accountId, typesName, quantity); + case "BoosterPacks": + return await handleBoosterPackPurchase(typesName, accountId); case "SlotItems": return await handleSlotPurchase(typesName, accountId); } diff --git a/src/types/purchaseTypes.ts b/src/types/purchaseTypes.ts index b746b4fc..93725cee 100644 --- a/src/types/purchaseTypes.ts +++ b/src/types/purchaseTypes.ts @@ -25,6 +25,7 @@ export interface IPurchaseResponse { Tag: string; Standing: number; }[]; + BoosterPackItems?: string; } export type IBinChanges = {