2023-03-03 15:23:46 +00:00
|
|
|
import { inject, injectable } from "tsyringe";
|
2024-05-21 17:59:04 +00:00
|
|
|
import { InventoryHelper } from "@spt/helpers/InventoryHelper";
|
2024-07-12 16:29:21 +01:00
|
|
|
import { IPmcData } from "@spt/models/eft/common/IPmcData";
|
2024-05-21 17:59:04 +00:00
|
|
|
import { Item } from "@spt/models/eft/common/tables/IItem";
|
|
|
|
import { ConfigTypes } from "@spt/models/enums/ConfigTypes";
|
|
|
|
import { ILostOnDeathConfig } from "@spt/models/spt/config/ILostOnDeathConfig";
|
|
|
|
import { ILogger } from "@spt/models/spt/utils/ILogger";
|
|
|
|
import { ConfigServer } from "@spt/servers/ConfigServer";
|
|
|
|
import { ICloner } from "@spt/utils/cloners/ICloner";
|
2023-03-03 15:23:46 +00:00
|
|
|
|
|
|
|
@injectable()
|
|
|
|
export class InRaidHelper
|
|
|
|
{
|
|
|
|
protected lostOnDeathConfig: ILostOnDeathConfig;
|
|
|
|
|
|
|
|
constructor(
|
2024-05-28 14:04:20 +00:00
|
|
|
@inject("PrimaryLogger") protected logger: ILogger,
|
2023-03-03 15:23:46 +00:00
|
|
|
@inject("InventoryHelper") protected inventoryHelper: InventoryHelper,
|
2023-11-16 21:42:06 +00:00
|
|
|
@inject("ConfigServer") protected configServer: ConfigServer,
|
2024-05-28 14:04:20 +00:00
|
|
|
@inject("PrimaryCloner") protected cloner: ICloner,
|
2023-03-03 15:23:46 +00:00
|
|
|
)
|
|
|
|
{
|
|
|
|
this.lostOnDeathConfig = this.configServer.getConfig(ConfigTypes.LOST_ON_DEATH);
|
2023-11-20 16:33:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-07-07 21:51:24 +01:00
|
|
|
* @deprecated
|
2023-11-20 16:33:04 +00:00
|
|
|
* Reset the skill points earned in a raid to 0, ready for next raid
|
|
|
|
* @param profile Profile to update
|
|
|
|
*/
|
|
|
|
protected resetSkillPointsEarnedDuringRaid(profile: IPmcData): void
|
|
|
|
{
|
|
|
|
for (const skill of profile.Skills.Common)
|
|
|
|
{
|
|
|
|
skill.PointsEarnedDuringSession = 0.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-03 15:23:46 +00:00
|
|
|
/**
|
|
|
|
* Update a players inventory post-raid
|
|
|
|
* Remove equipped items from pre-raid
|
|
|
|
* Add new items found in raid to profile
|
|
|
|
* Store insurance items in profile
|
|
|
|
* @param sessionID Session id
|
2023-10-11 10:47:54 +01:00
|
|
|
* @param serverProfile Profile to update
|
2023-03-03 15:23:46 +00:00
|
|
|
* @param postRaidProfile Profile returned by client after a raid
|
|
|
|
*/
|
2024-02-13 12:20:30 +00:00
|
|
|
public setInventory(sessionID: string, serverProfile: IPmcData, postRaidProfile: IPmcData): void
|
2023-03-03 15:23:46 +00:00
|
|
|
{
|
2023-10-11 10:47:54 +01:00
|
|
|
// Store insurance (as removeItem() removes insurance also)
|
2024-05-13 17:58:17 +00:00
|
|
|
const insured = this.cloner.clone(serverProfile.InsuredItems);
|
2023-03-03 15:23:46 +00:00
|
|
|
|
2023-10-11 10:47:54 +01:00
|
|
|
// Remove possible equipped items from before the raid
|
|
|
|
this.inventoryHelper.removeItem(serverProfile, serverProfile.Inventory.equipment, sessionID);
|
|
|
|
this.inventoryHelper.removeItem(serverProfile, serverProfile.Inventory.questRaidItems, sessionID);
|
|
|
|
this.inventoryHelper.removeItem(serverProfile, serverProfile.Inventory.sortingTable, sessionID);
|
2023-03-03 15:23:46 +00:00
|
|
|
|
2023-10-11 10:47:54 +01:00
|
|
|
// Add the new items
|
|
|
|
serverProfile.Inventory.items = [...postRaidProfile.Inventory.items, ...serverProfile.Inventory.items];
|
2023-12-18 22:32:46 +00:00
|
|
|
serverProfile.Inventory.fastPanel = postRaidProfile.Inventory.fastPanel; // Quick access items bar
|
2023-10-11 10:47:54 +01:00
|
|
|
serverProfile.InsuredItems = insured;
|
2023-03-03 15:23:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-02-06 09:49:51 +00:00
|
|
|
* Clear PMC inventory of all items except those that are exempt
|
2023-03-03 15:23:46 +00:00
|
|
|
* Used post-raid to remove items after death
|
|
|
|
* @param pmcData Player profile
|
2024-02-06 09:49:51 +00:00
|
|
|
* @param sessionId Session id
|
2023-03-03 15:23:46 +00:00
|
|
|
*/
|
2024-02-06 09:49:51 +00:00
|
|
|
public deleteInventory(pmcData: IPmcData, sessionId: string): void
|
2023-03-03 15:23:46 +00:00
|
|
|
{
|
2023-04-22 16:27:46 +01:00
|
|
|
// Get inventory item ids to remove from players profile
|
2024-05-17 15:32:41 -04:00
|
|
|
const itemIdsToDeleteFromProfile = this.getInventoryItemsLostOnDeath(pmcData).map((item) => item._id);
|
2024-02-06 09:49:51 +00:00
|
|
|
for (const itemIdToDelete of itemIdsToDeleteFromProfile)
|
2023-03-03 15:23:46 +00:00
|
|
|
{
|
2024-02-02 15:00:12 -05:00
|
|
|
// Items inside containers are handled as part of function
|
2024-02-06 09:49:51 +00:00
|
|
|
this.inventoryHelper.removeItem(pmcData, itemIdToDelete, sessionId);
|
2024-02-02 15:00:12 -05:00
|
|
|
}
|
2023-04-22 16:27:46 +01:00
|
|
|
|
|
|
|
// Remove contents of fast panel
|
|
|
|
pmcData.Inventory.fastPanel = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get an array of items from a profile that will be lost on death
|
|
|
|
* @param pmcProfile Profile to get items from
|
|
|
|
* @returns Array of items lost on death
|
|
|
|
*/
|
|
|
|
protected getInventoryItemsLostOnDeath(pmcProfile: IPmcData): Item[]
|
|
|
|
{
|
2023-11-16 21:42:06 +00:00
|
|
|
const inventoryItems = pmcProfile.Inventory.items ?? [];
|
2023-12-15 10:36:26 +00:00
|
|
|
const equipmentRootId = pmcProfile?.Inventory?.equipment;
|
|
|
|
const questRaidItemContainerId = pmcProfile?.Inventory?.questRaidItems;
|
2023-04-22 16:27:46 +01:00
|
|
|
|
2023-12-15 10:36:26 +00:00
|
|
|
return inventoryItems.filter((item) =>
|
2023-04-22 16:27:46 +01:00
|
|
|
{
|
|
|
|
// Keep items flagged as kept after death
|
2023-12-15 10:36:26 +00:00
|
|
|
if (this.isItemKeptAfterDeath(pmcProfile, item))
|
2023-03-03 15:23:46 +00:00
|
|
|
{
|
2023-04-22 16:27:46 +01:00
|
|
|
return false;
|
2023-03-03 15:23:46 +00:00
|
|
|
}
|
2023-11-16 21:42:06 +00:00
|
|
|
|
2023-03-03 15:23:46 +00:00
|
|
|
// Remove normal items or quest raid items
|
2023-12-15 10:36:26 +00:00
|
|
|
if (item.parentId === equipmentRootId || item.parentId === questRaidItemContainerId)
|
2023-03-03 15:23:46 +00:00
|
|
|
{
|
2023-04-22 16:27:46 +01:00
|
|
|
return true;
|
2023-03-03 15:23:46 +00:00
|
|
|
}
|
2023-11-16 21:42:06 +00:00
|
|
|
|
2023-12-15 10:36:26 +00:00
|
|
|
// Pocket items are lost on death
|
|
|
|
if (item.slotId.startsWith("pocket"))
|
2023-03-03 15:23:46 +00:00
|
|
|
{
|
2023-04-22 16:27:46 +01:00
|
|
|
return true;
|
2023-03-03 15:23:46 +00:00
|
|
|
}
|
2023-11-16 21:42:06 +00:00
|
|
|
|
2023-04-22 16:27:46 +01:00
|
|
|
return false;
|
|
|
|
});
|
2023-03-03 15:23:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Does the provided items slotId mean its kept on the player after death
|
|
|
|
* @pmcData Player profile
|
|
|
|
* @itemToCheck Item to check should be kept
|
|
|
|
* @returns true if item is kept after death
|
|
|
|
*/
|
2023-03-03 17:53:28 +00:00
|
|
|
protected isItemKeptAfterDeath(pmcData: IPmcData, itemToCheck: Item): boolean
|
2023-03-03 15:23:46 +00:00
|
|
|
{
|
2024-03-06 08:50:04 +00:00
|
|
|
// Use pocket slotId's otherwise it deletes the root pocket item.
|
|
|
|
const pocketSlots = ["pocket1", "pocket2", "pocket3", "pocket4"];
|
|
|
|
|
2024-06-12 20:42:29 +01:00
|
|
|
// Base inventory items are always kept
|
2023-03-03 17:53:28 +00:00
|
|
|
if (!itemToCheck.parentId)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-03-03 15:23:46 +00:00
|
|
|
// Is item equipped on player
|
|
|
|
if (itemToCheck.parentId === pmcData.Inventory.equipment)
|
|
|
|
{
|
2023-03-03 17:53:28 +00:00
|
|
|
// Check slot id against config, true = delete, false = keep, undefined = delete
|
2024-02-06 09:49:51 +00:00
|
|
|
const discard: boolean = this.lostOnDeathConfig.equipment[itemToCheck.slotId];
|
2024-02-10 23:28:36 +00:00
|
|
|
if (typeof discard === "boolean" && discard === true)
|
2023-03-03 15:23:46 +00:00
|
|
|
{
|
2024-02-10 23:28:36 +00:00
|
|
|
// Lost on death
|
2023-03-03 15:23:46 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-02-10 23:28:36 +00:00
|
|
|
return true;
|
2023-03-03 15:23:46 +00:00
|
|
|
}
|
|
|
|
|
2024-03-06 08:50:04 +00:00
|
|
|
// Should we keep items in pockets on death
|
|
|
|
if (!this.lostOnDeathConfig.equipment.PocketItems && pocketSlots.includes(itemToCheck.slotId))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-03-03 15:23:46 +00:00
|
|
|
// Is quest item + quest item not lost on death
|
2023-12-15 10:36:26 +00:00
|
|
|
if (itemToCheck.parentId === pmcData.Inventory.questRaidItems && !this.lostOnDeathConfig.questItems)
|
2023-03-03 15:23:46 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-03-03 17:53:28 +00:00
|
|
|
// special slots are always kept after death
|
|
|
|
if (itemToCheck.slotId?.includes("SpecialSlot") && this.lostOnDeathConfig.specialSlotItems)
|
2023-03-03 15:23:46 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-06-12 20:42:29 +01:00
|
|
|
// All other cases item is lost
|
2023-03-03 15:23:46 +00:00
|
|
|
return false;
|
|
|
|
}
|
2023-11-16 21:42:06 +00:00
|
|
|
}
|