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

XFESpaceNinjaServer

A simple server for a small space ninja game

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

XFEstudio/XFESpaceNinjaServer

feat: purchasing of bundles (#301)

5036d6db
Sainan <sainan@calamity.gg>
提交于

代码差异

3 个文件 +51 -25
Modified package-lock.json +4 -4
@@ -13,7 +13,7 @@
13 13 "express": "^5.0.0-beta.3",
14 14 "mongoose": "^8.1.1",
15 15 "warframe-items": "^1.1262.74",
16 "warframe-public-export-plus": "^0.2.2",
16 "warframe-public-export-plus": "^0.2.3",
17 17 "warframe-riven-info": "^0.1.0",
18 18 "winston": "^3.11.0",
19 19 "winston-daily-rotate-file": "^4.7.1"
@@ -3909,9 +3909,9 @@
3909 3909 }
3910 3910 },
3911 3911 "node_modules/warframe-public-export-plus": {
3912 "version": "0.2.2",
3913 "resolved": "https://registry.npmjs.org/warframe-public-export-plus/-/warframe-public-export-plus-0.2.2.tgz",
3914 "integrity": "sha512-PAsiyiRDqXcsUwZTweihwrSksd+GT3USrbHwS/TrJUC3TqLS0Ng24OfefFKPWOmPfMxDbdkg2zV39uq72iZ/Yg=="
3912 "version": "0.2.3",
3913 "resolved": "https://registry.npmjs.org/warframe-public-export-plus/-/warframe-public-export-plus-0.2.3.tgz",
3914 "integrity": "sha512-Bl4gb3f1LIdGXLEOJg2XTIFYqrialdTIvVhDqDzVJIRfii0PKsy9jsr9vqM14tWz7oVpQMeCUyvisDkkXijTSg=="
3915 3915 },
3916 3916 "node_modules/warframe-riven-info": {
3917 3917 "version": "0.1.0",
Modified package.json +1 -1
@@ -17,7 +17,7 @@
17 17 "express": "^5.0.0-beta.3",
18 18 "mongoose": "^8.1.1",
19 19 "warframe-items": "^1.1262.74",
20 "warframe-public-export-plus": "^0.2.2",
20 "warframe-public-export-plus": "^0.2.3",
21 21 "warframe-riven-info": "^0.1.0",
22 22 "winston": "^3.11.0",
23 23 "winston-daily-rotate-file": "^4.7.1"
Modified src/services/purchaseService.ts +46 -20
@@ -3,6 +3,7 @@ import { getSubstringFromKeyword } from "@/src/helpers/stringHelpers";
3 3 import { addItem, addBooster, updateCurrency, updateSlots } from "@/src/services/inventoryService";
4 4 import { IPurchaseRequest, SlotPurchase } from "@/src/types/purchaseTypes";
5 5 import { logger } from "@/src/utils/logger";
6 import { ExportBundles } from "warframe-public-export-plus";
6 7
7 8 export const getStoreItemCategory = (storeItem: string) => {
8 9 const storeItemString = getSubstringFromKeyword(storeItem, "StoreItems/");
@@ -21,26 +22,12 @@ export const getStoreItemTypesCategory = (typesItem: string) => {
21 22
22 23 export const handlePurchase = async (purchaseRequest: IPurchaseRequest, accountId: string) => {
23 24 logger.debug("purchase request", purchaseRequest);
24 const storeCategory = getStoreItemCategory(purchaseRequest.PurchaseParams.StoreItem);
25 const internalName = purchaseRequest.PurchaseParams.StoreItem.replace("/StoreItems", "");
26 logger.debug(`store category ${storeCategory}`);
27 25
28 let purchaseResponse;
29 switch (storeCategory) {
30 default:
31 purchaseResponse = await addItem(accountId, internalName);
32 break;
33 case "Types":
34 purchaseResponse = await handleTypesPurchase(
35 internalName,
36 accountId,
37 purchaseRequest.PurchaseParams.Quantity
38 );
39 break;
40 case "Boosters":
41 purchaseResponse = await handleBoostersPurchase(internalName, accountId);
42 break;
43 }
26 const purchaseResponse = await handleStoreItemAcquisition(
27 purchaseRequest.PurchaseParams.StoreItem,
28 accountId,
29 purchaseRequest.PurchaseParams.Quantity
30 );
44 31
45 32 if (!purchaseResponse) throw new Error("purchase response was undefined");
46 33
@@ -58,6 +45,43 @@ export const handlePurchase = async (purchaseRequest: IPurchaseRequest, accountI
58 45 return purchaseResponse;
59 46 };
60 47
48 const handleStoreItemAcquisition = async (
49 storeItemName: string,
50 accountId: string,
51 quantity: number
52 ): Promise<{ InventoryChanges: object }> => {
53 let purchaseResponse = {
54 InventoryChanges: {}
55 };
56 logger.debug(`handling acquision of ${storeItemName}`);
57 if (storeItemName in ExportBundles) {
58 const bundle = ExportBundles[storeItemName];
59 logger.debug("acquiring bundle", bundle);
60 for (const component of bundle.components) {
61 purchaseResponse = {
62 ...purchaseResponse,
63 ...(await handleStoreItemAcquisition(component.typeName, accountId, component.purchaseQuantity))
64 };
65 }
66 } else {
67 const storeCategory = getStoreItemCategory(storeItemName);
68 const internalName = storeItemName.replace("/StoreItems", "");
69 logger.debug(`store category ${storeCategory}`);
70 switch (storeCategory) {
71 default:
72 purchaseResponse = await addItem(accountId, internalName);
73 break;
74 case "Types":
75 purchaseResponse = await handleTypesPurchase(internalName, accountId, quantity);
76 break;
77 case "Boosters":
78 purchaseResponse = await handleBoostersPurchase(internalName, accountId);
79 break;
80 }
81 }
82 return purchaseResponse;
83 };
84
61 85 export const slotPurchaseNameToSlotName: SlotPurchase = {
62 86 SuitSlotItem: { name: "SuitBin", slotsPerPurchase: 1 },
63 87 TwoSentinelSlotItem: { name: "SentinelBin", slotsPerPurchase: 2 },
@@ -122,7 +146,9 @@ const boosterCollection = [
122 146
123 147 const handleBoostersPurchase = async (boosterStoreName: string, accountId: string) => {
124 148 const match = boosterStoreName.match(/(\d+)Day/);
125 if (!match) return;
149 if (!match) {
150 return { InventoryChanges: {} };
151 }
126 152
127 153 const extractedDigit = Number(match[1]);
128 154 const ItemType = boosterCollection.find(i =>