From b761ff1bffdd67da3e0448f19520ba09c319230f Mon Sep 17 00:00:00 2001 From: Sainan Date: Thu, 20 Mar 2025 10:08:00 -0700 Subject: [PATCH] fix: tell client of PrimeTokens inventory change when buying from varzia (#1243) Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/1243 --- src/services/purchaseService.ts | 12 ++++++++---- src/types/purchaseTypes.ts | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/services/purchaseService.ts b/src/services/purchaseService.ts index d2985f1db..ef7a97b7c 100644 --- a/src/services/purchaseService.ts +++ b/src/services/purchaseService.ts @@ -50,7 +50,7 @@ export const handlePurchase = async ( ): Promise => { logger.debug("purchase request", purchaseRequest); - const inventoryChanges: IInventoryChanges = {}; + const prePurchaseInventoryChanges: IInventoryChanges = {}; if (purchaseRequest.PurchaseParams.Source == 7) { const manifest = getVendorManifestByOid(purchaseRequest.PurchaseParams.SourceId!); if (manifest) { @@ -65,7 +65,7 @@ export const handlePurchase = async ( inventory, offer.ItemPrices, purchaseRequest.PurchaseParams.Quantity, - inventoryChanges + prePurchaseInventoryChanges ); } if (!config.noVendorPurchaseLimits) { @@ -94,7 +94,7 @@ export const handlePurchase = async ( Expiry: new Date(parseInt(offer.Expiry.$date.$numberLong)) }); } - inventoryChanges.RecentVendorPurchases = [ + prePurchaseInventoryChanges.RecentVendorPurchases = [ { VendorType: manifest.VendorInfo.TypeName, PurchaseHistory: [ @@ -121,7 +121,7 @@ export const handlePurchase = async ( inventory, purchaseRequest.PurchaseParams.Quantity ); - combineInventoryChanges(purchaseResponse.InventoryChanges, inventoryChanges); + combineInventoryChanges(purchaseResponse.InventoryChanges, prePurchaseInventoryChanges); const currencyChanges = updateCurrency( inventory, @@ -240,6 +240,10 @@ export const handlePurchase = async ( purchaseResponse.InventoryChanges.MiscItems.push(invItem); } else if (!config.infiniteRegalAya) { inventory.PrimeTokens -= offer.PrimePrice! * purchaseRequest.PurchaseParams.Quantity; + + purchaseResponse.InventoryChanges.PrimeTokens ??= 0; + purchaseResponse.InventoryChanges.PrimeTokens -= + offer.PrimePrice! * purchaseRequest.PurchaseParams.Quantity; } } break; diff --git a/src/types/purchaseTypes.ts b/src/types/purchaseTypes.ts index 862bc0955..35bb21239 100644 --- a/src/types/purchaseTypes.ts +++ b/src/types/purchaseTypes.ts @@ -36,6 +36,7 @@ export type IInventoryChanges = { RegularCredits?: number; PremiumCredits?: number; PremiumCreditsFree?: number; + PrimeTokens?: number; InfestedFoundry?: IInfestedFoundryClient; Drones?: IDroneClient[]; MiscItems?: IMiscItem[];