chore: cleanup purchase stuff #2266

Merged
Sainan merged 3 commits from purchase-refactor into main 2025-06-23 21:51:10 -07:00
3 changed files with 56 additions and 40 deletions

View File

@ -11,13 +11,13 @@ import {
import { getAccountForRequest, getSuffixedName } from "@/src/services/loginService";
import { handleStoreItemAcquisition } from "@/src/services/purchaseService";
import { IOid } from "@/src/types/commonTypes";
import { IInventoryChanges, IPurchaseParams } from "@/src/types/purchaseTypes";
import { IInventoryChanges, IPurchaseParams, PurchaseSource } from "@/src/types/purchaseTypes";
import { RequestHandler } from "express";
import { ExportBundles, ExportFlavour } from "warframe-public-export-plus";
export const giftingController: RequestHandler = async (req, res) => {
const data = getJSONfromString<IGiftingRequest>(String(req.body));
if (data.PurchaseParams.Source != 0 || !data.PurchaseParams.UsePremium) {
if (data.PurchaseParams.Source != PurchaseSource.Market || !data.PurchaseParams.UsePremium) {
throw new Error(`unexpected purchase params in gifting request: ${String(req.body)}`);
}

View File

@ -11,7 +11,13 @@ import {
import { getRandomWeightedRewardUc } from "@/src/services/rngService";
import { applyStandingToVendorManifest, getVendorManifestByOid } from "@/src/services/serversideVendorsService";
import { IMiscItem } from "@/src/types/inventoryTypes/inventoryTypes";
import { IPurchaseRequest, IPurchaseResponse, SlotPurchase, IInventoryChanges } from "@/src/types/purchaseTypes";
import {
IPurchaseRequest,
IPurchaseResponse,
SlotPurchase,
IInventoryChanges,
PurchaseSource
} from "@/src/types/purchaseTypes";
import { logger } from "@/src/utils/logger";
import worldState from "@/static/fixed_responses/worldState/worldState.json";
import {
@ -52,7 +58,7 @@ export const handlePurchase = async (
const prePurchaseInventoryChanges: IInventoryChanges = {};
let seed: bigint | undefined;
if (purchaseRequest.PurchaseParams.Source == 7) {
if (purchaseRequest.PurchaseParams.Source == PurchaseSource.Vendor) {
let manifest = getVendorManifestByOid(purchaseRequest.PurchaseParams.SourceId!);
if (manifest) {
manifest = applyStandingToVendorManifest(inventory, manifest);
@ -69,18 +75,12 @@ export const handlePurchase = async (
}
if (!config.dontSubtractPurchaseCreditCost) {
if (offer.RegularPrice) {
combineInventoryChanges(
prePurchaseInventoryChanges,
updateCurrency(inventory, offer.RegularPrice[0], false)
);
updateCurrency(inventory, offer.RegularPrice[0], false, prePurchaseInventoryChanges);
}
}
if (!config.dontSubtractPurchasePlatinumCost) {
if (offer.PremiumPrice) {
combineInventoryChanges(
prePurchaseInventoryChanges,
updateCurrency(inventory, offer.PremiumPrice[0], true)
);
updateCurrency(inventory, offer.PremiumPrice[0], true, prePurchaseInventoryChanges);
}
}
if (!config.dontSubtractPurchaseItemCost) {
@ -166,18 +166,15 @@ export const handlePurchase = async (
);
combineInventoryChanges(purchaseResponse.InventoryChanges, prePurchaseInventoryChanges);
const currencyChanges = updateCurrency(
updateCurrency(
inventory,
purchaseRequest.PurchaseParams.ExpectedPrice,
purchaseRequest.PurchaseParams.UsePremium
purchaseRequest.PurchaseParams.UsePremium,
prePurchaseInventoryChanges
);
purchaseResponse.InventoryChanges = {
...currencyChanges,
...purchaseResponse.InventoryChanges
};
switch (purchaseRequest.PurchaseParams.Source) {
case 1: {
case PurchaseSource.VoidTrader: {
if (purchaseRequest.PurchaseParams.SourceId! != worldState.VoidTraders[0]._id.$oid) {
throw new Error("invalid request source");
}
@ -186,10 +183,7 @@ export const handlePurchase = async (
);
if (offer) {
if (!config.dontSubtractPurchaseCreditCost) {
combineInventoryChanges(
purchaseResponse.InventoryChanges,
updateCurrency(inventory, offer.RegularPrice, false)
);
updateCurrency(inventory, offer.RegularPrice, false, purchaseResponse.InventoryChanges);
}
if (purchaseRequest.PurchaseParams.ExpectedPrice) {
throw new Error(`vendor purchase should not have an expected price`);
@ -207,7 +201,7 @@ export const handlePurchase = async (
}
break;
}
case 2:
case PurchaseSource.SyndicateFavor:
{
const syndicateTag = purchaseRequest.PurchaseParams.SyndicateTag!;
if (purchaseRequest.PurchaseParams.UseFreeFavor!) {
@ -244,22 +238,16 @@ export const handlePurchase = async (
}
}
break;
case 7:
case PurchaseSource.Vendor:
if (purchaseRequest.PurchaseParams.SourceId! in ExportVendors) {
const vendor = ExportVendors[purchaseRequest.PurchaseParams.SourceId!];
const offer = vendor.items.find(x => x.storeItem == purchaseRequest.PurchaseParams.StoreItem);
if (offer) {
if (typeof offer.credits == "number" && !config.dontSubtractPurchaseCreditCost) {
combineInventoryChanges(
purchaseResponse.InventoryChanges,
updateCurrency(inventory, offer.credits, false)
);
updateCurrency(inventory, offer.credits, false, purchaseResponse.InventoryChanges);
}
if (typeof offer.platinum == "number" && !config.dontSubtractPurchasePlatinumCost) {
combineInventoryChanges(
purchaseResponse.InventoryChanges,
updateCurrency(inventory, offer.platinum, true)
);
updateCurrency(inventory, offer.platinum, true, purchaseResponse.InventoryChanges);
}
if (offer.itemPrices && !config.dontSubtractPurchaseItemCost) {
handleItemPrices(
@ -275,7 +263,7 @@ export const handlePurchase = async (
throw new Error(`vendor purchase should not have an expected price`);
}
break;
case 18: {
case PurchaseSource.PrimeVaultTrader: {
if (purchaseRequest.PurchaseParams.SourceId! != worldState.PrimeVaultTraders[0]._id.$oid) {
throw new Error("invalid request source");
}

View File

@ -10,14 +10,42 @@ import {
ICrewMemberClient
} from "./inventoryTypes/inventoryTypes";
export enum PurchaseSource {
Market = 0,
VoidTrader = 1,
SyndicateFavor = 2,
DailyDeal = 3,
Arsenal = 4,
Profile = 5,
Hub = 6,
Vendor = 7,
AppearancePreview = 8,
Museum = 9,
Operator = 10,
PlayerShip = 11,
Crewship = 12,
MenuStyle = 13,
MenuHud = 14,
Chat = 15,
Inventory = 16,
StarChart = 17,
PrimeVaultTrader = 18,
Incubator = 19,
Prompt = 20,
Kaithe = 21,
DuviriWeapon = 22,
UpdateScreen = 23,
Motorcycle = 24
}
export interface IPurchaseRequest {
PurchaseParams: IPurchaseParams;
buildLabel: string;
}
export interface IPurchaseParams {
Source: number;
SourceId?: string; // for Source 1, 7 & 18
Source: PurchaseSource;
SourceId?: string; // VoidTrader, Vendor, PrimeVaultTrader
StoreItem: string;
StorePage: string;
SearchTerm: string;
@ -25,10 +53,10 @@ export interface IPurchaseParams {
Quantity: number;
UsePremium: boolean;
ExpectedPrice: number;
SyndicateTag?: string; // for Source 2
UseFreeFavor?: boolean; // for Source 2
ExtraPurchaseInfoJson?: string; // for Source 7
IsWeekly?: boolean; // for Source 7
SyndicateTag?: string; // SyndicateFavor
UseFreeFavor?: boolean; // SyndicateFavor
ExtraPurchaseInfoJson?: string; // Vendor
IsWeekly?: boolean; // Vendor
}
export type IInventoryChanges = {