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

fix: not being able to purchase boosters (#316)

77c2761a
Sainan <sainan@calamity.gg>
提交于

代码差异

3 个文件 +29 -18
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.3",
16 "warframe-public-export-plus": "^0.2.4",
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.3",
3913 "resolved": "https://registry.npmjs.org/warframe-public-export-plus/-/warframe-public-export-plus-0.2.3.tgz",
3914 "integrity": "sha512-Bl4gb3f1LIdGXLEOJg2XTIFYqrialdTIvVhDqDzVJIRfii0PKsy9jsr9vqM14tWz7oVpQMeCUyvisDkkXijTSg=="
3912 "version": "0.2.4",
3913 "resolved": "https://registry.npmjs.org/warframe-public-export-plus/-/warframe-public-export-plus-0.2.4.tgz",
3914 "integrity": "sha512-Kh2+4p0qirTNUfHLr/nUJ1y/kH9mKnig28dwgpPaWt41ZfGzA+/qrpqI3DHYUvpd4wTCii/HItIy6tZtpTsy4Q=="
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.3",
20 "warframe-public-export-plus": "^0.2.4",
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 +24 -13
@@ -3,7 +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 import { ExportBundles, TRarity } from "warframe-public-export-plus";
7 7
8 8 export const getStoreItemCategory = (storeItem: string) => {
9 9 const storeItemString = getSubstringFromKeyword(storeItem, "StoreItems/");
@@ -26,7 +26,8 @@ export const handlePurchase = async (purchaseRequest: IPurchaseRequest, accountI
26 26 const purchaseResponse = await handleStoreItemAcquisition(
27 27 purchaseRequest.PurchaseParams.StoreItem,
28 28 accountId,
29 purchaseRequest.PurchaseParams.Quantity
29 purchaseRequest.PurchaseParams.Quantity,
30 "COMMON"
30 31 );
31 32
32 33 if (!purchaseResponse) throw new Error("purchase response was undefined");
@@ -48,7 +49,8 @@ export const handlePurchase = async (purchaseRequest: IPurchaseRequest, accountI
48 49 const handleStoreItemAcquisition = async (
49 50 storeItemName: string,
50 51 accountId: string,
51 quantity: number
52 quantity: number,
53 durability: TRarity
52 54 ): Promise<{ InventoryChanges: object }> => {
53 55 let purchaseResponse = {
54 56 InventoryChanges: {}
@@ -60,7 +62,12 @@ const handleStoreItemAcquisition = async (
60 62 for (const component of bundle.components) {
61 63 purchaseResponse = {
62 64 ...purchaseResponse,
63 ...(await handleStoreItemAcquisition(component.typeName, accountId, component.purchaseQuantity))
65 ...(await handleStoreItemAcquisition(
66 component.typeName,
67 accountId,
68 component.purchaseQuantity,
69 component.durability
70 ))
64 71 };
65 72 }
66 73 } else {
@@ -75,7 +82,7 @@ const handleStoreItemAcquisition = async (
75 82 purchaseResponse = await handleTypesPurchase(internalName, accountId, quantity);
76 83 break;
77 84 case "Boosters":
78 purchaseResponse = await handleBoostersPurchase(internalName, accountId);
85 purchaseResponse = await handleBoostersPurchase(internalName, accountId, durability);
79 86 break;
80 87 }
81 88 }
@@ -144,17 +151,21 @@ const boosterCollection = [
144 151 "/Lotus/Types/Boosters/CreditBooster"
145 152 ];
146 153
147 const handleBoostersPurchase = async (boosterStoreName: string, accountId: string) => {
148 const match = boosterStoreName.match(/(\d+)Day/);
149 if (!match) {
154 const boosterDuration: Record<TRarity, number> = {
155 COMMON: 3 * 86400,
156 UNCOMMON: 7 * 86400,
157 RARE: 30 * 86400,
158 LEGENDARY: 90 * 86400
159 };
160
161 const handleBoostersPurchase = async (boosterStoreName: string, accountId: string, durability: TRarity) => {
162 const ItemType = boosterStoreName.replace("StoreItem", "");
163 if (!boosterCollection.find(x => x == ItemType)) {
164 logger.error(`unknown booster type: ${ItemType}`);
150 165 return { InventoryChanges: {} };
151 166 }
152 167
153 const extractedDigit = Number(match[1]);
154 const ItemType = boosterCollection.find(i =>
155 boosterStoreName.includes(i.split("/").pop()!.replace("Booster", ""))
156 )!;
157 const ExpiryDate = extractedDigit * 86400;
168 const ExpiryDate = boosterDuration[durability];
158 169
159 170 await addBooster(ItemType, ExpiryDate, accountId);
160 171