From 5bd32f83872683cccfea5c31d5e567780058374e Mon Sep 17 00:00:00 2001 From: Sainan Date: Sun, 22 Dec 2024 21:57:30 +0100 Subject: [PATCH 1/3] feat: implement aya costs for varzia offers --- src/models/inventoryModels/inventoryModel.ts | 2 ++ src/services/purchaseService.ts | 30 ++++++++++++++++++++ src/types/inventoryTypes/inventoryTypes.ts | 1 + src/types/purchaseTypes.ts | 2 +- 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/models/inventoryModels/inventoryModel.ts b/src/models/inventoryModels/inventoryModel.ts index 28292ba4..d85f6d11 100644 --- a/src/models/inventoryModels/inventoryModel.ts +++ b/src/models/inventoryModels/inventoryModel.ts @@ -605,6 +605,8 @@ const inventorySchema = new Schema( PremiumCreditsFree: Number, //Endo FusionPoints: Number, + //Regal Aya + PrimeTokens: Number, //Slots SuitBin: slotsBinSchema, diff --git a/src/services/purchaseService.ts b/src/services/purchaseService.ts index ea4673f0..a1f63785 100644 --- a/src/services/purchaseService.ts +++ b/src/services/purchaseService.ts @@ -12,6 +12,7 @@ import { import { IMiscItem } from "@/src/types/inventoryTypes/inventoryTypes"; import { IPurchaseRequest, SlotPurchase, IInventoryChanges } from "@/src/types/purchaseTypes"; import { logger } from "@/src/utils/logger"; +import worldState from "@/static/fixed_responses/worldState.json"; import { ExportBundles, ExportGear, ExportVendors, TRarity } from "warframe-public-export-plus"; export const getStoreItemCategory = (storeItem: string) => { @@ -84,6 +85,35 @@ export const handlePurchase = async (purchaseRequest: IPurchaseRequest, accountI } } break; + case 18: + if (purchaseRequest.PurchaseParams.SourceId! != worldState.PrimeVaultTraders[0]._id.$oid) { + throw new Error("invalid request source"); + } + const offer = + worldState.PrimeVaultTraders[0].Manifest.find( + x => x.ItemType == purchaseRequest.PurchaseParams.StoreItem + ) ?? + worldState.PrimeVaultTraders[0].EvergreenManifest.find( + x => x.ItemType == purchaseRequest.PurchaseParams.StoreItem + ); + if (offer) { + const inventory = await getInventory(accountId); + if (offer.RegularPrice) { + const invItem: IMiscItem = { + ItemType: "/Lotus/Types/Items/MiscItems/SchismKey", + ItemCount: offer.RegularPrice * -1 + }; + + addMiscItems(inventory, [invItem]); + + purchaseResponse.InventoryChanges.MiscItems ??= []; + (purchaseResponse.InventoryChanges.MiscItems as IMiscItem[]).push(invItem); + } else { + inventory.PrimeTokens -= offer.PrimePrice!; + } + await inventory.save(); + } + break; } return purchaseResponse; diff --git a/src/types/inventoryTypes/inventoryTypes.ts b/src/types/inventoryTypes/inventoryTypes.ts index fd207bc9..bb93d8e0 100644 --- a/src/types/inventoryTypes/inventoryTypes.ts +++ b/src/types/inventoryTypes/inventoryTypes.ts @@ -125,6 +125,7 @@ export interface IInventoryResponse { PremiumCredits: number; PremiumCreditsFree: number; FusionPoints: number; + PrimeTokens: number; SuitBin: ISlots; WeaponBin: ISlots; SentinelBin: ISlots; diff --git a/src/types/purchaseTypes.ts b/src/types/purchaseTypes.ts index 9a7edd1e..c09dff33 100644 --- a/src/types/purchaseTypes.ts +++ b/src/types/purchaseTypes.ts @@ -5,7 +5,7 @@ export interface IPurchaseRequest { export interface IPurchaseParams { Source: number; - SourceId?: string; // for Source 7 + SourceId?: string; // for Source 7 & 18 StoreItem: string; StorePage: string; SearchTerm: string; -- 2.47.2 From 6d3ea67273d31c5307d57b5e55d9ae8e1d657a43 Mon Sep 17 00:00:00 2001 From: Sainan Date: Sun, 22 Dec 2024 22:02:56 +0100 Subject: [PATCH 2/3] narrow scope of 'offer' variable --- src/services/purchaseService.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/services/purchaseService.ts b/src/services/purchaseService.ts index a1f63785..e1e444d9 100644 --- a/src/services/purchaseService.ts +++ b/src/services/purchaseService.ts @@ -85,7 +85,7 @@ export const handlePurchase = async (purchaseRequest: IPurchaseRequest, accountI } } break; - case 18: + case 18: { if (purchaseRequest.PurchaseParams.SourceId! != worldState.PrimeVaultTraders[0]._id.$oid) { throw new Error("invalid request source"); } @@ -114,6 +114,7 @@ export const handlePurchase = async (purchaseRequest: IPurchaseRequest, accountI await inventory.save(); } break; + } } return purchaseResponse; -- 2.47.2 From ae4fa79decf83ba3de7fb3cdc6ce8f36f491f45a Mon Sep 17 00:00:00 2001 From: Sainan Date: Sun, 22 Dec 2024 22:08:37 +0100 Subject: [PATCH 3/3] fix: scale non-standard prices by quantity --- src/services/purchaseService.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/services/purchaseService.ts b/src/services/purchaseService.ts index e1e444d9..fa1ff3d9 100644 --- a/src/services/purchaseService.ts +++ b/src/services/purchaseService.ts @@ -65,7 +65,7 @@ export const handlePurchase = async (purchaseRequest: IPurchaseRequest, accountI for (const item of offer.itemPrices) { const invItem: IMiscItem = { ItemType: item.ItemType, - ItemCount: item.ItemCount * -1 + ItemCount: item.ItemCount * purchaseRequest.PurchaseParams.Quantity * -1 }; addMiscItems(inventory, [invItem]); @@ -75,7 +75,7 @@ export const handlePurchase = async (purchaseRequest: IPurchaseRequest, accountI x => x.ItemType == item.ItemType ); if (change) { - change.ItemCount -= item.ItemCount; + change.ItemCount += invItem.ItemCount; } else { (purchaseResponse.InventoryChanges.MiscItems as IMiscItem[]).push(invItem); } @@ -101,7 +101,7 @@ export const handlePurchase = async (purchaseRequest: IPurchaseRequest, accountI if (offer.RegularPrice) { const invItem: IMiscItem = { ItemType: "/Lotus/Types/Items/MiscItems/SchismKey", - ItemCount: offer.RegularPrice * -1 + ItemCount: offer.RegularPrice * purchaseRequest.PurchaseParams.Quantity * -1 }; addMiscItems(inventory, [invItem]); @@ -109,7 +109,7 @@ export const handlePurchase = async (purchaseRequest: IPurchaseRequest, accountI purchaseResponse.InventoryChanges.MiscItems ??= []; (purchaseResponse.InventoryChanges.MiscItems as IMiscItem[]).push(invItem); } else { - inventory.PrimeTokens -= offer.PrimePrice!; + inventory.PrimeTokens -= offer.PrimePrice! * purchaseRequest.PurchaseParams.Quantity; } await inventory.save(); } -- 2.47.2