Fixed FiR status persisting after death for items inside secure container

This commit is contained in:
Dev 2024-08-02 15:54:39 +01:00
parent f94985f3f2
commit 18158bb4dc
3 changed files with 36 additions and 3 deletions

View File

@ -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

View File

@ -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;

View File

@ -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