two-slot-extended-mags/types/controllers/InsuranceController.d.ts

208 lines
12 KiB
TypeScript
Raw Normal View History

2024-08-05 20:33:00 +10:00
import { DialogueHelper } from "@spt/helpers/DialogueHelper";
import { ItemHelper } from "@spt/helpers/ItemHelper";
import { ProfileHelper } from "@spt/helpers/ProfileHelper";
import { TraderHelper } from "@spt/helpers/TraderHelper";
import { WeightedRandomHelper } from "@spt/helpers/WeightedRandomHelper";
import { IPmcData } from "@spt/models/eft/common/IPmcData";
import { Item } from "@spt/models/eft/common/tables/IItem";
import { IGetInsuranceCostRequestData } from "@spt/models/eft/insurance/IGetInsuranceCostRequestData";
import { IGetInsuranceCostResponseData } from "@spt/models/eft/insurance/IGetInsuranceCostResponseData";
import { IInsureRequestData } from "@spt/models/eft/insurance/IInsureRequestData";
import { IItemEventRouterResponse } from "@spt/models/eft/itemEvent/IItemEventRouterResponse";
import { Insurance } from "@spt/models/eft/profile/ISptProfile";
import { IInsuranceConfig } from "@spt/models/spt/config/IInsuranceConfig";
import { ILogger } from "@spt/models/spt/utils/ILogger";
import { EventOutputHolder } from "@spt/routers/EventOutputHolder";
import { ConfigServer } from "@spt/servers/ConfigServer";
import { SaveServer } from "@spt/servers/SaveServer";
import { DatabaseService } from "@spt/services/DatabaseService";
import { InsuranceService } from "@spt/services/InsuranceService";
import { LocalisationService } from "@spt/services/LocalisationService";
import { MailSendService } from "@spt/services/MailSendService";
import { PaymentService } from "@spt/services/PaymentService";
import { RagfairPriceService } from "@spt/services/RagfairPriceService";
import { HashUtil } from "@spt/utils/HashUtil";
import { MathUtil } from "@spt/utils/MathUtil";
import { RandomUtil } from "@spt/utils/RandomUtil";
import { TimeUtil } from "@spt/utils/TimeUtil";
import { ICloner } from "@spt/utils/cloners/ICloner";
2023-06-11 15:10:34 +10:00
export declare class InsuranceController {
protected logger: ILogger;
protected randomUtil: RandomUtil;
2024-04-03 20:15:11 +11:00
protected mathUtil: MathUtil;
protected hashUtil: HashUtil;
2023-06-11 15:10:34 +10:00
protected eventOutputHolder: EventOutputHolder;
protected timeUtil: TimeUtil;
protected saveServer: SaveServer;
2024-08-05 20:33:00 +10:00
protected databaseService: DatabaseService;
2023-06-11 15:10:34 +10:00
protected itemHelper: ItemHelper;
protected profileHelper: ProfileHelper;
protected dialogueHelper: DialogueHelper;
2024-08-05 20:33:00 +10:00
protected weightedRandomHelper: WeightedRandomHelper;
2023-10-09 20:21:00 +11:00
protected traderHelper: TraderHelper;
2023-06-11 15:10:34 +10:00
protected paymentService: PaymentService;
protected insuranceService: InsuranceService;
2023-10-09 20:21:00 +11:00
protected mailSendService: MailSendService;
2024-08-05 20:33:00 +10:00
protected ragfairPriceService: RagfairPriceService;
protected localisationService: LocalisationService;
2023-06-11 15:10:34 +10:00
protected configServer: ConfigServer;
2024-08-05 20:33:00 +10:00
protected cloner: ICloner;
2023-06-11 15:10:34 +10:00
protected insuranceConfig: IInsuranceConfig;
2024-08-05 20:33:00 +10:00
constructor(logger: ILogger, randomUtil: RandomUtil, mathUtil: MathUtil, hashUtil: HashUtil, eventOutputHolder: EventOutputHolder, timeUtil: TimeUtil, saveServer: SaveServer, databaseService: DatabaseService, itemHelper: ItemHelper, profileHelper: ProfileHelper, dialogueHelper: DialogueHelper, weightedRandomHelper: WeightedRandomHelper, traderHelper: TraderHelper, paymentService: PaymentService, insuranceService: InsuranceService, mailSendService: MailSendService, ragfairPriceService: RagfairPriceService, localisationService: LocalisationService, configServer: ConfigServer, cloner: ICloner);
2023-06-11 15:10:34 +10:00
/**
2023-10-09 20:21:00 +11:00
* Process insurance items of all profiles prior to being given back to the player through the mail service.
*
* @returns void
2024-04-03 20:15:11 +11:00
*/
2023-06-11 15:10:34 +10:00
processReturn(): void;
/**
2023-10-09 20:21:00 +11:00
* Process insurance items of a single profile prior to being given back to the player through the mail service.
*
* @returns void
2024-04-03 20:15:11 +11:00
*/
2023-10-09 20:21:00 +11:00
processReturnByProfile(sessionID: string): void;
/**
* Get all insured items that are ready to be processed in a specific profile.
*
* @param sessionID Session ID of the profile to check.
* @param time The time to check ready status against. Current time by default.
* @returns All insured items that are ready to be processed.
*/
protected filterInsuredItems(sessionID: string, time?: number): Insurance[];
/**
* This method orchestrates the processing of insured items in a profile.
*
* @param insuranceDetails The insured items to process.
* @param sessionID The session ID that should receive the processed items.
* @returns void
*/
protected processInsuredItems(insuranceDetails: Insurance[], sessionID: string): void;
/**
2024-04-03 20:15:11 +11:00
* Count all items in all insurance packages.
* @param insurance
* @returns
*/
protected countAllInsuranceItems(insurance: Insurance[]): number;
/**
* Remove an insurance package from a profile using the package's system data information.
2023-10-09 20:21:00 +11:00
*
2024-04-03 20:15:11 +11:00
* @param sessionID The session ID of the profile to remove the package from.
* @param index The array index of the insurance package to remove.
* @returns void
*/
protected removeInsurancePackageFromProfile(sessionID: string, insPackage: Insurance): void;
/**
* Finds the items that should be deleted based on the given Insurance object.
2023-10-09 20:21:00 +11:00
*
2024-04-03 20:15:11 +11:00
* @param rootItemParentID - The ID that should be assigned to all "hideout"/root items.
* @param insured - The insurance object containing the items to evaluate for deletion.
* @returns A Set containing the IDs of items that should be deleted.
*/
protected findItemsToDelete(rootItemParentID: string, insured: Insurance): Set<string>;
/**
* Initialize a Map object that holds main-parents to all of their attachments. Note that "main-parent" in this
* context refers to the parent item that an attachment is attached to. For example, a suppressor attached to a gun,
* not the backpack that the gun is located in (the gun's parent).
*
* @param rootItemParentID - The ID that should be assigned to all "hideout"/root items.
* @param insured - The insurance object containing the items to evaluate.
* @param itemsMap - A Map object for quick item look-up by item ID.
* @returns A Map object containing parent item IDs to arrays of their attachment items.
2023-10-09 20:21:00 +11:00
*/
2024-04-03 20:15:11 +11:00
protected populateParentAttachmentsMap(rootItemParentID: string, insured: Insurance, itemsMap: Map<string, Item>): Map<string, Item[]>;
2023-10-09 20:21:00 +11:00
/**
2024-04-03 20:15:11 +11:00
* Remove attachments that can not be moddable in-raid from the parentAttachmentsMap. If no moddable attachments
* remain, the parent is removed from the map as well.
2023-10-09 20:21:00 +11:00
*
2024-04-03 20:15:11 +11:00
* @param parentAttachmentsMap - A Map object containing parent item IDs to arrays of their attachment items.
* @param itemsMap - A Map object for quick item look-up by item ID.
* @returns A Map object containing parent item IDs to arrays of their attachment items which are not moddable in-raid.
2023-10-09 20:21:00 +11:00
*/
2024-04-03 20:15:11 +11:00
protected removeNonModdableAttachments(parentAttachmentsMap: Map<string, Item[]>, itemsMap: Map<string, Item>): Map<string, Item[]>;
2023-10-09 20:21:00 +11:00
/**
2024-04-03 20:15:11 +11:00
* Process "regular" insurance items. Any insured item that is not an attached, attachment is considered a "regular"
* item. This method iterates over them, preforming item deletion rolls to see if they should be deleted. If so,
* they (and their attached, attachments, if any) are marked for deletion in the toDelete Set.
2023-10-09 20:21:00 +11:00
*
2024-04-03 20:15:11 +11:00
* @param insured The insurance object containing the items to evaluate.
* @param toDelete A Set to keep track of items marked for deletion.
* @param parentAttachmentsMap A Map object containing parent item IDs to arrays of their attachment items.
* @returns void
2023-10-09 20:21:00 +11:00
*/
2024-04-03 20:15:11 +11:00
protected processRegularItems(insured: Insurance, toDelete: Set<string>, parentAttachmentsMap: Map<string, Item[]>): void;
2023-10-09 20:21:00 +11:00
/**
2024-04-03 20:15:11 +11:00
* Process parent items and their attachments, updating the toDelete Set accordingly.
2023-10-09 20:21:00 +11:00
*
2024-04-03 20:15:11 +11:00
* @param mainParentToAttachmentsMap A Map object containing parent item IDs to arrays of their attachment items.
* @param itemsMap A Map object for quick item look-up by item ID.
* @param traderId The trader ID from the Insurance object.
* @param toDelete A Set object to keep track of items marked for deletion.
2023-10-09 20:21:00 +11:00
*/
2024-04-03 20:15:11 +11:00
protected processAttachments(mainParentToAttachmentsMap: Map<string, Item[]>, itemsMap: Map<string, Item>, traderId: string, toDelete: Set<string>): void;
2023-10-09 20:21:00 +11:00
/**
2024-04-03 20:15:11 +11:00
* Takes an array of attachment items that belong to the same main-parent item, sorts them in descending order by
* their maximum price. For each attachment, a roll is made to determine if a deletion should be made. Once the
* number of deletions has been counted, the attachments are added to the toDelete Set, starting with the most
* valuable attachments first.
2023-10-09 20:21:00 +11:00
*
2024-04-03 20:15:11 +11:00
* @param attachments The array of attachment items to sort, filter, and roll.
* @param traderId The ID of the trader to that has ensured these items.
* @param toDelete The array that accumulates the IDs of the items to be deleted.
2023-10-09 20:21:00 +11:00
* @returns void
*/
2024-04-03 20:15:11 +11:00
protected processAttachmentByParent(attachments: Item[], traderId: string, toDelete: Set<string>): void;
2024-08-05 20:33:00 +10:00
protected logAttachmentsBeingRemoved(attachmentIdsToRemove: string[], attachments: Item[], attachmentPrices: Record<string, number>): void;
protected weightAttachmentsByPrice(attachments: Item[]): Record<string, number>;
2023-10-09 20:21:00 +11:00
/**
2024-08-05 20:33:00 +10:00
* Get count of items to remove from weapon (take into account trader + price of attachment)
* @param weightedAttachmentByPrice Dict of item Tpls and thier rouble price
* @param traderId Trader attachment insured against
* @returns Attachment count to remove
2023-10-09 20:21:00 +11:00
*/
2024-08-05 20:33:00 +10:00
protected getAttachmentCountToRemove(weightedAttachmentByPrice: Record<string, number>, traderId: string): number;
2023-10-09 20:21:00 +11:00
/**
* Remove items from the insured items that should not be returned to the player.
*
* @param insured The insured items to process.
* @param toDelete The items that should be deleted.
* @returns void
*/
2024-04-03 20:15:11 +11:00
protected removeItemsFromInsurance(insured: Insurance, toDelete: Set<string>): void;
2023-10-09 20:21:00 +11:00
/**
* Handle sending the insurance message to the user that potentially contains the valid insurance items.
*
* @param sessionID The session ID that should receive the insurance message.
* @param insurance The context of insurance to use.
* @returns void
*/
2024-04-03 20:15:11 +11:00
protected sendMail(sessionID: string, insurance: Insurance): void;
2023-10-09 20:21:00 +11:00
/**
2024-08-05 20:33:00 +10:00
* Determines whether an insured item should be removed from the player's inventory based on a random roll and
2023-10-09 20:21:00 +11:00
* trader-specific return chance.
*
* @param traderId The ID of the trader who insured the item.
2024-04-03 20:15:11 +11:00
* @param insuredItem Optional. The item to roll for. Only used for logging.
2024-08-05 20:33:00 +10:00
* @returns true if the insured item should be removed from inventory, false otherwise, or undefined on error.
2023-06-11 15:10:34 +10:00
*/
2024-08-05 20:33:00 +10:00
protected rollForDelete(traderId: string, insuredItem?: Item): boolean | undefined;
2023-06-11 15:10:34 +10:00
/**
2023-10-09 20:21:00 +11:00
* Handle Insure event
2023-06-11 15:10:34 +10:00
* Add insurance to an item
2023-10-09 20:21:00 +11:00
*
2023-06-11 15:10:34 +10:00
* @param pmcData Player profile
* @param body Insurance request
* @param sessionID Session id
* @returns IItemEventRouterResponse object to send to client
*/
insure(pmcData: IPmcData, body: IInsureRequestData, sessionID: string): IItemEventRouterResponse;
/**
2023-10-09 20:21:00 +11:00
* Handle client/insurance/items/list/cost
2023-06-11 15:10:34 +10:00
* Calculate insurance cost
2023-10-09 20:21:00 +11:00
*
* @param request request object
2023-06-11 15:10:34 +10:00
* @param sessionID session id
* @returns IGetInsuranceCostResponseData object to send to client
*/
2023-10-09 20:21:00 +11:00
cost(request: IGetInsuranceCostRequestData, sessionID: string): IGetInsuranceCostResponseData;
2023-06-11 15:10:34 +10:00
}