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

feat: implement purchasing of blueprints & gear items (#208)

b9c7daf4
Sainan <sainan@calamity.gg>
提交于

代码差异

2 个文件 +47 -6
Modified src/services/inventoryService.ts +4 -3
@@ -12,7 +12,8 @@ import {
12 12 IInventoryDatabaseDocument,
13 13 IMiscItem,
14 14 IMission,
15 IRawUpgrade
15 IRawUpgrade,
16 ITypeCount
16 17 } from "@/src/types/inventoryTypes/inventoryTypes";
17 18 import { IGenericUpdate } from "../types/genericUpdate";
18 19 import { IArtifactsRequest, IMissionInventoryUpdateRequest, IThemeUpdateRequest } from "../types/requestTypes";
@@ -245,7 +246,7 @@ export const addMiscItems = (inventory: IInventoryDatabaseDocument, itemsArray:
245 246 });
246 247 };
247 248
248 const addConsumables = (inventory: IInventoryDatabaseDocument, itemsArray: IConsumable[] | undefined) => {
249 export const addConsumables = (inventory: IInventoryDatabaseDocument, itemsArray: IConsumable[] | undefined) => {
249 250 const { Consumables } = inventory;
250 251
251 252 itemsArray?.forEach(({ ItemCount, ItemType }) => {
@@ -260,7 +261,7 @@ const addConsumables = (inventory: IInventoryDatabaseDocument, itemsArray: ICons
260 261 });
261 262 };
262 263
263 const addRecipes = (inventory: IInventoryDatabaseDocument, itemsArray: IConsumable[] | undefined) => {
264 export const addRecipes = (inventory: IInventoryDatabaseDocument, itemsArray: ITypeCount[] | undefined) => {
264 265 const { Recipes } = inventory;
265 266
266 267 itemsArray?.forEach(({ ItemCount, ItemType }) => {
Modified src/services/purchaseService.ts +43 -3
@@ -3,17 +3,19 @@ import { getWeaponType } from "@/src/services/itemDataService";
3 3 import { getSubstringFromKeyword } from "@/src/helpers/stringHelpers";
4 4 import {
5 5 addBooster,
6 addConsumables,
6 7 addCustomization,
7 8 addMechSuit,
8 9 addMiscItems,
9 10 addPowerSuit,
11 addRecipes,
10 12 addSentinel,
11 13 addWeapon,
12 14 getInventory,
13 15 updateCurrency,
14 16 updateSlots
15 17 } from "@/src/services/inventoryService";
16 import { IMiscItem } from "@/src/types/inventoryTypes/inventoryTypes";
18 import { IConsumable, IMiscItem, ITypeCount } from "@/src/types/inventoryTypes/inventoryTypes";
17 19 import { IPurchaseRequest, IPurchaseResponse, SlotNameToInventoryName, SlotPurchase } from "@/src/types/purchaseTypes";
18 20 import { logger } from "@/src/utils/logger";
19 21
@@ -180,14 +182,18 @@ const handleTypesPurchase = async (typesName: string, accountId: string, quantit
180 182 case "AvatarImages":
181 183 case "SuitCustomizations":
182 184 return await handleCustomizationPurchase(typesName, accountId);
183 // case "Recipes":
184 // break;
185 185 case "Sentinels":
186 186 return await handleSentinelPurchase(typesName, accountId);
187 187 case "SlotItems":
188 188 return await handleSlotPurchase(typesName, accountId);
189 189 case "Items":
190 190 return await handleMiscItemPurchase(typesName, accountId, quantity);
191 case "Recipes":
192 case "Consumables": // Blueprints for Ciphers, Antitoxins
193 return await handleRecipesPurchase(typesName, accountId, quantity);
194 case "Restoratives": // Codex Scanner, Remote Observer, Starburst
195 return await handleRestorativesPurchase(typesName, accountId, quantity);
196 break;
191 197 default:
192 198 throw new Error(`unknown Types category: ${typeCategory} not implemented or new`);
193 199 }
@@ -258,3 +264,37 @@ const handleMiscItemPurchase = async (uniqueName: string, accountId: string, qua
258 264 }
259 265 };
260 266 };
267
268 const handleRecipesPurchase = async (uniqueName: string, accountId: string, quantity: number) => {
269 const inventory = await getInventory(accountId);
270 const recipeChanges = [
271 {
272 ItemType: uniqueName,
273 ItemCount: quantity
274 } satisfies ITypeCount
275 ];
276 addRecipes(inventory, recipeChanges);
277 await inventory.save();
278 return {
279 InventoryChanges: {
280 Recipes: recipeChanges
281 }
282 };
283 };
284
285 const handleRestorativesPurchase = async (uniqueName: string, accountId: string, quantity: number) => {
286 const inventory = await getInventory(accountId);
287 const consumablesChanges = [
288 {
289 ItemType: uniqueName,
290 ItemCount: quantity
291 } satisfies IConsumable
292 ];
293 addConsumables(inventory, consumablesChanges);
294 await inventory.save();
295 return {
296 InventoryChanges: {
297 Consumables: consumablesChanges
298 }
299 };
300 };