0
0
mirror of https://github.com/sp-tarkov/server.git synced 2025-02-13 09:50:43 -05:00
server/project/src/services/InsuranceService.ts

323 lines
14 KiB
TypeScript
Raw Normal View History

import { ItemHelper } from "@spt/helpers/ItemHelper";
import { TraderHelper } from "@spt/helpers/TraderHelper";
import { IPmcData } from "@spt/models/eft/common/IPmcData";
import { Item } from "@spt/models/eft/common/tables/IItem";
import { ITraderBase } from "@spt/models/eft/common/tables/ITrader";
import { BonusType } from "@spt/models/enums/BonusType";
import { ConfigTypes } from "@spt/models/enums/ConfigTypes";
import { ItemTpl } from "@spt/models/enums/ItemTpl";
import { MessageType } from "@spt/models/enums/MessageType";
import { IInsuranceConfig } from "@spt/models/spt/config/IInsuranceConfig";
import { IInsuranceEquipmentPkg } from "@spt/models/spt/services/IInsuranceEquipmentPkg";
import { ILogger } from "@spt/models/spt/utils/ILogger";
import { ConfigServer } from "@spt/servers/ConfigServer";
import { SaveServer } from "@spt/servers/SaveServer";
import { DatabaseService } from "@spt/services/DatabaseService";
import { LocalisationService } from "@spt/services/LocalisationService";
import { MailSendService } from "@spt/services/MailSendService";
import { HashUtil } from "@spt/utils/HashUtil";
import { RandomUtil } from "@spt/utils/RandomUtil";
import { TimeUtil } from "@spt/utils/TimeUtil";
import { ICloner } from "@spt/utils/cloners/ICloner";
import { inject, injectable } from "tsyringe";
2023-03-03 15:23:46 +00:00
@injectable()
export class InsuranceService {
protected insured: Record<string, Record<string, Item[]>> = {};
2023-03-03 15:23:46 +00:00
protected insuranceConfig: IInsuranceConfig;
constructor(
@inject("PrimaryLogger") protected logger: ILogger,
@inject("DatabaseService") protected databaseService: DatabaseService,
2023-03-03 15:23:46 +00:00
@inject("RandomUtil") protected randomUtil: RandomUtil,
@inject("ItemHelper") protected itemHelper: ItemHelper,
Refactor Insurance Processing for Gear Lost in Raids Notable coding Changes: - Added `getRootItemParentID` method in `InsuranceService` to standardize the determination of the root insurance container. - Added `IInsuranceEquipmentPkg` model for structuring insurance packages, a type used to store insurance item data before it's saved in the profile. - Added `HashUtil` in `InsuranceController` and `InsuranceService` for generating an ID for the root insurance container in the case that the root ID cannot be found. - Updated and normalized item map generation and usage across `InsuranceService` and `InsuranceController`. - Updated `ItemHelper` with new methods `adoptOrphanedItems` and `generateItemsMap`, facilitating better management of item relationships and efficient item look-ups. - Updated `InsuranceController.findItemsToDelete` and related methods to use the new `rootItemParentID` parameter to ensure that all root level items share the same parent ID. - Updated logic in `InsuranceService` for creating insurance packages and handling orphaned items. Uh-huh, but what would you say you do here? - Resolves an issue that arose when `lostondeath.json` equipment configuration options were set to `false`. On death, the equipment's children items would be sent back to the player through insurance, duplicating them. - Resolves an issue that prevented items from appearing in an insurance return even though they passed an insurance roll. - Improved debug logging. Remaining Oopses: - We do not have data on items that were dropped in a raid. This means we have to pull item data from the profile at the start of the raid to return to the player in insurance. Because of this, the item positioning may differ from the position the item was in when the player died. Apart from removing all positioning, this is the best we can do. Resolves #425
2024-02-08 15:56:45 -05:00
@inject("HashUtil") protected hashUtil: HashUtil,
2023-03-03 15:23:46 +00:00
@inject("TimeUtil") protected timeUtil: TimeUtil,
@inject("SaveServer") protected saveServer: SaveServer,
@inject("TraderHelper") protected traderHelper: TraderHelper,
@inject("LocalisationService") protected localisationService: LocalisationService,
@inject("MailSendService") protected mailSendService: MailSendService,
2023-11-13 11:13:25 -05:00
@inject("ConfigServer") protected configServer: ConfigServer,
@inject("PrimaryCloner") protected cloner: ICloner,
) {
2023-03-03 15:23:46 +00:00
this.insuranceConfig = this.configServer.getConfig(ConfigTypes.INSURANCE);
}
/**
* Does player have insurance array
* @param sessionId Player id
* @returns True if exists
*/
public isuranceDictionaryExists(sessionId: string): boolean {
2023-03-03 15:23:46 +00:00
return this.insured[sessionId] !== undefined;
}
/**
* Get all insured items by all traders for a profile
* @param sessionId Profile id (session id)
* @returns Item array
*/
public getInsurance(sessionId: string): Record<string, Item[]> {
2023-03-03 15:23:46 +00:00
return this.insured[sessionId];
}
public resetInsurance(sessionId: string): void {
2023-03-03 15:23:46 +00:00
this.insured[sessionId] = {};
}
/**
* Sends stored insured items as message to player
* @param pmcData profile to send insured items to
2023-03-03 15:23:46 +00:00
* @param sessionID SessionId of current player
* @param mapId Id of the map player died/exited that caused the insurance to be issued on
*/
public sendInsuredItems(pmcData: IPmcData, sessionID: string, mapId: string): void {
// Get insurance items for each trader
const globals = this.databaseService.getGlobals();
for (const traderId in this.getInsurance(sessionID)) {
const traderBase = this.traderHelper.getTrader(traderId, sessionID);
if (!traderBase) {
2024-05-27 20:06:10 +01:00
throw new Error(this.localisationService.getText("insurance-unable_to_find_trader_by_id", traderId));
}
2024-05-27 20:06:10 +01:00
const dialogueTemplates = this.databaseService.getTrader(traderId).dialogue;
if (!dialogueTemplates) {
2024-05-27 20:06:10 +01:00
throw new Error(this.localisationService.getText("insurance-trader_lacks_dialogue_property", traderId));
}
2023-03-03 15:23:46 +00:00
const systemData = {
date: this.timeUtil.getDateMailFormat(),
time: this.timeUtil.getTimeMailFormat(),
location: mapId,
2023-03-03 15:23:46 +00:00
};
2024-05-27 20:06:10 +01:00
const traderEnum = this.traderHelper.getTraderById(traderId);
if (!traderEnum) {
2024-05-27 20:06:10 +01:00
throw new Error(this.localisationService.getText("insurance-trader_missing_from_enum", traderId));
}
// Send "i will go look for your stuff" message from trader to player
this.mailSendService.sendLocalisedNpcMessageToPlayer(
sessionID,
traderEnum,
MessageType.NPC_TRADER,
this.randomUtil.getArrayValue(dialogueTemplates?.insuranceStart ?? ["INSURANCE START MESSAGE MISSING"]),
undefined,
this.timeUtil.getHoursAsSeconds(globals.config.Insurance.MaxStorageTimeInHour),
systemData,
);
2023-03-03 15:23:46 +00:00
// Store insurance to send to player later in profile
// Store insurance return details in profile + "hey i found your stuff, here you go!" message details to send to player at a later date
2023-03-03 15:23:46 +00:00
this.saveServer.getProfile(sessionID).insurance.push({
scheduledTime: this.getInsuranceReturnTimestamp(pmcData, traderBase),
2023-03-03 15:23:46 +00:00
traderId: traderId,
maxStorageTime: this.timeUtil.getHoursAsSeconds(traderBase.insurance.max_storage_time),
systemData: systemData,
messageType: MessageType.INSURANCE_RETURN,
messageTemplateId: this.randomUtil.getArrayValue(dialogueTemplates.insuranceFound),
2023-11-13 11:13:25 -05:00
items: this.getInsurance(sessionID)[traderId],
2023-03-03 15:23:46 +00:00
});
}
this.resetInsurance(sessionID);
}
/**
* Get a timestamp of when insurance items should be sent to player based on trader used to insure
* Apply insurance return bonus if found in profile
2023-03-03 15:23:46 +00:00
* @param pmcData Player profile
* @param trader Trader base used to insure items
2023-03-03 15:23:46 +00:00
* @returns Timestamp to return items to player in seconds
*/
protected getInsuranceReturnTimestamp(pmcData: IPmcData, trader: ITraderBase): number {
// If override in config is non-zero, use that instead of trader values
if (this.insuranceConfig.returnTimeOverrideSeconds > 0) {
2023-11-13 11:13:25 -05:00
this.logger.debug(
`Insurance override used: returning in ${this.insuranceConfig.returnTimeOverrideSeconds} seconds`,
);
2023-03-03 15:23:46 +00:00
return this.timeUtil.getTimestamp() + this.insuranceConfig.returnTimeOverrideSeconds;
}
const insuranceReturnTimeBonus = pmcData.Bonuses.find(
(bonus) => bonus.type === BonusType.INSURANCE_RETURN_TIME,
);
const insuranceReturnTimeBonusPercent =
1.0 - (insuranceReturnTimeBonus ? Math.abs(insuranceReturnTimeBonus!.value ?? 0) : 0) / 100;
2023-03-03 15:23:46 +00:00
const traderMinReturnAsSeconds = trader.insurance.min_return_hour * TimeUtil.ONE_HOUR_AS_SECONDS;
const traderMaxReturnAsSeconds = trader.insurance.max_return_hour * TimeUtil.ONE_HOUR_AS_SECONDS;
let randomisedReturnTimeSeconds = this.randomUtil.getInt(traderMinReturnAsSeconds, traderMaxReturnAsSeconds);
// Check for Mark of The Unheard in players special slots (only slot item can fit)
const globals = this.databaseService.getGlobals();
const hasMarkOfUnheard = this.itemHelper.hasItemWithTpl(
pmcData.Inventory.items,
ItemTpl.MARKOFUNKNOWN_MARK_OF_THE_UNHEARD,
"SpecialSlot",
);
if (hasMarkOfUnheard) {
// Reduce return time by globals multipler value
randomisedReturnTimeSeconds *= globals.config.Insurance.CoefOfHavingMarkOfUnknown;
}
2023-03-03 15:23:46 +00:00
// EoD has 30% faster returns
const editionModifier = globals.config.Insurance.EditionSendingMessageTime[pmcData.Info.GameVersion];
if (editionModifier) {
randomisedReturnTimeSeconds *= editionModifier.multiplier;
}
// Current time + randomised time calculated above
return this.timeUtil.getTimestamp() + randomisedReturnTimeSeconds * insuranceReturnTimeBonusPercent;
2023-03-03 15:23:46 +00:00
}
Refactor Insurance Processing for Gear Lost in Raids Notable coding Changes: - Added `getRootItemParentID` method in `InsuranceService` to standardize the determination of the root insurance container. - Added `IInsuranceEquipmentPkg` model for structuring insurance packages, a type used to store insurance item data before it's saved in the profile. - Added `HashUtil` in `InsuranceController` and `InsuranceService` for generating an ID for the root insurance container in the case that the root ID cannot be found. - Updated and normalized item map generation and usage across `InsuranceService` and `InsuranceController`. - Updated `ItemHelper` with new methods `adoptOrphanedItems` and `generateItemsMap`, facilitating better management of item relationships and efficient item look-ups. - Updated `InsuranceController.findItemsToDelete` and related methods to use the new `rootItemParentID` parameter to ensure that all root level items share the same parent ID. - Updated logic in `InsuranceService` for creating insurance packages and handling orphaned items. Uh-huh, but what would you say you do here? - Resolves an issue that arose when `lostondeath.json` equipment configuration options were set to `false`. On death, the equipment's children items would be sent back to the player through insurance, duplicating them. - Resolves an issue that prevented items from appearing in an insurance return even though they passed an insurance roll. - Improved debug logging. Remaining Oopses: - We do not have data on items that were dropped in a raid. This means we have to pull item data from the profile at the start of the raid to return to the player in insurance. Because of this, the item positioning may differ from the position the item was in when the player died. Apart from removing all positioning, this is the best we can do. Resolves #425
2024-02-08 15:56:45 -05:00
/**
* Take the insurance item packages within a profile session and ensure that each of the items in that package are
* not orphaned from their parent ID.
*
* @param sessionID The session ID to update insurance equipment packages in.
* @returns void
*/
protected adoptOrphanedInsEquipment(sessionID: string): void {
Refactor Insurance Processing for Gear Lost in Raids Notable coding Changes: - Added `getRootItemParentID` method in `InsuranceService` to standardize the determination of the root insurance container. - Added `IInsuranceEquipmentPkg` model for structuring insurance packages, a type used to store insurance item data before it's saved in the profile. - Added `HashUtil` in `InsuranceController` and `InsuranceService` for generating an ID for the root insurance container in the case that the root ID cannot be found. - Updated and normalized item map generation and usage across `InsuranceService` and `InsuranceController`. - Updated `ItemHelper` with new methods `adoptOrphanedItems` and `generateItemsMap`, facilitating better management of item relationships and efficient item look-ups. - Updated `InsuranceController.findItemsToDelete` and related methods to use the new `rootItemParentID` parameter to ensure that all root level items share the same parent ID. - Updated logic in `InsuranceService` for creating insurance packages and handling orphaned items. Uh-huh, but what would you say you do here? - Resolves an issue that arose when `lostondeath.json` equipment configuration options were set to `false`. On death, the equipment's children items would be sent back to the player through insurance, duplicating them. - Resolves an issue that prevented items from appearing in an insurance return even though they passed an insurance roll. - Improved debug logging. Remaining Oopses: - We do not have data on items that were dropped in a raid. This means we have to pull item data from the profile at the start of the raid to return to the player in insurance. Because of this, the item positioning may differ from the position the item was in when the player died. Apart from removing all positioning, this is the best we can do. Resolves #425
2024-02-08 15:56:45 -05:00
const rootID = this.getRootItemParentID(sessionID);
const insuranceData = this.getInsurance(sessionID);
for (const [traderId, items] of Object.entries(insuranceData)) {
Refactor Insurance Processing for Gear Lost in Raids Notable coding Changes: - Added `getRootItemParentID` method in `InsuranceService` to standardize the determination of the root insurance container. - Added `IInsuranceEquipmentPkg` model for structuring insurance packages, a type used to store insurance item data before it's saved in the profile. - Added `HashUtil` in `InsuranceController` and `InsuranceService` for generating an ID for the root insurance container in the case that the root ID cannot be found. - Updated and normalized item map generation and usage across `InsuranceService` and `InsuranceController`. - Updated `ItemHelper` with new methods `adoptOrphanedItems` and `generateItemsMap`, facilitating better management of item relationships and efficient item look-ups. - Updated `InsuranceController.findItemsToDelete` and related methods to use the new `rootItemParentID` parameter to ensure that all root level items share the same parent ID. - Updated logic in `InsuranceService` for creating insurance packages and handling orphaned items. Uh-huh, but what would you say you do here? - Resolves an issue that arose when `lostondeath.json` equipment configuration options were set to `false`. On death, the equipment's children items would be sent back to the player through insurance, duplicating them. - Resolves an issue that prevented items from appearing in an insurance return even though they passed an insurance roll. - Improved debug logging. Remaining Oopses: - We do not have data on items that were dropped in a raid. This means we have to pull item data from the profile at the start of the raid to return to the player in insurance. Because of this, the item positioning may differ from the position the item was in when the player died. Apart from removing all positioning, this is the best we can do. Resolves #425
2024-02-08 15:56:45 -05:00
this.insured[sessionID][traderId] = this.itemHelper.adoptOrphanedItems(rootID, items);
}
}
/**
* Store lost gear post-raid inside profile, ready for later code to pick it up and mail it
Refactor Insurance Processing for Gear Lost in Raids Notable coding Changes: - Added `getRootItemParentID` method in `InsuranceService` to standardize the determination of the root insurance container. - Added `IInsuranceEquipmentPkg` model for structuring insurance packages, a type used to store insurance item data before it's saved in the profile. - Added `HashUtil` in `InsuranceController` and `InsuranceService` for generating an ID for the root insurance container in the case that the root ID cannot be found. - Updated and normalized item map generation and usage across `InsuranceService` and `InsuranceController`. - Updated `ItemHelper` with new methods `adoptOrphanedItems` and `generateItemsMap`, facilitating better management of item relationships and efficient item look-ups. - Updated `InsuranceController.findItemsToDelete` and related methods to use the new `rootItemParentID` parameter to ensure that all root level items share the same parent ID. - Updated logic in `InsuranceService` for creating insurance packages and handling orphaned items. Uh-huh, but what would you say you do here? - Resolves an issue that arose when `lostondeath.json` equipment configuration options were set to `false`. On death, the equipment's children items would be sent back to the player through insurance, duplicating them. - Resolves an issue that prevented items from appearing in an insurance return even though they passed an insurance roll. - Improved debug logging. Remaining Oopses: - We do not have data on items that were dropped in a raid. This means we have to pull item data from the profile at the start of the raid to return to the player in insurance. Because of this, the item positioning may differ from the position the item was in when the player died. Apart from removing all positioning, this is the best we can do. Resolves #425
2024-02-08 15:56:45 -05:00
* @param equipmentPkg Gear to store - generated by getGearLostInRaid()
*/
public storeGearLostInRaidToSendLater(sessionID: string, equipmentPkg: IInsuranceEquipmentPkg[]): void {
// Process all insured items lost in-raid
for (const gear of equipmentPkg) {
this.addGearToSend(gear);
2023-03-03 15:23:46 +00:00
}
Refactor Insurance Processing for Gear Lost in Raids Notable coding Changes: - Added `getRootItemParentID` method in `InsuranceService` to standardize the determination of the root insurance container. - Added `IInsuranceEquipmentPkg` model for structuring insurance packages, a type used to store insurance item data before it's saved in the profile. - Added `HashUtil` in `InsuranceController` and `InsuranceService` for generating an ID for the root insurance container in the case that the root ID cannot be found. - Updated and normalized item map generation and usage across `InsuranceService` and `InsuranceController`. - Updated `ItemHelper` with new methods `adoptOrphanedItems` and `generateItemsMap`, facilitating better management of item relationships and efficient item look-ups. - Updated `InsuranceController.findItemsToDelete` and related methods to use the new `rootItemParentID` parameter to ensure that all root level items share the same parent ID. - Updated logic in `InsuranceService` for creating insurance packages and handling orphaned items. Uh-huh, but what would you say you do here? - Resolves an issue that arose when `lostondeath.json` equipment configuration options were set to `false`. On death, the equipment's children items would be sent back to the player through insurance, duplicating them. - Resolves an issue that prevented items from appearing in an insurance return even though they passed an insurance roll. - Improved debug logging. Remaining Oopses: - We do not have data on items that were dropped in a raid. This means we have to pull item data from the profile at the start of the raid to return to the player in insurance. Because of this, the item positioning may differ from the position the item was in when the player died. Apart from removing all positioning, this is the best we can do. Resolves #425
2024-02-08 15:56:45 -05:00
// Items are separated into their individual trader packages, now we can ensure that they all have valid parents
this.adoptOrphanedInsEquipment(sessionID);
2023-03-03 15:23:46 +00:00
}
2024-07-07 20:57:41 +01:00
/**
* For the passed in items, find the trader it was insured against
* @param sessionId Session id
* @param lostInsuredItems Insured items lost in a raid
* @param pmcProfile Player profile
* @returns IInsuranceEquipmentPkg array
*/
public mapInsuredItemsToTrader(
sessionId: string,
lostInsuredItems: Item[],
pmcProfile: IPmcData,
): IInsuranceEquipmentPkg[] {
2024-07-07 20:57:41 +01:00
const result: IInsuranceEquipmentPkg[] = [];
for (const lostItem of lostInsuredItems) {
2024-07-07 20:57:41 +01:00
const insuranceDetails = pmcProfile.InsuredItems.find((insuredItem) => insuredItem.itemId == lostItem._id);
if (!insuranceDetails) {
this.logger.error(
`unable to find insurance details for item id: ${lostItem._id} with tpl: ${lostItem._tpl}`,
);
2024-07-07 20:57:41 +01:00
continue;
}
// Add insured item + details to return array
result.push({
sessionID: sessionId,
itemToReturnToPlayer: lostItem,
pmcData: pmcProfile,
traderId: insuranceDetails.tid,
});
}
return result;
}
/**
* Add gear item to InsuredItems array in player profile
* @param sessionID Session id
* @param pmcData Player profile
* @param itemToReturnToPlayer item to store
* @param traderId Id of trader item was insured with
*/
protected addGearToSend(gear: IInsuranceEquipmentPkg): void {
const sessionId = gear.sessionID;
const pmcData = gear.pmcData;
const itemToReturnToPlayer = gear.itemToReturnToPlayer;
const traderId = gear.traderId;
2023-03-03 15:23:46 +00:00
// Ensure insurance array is init
if (!this.isuranceDictionaryExists(sessionId)) {
this.resetInsurance(sessionId);
2023-03-03 15:23:46 +00:00
}
// init trader insurance array
if (!this.insuranceTraderArrayExists(sessionId, traderId)) {
this.resetInsuranceTraderArray(sessionId, traderId);
2023-03-03 15:23:46 +00:00
}
this.addInsuranceItemToArray(sessionId, traderId, itemToReturnToPlayer);
2023-03-03 15:23:46 +00:00
// Remove item from insured items array as its been processed
pmcData.InsuredItems = pmcData.InsuredItems.filter((item) => {
return item.itemId !== itemToReturnToPlayer._id;
});
2023-03-03 15:23:46 +00:00
}
/**
* Does insurance exist for a player and by trader
* @param sessionId Player id (session id)
* @param traderId Trader items insured with
* @returns True if exists
*/
protected insuranceTraderArrayExists(sessionId: string, traderId: string): boolean {
return this.insured[sessionId][traderId] !== undefined;
}
/**
* Empty out array holding insured items by sessionid + traderid
* @param sessionId Player id (session id)
* @param traderId Trader items insured with
*/
public resetInsuranceTraderArray(sessionId: string, traderId: string): void {
this.insured[sessionId][traderId] = [];
}
/**
* Store insured item
* @param sessionId Player id (session id)
* @param traderId Trader item insured with
* @param itemToAdd Insured item (with children)
*/
public addInsuranceItemToArray(sessionId: string, traderId: string, itemToAdd: Item): void {
this.insured[sessionId][traderId].push(itemToAdd);
}
/**
* Get price of insurance * multiplier from config
* @param pmcData Player profile
* @param inventoryItem Item to be insured
* @param traderId Trader item is insured with
* @returns price in roubles
*/
public getRoublePriceToInsureItemWithTrader(pmcData: IPmcData, inventoryItem: Item, traderId: string): number {
const price =
this.itemHelper.getStaticItemPrice(inventoryItem._tpl) *
(this.traderHelper.getLoyaltyLevel(traderId, pmcData).insurance_price_coef / 100);
2023-03-03 15:23:46 +00:00
return Math.ceil(price);
2023-03-03 15:23:46 +00:00
}
Refactor Insurance Processing for Gear Lost in Raids Notable coding Changes: - Added `getRootItemParentID` method in `InsuranceService` to standardize the determination of the root insurance container. - Added `IInsuranceEquipmentPkg` model for structuring insurance packages, a type used to store insurance item data before it's saved in the profile. - Added `HashUtil` in `InsuranceController` and `InsuranceService` for generating an ID for the root insurance container in the case that the root ID cannot be found. - Updated and normalized item map generation and usage across `InsuranceService` and `InsuranceController`. - Updated `ItemHelper` with new methods `adoptOrphanedItems` and `generateItemsMap`, facilitating better management of item relationships and efficient item look-ups. - Updated `InsuranceController.findItemsToDelete` and related methods to use the new `rootItemParentID` parameter to ensure that all root level items share the same parent ID. - Updated logic in `InsuranceService` for creating insurance packages and handling orphaned items. Uh-huh, but what would you say you do here? - Resolves an issue that arose when `lostondeath.json` equipment configuration options were set to `false`. On death, the equipment's children items would be sent back to the player through insurance, duplicating them. - Resolves an issue that prevented items from appearing in an insurance return even though they passed an insurance roll. - Improved debug logging. Remaining Oopses: - We do not have data on items that were dropped in a raid. This means we have to pull item data from the profile at the start of the raid to return to the player in insurance. Because of this, the item positioning may differ from the position the item was in when the player died. Apart from removing all positioning, this is the best we can do. Resolves #425
2024-02-08 15:56:45 -05:00
/**
* Returns the ID that should be used for a root-level Item's parentId property value within in the context of insurance.
* @param sessionID Players id
* @returns The root item Id.
Refactor Insurance Processing for Gear Lost in Raids Notable coding Changes: - Added `getRootItemParentID` method in `InsuranceService` to standardize the determination of the root insurance container. - Added `IInsuranceEquipmentPkg` model for structuring insurance packages, a type used to store insurance item data before it's saved in the profile. - Added `HashUtil` in `InsuranceController` and `InsuranceService` for generating an ID for the root insurance container in the case that the root ID cannot be found. - Updated and normalized item map generation and usage across `InsuranceService` and `InsuranceController`. - Updated `ItemHelper` with new methods `adoptOrphanedItems` and `generateItemsMap`, facilitating better management of item relationships and efficient item look-ups. - Updated `InsuranceController.findItemsToDelete` and related methods to use the new `rootItemParentID` parameter to ensure that all root level items share the same parent ID. - Updated logic in `InsuranceService` for creating insurance packages and handling orphaned items. Uh-huh, but what would you say you do here? - Resolves an issue that arose when `lostondeath.json` equipment configuration options were set to `false`. On death, the equipment's children items would be sent back to the player through insurance, duplicating them. - Resolves an issue that prevented items from appearing in an insurance return even though they passed an insurance roll. - Improved debug logging. Remaining Oopses: - We do not have data on items that were dropped in a raid. This means we have to pull item data from the profile at the start of the raid to return to the player in insurance. Because of this, the item positioning may differ from the position the item was in when the player died. Apart from removing all positioning, this is the best we can do. Resolves #425
2024-02-08 15:56:45 -05:00
*/
public getRootItemParentID(sessionID: string): string {
Refactor Insurance Processing for Gear Lost in Raids Notable coding Changes: - Added `getRootItemParentID` method in `InsuranceService` to standardize the determination of the root insurance container. - Added `IInsuranceEquipmentPkg` model for structuring insurance packages, a type used to store insurance item data before it's saved in the profile. - Added `HashUtil` in `InsuranceController` and `InsuranceService` for generating an ID for the root insurance container in the case that the root ID cannot be found. - Updated and normalized item map generation and usage across `InsuranceService` and `InsuranceController`. - Updated `ItemHelper` with new methods `adoptOrphanedItems` and `generateItemsMap`, facilitating better management of item relationships and efficient item look-ups. - Updated `InsuranceController.findItemsToDelete` and related methods to use the new `rootItemParentID` parameter to ensure that all root level items share the same parent ID. - Updated logic in `InsuranceService` for creating insurance packages and handling orphaned items. Uh-huh, but what would you say you do here? - Resolves an issue that arose when `lostondeath.json` equipment configuration options were set to `false`. On death, the equipment's children items would be sent back to the player through insurance, duplicating them. - Resolves an issue that prevented items from appearing in an insurance return even though they passed an insurance roll. - Improved debug logging. Remaining Oopses: - We do not have data on items that were dropped in a raid. This means we have to pull item data from the profile at the start of the raid to return to the player in insurance. Because of this, the item positioning may differ from the position the item was in when the player died. Apart from removing all positioning, this is the best we can do. Resolves #425
2024-02-08 15:56:45 -05:00
// Try to use the equipment id from the profile. I'm not sure this is strictly required, but it feels neat.
return this.saveServer.getProfile(sessionID)?.characters?.pmc?.Inventory?.equipment ?? this.hashUtil.generate();
}
2023-11-13 11:13:25 -05:00
}