chore: cleanup purchase stuff #2266
@ -11,13 +11,13 @@ import {
|
|||||||
import { getAccountForRequest, getSuffixedName } from "@/src/services/loginService";
|
import { getAccountForRequest, getSuffixedName } from "@/src/services/loginService";
|
||||||
import { handleStoreItemAcquisition } from "@/src/services/purchaseService";
|
import { handleStoreItemAcquisition } from "@/src/services/purchaseService";
|
||||||
import { IOid } from "@/src/types/commonTypes";
|
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 { RequestHandler } from "express";
|
||||||
import { ExportBundles, ExportFlavour } from "warframe-public-export-plus";
|
import { ExportBundles, ExportFlavour } from "warframe-public-export-plus";
|
||||||
|
|
||||||
export const giftingController: RequestHandler = async (req, res) => {
|
export const giftingController: RequestHandler = async (req, res) => {
|
||||||
const data = getJSONfromString<IGiftingRequest>(String(req.body));
|
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)}`);
|
throw new Error(`unexpected purchase params in gifting request: ${String(req.body)}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,13 @@ import {
|
|||||||
import { getRandomWeightedRewardUc } from "@/src/services/rngService";
|
import { getRandomWeightedRewardUc } from "@/src/services/rngService";
|
||||||
import { applyStandingToVendorManifest, getVendorManifestByOid } from "@/src/services/serversideVendorsService";
|
import { applyStandingToVendorManifest, getVendorManifestByOid } from "@/src/services/serversideVendorsService";
|
||||||
import { IMiscItem } from "@/src/types/inventoryTypes/inventoryTypes";
|
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 { logger } from "@/src/utils/logger";
|
||||||
import worldState from "@/static/fixed_responses/worldState/worldState.json";
|
import worldState from "@/static/fixed_responses/worldState/worldState.json";
|
||||||
import {
|
import {
|
||||||
@ -52,7 +58,7 @@ export const handlePurchase = async (
|
|||||||
|
|
||||||
const prePurchaseInventoryChanges: IInventoryChanges = {};
|
const prePurchaseInventoryChanges: IInventoryChanges = {};
|
||||||
let seed: bigint | undefined;
|
let seed: bigint | undefined;
|
||||||
if (purchaseRequest.PurchaseParams.Source == 7) {
|
if (purchaseRequest.PurchaseParams.Source == PurchaseSource.Vendor) {
|
||||||
let manifest = getVendorManifestByOid(purchaseRequest.PurchaseParams.SourceId!);
|
let manifest = getVendorManifestByOid(purchaseRequest.PurchaseParams.SourceId!);
|
||||||
if (manifest) {
|
if (manifest) {
|
||||||
manifest = applyStandingToVendorManifest(inventory, manifest);
|
manifest = applyStandingToVendorManifest(inventory, manifest);
|
||||||
@ -69,18 +75,12 @@ export const handlePurchase = async (
|
|||||||
}
|
}
|
||||||
if (!config.dontSubtractPurchaseCreditCost) {
|
if (!config.dontSubtractPurchaseCreditCost) {
|
||||||
if (offer.RegularPrice) {
|
if (offer.RegularPrice) {
|
||||||
combineInventoryChanges(
|
updateCurrency(inventory, offer.RegularPrice[0], false, prePurchaseInventoryChanges);
|
||||||
prePurchaseInventoryChanges,
|
|
||||||
updateCurrency(inventory, offer.RegularPrice[0], false)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!config.dontSubtractPurchasePlatinumCost) {
|
if (!config.dontSubtractPurchasePlatinumCost) {
|
||||||
if (offer.PremiumPrice) {
|
if (offer.PremiumPrice) {
|
||||||
combineInventoryChanges(
|
updateCurrency(inventory, offer.PremiumPrice[0], true, prePurchaseInventoryChanges);
|
||||||
prePurchaseInventoryChanges,
|
|
||||||
updateCurrency(inventory, offer.PremiumPrice[0], true)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!config.dontSubtractPurchaseItemCost) {
|
if (!config.dontSubtractPurchaseItemCost) {
|
||||||
@ -166,18 +166,15 @@ export const handlePurchase = async (
|
|||||||
);
|
);
|
||||||
combineInventoryChanges(purchaseResponse.InventoryChanges, prePurchaseInventoryChanges);
|
combineInventoryChanges(purchaseResponse.InventoryChanges, prePurchaseInventoryChanges);
|
||||||
|
|
||||||
const currencyChanges = updateCurrency(
|
updateCurrency(
|
||||||
inventory,
|
inventory,
|
||||||
purchaseRequest.PurchaseParams.ExpectedPrice,
|
purchaseRequest.PurchaseParams.ExpectedPrice,
|
||||||
purchaseRequest.PurchaseParams.UsePremium
|
purchaseRequest.PurchaseParams.UsePremium,
|
||||||
|
prePurchaseInventoryChanges
|
||||||
);
|
);
|
||||||
purchaseResponse.InventoryChanges = {
|
|
||||||
...currencyChanges,
|
|
||||||
...purchaseResponse.InventoryChanges
|
|
||||||
};
|
|
||||||
|
|
||||||
switch (purchaseRequest.PurchaseParams.Source) {
|
switch (purchaseRequest.PurchaseParams.Source) {
|
||||||
case 1: {
|
case PurchaseSource.VoidTrader: {
|
||||||
if (purchaseRequest.PurchaseParams.SourceId! != worldState.VoidTraders[0]._id.$oid) {
|
if (purchaseRequest.PurchaseParams.SourceId! != worldState.VoidTraders[0]._id.$oid) {
|
||||||
throw new Error("invalid request source");
|
throw new Error("invalid request source");
|
||||||
}
|
}
|
||||||
@ -186,10 +183,7 @@ export const handlePurchase = async (
|
|||||||
);
|
);
|
||||||
if (offer) {
|
if (offer) {
|
||||||
if (!config.dontSubtractPurchaseCreditCost) {
|
if (!config.dontSubtractPurchaseCreditCost) {
|
||||||
combineInventoryChanges(
|
updateCurrency(inventory, offer.RegularPrice, false, purchaseResponse.InventoryChanges);
|
||||||
purchaseResponse.InventoryChanges,
|
|
||||||
updateCurrency(inventory, offer.RegularPrice, false)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if (purchaseRequest.PurchaseParams.ExpectedPrice) {
|
if (purchaseRequest.PurchaseParams.ExpectedPrice) {
|
||||||
throw new Error(`vendor purchase should not have an expected price`);
|
throw new Error(`vendor purchase should not have an expected price`);
|
||||||
@ -207,7 +201,7 @@ export const handlePurchase = async (
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 2:
|
case PurchaseSource.SyndicateFavor:
|
||||||
{
|
{
|
||||||
const syndicateTag = purchaseRequest.PurchaseParams.SyndicateTag!;
|
const syndicateTag = purchaseRequest.PurchaseParams.SyndicateTag!;
|
||||||
if (purchaseRequest.PurchaseParams.UseFreeFavor!) {
|
if (purchaseRequest.PurchaseParams.UseFreeFavor!) {
|
||||||
@ -244,22 +238,16 @@ export const handlePurchase = async (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 7:
|
case PurchaseSource.Vendor:
|
||||||
if (purchaseRequest.PurchaseParams.SourceId! in ExportVendors) {
|
if (purchaseRequest.PurchaseParams.SourceId! in ExportVendors) {
|
||||||
const vendor = ExportVendors[purchaseRequest.PurchaseParams.SourceId!];
|
const vendor = ExportVendors[purchaseRequest.PurchaseParams.SourceId!];
|
||||||
const offer = vendor.items.find(x => x.storeItem == purchaseRequest.PurchaseParams.StoreItem);
|
const offer = vendor.items.find(x => x.storeItem == purchaseRequest.PurchaseParams.StoreItem);
|
||||||
if (offer) {
|
if (offer) {
|
||||||
if (typeof offer.credits == "number" && !config.dontSubtractPurchaseCreditCost) {
|
if (typeof offer.credits == "number" && !config.dontSubtractPurchaseCreditCost) {
|
||||||
combineInventoryChanges(
|
updateCurrency(inventory, offer.credits, false, purchaseResponse.InventoryChanges);
|
||||||
purchaseResponse.InventoryChanges,
|
|
||||||
updateCurrency(inventory, offer.credits, false)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if (typeof offer.platinum == "number" && !config.dontSubtractPurchasePlatinumCost) {
|
if (typeof offer.platinum == "number" && !config.dontSubtractPurchasePlatinumCost) {
|
||||||
combineInventoryChanges(
|
updateCurrency(inventory, offer.platinum, true, purchaseResponse.InventoryChanges);
|
||||||
purchaseResponse.InventoryChanges,
|
|
||||||
updateCurrency(inventory, offer.platinum, true)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if (offer.itemPrices && !config.dontSubtractPurchaseItemCost) {
|
if (offer.itemPrices && !config.dontSubtractPurchaseItemCost) {
|
||||||
handleItemPrices(
|
handleItemPrices(
|
||||||
@ -275,7 +263,7 @@ export const handlePurchase = async (
|
|||||||
throw new Error(`vendor purchase should not have an expected price`);
|
throw new Error(`vendor purchase should not have an expected price`);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 18: {
|
case PurchaseSource.PrimeVaultTrader: {
|
||||||
if (purchaseRequest.PurchaseParams.SourceId! != worldState.PrimeVaultTraders[0]._id.$oid) {
|
if (purchaseRequest.PurchaseParams.SourceId! != worldState.PrimeVaultTraders[0]._id.$oid) {
|
||||||
throw new Error("invalid request source");
|
throw new Error("invalid request source");
|
||||||
}
|
}
|
||||||
|
@ -10,14 +10,42 @@ import {
|
|||||||
ICrewMemberClient
|
ICrewMemberClient
|
||||||
} from "./inventoryTypes/inventoryTypes";
|
} 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 {
|
export interface IPurchaseRequest {
|
||||||
PurchaseParams: IPurchaseParams;
|
PurchaseParams: IPurchaseParams;
|
||||||
buildLabel: string;
|
buildLabel: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IPurchaseParams {
|
export interface IPurchaseParams {
|
||||||
Source: number;
|
Source: PurchaseSource;
|
||||||
SourceId?: string; // for Source 1, 7 & 18
|
SourceId?: string; // VoidTrader, Vendor, PrimeVaultTrader
|
||||||
StoreItem: string;
|
StoreItem: string;
|
||||||
StorePage: string;
|
StorePage: string;
|
||||||
SearchTerm: string;
|
SearchTerm: string;
|
||||||
@ -25,10 +53,10 @@ export interface IPurchaseParams {
|
|||||||
Quantity: number;
|
Quantity: number;
|
||||||
UsePremium: boolean;
|
UsePremium: boolean;
|
||||||
ExpectedPrice: number;
|
ExpectedPrice: number;
|
||||||
SyndicateTag?: string; // for Source 2
|
SyndicateTag?: string; // SyndicateFavor
|
||||||
UseFreeFavor?: boolean; // for Source 2
|
UseFreeFavor?: boolean; // SyndicateFavor
|
||||||
ExtraPurchaseInfoJson?: string; // for Source 7
|
ExtraPurchaseInfoJson?: string; // Vendor
|
||||||
IsWeekly?: boolean; // for Source 7
|
IsWeekly?: boolean; // Vendor
|
||||||
}
|
}
|
||||||
|
|
||||||
export type IInventoryChanges = {
|
export type IInventoryChanges = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user