From 8d8baec766f378ef0235fd3d056e5c0f2b4b0430 Mon Sep 17 00:00:00 2001 From: Dev Date: Thu, 1 Feb 2024 09:48:46 +0000 Subject: [PATCH] Add new `addItemsToStash()` function to `InventoryHelper` --- project/src/helpers/InventoryHelper.ts | 40 ++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/project/src/helpers/InventoryHelper.ts b/project/src/helpers/InventoryHelper.ts index 9a8e47af..ac12661e 100644 --- a/project/src/helpers/InventoryHelper.ts +++ b/project/src/helpers/InventoryHelper.ts @@ -13,6 +13,7 @@ import { Item, Location, Upd } from "@spt-aki/models/eft/common/tables/IItem"; import { IAddItemDirectRequest } from "@spt-aki/models/eft/inventory/IAddItemDirectRequest"; import { AddItem, IAddItemRequestData } from "@spt-aki/models/eft/inventory/IAddItemRequestData"; import { IAddItemTempObject } from "@spt-aki/models/eft/inventory/IAddItemTempObject"; +import { IAddItemsDirectRequest } from "@spt-aki/models/eft/inventory/IAddItemsDirectRequest"; import { IInventoryMergeRequestData } from "@spt-aki/models/eft/inventory/IInventoryMergeRequestData"; import { IInventoryMoveRequestData } from "@spt-aki/models/eft/inventory/IInventoryMoveRequestData"; import { IInventoryRemoveRequestData } from "@spt-aki/models/eft/inventory/IInventoryRemoveRequestData"; @@ -67,6 +68,45 @@ export class InventoryHelper this.inventoryConfig = this.configServer.getConfig(ConfigTypes.INVENTORY); } + /** + * Add multiple items to player stash + * @param sessionId Session id + * @param request addItemsDirect request + * @param pmcData Player profile + * @param output Client response object + */ + public addItemsToStash(sessionId: string, request: IAddItemsDirectRequest, pmcData: IPmcData, output: IItemEventRouterResponse): void + { + // Check all items fit into inventory before adding + if (!this.canPlaceItemsInInventory(sessionId, request.itemsWithModsToAdd)) + { + // no space, exit + this.httpResponse.appendErrorToOutput( + output, + this.localisationService.getText("inventory-no_stash_space"), + ) + + return; + } + + for (const itemToAdd of request.itemsWithModsToAdd) + { + const addItemRequest: IAddItemDirectRequest = { + itemWithModsToAdd: itemToAdd, + foundInRaid: request.foundInRaid, + useSortingTable: request.useSortingTable, + callback: request.callback + }; + + // Add to player inventory + this.addItemToStash(sessionId, addItemRequest, pmcData, output); + if (output.warnings.length > 0) + { + return; + } + } + } + /** * Add whatever is passed in `request.itemWithModsToAdd` into player inventory (if it fits) * @param sessionId Session id