From 18158bb4dc5b61719b339071e0174920d9015ede Mon Sep 17 00:00:00 2001 From: Dev Date: Fri, 2 Aug 2024 15:54:39 +0100 Subject: [PATCH] Fixed FiR status persisting after death for items inside secure container --- project/src/helpers/InRaidHelper.ts | 31 +++++++++++++++++++ project/src/helpers/ItemHelper.ts | 6 ++-- .../src/services/LocationLifecycleService.ts | 2 ++ 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/project/src/helpers/InRaidHelper.ts b/project/src/helpers/InRaidHelper.ts index e1b9f70c..ff958ea7 100644 --- a/project/src/helpers/InRaidHelper.ts +++ b/project/src/helpers/InRaidHelper.ts @@ -1,4 +1,5 @@ import { InventoryHelper } from "@spt/helpers/InventoryHelper"; +import { ItemHelper } from "@spt/helpers/ItemHelper"; import { IPmcData } from "@spt/models/eft/common/IPmcData"; import { Item } from "@spt/models/eft/common/tables/IItem"; import { ConfigTypes } from "@spt/models/enums/ConfigTypes"; @@ -15,6 +16,7 @@ export class InRaidHelper { constructor( @inject("PrimaryLogger") protected logger: ILogger, @inject("InventoryHelper") protected inventoryHelper: InventoryHelper, + @inject("ItemHelper") protected itemHelper: ItemHelper, @inject("ConfigServer") protected configServer: ConfigServer, @inject("PrimaryCloner") protected cloner: ICloner, ) { @@ -74,6 +76,35 @@ export class InRaidHelper { pmcData.Inventory.fastPanel = {}; } + /** + * Remove FiR status from designated container + * @param sessionId Session id + * @param pmcData Player profile + * @param secureContainerSlotId Container slot id to find items for and remove FiR from + */ + public removeFiRStatusFromItemsInContainer( + sessionId: string, + pmcData: IPmcData, + secureContainerSlotId: string, + ): void { + if (!pmcData.Inventory.items.some((item) => item.slotId === secureContainerSlotId)) { + return; + } + + const itemsInsideContainer = []; + for (const inventoryItem of pmcData.Inventory.items.filter((item) => item.upd && item.slotId !== "hideout")) { + if (this.itemHelper.itemIsInsideContainer(inventoryItem, secureContainerSlotId, pmcData.Inventory.items)) { + itemsInsideContainer.push(inventoryItem); + } + } + + for (const item of itemsInsideContainer) { + if (item.upd.SpawnedInSession) { + item.upd.SpawnedInSession = false; + } + } + } + /** * Get an array of items from a profile that will be lost on death * @param pmcProfile Profile to get items from diff --git a/project/src/helpers/ItemHelper.ts b/project/src/helpers/ItemHelper.ts index 6c690ece..f4609d4f 100644 --- a/project/src/helpers/ItemHelper.ts +++ b/project/src/helpers/ItemHelper.ts @@ -1193,14 +1193,14 @@ export class ItemHelper { /** * Check if item is stored inside of a container - * @param item Item to check is inside of container + * @param itemToCheck Item to check is inside of container * @param desiredContainerSlotId Name of slot to check item is in e.g. SecuredContainer/Backpack * @param items Inventory with child parent items to check * @returns True when item is in container */ - public itemIsInsideContainer(item: Item, desiredContainerSlotId: string, items: Item[]): boolean { + public itemIsInsideContainer(itemToCheck: Item, desiredContainerSlotId: string, items: Item[]): boolean { // Get items parent - const parent = items.find((x) => x._id === item.parentId); + const parent = items.find((x) => x._id === itemToCheck.parentId); if (!parent) { // No parent, end of line, not inside container return false; diff --git a/project/src/services/LocationLifecycleService.ts b/project/src/services/LocationLifecycleService.ts index c7daa429..f0b5914c 100644 --- a/project/src/services/LocationLifecycleService.ts +++ b/project/src/services/LocationLifecycleService.ts @@ -464,6 +464,8 @@ export class LocationLifecycleService { this.pmcChatResponseService.sendKillerResponse(sessionId, pmcProfile, postRaidProfile.Stats.Eft.Aggressor); this.inRaidHelper.deleteInventory(pmcProfile, sessionId); + + this.inRaidHelper.removeFiRStatusFromItemsInContainer(sessionId, pmcProfile, "SecuredContainer"); } // Must occur AFTER killer messages have been sent