From 9fd6ed3b213637da5df3f03c280ed42c00a839d8 Mon Sep 17 00:00:00 2001 From: Sainan Date: Sun, 22 Dec 2024 20:35:08 +0100 Subject: [PATCH] fix: purchasing an arcane pack does not consume vosfor (#601) --- package-lock.json | 8 +++--- package.json | 2 +- src/services/purchaseService.ts | 43 ++++++++++++++++++++++++++++++--- src/types/purchaseTypes.ts | 1 + 4 files changed, 46 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index d51729a6..5f7cbf66 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "copyfiles": "^2.4.1", "express": "^5", "mongoose": "^8.9.2", - "warframe-public-export-plus": "^0.5.8", + "warframe-public-export-plus": "^0.5.9", "warframe-riven-info": "^0.1.2", "winston": "^3.17.0", "winston-daily-rotate-file": "^5.0.0" @@ -3877,9 +3877,9 @@ } }, "node_modules/warframe-public-export-plus": { - "version": "0.5.8", - "resolved": "https://registry.npmjs.org/warframe-public-export-plus/-/warframe-public-export-plus-0.5.8.tgz", - "integrity": "sha512-ZhHrKIkI6nhjKDlxhrNcfN8r2Yc9g+eeKLS6+9w7gzC4NscIt6TU8tH8bfjJTDeo6nRrzt88szX1/Oo3WnUY4Q==" + "version": "0.5.9", + "resolved": "https://registry.npmjs.org/warframe-public-export-plus/-/warframe-public-export-plus-0.5.9.tgz", + "integrity": "sha512-qwQVtYI7wghatg7UrJ3CFstXba5Hsks398L6ngv16auqoTVAfw/cLBqFv9DzsEpqvcVWL22IZIH+cNWiq1JXOQ==" }, "node_modules/warframe-riven-info": { "version": "0.1.2", diff --git a/package.json b/package.json index b968388b..ce81953a 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "copyfiles": "^2.4.1", "express": "^5", "mongoose": "^8.9.2", - "warframe-public-export-plus": "^0.5.8", + "warframe-public-export-plus": "^0.5.9", "warframe-riven-info": "^0.1.2", "winston": "^3.17.0", "winston-daily-rotate-file": "^5.0.0" diff --git a/src/services/purchaseService.ts b/src/services/purchaseService.ts index 29bdc218..ea4673f0 100644 --- a/src/services/purchaseService.ts +++ b/src/services/purchaseService.ts @@ -1,15 +1,18 @@ import { parseSlotPurchaseName } from "@/src/helpers/purchaseHelpers"; import { getSubstringFromKeyword } from "@/src/helpers/stringHelpers"; import { - addItem, addBooster, + addItem, + addMiscItems, combineInventoryChanges, + getInventory, updateCurrency, updateSlots } from "@/src/services/inventoryService"; +import { IMiscItem } from "@/src/types/inventoryTypes/inventoryTypes"; import { IPurchaseRequest, SlotPurchase, IInventoryChanges } from "@/src/types/purchaseTypes"; import { logger } from "@/src/utils/logger"; -import { ExportBundles, ExportGear, TRarity } from "warframe-public-export-plus"; +import { ExportBundles, ExportGear, ExportVendors, TRarity } from "warframe-public-export-plus"; export const getStoreItemCategory = (storeItem: string) => { const storeItemString = getSubstringFromKeyword(storeItem, "StoreItems/"); @@ -43,12 +46,46 @@ export const handlePurchase = async (purchaseRequest: IPurchaseRequest, accountI purchaseRequest.PurchaseParams.UsePremium, accountId ); - purchaseResponse.InventoryChanges = { ...currencyChanges, ...purchaseResponse.InventoryChanges }; + switch (purchaseRequest.PurchaseParams.Source) { + case 7: + if (!purchaseRequest.PurchaseParams.SourceId) { + throw new Error("invalid request source"); + } + if (ExportVendors[purchaseRequest.PurchaseParams.SourceId]) { + const vendor = ExportVendors[purchaseRequest.PurchaseParams.SourceId]; + const offer = vendor.items.find(x => x.storeItem == purchaseRequest.PurchaseParams.StoreItem); + if (offer) { + const inventory = await getInventory(accountId); + for (const item of offer.itemPrices) { + const invItem: IMiscItem = { + ItemType: item.ItemType, + ItemCount: item.ItemCount * -1 + }; + + addMiscItems(inventory, [invItem]); + + purchaseResponse.InventoryChanges.MiscItems ??= []; + const change = (purchaseResponse.InventoryChanges.MiscItems as IMiscItem[]).find( + x => x.ItemType == item.ItemType + ); + if (change) { + change.ItemCount -= item.ItemCount; + } else { + (purchaseResponse.InventoryChanges.MiscItems as IMiscItem[]).push(invItem); + } + } + + await inventory.save(); + } + } + break; + } + return purchaseResponse; }; diff --git a/src/types/purchaseTypes.ts b/src/types/purchaseTypes.ts index 0d04114e..9a7edd1e 100644 --- a/src/types/purchaseTypes.ts +++ b/src/types/purchaseTypes.ts @@ -5,6 +5,7 @@ export interface IPurchaseRequest { export interface IPurchaseParams { Source: number; + SourceId?: string; // for Source 7 StoreItem: string; StorePage: string; SearchTerm: string;