From f216d5222fb44f46af09a9aa12c53f7a9fcecb31 Mon Sep 17 00:00:00 2001 From: Sainan Date: Sat, 15 Jun 2024 15:12:08 +0200 Subject: [PATCH] feat: purchase shop decorations (#299) --- src/services/inventoryService.ts | 78 ++++++++++++++++++++++++++------ 1 file changed, 65 insertions(+), 13 deletions(-) diff --git a/src/services/inventoryService.ts b/src/services/inventoryService.ts index f21ea25a6..e5f82b973 100644 --- a/src/services/inventoryService.ts +++ b/src/services/inventoryService.ts @@ -116,6 +116,23 @@ export const addItem = async ( FlavourItems: [await addCustomization(typeName, accountId)] } }; + case "Objects": { + // /Lotus/Objects/Tenno/Props/TnoLisetTextProjector (Note Beacon) + const inventory = await getInventory(accountId); + const changes = [ + { + ItemType: typeName, + ItemCount: quantity + } satisfies IMiscItem + ]; + addShipDecorations(inventory, changes); + await inventory.save(); + return { + InventoryChanges: { + ShipDecorations: changes + } + }; + } case "Types": switch (typeName.substr(1).split("/")[2]) { case "AvatarImages": @@ -136,20 +153,40 @@ export const addItem = async ( } }; case "Items": { - const inventory = await getInventory(accountId); - const miscItemChanges = [ - { - ItemType: typeName, - ItemCount: quantity - } satisfies IMiscItem - ]; - addMiscItems(inventory, miscItemChanges); - await inventory.save(); - return { - InventoryChanges: { - MiscItems: miscItemChanges + switch (typeName.substr(1).split("/")[3]) { + case "ShipDecos": { + const inventory = await getInventory(accountId); + const changes = [ + { + ItemType: typeName, + ItemCount: quantity + } satisfies IMiscItem + ]; + addShipDecorations(inventory, changes); + await inventory.save(); + return { + InventoryChanges: { + ShipDecorations: changes + } + }; } - }; + default: { + const inventory = await getInventory(accountId); + const miscItemChanges = [ + { + ItemType: typeName, + ItemCount: quantity + } satisfies IMiscItem + ]; + addMiscItems(inventory, miscItemChanges); + await inventory.save(); + return { + InventoryChanges: { + MiscItems: miscItemChanges + } + }; + } + } } case "Recipes": case "Consumables": { @@ -427,6 +464,21 @@ export const addMiscItems = (inventory: IInventoryDatabaseDocument, itemsArray: }); }; +export const addShipDecorations = (inventory: IInventoryDatabaseDocument, itemsArray: IConsumable[] | undefined) => { + const { ShipDecorations } = inventory; + + itemsArray?.forEach(({ ItemCount, ItemType }) => { + const itemIndex = ShipDecorations.findIndex(miscItem => miscItem.ItemType === ItemType); + + if (itemIndex !== -1) { + ShipDecorations[itemIndex].ItemCount += ItemCount; + inventory.markModified(`ShipDecorations.${itemIndex}.ItemCount`); + } else { + ShipDecorations.push({ ItemCount, ItemType }); + } + }); +}; + export const addConsumables = (inventory: IInventoryDatabaseDocument, itemsArray: IConsumable[] | undefined) => { const { Consumables } = inventory;