From d3004b19dda194a0de942825fb6c3348169eb261 Mon Sep 17 00:00:00 2001 From: Sainan Date: Mon, 24 Jun 2024 12:31:29 +0200 Subject: [PATCH] improve: handle purchase quantity of gear items (#389) Co-authored-by: Sainan --- package-lock.json | 8 ++++---- package.json | 2 +- src/services/purchaseService.ts | 15 +++++++++++---- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index a69058da6..d2ca4c16d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "copyfiles": "^2.4.1", "express": "^5.0.0-beta.3", "mongoose": "^8.1.1", - "warframe-public-export-plus": "^0.3.2", + "warframe-public-export-plus": "^0.3.3", "warframe-riven-info": "^0.1.0", "winston": "^3.11.0", "winston-daily-rotate-file": "^4.7.1" @@ -3669,9 +3669,9 @@ } }, "node_modules/warframe-public-export-plus": { - "version": "0.3.2", - "resolved": "https://registry.npmjs.org/warframe-public-export-plus/-/warframe-public-export-plus-0.3.2.tgz", - "integrity": "sha512-0jAStLLrMaz0zm7wfY1/3SWLPmMJcYNNErVTPo8YqBZlot1aikVuDNu+crVmN+LWDDLrn01T7f83EYaw7TYo6w==" + "version": "0.3.3", + "resolved": "https://registry.npmjs.org/warframe-public-export-plus/-/warframe-public-export-plus-0.3.3.tgz", + "integrity": "sha512-35pSMqXxe9vG4kdA+SnCyZyWO8zRGuPQbNeOPgZm5886kiujR+Qd6iY7TH0fdQYgKCk1M+q8lXonATT9VB9bbQ==" }, "node_modules/warframe-riven-info": { "version": "0.1.0", diff --git a/package.json b/package.json index 3436b14a5..f5b472dfc 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "copyfiles": "^2.4.1", "express": "^5.0.0-beta.3", "mongoose": "^8.1.1", - "warframe-public-export-plus": "^0.3.2", + "warframe-public-export-plus": "^0.3.3", "warframe-riven-info": "^0.1.0", "winston": "^3.11.0", "winston-daily-rotate-file": "^4.7.1" diff --git a/src/services/purchaseService.ts b/src/services/purchaseService.ts index 6f55bad00..add4032c8 100644 --- a/src/services/purchaseService.ts +++ b/src/services/purchaseService.ts @@ -3,7 +3,7 @@ import { getSubstringFromKeyword } from "@/src/helpers/stringHelpers"; import { addItem, addBooster, updateCurrency, updateSlots } from "@/src/services/inventoryService"; import { IPurchaseRequest, SlotPurchase, IInventoryChanges, IBinChanges } from "@/src/types/purchaseTypes"; import { logger } from "@/src/utils/logger"; -import { ExportBundles, TRarity } from "warframe-public-export-plus"; +import { ExportBundles, ExportGear, TRarity } from "warframe-public-export-plus"; export const getStoreItemCategory = (storeItem: string) => { const storeItemString = getSubstringFromKeyword(storeItem, "StoreItems/"); @@ -75,7 +75,8 @@ const handleStoreItemAcquisition = async ( storeItemName: string, accountId: string, quantity: number, - durability: TRarity + durability: TRarity, + ignorePurchaseQuantity: boolean = false ): Promise<{ InventoryChanges: IInventoryChanges }> => { let purchaseResponse = { InventoryChanges: {} @@ -92,7 +93,8 @@ const handleStoreItemAcquisition = async ( component.typeName, accountId, component.purchaseQuantity * quantity, - component.durability + component.durability, + true ) ).InventoryChanges ); @@ -101,9 +103,14 @@ const handleStoreItemAcquisition = async ( const storeCategory = getStoreItemCategory(storeItemName); const internalName = storeItemName.replace("/StoreItems", ""); logger.debug(`store category ${storeCategory}`); + if (!ignorePurchaseQuantity) { + if (internalName in ExportGear) { + quantity *= ExportGear[internalName].purchaseQuantity || 1; + } + } switch (storeCategory) { default: - purchaseResponse = await addItem(accountId, internalName); + purchaseResponse = await addItem(accountId, internalName, quantity); break; case "Types": purchaseResponse = await handleTypesPurchase(internalName, accountId, quantity);