XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

SpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 1 Star 0
返回提交历史

XFEstudio/SpaceNinjaServer

chore: cleanup purchase stuff (#2266)

Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/2266 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>

12295003
Sainan <63328889+Sainan@users.noreply.github.com>
提交于

代码差异

3 个文件 +56 -40
Modified src/controllers/api/giftingController.ts +2 -2
@@ -11,13 +11,13 @@ import {
11 11 import { getAccountForRequest, getSuffixedName } from "@/src/services/loginService";
12 12 import { handleStoreItemAcquisition } from "@/src/services/purchaseService";
13 13 import { IOid } from "@/src/types/commonTypes";
14 import { IInventoryChanges, IPurchaseParams } from "@/src/types/purchaseTypes";
14 import { IInventoryChanges, IPurchaseParams, PurchaseSource } from "@/src/types/purchaseTypes";
15 15 import { RequestHandler } from "express";
16 16 import { ExportBundles, ExportFlavour } from "warframe-public-export-plus";
17 17
18 18 export const giftingController: RequestHandler = async (req, res) => {
19 19 const data = getJSONfromString<IGiftingRequest>(String(req.body));
20 if (data.PurchaseParams.Source != 0 || !data.PurchaseParams.UsePremium) {
20 if (data.PurchaseParams.Source != PurchaseSource.Market || !data.PurchaseParams.UsePremium) {
21 21 throw new Error(`unexpected purchase params in gifting request: ${String(req.body)}`);
22 22 }
23 23
Modified src/services/purchaseService.ts +20 -32
@@ -11,7 +11,13 @@ import {
11 11 import { getRandomWeightedRewardUc } from "@/src/services/rngService";
12 12 import { applyStandingToVendorManifest, getVendorManifestByOid } from "@/src/services/serversideVendorsService";
13 13 import { IMiscItem } from "@/src/types/inventoryTypes/inventoryTypes";
14 import { IPurchaseRequest, IPurchaseResponse, SlotPurchase, IInventoryChanges } from "@/src/types/purchaseTypes";
14 import {
15 IPurchaseRequest,
16 IPurchaseResponse,
17 SlotPurchase,
18 IInventoryChanges,
19 PurchaseSource
20 } from "@/src/types/purchaseTypes";
15 21 import { logger } from "@/src/utils/logger";
16 22 import worldState from "@/static/fixed_responses/worldState/worldState.json";
17 23 import {
@@ -52,7 +58,7 @@ export const handlePurchase = async (
52 58
53 59 const prePurchaseInventoryChanges: IInventoryChanges = {};
54 60 let seed: bigint | undefined;
55 if (purchaseRequest.PurchaseParams.Source == 7) {
61 if (purchaseRequest.PurchaseParams.Source == PurchaseSource.Vendor) {
56 62 let manifest = getVendorManifestByOid(purchaseRequest.PurchaseParams.SourceId!);
57 63 if (manifest) {
58 64 manifest = applyStandingToVendorManifest(inventory, manifest);
@@ -69,18 +75,12 @@ export const handlePurchase = async (
69 75 }
70 76 if (!config.dontSubtractPurchaseCreditCost) {
71 77 if (offer.RegularPrice) {
72 combineInventoryChanges(
73 prePurchaseInventoryChanges,
74 updateCurrency(inventory, offer.RegularPrice[0], false)
75 );
78 updateCurrency(inventory, offer.RegularPrice[0], false, prePurchaseInventoryChanges);
76 79 }
77 80 }
78 81 if (!config.dontSubtractPurchasePlatinumCost) {
79 82 if (offer.PremiumPrice) {
80 combineInventoryChanges(
81 prePurchaseInventoryChanges,
82 updateCurrency(inventory, offer.PremiumPrice[0], true)
83 );
83 updateCurrency(inventory, offer.PremiumPrice[0], true, prePurchaseInventoryChanges);
84 84 }
85 85 }
86 86 if (!config.dontSubtractPurchaseItemCost) {
@@ -166,18 +166,15 @@ export const handlePurchase = async (
166 166 );
167 167 combineInventoryChanges(purchaseResponse.InventoryChanges, prePurchaseInventoryChanges);
168 168
169 const currencyChanges = updateCurrency(
169 updateCurrency(
170 170 inventory,
171 171 purchaseRequest.PurchaseParams.ExpectedPrice,
172 purchaseRequest.PurchaseParams.UsePremium
172 purchaseRequest.PurchaseParams.UsePremium,
173 prePurchaseInventoryChanges
173 174 );
174 purchaseResponse.InventoryChanges = {
175 ...currencyChanges,
176 ...purchaseResponse.InventoryChanges
177 };
178 175
179 176 switch (purchaseRequest.PurchaseParams.Source) {
180 case 1: {
177 case PurchaseSource.VoidTrader: {
181 178 if (purchaseRequest.PurchaseParams.SourceId! != worldState.VoidTraders[0]._id.$oid) {
182 179 throw new Error("invalid request source");
183 180 }
@@ -186,10 +183,7 @@ export const handlePurchase = async (
186 183 );
187 184 if (offer) {
188 185 if (!config.dontSubtractPurchaseCreditCost) {
189 combineInventoryChanges(
190 purchaseResponse.InventoryChanges,
191 updateCurrency(inventory, offer.RegularPrice, false)
192 );
186 updateCurrency(inventory, offer.RegularPrice, false, purchaseResponse.InventoryChanges);
193 187 }
194 188 if (purchaseRequest.PurchaseParams.ExpectedPrice) {
195 189 throw new Error(`vendor purchase should not have an expected price`);
@@ -207,7 +201,7 @@ export const handlePurchase = async (
207 201 }
208 202 break;
209 203 }
210 case 2:
204 case PurchaseSource.SyndicateFavor:
211 205 {
212 206 const syndicateTag = purchaseRequest.PurchaseParams.SyndicateTag!;
213 207 if (purchaseRequest.PurchaseParams.UseFreeFavor!) {
@@ -244,22 +238,16 @@ export const handlePurchase = async (
244 238 }
245 239 }
246 240 break;
247 case 7:
241 case PurchaseSource.Vendor:
248 242 if (purchaseRequest.PurchaseParams.SourceId! in ExportVendors) {
249 243 const vendor = ExportVendors[purchaseRequest.PurchaseParams.SourceId!];
250 244 const offer = vendor.items.find(x => x.storeItem == purchaseRequest.PurchaseParams.StoreItem);
251 245 if (offer) {
252 246 if (typeof offer.credits == "number" && !config.dontSubtractPurchaseCreditCost) {
253 combineInventoryChanges(
254 purchaseResponse.InventoryChanges,
255 updateCurrency(inventory, offer.credits, false)
256 );
247 updateCurrency(inventory, offer.credits, false, purchaseResponse.InventoryChanges);
257 248 }
258 249 if (typeof offer.platinum == "number" && !config.dontSubtractPurchasePlatinumCost) {
259 combineInventoryChanges(
260 purchaseResponse.InventoryChanges,
261 updateCurrency(inventory, offer.platinum, true)
262 );
250 updateCurrency(inventory, offer.platinum, true, purchaseResponse.InventoryChanges);
263 251 }
264 252 if (offer.itemPrices && !config.dontSubtractPurchaseItemCost) {
265 253 handleItemPrices(
@@ -275,7 +263,7 @@ export const handlePurchase = async (
275 263 throw new Error(`vendor purchase should not have an expected price`);
276 264 }
277 265 break;
278 case 18: {
266 case PurchaseSource.PrimeVaultTrader: {
279 267 if (purchaseRequest.PurchaseParams.SourceId! != worldState.PrimeVaultTraders[0]._id.$oid) {
280 268 throw new Error("invalid request source");
281 269 }
Modified src/types/purchaseTypes.ts +34 -6
@@ -10,14 +10,42 @@ import {
10 10 ICrewMemberClient
11 11 } from "./inventoryTypes/inventoryTypes";
12 12
13 export enum PurchaseSource {
14 Market = 0,
15 VoidTrader = 1,
16 SyndicateFavor = 2,
17 DailyDeal = 3,
18 Arsenal = 4,
19 Profile = 5,
20 Hub = 6,
21 Vendor = 7,
22 AppearancePreview = 8,
23 Museum = 9,
24 Operator = 10,
25 PlayerShip = 11,
26 Crewship = 12,
27 MenuStyle = 13,
28 MenuHud = 14,
29 Chat = 15,
30 Inventory = 16,
31 StarChart = 17,
32 PrimeVaultTrader = 18,
33 Incubator = 19,
34 Prompt = 20,
35 Kaithe = 21,
36 DuviriWeapon = 22,
37 UpdateScreen = 23,
38 Motorcycle = 24
39 }
40
13 41 export interface IPurchaseRequest {
14 42 PurchaseParams: IPurchaseParams;
15 43 buildLabel: string;
16 44 }
17 45
18 46 export interface IPurchaseParams {
19 Source: number;
20 SourceId?: string; // for Source 1, 7 & 18
47 Source: PurchaseSource;
48 SourceId?: string; // VoidTrader, Vendor, PrimeVaultTrader
21 49 StoreItem: string;
22 50 StorePage: string;
23 51 SearchTerm: string;
@@ -25,10 +53,10 @@ export interface IPurchaseParams {
25 53 Quantity: number;
26 54 UsePremium: boolean;
27 55 ExpectedPrice: number;
28 SyndicateTag?: string; // for Source 2
29 UseFreeFavor?: boolean; // for Source 2
30 ExtraPurchaseInfoJson?: string; // for Source 7
31 IsWeekly?: boolean; // for Source 7
56 SyndicateTag?: string; // SyndicateFavor
57 UseFreeFavor?: boolean; // SyndicateFavor
58 ExtraPurchaseInfoJson?: string; // Vendor
59 IsWeekly?: boolean; // Vendor
32 60 }
33 61
34 62 export type IInventoryChanges = {