diff --git a/TypeScript/10ScopesAndTypes/types/controllers/GameController.d.ts b/TypeScript/10ScopesAndTypes/types/controllers/GameController.d.ts index 73596ff..74123b2 100644 --- a/TypeScript/10ScopesAndTypes/types/controllers/GameController.d.ts +++ b/TypeScript/10ScopesAndTypes/types/controllers/GameController.d.ts @@ -49,7 +49,6 @@ export declare class GameController { protected giftService: GiftService; protected applicationContext: ApplicationContext; protected configServer: ConfigServer; - protected os: any; protected httpConfig: IHttpConfig; protected coreConfig: ICoreConfig; protected locationConfig: ILocationConfig; diff --git a/TypeScript/10ScopesAndTypes/types/controllers/InsuranceController.d.ts b/TypeScript/10ScopesAndTypes/types/controllers/InsuranceController.d.ts index fb41610..fc3229b 100644 --- a/TypeScript/10ScopesAndTypes/types/controllers/InsuranceController.d.ts +++ b/TypeScript/10ScopesAndTypes/types/controllers/InsuranceController.d.ts @@ -4,7 +4,6 @@ import { ProfileHelper } from "../helpers/ProfileHelper"; import { TraderHelper } from "../helpers/TraderHelper"; import { IPmcData } from "../models/eft/common/IPmcData"; import { Item } from "../models/eft/common/tables/IItem"; -import { ITemplateItem } from "../models/eft/common/tables/ITemplateItem"; import { IGetInsuranceCostRequestData } from "../models/eft/insurance/IGetInsuranceCostRequestData"; import { IGetInsuranceCostResponseData } from "../models/eft/insurance/IGetInsuranceCostResponseData"; import { IInsureRequestData } from "../models/eft/insurance/IInsureRequestData"; @@ -75,67 +74,92 @@ export declare class InsuranceController { */ protected removeInsurancePackageFromProfile(sessionID: string, packageInfo: ISystemData): void; /** - * Build an array of items to delete from the insured items. + * Finds the items that should be deleted based on the given Insurance object. * - * This method orchestrates several steps: - * - Filters items based on their presence in the database and their raid moddability. - * - Sorts base and independent child items to consider for deletion. - * - Groups child items by their parent for later evaluation. - * - Evaluates grouped child items to decide which should be deleted, based on their value and a random roll. - * - * @param insured - The insured items to build a removal array from. - * @returns An array of IDs representing items that should be deleted. + * @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(insured: Insurance): Set; /** - * Filters an item based on its existence in the database, raid moddability, and slot requirements. + * Populate a Map object of items for quick lookup by their ID. * - * @param item The item to be filtered. - * @param parentItemDbDetails The database details of the parent item, or null if the item has no parent. - * @param itemDbDetails A tuple where the first element is a boolean indicating if the item exists in the database, - * and the second element is the item details if it does. - * @returns true if the item exists in the database and neither of the following conditions are met: - * - The item has the RaidModdable property set to false. - * - The item is attached to a required slot in its parent item. - * Otherwise, returns false. + * @param insured The insurance object containing the items to populate the map with. + * @returns A Map where the keys are the item IDs and the values are the corresponding Item objects. */ - protected filterByRaidModdability(item: Item, parentItemDbDetails: ITemplateItem | null, itemDbDetails: [boolean, ITemplateItem]): boolean; + protected populateItemsMap(insured: Insurance): Map; /** - * Determines if an item is either a base item or a child item that is not equipped to its parent. + * 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 item The item to check. - * @returns true if the item is a base or an independent child item, otherwise false. + * @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. */ - protected isBaseOrIndependentChild(item: Item): boolean; + protected populateParentAttachmentsMap(insured: Insurance, itemsMap: Map): Map; /** - * Makes a roll to determine if a given item should be deleted. If the roll is successful, the item's ID is added - * to the `toDelete` array. + * 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. * - * @param item The item for which the roll is made. - * @param traderId The ID of the trader to consider in the rollForItemDelete method. - * @param toDelete The array accumulating the IDs of items to be deleted. - * @returns true if the item is marked for deletion, otherwise false. - */ - protected makeRollAndMarkForDeletion(item: Item, traderId: string, toDelete: Set): boolean; - /** - * Groups child items by their parent IDs in a Map data structure. - * - * @param item The child item to be grouped by its parent. - * @param childrenGroupedByParent The Map that holds arrays of children items grouped by their parent IDs. + * @param insured The insurance object containing the items to evaluate. + * @param toDelete A Set to keep track of items marked for deletion. * @returns void */ - protected groupChildrenByParent(item: Item, childrenGroupedByParent: Map): void; + protected processRegularItems(insured: Insurance, toDelete: Set): void; /** - * Sorts the array of children items in descending order by their maximum price. For each child, a roll is made to - * determine if it should be deleted. The method then deletes the most valuable children based on the number of - * successful rolls made. + * Process parent items and their attachments, updating the toDelete Set accordingly. * - * @param children The array of children items to sort and filter. - * @param traderId The ID of the trader to consider in the rollForItemDelete method. + * This method iterates over a map of parent items to their attachments and performs evaluations on each. + * It marks items for deletion based on certain conditions and updates the toDelete Set accordingly. + * + * @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. + */ + protected processAttachments(mainParentToAttachmentsMap: Map, itemsMap: Map, traderId: string, toDelete: Set): void; + /** + * 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. + * + * @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. * @returns void */ - protected sortAndFilterChildren(children: Item[], traderId: string, toDelete: Set): void; + protected processAttachmentByParent(attachments: Item[], traderId: string, toDelete: Set): void; + /** + * Sorts the attachment items by their max price in descending order. + * + * @param attachments The array of attachments items. + * @returns An array of items enriched with their max price and common locale-name. + */ + protected sortAttachmentsByPrice(attachments: Item[]): EnrichedItem[]; + /** + * Logs the details of each attachment item. + * + * @param attachments The array of attachment items. + */ + protected logAttachmentsDetails(attachments: EnrichedItem[]): void; + /** + * Counts the number of successful rolls for the attachment items. + * + * @param attachments The array of attachment items. + * @param traderId The ID of the trader that has insured these attachments. + * @returns The number of successful rolls. + */ + protected countSuccessfulRolls(attachments: Item[], traderId: string): number; + /** + * Marks the most valuable attachments for deletion based on the number of successful rolls made. + * + * @param attachments The array of attachment items. + * @param successfulRolls The number of successful rolls. + * @param toDelete The array that accumulates the IDs of the items to be deleted. + */ + protected attachmentDeletionByValue(attachments: EnrichedItem[], successfulRolls: number, toDelete: Set): void; /** * Remove items from the insured items that should not be returned to the player. * @@ -144,6 +168,22 @@ export declare class InsuranceController { * @returns void */ protected removeItemsFromInsurance(insured: Insurance, toDelete: Set): void; + /** + * Adopts orphaned items by resetting them as base-level items. Helpful in situations where a parent has been + * deleted from insurance, but any insured items within the parent should remain. This method will remove the + * reference from the children to the parent and set item properties to main-level values. + * + * @param insured Insurance object containing items. + */ + protected adoptOrphanedItems(insured: Insurance): void; + /** + * Fetches the parentId property of an item with a slotId "hideout". Not sure if this is actually dynamic, but this + * method should be a reliable way to fetch it, if it ever does change. + * + * @param items Array of items to search through. + * @returns The parentId of an item with slotId 'hideout'. Empty string if not found. + */ + protected fetchHideoutItemParent(items: Item[]): string; /** * Handle sending the insurance message to the user that potentially contains the valid insurance items. * @@ -154,15 +194,14 @@ export declare class InsuranceController { */ protected sendMail(sessionID: string, insurance: Insurance, noItems: boolean): void; /** - * Determines whether a valid insured item should be removed from the player's inventory based on a random roll and + * Determines whether a insured item should be removed from the player's inventory based on a random roll and * trader-specific return chance. * - * @param insuredItem The insured item being evaluated for removal. * @param traderId The ID of the trader who insured the item. - * @param itemsBeingDeleted List of items that are already slated for removal. + * @param insuredItem Optional. The item to roll for. Only used for logging. * @returns true if the insured item should be removed from inventory, false otherwise. */ - protected rollForItemDelete(insuredItem: Item, traderId: string, itemsBeingDeleted: Set): boolean; + protected rollForDelete(traderId: string, insuredItem?: Item): boolean; /** * Handle Insure event * Add insurance to an item @@ -183,3 +222,8 @@ export declare class InsuranceController { */ cost(request: IGetInsuranceCostRequestData, sessionID: string): IGetInsuranceCostResponseData; } +interface EnrichedItem extends Item { + name: string; + maxPrice: number; +} +export {}; diff --git a/TypeScript/10ScopesAndTypes/types/di/Serializer.d.ts b/TypeScript/10ScopesAndTypes/types/di/Serializer.d.ts index 2617007..b760b8b 100644 --- a/TypeScript/10ScopesAndTypes/types/di/Serializer.d.ts +++ b/TypeScript/10ScopesAndTypes/types/di/Serializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export declare class Serializer { serialize(sessionID: string, req: IncomingMessage, resp: ServerResponse, body: any): void; canHandle(something: string): boolean; diff --git a/TypeScript/10ScopesAndTypes/types/helpers/ItemHelper.d.ts b/TypeScript/10ScopesAndTypes/types/helpers/ItemHelper.d.ts index 6f1511c..5920d8a 100644 --- a/TypeScript/10ScopesAndTypes/types/helpers/ItemHelper.d.ts +++ b/TypeScript/10ScopesAndTypes/types/helpers/ItemHelper.d.ts @@ -225,6 +225,48 @@ declare class ItemHelper { * @returns true if item is flagged as quest item */ isQuestItem(tpl: string): boolean; + /** + * Checks to see if the item is *actually* moddable in-raid. Checks include the items existence in the database, the + * parent items existence in the database, the existence (and value) of the items RaidModdable property, and that + * the parents slot-required property exists, matches that of the item, and it's value. + * + * Note: this function does not preform any checks to see if the item and parent are *actually* related. + * + * @param item The item to be checked + * @param parent The parent of the item to be checked + * @returns True if the item is actually moddable, false if it is not, and null if the check cannot be performed. + */ + isRaidModdable(item: Item, parent: Item): boolean | null; + /** + * Retrieves the main parent item for a given attachment item. + * + * This method traverses up the hierarchy of items starting from a given `itemId`, until it finds the main parent + * item that is not an attached attachment itself. In other words, if you pass it an item id of a suppressor, it + * will traverse up the muzzle brake, barrel, upper receiver, and return the gun that the suppressor is ultimately + * attached to, even if that gun is located within multiple containers. + * + * It's important to note that traversal is expensive, so this method requires that you pass it a Map of the items + * to traverse, where the keys are the item IDs and the values are the corresponding Item objects. This alleviates + * some of the performance concerns, as it allows for quick lookups of items by ID. + * + * To generate the map: + * ``` + * const itemsMap = new Map(); + * items.forEach(item => itemsMap.set(item._id, item)); + * ``` + * + * @param itemId - The unique identifier of the item for which to find the main parent. + * @param itemsMap - A Map containing item IDs mapped to their corresponding Item objects for quick lookup. + * @returns The Item object representing the top-most parent of the given item, or `null` if no such parent exists. + */ + getAttachmentMainParent(itemId: string, itemsMap: Map): Item | null; + /** + * Determines if an item is an attachment that is currently attached to it's parent item. + * + * @param item The item to check. + * @returns true if the item is attached attachment, otherwise false. + */ + isAttachmentAttached(item: Item): boolean; /** * Get the inventory size of an item * @param items Item with children diff --git a/TypeScript/10ScopesAndTypes/types/loaders/PreAkiModLoader.d.ts b/TypeScript/10ScopesAndTypes/types/loaders/PreAkiModLoader.d.ts index 1e24b96..c0868b7 100644 --- a/TypeScript/10ScopesAndTypes/types/loaders/PreAkiModLoader.d.ts +++ b/TypeScript/10ScopesAndTypes/types/loaders/PreAkiModLoader.d.ts @@ -66,6 +66,10 @@ export declare class PreAkiModLoader implements IModLoader { protected isModCombatibleWithAki(mod: IPackageJsonData): boolean; protected executeMods(container: DependencyContainer): Promise; sortModsLoadOrder(): string[]; + /** + * Compile mod and add into class property "imported" + * @param mod Name of mod to compile/add + */ protected addMod(mod: string): Promise; protected autoInstallDependencies(modPath: string, pkg: IPackageJsonData): void; protected areModDependenciesFulfilled(pkg: IPackageJsonData, loadedMods: Record): boolean; diff --git a/TypeScript/10ScopesAndTypes/types/models/external/HttpFramework.d.ts b/TypeScript/10ScopesAndTypes/types/models/external/HttpFramework.d.ts index 64a37d6..fda8732 100644 --- a/TypeScript/10ScopesAndTypes/types/models/external/HttpFramework.d.ts +++ b/TypeScript/10ScopesAndTypes/types/models/external/HttpFramework.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export type HandleFn = (_: string, req: IncomingMessage, resp: ServerResponse) => void; /** * Associates handlers, HTTP methods and a base url to a listener using a proxy diff --git a/TypeScript/10ScopesAndTypes/types/models/spt/mod/IPackageJsonData.d.ts b/TypeScript/10ScopesAndTypes/types/models/spt/mod/IPackageJsonData.d.ts index 06f7454..f58d7cc 100644 --- a/TypeScript/10ScopesAndTypes/types/models/spt/mod/IPackageJsonData.d.ts +++ b/TypeScript/10ScopesAndTypes/types/models/spt/mod/IPackageJsonData.d.ts @@ -6,6 +6,9 @@ export interface IPackageJsonData { author: string; version: string; akiVersion: string; + /** We deliberately purge this data */ + scripts: Record; + devDependencies: Record; licence: string; main: string; isBundleMod: boolean; diff --git a/TypeScript/10ScopesAndTypes/types/routers/HttpRouter.d.ts b/TypeScript/10ScopesAndTypes/types/routers/HttpRouter.d.ts index f75a47d..46f847a 100644 --- a/TypeScript/10ScopesAndTypes/types/routers/HttpRouter.d.ts +++ b/TypeScript/10ScopesAndTypes/types/routers/HttpRouter.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage } from "http"; +import { IncomingMessage } from "node:http"; import { DynamicRouter, Router, StaticRouter } from "../di/Router"; export declare class HttpRouter { protected staticRouters: StaticRouter[]; diff --git a/TypeScript/10ScopesAndTypes/types/routers/ImageRouter.d.ts b/TypeScript/10ScopesAndTypes/types/routers/ImageRouter.d.ts index 675441c..fd03c59 100644 --- a/TypeScript/10ScopesAndTypes/types/routers/ImageRouter.d.ts +++ b/TypeScript/10ScopesAndTypes/types/routers/ImageRouter.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { ImageRouteService } from "../services/mod/image/ImageRouteService"; import { HttpFileUtil } from "../utils/HttpFileUtil"; import { VFS } from "../utils/VFS"; diff --git a/TypeScript/10ScopesAndTypes/types/routers/serializers/BundleSerializer.d.ts b/TypeScript/10ScopesAndTypes/types/routers/serializers/BundleSerializer.d.ts index ca4d8b6..db41142 100644 --- a/TypeScript/10ScopesAndTypes/types/routers/serializers/BundleSerializer.d.ts +++ b/TypeScript/10ScopesAndTypes/types/routers/serializers/BundleSerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { BundleLoader } from "../../loaders/BundleLoader"; import { ILogger } from "../../models/spt/utils/ILogger"; diff --git a/TypeScript/10ScopesAndTypes/types/routers/serializers/ImageSerializer.d.ts b/TypeScript/10ScopesAndTypes/types/routers/serializers/ImageSerializer.d.ts index 5de48ff..62ce84d 100644 --- a/TypeScript/10ScopesAndTypes/types/routers/serializers/ImageSerializer.d.ts +++ b/TypeScript/10ScopesAndTypes/types/routers/serializers/ImageSerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { ImageRouter } from "../ImageRouter"; export declare class ImageSerializer extends Serializer { diff --git a/TypeScript/10ScopesAndTypes/types/routers/serializers/NotifySerializer.d.ts b/TypeScript/10ScopesAndTypes/types/routers/serializers/NotifySerializer.d.ts index 1d179b2..e92d6e1 100644 --- a/TypeScript/10ScopesAndTypes/types/routers/serializers/NotifySerializer.d.ts +++ b/TypeScript/10ScopesAndTypes/types/routers/serializers/NotifySerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { NotifierController } from "../../controllers/NotifierController"; import { Serializer } from "../../di/Serializer"; import { HttpServerHelper } from "../../helpers/HttpServerHelper"; diff --git a/TypeScript/10ScopesAndTypes/types/servers/HttpServer.d.ts b/TypeScript/10ScopesAndTypes/types/servers/HttpServer.d.ts index 97e0705..c73eb3c 100644 --- a/TypeScript/10ScopesAndTypes/types/servers/HttpServer.d.ts +++ b/TypeScript/10ScopesAndTypes/types/servers/HttpServer.d.ts @@ -1,5 +1,5 @@ /// -import http, { IncomingMessage, ServerResponse } from "http"; +import http, { IncomingMessage, ServerResponse } from "node:http"; import { ApplicationContext } from "../context/ApplicationContext"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; import { IHttpConfig } from "../models/spt/config/IHttpConfig"; diff --git a/TypeScript/10ScopesAndTypes/types/servers/WebSocketServer.d.ts b/TypeScript/10ScopesAndTypes/types/servers/WebSocketServer.d.ts index fffbea2..b4c6158 100644 --- a/TypeScript/10ScopesAndTypes/types/servers/WebSocketServer.d.ts +++ b/TypeScript/10ScopesAndTypes/types/servers/WebSocketServer.d.ts @@ -1,5 +1,5 @@ /// -import http, { IncomingMessage } from "http"; +import http, { IncomingMessage } from "node:http"; import WebSocket from "ws"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; import { INotification } from "../models/eft/notifier/INotifier"; diff --git a/TypeScript/10ScopesAndTypes/types/servers/http/AkiHttpListener.d.ts b/TypeScript/10ScopesAndTypes/types/servers/http/AkiHttpListener.d.ts index c72e18f..e4ac80c 100644 --- a/TypeScript/10ScopesAndTypes/types/servers/http/AkiHttpListener.d.ts +++ b/TypeScript/10ScopesAndTypes/types/servers/http/AkiHttpListener.d.ts @@ -1,6 +1,6 @@ /// /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { ILogger } from "../../models/spt/utils/ILogger"; import { HttpRouter } from "../../routers/HttpRouter"; diff --git a/TypeScript/10ScopesAndTypes/types/servers/http/IHttpListener.d.ts b/TypeScript/10ScopesAndTypes/types/servers/http/IHttpListener.d.ts index 758bb5a..29d5fce 100644 --- a/TypeScript/10ScopesAndTypes/types/servers/http/IHttpListener.d.ts +++ b/TypeScript/10ScopesAndTypes/types/servers/http/IHttpListener.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export interface IHttpListener { canHandle(sessionId: string, req: IncomingMessage): boolean; handle(sessionId: string, req: IncomingMessage, resp: ServerResponse): void; diff --git a/TypeScript/10ScopesAndTypes/types/services/mod/httpListener/HttpListenerMod.d.ts b/TypeScript/10ScopesAndTypes/types/services/mod/httpListener/HttpListenerMod.d.ts index 2cdfbda..afe4574 100644 --- a/TypeScript/10ScopesAndTypes/types/services/mod/httpListener/HttpListenerMod.d.ts +++ b/TypeScript/10ScopesAndTypes/types/services/mod/httpListener/HttpListenerMod.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { IHttpListener } from "../../../servers/http/IHttpListener"; export declare class HttpListenerMod implements IHttpListener { private canHandleOverride; diff --git a/TypeScript/10ScopesAndTypes/types/services/mod/httpListener/HttpListenerModService.d.ts b/TypeScript/10ScopesAndTypes/types/services/mod/httpListener/HttpListenerModService.d.ts index 9dd3473..23abfbe 100644 --- a/TypeScript/10ScopesAndTypes/types/services/mod/httpListener/HttpListenerModService.d.ts +++ b/TypeScript/10ScopesAndTypes/types/services/mod/httpListener/HttpListenerModService.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { DependencyContainer } from "tsyringe"; export declare class HttpListenerModService { protected container: DependencyContainer; diff --git a/TypeScript/10ScopesAndTypes/types/utils/App.d.ts b/TypeScript/10ScopesAndTypes/types/utils/App.d.ts index dd8f24c..5e759ad 100644 --- a/TypeScript/10ScopesAndTypes/types/utils/App.d.ts +++ b/TypeScript/10ScopesAndTypes/types/utils/App.d.ts @@ -12,7 +12,6 @@ export declare class App { protected onLoadComponents: OnLoad[]; protected onUpdateComponents: OnUpdate[]; protected onUpdateLastRun: {}; - protected os: any; constructor(logger: ILogger, timeUtil: TimeUtil, localisationService: LocalisationService, encodingUtil: EncodingUtil, onLoadComponents: OnLoad[], onUpdateComponents: OnUpdate[]); load(): Promise; protected update(onUpdateComponents: OnUpdate[]): Promise; diff --git a/TypeScript/10ScopesAndTypes/types/utils/HashUtil.d.ts b/TypeScript/10ScopesAndTypes/types/utils/HashUtil.d.ts index c017ca8..27204cb 100644 --- a/TypeScript/10ScopesAndTypes/types/utils/HashUtil.d.ts +++ b/TypeScript/10ScopesAndTypes/types/utils/HashUtil.d.ts @@ -1,5 +1,5 @@ /// -import crypto from "crypto"; +import crypto from "node:crypto"; import { TimeUtil } from "./TimeUtil"; export declare class HashUtil { protected timeUtil: TimeUtil; diff --git a/TypeScript/10ScopesAndTypes/types/utils/HttpFileUtil.d.ts b/TypeScript/10ScopesAndTypes/types/utils/HttpFileUtil.d.ts index afc8409..6a386ce 100644 --- a/TypeScript/10ScopesAndTypes/types/utils/HttpFileUtil.d.ts +++ b/TypeScript/10ScopesAndTypes/types/utils/HttpFileUtil.d.ts @@ -1,5 +1,5 @@ /// -import { ServerResponse } from "http"; +import { ServerResponse } from "node:http"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; export declare class HttpFileUtil { protected httpServerHelper: HttpServerHelper; diff --git a/TypeScript/10ScopesAndTypes/types/utils/VFS.d.ts b/TypeScript/10ScopesAndTypes/types/utils/VFS.d.ts index 2cb09fa..3911c4b 100644 --- a/TypeScript/10ScopesAndTypes/types/utils/VFS.d.ts +++ b/TypeScript/10ScopesAndTypes/types/utils/VFS.d.ts @@ -1,6 +1,6 @@ /// /// -import fs from "fs"; +import fs from "node:fs"; import "reflect-metadata"; import { IAsyncQueue } from "../models/spt/utils/IAsyncQueue"; import { IUUidGenerator } from "../models/spt/utils/IUuidGenerator"; diff --git a/TypeScript/10ScopesAndTypes/types/utils/Watermark.d.ts b/TypeScript/10ScopesAndTypes/types/utils/Watermark.d.ts index fa63205..864e9b6 100644 --- a/TypeScript/10ScopesAndTypes/types/utils/Watermark.d.ts +++ b/TypeScript/10ScopesAndTypes/types/utils/Watermark.d.ts @@ -4,12 +4,10 @@ import { ConfigServer } from "../servers/ConfigServer"; import { LocalisationService } from "../services/LocalisationService"; export declare class WatermarkLocale { protected localisationService: LocalisationService; + protected description: string[]; + protected warning: string[]; + protected modding: string[]; constructor(localisationService: LocalisationService); - protected watermark: { - description: string[]; - warning: string[]; - modding: string[]; - }; getDescription(): string[]; getWarning(): string[]; getModding(): string[]; diff --git a/TypeScript/10ScopesAndTypes/types/utils/logging/AbstractWinstonLogger.d.ts b/TypeScript/10ScopesAndTypes/types/utils/logging/AbstractWinstonLogger.d.ts index 1ae1100..74767a2 100644 --- a/TypeScript/10ScopesAndTypes/types/utils/logging/AbstractWinstonLogger.d.ts +++ b/TypeScript/10ScopesAndTypes/types/utils/logging/AbstractWinstonLogger.d.ts @@ -1,5 +1,5 @@ /// -import fs from "fs"; +import fs from "node:fs"; import winston from "winston"; import { Daum } from "../../models/eft/itemEvent/IItemEventRouterRequest"; import { LogBackgroundColor } from "../../models/spt/logging/LogBackgroundColor"; diff --git a/TypeScript/11BundleLoadingSample/types/controllers/GameController.d.ts b/TypeScript/11BundleLoadingSample/types/controllers/GameController.d.ts index 73596ff..74123b2 100644 --- a/TypeScript/11BundleLoadingSample/types/controllers/GameController.d.ts +++ b/TypeScript/11BundleLoadingSample/types/controllers/GameController.d.ts @@ -49,7 +49,6 @@ export declare class GameController { protected giftService: GiftService; protected applicationContext: ApplicationContext; protected configServer: ConfigServer; - protected os: any; protected httpConfig: IHttpConfig; protected coreConfig: ICoreConfig; protected locationConfig: ILocationConfig; diff --git a/TypeScript/11BundleLoadingSample/types/controllers/InsuranceController.d.ts b/TypeScript/11BundleLoadingSample/types/controllers/InsuranceController.d.ts index fb41610..fc3229b 100644 --- a/TypeScript/11BundleLoadingSample/types/controllers/InsuranceController.d.ts +++ b/TypeScript/11BundleLoadingSample/types/controllers/InsuranceController.d.ts @@ -4,7 +4,6 @@ import { ProfileHelper } from "../helpers/ProfileHelper"; import { TraderHelper } from "../helpers/TraderHelper"; import { IPmcData } from "../models/eft/common/IPmcData"; import { Item } from "../models/eft/common/tables/IItem"; -import { ITemplateItem } from "../models/eft/common/tables/ITemplateItem"; import { IGetInsuranceCostRequestData } from "../models/eft/insurance/IGetInsuranceCostRequestData"; import { IGetInsuranceCostResponseData } from "../models/eft/insurance/IGetInsuranceCostResponseData"; import { IInsureRequestData } from "../models/eft/insurance/IInsureRequestData"; @@ -75,67 +74,92 @@ export declare class InsuranceController { */ protected removeInsurancePackageFromProfile(sessionID: string, packageInfo: ISystemData): void; /** - * Build an array of items to delete from the insured items. + * Finds the items that should be deleted based on the given Insurance object. * - * This method orchestrates several steps: - * - Filters items based on their presence in the database and their raid moddability. - * - Sorts base and independent child items to consider for deletion. - * - Groups child items by their parent for later evaluation. - * - Evaluates grouped child items to decide which should be deleted, based on their value and a random roll. - * - * @param insured - The insured items to build a removal array from. - * @returns An array of IDs representing items that should be deleted. + * @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(insured: Insurance): Set; /** - * Filters an item based on its existence in the database, raid moddability, and slot requirements. + * Populate a Map object of items for quick lookup by their ID. * - * @param item The item to be filtered. - * @param parentItemDbDetails The database details of the parent item, or null if the item has no parent. - * @param itemDbDetails A tuple where the first element is a boolean indicating if the item exists in the database, - * and the second element is the item details if it does. - * @returns true if the item exists in the database and neither of the following conditions are met: - * - The item has the RaidModdable property set to false. - * - The item is attached to a required slot in its parent item. - * Otherwise, returns false. + * @param insured The insurance object containing the items to populate the map with. + * @returns A Map where the keys are the item IDs and the values are the corresponding Item objects. */ - protected filterByRaidModdability(item: Item, parentItemDbDetails: ITemplateItem | null, itemDbDetails: [boolean, ITemplateItem]): boolean; + protected populateItemsMap(insured: Insurance): Map; /** - * Determines if an item is either a base item or a child item that is not equipped to its parent. + * 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 item The item to check. - * @returns true if the item is a base or an independent child item, otherwise false. + * @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. */ - protected isBaseOrIndependentChild(item: Item): boolean; + protected populateParentAttachmentsMap(insured: Insurance, itemsMap: Map): Map; /** - * Makes a roll to determine if a given item should be deleted. If the roll is successful, the item's ID is added - * to the `toDelete` array. + * 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. * - * @param item The item for which the roll is made. - * @param traderId The ID of the trader to consider in the rollForItemDelete method. - * @param toDelete The array accumulating the IDs of items to be deleted. - * @returns true if the item is marked for deletion, otherwise false. - */ - protected makeRollAndMarkForDeletion(item: Item, traderId: string, toDelete: Set): boolean; - /** - * Groups child items by their parent IDs in a Map data structure. - * - * @param item The child item to be grouped by its parent. - * @param childrenGroupedByParent The Map that holds arrays of children items grouped by their parent IDs. + * @param insured The insurance object containing the items to evaluate. + * @param toDelete A Set to keep track of items marked for deletion. * @returns void */ - protected groupChildrenByParent(item: Item, childrenGroupedByParent: Map): void; + protected processRegularItems(insured: Insurance, toDelete: Set): void; /** - * Sorts the array of children items in descending order by their maximum price. For each child, a roll is made to - * determine if it should be deleted. The method then deletes the most valuable children based on the number of - * successful rolls made. + * Process parent items and their attachments, updating the toDelete Set accordingly. * - * @param children The array of children items to sort and filter. - * @param traderId The ID of the trader to consider in the rollForItemDelete method. + * This method iterates over a map of parent items to their attachments and performs evaluations on each. + * It marks items for deletion based on certain conditions and updates the toDelete Set accordingly. + * + * @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. + */ + protected processAttachments(mainParentToAttachmentsMap: Map, itemsMap: Map, traderId: string, toDelete: Set): void; + /** + * 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. + * + * @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. * @returns void */ - protected sortAndFilterChildren(children: Item[], traderId: string, toDelete: Set): void; + protected processAttachmentByParent(attachments: Item[], traderId: string, toDelete: Set): void; + /** + * Sorts the attachment items by their max price in descending order. + * + * @param attachments The array of attachments items. + * @returns An array of items enriched with their max price and common locale-name. + */ + protected sortAttachmentsByPrice(attachments: Item[]): EnrichedItem[]; + /** + * Logs the details of each attachment item. + * + * @param attachments The array of attachment items. + */ + protected logAttachmentsDetails(attachments: EnrichedItem[]): void; + /** + * Counts the number of successful rolls for the attachment items. + * + * @param attachments The array of attachment items. + * @param traderId The ID of the trader that has insured these attachments. + * @returns The number of successful rolls. + */ + protected countSuccessfulRolls(attachments: Item[], traderId: string): number; + /** + * Marks the most valuable attachments for deletion based on the number of successful rolls made. + * + * @param attachments The array of attachment items. + * @param successfulRolls The number of successful rolls. + * @param toDelete The array that accumulates the IDs of the items to be deleted. + */ + protected attachmentDeletionByValue(attachments: EnrichedItem[], successfulRolls: number, toDelete: Set): void; /** * Remove items from the insured items that should not be returned to the player. * @@ -144,6 +168,22 @@ export declare class InsuranceController { * @returns void */ protected removeItemsFromInsurance(insured: Insurance, toDelete: Set): void; + /** + * Adopts orphaned items by resetting them as base-level items. Helpful in situations where a parent has been + * deleted from insurance, but any insured items within the parent should remain. This method will remove the + * reference from the children to the parent and set item properties to main-level values. + * + * @param insured Insurance object containing items. + */ + protected adoptOrphanedItems(insured: Insurance): void; + /** + * Fetches the parentId property of an item with a slotId "hideout". Not sure if this is actually dynamic, but this + * method should be a reliable way to fetch it, if it ever does change. + * + * @param items Array of items to search through. + * @returns The parentId of an item with slotId 'hideout'. Empty string if not found. + */ + protected fetchHideoutItemParent(items: Item[]): string; /** * Handle sending the insurance message to the user that potentially contains the valid insurance items. * @@ -154,15 +194,14 @@ export declare class InsuranceController { */ protected sendMail(sessionID: string, insurance: Insurance, noItems: boolean): void; /** - * Determines whether a valid insured item should be removed from the player's inventory based on a random roll and + * Determines whether a insured item should be removed from the player's inventory based on a random roll and * trader-specific return chance. * - * @param insuredItem The insured item being evaluated for removal. * @param traderId The ID of the trader who insured the item. - * @param itemsBeingDeleted List of items that are already slated for removal. + * @param insuredItem Optional. The item to roll for. Only used for logging. * @returns true if the insured item should be removed from inventory, false otherwise. */ - protected rollForItemDelete(insuredItem: Item, traderId: string, itemsBeingDeleted: Set): boolean; + protected rollForDelete(traderId: string, insuredItem?: Item): boolean; /** * Handle Insure event * Add insurance to an item @@ -183,3 +222,8 @@ export declare class InsuranceController { */ cost(request: IGetInsuranceCostRequestData, sessionID: string): IGetInsuranceCostResponseData; } +interface EnrichedItem extends Item { + name: string; + maxPrice: number; +} +export {}; diff --git a/TypeScript/11BundleLoadingSample/types/di/Serializer.d.ts b/TypeScript/11BundleLoadingSample/types/di/Serializer.d.ts index 2617007..b760b8b 100644 --- a/TypeScript/11BundleLoadingSample/types/di/Serializer.d.ts +++ b/TypeScript/11BundleLoadingSample/types/di/Serializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export declare class Serializer { serialize(sessionID: string, req: IncomingMessage, resp: ServerResponse, body: any): void; canHandle(something: string): boolean; diff --git a/TypeScript/11BundleLoadingSample/types/helpers/ItemHelper.d.ts b/TypeScript/11BundleLoadingSample/types/helpers/ItemHelper.d.ts index 6f1511c..5920d8a 100644 --- a/TypeScript/11BundleLoadingSample/types/helpers/ItemHelper.d.ts +++ b/TypeScript/11BundleLoadingSample/types/helpers/ItemHelper.d.ts @@ -225,6 +225,48 @@ declare class ItemHelper { * @returns true if item is flagged as quest item */ isQuestItem(tpl: string): boolean; + /** + * Checks to see if the item is *actually* moddable in-raid. Checks include the items existence in the database, the + * parent items existence in the database, the existence (and value) of the items RaidModdable property, and that + * the parents slot-required property exists, matches that of the item, and it's value. + * + * Note: this function does not preform any checks to see if the item and parent are *actually* related. + * + * @param item The item to be checked + * @param parent The parent of the item to be checked + * @returns True if the item is actually moddable, false if it is not, and null if the check cannot be performed. + */ + isRaidModdable(item: Item, parent: Item): boolean | null; + /** + * Retrieves the main parent item for a given attachment item. + * + * This method traverses up the hierarchy of items starting from a given `itemId`, until it finds the main parent + * item that is not an attached attachment itself. In other words, if you pass it an item id of a suppressor, it + * will traverse up the muzzle brake, barrel, upper receiver, and return the gun that the suppressor is ultimately + * attached to, even if that gun is located within multiple containers. + * + * It's important to note that traversal is expensive, so this method requires that you pass it a Map of the items + * to traverse, where the keys are the item IDs and the values are the corresponding Item objects. This alleviates + * some of the performance concerns, as it allows for quick lookups of items by ID. + * + * To generate the map: + * ``` + * const itemsMap = new Map(); + * items.forEach(item => itemsMap.set(item._id, item)); + * ``` + * + * @param itemId - The unique identifier of the item for which to find the main parent. + * @param itemsMap - A Map containing item IDs mapped to their corresponding Item objects for quick lookup. + * @returns The Item object representing the top-most parent of the given item, or `null` if no such parent exists. + */ + getAttachmentMainParent(itemId: string, itemsMap: Map): Item | null; + /** + * Determines if an item is an attachment that is currently attached to it's parent item. + * + * @param item The item to check. + * @returns true if the item is attached attachment, otherwise false. + */ + isAttachmentAttached(item: Item): boolean; /** * Get the inventory size of an item * @param items Item with children diff --git a/TypeScript/11BundleLoadingSample/types/loaders/PreAkiModLoader.d.ts b/TypeScript/11BundleLoadingSample/types/loaders/PreAkiModLoader.d.ts index 1e24b96..c0868b7 100644 --- a/TypeScript/11BundleLoadingSample/types/loaders/PreAkiModLoader.d.ts +++ b/TypeScript/11BundleLoadingSample/types/loaders/PreAkiModLoader.d.ts @@ -66,6 +66,10 @@ export declare class PreAkiModLoader implements IModLoader { protected isModCombatibleWithAki(mod: IPackageJsonData): boolean; protected executeMods(container: DependencyContainer): Promise; sortModsLoadOrder(): string[]; + /** + * Compile mod and add into class property "imported" + * @param mod Name of mod to compile/add + */ protected addMod(mod: string): Promise; protected autoInstallDependencies(modPath: string, pkg: IPackageJsonData): void; protected areModDependenciesFulfilled(pkg: IPackageJsonData, loadedMods: Record): boolean; diff --git a/TypeScript/11BundleLoadingSample/types/models/external/HttpFramework.d.ts b/TypeScript/11BundleLoadingSample/types/models/external/HttpFramework.d.ts index 64a37d6..fda8732 100644 --- a/TypeScript/11BundleLoadingSample/types/models/external/HttpFramework.d.ts +++ b/TypeScript/11BundleLoadingSample/types/models/external/HttpFramework.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export type HandleFn = (_: string, req: IncomingMessage, resp: ServerResponse) => void; /** * Associates handlers, HTTP methods and a base url to a listener using a proxy diff --git a/TypeScript/11BundleLoadingSample/types/models/spt/mod/IPackageJsonData.d.ts b/TypeScript/11BundleLoadingSample/types/models/spt/mod/IPackageJsonData.d.ts index 06f7454..f58d7cc 100644 --- a/TypeScript/11BundleLoadingSample/types/models/spt/mod/IPackageJsonData.d.ts +++ b/TypeScript/11BundleLoadingSample/types/models/spt/mod/IPackageJsonData.d.ts @@ -6,6 +6,9 @@ export interface IPackageJsonData { author: string; version: string; akiVersion: string; + /** We deliberately purge this data */ + scripts: Record; + devDependencies: Record; licence: string; main: string; isBundleMod: boolean; diff --git a/TypeScript/11BundleLoadingSample/types/routers/HttpRouter.d.ts b/TypeScript/11BundleLoadingSample/types/routers/HttpRouter.d.ts index f75a47d..46f847a 100644 --- a/TypeScript/11BundleLoadingSample/types/routers/HttpRouter.d.ts +++ b/TypeScript/11BundleLoadingSample/types/routers/HttpRouter.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage } from "http"; +import { IncomingMessage } from "node:http"; import { DynamicRouter, Router, StaticRouter } from "../di/Router"; export declare class HttpRouter { protected staticRouters: StaticRouter[]; diff --git a/TypeScript/11BundleLoadingSample/types/routers/ImageRouter.d.ts b/TypeScript/11BundleLoadingSample/types/routers/ImageRouter.d.ts index 675441c..fd03c59 100644 --- a/TypeScript/11BundleLoadingSample/types/routers/ImageRouter.d.ts +++ b/TypeScript/11BundleLoadingSample/types/routers/ImageRouter.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { ImageRouteService } from "../services/mod/image/ImageRouteService"; import { HttpFileUtil } from "../utils/HttpFileUtil"; import { VFS } from "../utils/VFS"; diff --git a/TypeScript/11BundleLoadingSample/types/routers/serializers/BundleSerializer.d.ts b/TypeScript/11BundleLoadingSample/types/routers/serializers/BundleSerializer.d.ts index ca4d8b6..db41142 100644 --- a/TypeScript/11BundleLoadingSample/types/routers/serializers/BundleSerializer.d.ts +++ b/TypeScript/11BundleLoadingSample/types/routers/serializers/BundleSerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { BundleLoader } from "../../loaders/BundleLoader"; import { ILogger } from "../../models/spt/utils/ILogger"; diff --git a/TypeScript/11BundleLoadingSample/types/routers/serializers/ImageSerializer.d.ts b/TypeScript/11BundleLoadingSample/types/routers/serializers/ImageSerializer.d.ts index 5de48ff..62ce84d 100644 --- a/TypeScript/11BundleLoadingSample/types/routers/serializers/ImageSerializer.d.ts +++ b/TypeScript/11BundleLoadingSample/types/routers/serializers/ImageSerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { ImageRouter } from "../ImageRouter"; export declare class ImageSerializer extends Serializer { diff --git a/TypeScript/11BundleLoadingSample/types/routers/serializers/NotifySerializer.d.ts b/TypeScript/11BundleLoadingSample/types/routers/serializers/NotifySerializer.d.ts index 1d179b2..e92d6e1 100644 --- a/TypeScript/11BundleLoadingSample/types/routers/serializers/NotifySerializer.d.ts +++ b/TypeScript/11BundleLoadingSample/types/routers/serializers/NotifySerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { NotifierController } from "../../controllers/NotifierController"; import { Serializer } from "../../di/Serializer"; import { HttpServerHelper } from "../../helpers/HttpServerHelper"; diff --git a/TypeScript/11BundleLoadingSample/types/servers/HttpServer.d.ts b/TypeScript/11BundleLoadingSample/types/servers/HttpServer.d.ts index 97e0705..c73eb3c 100644 --- a/TypeScript/11BundleLoadingSample/types/servers/HttpServer.d.ts +++ b/TypeScript/11BundleLoadingSample/types/servers/HttpServer.d.ts @@ -1,5 +1,5 @@ /// -import http, { IncomingMessage, ServerResponse } from "http"; +import http, { IncomingMessage, ServerResponse } from "node:http"; import { ApplicationContext } from "../context/ApplicationContext"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; import { IHttpConfig } from "../models/spt/config/IHttpConfig"; diff --git a/TypeScript/11BundleLoadingSample/types/servers/WebSocketServer.d.ts b/TypeScript/11BundleLoadingSample/types/servers/WebSocketServer.d.ts index fffbea2..b4c6158 100644 --- a/TypeScript/11BundleLoadingSample/types/servers/WebSocketServer.d.ts +++ b/TypeScript/11BundleLoadingSample/types/servers/WebSocketServer.d.ts @@ -1,5 +1,5 @@ /// -import http, { IncomingMessage } from "http"; +import http, { IncomingMessage } from "node:http"; import WebSocket from "ws"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; import { INotification } from "../models/eft/notifier/INotifier"; diff --git a/TypeScript/11BundleLoadingSample/types/servers/http/AkiHttpListener.d.ts b/TypeScript/11BundleLoadingSample/types/servers/http/AkiHttpListener.d.ts index c72e18f..e4ac80c 100644 --- a/TypeScript/11BundleLoadingSample/types/servers/http/AkiHttpListener.d.ts +++ b/TypeScript/11BundleLoadingSample/types/servers/http/AkiHttpListener.d.ts @@ -1,6 +1,6 @@ /// /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { ILogger } from "../../models/spt/utils/ILogger"; import { HttpRouter } from "../../routers/HttpRouter"; diff --git a/TypeScript/11BundleLoadingSample/types/servers/http/IHttpListener.d.ts b/TypeScript/11BundleLoadingSample/types/servers/http/IHttpListener.d.ts index 758bb5a..29d5fce 100644 --- a/TypeScript/11BundleLoadingSample/types/servers/http/IHttpListener.d.ts +++ b/TypeScript/11BundleLoadingSample/types/servers/http/IHttpListener.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export interface IHttpListener { canHandle(sessionId: string, req: IncomingMessage): boolean; handle(sessionId: string, req: IncomingMessage, resp: ServerResponse): void; diff --git a/TypeScript/11BundleLoadingSample/types/services/mod/httpListener/HttpListenerMod.d.ts b/TypeScript/11BundleLoadingSample/types/services/mod/httpListener/HttpListenerMod.d.ts index 2cdfbda..afe4574 100644 --- a/TypeScript/11BundleLoadingSample/types/services/mod/httpListener/HttpListenerMod.d.ts +++ b/TypeScript/11BundleLoadingSample/types/services/mod/httpListener/HttpListenerMod.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { IHttpListener } from "../../../servers/http/IHttpListener"; export declare class HttpListenerMod implements IHttpListener { private canHandleOverride; diff --git a/TypeScript/11BundleLoadingSample/types/services/mod/httpListener/HttpListenerModService.d.ts b/TypeScript/11BundleLoadingSample/types/services/mod/httpListener/HttpListenerModService.d.ts index 9dd3473..23abfbe 100644 --- a/TypeScript/11BundleLoadingSample/types/services/mod/httpListener/HttpListenerModService.d.ts +++ b/TypeScript/11BundleLoadingSample/types/services/mod/httpListener/HttpListenerModService.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { DependencyContainer } from "tsyringe"; export declare class HttpListenerModService { protected container: DependencyContainer; diff --git a/TypeScript/11BundleLoadingSample/types/utils/App.d.ts b/TypeScript/11BundleLoadingSample/types/utils/App.d.ts index dd8f24c..5e759ad 100644 --- a/TypeScript/11BundleLoadingSample/types/utils/App.d.ts +++ b/TypeScript/11BundleLoadingSample/types/utils/App.d.ts @@ -12,7 +12,6 @@ export declare class App { protected onLoadComponents: OnLoad[]; protected onUpdateComponents: OnUpdate[]; protected onUpdateLastRun: {}; - protected os: any; constructor(logger: ILogger, timeUtil: TimeUtil, localisationService: LocalisationService, encodingUtil: EncodingUtil, onLoadComponents: OnLoad[], onUpdateComponents: OnUpdate[]); load(): Promise; protected update(onUpdateComponents: OnUpdate[]): Promise; diff --git a/TypeScript/11BundleLoadingSample/types/utils/HashUtil.d.ts b/TypeScript/11BundleLoadingSample/types/utils/HashUtil.d.ts index c017ca8..27204cb 100644 --- a/TypeScript/11BundleLoadingSample/types/utils/HashUtil.d.ts +++ b/TypeScript/11BundleLoadingSample/types/utils/HashUtil.d.ts @@ -1,5 +1,5 @@ /// -import crypto from "crypto"; +import crypto from "node:crypto"; import { TimeUtil } from "./TimeUtil"; export declare class HashUtil { protected timeUtil: TimeUtil; diff --git a/TypeScript/11BundleLoadingSample/types/utils/HttpFileUtil.d.ts b/TypeScript/11BundleLoadingSample/types/utils/HttpFileUtil.d.ts index afc8409..6a386ce 100644 --- a/TypeScript/11BundleLoadingSample/types/utils/HttpFileUtil.d.ts +++ b/TypeScript/11BundleLoadingSample/types/utils/HttpFileUtil.d.ts @@ -1,5 +1,5 @@ /// -import { ServerResponse } from "http"; +import { ServerResponse } from "node:http"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; export declare class HttpFileUtil { protected httpServerHelper: HttpServerHelper; diff --git a/TypeScript/11BundleLoadingSample/types/utils/VFS.d.ts b/TypeScript/11BundleLoadingSample/types/utils/VFS.d.ts index 2cb09fa..3911c4b 100644 --- a/TypeScript/11BundleLoadingSample/types/utils/VFS.d.ts +++ b/TypeScript/11BundleLoadingSample/types/utils/VFS.d.ts @@ -1,6 +1,6 @@ /// /// -import fs from "fs"; +import fs from "node:fs"; import "reflect-metadata"; import { IAsyncQueue } from "../models/spt/utils/IAsyncQueue"; import { IUUidGenerator } from "../models/spt/utils/IUuidGenerator"; diff --git a/TypeScript/11BundleLoadingSample/types/utils/Watermark.d.ts b/TypeScript/11BundleLoadingSample/types/utils/Watermark.d.ts index fa63205..864e9b6 100644 --- a/TypeScript/11BundleLoadingSample/types/utils/Watermark.d.ts +++ b/TypeScript/11BundleLoadingSample/types/utils/Watermark.d.ts @@ -4,12 +4,10 @@ import { ConfigServer } from "../servers/ConfigServer"; import { LocalisationService } from "../services/LocalisationService"; export declare class WatermarkLocale { protected localisationService: LocalisationService; + protected description: string[]; + protected warning: string[]; + protected modding: string[]; constructor(localisationService: LocalisationService); - protected watermark: { - description: string[]; - warning: string[]; - modding: string[]; - }; getDescription(): string[]; getWarning(): string[]; getModding(): string[]; diff --git a/TypeScript/11BundleLoadingSample/types/utils/logging/AbstractWinstonLogger.d.ts b/TypeScript/11BundleLoadingSample/types/utils/logging/AbstractWinstonLogger.d.ts index 1ae1100..74767a2 100644 --- a/TypeScript/11BundleLoadingSample/types/utils/logging/AbstractWinstonLogger.d.ts +++ b/TypeScript/11BundleLoadingSample/types/utils/logging/AbstractWinstonLogger.d.ts @@ -1,5 +1,5 @@ /// -import fs from "fs"; +import fs from "node:fs"; import winston from "winston"; import { Daum } from "../../models/eft/itemEvent/IItemEventRouterRequest"; import { LogBackgroundColor } from "../../models/spt/logging/LogBackgroundColor"; diff --git a/TypeScript/12ClassExtensionOverride/types/controllers/GameController.d.ts b/TypeScript/12ClassExtensionOverride/types/controllers/GameController.d.ts index 73596ff..74123b2 100644 --- a/TypeScript/12ClassExtensionOverride/types/controllers/GameController.d.ts +++ b/TypeScript/12ClassExtensionOverride/types/controllers/GameController.d.ts @@ -49,7 +49,6 @@ export declare class GameController { protected giftService: GiftService; protected applicationContext: ApplicationContext; protected configServer: ConfigServer; - protected os: any; protected httpConfig: IHttpConfig; protected coreConfig: ICoreConfig; protected locationConfig: ILocationConfig; diff --git a/TypeScript/12ClassExtensionOverride/types/controllers/InsuranceController.d.ts b/TypeScript/12ClassExtensionOverride/types/controllers/InsuranceController.d.ts index fb41610..fc3229b 100644 --- a/TypeScript/12ClassExtensionOverride/types/controllers/InsuranceController.d.ts +++ b/TypeScript/12ClassExtensionOverride/types/controllers/InsuranceController.d.ts @@ -4,7 +4,6 @@ import { ProfileHelper } from "../helpers/ProfileHelper"; import { TraderHelper } from "../helpers/TraderHelper"; import { IPmcData } from "../models/eft/common/IPmcData"; import { Item } from "../models/eft/common/tables/IItem"; -import { ITemplateItem } from "../models/eft/common/tables/ITemplateItem"; import { IGetInsuranceCostRequestData } from "../models/eft/insurance/IGetInsuranceCostRequestData"; import { IGetInsuranceCostResponseData } from "../models/eft/insurance/IGetInsuranceCostResponseData"; import { IInsureRequestData } from "../models/eft/insurance/IInsureRequestData"; @@ -75,67 +74,92 @@ export declare class InsuranceController { */ protected removeInsurancePackageFromProfile(sessionID: string, packageInfo: ISystemData): void; /** - * Build an array of items to delete from the insured items. + * Finds the items that should be deleted based on the given Insurance object. * - * This method orchestrates several steps: - * - Filters items based on their presence in the database and their raid moddability. - * - Sorts base and independent child items to consider for deletion. - * - Groups child items by their parent for later evaluation. - * - Evaluates grouped child items to decide which should be deleted, based on their value and a random roll. - * - * @param insured - The insured items to build a removal array from. - * @returns An array of IDs representing items that should be deleted. + * @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(insured: Insurance): Set; /** - * Filters an item based on its existence in the database, raid moddability, and slot requirements. + * Populate a Map object of items for quick lookup by their ID. * - * @param item The item to be filtered. - * @param parentItemDbDetails The database details of the parent item, or null if the item has no parent. - * @param itemDbDetails A tuple where the first element is a boolean indicating if the item exists in the database, - * and the second element is the item details if it does. - * @returns true if the item exists in the database and neither of the following conditions are met: - * - The item has the RaidModdable property set to false. - * - The item is attached to a required slot in its parent item. - * Otherwise, returns false. + * @param insured The insurance object containing the items to populate the map with. + * @returns A Map where the keys are the item IDs and the values are the corresponding Item objects. */ - protected filterByRaidModdability(item: Item, parentItemDbDetails: ITemplateItem | null, itemDbDetails: [boolean, ITemplateItem]): boolean; + protected populateItemsMap(insured: Insurance): Map; /** - * Determines if an item is either a base item or a child item that is not equipped to its parent. + * 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 item The item to check. - * @returns true if the item is a base or an independent child item, otherwise false. + * @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. */ - protected isBaseOrIndependentChild(item: Item): boolean; + protected populateParentAttachmentsMap(insured: Insurance, itemsMap: Map): Map; /** - * Makes a roll to determine if a given item should be deleted. If the roll is successful, the item's ID is added - * to the `toDelete` array. + * 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. * - * @param item The item for which the roll is made. - * @param traderId The ID of the trader to consider in the rollForItemDelete method. - * @param toDelete The array accumulating the IDs of items to be deleted. - * @returns true if the item is marked for deletion, otherwise false. - */ - protected makeRollAndMarkForDeletion(item: Item, traderId: string, toDelete: Set): boolean; - /** - * Groups child items by their parent IDs in a Map data structure. - * - * @param item The child item to be grouped by its parent. - * @param childrenGroupedByParent The Map that holds arrays of children items grouped by their parent IDs. + * @param insured The insurance object containing the items to evaluate. + * @param toDelete A Set to keep track of items marked for deletion. * @returns void */ - protected groupChildrenByParent(item: Item, childrenGroupedByParent: Map): void; + protected processRegularItems(insured: Insurance, toDelete: Set): void; /** - * Sorts the array of children items in descending order by their maximum price. For each child, a roll is made to - * determine if it should be deleted. The method then deletes the most valuable children based on the number of - * successful rolls made. + * Process parent items and their attachments, updating the toDelete Set accordingly. * - * @param children The array of children items to sort and filter. - * @param traderId The ID of the trader to consider in the rollForItemDelete method. + * This method iterates over a map of parent items to their attachments and performs evaluations on each. + * It marks items for deletion based on certain conditions and updates the toDelete Set accordingly. + * + * @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. + */ + protected processAttachments(mainParentToAttachmentsMap: Map, itemsMap: Map, traderId: string, toDelete: Set): void; + /** + * 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. + * + * @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. * @returns void */ - protected sortAndFilterChildren(children: Item[], traderId: string, toDelete: Set): void; + protected processAttachmentByParent(attachments: Item[], traderId: string, toDelete: Set): void; + /** + * Sorts the attachment items by their max price in descending order. + * + * @param attachments The array of attachments items. + * @returns An array of items enriched with their max price and common locale-name. + */ + protected sortAttachmentsByPrice(attachments: Item[]): EnrichedItem[]; + /** + * Logs the details of each attachment item. + * + * @param attachments The array of attachment items. + */ + protected logAttachmentsDetails(attachments: EnrichedItem[]): void; + /** + * Counts the number of successful rolls for the attachment items. + * + * @param attachments The array of attachment items. + * @param traderId The ID of the trader that has insured these attachments. + * @returns The number of successful rolls. + */ + protected countSuccessfulRolls(attachments: Item[], traderId: string): number; + /** + * Marks the most valuable attachments for deletion based on the number of successful rolls made. + * + * @param attachments The array of attachment items. + * @param successfulRolls The number of successful rolls. + * @param toDelete The array that accumulates the IDs of the items to be deleted. + */ + protected attachmentDeletionByValue(attachments: EnrichedItem[], successfulRolls: number, toDelete: Set): void; /** * Remove items from the insured items that should not be returned to the player. * @@ -144,6 +168,22 @@ export declare class InsuranceController { * @returns void */ protected removeItemsFromInsurance(insured: Insurance, toDelete: Set): void; + /** + * Adopts orphaned items by resetting them as base-level items. Helpful in situations where a parent has been + * deleted from insurance, but any insured items within the parent should remain. This method will remove the + * reference from the children to the parent and set item properties to main-level values. + * + * @param insured Insurance object containing items. + */ + protected adoptOrphanedItems(insured: Insurance): void; + /** + * Fetches the parentId property of an item with a slotId "hideout". Not sure if this is actually dynamic, but this + * method should be a reliable way to fetch it, if it ever does change. + * + * @param items Array of items to search through. + * @returns The parentId of an item with slotId 'hideout'. Empty string if not found. + */ + protected fetchHideoutItemParent(items: Item[]): string; /** * Handle sending the insurance message to the user that potentially contains the valid insurance items. * @@ -154,15 +194,14 @@ export declare class InsuranceController { */ protected sendMail(sessionID: string, insurance: Insurance, noItems: boolean): void; /** - * Determines whether a valid insured item should be removed from the player's inventory based on a random roll and + * Determines whether a insured item should be removed from the player's inventory based on a random roll and * trader-specific return chance. * - * @param insuredItem The insured item being evaluated for removal. * @param traderId The ID of the trader who insured the item. - * @param itemsBeingDeleted List of items that are already slated for removal. + * @param insuredItem Optional. The item to roll for. Only used for logging. * @returns true if the insured item should be removed from inventory, false otherwise. */ - protected rollForItemDelete(insuredItem: Item, traderId: string, itemsBeingDeleted: Set): boolean; + protected rollForDelete(traderId: string, insuredItem?: Item): boolean; /** * Handle Insure event * Add insurance to an item @@ -183,3 +222,8 @@ export declare class InsuranceController { */ cost(request: IGetInsuranceCostRequestData, sessionID: string): IGetInsuranceCostResponseData; } +interface EnrichedItem extends Item { + name: string; + maxPrice: number; +} +export {}; diff --git a/TypeScript/12ClassExtensionOverride/types/di/Serializer.d.ts b/TypeScript/12ClassExtensionOverride/types/di/Serializer.d.ts index 2617007..b760b8b 100644 --- a/TypeScript/12ClassExtensionOverride/types/di/Serializer.d.ts +++ b/TypeScript/12ClassExtensionOverride/types/di/Serializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export declare class Serializer { serialize(sessionID: string, req: IncomingMessage, resp: ServerResponse, body: any): void; canHandle(something: string): boolean; diff --git a/TypeScript/12ClassExtensionOverride/types/helpers/ItemHelper.d.ts b/TypeScript/12ClassExtensionOverride/types/helpers/ItemHelper.d.ts index 6f1511c..5920d8a 100644 --- a/TypeScript/12ClassExtensionOverride/types/helpers/ItemHelper.d.ts +++ b/TypeScript/12ClassExtensionOverride/types/helpers/ItemHelper.d.ts @@ -225,6 +225,48 @@ declare class ItemHelper { * @returns true if item is flagged as quest item */ isQuestItem(tpl: string): boolean; + /** + * Checks to see if the item is *actually* moddable in-raid. Checks include the items existence in the database, the + * parent items existence in the database, the existence (and value) of the items RaidModdable property, and that + * the parents slot-required property exists, matches that of the item, and it's value. + * + * Note: this function does not preform any checks to see if the item and parent are *actually* related. + * + * @param item The item to be checked + * @param parent The parent of the item to be checked + * @returns True if the item is actually moddable, false if it is not, and null if the check cannot be performed. + */ + isRaidModdable(item: Item, parent: Item): boolean | null; + /** + * Retrieves the main parent item for a given attachment item. + * + * This method traverses up the hierarchy of items starting from a given `itemId`, until it finds the main parent + * item that is not an attached attachment itself. In other words, if you pass it an item id of a suppressor, it + * will traverse up the muzzle brake, barrel, upper receiver, and return the gun that the suppressor is ultimately + * attached to, even if that gun is located within multiple containers. + * + * It's important to note that traversal is expensive, so this method requires that you pass it a Map of the items + * to traverse, where the keys are the item IDs and the values are the corresponding Item objects. This alleviates + * some of the performance concerns, as it allows for quick lookups of items by ID. + * + * To generate the map: + * ``` + * const itemsMap = new Map(); + * items.forEach(item => itemsMap.set(item._id, item)); + * ``` + * + * @param itemId - The unique identifier of the item for which to find the main parent. + * @param itemsMap - A Map containing item IDs mapped to their corresponding Item objects for quick lookup. + * @returns The Item object representing the top-most parent of the given item, or `null` if no such parent exists. + */ + getAttachmentMainParent(itemId: string, itemsMap: Map): Item | null; + /** + * Determines if an item is an attachment that is currently attached to it's parent item. + * + * @param item The item to check. + * @returns true if the item is attached attachment, otherwise false. + */ + isAttachmentAttached(item: Item): boolean; /** * Get the inventory size of an item * @param items Item with children diff --git a/TypeScript/12ClassExtensionOverride/types/loaders/PreAkiModLoader.d.ts b/TypeScript/12ClassExtensionOverride/types/loaders/PreAkiModLoader.d.ts index 1e24b96..c0868b7 100644 --- a/TypeScript/12ClassExtensionOverride/types/loaders/PreAkiModLoader.d.ts +++ b/TypeScript/12ClassExtensionOverride/types/loaders/PreAkiModLoader.d.ts @@ -66,6 +66,10 @@ export declare class PreAkiModLoader implements IModLoader { protected isModCombatibleWithAki(mod: IPackageJsonData): boolean; protected executeMods(container: DependencyContainer): Promise; sortModsLoadOrder(): string[]; + /** + * Compile mod and add into class property "imported" + * @param mod Name of mod to compile/add + */ protected addMod(mod: string): Promise; protected autoInstallDependencies(modPath: string, pkg: IPackageJsonData): void; protected areModDependenciesFulfilled(pkg: IPackageJsonData, loadedMods: Record): boolean; diff --git a/TypeScript/12ClassExtensionOverride/types/models/external/HttpFramework.d.ts b/TypeScript/12ClassExtensionOverride/types/models/external/HttpFramework.d.ts index 64a37d6..fda8732 100644 --- a/TypeScript/12ClassExtensionOverride/types/models/external/HttpFramework.d.ts +++ b/TypeScript/12ClassExtensionOverride/types/models/external/HttpFramework.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export type HandleFn = (_: string, req: IncomingMessage, resp: ServerResponse) => void; /** * Associates handlers, HTTP methods and a base url to a listener using a proxy diff --git a/TypeScript/12ClassExtensionOverride/types/models/spt/mod/IPackageJsonData.d.ts b/TypeScript/12ClassExtensionOverride/types/models/spt/mod/IPackageJsonData.d.ts index 06f7454..f58d7cc 100644 --- a/TypeScript/12ClassExtensionOverride/types/models/spt/mod/IPackageJsonData.d.ts +++ b/TypeScript/12ClassExtensionOverride/types/models/spt/mod/IPackageJsonData.d.ts @@ -6,6 +6,9 @@ export interface IPackageJsonData { author: string; version: string; akiVersion: string; + /** We deliberately purge this data */ + scripts: Record; + devDependencies: Record; licence: string; main: string; isBundleMod: boolean; diff --git a/TypeScript/12ClassExtensionOverride/types/routers/HttpRouter.d.ts b/TypeScript/12ClassExtensionOverride/types/routers/HttpRouter.d.ts index f75a47d..46f847a 100644 --- a/TypeScript/12ClassExtensionOverride/types/routers/HttpRouter.d.ts +++ b/TypeScript/12ClassExtensionOverride/types/routers/HttpRouter.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage } from "http"; +import { IncomingMessage } from "node:http"; import { DynamicRouter, Router, StaticRouter } from "../di/Router"; export declare class HttpRouter { protected staticRouters: StaticRouter[]; diff --git a/TypeScript/12ClassExtensionOverride/types/routers/ImageRouter.d.ts b/TypeScript/12ClassExtensionOverride/types/routers/ImageRouter.d.ts index 675441c..fd03c59 100644 --- a/TypeScript/12ClassExtensionOverride/types/routers/ImageRouter.d.ts +++ b/TypeScript/12ClassExtensionOverride/types/routers/ImageRouter.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { ImageRouteService } from "../services/mod/image/ImageRouteService"; import { HttpFileUtil } from "../utils/HttpFileUtil"; import { VFS } from "../utils/VFS"; diff --git a/TypeScript/12ClassExtensionOverride/types/routers/serializers/BundleSerializer.d.ts b/TypeScript/12ClassExtensionOverride/types/routers/serializers/BundleSerializer.d.ts index ca4d8b6..db41142 100644 --- a/TypeScript/12ClassExtensionOverride/types/routers/serializers/BundleSerializer.d.ts +++ b/TypeScript/12ClassExtensionOverride/types/routers/serializers/BundleSerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { BundleLoader } from "../../loaders/BundleLoader"; import { ILogger } from "../../models/spt/utils/ILogger"; diff --git a/TypeScript/12ClassExtensionOverride/types/routers/serializers/ImageSerializer.d.ts b/TypeScript/12ClassExtensionOverride/types/routers/serializers/ImageSerializer.d.ts index 5de48ff..62ce84d 100644 --- a/TypeScript/12ClassExtensionOverride/types/routers/serializers/ImageSerializer.d.ts +++ b/TypeScript/12ClassExtensionOverride/types/routers/serializers/ImageSerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { ImageRouter } from "../ImageRouter"; export declare class ImageSerializer extends Serializer { diff --git a/TypeScript/12ClassExtensionOverride/types/routers/serializers/NotifySerializer.d.ts b/TypeScript/12ClassExtensionOverride/types/routers/serializers/NotifySerializer.d.ts index 1d179b2..e92d6e1 100644 --- a/TypeScript/12ClassExtensionOverride/types/routers/serializers/NotifySerializer.d.ts +++ b/TypeScript/12ClassExtensionOverride/types/routers/serializers/NotifySerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { NotifierController } from "../../controllers/NotifierController"; import { Serializer } from "../../di/Serializer"; import { HttpServerHelper } from "../../helpers/HttpServerHelper"; diff --git a/TypeScript/12ClassExtensionOverride/types/servers/HttpServer.d.ts b/TypeScript/12ClassExtensionOverride/types/servers/HttpServer.d.ts index 97e0705..c73eb3c 100644 --- a/TypeScript/12ClassExtensionOverride/types/servers/HttpServer.d.ts +++ b/TypeScript/12ClassExtensionOverride/types/servers/HttpServer.d.ts @@ -1,5 +1,5 @@ /// -import http, { IncomingMessage, ServerResponse } from "http"; +import http, { IncomingMessage, ServerResponse } from "node:http"; import { ApplicationContext } from "../context/ApplicationContext"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; import { IHttpConfig } from "../models/spt/config/IHttpConfig"; diff --git a/TypeScript/12ClassExtensionOverride/types/servers/WebSocketServer.d.ts b/TypeScript/12ClassExtensionOverride/types/servers/WebSocketServer.d.ts index fffbea2..b4c6158 100644 --- a/TypeScript/12ClassExtensionOverride/types/servers/WebSocketServer.d.ts +++ b/TypeScript/12ClassExtensionOverride/types/servers/WebSocketServer.d.ts @@ -1,5 +1,5 @@ /// -import http, { IncomingMessage } from "http"; +import http, { IncomingMessage } from "node:http"; import WebSocket from "ws"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; import { INotification } from "../models/eft/notifier/INotifier"; diff --git a/TypeScript/12ClassExtensionOverride/types/servers/http/AkiHttpListener.d.ts b/TypeScript/12ClassExtensionOverride/types/servers/http/AkiHttpListener.d.ts index c72e18f..e4ac80c 100644 --- a/TypeScript/12ClassExtensionOverride/types/servers/http/AkiHttpListener.d.ts +++ b/TypeScript/12ClassExtensionOverride/types/servers/http/AkiHttpListener.d.ts @@ -1,6 +1,6 @@ /// /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { ILogger } from "../../models/spt/utils/ILogger"; import { HttpRouter } from "../../routers/HttpRouter"; diff --git a/TypeScript/12ClassExtensionOverride/types/servers/http/IHttpListener.d.ts b/TypeScript/12ClassExtensionOverride/types/servers/http/IHttpListener.d.ts index 758bb5a..29d5fce 100644 --- a/TypeScript/12ClassExtensionOverride/types/servers/http/IHttpListener.d.ts +++ b/TypeScript/12ClassExtensionOverride/types/servers/http/IHttpListener.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export interface IHttpListener { canHandle(sessionId: string, req: IncomingMessage): boolean; handle(sessionId: string, req: IncomingMessage, resp: ServerResponse): void; diff --git a/TypeScript/12ClassExtensionOverride/types/services/mod/httpListener/HttpListenerMod.d.ts b/TypeScript/12ClassExtensionOverride/types/services/mod/httpListener/HttpListenerMod.d.ts index 2cdfbda..afe4574 100644 --- a/TypeScript/12ClassExtensionOverride/types/services/mod/httpListener/HttpListenerMod.d.ts +++ b/TypeScript/12ClassExtensionOverride/types/services/mod/httpListener/HttpListenerMod.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { IHttpListener } from "../../../servers/http/IHttpListener"; export declare class HttpListenerMod implements IHttpListener { private canHandleOverride; diff --git a/TypeScript/12ClassExtensionOverride/types/services/mod/httpListener/HttpListenerModService.d.ts b/TypeScript/12ClassExtensionOverride/types/services/mod/httpListener/HttpListenerModService.d.ts index 9dd3473..23abfbe 100644 --- a/TypeScript/12ClassExtensionOverride/types/services/mod/httpListener/HttpListenerModService.d.ts +++ b/TypeScript/12ClassExtensionOverride/types/services/mod/httpListener/HttpListenerModService.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { DependencyContainer } from "tsyringe"; export declare class HttpListenerModService { protected container: DependencyContainer; diff --git a/TypeScript/12ClassExtensionOverride/types/utils/App.d.ts b/TypeScript/12ClassExtensionOverride/types/utils/App.d.ts index dd8f24c..5e759ad 100644 --- a/TypeScript/12ClassExtensionOverride/types/utils/App.d.ts +++ b/TypeScript/12ClassExtensionOverride/types/utils/App.d.ts @@ -12,7 +12,6 @@ export declare class App { protected onLoadComponents: OnLoad[]; protected onUpdateComponents: OnUpdate[]; protected onUpdateLastRun: {}; - protected os: any; constructor(logger: ILogger, timeUtil: TimeUtil, localisationService: LocalisationService, encodingUtil: EncodingUtil, onLoadComponents: OnLoad[], onUpdateComponents: OnUpdate[]); load(): Promise; protected update(onUpdateComponents: OnUpdate[]): Promise; diff --git a/TypeScript/12ClassExtensionOverride/types/utils/HashUtil.d.ts b/TypeScript/12ClassExtensionOverride/types/utils/HashUtil.d.ts index c017ca8..27204cb 100644 --- a/TypeScript/12ClassExtensionOverride/types/utils/HashUtil.d.ts +++ b/TypeScript/12ClassExtensionOverride/types/utils/HashUtil.d.ts @@ -1,5 +1,5 @@ /// -import crypto from "crypto"; +import crypto from "node:crypto"; import { TimeUtil } from "./TimeUtil"; export declare class HashUtil { protected timeUtil: TimeUtil; diff --git a/TypeScript/12ClassExtensionOverride/types/utils/HttpFileUtil.d.ts b/TypeScript/12ClassExtensionOverride/types/utils/HttpFileUtil.d.ts index afc8409..6a386ce 100644 --- a/TypeScript/12ClassExtensionOverride/types/utils/HttpFileUtil.d.ts +++ b/TypeScript/12ClassExtensionOverride/types/utils/HttpFileUtil.d.ts @@ -1,5 +1,5 @@ /// -import { ServerResponse } from "http"; +import { ServerResponse } from "node:http"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; export declare class HttpFileUtil { protected httpServerHelper: HttpServerHelper; diff --git a/TypeScript/12ClassExtensionOverride/types/utils/VFS.d.ts b/TypeScript/12ClassExtensionOverride/types/utils/VFS.d.ts index 2cb09fa..3911c4b 100644 --- a/TypeScript/12ClassExtensionOverride/types/utils/VFS.d.ts +++ b/TypeScript/12ClassExtensionOverride/types/utils/VFS.d.ts @@ -1,6 +1,6 @@ /// /// -import fs from "fs"; +import fs from "node:fs"; import "reflect-metadata"; import { IAsyncQueue } from "../models/spt/utils/IAsyncQueue"; import { IUUidGenerator } from "../models/spt/utils/IUuidGenerator"; diff --git a/TypeScript/12ClassExtensionOverride/types/utils/Watermark.d.ts b/TypeScript/12ClassExtensionOverride/types/utils/Watermark.d.ts index fa63205..864e9b6 100644 --- a/TypeScript/12ClassExtensionOverride/types/utils/Watermark.d.ts +++ b/TypeScript/12ClassExtensionOverride/types/utils/Watermark.d.ts @@ -4,12 +4,10 @@ import { ConfigServer } from "../servers/ConfigServer"; import { LocalisationService } from "../services/LocalisationService"; export declare class WatermarkLocale { protected localisationService: LocalisationService; + protected description: string[]; + protected warning: string[]; + protected modding: string[]; constructor(localisationService: LocalisationService); - protected watermark: { - description: string[]; - warning: string[]; - modding: string[]; - }; getDescription(): string[]; getWarning(): string[]; getModding(): string[]; diff --git a/TypeScript/12ClassExtensionOverride/types/utils/logging/AbstractWinstonLogger.d.ts b/TypeScript/12ClassExtensionOverride/types/utils/logging/AbstractWinstonLogger.d.ts index 1ae1100..74767a2 100644 --- a/TypeScript/12ClassExtensionOverride/types/utils/logging/AbstractWinstonLogger.d.ts +++ b/TypeScript/12ClassExtensionOverride/types/utils/logging/AbstractWinstonLogger.d.ts @@ -1,5 +1,5 @@ /// -import fs from "fs"; +import fs from "node:fs"; import winston from "winston"; import { Daum } from "../../models/eft/itemEvent/IItemEventRouterRequest"; import { LogBackgroundColor } from "../../models/spt/logging/LogBackgroundColor"; diff --git a/TypeScript/13AddTrader/types/controllers/GameController.d.ts b/TypeScript/13AddTrader/types/controllers/GameController.d.ts index 73596ff..74123b2 100644 --- a/TypeScript/13AddTrader/types/controllers/GameController.d.ts +++ b/TypeScript/13AddTrader/types/controllers/GameController.d.ts @@ -49,7 +49,6 @@ export declare class GameController { protected giftService: GiftService; protected applicationContext: ApplicationContext; protected configServer: ConfigServer; - protected os: any; protected httpConfig: IHttpConfig; protected coreConfig: ICoreConfig; protected locationConfig: ILocationConfig; diff --git a/TypeScript/13AddTrader/types/controllers/InsuranceController.d.ts b/TypeScript/13AddTrader/types/controllers/InsuranceController.d.ts index fb41610..fc3229b 100644 --- a/TypeScript/13AddTrader/types/controllers/InsuranceController.d.ts +++ b/TypeScript/13AddTrader/types/controllers/InsuranceController.d.ts @@ -4,7 +4,6 @@ import { ProfileHelper } from "../helpers/ProfileHelper"; import { TraderHelper } from "../helpers/TraderHelper"; import { IPmcData } from "../models/eft/common/IPmcData"; import { Item } from "../models/eft/common/tables/IItem"; -import { ITemplateItem } from "../models/eft/common/tables/ITemplateItem"; import { IGetInsuranceCostRequestData } from "../models/eft/insurance/IGetInsuranceCostRequestData"; import { IGetInsuranceCostResponseData } from "../models/eft/insurance/IGetInsuranceCostResponseData"; import { IInsureRequestData } from "../models/eft/insurance/IInsureRequestData"; @@ -75,67 +74,92 @@ export declare class InsuranceController { */ protected removeInsurancePackageFromProfile(sessionID: string, packageInfo: ISystemData): void; /** - * Build an array of items to delete from the insured items. + * Finds the items that should be deleted based on the given Insurance object. * - * This method orchestrates several steps: - * - Filters items based on their presence in the database and their raid moddability. - * - Sorts base and independent child items to consider for deletion. - * - Groups child items by their parent for later evaluation. - * - Evaluates grouped child items to decide which should be deleted, based on their value and a random roll. - * - * @param insured - The insured items to build a removal array from. - * @returns An array of IDs representing items that should be deleted. + * @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(insured: Insurance): Set; /** - * Filters an item based on its existence in the database, raid moddability, and slot requirements. + * Populate a Map object of items for quick lookup by their ID. * - * @param item The item to be filtered. - * @param parentItemDbDetails The database details of the parent item, or null if the item has no parent. - * @param itemDbDetails A tuple where the first element is a boolean indicating if the item exists in the database, - * and the second element is the item details if it does. - * @returns true if the item exists in the database and neither of the following conditions are met: - * - The item has the RaidModdable property set to false. - * - The item is attached to a required slot in its parent item. - * Otherwise, returns false. + * @param insured The insurance object containing the items to populate the map with. + * @returns A Map where the keys are the item IDs and the values are the corresponding Item objects. */ - protected filterByRaidModdability(item: Item, parentItemDbDetails: ITemplateItem | null, itemDbDetails: [boolean, ITemplateItem]): boolean; + protected populateItemsMap(insured: Insurance): Map; /** - * Determines if an item is either a base item or a child item that is not equipped to its parent. + * 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 item The item to check. - * @returns true if the item is a base or an independent child item, otherwise false. + * @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. */ - protected isBaseOrIndependentChild(item: Item): boolean; + protected populateParentAttachmentsMap(insured: Insurance, itemsMap: Map): Map; /** - * Makes a roll to determine if a given item should be deleted. If the roll is successful, the item's ID is added - * to the `toDelete` array. + * 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. * - * @param item The item for which the roll is made. - * @param traderId The ID of the trader to consider in the rollForItemDelete method. - * @param toDelete The array accumulating the IDs of items to be deleted. - * @returns true if the item is marked for deletion, otherwise false. - */ - protected makeRollAndMarkForDeletion(item: Item, traderId: string, toDelete: Set): boolean; - /** - * Groups child items by their parent IDs in a Map data structure. - * - * @param item The child item to be grouped by its parent. - * @param childrenGroupedByParent The Map that holds arrays of children items grouped by their parent IDs. + * @param insured The insurance object containing the items to evaluate. + * @param toDelete A Set to keep track of items marked for deletion. * @returns void */ - protected groupChildrenByParent(item: Item, childrenGroupedByParent: Map): void; + protected processRegularItems(insured: Insurance, toDelete: Set): void; /** - * Sorts the array of children items in descending order by their maximum price. For each child, a roll is made to - * determine if it should be deleted. The method then deletes the most valuable children based on the number of - * successful rolls made. + * Process parent items and their attachments, updating the toDelete Set accordingly. * - * @param children The array of children items to sort and filter. - * @param traderId The ID of the trader to consider in the rollForItemDelete method. + * This method iterates over a map of parent items to their attachments and performs evaluations on each. + * It marks items for deletion based on certain conditions and updates the toDelete Set accordingly. + * + * @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. + */ + protected processAttachments(mainParentToAttachmentsMap: Map, itemsMap: Map, traderId: string, toDelete: Set): void; + /** + * 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. + * + * @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. * @returns void */ - protected sortAndFilterChildren(children: Item[], traderId: string, toDelete: Set): void; + protected processAttachmentByParent(attachments: Item[], traderId: string, toDelete: Set): void; + /** + * Sorts the attachment items by their max price in descending order. + * + * @param attachments The array of attachments items. + * @returns An array of items enriched with their max price and common locale-name. + */ + protected sortAttachmentsByPrice(attachments: Item[]): EnrichedItem[]; + /** + * Logs the details of each attachment item. + * + * @param attachments The array of attachment items. + */ + protected logAttachmentsDetails(attachments: EnrichedItem[]): void; + /** + * Counts the number of successful rolls for the attachment items. + * + * @param attachments The array of attachment items. + * @param traderId The ID of the trader that has insured these attachments. + * @returns The number of successful rolls. + */ + protected countSuccessfulRolls(attachments: Item[], traderId: string): number; + /** + * Marks the most valuable attachments for deletion based on the number of successful rolls made. + * + * @param attachments The array of attachment items. + * @param successfulRolls The number of successful rolls. + * @param toDelete The array that accumulates the IDs of the items to be deleted. + */ + protected attachmentDeletionByValue(attachments: EnrichedItem[], successfulRolls: number, toDelete: Set): void; /** * Remove items from the insured items that should not be returned to the player. * @@ -144,6 +168,22 @@ export declare class InsuranceController { * @returns void */ protected removeItemsFromInsurance(insured: Insurance, toDelete: Set): void; + /** + * Adopts orphaned items by resetting them as base-level items. Helpful in situations where a parent has been + * deleted from insurance, but any insured items within the parent should remain. This method will remove the + * reference from the children to the parent and set item properties to main-level values. + * + * @param insured Insurance object containing items. + */ + protected adoptOrphanedItems(insured: Insurance): void; + /** + * Fetches the parentId property of an item with a slotId "hideout". Not sure if this is actually dynamic, but this + * method should be a reliable way to fetch it, if it ever does change. + * + * @param items Array of items to search through. + * @returns The parentId of an item with slotId 'hideout'. Empty string if not found. + */ + protected fetchHideoutItemParent(items: Item[]): string; /** * Handle sending the insurance message to the user that potentially contains the valid insurance items. * @@ -154,15 +194,14 @@ export declare class InsuranceController { */ protected sendMail(sessionID: string, insurance: Insurance, noItems: boolean): void; /** - * Determines whether a valid insured item should be removed from the player's inventory based on a random roll and + * Determines whether a insured item should be removed from the player's inventory based on a random roll and * trader-specific return chance. * - * @param insuredItem The insured item being evaluated for removal. * @param traderId The ID of the trader who insured the item. - * @param itemsBeingDeleted List of items that are already slated for removal. + * @param insuredItem Optional. The item to roll for. Only used for logging. * @returns true if the insured item should be removed from inventory, false otherwise. */ - protected rollForItemDelete(insuredItem: Item, traderId: string, itemsBeingDeleted: Set): boolean; + protected rollForDelete(traderId: string, insuredItem?: Item): boolean; /** * Handle Insure event * Add insurance to an item @@ -183,3 +222,8 @@ export declare class InsuranceController { */ cost(request: IGetInsuranceCostRequestData, sessionID: string): IGetInsuranceCostResponseData; } +interface EnrichedItem extends Item { + name: string; + maxPrice: number; +} +export {}; diff --git a/TypeScript/13AddTrader/types/di/Serializer.d.ts b/TypeScript/13AddTrader/types/di/Serializer.d.ts index 2617007..b760b8b 100644 --- a/TypeScript/13AddTrader/types/di/Serializer.d.ts +++ b/TypeScript/13AddTrader/types/di/Serializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export declare class Serializer { serialize(sessionID: string, req: IncomingMessage, resp: ServerResponse, body: any): void; canHandle(something: string): boolean; diff --git a/TypeScript/13AddTrader/types/helpers/ItemHelper.d.ts b/TypeScript/13AddTrader/types/helpers/ItemHelper.d.ts index 6f1511c..5920d8a 100644 --- a/TypeScript/13AddTrader/types/helpers/ItemHelper.d.ts +++ b/TypeScript/13AddTrader/types/helpers/ItemHelper.d.ts @@ -225,6 +225,48 @@ declare class ItemHelper { * @returns true if item is flagged as quest item */ isQuestItem(tpl: string): boolean; + /** + * Checks to see if the item is *actually* moddable in-raid. Checks include the items existence in the database, the + * parent items existence in the database, the existence (and value) of the items RaidModdable property, and that + * the parents slot-required property exists, matches that of the item, and it's value. + * + * Note: this function does not preform any checks to see if the item and parent are *actually* related. + * + * @param item The item to be checked + * @param parent The parent of the item to be checked + * @returns True if the item is actually moddable, false if it is not, and null if the check cannot be performed. + */ + isRaidModdable(item: Item, parent: Item): boolean | null; + /** + * Retrieves the main parent item for a given attachment item. + * + * This method traverses up the hierarchy of items starting from a given `itemId`, until it finds the main parent + * item that is not an attached attachment itself. In other words, if you pass it an item id of a suppressor, it + * will traverse up the muzzle brake, barrel, upper receiver, and return the gun that the suppressor is ultimately + * attached to, even if that gun is located within multiple containers. + * + * It's important to note that traversal is expensive, so this method requires that you pass it a Map of the items + * to traverse, where the keys are the item IDs and the values are the corresponding Item objects. This alleviates + * some of the performance concerns, as it allows for quick lookups of items by ID. + * + * To generate the map: + * ``` + * const itemsMap = new Map(); + * items.forEach(item => itemsMap.set(item._id, item)); + * ``` + * + * @param itemId - The unique identifier of the item for which to find the main parent. + * @param itemsMap - A Map containing item IDs mapped to their corresponding Item objects for quick lookup. + * @returns The Item object representing the top-most parent of the given item, or `null` if no such parent exists. + */ + getAttachmentMainParent(itemId: string, itemsMap: Map): Item | null; + /** + * Determines if an item is an attachment that is currently attached to it's parent item. + * + * @param item The item to check. + * @returns true if the item is attached attachment, otherwise false. + */ + isAttachmentAttached(item: Item): boolean; /** * Get the inventory size of an item * @param items Item with children diff --git a/TypeScript/13AddTrader/types/loaders/PreAkiModLoader.d.ts b/TypeScript/13AddTrader/types/loaders/PreAkiModLoader.d.ts index 1e24b96..c0868b7 100644 --- a/TypeScript/13AddTrader/types/loaders/PreAkiModLoader.d.ts +++ b/TypeScript/13AddTrader/types/loaders/PreAkiModLoader.d.ts @@ -66,6 +66,10 @@ export declare class PreAkiModLoader implements IModLoader { protected isModCombatibleWithAki(mod: IPackageJsonData): boolean; protected executeMods(container: DependencyContainer): Promise; sortModsLoadOrder(): string[]; + /** + * Compile mod and add into class property "imported" + * @param mod Name of mod to compile/add + */ protected addMod(mod: string): Promise; protected autoInstallDependencies(modPath: string, pkg: IPackageJsonData): void; protected areModDependenciesFulfilled(pkg: IPackageJsonData, loadedMods: Record): boolean; diff --git a/TypeScript/13AddTrader/types/models/external/HttpFramework.d.ts b/TypeScript/13AddTrader/types/models/external/HttpFramework.d.ts index 64a37d6..fda8732 100644 --- a/TypeScript/13AddTrader/types/models/external/HttpFramework.d.ts +++ b/TypeScript/13AddTrader/types/models/external/HttpFramework.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export type HandleFn = (_: string, req: IncomingMessage, resp: ServerResponse) => void; /** * Associates handlers, HTTP methods and a base url to a listener using a proxy diff --git a/TypeScript/13AddTrader/types/models/spt/mod/IPackageJsonData.d.ts b/TypeScript/13AddTrader/types/models/spt/mod/IPackageJsonData.d.ts index 06f7454..f58d7cc 100644 --- a/TypeScript/13AddTrader/types/models/spt/mod/IPackageJsonData.d.ts +++ b/TypeScript/13AddTrader/types/models/spt/mod/IPackageJsonData.d.ts @@ -6,6 +6,9 @@ export interface IPackageJsonData { author: string; version: string; akiVersion: string; + /** We deliberately purge this data */ + scripts: Record; + devDependencies: Record; licence: string; main: string; isBundleMod: boolean; diff --git a/TypeScript/13AddTrader/types/routers/HttpRouter.d.ts b/TypeScript/13AddTrader/types/routers/HttpRouter.d.ts index f75a47d..46f847a 100644 --- a/TypeScript/13AddTrader/types/routers/HttpRouter.d.ts +++ b/TypeScript/13AddTrader/types/routers/HttpRouter.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage } from "http"; +import { IncomingMessage } from "node:http"; import { DynamicRouter, Router, StaticRouter } from "../di/Router"; export declare class HttpRouter { protected staticRouters: StaticRouter[]; diff --git a/TypeScript/13AddTrader/types/routers/ImageRouter.d.ts b/TypeScript/13AddTrader/types/routers/ImageRouter.d.ts index 675441c..fd03c59 100644 --- a/TypeScript/13AddTrader/types/routers/ImageRouter.d.ts +++ b/TypeScript/13AddTrader/types/routers/ImageRouter.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { ImageRouteService } from "../services/mod/image/ImageRouteService"; import { HttpFileUtil } from "../utils/HttpFileUtil"; import { VFS } from "../utils/VFS"; diff --git a/TypeScript/13AddTrader/types/routers/serializers/BundleSerializer.d.ts b/TypeScript/13AddTrader/types/routers/serializers/BundleSerializer.d.ts index ca4d8b6..db41142 100644 --- a/TypeScript/13AddTrader/types/routers/serializers/BundleSerializer.d.ts +++ b/TypeScript/13AddTrader/types/routers/serializers/BundleSerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { BundleLoader } from "../../loaders/BundleLoader"; import { ILogger } from "../../models/spt/utils/ILogger"; diff --git a/TypeScript/13AddTrader/types/routers/serializers/ImageSerializer.d.ts b/TypeScript/13AddTrader/types/routers/serializers/ImageSerializer.d.ts index 5de48ff..62ce84d 100644 --- a/TypeScript/13AddTrader/types/routers/serializers/ImageSerializer.d.ts +++ b/TypeScript/13AddTrader/types/routers/serializers/ImageSerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { ImageRouter } from "../ImageRouter"; export declare class ImageSerializer extends Serializer { diff --git a/TypeScript/13AddTrader/types/routers/serializers/NotifySerializer.d.ts b/TypeScript/13AddTrader/types/routers/serializers/NotifySerializer.d.ts index 1d179b2..e92d6e1 100644 --- a/TypeScript/13AddTrader/types/routers/serializers/NotifySerializer.d.ts +++ b/TypeScript/13AddTrader/types/routers/serializers/NotifySerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { NotifierController } from "../../controllers/NotifierController"; import { Serializer } from "../../di/Serializer"; import { HttpServerHelper } from "../../helpers/HttpServerHelper"; diff --git a/TypeScript/13AddTrader/types/servers/HttpServer.d.ts b/TypeScript/13AddTrader/types/servers/HttpServer.d.ts index 97e0705..c73eb3c 100644 --- a/TypeScript/13AddTrader/types/servers/HttpServer.d.ts +++ b/TypeScript/13AddTrader/types/servers/HttpServer.d.ts @@ -1,5 +1,5 @@ /// -import http, { IncomingMessage, ServerResponse } from "http"; +import http, { IncomingMessage, ServerResponse } from "node:http"; import { ApplicationContext } from "../context/ApplicationContext"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; import { IHttpConfig } from "../models/spt/config/IHttpConfig"; diff --git a/TypeScript/13AddTrader/types/servers/WebSocketServer.d.ts b/TypeScript/13AddTrader/types/servers/WebSocketServer.d.ts index fffbea2..b4c6158 100644 --- a/TypeScript/13AddTrader/types/servers/WebSocketServer.d.ts +++ b/TypeScript/13AddTrader/types/servers/WebSocketServer.d.ts @@ -1,5 +1,5 @@ /// -import http, { IncomingMessage } from "http"; +import http, { IncomingMessage } from "node:http"; import WebSocket from "ws"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; import { INotification } from "../models/eft/notifier/INotifier"; diff --git a/TypeScript/13AddTrader/types/servers/http/AkiHttpListener.d.ts b/TypeScript/13AddTrader/types/servers/http/AkiHttpListener.d.ts index c72e18f..e4ac80c 100644 --- a/TypeScript/13AddTrader/types/servers/http/AkiHttpListener.d.ts +++ b/TypeScript/13AddTrader/types/servers/http/AkiHttpListener.d.ts @@ -1,6 +1,6 @@ /// /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { ILogger } from "../../models/spt/utils/ILogger"; import { HttpRouter } from "../../routers/HttpRouter"; diff --git a/TypeScript/13AddTrader/types/servers/http/IHttpListener.d.ts b/TypeScript/13AddTrader/types/servers/http/IHttpListener.d.ts index 758bb5a..29d5fce 100644 --- a/TypeScript/13AddTrader/types/servers/http/IHttpListener.d.ts +++ b/TypeScript/13AddTrader/types/servers/http/IHttpListener.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export interface IHttpListener { canHandle(sessionId: string, req: IncomingMessage): boolean; handle(sessionId: string, req: IncomingMessage, resp: ServerResponse): void; diff --git a/TypeScript/13AddTrader/types/services/mod/httpListener/HttpListenerMod.d.ts b/TypeScript/13AddTrader/types/services/mod/httpListener/HttpListenerMod.d.ts index 2cdfbda..afe4574 100644 --- a/TypeScript/13AddTrader/types/services/mod/httpListener/HttpListenerMod.d.ts +++ b/TypeScript/13AddTrader/types/services/mod/httpListener/HttpListenerMod.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { IHttpListener } from "../../../servers/http/IHttpListener"; export declare class HttpListenerMod implements IHttpListener { private canHandleOverride; diff --git a/TypeScript/13AddTrader/types/services/mod/httpListener/HttpListenerModService.d.ts b/TypeScript/13AddTrader/types/services/mod/httpListener/HttpListenerModService.d.ts index 9dd3473..23abfbe 100644 --- a/TypeScript/13AddTrader/types/services/mod/httpListener/HttpListenerModService.d.ts +++ b/TypeScript/13AddTrader/types/services/mod/httpListener/HttpListenerModService.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { DependencyContainer } from "tsyringe"; export declare class HttpListenerModService { protected container: DependencyContainer; diff --git a/TypeScript/13AddTrader/types/utils/App.d.ts b/TypeScript/13AddTrader/types/utils/App.d.ts index dd8f24c..5e759ad 100644 --- a/TypeScript/13AddTrader/types/utils/App.d.ts +++ b/TypeScript/13AddTrader/types/utils/App.d.ts @@ -12,7 +12,6 @@ export declare class App { protected onLoadComponents: OnLoad[]; protected onUpdateComponents: OnUpdate[]; protected onUpdateLastRun: {}; - protected os: any; constructor(logger: ILogger, timeUtil: TimeUtil, localisationService: LocalisationService, encodingUtil: EncodingUtil, onLoadComponents: OnLoad[], onUpdateComponents: OnUpdate[]); load(): Promise; protected update(onUpdateComponents: OnUpdate[]): Promise; diff --git a/TypeScript/13AddTrader/types/utils/HashUtil.d.ts b/TypeScript/13AddTrader/types/utils/HashUtil.d.ts index c017ca8..27204cb 100644 --- a/TypeScript/13AddTrader/types/utils/HashUtil.d.ts +++ b/TypeScript/13AddTrader/types/utils/HashUtil.d.ts @@ -1,5 +1,5 @@ /// -import crypto from "crypto"; +import crypto from "node:crypto"; import { TimeUtil } from "./TimeUtil"; export declare class HashUtil { protected timeUtil: TimeUtil; diff --git a/TypeScript/13AddTrader/types/utils/HttpFileUtil.d.ts b/TypeScript/13AddTrader/types/utils/HttpFileUtil.d.ts index afc8409..6a386ce 100644 --- a/TypeScript/13AddTrader/types/utils/HttpFileUtil.d.ts +++ b/TypeScript/13AddTrader/types/utils/HttpFileUtil.d.ts @@ -1,5 +1,5 @@ /// -import { ServerResponse } from "http"; +import { ServerResponse } from "node:http"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; export declare class HttpFileUtil { protected httpServerHelper: HttpServerHelper; diff --git a/TypeScript/13AddTrader/types/utils/VFS.d.ts b/TypeScript/13AddTrader/types/utils/VFS.d.ts index 2cb09fa..3911c4b 100644 --- a/TypeScript/13AddTrader/types/utils/VFS.d.ts +++ b/TypeScript/13AddTrader/types/utils/VFS.d.ts @@ -1,6 +1,6 @@ /// /// -import fs from "fs"; +import fs from "node:fs"; import "reflect-metadata"; import { IAsyncQueue } from "../models/spt/utils/IAsyncQueue"; import { IUUidGenerator } from "../models/spt/utils/IUuidGenerator"; diff --git a/TypeScript/13AddTrader/types/utils/Watermark.d.ts b/TypeScript/13AddTrader/types/utils/Watermark.d.ts index fa63205..864e9b6 100644 --- a/TypeScript/13AddTrader/types/utils/Watermark.d.ts +++ b/TypeScript/13AddTrader/types/utils/Watermark.d.ts @@ -4,12 +4,10 @@ import { ConfigServer } from "../servers/ConfigServer"; import { LocalisationService } from "../services/LocalisationService"; export declare class WatermarkLocale { protected localisationService: LocalisationService; + protected description: string[]; + protected warning: string[]; + protected modding: string[]; constructor(localisationService: LocalisationService); - protected watermark: { - description: string[]; - warning: string[]; - modding: string[]; - }; getDescription(): string[]; getWarning(): string[]; getModding(): string[]; diff --git a/TypeScript/13AddTrader/types/utils/logging/AbstractWinstonLogger.d.ts b/TypeScript/13AddTrader/types/utils/logging/AbstractWinstonLogger.d.ts index 1ae1100..74767a2 100644 --- a/TypeScript/13AddTrader/types/utils/logging/AbstractWinstonLogger.d.ts +++ b/TypeScript/13AddTrader/types/utils/logging/AbstractWinstonLogger.d.ts @@ -1,5 +1,5 @@ /// -import fs from "fs"; +import fs from "node:fs"; import winston from "winston"; import { Daum } from "../../models/eft/itemEvent/IItemEventRouterRequest"; import { LogBackgroundColor } from "../../models/spt/logging/LogBackgroundColor"; diff --git a/TypeScript/14AfterDBLoadHook/types/controllers/GameController.d.ts b/TypeScript/14AfterDBLoadHook/types/controllers/GameController.d.ts index 73596ff..74123b2 100644 --- a/TypeScript/14AfterDBLoadHook/types/controllers/GameController.d.ts +++ b/TypeScript/14AfterDBLoadHook/types/controllers/GameController.d.ts @@ -49,7 +49,6 @@ export declare class GameController { protected giftService: GiftService; protected applicationContext: ApplicationContext; protected configServer: ConfigServer; - protected os: any; protected httpConfig: IHttpConfig; protected coreConfig: ICoreConfig; protected locationConfig: ILocationConfig; diff --git a/TypeScript/14AfterDBLoadHook/types/controllers/InsuranceController.d.ts b/TypeScript/14AfterDBLoadHook/types/controllers/InsuranceController.d.ts index fb41610..fc3229b 100644 --- a/TypeScript/14AfterDBLoadHook/types/controllers/InsuranceController.d.ts +++ b/TypeScript/14AfterDBLoadHook/types/controllers/InsuranceController.d.ts @@ -4,7 +4,6 @@ import { ProfileHelper } from "../helpers/ProfileHelper"; import { TraderHelper } from "../helpers/TraderHelper"; import { IPmcData } from "../models/eft/common/IPmcData"; import { Item } from "../models/eft/common/tables/IItem"; -import { ITemplateItem } from "../models/eft/common/tables/ITemplateItem"; import { IGetInsuranceCostRequestData } from "../models/eft/insurance/IGetInsuranceCostRequestData"; import { IGetInsuranceCostResponseData } from "../models/eft/insurance/IGetInsuranceCostResponseData"; import { IInsureRequestData } from "../models/eft/insurance/IInsureRequestData"; @@ -75,67 +74,92 @@ export declare class InsuranceController { */ protected removeInsurancePackageFromProfile(sessionID: string, packageInfo: ISystemData): void; /** - * Build an array of items to delete from the insured items. + * Finds the items that should be deleted based on the given Insurance object. * - * This method orchestrates several steps: - * - Filters items based on their presence in the database and their raid moddability. - * - Sorts base and independent child items to consider for deletion. - * - Groups child items by their parent for later evaluation. - * - Evaluates grouped child items to decide which should be deleted, based on their value and a random roll. - * - * @param insured - The insured items to build a removal array from. - * @returns An array of IDs representing items that should be deleted. + * @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(insured: Insurance): Set; /** - * Filters an item based on its existence in the database, raid moddability, and slot requirements. + * Populate a Map object of items for quick lookup by their ID. * - * @param item The item to be filtered. - * @param parentItemDbDetails The database details of the parent item, or null if the item has no parent. - * @param itemDbDetails A tuple where the first element is a boolean indicating if the item exists in the database, - * and the second element is the item details if it does. - * @returns true if the item exists in the database and neither of the following conditions are met: - * - The item has the RaidModdable property set to false. - * - The item is attached to a required slot in its parent item. - * Otherwise, returns false. + * @param insured The insurance object containing the items to populate the map with. + * @returns A Map where the keys are the item IDs and the values are the corresponding Item objects. */ - protected filterByRaidModdability(item: Item, parentItemDbDetails: ITemplateItem | null, itemDbDetails: [boolean, ITemplateItem]): boolean; + protected populateItemsMap(insured: Insurance): Map; /** - * Determines if an item is either a base item or a child item that is not equipped to its parent. + * 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 item The item to check. - * @returns true if the item is a base or an independent child item, otherwise false. + * @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. */ - protected isBaseOrIndependentChild(item: Item): boolean; + protected populateParentAttachmentsMap(insured: Insurance, itemsMap: Map): Map; /** - * Makes a roll to determine if a given item should be deleted. If the roll is successful, the item's ID is added - * to the `toDelete` array. + * 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. * - * @param item The item for which the roll is made. - * @param traderId The ID of the trader to consider in the rollForItemDelete method. - * @param toDelete The array accumulating the IDs of items to be deleted. - * @returns true if the item is marked for deletion, otherwise false. - */ - protected makeRollAndMarkForDeletion(item: Item, traderId: string, toDelete: Set): boolean; - /** - * Groups child items by their parent IDs in a Map data structure. - * - * @param item The child item to be grouped by its parent. - * @param childrenGroupedByParent The Map that holds arrays of children items grouped by their parent IDs. + * @param insured The insurance object containing the items to evaluate. + * @param toDelete A Set to keep track of items marked for deletion. * @returns void */ - protected groupChildrenByParent(item: Item, childrenGroupedByParent: Map): void; + protected processRegularItems(insured: Insurance, toDelete: Set): void; /** - * Sorts the array of children items in descending order by their maximum price. For each child, a roll is made to - * determine if it should be deleted. The method then deletes the most valuable children based on the number of - * successful rolls made. + * Process parent items and their attachments, updating the toDelete Set accordingly. * - * @param children The array of children items to sort and filter. - * @param traderId The ID of the trader to consider in the rollForItemDelete method. + * This method iterates over a map of parent items to their attachments and performs evaluations on each. + * It marks items for deletion based on certain conditions and updates the toDelete Set accordingly. + * + * @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. + */ + protected processAttachments(mainParentToAttachmentsMap: Map, itemsMap: Map, traderId: string, toDelete: Set): void; + /** + * 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. + * + * @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. * @returns void */ - protected sortAndFilterChildren(children: Item[], traderId: string, toDelete: Set): void; + protected processAttachmentByParent(attachments: Item[], traderId: string, toDelete: Set): void; + /** + * Sorts the attachment items by their max price in descending order. + * + * @param attachments The array of attachments items. + * @returns An array of items enriched with their max price and common locale-name. + */ + protected sortAttachmentsByPrice(attachments: Item[]): EnrichedItem[]; + /** + * Logs the details of each attachment item. + * + * @param attachments The array of attachment items. + */ + protected logAttachmentsDetails(attachments: EnrichedItem[]): void; + /** + * Counts the number of successful rolls for the attachment items. + * + * @param attachments The array of attachment items. + * @param traderId The ID of the trader that has insured these attachments. + * @returns The number of successful rolls. + */ + protected countSuccessfulRolls(attachments: Item[], traderId: string): number; + /** + * Marks the most valuable attachments for deletion based on the number of successful rolls made. + * + * @param attachments The array of attachment items. + * @param successfulRolls The number of successful rolls. + * @param toDelete The array that accumulates the IDs of the items to be deleted. + */ + protected attachmentDeletionByValue(attachments: EnrichedItem[], successfulRolls: number, toDelete: Set): void; /** * Remove items from the insured items that should not be returned to the player. * @@ -144,6 +168,22 @@ export declare class InsuranceController { * @returns void */ protected removeItemsFromInsurance(insured: Insurance, toDelete: Set): void; + /** + * Adopts orphaned items by resetting them as base-level items. Helpful in situations where a parent has been + * deleted from insurance, but any insured items within the parent should remain. This method will remove the + * reference from the children to the parent and set item properties to main-level values. + * + * @param insured Insurance object containing items. + */ + protected adoptOrphanedItems(insured: Insurance): void; + /** + * Fetches the parentId property of an item with a slotId "hideout". Not sure if this is actually dynamic, but this + * method should be a reliable way to fetch it, if it ever does change. + * + * @param items Array of items to search through. + * @returns The parentId of an item with slotId 'hideout'. Empty string if not found. + */ + protected fetchHideoutItemParent(items: Item[]): string; /** * Handle sending the insurance message to the user that potentially contains the valid insurance items. * @@ -154,15 +194,14 @@ export declare class InsuranceController { */ protected sendMail(sessionID: string, insurance: Insurance, noItems: boolean): void; /** - * Determines whether a valid insured item should be removed from the player's inventory based on a random roll and + * Determines whether a insured item should be removed from the player's inventory based on a random roll and * trader-specific return chance. * - * @param insuredItem The insured item being evaluated for removal. * @param traderId The ID of the trader who insured the item. - * @param itemsBeingDeleted List of items that are already slated for removal. + * @param insuredItem Optional. The item to roll for. Only used for logging. * @returns true if the insured item should be removed from inventory, false otherwise. */ - protected rollForItemDelete(insuredItem: Item, traderId: string, itemsBeingDeleted: Set): boolean; + protected rollForDelete(traderId: string, insuredItem?: Item): boolean; /** * Handle Insure event * Add insurance to an item @@ -183,3 +222,8 @@ export declare class InsuranceController { */ cost(request: IGetInsuranceCostRequestData, sessionID: string): IGetInsuranceCostResponseData; } +interface EnrichedItem extends Item { + name: string; + maxPrice: number; +} +export {}; diff --git a/TypeScript/14AfterDBLoadHook/types/di/Serializer.d.ts b/TypeScript/14AfterDBLoadHook/types/di/Serializer.d.ts index 2617007..b760b8b 100644 --- a/TypeScript/14AfterDBLoadHook/types/di/Serializer.d.ts +++ b/TypeScript/14AfterDBLoadHook/types/di/Serializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export declare class Serializer { serialize(sessionID: string, req: IncomingMessage, resp: ServerResponse, body: any): void; canHandle(something: string): boolean; diff --git a/TypeScript/14AfterDBLoadHook/types/helpers/ItemHelper.d.ts b/TypeScript/14AfterDBLoadHook/types/helpers/ItemHelper.d.ts index 6f1511c..5920d8a 100644 --- a/TypeScript/14AfterDBLoadHook/types/helpers/ItemHelper.d.ts +++ b/TypeScript/14AfterDBLoadHook/types/helpers/ItemHelper.d.ts @@ -225,6 +225,48 @@ declare class ItemHelper { * @returns true if item is flagged as quest item */ isQuestItem(tpl: string): boolean; + /** + * Checks to see if the item is *actually* moddable in-raid. Checks include the items existence in the database, the + * parent items existence in the database, the existence (and value) of the items RaidModdable property, and that + * the parents slot-required property exists, matches that of the item, and it's value. + * + * Note: this function does not preform any checks to see if the item and parent are *actually* related. + * + * @param item The item to be checked + * @param parent The parent of the item to be checked + * @returns True if the item is actually moddable, false if it is not, and null if the check cannot be performed. + */ + isRaidModdable(item: Item, parent: Item): boolean | null; + /** + * Retrieves the main parent item for a given attachment item. + * + * This method traverses up the hierarchy of items starting from a given `itemId`, until it finds the main parent + * item that is not an attached attachment itself. In other words, if you pass it an item id of a suppressor, it + * will traverse up the muzzle brake, barrel, upper receiver, and return the gun that the suppressor is ultimately + * attached to, even if that gun is located within multiple containers. + * + * It's important to note that traversal is expensive, so this method requires that you pass it a Map of the items + * to traverse, where the keys are the item IDs and the values are the corresponding Item objects. This alleviates + * some of the performance concerns, as it allows for quick lookups of items by ID. + * + * To generate the map: + * ``` + * const itemsMap = new Map(); + * items.forEach(item => itemsMap.set(item._id, item)); + * ``` + * + * @param itemId - The unique identifier of the item for which to find the main parent. + * @param itemsMap - A Map containing item IDs mapped to their corresponding Item objects for quick lookup. + * @returns The Item object representing the top-most parent of the given item, or `null` if no such parent exists. + */ + getAttachmentMainParent(itemId: string, itemsMap: Map): Item | null; + /** + * Determines if an item is an attachment that is currently attached to it's parent item. + * + * @param item The item to check. + * @returns true if the item is attached attachment, otherwise false. + */ + isAttachmentAttached(item: Item): boolean; /** * Get the inventory size of an item * @param items Item with children diff --git a/TypeScript/14AfterDBLoadHook/types/loaders/PreAkiModLoader.d.ts b/TypeScript/14AfterDBLoadHook/types/loaders/PreAkiModLoader.d.ts index 1e24b96..c0868b7 100644 --- a/TypeScript/14AfterDBLoadHook/types/loaders/PreAkiModLoader.d.ts +++ b/TypeScript/14AfterDBLoadHook/types/loaders/PreAkiModLoader.d.ts @@ -66,6 +66,10 @@ export declare class PreAkiModLoader implements IModLoader { protected isModCombatibleWithAki(mod: IPackageJsonData): boolean; protected executeMods(container: DependencyContainer): Promise; sortModsLoadOrder(): string[]; + /** + * Compile mod and add into class property "imported" + * @param mod Name of mod to compile/add + */ protected addMod(mod: string): Promise; protected autoInstallDependencies(modPath: string, pkg: IPackageJsonData): void; protected areModDependenciesFulfilled(pkg: IPackageJsonData, loadedMods: Record): boolean; diff --git a/TypeScript/14AfterDBLoadHook/types/models/external/HttpFramework.d.ts b/TypeScript/14AfterDBLoadHook/types/models/external/HttpFramework.d.ts index 64a37d6..fda8732 100644 --- a/TypeScript/14AfterDBLoadHook/types/models/external/HttpFramework.d.ts +++ b/TypeScript/14AfterDBLoadHook/types/models/external/HttpFramework.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export type HandleFn = (_: string, req: IncomingMessage, resp: ServerResponse) => void; /** * Associates handlers, HTTP methods and a base url to a listener using a proxy diff --git a/TypeScript/14AfterDBLoadHook/types/models/spt/mod/IPackageJsonData.d.ts b/TypeScript/14AfterDBLoadHook/types/models/spt/mod/IPackageJsonData.d.ts index 06f7454..f58d7cc 100644 --- a/TypeScript/14AfterDBLoadHook/types/models/spt/mod/IPackageJsonData.d.ts +++ b/TypeScript/14AfterDBLoadHook/types/models/spt/mod/IPackageJsonData.d.ts @@ -6,6 +6,9 @@ export interface IPackageJsonData { author: string; version: string; akiVersion: string; + /** We deliberately purge this data */ + scripts: Record; + devDependencies: Record; licence: string; main: string; isBundleMod: boolean; diff --git a/TypeScript/14AfterDBLoadHook/types/routers/HttpRouter.d.ts b/TypeScript/14AfterDBLoadHook/types/routers/HttpRouter.d.ts index f75a47d..46f847a 100644 --- a/TypeScript/14AfterDBLoadHook/types/routers/HttpRouter.d.ts +++ b/TypeScript/14AfterDBLoadHook/types/routers/HttpRouter.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage } from "http"; +import { IncomingMessage } from "node:http"; import { DynamicRouter, Router, StaticRouter } from "../di/Router"; export declare class HttpRouter { protected staticRouters: StaticRouter[]; diff --git a/TypeScript/14AfterDBLoadHook/types/routers/ImageRouter.d.ts b/TypeScript/14AfterDBLoadHook/types/routers/ImageRouter.d.ts index 675441c..fd03c59 100644 --- a/TypeScript/14AfterDBLoadHook/types/routers/ImageRouter.d.ts +++ b/TypeScript/14AfterDBLoadHook/types/routers/ImageRouter.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { ImageRouteService } from "../services/mod/image/ImageRouteService"; import { HttpFileUtil } from "../utils/HttpFileUtil"; import { VFS } from "../utils/VFS"; diff --git a/TypeScript/14AfterDBLoadHook/types/routers/serializers/BundleSerializer.d.ts b/TypeScript/14AfterDBLoadHook/types/routers/serializers/BundleSerializer.d.ts index ca4d8b6..db41142 100644 --- a/TypeScript/14AfterDBLoadHook/types/routers/serializers/BundleSerializer.d.ts +++ b/TypeScript/14AfterDBLoadHook/types/routers/serializers/BundleSerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { BundleLoader } from "../../loaders/BundleLoader"; import { ILogger } from "../../models/spt/utils/ILogger"; diff --git a/TypeScript/14AfterDBLoadHook/types/routers/serializers/ImageSerializer.d.ts b/TypeScript/14AfterDBLoadHook/types/routers/serializers/ImageSerializer.d.ts index 5de48ff..62ce84d 100644 --- a/TypeScript/14AfterDBLoadHook/types/routers/serializers/ImageSerializer.d.ts +++ b/TypeScript/14AfterDBLoadHook/types/routers/serializers/ImageSerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { ImageRouter } from "../ImageRouter"; export declare class ImageSerializer extends Serializer { diff --git a/TypeScript/14AfterDBLoadHook/types/routers/serializers/NotifySerializer.d.ts b/TypeScript/14AfterDBLoadHook/types/routers/serializers/NotifySerializer.d.ts index 1d179b2..e92d6e1 100644 --- a/TypeScript/14AfterDBLoadHook/types/routers/serializers/NotifySerializer.d.ts +++ b/TypeScript/14AfterDBLoadHook/types/routers/serializers/NotifySerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { NotifierController } from "../../controllers/NotifierController"; import { Serializer } from "../../di/Serializer"; import { HttpServerHelper } from "../../helpers/HttpServerHelper"; diff --git a/TypeScript/14AfterDBLoadHook/types/servers/HttpServer.d.ts b/TypeScript/14AfterDBLoadHook/types/servers/HttpServer.d.ts index 97e0705..c73eb3c 100644 --- a/TypeScript/14AfterDBLoadHook/types/servers/HttpServer.d.ts +++ b/TypeScript/14AfterDBLoadHook/types/servers/HttpServer.d.ts @@ -1,5 +1,5 @@ /// -import http, { IncomingMessage, ServerResponse } from "http"; +import http, { IncomingMessage, ServerResponse } from "node:http"; import { ApplicationContext } from "../context/ApplicationContext"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; import { IHttpConfig } from "../models/spt/config/IHttpConfig"; diff --git a/TypeScript/14AfterDBLoadHook/types/servers/WebSocketServer.d.ts b/TypeScript/14AfterDBLoadHook/types/servers/WebSocketServer.d.ts index fffbea2..b4c6158 100644 --- a/TypeScript/14AfterDBLoadHook/types/servers/WebSocketServer.d.ts +++ b/TypeScript/14AfterDBLoadHook/types/servers/WebSocketServer.d.ts @@ -1,5 +1,5 @@ /// -import http, { IncomingMessage } from "http"; +import http, { IncomingMessage } from "node:http"; import WebSocket from "ws"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; import { INotification } from "../models/eft/notifier/INotifier"; diff --git a/TypeScript/14AfterDBLoadHook/types/servers/http/AkiHttpListener.d.ts b/TypeScript/14AfterDBLoadHook/types/servers/http/AkiHttpListener.d.ts index c72e18f..e4ac80c 100644 --- a/TypeScript/14AfterDBLoadHook/types/servers/http/AkiHttpListener.d.ts +++ b/TypeScript/14AfterDBLoadHook/types/servers/http/AkiHttpListener.d.ts @@ -1,6 +1,6 @@ /// /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { ILogger } from "../../models/spt/utils/ILogger"; import { HttpRouter } from "../../routers/HttpRouter"; diff --git a/TypeScript/14AfterDBLoadHook/types/servers/http/IHttpListener.d.ts b/TypeScript/14AfterDBLoadHook/types/servers/http/IHttpListener.d.ts index 758bb5a..29d5fce 100644 --- a/TypeScript/14AfterDBLoadHook/types/servers/http/IHttpListener.d.ts +++ b/TypeScript/14AfterDBLoadHook/types/servers/http/IHttpListener.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export interface IHttpListener { canHandle(sessionId: string, req: IncomingMessage): boolean; handle(sessionId: string, req: IncomingMessage, resp: ServerResponse): void; diff --git a/TypeScript/14AfterDBLoadHook/types/services/mod/httpListener/HttpListenerMod.d.ts b/TypeScript/14AfterDBLoadHook/types/services/mod/httpListener/HttpListenerMod.d.ts index 2cdfbda..afe4574 100644 --- a/TypeScript/14AfterDBLoadHook/types/services/mod/httpListener/HttpListenerMod.d.ts +++ b/TypeScript/14AfterDBLoadHook/types/services/mod/httpListener/HttpListenerMod.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { IHttpListener } from "../../../servers/http/IHttpListener"; export declare class HttpListenerMod implements IHttpListener { private canHandleOverride; diff --git a/TypeScript/14AfterDBLoadHook/types/services/mod/httpListener/HttpListenerModService.d.ts b/TypeScript/14AfterDBLoadHook/types/services/mod/httpListener/HttpListenerModService.d.ts index 9dd3473..23abfbe 100644 --- a/TypeScript/14AfterDBLoadHook/types/services/mod/httpListener/HttpListenerModService.d.ts +++ b/TypeScript/14AfterDBLoadHook/types/services/mod/httpListener/HttpListenerModService.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { DependencyContainer } from "tsyringe"; export declare class HttpListenerModService { protected container: DependencyContainer; diff --git a/TypeScript/14AfterDBLoadHook/types/utils/App.d.ts b/TypeScript/14AfterDBLoadHook/types/utils/App.d.ts index dd8f24c..5e759ad 100644 --- a/TypeScript/14AfterDBLoadHook/types/utils/App.d.ts +++ b/TypeScript/14AfterDBLoadHook/types/utils/App.d.ts @@ -12,7 +12,6 @@ export declare class App { protected onLoadComponents: OnLoad[]; protected onUpdateComponents: OnUpdate[]; protected onUpdateLastRun: {}; - protected os: any; constructor(logger: ILogger, timeUtil: TimeUtil, localisationService: LocalisationService, encodingUtil: EncodingUtil, onLoadComponents: OnLoad[], onUpdateComponents: OnUpdate[]); load(): Promise; protected update(onUpdateComponents: OnUpdate[]): Promise; diff --git a/TypeScript/14AfterDBLoadHook/types/utils/HashUtil.d.ts b/TypeScript/14AfterDBLoadHook/types/utils/HashUtil.d.ts index c017ca8..27204cb 100644 --- a/TypeScript/14AfterDBLoadHook/types/utils/HashUtil.d.ts +++ b/TypeScript/14AfterDBLoadHook/types/utils/HashUtil.d.ts @@ -1,5 +1,5 @@ /// -import crypto from "crypto"; +import crypto from "node:crypto"; import { TimeUtil } from "./TimeUtil"; export declare class HashUtil { protected timeUtil: TimeUtil; diff --git a/TypeScript/14AfterDBLoadHook/types/utils/HttpFileUtil.d.ts b/TypeScript/14AfterDBLoadHook/types/utils/HttpFileUtil.d.ts index afc8409..6a386ce 100644 --- a/TypeScript/14AfterDBLoadHook/types/utils/HttpFileUtil.d.ts +++ b/TypeScript/14AfterDBLoadHook/types/utils/HttpFileUtil.d.ts @@ -1,5 +1,5 @@ /// -import { ServerResponse } from "http"; +import { ServerResponse } from "node:http"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; export declare class HttpFileUtil { protected httpServerHelper: HttpServerHelper; diff --git a/TypeScript/14AfterDBLoadHook/types/utils/VFS.d.ts b/TypeScript/14AfterDBLoadHook/types/utils/VFS.d.ts index 2cb09fa..3911c4b 100644 --- a/TypeScript/14AfterDBLoadHook/types/utils/VFS.d.ts +++ b/TypeScript/14AfterDBLoadHook/types/utils/VFS.d.ts @@ -1,6 +1,6 @@ /// /// -import fs from "fs"; +import fs from "node:fs"; import "reflect-metadata"; import { IAsyncQueue } from "../models/spt/utils/IAsyncQueue"; import { IUUidGenerator } from "../models/spt/utils/IUuidGenerator"; diff --git a/TypeScript/14AfterDBLoadHook/types/utils/Watermark.d.ts b/TypeScript/14AfterDBLoadHook/types/utils/Watermark.d.ts index fa63205..864e9b6 100644 --- a/TypeScript/14AfterDBLoadHook/types/utils/Watermark.d.ts +++ b/TypeScript/14AfterDBLoadHook/types/utils/Watermark.d.ts @@ -4,12 +4,10 @@ import { ConfigServer } from "../servers/ConfigServer"; import { LocalisationService } from "../services/LocalisationService"; export declare class WatermarkLocale { protected localisationService: LocalisationService; + protected description: string[]; + protected warning: string[]; + protected modding: string[]; constructor(localisationService: LocalisationService); - protected watermark: { - description: string[]; - warning: string[]; - modding: string[]; - }; getDescription(): string[]; getWarning(): string[]; getModding(): string[]; diff --git a/TypeScript/14AfterDBLoadHook/types/utils/logging/AbstractWinstonLogger.d.ts b/TypeScript/14AfterDBLoadHook/types/utils/logging/AbstractWinstonLogger.d.ts index 1ae1100..74767a2 100644 --- a/TypeScript/14AfterDBLoadHook/types/utils/logging/AbstractWinstonLogger.d.ts +++ b/TypeScript/14AfterDBLoadHook/types/utils/logging/AbstractWinstonLogger.d.ts @@ -1,5 +1,5 @@ /// -import fs from "fs"; +import fs from "node:fs"; import winston from "winston"; import { Daum } from "../../models/eft/itemEvent/IItemEventRouterRequest"; import { LogBackgroundColor } from "../../models/spt/logging/LogBackgroundColor"; diff --git a/TypeScript/15HttpListenerExample/types/controllers/GameController.d.ts b/TypeScript/15HttpListenerExample/types/controllers/GameController.d.ts index 73596ff..74123b2 100644 --- a/TypeScript/15HttpListenerExample/types/controllers/GameController.d.ts +++ b/TypeScript/15HttpListenerExample/types/controllers/GameController.d.ts @@ -49,7 +49,6 @@ export declare class GameController { protected giftService: GiftService; protected applicationContext: ApplicationContext; protected configServer: ConfigServer; - protected os: any; protected httpConfig: IHttpConfig; protected coreConfig: ICoreConfig; protected locationConfig: ILocationConfig; diff --git a/TypeScript/15HttpListenerExample/types/controllers/InsuranceController.d.ts b/TypeScript/15HttpListenerExample/types/controllers/InsuranceController.d.ts index fb41610..fc3229b 100644 --- a/TypeScript/15HttpListenerExample/types/controllers/InsuranceController.d.ts +++ b/TypeScript/15HttpListenerExample/types/controllers/InsuranceController.d.ts @@ -4,7 +4,6 @@ import { ProfileHelper } from "../helpers/ProfileHelper"; import { TraderHelper } from "../helpers/TraderHelper"; import { IPmcData } from "../models/eft/common/IPmcData"; import { Item } from "../models/eft/common/tables/IItem"; -import { ITemplateItem } from "../models/eft/common/tables/ITemplateItem"; import { IGetInsuranceCostRequestData } from "../models/eft/insurance/IGetInsuranceCostRequestData"; import { IGetInsuranceCostResponseData } from "../models/eft/insurance/IGetInsuranceCostResponseData"; import { IInsureRequestData } from "../models/eft/insurance/IInsureRequestData"; @@ -75,67 +74,92 @@ export declare class InsuranceController { */ protected removeInsurancePackageFromProfile(sessionID: string, packageInfo: ISystemData): void; /** - * Build an array of items to delete from the insured items. + * Finds the items that should be deleted based on the given Insurance object. * - * This method orchestrates several steps: - * - Filters items based on their presence in the database and their raid moddability. - * - Sorts base and independent child items to consider for deletion. - * - Groups child items by their parent for later evaluation. - * - Evaluates grouped child items to decide which should be deleted, based on their value and a random roll. - * - * @param insured - The insured items to build a removal array from. - * @returns An array of IDs representing items that should be deleted. + * @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(insured: Insurance): Set; /** - * Filters an item based on its existence in the database, raid moddability, and slot requirements. + * Populate a Map object of items for quick lookup by their ID. * - * @param item The item to be filtered. - * @param parentItemDbDetails The database details of the parent item, or null if the item has no parent. - * @param itemDbDetails A tuple where the first element is a boolean indicating if the item exists in the database, - * and the second element is the item details if it does. - * @returns true if the item exists in the database and neither of the following conditions are met: - * - The item has the RaidModdable property set to false. - * - The item is attached to a required slot in its parent item. - * Otherwise, returns false. + * @param insured The insurance object containing the items to populate the map with. + * @returns A Map where the keys are the item IDs and the values are the corresponding Item objects. */ - protected filterByRaidModdability(item: Item, parentItemDbDetails: ITemplateItem | null, itemDbDetails: [boolean, ITemplateItem]): boolean; + protected populateItemsMap(insured: Insurance): Map; /** - * Determines if an item is either a base item or a child item that is not equipped to its parent. + * 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 item The item to check. - * @returns true if the item is a base or an independent child item, otherwise false. + * @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. */ - protected isBaseOrIndependentChild(item: Item): boolean; + protected populateParentAttachmentsMap(insured: Insurance, itemsMap: Map): Map; /** - * Makes a roll to determine if a given item should be deleted. If the roll is successful, the item's ID is added - * to the `toDelete` array. + * 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. * - * @param item The item for which the roll is made. - * @param traderId The ID of the trader to consider in the rollForItemDelete method. - * @param toDelete The array accumulating the IDs of items to be deleted. - * @returns true if the item is marked for deletion, otherwise false. - */ - protected makeRollAndMarkForDeletion(item: Item, traderId: string, toDelete: Set): boolean; - /** - * Groups child items by their parent IDs in a Map data structure. - * - * @param item The child item to be grouped by its parent. - * @param childrenGroupedByParent The Map that holds arrays of children items grouped by their parent IDs. + * @param insured The insurance object containing the items to evaluate. + * @param toDelete A Set to keep track of items marked for deletion. * @returns void */ - protected groupChildrenByParent(item: Item, childrenGroupedByParent: Map): void; + protected processRegularItems(insured: Insurance, toDelete: Set): void; /** - * Sorts the array of children items in descending order by their maximum price. For each child, a roll is made to - * determine if it should be deleted. The method then deletes the most valuable children based on the number of - * successful rolls made. + * Process parent items and their attachments, updating the toDelete Set accordingly. * - * @param children The array of children items to sort and filter. - * @param traderId The ID of the trader to consider in the rollForItemDelete method. + * This method iterates over a map of parent items to their attachments and performs evaluations on each. + * It marks items for deletion based on certain conditions and updates the toDelete Set accordingly. + * + * @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. + */ + protected processAttachments(mainParentToAttachmentsMap: Map, itemsMap: Map, traderId: string, toDelete: Set): void; + /** + * 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. + * + * @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. * @returns void */ - protected sortAndFilterChildren(children: Item[], traderId: string, toDelete: Set): void; + protected processAttachmentByParent(attachments: Item[], traderId: string, toDelete: Set): void; + /** + * Sorts the attachment items by their max price in descending order. + * + * @param attachments The array of attachments items. + * @returns An array of items enriched with their max price and common locale-name. + */ + protected sortAttachmentsByPrice(attachments: Item[]): EnrichedItem[]; + /** + * Logs the details of each attachment item. + * + * @param attachments The array of attachment items. + */ + protected logAttachmentsDetails(attachments: EnrichedItem[]): void; + /** + * Counts the number of successful rolls for the attachment items. + * + * @param attachments The array of attachment items. + * @param traderId The ID of the trader that has insured these attachments. + * @returns The number of successful rolls. + */ + protected countSuccessfulRolls(attachments: Item[], traderId: string): number; + /** + * Marks the most valuable attachments for deletion based on the number of successful rolls made. + * + * @param attachments The array of attachment items. + * @param successfulRolls The number of successful rolls. + * @param toDelete The array that accumulates the IDs of the items to be deleted. + */ + protected attachmentDeletionByValue(attachments: EnrichedItem[], successfulRolls: number, toDelete: Set): void; /** * Remove items from the insured items that should not be returned to the player. * @@ -144,6 +168,22 @@ export declare class InsuranceController { * @returns void */ protected removeItemsFromInsurance(insured: Insurance, toDelete: Set): void; + /** + * Adopts orphaned items by resetting them as base-level items. Helpful in situations where a parent has been + * deleted from insurance, but any insured items within the parent should remain. This method will remove the + * reference from the children to the parent and set item properties to main-level values. + * + * @param insured Insurance object containing items. + */ + protected adoptOrphanedItems(insured: Insurance): void; + /** + * Fetches the parentId property of an item with a slotId "hideout". Not sure if this is actually dynamic, but this + * method should be a reliable way to fetch it, if it ever does change. + * + * @param items Array of items to search through. + * @returns The parentId of an item with slotId 'hideout'. Empty string if not found. + */ + protected fetchHideoutItemParent(items: Item[]): string; /** * Handle sending the insurance message to the user that potentially contains the valid insurance items. * @@ -154,15 +194,14 @@ export declare class InsuranceController { */ protected sendMail(sessionID: string, insurance: Insurance, noItems: boolean): void; /** - * Determines whether a valid insured item should be removed from the player's inventory based on a random roll and + * Determines whether a insured item should be removed from the player's inventory based on a random roll and * trader-specific return chance. * - * @param insuredItem The insured item being evaluated for removal. * @param traderId The ID of the trader who insured the item. - * @param itemsBeingDeleted List of items that are already slated for removal. + * @param insuredItem Optional. The item to roll for. Only used for logging. * @returns true if the insured item should be removed from inventory, false otherwise. */ - protected rollForItemDelete(insuredItem: Item, traderId: string, itemsBeingDeleted: Set): boolean; + protected rollForDelete(traderId: string, insuredItem?: Item): boolean; /** * Handle Insure event * Add insurance to an item @@ -183,3 +222,8 @@ export declare class InsuranceController { */ cost(request: IGetInsuranceCostRequestData, sessionID: string): IGetInsuranceCostResponseData; } +interface EnrichedItem extends Item { + name: string; + maxPrice: number; +} +export {}; diff --git a/TypeScript/15HttpListenerExample/types/di/Serializer.d.ts b/TypeScript/15HttpListenerExample/types/di/Serializer.d.ts index 2617007..b760b8b 100644 --- a/TypeScript/15HttpListenerExample/types/di/Serializer.d.ts +++ b/TypeScript/15HttpListenerExample/types/di/Serializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export declare class Serializer { serialize(sessionID: string, req: IncomingMessage, resp: ServerResponse, body: any): void; canHandle(something: string): boolean; diff --git a/TypeScript/15HttpListenerExample/types/helpers/ItemHelper.d.ts b/TypeScript/15HttpListenerExample/types/helpers/ItemHelper.d.ts index 6f1511c..5920d8a 100644 --- a/TypeScript/15HttpListenerExample/types/helpers/ItemHelper.d.ts +++ b/TypeScript/15HttpListenerExample/types/helpers/ItemHelper.d.ts @@ -225,6 +225,48 @@ declare class ItemHelper { * @returns true if item is flagged as quest item */ isQuestItem(tpl: string): boolean; + /** + * Checks to see if the item is *actually* moddable in-raid. Checks include the items existence in the database, the + * parent items existence in the database, the existence (and value) of the items RaidModdable property, and that + * the parents slot-required property exists, matches that of the item, and it's value. + * + * Note: this function does not preform any checks to see if the item and parent are *actually* related. + * + * @param item The item to be checked + * @param parent The parent of the item to be checked + * @returns True if the item is actually moddable, false if it is not, and null if the check cannot be performed. + */ + isRaidModdable(item: Item, parent: Item): boolean | null; + /** + * Retrieves the main parent item for a given attachment item. + * + * This method traverses up the hierarchy of items starting from a given `itemId`, until it finds the main parent + * item that is not an attached attachment itself. In other words, if you pass it an item id of a suppressor, it + * will traverse up the muzzle brake, barrel, upper receiver, and return the gun that the suppressor is ultimately + * attached to, even if that gun is located within multiple containers. + * + * It's important to note that traversal is expensive, so this method requires that you pass it a Map of the items + * to traverse, where the keys are the item IDs and the values are the corresponding Item objects. This alleviates + * some of the performance concerns, as it allows for quick lookups of items by ID. + * + * To generate the map: + * ``` + * const itemsMap = new Map(); + * items.forEach(item => itemsMap.set(item._id, item)); + * ``` + * + * @param itemId - The unique identifier of the item for which to find the main parent. + * @param itemsMap - A Map containing item IDs mapped to their corresponding Item objects for quick lookup. + * @returns The Item object representing the top-most parent of the given item, or `null` if no such parent exists. + */ + getAttachmentMainParent(itemId: string, itemsMap: Map): Item | null; + /** + * Determines if an item is an attachment that is currently attached to it's parent item. + * + * @param item The item to check. + * @returns true if the item is attached attachment, otherwise false. + */ + isAttachmentAttached(item: Item): boolean; /** * Get the inventory size of an item * @param items Item with children diff --git a/TypeScript/15HttpListenerExample/types/loaders/PreAkiModLoader.d.ts b/TypeScript/15HttpListenerExample/types/loaders/PreAkiModLoader.d.ts index 1e24b96..c0868b7 100644 --- a/TypeScript/15HttpListenerExample/types/loaders/PreAkiModLoader.d.ts +++ b/TypeScript/15HttpListenerExample/types/loaders/PreAkiModLoader.d.ts @@ -66,6 +66,10 @@ export declare class PreAkiModLoader implements IModLoader { protected isModCombatibleWithAki(mod: IPackageJsonData): boolean; protected executeMods(container: DependencyContainer): Promise; sortModsLoadOrder(): string[]; + /** + * Compile mod and add into class property "imported" + * @param mod Name of mod to compile/add + */ protected addMod(mod: string): Promise; protected autoInstallDependencies(modPath: string, pkg: IPackageJsonData): void; protected areModDependenciesFulfilled(pkg: IPackageJsonData, loadedMods: Record): boolean; diff --git a/TypeScript/15HttpListenerExample/types/models/external/HttpFramework.d.ts b/TypeScript/15HttpListenerExample/types/models/external/HttpFramework.d.ts index 64a37d6..fda8732 100644 --- a/TypeScript/15HttpListenerExample/types/models/external/HttpFramework.d.ts +++ b/TypeScript/15HttpListenerExample/types/models/external/HttpFramework.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export type HandleFn = (_: string, req: IncomingMessage, resp: ServerResponse) => void; /** * Associates handlers, HTTP methods and a base url to a listener using a proxy diff --git a/TypeScript/15HttpListenerExample/types/models/spt/mod/IPackageJsonData.d.ts b/TypeScript/15HttpListenerExample/types/models/spt/mod/IPackageJsonData.d.ts index 06f7454..f58d7cc 100644 --- a/TypeScript/15HttpListenerExample/types/models/spt/mod/IPackageJsonData.d.ts +++ b/TypeScript/15HttpListenerExample/types/models/spt/mod/IPackageJsonData.d.ts @@ -6,6 +6,9 @@ export interface IPackageJsonData { author: string; version: string; akiVersion: string; + /** We deliberately purge this data */ + scripts: Record; + devDependencies: Record; licence: string; main: string; isBundleMod: boolean; diff --git a/TypeScript/15HttpListenerExample/types/routers/HttpRouter.d.ts b/TypeScript/15HttpListenerExample/types/routers/HttpRouter.d.ts index f75a47d..46f847a 100644 --- a/TypeScript/15HttpListenerExample/types/routers/HttpRouter.d.ts +++ b/TypeScript/15HttpListenerExample/types/routers/HttpRouter.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage } from "http"; +import { IncomingMessage } from "node:http"; import { DynamicRouter, Router, StaticRouter } from "../di/Router"; export declare class HttpRouter { protected staticRouters: StaticRouter[]; diff --git a/TypeScript/15HttpListenerExample/types/routers/ImageRouter.d.ts b/TypeScript/15HttpListenerExample/types/routers/ImageRouter.d.ts index 675441c..fd03c59 100644 --- a/TypeScript/15HttpListenerExample/types/routers/ImageRouter.d.ts +++ b/TypeScript/15HttpListenerExample/types/routers/ImageRouter.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { ImageRouteService } from "../services/mod/image/ImageRouteService"; import { HttpFileUtil } from "../utils/HttpFileUtil"; import { VFS } from "../utils/VFS"; diff --git a/TypeScript/15HttpListenerExample/types/routers/serializers/BundleSerializer.d.ts b/TypeScript/15HttpListenerExample/types/routers/serializers/BundleSerializer.d.ts index ca4d8b6..db41142 100644 --- a/TypeScript/15HttpListenerExample/types/routers/serializers/BundleSerializer.d.ts +++ b/TypeScript/15HttpListenerExample/types/routers/serializers/BundleSerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { BundleLoader } from "../../loaders/BundleLoader"; import { ILogger } from "../../models/spt/utils/ILogger"; diff --git a/TypeScript/15HttpListenerExample/types/routers/serializers/ImageSerializer.d.ts b/TypeScript/15HttpListenerExample/types/routers/serializers/ImageSerializer.d.ts index 5de48ff..62ce84d 100644 --- a/TypeScript/15HttpListenerExample/types/routers/serializers/ImageSerializer.d.ts +++ b/TypeScript/15HttpListenerExample/types/routers/serializers/ImageSerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { ImageRouter } from "../ImageRouter"; export declare class ImageSerializer extends Serializer { diff --git a/TypeScript/15HttpListenerExample/types/routers/serializers/NotifySerializer.d.ts b/TypeScript/15HttpListenerExample/types/routers/serializers/NotifySerializer.d.ts index 1d179b2..e92d6e1 100644 --- a/TypeScript/15HttpListenerExample/types/routers/serializers/NotifySerializer.d.ts +++ b/TypeScript/15HttpListenerExample/types/routers/serializers/NotifySerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { NotifierController } from "../../controllers/NotifierController"; import { Serializer } from "../../di/Serializer"; import { HttpServerHelper } from "../../helpers/HttpServerHelper"; diff --git a/TypeScript/15HttpListenerExample/types/servers/HttpServer.d.ts b/TypeScript/15HttpListenerExample/types/servers/HttpServer.d.ts index 97e0705..c73eb3c 100644 --- a/TypeScript/15HttpListenerExample/types/servers/HttpServer.d.ts +++ b/TypeScript/15HttpListenerExample/types/servers/HttpServer.d.ts @@ -1,5 +1,5 @@ /// -import http, { IncomingMessage, ServerResponse } from "http"; +import http, { IncomingMessage, ServerResponse } from "node:http"; import { ApplicationContext } from "../context/ApplicationContext"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; import { IHttpConfig } from "../models/spt/config/IHttpConfig"; diff --git a/TypeScript/15HttpListenerExample/types/servers/WebSocketServer.d.ts b/TypeScript/15HttpListenerExample/types/servers/WebSocketServer.d.ts index fffbea2..b4c6158 100644 --- a/TypeScript/15HttpListenerExample/types/servers/WebSocketServer.d.ts +++ b/TypeScript/15HttpListenerExample/types/servers/WebSocketServer.d.ts @@ -1,5 +1,5 @@ /// -import http, { IncomingMessage } from "http"; +import http, { IncomingMessage } from "node:http"; import WebSocket from "ws"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; import { INotification } from "../models/eft/notifier/INotifier"; diff --git a/TypeScript/15HttpListenerExample/types/servers/http/AkiHttpListener.d.ts b/TypeScript/15HttpListenerExample/types/servers/http/AkiHttpListener.d.ts index c72e18f..e4ac80c 100644 --- a/TypeScript/15HttpListenerExample/types/servers/http/AkiHttpListener.d.ts +++ b/TypeScript/15HttpListenerExample/types/servers/http/AkiHttpListener.d.ts @@ -1,6 +1,6 @@ /// /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { ILogger } from "../../models/spt/utils/ILogger"; import { HttpRouter } from "../../routers/HttpRouter"; diff --git a/TypeScript/15HttpListenerExample/types/servers/http/IHttpListener.d.ts b/TypeScript/15HttpListenerExample/types/servers/http/IHttpListener.d.ts index 758bb5a..29d5fce 100644 --- a/TypeScript/15HttpListenerExample/types/servers/http/IHttpListener.d.ts +++ b/TypeScript/15HttpListenerExample/types/servers/http/IHttpListener.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export interface IHttpListener { canHandle(sessionId: string, req: IncomingMessage): boolean; handle(sessionId: string, req: IncomingMessage, resp: ServerResponse): void; diff --git a/TypeScript/15HttpListenerExample/types/services/mod/httpListener/HttpListenerMod.d.ts b/TypeScript/15HttpListenerExample/types/services/mod/httpListener/HttpListenerMod.d.ts index 2cdfbda..afe4574 100644 --- a/TypeScript/15HttpListenerExample/types/services/mod/httpListener/HttpListenerMod.d.ts +++ b/TypeScript/15HttpListenerExample/types/services/mod/httpListener/HttpListenerMod.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { IHttpListener } from "../../../servers/http/IHttpListener"; export declare class HttpListenerMod implements IHttpListener { private canHandleOverride; diff --git a/TypeScript/15HttpListenerExample/types/services/mod/httpListener/HttpListenerModService.d.ts b/TypeScript/15HttpListenerExample/types/services/mod/httpListener/HttpListenerModService.d.ts index 9dd3473..23abfbe 100644 --- a/TypeScript/15HttpListenerExample/types/services/mod/httpListener/HttpListenerModService.d.ts +++ b/TypeScript/15HttpListenerExample/types/services/mod/httpListener/HttpListenerModService.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { DependencyContainer } from "tsyringe"; export declare class HttpListenerModService { protected container: DependencyContainer; diff --git a/TypeScript/15HttpListenerExample/types/utils/App.d.ts b/TypeScript/15HttpListenerExample/types/utils/App.d.ts index dd8f24c..5e759ad 100644 --- a/TypeScript/15HttpListenerExample/types/utils/App.d.ts +++ b/TypeScript/15HttpListenerExample/types/utils/App.d.ts @@ -12,7 +12,6 @@ export declare class App { protected onLoadComponents: OnLoad[]; protected onUpdateComponents: OnUpdate[]; protected onUpdateLastRun: {}; - protected os: any; constructor(logger: ILogger, timeUtil: TimeUtil, localisationService: LocalisationService, encodingUtil: EncodingUtil, onLoadComponents: OnLoad[], onUpdateComponents: OnUpdate[]); load(): Promise; protected update(onUpdateComponents: OnUpdate[]): Promise; diff --git a/TypeScript/15HttpListenerExample/types/utils/HashUtil.d.ts b/TypeScript/15HttpListenerExample/types/utils/HashUtil.d.ts index c017ca8..27204cb 100644 --- a/TypeScript/15HttpListenerExample/types/utils/HashUtil.d.ts +++ b/TypeScript/15HttpListenerExample/types/utils/HashUtil.d.ts @@ -1,5 +1,5 @@ /// -import crypto from "crypto"; +import crypto from "node:crypto"; import { TimeUtil } from "./TimeUtil"; export declare class HashUtil { protected timeUtil: TimeUtil; diff --git a/TypeScript/15HttpListenerExample/types/utils/HttpFileUtil.d.ts b/TypeScript/15HttpListenerExample/types/utils/HttpFileUtil.d.ts index afc8409..6a386ce 100644 --- a/TypeScript/15HttpListenerExample/types/utils/HttpFileUtil.d.ts +++ b/TypeScript/15HttpListenerExample/types/utils/HttpFileUtil.d.ts @@ -1,5 +1,5 @@ /// -import { ServerResponse } from "http"; +import { ServerResponse } from "node:http"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; export declare class HttpFileUtil { protected httpServerHelper: HttpServerHelper; diff --git a/TypeScript/15HttpListenerExample/types/utils/VFS.d.ts b/TypeScript/15HttpListenerExample/types/utils/VFS.d.ts index 2cb09fa..3911c4b 100644 --- a/TypeScript/15HttpListenerExample/types/utils/VFS.d.ts +++ b/TypeScript/15HttpListenerExample/types/utils/VFS.d.ts @@ -1,6 +1,6 @@ /// /// -import fs from "fs"; +import fs from "node:fs"; import "reflect-metadata"; import { IAsyncQueue } from "../models/spt/utils/IAsyncQueue"; import { IUUidGenerator } from "../models/spt/utils/IUuidGenerator"; diff --git a/TypeScript/15HttpListenerExample/types/utils/Watermark.d.ts b/TypeScript/15HttpListenerExample/types/utils/Watermark.d.ts index fa63205..864e9b6 100644 --- a/TypeScript/15HttpListenerExample/types/utils/Watermark.d.ts +++ b/TypeScript/15HttpListenerExample/types/utils/Watermark.d.ts @@ -4,12 +4,10 @@ import { ConfigServer } from "../servers/ConfigServer"; import { LocalisationService } from "../services/LocalisationService"; export declare class WatermarkLocale { protected localisationService: LocalisationService; + protected description: string[]; + protected warning: string[]; + protected modding: string[]; constructor(localisationService: LocalisationService); - protected watermark: { - description: string[]; - warning: string[]; - modding: string[]; - }; getDescription(): string[]; getWarning(): string[]; getModding(): string[]; diff --git a/TypeScript/15HttpListenerExample/types/utils/logging/AbstractWinstonLogger.d.ts b/TypeScript/15HttpListenerExample/types/utils/logging/AbstractWinstonLogger.d.ts index 1ae1100..74767a2 100644 --- a/TypeScript/15HttpListenerExample/types/utils/logging/AbstractWinstonLogger.d.ts +++ b/TypeScript/15HttpListenerExample/types/utils/logging/AbstractWinstonLogger.d.ts @@ -1,5 +1,5 @@ /// -import fs from "fs"; +import fs from "node:fs"; import winston from "winston"; import { Daum } from "../../models/eft/itemEvent/IItemEventRouterRequest"; import { LogBackgroundColor } from "../../models/spt/logging/LogBackgroundColor"; diff --git a/TypeScript/16ImporterUtil/types/controllers/GameController.d.ts b/TypeScript/16ImporterUtil/types/controllers/GameController.d.ts index 73596ff..74123b2 100644 --- a/TypeScript/16ImporterUtil/types/controllers/GameController.d.ts +++ b/TypeScript/16ImporterUtil/types/controllers/GameController.d.ts @@ -49,7 +49,6 @@ export declare class GameController { protected giftService: GiftService; protected applicationContext: ApplicationContext; protected configServer: ConfigServer; - protected os: any; protected httpConfig: IHttpConfig; protected coreConfig: ICoreConfig; protected locationConfig: ILocationConfig; diff --git a/TypeScript/16ImporterUtil/types/controllers/InsuranceController.d.ts b/TypeScript/16ImporterUtil/types/controllers/InsuranceController.d.ts index fb41610..fc3229b 100644 --- a/TypeScript/16ImporterUtil/types/controllers/InsuranceController.d.ts +++ b/TypeScript/16ImporterUtil/types/controllers/InsuranceController.d.ts @@ -4,7 +4,6 @@ import { ProfileHelper } from "../helpers/ProfileHelper"; import { TraderHelper } from "../helpers/TraderHelper"; import { IPmcData } from "../models/eft/common/IPmcData"; import { Item } from "../models/eft/common/tables/IItem"; -import { ITemplateItem } from "../models/eft/common/tables/ITemplateItem"; import { IGetInsuranceCostRequestData } from "../models/eft/insurance/IGetInsuranceCostRequestData"; import { IGetInsuranceCostResponseData } from "../models/eft/insurance/IGetInsuranceCostResponseData"; import { IInsureRequestData } from "../models/eft/insurance/IInsureRequestData"; @@ -75,67 +74,92 @@ export declare class InsuranceController { */ protected removeInsurancePackageFromProfile(sessionID: string, packageInfo: ISystemData): void; /** - * Build an array of items to delete from the insured items. + * Finds the items that should be deleted based on the given Insurance object. * - * This method orchestrates several steps: - * - Filters items based on their presence in the database and their raid moddability. - * - Sorts base and independent child items to consider for deletion. - * - Groups child items by their parent for later evaluation. - * - Evaluates grouped child items to decide which should be deleted, based on their value and a random roll. - * - * @param insured - The insured items to build a removal array from. - * @returns An array of IDs representing items that should be deleted. + * @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(insured: Insurance): Set; /** - * Filters an item based on its existence in the database, raid moddability, and slot requirements. + * Populate a Map object of items for quick lookup by their ID. * - * @param item The item to be filtered. - * @param parentItemDbDetails The database details of the parent item, or null if the item has no parent. - * @param itemDbDetails A tuple where the first element is a boolean indicating if the item exists in the database, - * and the second element is the item details if it does. - * @returns true if the item exists in the database and neither of the following conditions are met: - * - The item has the RaidModdable property set to false. - * - The item is attached to a required slot in its parent item. - * Otherwise, returns false. + * @param insured The insurance object containing the items to populate the map with. + * @returns A Map where the keys are the item IDs and the values are the corresponding Item objects. */ - protected filterByRaidModdability(item: Item, parentItemDbDetails: ITemplateItem | null, itemDbDetails: [boolean, ITemplateItem]): boolean; + protected populateItemsMap(insured: Insurance): Map; /** - * Determines if an item is either a base item or a child item that is not equipped to its parent. + * 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 item The item to check. - * @returns true if the item is a base or an independent child item, otherwise false. + * @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. */ - protected isBaseOrIndependentChild(item: Item): boolean; + protected populateParentAttachmentsMap(insured: Insurance, itemsMap: Map): Map; /** - * Makes a roll to determine if a given item should be deleted. If the roll is successful, the item's ID is added - * to the `toDelete` array. + * 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. * - * @param item The item for which the roll is made. - * @param traderId The ID of the trader to consider in the rollForItemDelete method. - * @param toDelete The array accumulating the IDs of items to be deleted. - * @returns true if the item is marked for deletion, otherwise false. - */ - protected makeRollAndMarkForDeletion(item: Item, traderId: string, toDelete: Set): boolean; - /** - * Groups child items by their parent IDs in a Map data structure. - * - * @param item The child item to be grouped by its parent. - * @param childrenGroupedByParent The Map that holds arrays of children items grouped by their parent IDs. + * @param insured The insurance object containing the items to evaluate. + * @param toDelete A Set to keep track of items marked for deletion. * @returns void */ - protected groupChildrenByParent(item: Item, childrenGroupedByParent: Map): void; + protected processRegularItems(insured: Insurance, toDelete: Set): void; /** - * Sorts the array of children items in descending order by their maximum price. For each child, a roll is made to - * determine if it should be deleted. The method then deletes the most valuable children based on the number of - * successful rolls made. + * Process parent items and their attachments, updating the toDelete Set accordingly. * - * @param children The array of children items to sort and filter. - * @param traderId The ID of the trader to consider in the rollForItemDelete method. + * This method iterates over a map of parent items to their attachments and performs evaluations on each. + * It marks items for deletion based on certain conditions and updates the toDelete Set accordingly. + * + * @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. + */ + protected processAttachments(mainParentToAttachmentsMap: Map, itemsMap: Map, traderId: string, toDelete: Set): void; + /** + * 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. + * + * @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. * @returns void */ - protected sortAndFilterChildren(children: Item[], traderId: string, toDelete: Set): void; + protected processAttachmentByParent(attachments: Item[], traderId: string, toDelete: Set): void; + /** + * Sorts the attachment items by their max price in descending order. + * + * @param attachments The array of attachments items. + * @returns An array of items enriched with their max price and common locale-name. + */ + protected sortAttachmentsByPrice(attachments: Item[]): EnrichedItem[]; + /** + * Logs the details of each attachment item. + * + * @param attachments The array of attachment items. + */ + protected logAttachmentsDetails(attachments: EnrichedItem[]): void; + /** + * Counts the number of successful rolls for the attachment items. + * + * @param attachments The array of attachment items. + * @param traderId The ID of the trader that has insured these attachments. + * @returns The number of successful rolls. + */ + protected countSuccessfulRolls(attachments: Item[], traderId: string): number; + /** + * Marks the most valuable attachments for deletion based on the number of successful rolls made. + * + * @param attachments The array of attachment items. + * @param successfulRolls The number of successful rolls. + * @param toDelete The array that accumulates the IDs of the items to be deleted. + */ + protected attachmentDeletionByValue(attachments: EnrichedItem[], successfulRolls: number, toDelete: Set): void; /** * Remove items from the insured items that should not be returned to the player. * @@ -144,6 +168,22 @@ export declare class InsuranceController { * @returns void */ protected removeItemsFromInsurance(insured: Insurance, toDelete: Set): void; + /** + * Adopts orphaned items by resetting them as base-level items. Helpful in situations where a parent has been + * deleted from insurance, but any insured items within the parent should remain. This method will remove the + * reference from the children to the parent and set item properties to main-level values. + * + * @param insured Insurance object containing items. + */ + protected adoptOrphanedItems(insured: Insurance): void; + /** + * Fetches the parentId property of an item with a slotId "hideout". Not sure if this is actually dynamic, but this + * method should be a reliable way to fetch it, if it ever does change. + * + * @param items Array of items to search through. + * @returns The parentId of an item with slotId 'hideout'. Empty string if not found. + */ + protected fetchHideoutItemParent(items: Item[]): string; /** * Handle sending the insurance message to the user that potentially contains the valid insurance items. * @@ -154,15 +194,14 @@ export declare class InsuranceController { */ protected sendMail(sessionID: string, insurance: Insurance, noItems: boolean): void; /** - * Determines whether a valid insured item should be removed from the player's inventory based on a random roll and + * Determines whether a insured item should be removed from the player's inventory based on a random roll and * trader-specific return chance. * - * @param insuredItem The insured item being evaluated for removal. * @param traderId The ID of the trader who insured the item. - * @param itemsBeingDeleted List of items that are already slated for removal. + * @param insuredItem Optional. The item to roll for. Only used for logging. * @returns true if the insured item should be removed from inventory, false otherwise. */ - protected rollForItemDelete(insuredItem: Item, traderId: string, itemsBeingDeleted: Set): boolean; + protected rollForDelete(traderId: string, insuredItem?: Item): boolean; /** * Handle Insure event * Add insurance to an item @@ -183,3 +222,8 @@ export declare class InsuranceController { */ cost(request: IGetInsuranceCostRequestData, sessionID: string): IGetInsuranceCostResponseData; } +interface EnrichedItem extends Item { + name: string; + maxPrice: number; +} +export {}; diff --git a/TypeScript/16ImporterUtil/types/di/Serializer.d.ts b/TypeScript/16ImporterUtil/types/di/Serializer.d.ts index 2617007..b760b8b 100644 --- a/TypeScript/16ImporterUtil/types/di/Serializer.d.ts +++ b/TypeScript/16ImporterUtil/types/di/Serializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export declare class Serializer { serialize(sessionID: string, req: IncomingMessage, resp: ServerResponse, body: any): void; canHandle(something: string): boolean; diff --git a/TypeScript/16ImporterUtil/types/helpers/ItemHelper.d.ts b/TypeScript/16ImporterUtil/types/helpers/ItemHelper.d.ts index 6f1511c..5920d8a 100644 --- a/TypeScript/16ImporterUtil/types/helpers/ItemHelper.d.ts +++ b/TypeScript/16ImporterUtil/types/helpers/ItemHelper.d.ts @@ -225,6 +225,48 @@ declare class ItemHelper { * @returns true if item is flagged as quest item */ isQuestItem(tpl: string): boolean; + /** + * Checks to see if the item is *actually* moddable in-raid. Checks include the items existence in the database, the + * parent items existence in the database, the existence (and value) of the items RaidModdable property, and that + * the parents slot-required property exists, matches that of the item, and it's value. + * + * Note: this function does not preform any checks to see if the item and parent are *actually* related. + * + * @param item The item to be checked + * @param parent The parent of the item to be checked + * @returns True if the item is actually moddable, false if it is not, and null if the check cannot be performed. + */ + isRaidModdable(item: Item, parent: Item): boolean | null; + /** + * Retrieves the main parent item for a given attachment item. + * + * This method traverses up the hierarchy of items starting from a given `itemId`, until it finds the main parent + * item that is not an attached attachment itself. In other words, if you pass it an item id of a suppressor, it + * will traverse up the muzzle brake, barrel, upper receiver, and return the gun that the suppressor is ultimately + * attached to, even if that gun is located within multiple containers. + * + * It's important to note that traversal is expensive, so this method requires that you pass it a Map of the items + * to traverse, where the keys are the item IDs and the values are the corresponding Item objects. This alleviates + * some of the performance concerns, as it allows for quick lookups of items by ID. + * + * To generate the map: + * ``` + * const itemsMap = new Map(); + * items.forEach(item => itemsMap.set(item._id, item)); + * ``` + * + * @param itemId - The unique identifier of the item for which to find the main parent. + * @param itemsMap - A Map containing item IDs mapped to their corresponding Item objects for quick lookup. + * @returns The Item object representing the top-most parent of the given item, or `null` if no such parent exists. + */ + getAttachmentMainParent(itemId: string, itemsMap: Map): Item | null; + /** + * Determines if an item is an attachment that is currently attached to it's parent item. + * + * @param item The item to check. + * @returns true if the item is attached attachment, otherwise false. + */ + isAttachmentAttached(item: Item): boolean; /** * Get the inventory size of an item * @param items Item with children diff --git a/TypeScript/16ImporterUtil/types/loaders/PreAkiModLoader.d.ts b/TypeScript/16ImporterUtil/types/loaders/PreAkiModLoader.d.ts index 1e24b96..c0868b7 100644 --- a/TypeScript/16ImporterUtil/types/loaders/PreAkiModLoader.d.ts +++ b/TypeScript/16ImporterUtil/types/loaders/PreAkiModLoader.d.ts @@ -66,6 +66,10 @@ export declare class PreAkiModLoader implements IModLoader { protected isModCombatibleWithAki(mod: IPackageJsonData): boolean; protected executeMods(container: DependencyContainer): Promise; sortModsLoadOrder(): string[]; + /** + * Compile mod and add into class property "imported" + * @param mod Name of mod to compile/add + */ protected addMod(mod: string): Promise; protected autoInstallDependencies(modPath: string, pkg: IPackageJsonData): void; protected areModDependenciesFulfilled(pkg: IPackageJsonData, loadedMods: Record): boolean; diff --git a/TypeScript/16ImporterUtil/types/models/external/HttpFramework.d.ts b/TypeScript/16ImporterUtil/types/models/external/HttpFramework.d.ts index 64a37d6..fda8732 100644 --- a/TypeScript/16ImporterUtil/types/models/external/HttpFramework.d.ts +++ b/TypeScript/16ImporterUtil/types/models/external/HttpFramework.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export type HandleFn = (_: string, req: IncomingMessage, resp: ServerResponse) => void; /** * Associates handlers, HTTP methods and a base url to a listener using a proxy diff --git a/TypeScript/16ImporterUtil/types/models/spt/mod/IPackageJsonData.d.ts b/TypeScript/16ImporterUtil/types/models/spt/mod/IPackageJsonData.d.ts index 06f7454..f58d7cc 100644 --- a/TypeScript/16ImporterUtil/types/models/spt/mod/IPackageJsonData.d.ts +++ b/TypeScript/16ImporterUtil/types/models/spt/mod/IPackageJsonData.d.ts @@ -6,6 +6,9 @@ export interface IPackageJsonData { author: string; version: string; akiVersion: string; + /** We deliberately purge this data */ + scripts: Record; + devDependencies: Record; licence: string; main: string; isBundleMod: boolean; diff --git a/TypeScript/16ImporterUtil/types/routers/HttpRouter.d.ts b/TypeScript/16ImporterUtil/types/routers/HttpRouter.d.ts index f75a47d..46f847a 100644 --- a/TypeScript/16ImporterUtil/types/routers/HttpRouter.d.ts +++ b/TypeScript/16ImporterUtil/types/routers/HttpRouter.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage } from "http"; +import { IncomingMessage } from "node:http"; import { DynamicRouter, Router, StaticRouter } from "../di/Router"; export declare class HttpRouter { protected staticRouters: StaticRouter[]; diff --git a/TypeScript/16ImporterUtil/types/routers/ImageRouter.d.ts b/TypeScript/16ImporterUtil/types/routers/ImageRouter.d.ts index 675441c..fd03c59 100644 --- a/TypeScript/16ImporterUtil/types/routers/ImageRouter.d.ts +++ b/TypeScript/16ImporterUtil/types/routers/ImageRouter.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { ImageRouteService } from "../services/mod/image/ImageRouteService"; import { HttpFileUtil } from "../utils/HttpFileUtil"; import { VFS } from "../utils/VFS"; diff --git a/TypeScript/16ImporterUtil/types/routers/serializers/BundleSerializer.d.ts b/TypeScript/16ImporterUtil/types/routers/serializers/BundleSerializer.d.ts index ca4d8b6..db41142 100644 --- a/TypeScript/16ImporterUtil/types/routers/serializers/BundleSerializer.d.ts +++ b/TypeScript/16ImporterUtil/types/routers/serializers/BundleSerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { BundleLoader } from "../../loaders/BundleLoader"; import { ILogger } from "../../models/spt/utils/ILogger"; diff --git a/TypeScript/16ImporterUtil/types/routers/serializers/ImageSerializer.d.ts b/TypeScript/16ImporterUtil/types/routers/serializers/ImageSerializer.d.ts index 5de48ff..62ce84d 100644 --- a/TypeScript/16ImporterUtil/types/routers/serializers/ImageSerializer.d.ts +++ b/TypeScript/16ImporterUtil/types/routers/serializers/ImageSerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { ImageRouter } from "../ImageRouter"; export declare class ImageSerializer extends Serializer { diff --git a/TypeScript/16ImporterUtil/types/routers/serializers/NotifySerializer.d.ts b/TypeScript/16ImporterUtil/types/routers/serializers/NotifySerializer.d.ts index 1d179b2..e92d6e1 100644 --- a/TypeScript/16ImporterUtil/types/routers/serializers/NotifySerializer.d.ts +++ b/TypeScript/16ImporterUtil/types/routers/serializers/NotifySerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { NotifierController } from "../../controllers/NotifierController"; import { Serializer } from "../../di/Serializer"; import { HttpServerHelper } from "../../helpers/HttpServerHelper"; diff --git a/TypeScript/16ImporterUtil/types/servers/HttpServer.d.ts b/TypeScript/16ImporterUtil/types/servers/HttpServer.d.ts index 97e0705..c73eb3c 100644 --- a/TypeScript/16ImporterUtil/types/servers/HttpServer.d.ts +++ b/TypeScript/16ImporterUtil/types/servers/HttpServer.d.ts @@ -1,5 +1,5 @@ /// -import http, { IncomingMessage, ServerResponse } from "http"; +import http, { IncomingMessage, ServerResponse } from "node:http"; import { ApplicationContext } from "../context/ApplicationContext"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; import { IHttpConfig } from "../models/spt/config/IHttpConfig"; diff --git a/TypeScript/16ImporterUtil/types/servers/WebSocketServer.d.ts b/TypeScript/16ImporterUtil/types/servers/WebSocketServer.d.ts index fffbea2..b4c6158 100644 --- a/TypeScript/16ImporterUtil/types/servers/WebSocketServer.d.ts +++ b/TypeScript/16ImporterUtil/types/servers/WebSocketServer.d.ts @@ -1,5 +1,5 @@ /// -import http, { IncomingMessage } from "http"; +import http, { IncomingMessage } from "node:http"; import WebSocket from "ws"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; import { INotification } from "../models/eft/notifier/INotifier"; diff --git a/TypeScript/16ImporterUtil/types/servers/http/AkiHttpListener.d.ts b/TypeScript/16ImporterUtil/types/servers/http/AkiHttpListener.d.ts index c72e18f..e4ac80c 100644 --- a/TypeScript/16ImporterUtil/types/servers/http/AkiHttpListener.d.ts +++ b/TypeScript/16ImporterUtil/types/servers/http/AkiHttpListener.d.ts @@ -1,6 +1,6 @@ /// /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { ILogger } from "../../models/spt/utils/ILogger"; import { HttpRouter } from "../../routers/HttpRouter"; diff --git a/TypeScript/16ImporterUtil/types/servers/http/IHttpListener.d.ts b/TypeScript/16ImporterUtil/types/servers/http/IHttpListener.d.ts index 758bb5a..29d5fce 100644 --- a/TypeScript/16ImporterUtil/types/servers/http/IHttpListener.d.ts +++ b/TypeScript/16ImporterUtil/types/servers/http/IHttpListener.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export interface IHttpListener { canHandle(sessionId: string, req: IncomingMessage): boolean; handle(sessionId: string, req: IncomingMessage, resp: ServerResponse): void; diff --git a/TypeScript/16ImporterUtil/types/services/mod/httpListener/HttpListenerMod.d.ts b/TypeScript/16ImporterUtil/types/services/mod/httpListener/HttpListenerMod.d.ts index 2cdfbda..afe4574 100644 --- a/TypeScript/16ImporterUtil/types/services/mod/httpListener/HttpListenerMod.d.ts +++ b/TypeScript/16ImporterUtil/types/services/mod/httpListener/HttpListenerMod.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { IHttpListener } from "../../../servers/http/IHttpListener"; export declare class HttpListenerMod implements IHttpListener { private canHandleOverride; diff --git a/TypeScript/16ImporterUtil/types/services/mod/httpListener/HttpListenerModService.d.ts b/TypeScript/16ImporterUtil/types/services/mod/httpListener/HttpListenerModService.d.ts index 9dd3473..23abfbe 100644 --- a/TypeScript/16ImporterUtil/types/services/mod/httpListener/HttpListenerModService.d.ts +++ b/TypeScript/16ImporterUtil/types/services/mod/httpListener/HttpListenerModService.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { DependencyContainer } from "tsyringe"; export declare class HttpListenerModService { protected container: DependencyContainer; diff --git a/TypeScript/16ImporterUtil/types/utils/App.d.ts b/TypeScript/16ImporterUtil/types/utils/App.d.ts index dd8f24c..5e759ad 100644 --- a/TypeScript/16ImporterUtil/types/utils/App.d.ts +++ b/TypeScript/16ImporterUtil/types/utils/App.d.ts @@ -12,7 +12,6 @@ export declare class App { protected onLoadComponents: OnLoad[]; protected onUpdateComponents: OnUpdate[]; protected onUpdateLastRun: {}; - protected os: any; constructor(logger: ILogger, timeUtil: TimeUtil, localisationService: LocalisationService, encodingUtil: EncodingUtil, onLoadComponents: OnLoad[], onUpdateComponents: OnUpdate[]); load(): Promise; protected update(onUpdateComponents: OnUpdate[]): Promise; diff --git a/TypeScript/16ImporterUtil/types/utils/HashUtil.d.ts b/TypeScript/16ImporterUtil/types/utils/HashUtil.d.ts index c017ca8..27204cb 100644 --- a/TypeScript/16ImporterUtil/types/utils/HashUtil.d.ts +++ b/TypeScript/16ImporterUtil/types/utils/HashUtil.d.ts @@ -1,5 +1,5 @@ /// -import crypto from "crypto"; +import crypto from "node:crypto"; import { TimeUtil } from "./TimeUtil"; export declare class HashUtil { protected timeUtil: TimeUtil; diff --git a/TypeScript/16ImporterUtil/types/utils/HttpFileUtil.d.ts b/TypeScript/16ImporterUtil/types/utils/HttpFileUtil.d.ts index afc8409..6a386ce 100644 --- a/TypeScript/16ImporterUtil/types/utils/HttpFileUtil.d.ts +++ b/TypeScript/16ImporterUtil/types/utils/HttpFileUtil.d.ts @@ -1,5 +1,5 @@ /// -import { ServerResponse } from "http"; +import { ServerResponse } from "node:http"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; export declare class HttpFileUtil { protected httpServerHelper: HttpServerHelper; diff --git a/TypeScript/16ImporterUtil/types/utils/VFS.d.ts b/TypeScript/16ImporterUtil/types/utils/VFS.d.ts index 2cb09fa..3911c4b 100644 --- a/TypeScript/16ImporterUtil/types/utils/VFS.d.ts +++ b/TypeScript/16ImporterUtil/types/utils/VFS.d.ts @@ -1,6 +1,6 @@ /// /// -import fs from "fs"; +import fs from "node:fs"; import "reflect-metadata"; import { IAsyncQueue } from "../models/spt/utils/IAsyncQueue"; import { IUUidGenerator } from "../models/spt/utils/IUuidGenerator"; diff --git a/TypeScript/16ImporterUtil/types/utils/Watermark.d.ts b/TypeScript/16ImporterUtil/types/utils/Watermark.d.ts index fa63205..864e9b6 100644 --- a/TypeScript/16ImporterUtil/types/utils/Watermark.d.ts +++ b/TypeScript/16ImporterUtil/types/utils/Watermark.d.ts @@ -4,12 +4,10 @@ import { ConfigServer } from "../servers/ConfigServer"; import { LocalisationService } from "../services/LocalisationService"; export declare class WatermarkLocale { protected localisationService: LocalisationService; + protected description: string[]; + protected warning: string[]; + protected modding: string[]; constructor(localisationService: LocalisationService); - protected watermark: { - description: string[]; - warning: string[]; - modding: string[]; - }; getDescription(): string[]; getWarning(): string[]; getModding(): string[]; diff --git a/TypeScript/16ImporterUtil/types/utils/logging/AbstractWinstonLogger.d.ts b/TypeScript/16ImporterUtil/types/utils/logging/AbstractWinstonLogger.d.ts index 1ae1100..74767a2 100644 --- a/TypeScript/16ImporterUtil/types/utils/logging/AbstractWinstonLogger.d.ts +++ b/TypeScript/16ImporterUtil/types/utils/logging/AbstractWinstonLogger.d.ts @@ -1,5 +1,5 @@ /// -import fs from "fs"; +import fs from "node:fs"; import winston from "winston"; import { Daum } from "../../models/eft/itemEvent/IItemEventRouterRequest"; import { LogBackgroundColor } from "../../models/spt/logging/LogBackgroundColor"; diff --git a/TypeScript/17AsyncImporterWithDependency1/types/controllers/GameController.d.ts b/TypeScript/17AsyncImporterWithDependency1/types/controllers/GameController.d.ts index 73596ff..74123b2 100644 --- a/TypeScript/17AsyncImporterWithDependency1/types/controllers/GameController.d.ts +++ b/TypeScript/17AsyncImporterWithDependency1/types/controllers/GameController.d.ts @@ -49,7 +49,6 @@ export declare class GameController { protected giftService: GiftService; protected applicationContext: ApplicationContext; protected configServer: ConfigServer; - protected os: any; protected httpConfig: IHttpConfig; protected coreConfig: ICoreConfig; protected locationConfig: ILocationConfig; diff --git a/TypeScript/17AsyncImporterWithDependency1/types/controllers/InsuranceController.d.ts b/TypeScript/17AsyncImporterWithDependency1/types/controllers/InsuranceController.d.ts index fb41610..fc3229b 100644 --- a/TypeScript/17AsyncImporterWithDependency1/types/controllers/InsuranceController.d.ts +++ b/TypeScript/17AsyncImporterWithDependency1/types/controllers/InsuranceController.d.ts @@ -4,7 +4,6 @@ import { ProfileHelper } from "../helpers/ProfileHelper"; import { TraderHelper } from "../helpers/TraderHelper"; import { IPmcData } from "../models/eft/common/IPmcData"; import { Item } from "../models/eft/common/tables/IItem"; -import { ITemplateItem } from "../models/eft/common/tables/ITemplateItem"; import { IGetInsuranceCostRequestData } from "../models/eft/insurance/IGetInsuranceCostRequestData"; import { IGetInsuranceCostResponseData } from "../models/eft/insurance/IGetInsuranceCostResponseData"; import { IInsureRequestData } from "../models/eft/insurance/IInsureRequestData"; @@ -75,67 +74,92 @@ export declare class InsuranceController { */ protected removeInsurancePackageFromProfile(sessionID: string, packageInfo: ISystemData): void; /** - * Build an array of items to delete from the insured items. + * Finds the items that should be deleted based on the given Insurance object. * - * This method orchestrates several steps: - * - Filters items based on their presence in the database and their raid moddability. - * - Sorts base and independent child items to consider for deletion. - * - Groups child items by their parent for later evaluation. - * - Evaluates grouped child items to decide which should be deleted, based on their value and a random roll. - * - * @param insured - The insured items to build a removal array from. - * @returns An array of IDs representing items that should be deleted. + * @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(insured: Insurance): Set; /** - * Filters an item based on its existence in the database, raid moddability, and slot requirements. + * Populate a Map object of items for quick lookup by their ID. * - * @param item The item to be filtered. - * @param parentItemDbDetails The database details of the parent item, or null if the item has no parent. - * @param itemDbDetails A tuple where the first element is a boolean indicating if the item exists in the database, - * and the second element is the item details if it does. - * @returns true if the item exists in the database and neither of the following conditions are met: - * - The item has the RaidModdable property set to false. - * - The item is attached to a required slot in its parent item. - * Otherwise, returns false. + * @param insured The insurance object containing the items to populate the map with. + * @returns A Map where the keys are the item IDs and the values are the corresponding Item objects. */ - protected filterByRaidModdability(item: Item, parentItemDbDetails: ITemplateItem | null, itemDbDetails: [boolean, ITemplateItem]): boolean; + protected populateItemsMap(insured: Insurance): Map; /** - * Determines if an item is either a base item or a child item that is not equipped to its parent. + * 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 item The item to check. - * @returns true if the item is a base or an independent child item, otherwise false. + * @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. */ - protected isBaseOrIndependentChild(item: Item): boolean; + protected populateParentAttachmentsMap(insured: Insurance, itemsMap: Map): Map; /** - * Makes a roll to determine if a given item should be deleted. If the roll is successful, the item's ID is added - * to the `toDelete` array. + * 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. * - * @param item The item for which the roll is made. - * @param traderId The ID of the trader to consider in the rollForItemDelete method. - * @param toDelete The array accumulating the IDs of items to be deleted. - * @returns true if the item is marked for deletion, otherwise false. - */ - protected makeRollAndMarkForDeletion(item: Item, traderId: string, toDelete: Set): boolean; - /** - * Groups child items by their parent IDs in a Map data structure. - * - * @param item The child item to be grouped by its parent. - * @param childrenGroupedByParent The Map that holds arrays of children items grouped by their parent IDs. + * @param insured The insurance object containing the items to evaluate. + * @param toDelete A Set to keep track of items marked for deletion. * @returns void */ - protected groupChildrenByParent(item: Item, childrenGroupedByParent: Map): void; + protected processRegularItems(insured: Insurance, toDelete: Set): void; /** - * Sorts the array of children items in descending order by their maximum price. For each child, a roll is made to - * determine if it should be deleted. The method then deletes the most valuable children based on the number of - * successful rolls made. + * Process parent items and their attachments, updating the toDelete Set accordingly. * - * @param children The array of children items to sort and filter. - * @param traderId The ID of the trader to consider in the rollForItemDelete method. + * This method iterates over a map of parent items to their attachments and performs evaluations on each. + * It marks items for deletion based on certain conditions and updates the toDelete Set accordingly. + * + * @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. + */ + protected processAttachments(mainParentToAttachmentsMap: Map, itemsMap: Map, traderId: string, toDelete: Set): void; + /** + * 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. + * + * @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. * @returns void */ - protected sortAndFilterChildren(children: Item[], traderId: string, toDelete: Set): void; + protected processAttachmentByParent(attachments: Item[], traderId: string, toDelete: Set): void; + /** + * Sorts the attachment items by their max price in descending order. + * + * @param attachments The array of attachments items. + * @returns An array of items enriched with their max price and common locale-name. + */ + protected sortAttachmentsByPrice(attachments: Item[]): EnrichedItem[]; + /** + * Logs the details of each attachment item. + * + * @param attachments The array of attachment items. + */ + protected logAttachmentsDetails(attachments: EnrichedItem[]): void; + /** + * Counts the number of successful rolls for the attachment items. + * + * @param attachments The array of attachment items. + * @param traderId The ID of the trader that has insured these attachments. + * @returns The number of successful rolls. + */ + protected countSuccessfulRolls(attachments: Item[], traderId: string): number; + /** + * Marks the most valuable attachments for deletion based on the number of successful rolls made. + * + * @param attachments The array of attachment items. + * @param successfulRolls The number of successful rolls. + * @param toDelete The array that accumulates the IDs of the items to be deleted. + */ + protected attachmentDeletionByValue(attachments: EnrichedItem[], successfulRolls: number, toDelete: Set): void; /** * Remove items from the insured items that should not be returned to the player. * @@ -144,6 +168,22 @@ export declare class InsuranceController { * @returns void */ protected removeItemsFromInsurance(insured: Insurance, toDelete: Set): void; + /** + * Adopts orphaned items by resetting them as base-level items. Helpful in situations where a parent has been + * deleted from insurance, but any insured items within the parent should remain. This method will remove the + * reference from the children to the parent and set item properties to main-level values. + * + * @param insured Insurance object containing items. + */ + protected adoptOrphanedItems(insured: Insurance): void; + /** + * Fetches the parentId property of an item with a slotId "hideout". Not sure if this is actually dynamic, but this + * method should be a reliable way to fetch it, if it ever does change. + * + * @param items Array of items to search through. + * @returns The parentId of an item with slotId 'hideout'. Empty string if not found. + */ + protected fetchHideoutItemParent(items: Item[]): string; /** * Handle sending the insurance message to the user that potentially contains the valid insurance items. * @@ -154,15 +194,14 @@ export declare class InsuranceController { */ protected sendMail(sessionID: string, insurance: Insurance, noItems: boolean): void; /** - * Determines whether a valid insured item should be removed from the player's inventory based on a random roll and + * Determines whether a insured item should be removed from the player's inventory based on a random roll and * trader-specific return chance. * - * @param insuredItem The insured item being evaluated for removal. * @param traderId The ID of the trader who insured the item. - * @param itemsBeingDeleted List of items that are already slated for removal. + * @param insuredItem Optional. The item to roll for. Only used for logging. * @returns true if the insured item should be removed from inventory, false otherwise. */ - protected rollForItemDelete(insuredItem: Item, traderId: string, itemsBeingDeleted: Set): boolean; + protected rollForDelete(traderId: string, insuredItem?: Item): boolean; /** * Handle Insure event * Add insurance to an item @@ -183,3 +222,8 @@ export declare class InsuranceController { */ cost(request: IGetInsuranceCostRequestData, sessionID: string): IGetInsuranceCostResponseData; } +interface EnrichedItem extends Item { + name: string; + maxPrice: number; +} +export {}; diff --git a/TypeScript/17AsyncImporterWithDependency1/types/di/Serializer.d.ts b/TypeScript/17AsyncImporterWithDependency1/types/di/Serializer.d.ts index 2617007..b760b8b 100644 --- a/TypeScript/17AsyncImporterWithDependency1/types/di/Serializer.d.ts +++ b/TypeScript/17AsyncImporterWithDependency1/types/di/Serializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export declare class Serializer { serialize(sessionID: string, req: IncomingMessage, resp: ServerResponse, body: any): void; canHandle(something: string): boolean; diff --git a/TypeScript/17AsyncImporterWithDependency1/types/helpers/ItemHelper.d.ts b/TypeScript/17AsyncImporterWithDependency1/types/helpers/ItemHelper.d.ts index 6f1511c..5920d8a 100644 --- a/TypeScript/17AsyncImporterWithDependency1/types/helpers/ItemHelper.d.ts +++ b/TypeScript/17AsyncImporterWithDependency1/types/helpers/ItemHelper.d.ts @@ -225,6 +225,48 @@ declare class ItemHelper { * @returns true if item is flagged as quest item */ isQuestItem(tpl: string): boolean; + /** + * Checks to see if the item is *actually* moddable in-raid. Checks include the items existence in the database, the + * parent items existence in the database, the existence (and value) of the items RaidModdable property, and that + * the parents slot-required property exists, matches that of the item, and it's value. + * + * Note: this function does not preform any checks to see if the item and parent are *actually* related. + * + * @param item The item to be checked + * @param parent The parent of the item to be checked + * @returns True if the item is actually moddable, false if it is not, and null if the check cannot be performed. + */ + isRaidModdable(item: Item, parent: Item): boolean | null; + /** + * Retrieves the main parent item for a given attachment item. + * + * This method traverses up the hierarchy of items starting from a given `itemId`, until it finds the main parent + * item that is not an attached attachment itself. In other words, if you pass it an item id of a suppressor, it + * will traverse up the muzzle brake, barrel, upper receiver, and return the gun that the suppressor is ultimately + * attached to, even if that gun is located within multiple containers. + * + * It's important to note that traversal is expensive, so this method requires that you pass it a Map of the items + * to traverse, where the keys are the item IDs and the values are the corresponding Item objects. This alleviates + * some of the performance concerns, as it allows for quick lookups of items by ID. + * + * To generate the map: + * ``` + * const itemsMap = new Map(); + * items.forEach(item => itemsMap.set(item._id, item)); + * ``` + * + * @param itemId - The unique identifier of the item for which to find the main parent. + * @param itemsMap - A Map containing item IDs mapped to their corresponding Item objects for quick lookup. + * @returns The Item object representing the top-most parent of the given item, or `null` if no such parent exists. + */ + getAttachmentMainParent(itemId: string, itemsMap: Map): Item | null; + /** + * Determines if an item is an attachment that is currently attached to it's parent item. + * + * @param item The item to check. + * @returns true if the item is attached attachment, otherwise false. + */ + isAttachmentAttached(item: Item): boolean; /** * Get the inventory size of an item * @param items Item with children diff --git a/TypeScript/17AsyncImporterWithDependency1/types/loaders/PreAkiModLoader.d.ts b/TypeScript/17AsyncImporterWithDependency1/types/loaders/PreAkiModLoader.d.ts index 1e24b96..c0868b7 100644 --- a/TypeScript/17AsyncImporterWithDependency1/types/loaders/PreAkiModLoader.d.ts +++ b/TypeScript/17AsyncImporterWithDependency1/types/loaders/PreAkiModLoader.d.ts @@ -66,6 +66,10 @@ export declare class PreAkiModLoader implements IModLoader { protected isModCombatibleWithAki(mod: IPackageJsonData): boolean; protected executeMods(container: DependencyContainer): Promise; sortModsLoadOrder(): string[]; + /** + * Compile mod and add into class property "imported" + * @param mod Name of mod to compile/add + */ protected addMod(mod: string): Promise; protected autoInstallDependencies(modPath: string, pkg: IPackageJsonData): void; protected areModDependenciesFulfilled(pkg: IPackageJsonData, loadedMods: Record): boolean; diff --git a/TypeScript/17AsyncImporterWithDependency1/types/models/external/HttpFramework.d.ts b/TypeScript/17AsyncImporterWithDependency1/types/models/external/HttpFramework.d.ts index 64a37d6..fda8732 100644 --- a/TypeScript/17AsyncImporterWithDependency1/types/models/external/HttpFramework.d.ts +++ b/TypeScript/17AsyncImporterWithDependency1/types/models/external/HttpFramework.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export type HandleFn = (_: string, req: IncomingMessage, resp: ServerResponse) => void; /** * Associates handlers, HTTP methods and a base url to a listener using a proxy diff --git a/TypeScript/17AsyncImporterWithDependency1/types/models/spt/mod/IPackageJsonData.d.ts b/TypeScript/17AsyncImporterWithDependency1/types/models/spt/mod/IPackageJsonData.d.ts index 06f7454..f58d7cc 100644 --- a/TypeScript/17AsyncImporterWithDependency1/types/models/spt/mod/IPackageJsonData.d.ts +++ b/TypeScript/17AsyncImporterWithDependency1/types/models/spt/mod/IPackageJsonData.d.ts @@ -6,6 +6,9 @@ export interface IPackageJsonData { author: string; version: string; akiVersion: string; + /** We deliberately purge this data */ + scripts: Record; + devDependencies: Record; licence: string; main: string; isBundleMod: boolean; diff --git a/TypeScript/17AsyncImporterWithDependency1/types/routers/HttpRouter.d.ts b/TypeScript/17AsyncImporterWithDependency1/types/routers/HttpRouter.d.ts index f75a47d..46f847a 100644 --- a/TypeScript/17AsyncImporterWithDependency1/types/routers/HttpRouter.d.ts +++ b/TypeScript/17AsyncImporterWithDependency1/types/routers/HttpRouter.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage } from "http"; +import { IncomingMessage } from "node:http"; import { DynamicRouter, Router, StaticRouter } from "../di/Router"; export declare class HttpRouter { protected staticRouters: StaticRouter[]; diff --git a/TypeScript/17AsyncImporterWithDependency1/types/routers/ImageRouter.d.ts b/TypeScript/17AsyncImporterWithDependency1/types/routers/ImageRouter.d.ts index 675441c..fd03c59 100644 --- a/TypeScript/17AsyncImporterWithDependency1/types/routers/ImageRouter.d.ts +++ b/TypeScript/17AsyncImporterWithDependency1/types/routers/ImageRouter.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { ImageRouteService } from "../services/mod/image/ImageRouteService"; import { HttpFileUtil } from "../utils/HttpFileUtil"; import { VFS } from "../utils/VFS"; diff --git a/TypeScript/17AsyncImporterWithDependency1/types/routers/serializers/BundleSerializer.d.ts b/TypeScript/17AsyncImporterWithDependency1/types/routers/serializers/BundleSerializer.d.ts index ca4d8b6..db41142 100644 --- a/TypeScript/17AsyncImporterWithDependency1/types/routers/serializers/BundleSerializer.d.ts +++ b/TypeScript/17AsyncImporterWithDependency1/types/routers/serializers/BundleSerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { BundleLoader } from "../../loaders/BundleLoader"; import { ILogger } from "../../models/spt/utils/ILogger"; diff --git a/TypeScript/17AsyncImporterWithDependency1/types/routers/serializers/ImageSerializer.d.ts b/TypeScript/17AsyncImporterWithDependency1/types/routers/serializers/ImageSerializer.d.ts index 5de48ff..62ce84d 100644 --- a/TypeScript/17AsyncImporterWithDependency1/types/routers/serializers/ImageSerializer.d.ts +++ b/TypeScript/17AsyncImporterWithDependency1/types/routers/serializers/ImageSerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { ImageRouter } from "../ImageRouter"; export declare class ImageSerializer extends Serializer { diff --git a/TypeScript/17AsyncImporterWithDependency1/types/routers/serializers/NotifySerializer.d.ts b/TypeScript/17AsyncImporterWithDependency1/types/routers/serializers/NotifySerializer.d.ts index 1d179b2..e92d6e1 100644 --- a/TypeScript/17AsyncImporterWithDependency1/types/routers/serializers/NotifySerializer.d.ts +++ b/TypeScript/17AsyncImporterWithDependency1/types/routers/serializers/NotifySerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { NotifierController } from "../../controllers/NotifierController"; import { Serializer } from "../../di/Serializer"; import { HttpServerHelper } from "../../helpers/HttpServerHelper"; diff --git a/TypeScript/17AsyncImporterWithDependency1/types/servers/HttpServer.d.ts b/TypeScript/17AsyncImporterWithDependency1/types/servers/HttpServer.d.ts index 97e0705..c73eb3c 100644 --- a/TypeScript/17AsyncImporterWithDependency1/types/servers/HttpServer.d.ts +++ b/TypeScript/17AsyncImporterWithDependency1/types/servers/HttpServer.d.ts @@ -1,5 +1,5 @@ /// -import http, { IncomingMessage, ServerResponse } from "http"; +import http, { IncomingMessage, ServerResponse } from "node:http"; import { ApplicationContext } from "../context/ApplicationContext"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; import { IHttpConfig } from "../models/spt/config/IHttpConfig"; diff --git a/TypeScript/17AsyncImporterWithDependency1/types/servers/WebSocketServer.d.ts b/TypeScript/17AsyncImporterWithDependency1/types/servers/WebSocketServer.d.ts index fffbea2..b4c6158 100644 --- a/TypeScript/17AsyncImporterWithDependency1/types/servers/WebSocketServer.d.ts +++ b/TypeScript/17AsyncImporterWithDependency1/types/servers/WebSocketServer.d.ts @@ -1,5 +1,5 @@ /// -import http, { IncomingMessage } from "http"; +import http, { IncomingMessage } from "node:http"; import WebSocket from "ws"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; import { INotification } from "../models/eft/notifier/INotifier"; diff --git a/TypeScript/17AsyncImporterWithDependency1/types/servers/http/AkiHttpListener.d.ts b/TypeScript/17AsyncImporterWithDependency1/types/servers/http/AkiHttpListener.d.ts index c72e18f..e4ac80c 100644 --- a/TypeScript/17AsyncImporterWithDependency1/types/servers/http/AkiHttpListener.d.ts +++ b/TypeScript/17AsyncImporterWithDependency1/types/servers/http/AkiHttpListener.d.ts @@ -1,6 +1,6 @@ /// /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { ILogger } from "../../models/spt/utils/ILogger"; import { HttpRouter } from "../../routers/HttpRouter"; diff --git a/TypeScript/17AsyncImporterWithDependency1/types/servers/http/IHttpListener.d.ts b/TypeScript/17AsyncImporterWithDependency1/types/servers/http/IHttpListener.d.ts index 758bb5a..29d5fce 100644 --- a/TypeScript/17AsyncImporterWithDependency1/types/servers/http/IHttpListener.d.ts +++ b/TypeScript/17AsyncImporterWithDependency1/types/servers/http/IHttpListener.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export interface IHttpListener { canHandle(sessionId: string, req: IncomingMessage): boolean; handle(sessionId: string, req: IncomingMessage, resp: ServerResponse): void; diff --git a/TypeScript/17AsyncImporterWithDependency1/types/services/mod/httpListener/HttpListenerMod.d.ts b/TypeScript/17AsyncImporterWithDependency1/types/services/mod/httpListener/HttpListenerMod.d.ts index 2cdfbda..afe4574 100644 --- a/TypeScript/17AsyncImporterWithDependency1/types/services/mod/httpListener/HttpListenerMod.d.ts +++ b/TypeScript/17AsyncImporterWithDependency1/types/services/mod/httpListener/HttpListenerMod.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { IHttpListener } from "../../../servers/http/IHttpListener"; export declare class HttpListenerMod implements IHttpListener { private canHandleOverride; diff --git a/TypeScript/17AsyncImporterWithDependency1/types/services/mod/httpListener/HttpListenerModService.d.ts b/TypeScript/17AsyncImporterWithDependency1/types/services/mod/httpListener/HttpListenerModService.d.ts index 9dd3473..23abfbe 100644 --- a/TypeScript/17AsyncImporterWithDependency1/types/services/mod/httpListener/HttpListenerModService.d.ts +++ b/TypeScript/17AsyncImporterWithDependency1/types/services/mod/httpListener/HttpListenerModService.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { DependencyContainer } from "tsyringe"; export declare class HttpListenerModService { protected container: DependencyContainer; diff --git a/TypeScript/17AsyncImporterWithDependency1/types/utils/App.d.ts b/TypeScript/17AsyncImporterWithDependency1/types/utils/App.d.ts index dd8f24c..5e759ad 100644 --- a/TypeScript/17AsyncImporterWithDependency1/types/utils/App.d.ts +++ b/TypeScript/17AsyncImporterWithDependency1/types/utils/App.d.ts @@ -12,7 +12,6 @@ export declare class App { protected onLoadComponents: OnLoad[]; protected onUpdateComponents: OnUpdate[]; protected onUpdateLastRun: {}; - protected os: any; constructor(logger: ILogger, timeUtil: TimeUtil, localisationService: LocalisationService, encodingUtil: EncodingUtil, onLoadComponents: OnLoad[], onUpdateComponents: OnUpdate[]); load(): Promise; protected update(onUpdateComponents: OnUpdate[]): Promise; diff --git a/TypeScript/17AsyncImporterWithDependency1/types/utils/HashUtil.d.ts b/TypeScript/17AsyncImporterWithDependency1/types/utils/HashUtil.d.ts index c017ca8..27204cb 100644 --- a/TypeScript/17AsyncImporterWithDependency1/types/utils/HashUtil.d.ts +++ b/TypeScript/17AsyncImporterWithDependency1/types/utils/HashUtil.d.ts @@ -1,5 +1,5 @@ /// -import crypto from "crypto"; +import crypto from "node:crypto"; import { TimeUtil } from "./TimeUtil"; export declare class HashUtil { protected timeUtil: TimeUtil; diff --git a/TypeScript/17AsyncImporterWithDependency1/types/utils/HttpFileUtil.d.ts b/TypeScript/17AsyncImporterWithDependency1/types/utils/HttpFileUtil.d.ts index afc8409..6a386ce 100644 --- a/TypeScript/17AsyncImporterWithDependency1/types/utils/HttpFileUtil.d.ts +++ b/TypeScript/17AsyncImporterWithDependency1/types/utils/HttpFileUtil.d.ts @@ -1,5 +1,5 @@ /// -import { ServerResponse } from "http"; +import { ServerResponse } from "node:http"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; export declare class HttpFileUtil { protected httpServerHelper: HttpServerHelper; diff --git a/TypeScript/17AsyncImporterWithDependency1/types/utils/VFS.d.ts b/TypeScript/17AsyncImporterWithDependency1/types/utils/VFS.d.ts index 2cb09fa..3911c4b 100644 --- a/TypeScript/17AsyncImporterWithDependency1/types/utils/VFS.d.ts +++ b/TypeScript/17AsyncImporterWithDependency1/types/utils/VFS.d.ts @@ -1,6 +1,6 @@ /// /// -import fs from "fs"; +import fs from "node:fs"; import "reflect-metadata"; import { IAsyncQueue } from "../models/spt/utils/IAsyncQueue"; import { IUUidGenerator } from "../models/spt/utils/IUuidGenerator"; diff --git a/TypeScript/17AsyncImporterWithDependency1/types/utils/Watermark.d.ts b/TypeScript/17AsyncImporterWithDependency1/types/utils/Watermark.d.ts index fa63205..864e9b6 100644 --- a/TypeScript/17AsyncImporterWithDependency1/types/utils/Watermark.d.ts +++ b/TypeScript/17AsyncImporterWithDependency1/types/utils/Watermark.d.ts @@ -4,12 +4,10 @@ import { ConfigServer } from "../servers/ConfigServer"; import { LocalisationService } from "../services/LocalisationService"; export declare class WatermarkLocale { protected localisationService: LocalisationService; + protected description: string[]; + protected warning: string[]; + protected modding: string[]; constructor(localisationService: LocalisationService); - protected watermark: { - description: string[]; - warning: string[]; - modding: string[]; - }; getDescription(): string[]; getWarning(): string[]; getModding(): string[]; diff --git a/TypeScript/17AsyncImporterWithDependency1/types/utils/logging/AbstractWinstonLogger.d.ts b/TypeScript/17AsyncImporterWithDependency1/types/utils/logging/AbstractWinstonLogger.d.ts index 1ae1100..74767a2 100644 --- a/TypeScript/17AsyncImporterWithDependency1/types/utils/logging/AbstractWinstonLogger.d.ts +++ b/TypeScript/17AsyncImporterWithDependency1/types/utils/logging/AbstractWinstonLogger.d.ts @@ -1,5 +1,5 @@ /// -import fs from "fs"; +import fs from "node:fs"; import winston from "winston"; import { Daum } from "../../models/eft/itemEvent/IItemEventRouterRequest"; import { LogBackgroundColor } from "../../models/spt/logging/LogBackgroundColor"; diff --git a/TypeScript/17AsyncImporterWithDependency2/types/controllers/GameController.d.ts b/TypeScript/17AsyncImporterWithDependency2/types/controllers/GameController.d.ts index 73596ff..74123b2 100644 --- a/TypeScript/17AsyncImporterWithDependency2/types/controllers/GameController.d.ts +++ b/TypeScript/17AsyncImporterWithDependency2/types/controllers/GameController.d.ts @@ -49,7 +49,6 @@ export declare class GameController { protected giftService: GiftService; protected applicationContext: ApplicationContext; protected configServer: ConfigServer; - protected os: any; protected httpConfig: IHttpConfig; protected coreConfig: ICoreConfig; protected locationConfig: ILocationConfig; diff --git a/TypeScript/17AsyncImporterWithDependency2/types/controllers/InsuranceController.d.ts b/TypeScript/17AsyncImporterWithDependency2/types/controllers/InsuranceController.d.ts index fb41610..fc3229b 100644 --- a/TypeScript/17AsyncImporterWithDependency2/types/controllers/InsuranceController.d.ts +++ b/TypeScript/17AsyncImporterWithDependency2/types/controllers/InsuranceController.d.ts @@ -4,7 +4,6 @@ import { ProfileHelper } from "../helpers/ProfileHelper"; import { TraderHelper } from "../helpers/TraderHelper"; import { IPmcData } from "../models/eft/common/IPmcData"; import { Item } from "../models/eft/common/tables/IItem"; -import { ITemplateItem } from "../models/eft/common/tables/ITemplateItem"; import { IGetInsuranceCostRequestData } from "../models/eft/insurance/IGetInsuranceCostRequestData"; import { IGetInsuranceCostResponseData } from "../models/eft/insurance/IGetInsuranceCostResponseData"; import { IInsureRequestData } from "../models/eft/insurance/IInsureRequestData"; @@ -75,67 +74,92 @@ export declare class InsuranceController { */ protected removeInsurancePackageFromProfile(sessionID: string, packageInfo: ISystemData): void; /** - * Build an array of items to delete from the insured items. + * Finds the items that should be deleted based on the given Insurance object. * - * This method orchestrates several steps: - * - Filters items based on their presence in the database and their raid moddability. - * - Sorts base and independent child items to consider for deletion. - * - Groups child items by their parent for later evaluation. - * - Evaluates grouped child items to decide which should be deleted, based on their value and a random roll. - * - * @param insured - The insured items to build a removal array from. - * @returns An array of IDs representing items that should be deleted. + * @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(insured: Insurance): Set; /** - * Filters an item based on its existence in the database, raid moddability, and slot requirements. + * Populate a Map object of items for quick lookup by their ID. * - * @param item The item to be filtered. - * @param parentItemDbDetails The database details of the parent item, or null if the item has no parent. - * @param itemDbDetails A tuple where the first element is a boolean indicating if the item exists in the database, - * and the second element is the item details if it does. - * @returns true if the item exists in the database and neither of the following conditions are met: - * - The item has the RaidModdable property set to false. - * - The item is attached to a required slot in its parent item. - * Otherwise, returns false. + * @param insured The insurance object containing the items to populate the map with. + * @returns A Map where the keys are the item IDs and the values are the corresponding Item objects. */ - protected filterByRaidModdability(item: Item, parentItemDbDetails: ITemplateItem | null, itemDbDetails: [boolean, ITemplateItem]): boolean; + protected populateItemsMap(insured: Insurance): Map; /** - * Determines if an item is either a base item or a child item that is not equipped to its parent. + * 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 item The item to check. - * @returns true if the item is a base or an independent child item, otherwise false. + * @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. */ - protected isBaseOrIndependentChild(item: Item): boolean; + protected populateParentAttachmentsMap(insured: Insurance, itemsMap: Map): Map; /** - * Makes a roll to determine if a given item should be deleted. If the roll is successful, the item's ID is added - * to the `toDelete` array. + * 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. * - * @param item The item for which the roll is made. - * @param traderId The ID of the trader to consider in the rollForItemDelete method. - * @param toDelete The array accumulating the IDs of items to be deleted. - * @returns true if the item is marked for deletion, otherwise false. - */ - protected makeRollAndMarkForDeletion(item: Item, traderId: string, toDelete: Set): boolean; - /** - * Groups child items by their parent IDs in a Map data structure. - * - * @param item The child item to be grouped by its parent. - * @param childrenGroupedByParent The Map that holds arrays of children items grouped by their parent IDs. + * @param insured The insurance object containing the items to evaluate. + * @param toDelete A Set to keep track of items marked for deletion. * @returns void */ - protected groupChildrenByParent(item: Item, childrenGroupedByParent: Map): void; + protected processRegularItems(insured: Insurance, toDelete: Set): void; /** - * Sorts the array of children items in descending order by their maximum price. For each child, a roll is made to - * determine if it should be deleted. The method then deletes the most valuable children based on the number of - * successful rolls made. + * Process parent items and their attachments, updating the toDelete Set accordingly. * - * @param children The array of children items to sort and filter. - * @param traderId The ID of the trader to consider in the rollForItemDelete method. + * This method iterates over a map of parent items to their attachments and performs evaluations on each. + * It marks items for deletion based on certain conditions and updates the toDelete Set accordingly. + * + * @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. + */ + protected processAttachments(mainParentToAttachmentsMap: Map, itemsMap: Map, traderId: string, toDelete: Set): void; + /** + * 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. + * + * @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. * @returns void */ - protected sortAndFilterChildren(children: Item[], traderId: string, toDelete: Set): void; + protected processAttachmentByParent(attachments: Item[], traderId: string, toDelete: Set): void; + /** + * Sorts the attachment items by their max price in descending order. + * + * @param attachments The array of attachments items. + * @returns An array of items enriched with their max price and common locale-name. + */ + protected sortAttachmentsByPrice(attachments: Item[]): EnrichedItem[]; + /** + * Logs the details of each attachment item. + * + * @param attachments The array of attachment items. + */ + protected logAttachmentsDetails(attachments: EnrichedItem[]): void; + /** + * Counts the number of successful rolls for the attachment items. + * + * @param attachments The array of attachment items. + * @param traderId The ID of the trader that has insured these attachments. + * @returns The number of successful rolls. + */ + protected countSuccessfulRolls(attachments: Item[], traderId: string): number; + /** + * Marks the most valuable attachments for deletion based on the number of successful rolls made. + * + * @param attachments The array of attachment items. + * @param successfulRolls The number of successful rolls. + * @param toDelete The array that accumulates the IDs of the items to be deleted. + */ + protected attachmentDeletionByValue(attachments: EnrichedItem[], successfulRolls: number, toDelete: Set): void; /** * Remove items from the insured items that should not be returned to the player. * @@ -144,6 +168,22 @@ export declare class InsuranceController { * @returns void */ protected removeItemsFromInsurance(insured: Insurance, toDelete: Set): void; + /** + * Adopts orphaned items by resetting them as base-level items. Helpful in situations where a parent has been + * deleted from insurance, but any insured items within the parent should remain. This method will remove the + * reference from the children to the parent and set item properties to main-level values. + * + * @param insured Insurance object containing items. + */ + protected adoptOrphanedItems(insured: Insurance): void; + /** + * Fetches the parentId property of an item with a slotId "hideout". Not sure if this is actually dynamic, but this + * method should be a reliable way to fetch it, if it ever does change. + * + * @param items Array of items to search through. + * @returns The parentId of an item with slotId 'hideout'. Empty string if not found. + */ + protected fetchHideoutItemParent(items: Item[]): string; /** * Handle sending the insurance message to the user that potentially contains the valid insurance items. * @@ -154,15 +194,14 @@ export declare class InsuranceController { */ protected sendMail(sessionID: string, insurance: Insurance, noItems: boolean): void; /** - * Determines whether a valid insured item should be removed from the player's inventory based on a random roll and + * Determines whether a insured item should be removed from the player's inventory based on a random roll and * trader-specific return chance. * - * @param insuredItem The insured item being evaluated for removal. * @param traderId The ID of the trader who insured the item. - * @param itemsBeingDeleted List of items that are already slated for removal. + * @param insuredItem Optional. The item to roll for. Only used for logging. * @returns true if the insured item should be removed from inventory, false otherwise. */ - protected rollForItemDelete(insuredItem: Item, traderId: string, itemsBeingDeleted: Set): boolean; + protected rollForDelete(traderId: string, insuredItem?: Item): boolean; /** * Handle Insure event * Add insurance to an item @@ -183,3 +222,8 @@ export declare class InsuranceController { */ cost(request: IGetInsuranceCostRequestData, sessionID: string): IGetInsuranceCostResponseData; } +interface EnrichedItem extends Item { + name: string; + maxPrice: number; +} +export {}; diff --git a/TypeScript/17AsyncImporterWithDependency2/types/di/Serializer.d.ts b/TypeScript/17AsyncImporterWithDependency2/types/di/Serializer.d.ts index 2617007..b760b8b 100644 --- a/TypeScript/17AsyncImporterWithDependency2/types/di/Serializer.d.ts +++ b/TypeScript/17AsyncImporterWithDependency2/types/di/Serializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export declare class Serializer { serialize(sessionID: string, req: IncomingMessage, resp: ServerResponse, body: any): void; canHandle(something: string): boolean; diff --git a/TypeScript/17AsyncImporterWithDependency2/types/helpers/ItemHelper.d.ts b/TypeScript/17AsyncImporterWithDependency2/types/helpers/ItemHelper.d.ts index 6f1511c..5920d8a 100644 --- a/TypeScript/17AsyncImporterWithDependency2/types/helpers/ItemHelper.d.ts +++ b/TypeScript/17AsyncImporterWithDependency2/types/helpers/ItemHelper.d.ts @@ -225,6 +225,48 @@ declare class ItemHelper { * @returns true if item is flagged as quest item */ isQuestItem(tpl: string): boolean; + /** + * Checks to see if the item is *actually* moddable in-raid. Checks include the items existence in the database, the + * parent items existence in the database, the existence (and value) of the items RaidModdable property, and that + * the parents slot-required property exists, matches that of the item, and it's value. + * + * Note: this function does not preform any checks to see if the item and parent are *actually* related. + * + * @param item The item to be checked + * @param parent The parent of the item to be checked + * @returns True if the item is actually moddable, false if it is not, and null if the check cannot be performed. + */ + isRaidModdable(item: Item, parent: Item): boolean | null; + /** + * Retrieves the main parent item for a given attachment item. + * + * This method traverses up the hierarchy of items starting from a given `itemId`, until it finds the main parent + * item that is not an attached attachment itself. In other words, if you pass it an item id of a suppressor, it + * will traverse up the muzzle brake, barrel, upper receiver, and return the gun that the suppressor is ultimately + * attached to, even if that gun is located within multiple containers. + * + * It's important to note that traversal is expensive, so this method requires that you pass it a Map of the items + * to traverse, where the keys are the item IDs and the values are the corresponding Item objects. This alleviates + * some of the performance concerns, as it allows for quick lookups of items by ID. + * + * To generate the map: + * ``` + * const itemsMap = new Map(); + * items.forEach(item => itemsMap.set(item._id, item)); + * ``` + * + * @param itemId - The unique identifier of the item for which to find the main parent. + * @param itemsMap - A Map containing item IDs mapped to their corresponding Item objects for quick lookup. + * @returns The Item object representing the top-most parent of the given item, or `null` if no such parent exists. + */ + getAttachmentMainParent(itemId: string, itemsMap: Map): Item | null; + /** + * Determines if an item is an attachment that is currently attached to it's parent item. + * + * @param item The item to check. + * @returns true if the item is attached attachment, otherwise false. + */ + isAttachmentAttached(item: Item): boolean; /** * Get the inventory size of an item * @param items Item with children diff --git a/TypeScript/17AsyncImporterWithDependency2/types/loaders/PreAkiModLoader.d.ts b/TypeScript/17AsyncImporterWithDependency2/types/loaders/PreAkiModLoader.d.ts index 1e24b96..c0868b7 100644 --- a/TypeScript/17AsyncImporterWithDependency2/types/loaders/PreAkiModLoader.d.ts +++ b/TypeScript/17AsyncImporterWithDependency2/types/loaders/PreAkiModLoader.d.ts @@ -66,6 +66,10 @@ export declare class PreAkiModLoader implements IModLoader { protected isModCombatibleWithAki(mod: IPackageJsonData): boolean; protected executeMods(container: DependencyContainer): Promise; sortModsLoadOrder(): string[]; + /** + * Compile mod and add into class property "imported" + * @param mod Name of mod to compile/add + */ protected addMod(mod: string): Promise; protected autoInstallDependencies(modPath: string, pkg: IPackageJsonData): void; protected areModDependenciesFulfilled(pkg: IPackageJsonData, loadedMods: Record): boolean; diff --git a/TypeScript/17AsyncImporterWithDependency2/types/models/external/HttpFramework.d.ts b/TypeScript/17AsyncImporterWithDependency2/types/models/external/HttpFramework.d.ts index 64a37d6..fda8732 100644 --- a/TypeScript/17AsyncImporterWithDependency2/types/models/external/HttpFramework.d.ts +++ b/TypeScript/17AsyncImporterWithDependency2/types/models/external/HttpFramework.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export type HandleFn = (_: string, req: IncomingMessage, resp: ServerResponse) => void; /** * Associates handlers, HTTP methods and a base url to a listener using a proxy diff --git a/TypeScript/17AsyncImporterWithDependency2/types/models/spt/mod/IPackageJsonData.d.ts b/TypeScript/17AsyncImporterWithDependency2/types/models/spt/mod/IPackageJsonData.d.ts index 06f7454..f58d7cc 100644 --- a/TypeScript/17AsyncImporterWithDependency2/types/models/spt/mod/IPackageJsonData.d.ts +++ b/TypeScript/17AsyncImporterWithDependency2/types/models/spt/mod/IPackageJsonData.d.ts @@ -6,6 +6,9 @@ export interface IPackageJsonData { author: string; version: string; akiVersion: string; + /** We deliberately purge this data */ + scripts: Record; + devDependencies: Record; licence: string; main: string; isBundleMod: boolean; diff --git a/TypeScript/17AsyncImporterWithDependency2/types/routers/HttpRouter.d.ts b/TypeScript/17AsyncImporterWithDependency2/types/routers/HttpRouter.d.ts index f75a47d..46f847a 100644 --- a/TypeScript/17AsyncImporterWithDependency2/types/routers/HttpRouter.d.ts +++ b/TypeScript/17AsyncImporterWithDependency2/types/routers/HttpRouter.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage } from "http"; +import { IncomingMessage } from "node:http"; import { DynamicRouter, Router, StaticRouter } from "../di/Router"; export declare class HttpRouter { protected staticRouters: StaticRouter[]; diff --git a/TypeScript/17AsyncImporterWithDependency2/types/routers/ImageRouter.d.ts b/TypeScript/17AsyncImporterWithDependency2/types/routers/ImageRouter.d.ts index 675441c..fd03c59 100644 --- a/TypeScript/17AsyncImporterWithDependency2/types/routers/ImageRouter.d.ts +++ b/TypeScript/17AsyncImporterWithDependency2/types/routers/ImageRouter.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { ImageRouteService } from "../services/mod/image/ImageRouteService"; import { HttpFileUtil } from "../utils/HttpFileUtil"; import { VFS } from "../utils/VFS"; diff --git a/TypeScript/17AsyncImporterWithDependency2/types/routers/serializers/BundleSerializer.d.ts b/TypeScript/17AsyncImporterWithDependency2/types/routers/serializers/BundleSerializer.d.ts index ca4d8b6..db41142 100644 --- a/TypeScript/17AsyncImporterWithDependency2/types/routers/serializers/BundleSerializer.d.ts +++ b/TypeScript/17AsyncImporterWithDependency2/types/routers/serializers/BundleSerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { BundleLoader } from "../../loaders/BundleLoader"; import { ILogger } from "../../models/spt/utils/ILogger"; diff --git a/TypeScript/17AsyncImporterWithDependency2/types/routers/serializers/ImageSerializer.d.ts b/TypeScript/17AsyncImporterWithDependency2/types/routers/serializers/ImageSerializer.d.ts index 5de48ff..62ce84d 100644 --- a/TypeScript/17AsyncImporterWithDependency2/types/routers/serializers/ImageSerializer.d.ts +++ b/TypeScript/17AsyncImporterWithDependency2/types/routers/serializers/ImageSerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { ImageRouter } from "../ImageRouter"; export declare class ImageSerializer extends Serializer { diff --git a/TypeScript/17AsyncImporterWithDependency2/types/routers/serializers/NotifySerializer.d.ts b/TypeScript/17AsyncImporterWithDependency2/types/routers/serializers/NotifySerializer.d.ts index 1d179b2..e92d6e1 100644 --- a/TypeScript/17AsyncImporterWithDependency2/types/routers/serializers/NotifySerializer.d.ts +++ b/TypeScript/17AsyncImporterWithDependency2/types/routers/serializers/NotifySerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { NotifierController } from "../../controllers/NotifierController"; import { Serializer } from "../../di/Serializer"; import { HttpServerHelper } from "../../helpers/HttpServerHelper"; diff --git a/TypeScript/17AsyncImporterWithDependency2/types/servers/HttpServer.d.ts b/TypeScript/17AsyncImporterWithDependency2/types/servers/HttpServer.d.ts index 97e0705..c73eb3c 100644 --- a/TypeScript/17AsyncImporterWithDependency2/types/servers/HttpServer.d.ts +++ b/TypeScript/17AsyncImporterWithDependency2/types/servers/HttpServer.d.ts @@ -1,5 +1,5 @@ /// -import http, { IncomingMessage, ServerResponse } from "http"; +import http, { IncomingMessage, ServerResponse } from "node:http"; import { ApplicationContext } from "../context/ApplicationContext"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; import { IHttpConfig } from "../models/spt/config/IHttpConfig"; diff --git a/TypeScript/17AsyncImporterWithDependency2/types/servers/WebSocketServer.d.ts b/TypeScript/17AsyncImporterWithDependency2/types/servers/WebSocketServer.d.ts index fffbea2..b4c6158 100644 --- a/TypeScript/17AsyncImporterWithDependency2/types/servers/WebSocketServer.d.ts +++ b/TypeScript/17AsyncImporterWithDependency2/types/servers/WebSocketServer.d.ts @@ -1,5 +1,5 @@ /// -import http, { IncomingMessage } from "http"; +import http, { IncomingMessage } from "node:http"; import WebSocket from "ws"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; import { INotification } from "../models/eft/notifier/INotifier"; diff --git a/TypeScript/17AsyncImporterWithDependency2/types/servers/http/AkiHttpListener.d.ts b/TypeScript/17AsyncImporterWithDependency2/types/servers/http/AkiHttpListener.d.ts index c72e18f..e4ac80c 100644 --- a/TypeScript/17AsyncImporterWithDependency2/types/servers/http/AkiHttpListener.d.ts +++ b/TypeScript/17AsyncImporterWithDependency2/types/servers/http/AkiHttpListener.d.ts @@ -1,6 +1,6 @@ /// /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { ILogger } from "../../models/spt/utils/ILogger"; import { HttpRouter } from "../../routers/HttpRouter"; diff --git a/TypeScript/17AsyncImporterWithDependency2/types/servers/http/IHttpListener.d.ts b/TypeScript/17AsyncImporterWithDependency2/types/servers/http/IHttpListener.d.ts index 758bb5a..29d5fce 100644 --- a/TypeScript/17AsyncImporterWithDependency2/types/servers/http/IHttpListener.d.ts +++ b/TypeScript/17AsyncImporterWithDependency2/types/servers/http/IHttpListener.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export interface IHttpListener { canHandle(sessionId: string, req: IncomingMessage): boolean; handle(sessionId: string, req: IncomingMessage, resp: ServerResponse): void; diff --git a/TypeScript/17AsyncImporterWithDependency2/types/services/mod/httpListener/HttpListenerMod.d.ts b/TypeScript/17AsyncImporterWithDependency2/types/services/mod/httpListener/HttpListenerMod.d.ts index 2cdfbda..afe4574 100644 --- a/TypeScript/17AsyncImporterWithDependency2/types/services/mod/httpListener/HttpListenerMod.d.ts +++ b/TypeScript/17AsyncImporterWithDependency2/types/services/mod/httpListener/HttpListenerMod.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { IHttpListener } from "../../../servers/http/IHttpListener"; export declare class HttpListenerMod implements IHttpListener { private canHandleOverride; diff --git a/TypeScript/17AsyncImporterWithDependency2/types/services/mod/httpListener/HttpListenerModService.d.ts b/TypeScript/17AsyncImporterWithDependency2/types/services/mod/httpListener/HttpListenerModService.d.ts index 9dd3473..23abfbe 100644 --- a/TypeScript/17AsyncImporterWithDependency2/types/services/mod/httpListener/HttpListenerModService.d.ts +++ b/TypeScript/17AsyncImporterWithDependency2/types/services/mod/httpListener/HttpListenerModService.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { DependencyContainer } from "tsyringe"; export declare class HttpListenerModService { protected container: DependencyContainer; diff --git a/TypeScript/17AsyncImporterWithDependency2/types/utils/App.d.ts b/TypeScript/17AsyncImporterWithDependency2/types/utils/App.d.ts index dd8f24c..5e759ad 100644 --- a/TypeScript/17AsyncImporterWithDependency2/types/utils/App.d.ts +++ b/TypeScript/17AsyncImporterWithDependency2/types/utils/App.d.ts @@ -12,7 +12,6 @@ export declare class App { protected onLoadComponents: OnLoad[]; protected onUpdateComponents: OnUpdate[]; protected onUpdateLastRun: {}; - protected os: any; constructor(logger: ILogger, timeUtil: TimeUtil, localisationService: LocalisationService, encodingUtil: EncodingUtil, onLoadComponents: OnLoad[], onUpdateComponents: OnUpdate[]); load(): Promise; protected update(onUpdateComponents: OnUpdate[]): Promise; diff --git a/TypeScript/17AsyncImporterWithDependency2/types/utils/HashUtil.d.ts b/TypeScript/17AsyncImporterWithDependency2/types/utils/HashUtil.d.ts index c017ca8..27204cb 100644 --- a/TypeScript/17AsyncImporterWithDependency2/types/utils/HashUtil.d.ts +++ b/TypeScript/17AsyncImporterWithDependency2/types/utils/HashUtil.d.ts @@ -1,5 +1,5 @@ /// -import crypto from "crypto"; +import crypto from "node:crypto"; import { TimeUtil } from "./TimeUtil"; export declare class HashUtil { protected timeUtil: TimeUtil; diff --git a/TypeScript/17AsyncImporterWithDependency2/types/utils/HttpFileUtil.d.ts b/TypeScript/17AsyncImporterWithDependency2/types/utils/HttpFileUtil.d.ts index afc8409..6a386ce 100644 --- a/TypeScript/17AsyncImporterWithDependency2/types/utils/HttpFileUtil.d.ts +++ b/TypeScript/17AsyncImporterWithDependency2/types/utils/HttpFileUtil.d.ts @@ -1,5 +1,5 @@ /// -import { ServerResponse } from "http"; +import { ServerResponse } from "node:http"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; export declare class HttpFileUtil { protected httpServerHelper: HttpServerHelper; diff --git a/TypeScript/17AsyncImporterWithDependency2/types/utils/VFS.d.ts b/TypeScript/17AsyncImporterWithDependency2/types/utils/VFS.d.ts index 2cb09fa..3911c4b 100644 --- a/TypeScript/17AsyncImporterWithDependency2/types/utils/VFS.d.ts +++ b/TypeScript/17AsyncImporterWithDependency2/types/utils/VFS.d.ts @@ -1,6 +1,6 @@ /// /// -import fs from "fs"; +import fs from "node:fs"; import "reflect-metadata"; import { IAsyncQueue } from "../models/spt/utils/IAsyncQueue"; import { IUUidGenerator } from "../models/spt/utils/IUuidGenerator"; diff --git a/TypeScript/17AsyncImporterWithDependency2/types/utils/Watermark.d.ts b/TypeScript/17AsyncImporterWithDependency2/types/utils/Watermark.d.ts index fa63205..864e9b6 100644 --- a/TypeScript/17AsyncImporterWithDependency2/types/utils/Watermark.d.ts +++ b/TypeScript/17AsyncImporterWithDependency2/types/utils/Watermark.d.ts @@ -4,12 +4,10 @@ import { ConfigServer } from "../servers/ConfigServer"; import { LocalisationService } from "../services/LocalisationService"; export declare class WatermarkLocale { protected localisationService: LocalisationService; + protected description: string[]; + protected warning: string[]; + protected modding: string[]; constructor(localisationService: LocalisationService); - protected watermark: { - description: string[]; - warning: string[]; - modding: string[]; - }; getDescription(): string[]; getWarning(): string[]; getModding(): string[]; diff --git a/TypeScript/17AsyncImporterWithDependency2/types/utils/logging/AbstractWinstonLogger.d.ts b/TypeScript/17AsyncImporterWithDependency2/types/utils/logging/AbstractWinstonLogger.d.ts index 1ae1100..74767a2 100644 --- a/TypeScript/17AsyncImporterWithDependency2/types/utils/logging/AbstractWinstonLogger.d.ts +++ b/TypeScript/17AsyncImporterWithDependency2/types/utils/logging/AbstractWinstonLogger.d.ts @@ -1,5 +1,5 @@ /// -import fs from "fs"; +import fs from "node:fs"; import winston from "winston"; import { Daum } from "../../models/eft/itemEvent/IItemEventRouterRequest"; import { LogBackgroundColor } from "../../models/spt/logging/LogBackgroundColor"; diff --git a/TypeScript/18CustomItemService/types/controllers/GameController.d.ts b/TypeScript/18CustomItemService/types/controllers/GameController.d.ts index 73596ff..74123b2 100644 --- a/TypeScript/18CustomItemService/types/controllers/GameController.d.ts +++ b/TypeScript/18CustomItemService/types/controllers/GameController.d.ts @@ -49,7 +49,6 @@ export declare class GameController { protected giftService: GiftService; protected applicationContext: ApplicationContext; protected configServer: ConfigServer; - protected os: any; protected httpConfig: IHttpConfig; protected coreConfig: ICoreConfig; protected locationConfig: ILocationConfig; diff --git a/TypeScript/18CustomItemService/types/controllers/InsuranceController.d.ts b/TypeScript/18CustomItemService/types/controllers/InsuranceController.d.ts index fb41610..fc3229b 100644 --- a/TypeScript/18CustomItemService/types/controllers/InsuranceController.d.ts +++ b/TypeScript/18CustomItemService/types/controllers/InsuranceController.d.ts @@ -4,7 +4,6 @@ import { ProfileHelper } from "../helpers/ProfileHelper"; import { TraderHelper } from "../helpers/TraderHelper"; import { IPmcData } from "../models/eft/common/IPmcData"; import { Item } from "../models/eft/common/tables/IItem"; -import { ITemplateItem } from "../models/eft/common/tables/ITemplateItem"; import { IGetInsuranceCostRequestData } from "../models/eft/insurance/IGetInsuranceCostRequestData"; import { IGetInsuranceCostResponseData } from "../models/eft/insurance/IGetInsuranceCostResponseData"; import { IInsureRequestData } from "../models/eft/insurance/IInsureRequestData"; @@ -75,67 +74,92 @@ export declare class InsuranceController { */ protected removeInsurancePackageFromProfile(sessionID: string, packageInfo: ISystemData): void; /** - * Build an array of items to delete from the insured items. + * Finds the items that should be deleted based on the given Insurance object. * - * This method orchestrates several steps: - * - Filters items based on their presence in the database and their raid moddability. - * - Sorts base and independent child items to consider for deletion. - * - Groups child items by their parent for later evaluation. - * - Evaluates grouped child items to decide which should be deleted, based on their value and a random roll. - * - * @param insured - The insured items to build a removal array from. - * @returns An array of IDs representing items that should be deleted. + * @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(insured: Insurance): Set; /** - * Filters an item based on its existence in the database, raid moddability, and slot requirements. + * Populate a Map object of items for quick lookup by their ID. * - * @param item The item to be filtered. - * @param parentItemDbDetails The database details of the parent item, or null if the item has no parent. - * @param itemDbDetails A tuple where the first element is a boolean indicating if the item exists in the database, - * and the second element is the item details if it does. - * @returns true if the item exists in the database and neither of the following conditions are met: - * - The item has the RaidModdable property set to false. - * - The item is attached to a required slot in its parent item. - * Otherwise, returns false. + * @param insured The insurance object containing the items to populate the map with. + * @returns A Map where the keys are the item IDs and the values are the corresponding Item objects. */ - protected filterByRaidModdability(item: Item, parentItemDbDetails: ITemplateItem | null, itemDbDetails: [boolean, ITemplateItem]): boolean; + protected populateItemsMap(insured: Insurance): Map; /** - * Determines if an item is either a base item or a child item that is not equipped to its parent. + * 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 item The item to check. - * @returns true if the item is a base or an independent child item, otherwise false. + * @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. */ - protected isBaseOrIndependentChild(item: Item): boolean; + protected populateParentAttachmentsMap(insured: Insurance, itemsMap: Map): Map; /** - * Makes a roll to determine if a given item should be deleted. If the roll is successful, the item's ID is added - * to the `toDelete` array. + * 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. * - * @param item The item for which the roll is made. - * @param traderId The ID of the trader to consider in the rollForItemDelete method. - * @param toDelete The array accumulating the IDs of items to be deleted. - * @returns true if the item is marked for deletion, otherwise false. - */ - protected makeRollAndMarkForDeletion(item: Item, traderId: string, toDelete: Set): boolean; - /** - * Groups child items by their parent IDs in a Map data structure. - * - * @param item The child item to be grouped by its parent. - * @param childrenGroupedByParent The Map that holds arrays of children items grouped by their parent IDs. + * @param insured The insurance object containing the items to evaluate. + * @param toDelete A Set to keep track of items marked for deletion. * @returns void */ - protected groupChildrenByParent(item: Item, childrenGroupedByParent: Map): void; + protected processRegularItems(insured: Insurance, toDelete: Set): void; /** - * Sorts the array of children items in descending order by their maximum price. For each child, a roll is made to - * determine if it should be deleted. The method then deletes the most valuable children based on the number of - * successful rolls made. + * Process parent items and their attachments, updating the toDelete Set accordingly. * - * @param children The array of children items to sort and filter. - * @param traderId The ID of the trader to consider in the rollForItemDelete method. + * This method iterates over a map of parent items to their attachments and performs evaluations on each. + * It marks items for deletion based on certain conditions and updates the toDelete Set accordingly. + * + * @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. + */ + protected processAttachments(mainParentToAttachmentsMap: Map, itemsMap: Map, traderId: string, toDelete: Set): void; + /** + * 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. + * + * @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. * @returns void */ - protected sortAndFilterChildren(children: Item[], traderId: string, toDelete: Set): void; + protected processAttachmentByParent(attachments: Item[], traderId: string, toDelete: Set): void; + /** + * Sorts the attachment items by their max price in descending order. + * + * @param attachments The array of attachments items. + * @returns An array of items enriched with their max price and common locale-name. + */ + protected sortAttachmentsByPrice(attachments: Item[]): EnrichedItem[]; + /** + * Logs the details of each attachment item. + * + * @param attachments The array of attachment items. + */ + protected logAttachmentsDetails(attachments: EnrichedItem[]): void; + /** + * Counts the number of successful rolls for the attachment items. + * + * @param attachments The array of attachment items. + * @param traderId The ID of the trader that has insured these attachments. + * @returns The number of successful rolls. + */ + protected countSuccessfulRolls(attachments: Item[], traderId: string): number; + /** + * Marks the most valuable attachments for deletion based on the number of successful rolls made. + * + * @param attachments The array of attachment items. + * @param successfulRolls The number of successful rolls. + * @param toDelete The array that accumulates the IDs of the items to be deleted. + */ + protected attachmentDeletionByValue(attachments: EnrichedItem[], successfulRolls: number, toDelete: Set): void; /** * Remove items from the insured items that should not be returned to the player. * @@ -144,6 +168,22 @@ export declare class InsuranceController { * @returns void */ protected removeItemsFromInsurance(insured: Insurance, toDelete: Set): void; + /** + * Adopts orphaned items by resetting them as base-level items. Helpful in situations where a parent has been + * deleted from insurance, but any insured items within the parent should remain. This method will remove the + * reference from the children to the parent and set item properties to main-level values. + * + * @param insured Insurance object containing items. + */ + protected adoptOrphanedItems(insured: Insurance): void; + /** + * Fetches the parentId property of an item with a slotId "hideout". Not sure if this is actually dynamic, but this + * method should be a reliable way to fetch it, if it ever does change. + * + * @param items Array of items to search through. + * @returns The parentId of an item with slotId 'hideout'. Empty string if not found. + */ + protected fetchHideoutItemParent(items: Item[]): string; /** * Handle sending the insurance message to the user that potentially contains the valid insurance items. * @@ -154,15 +194,14 @@ export declare class InsuranceController { */ protected sendMail(sessionID: string, insurance: Insurance, noItems: boolean): void; /** - * Determines whether a valid insured item should be removed from the player's inventory based on a random roll and + * Determines whether a insured item should be removed from the player's inventory based on a random roll and * trader-specific return chance. * - * @param insuredItem The insured item being evaluated for removal. * @param traderId The ID of the trader who insured the item. - * @param itemsBeingDeleted List of items that are already slated for removal. + * @param insuredItem Optional. The item to roll for. Only used for logging. * @returns true if the insured item should be removed from inventory, false otherwise. */ - protected rollForItemDelete(insuredItem: Item, traderId: string, itemsBeingDeleted: Set): boolean; + protected rollForDelete(traderId: string, insuredItem?: Item): boolean; /** * Handle Insure event * Add insurance to an item @@ -183,3 +222,8 @@ export declare class InsuranceController { */ cost(request: IGetInsuranceCostRequestData, sessionID: string): IGetInsuranceCostResponseData; } +interface EnrichedItem extends Item { + name: string; + maxPrice: number; +} +export {}; diff --git a/TypeScript/18CustomItemService/types/di/Serializer.d.ts b/TypeScript/18CustomItemService/types/di/Serializer.d.ts index 2617007..b760b8b 100644 --- a/TypeScript/18CustomItemService/types/di/Serializer.d.ts +++ b/TypeScript/18CustomItemService/types/di/Serializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export declare class Serializer { serialize(sessionID: string, req: IncomingMessage, resp: ServerResponse, body: any): void; canHandle(something: string): boolean; diff --git a/TypeScript/18CustomItemService/types/helpers/ItemHelper.d.ts b/TypeScript/18CustomItemService/types/helpers/ItemHelper.d.ts index 6f1511c..5920d8a 100644 --- a/TypeScript/18CustomItemService/types/helpers/ItemHelper.d.ts +++ b/TypeScript/18CustomItemService/types/helpers/ItemHelper.d.ts @@ -225,6 +225,48 @@ declare class ItemHelper { * @returns true if item is flagged as quest item */ isQuestItem(tpl: string): boolean; + /** + * Checks to see if the item is *actually* moddable in-raid. Checks include the items existence in the database, the + * parent items existence in the database, the existence (and value) of the items RaidModdable property, and that + * the parents slot-required property exists, matches that of the item, and it's value. + * + * Note: this function does not preform any checks to see if the item and parent are *actually* related. + * + * @param item The item to be checked + * @param parent The parent of the item to be checked + * @returns True if the item is actually moddable, false if it is not, and null if the check cannot be performed. + */ + isRaidModdable(item: Item, parent: Item): boolean | null; + /** + * Retrieves the main parent item for a given attachment item. + * + * This method traverses up the hierarchy of items starting from a given `itemId`, until it finds the main parent + * item that is not an attached attachment itself. In other words, if you pass it an item id of a suppressor, it + * will traverse up the muzzle brake, barrel, upper receiver, and return the gun that the suppressor is ultimately + * attached to, even if that gun is located within multiple containers. + * + * It's important to note that traversal is expensive, so this method requires that you pass it a Map of the items + * to traverse, where the keys are the item IDs and the values are the corresponding Item objects. This alleviates + * some of the performance concerns, as it allows for quick lookups of items by ID. + * + * To generate the map: + * ``` + * const itemsMap = new Map(); + * items.forEach(item => itemsMap.set(item._id, item)); + * ``` + * + * @param itemId - The unique identifier of the item for which to find the main parent. + * @param itemsMap - A Map containing item IDs mapped to their corresponding Item objects for quick lookup. + * @returns The Item object representing the top-most parent of the given item, or `null` if no such parent exists. + */ + getAttachmentMainParent(itemId: string, itemsMap: Map): Item | null; + /** + * Determines if an item is an attachment that is currently attached to it's parent item. + * + * @param item The item to check. + * @returns true if the item is attached attachment, otherwise false. + */ + isAttachmentAttached(item: Item): boolean; /** * Get the inventory size of an item * @param items Item with children diff --git a/TypeScript/18CustomItemService/types/loaders/PreAkiModLoader.d.ts b/TypeScript/18CustomItemService/types/loaders/PreAkiModLoader.d.ts index 1e24b96..c0868b7 100644 --- a/TypeScript/18CustomItemService/types/loaders/PreAkiModLoader.d.ts +++ b/TypeScript/18CustomItemService/types/loaders/PreAkiModLoader.d.ts @@ -66,6 +66,10 @@ export declare class PreAkiModLoader implements IModLoader { protected isModCombatibleWithAki(mod: IPackageJsonData): boolean; protected executeMods(container: DependencyContainer): Promise; sortModsLoadOrder(): string[]; + /** + * Compile mod and add into class property "imported" + * @param mod Name of mod to compile/add + */ protected addMod(mod: string): Promise; protected autoInstallDependencies(modPath: string, pkg: IPackageJsonData): void; protected areModDependenciesFulfilled(pkg: IPackageJsonData, loadedMods: Record): boolean; diff --git a/TypeScript/18CustomItemService/types/models/external/HttpFramework.d.ts b/TypeScript/18CustomItemService/types/models/external/HttpFramework.d.ts index 64a37d6..fda8732 100644 --- a/TypeScript/18CustomItemService/types/models/external/HttpFramework.d.ts +++ b/TypeScript/18CustomItemService/types/models/external/HttpFramework.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export type HandleFn = (_: string, req: IncomingMessage, resp: ServerResponse) => void; /** * Associates handlers, HTTP methods and a base url to a listener using a proxy diff --git a/TypeScript/18CustomItemService/types/models/spt/mod/IPackageJsonData.d.ts b/TypeScript/18CustomItemService/types/models/spt/mod/IPackageJsonData.d.ts index 06f7454..f58d7cc 100644 --- a/TypeScript/18CustomItemService/types/models/spt/mod/IPackageJsonData.d.ts +++ b/TypeScript/18CustomItemService/types/models/spt/mod/IPackageJsonData.d.ts @@ -6,6 +6,9 @@ export interface IPackageJsonData { author: string; version: string; akiVersion: string; + /** We deliberately purge this data */ + scripts: Record; + devDependencies: Record; licence: string; main: string; isBundleMod: boolean; diff --git a/TypeScript/18CustomItemService/types/routers/HttpRouter.d.ts b/TypeScript/18CustomItemService/types/routers/HttpRouter.d.ts index f75a47d..46f847a 100644 --- a/TypeScript/18CustomItemService/types/routers/HttpRouter.d.ts +++ b/TypeScript/18CustomItemService/types/routers/HttpRouter.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage } from "http"; +import { IncomingMessage } from "node:http"; import { DynamicRouter, Router, StaticRouter } from "../di/Router"; export declare class HttpRouter { protected staticRouters: StaticRouter[]; diff --git a/TypeScript/18CustomItemService/types/routers/ImageRouter.d.ts b/TypeScript/18CustomItemService/types/routers/ImageRouter.d.ts index 675441c..fd03c59 100644 --- a/TypeScript/18CustomItemService/types/routers/ImageRouter.d.ts +++ b/TypeScript/18CustomItemService/types/routers/ImageRouter.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { ImageRouteService } from "../services/mod/image/ImageRouteService"; import { HttpFileUtil } from "../utils/HttpFileUtil"; import { VFS } from "../utils/VFS"; diff --git a/TypeScript/18CustomItemService/types/routers/serializers/BundleSerializer.d.ts b/TypeScript/18CustomItemService/types/routers/serializers/BundleSerializer.d.ts index ca4d8b6..db41142 100644 --- a/TypeScript/18CustomItemService/types/routers/serializers/BundleSerializer.d.ts +++ b/TypeScript/18CustomItemService/types/routers/serializers/BundleSerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { BundleLoader } from "../../loaders/BundleLoader"; import { ILogger } from "../../models/spt/utils/ILogger"; diff --git a/TypeScript/18CustomItemService/types/routers/serializers/ImageSerializer.d.ts b/TypeScript/18CustomItemService/types/routers/serializers/ImageSerializer.d.ts index 5de48ff..62ce84d 100644 --- a/TypeScript/18CustomItemService/types/routers/serializers/ImageSerializer.d.ts +++ b/TypeScript/18CustomItemService/types/routers/serializers/ImageSerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { ImageRouter } from "../ImageRouter"; export declare class ImageSerializer extends Serializer { diff --git a/TypeScript/18CustomItemService/types/routers/serializers/NotifySerializer.d.ts b/TypeScript/18CustomItemService/types/routers/serializers/NotifySerializer.d.ts index 1d179b2..e92d6e1 100644 --- a/TypeScript/18CustomItemService/types/routers/serializers/NotifySerializer.d.ts +++ b/TypeScript/18CustomItemService/types/routers/serializers/NotifySerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { NotifierController } from "../../controllers/NotifierController"; import { Serializer } from "../../di/Serializer"; import { HttpServerHelper } from "../../helpers/HttpServerHelper"; diff --git a/TypeScript/18CustomItemService/types/servers/HttpServer.d.ts b/TypeScript/18CustomItemService/types/servers/HttpServer.d.ts index 97e0705..c73eb3c 100644 --- a/TypeScript/18CustomItemService/types/servers/HttpServer.d.ts +++ b/TypeScript/18CustomItemService/types/servers/HttpServer.d.ts @@ -1,5 +1,5 @@ /// -import http, { IncomingMessage, ServerResponse } from "http"; +import http, { IncomingMessage, ServerResponse } from "node:http"; import { ApplicationContext } from "../context/ApplicationContext"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; import { IHttpConfig } from "../models/spt/config/IHttpConfig"; diff --git a/TypeScript/18CustomItemService/types/servers/WebSocketServer.d.ts b/TypeScript/18CustomItemService/types/servers/WebSocketServer.d.ts index fffbea2..b4c6158 100644 --- a/TypeScript/18CustomItemService/types/servers/WebSocketServer.d.ts +++ b/TypeScript/18CustomItemService/types/servers/WebSocketServer.d.ts @@ -1,5 +1,5 @@ /// -import http, { IncomingMessage } from "http"; +import http, { IncomingMessage } from "node:http"; import WebSocket from "ws"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; import { INotification } from "../models/eft/notifier/INotifier"; diff --git a/TypeScript/18CustomItemService/types/servers/http/AkiHttpListener.d.ts b/TypeScript/18CustomItemService/types/servers/http/AkiHttpListener.d.ts index c72e18f..e4ac80c 100644 --- a/TypeScript/18CustomItemService/types/servers/http/AkiHttpListener.d.ts +++ b/TypeScript/18CustomItemService/types/servers/http/AkiHttpListener.d.ts @@ -1,6 +1,6 @@ /// /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { ILogger } from "../../models/spt/utils/ILogger"; import { HttpRouter } from "../../routers/HttpRouter"; diff --git a/TypeScript/18CustomItemService/types/servers/http/IHttpListener.d.ts b/TypeScript/18CustomItemService/types/servers/http/IHttpListener.d.ts index 758bb5a..29d5fce 100644 --- a/TypeScript/18CustomItemService/types/servers/http/IHttpListener.d.ts +++ b/TypeScript/18CustomItemService/types/servers/http/IHttpListener.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export interface IHttpListener { canHandle(sessionId: string, req: IncomingMessage): boolean; handle(sessionId: string, req: IncomingMessage, resp: ServerResponse): void; diff --git a/TypeScript/18CustomItemService/types/services/mod/httpListener/HttpListenerMod.d.ts b/TypeScript/18CustomItemService/types/services/mod/httpListener/HttpListenerMod.d.ts index 2cdfbda..afe4574 100644 --- a/TypeScript/18CustomItemService/types/services/mod/httpListener/HttpListenerMod.d.ts +++ b/TypeScript/18CustomItemService/types/services/mod/httpListener/HttpListenerMod.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { IHttpListener } from "../../../servers/http/IHttpListener"; export declare class HttpListenerMod implements IHttpListener { private canHandleOverride; diff --git a/TypeScript/18CustomItemService/types/services/mod/httpListener/HttpListenerModService.d.ts b/TypeScript/18CustomItemService/types/services/mod/httpListener/HttpListenerModService.d.ts index 9dd3473..23abfbe 100644 --- a/TypeScript/18CustomItemService/types/services/mod/httpListener/HttpListenerModService.d.ts +++ b/TypeScript/18CustomItemService/types/services/mod/httpListener/HttpListenerModService.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { DependencyContainer } from "tsyringe"; export declare class HttpListenerModService { protected container: DependencyContainer; diff --git a/TypeScript/18CustomItemService/types/utils/App.d.ts b/TypeScript/18CustomItemService/types/utils/App.d.ts index dd8f24c..5e759ad 100644 --- a/TypeScript/18CustomItemService/types/utils/App.d.ts +++ b/TypeScript/18CustomItemService/types/utils/App.d.ts @@ -12,7 +12,6 @@ export declare class App { protected onLoadComponents: OnLoad[]; protected onUpdateComponents: OnUpdate[]; protected onUpdateLastRun: {}; - protected os: any; constructor(logger: ILogger, timeUtil: TimeUtil, localisationService: LocalisationService, encodingUtil: EncodingUtil, onLoadComponents: OnLoad[], onUpdateComponents: OnUpdate[]); load(): Promise; protected update(onUpdateComponents: OnUpdate[]): Promise; diff --git a/TypeScript/18CustomItemService/types/utils/HashUtil.d.ts b/TypeScript/18CustomItemService/types/utils/HashUtil.d.ts index c017ca8..27204cb 100644 --- a/TypeScript/18CustomItemService/types/utils/HashUtil.d.ts +++ b/TypeScript/18CustomItemService/types/utils/HashUtil.d.ts @@ -1,5 +1,5 @@ /// -import crypto from "crypto"; +import crypto from "node:crypto"; import { TimeUtil } from "./TimeUtil"; export declare class HashUtil { protected timeUtil: TimeUtil; diff --git a/TypeScript/18CustomItemService/types/utils/HttpFileUtil.d.ts b/TypeScript/18CustomItemService/types/utils/HttpFileUtil.d.ts index afc8409..6a386ce 100644 --- a/TypeScript/18CustomItemService/types/utils/HttpFileUtil.d.ts +++ b/TypeScript/18CustomItemService/types/utils/HttpFileUtil.d.ts @@ -1,5 +1,5 @@ /// -import { ServerResponse } from "http"; +import { ServerResponse } from "node:http"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; export declare class HttpFileUtil { protected httpServerHelper: HttpServerHelper; diff --git a/TypeScript/18CustomItemService/types/utils/VFS.d.ts b/TypeScript/18CustomItemService/types/utils/VFS.d.ts index 2cb09fa..3911c4b 100644 --- a/TypeScript/18CustomItemService/types/utils/VFS.d.ts +++ b/TypeScript/18CustomItemService/types/utils/VFS.d.ts @@ -1,6 +1,6 @@ /// /// -import fs from "fs"; +import fs from "node:fs"; import "reflect-metadata"; import { IAsyncQueue } from "../models/spt/utils/IAsyncQueue"; import { IUUidGenerator } from "../models/spt/utils/IUuidGenerator"; diff --git a/TypeScript/18CustomItemService/types/utils/Watermark.d.ts b/TypeScript/18CustomItemService/types/utils/Watermark.d.ts index fa63205..864e9b6 100644 --- a/TypeScript/18CustomItemService/types/utils/Watermark.d.ts +++ b/TypeScript/18CustomItemService/types/utils/Watermark.d.ts @@ -4,12 +4,10 @@ import { ConfigServer } from "../servers/ConfigServer"; import { LocalisationService } from "../services/LocalisationService"; export declare class WatermarkLocale { protected localisationService: LocalisationService; + protected description: string[]; + protected warning: string[]; + protected modding: string[]; constructor(localisationService: LocalisationService); - protected watermark: { - description: string[]; - warning: string[]; - modding: string[]; - }; getDescription(): string[]; getWarning(): string[]; getModding(): string[]; diff --git a/TypeScript/18CustomItemService/types/utils/logging/AbstractWinstonLogger.d.ts b/TypeScript/18CustomItemService/types/utils/logging/AbstractWinstonLogger.d.ts index 1ae1100..74767a2 100644 --- a/TypeScript/18CustomItemService/types/utils/logging/AbstractWinstonLogger.d.ts +++ b/TypeScript/18CustomItemService/types/utils/logging/AbstractWinstonLogger.d.ts @@ -1,5 +1,5 @@ /// -import fs from "fs"; +import fs from "node:fs"; import winston from "winston"; import { Daum } from "../../models/eft/itemEvent/IItemEventRouterRequest"; import { LogBackgroundColor } from "../../models/spt/logging/LogBackgroundColor"; diff --git a/TypeScript/19UseExternalLibraries/types/controllers/GameController.d.ts b/TypeScript/19UseExternalLibraries/types/controllers/GameController.d.ts index 73596ff..74123b2 100644 --- a/TypeScript/19UseExternalLibraries/types/controllers/GameController.d.ts +++ b/TypeScript/19UseExternalLibraries/types/controllers/GameController.d.ts @@ -49,7 +49,6 @@ export declare class GameController { protected giftService: GiftService; protected applicationContext: ApplicationContext; protected configServer: ConfigServer; - protected os: any; protected httpConfig: IHttpConfig; protected coreConfig: ICoreConfig; protected locationConfig: ILocationConfig; diff --git a/TypeScript/19UseExternalLibraries/types/controllers/InsuranceController.d.ts b/TypeScript/19UseExternalLibraries/types/controllers/InsuranceController.d.ts index fb41610..fc3229b 100644 --- a/TypeScript/19UseExternalLibraries/types/controllers/InsuranceController.d.ts +++ b/TypeScript/19UseExternalLibraries/types/controllers/InsuranceController.d.ts @@ -4,7 +4,6 @@ import { ProfileHelper } from "../helpers/ProfileHelper"; import { TraderHelper } from "../helpers/TraderHelper"; import { IPmcData } from "../models/eft/common/IPmcData"; import { Item } from "../models/eft/common/tables/IItem"; -import { ITemplateItem } from "../models/eft/common/tables/ITemplateItem"; import { IGetInsuranceCostRequestData } from "../models/eft/insurance/IGetInsuranceCostRequestData"; import { IGetInsuranceCostResponseData } from "../models/eft/insurance/IGetInsuranceCostResponseData"; import { IInsureRequestData } from "../models/eft/insurance/IInsureRequestData"; @@ -75,67 +74,92 @@ export declare class InsuranceController { */ protected removeInsurancePackageFromProfile(sessionID: string, packageInfo: ISystemData): void; /** - * Build an array of items to delete from the insured items. + * Finds the items that should be deleted based on the given Insurance object. * - * This method orchestrates several steps: - * - Filters items based on their presence in the database and their raid moddability. - * - Sorts base and independent child items to consider for deletion. - * - Groups child items by their parent for later evaluation. - * - Evaluates grouped child items to decide which should be deleted, based on their value and a random roll. - * - * @param insured - The insured items to build a removal array from. - * @returns An array of IDs representing items that should be deleted. + * @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(insured: Insurance): Set; /** - * Filters an item based on its existence in the database, raid moddability, and slot requirements. + * Populate a Map object of items for quick lookup by their ID. * - * @param item The item to be filtered. - * @param parentItemDbDetails The database details of the parent item, or null if the item has no parent. - * @param itemDbDetails A tuple where the first element is a boolean indicating if the item exists in the database, - * and the second element is the item details if it does. - * @returns true if the item exists in the database and neither of the following conditions are met: - * - The item has the RaidModdable property set to false. - * - The item is attached to a required slot in its parent item. - * Otherwise, returns false. + * @param insured The insurance object containing the items to populate the map with. + * @returns A Map where the keys are the item IDs and the values are the corresponding Item objects. */ - protected filterByRaidModdability(item: Item, parentItemDbDetails: ITemplateItem | null, itemDbDetails: [boolean, ITemplateItem]): boolean; + protected populateItemsMap(insured: Insurance): Map; /** - * Determines if an item is either a base item or a child item that is not equipped to its parent. + * 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 item The item to check. - * @returns true if the item is a base or an independent child item, otherwise false. + * @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. */ - protected isBaseOrIndependentChild(item: Item): boolean; + protected populateParentAttachmentsMap(insured: Insurance, itemsMap: Map): Map; /** - * Makes a roll to determine if a given item should be deleted. If the roll is successful, the item's ID is added - * to the `toDelete` array. + * 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. * - * @param item The item for which the roll is made. - * @param traderId The ID of the trader to consider in the rollForItemDelete method. - * @param toDelete The array accumulating the IDs of items to be deleted. - * @returns true if the item is marked for deletion, otherwise false. - */ - protected makeRollAndMarkForDeletion(item: Item, traderId: string, toDelete: Set): boolean; - /** - * Groups child items by their parent IDs in a Map data structure. - * - * @param item The child item to be grouped by its parent. - * @param childrenGroupedByParent The Map that holds arrays of children items grouped by their parent IDs. + * @param insured The insurance object containing the items to evaluate. + * @param toDelete A Set to keep track of items marked for deletion. * @returns void */ - protected groupChildrenByParent(item: Item, childrenGroupedByParent: Map): void; + protected processRegularItems(insured: Insurance, toDelete: Set): void; /** - * Sorts the array of children items in descending order by their maximum price. For each child, a roll is made to - * determine if it should be deleted. The method then deletes the most valuable children based on the number of - * successful rolls made. + * Process parent items and their attachments, updating the toDelete Set accordingly. * - * @param children The array of children items to sort and filter. - * @param traderId The ID of the trader to consider in the rollForItemDelete method. + * This method iterates over a map of parent items to their attachments and performs evaluations on each. + * It marks items for deletion based on certain conditions and updates the toDelete Set accordingly. + * + * @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. + */ + protected processAttachments(mainParentToAttachmentsMap: Map, itemsMap: Map, traderId: string, toDelete: Set): void; + /** + * 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. + * + * @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. * @returns void */ - protected sortAndFilterChildren(children: Item[], traderId: string, toDelete: Set): void; + protected processAttachmentByParent(attachments: Item[], traderId: string, toDelete: Set): void; + /** + * Sorts the attachment items by their max price in descending order. + * + * @param attachments The array of attachments items. + * @returns An array of items enriched with their max price and common locale-name. + */ + protected sortAttachmentsByPrice(attachments: Item[]): EnrichedItem[]; + /** + * Logs the details of each attachment item. + * + * @param attachments The array of attachment items. + */ + protected logAttachmentsDetails(attachments: EnrichedItem[]): void; + /** + * Counts the number of successful rolls for the attachment items. + * + * @param attachments The array of attachment items. + * @param traderId The ID of the trader that has insured these attachments. + * @returns The number of successful rolls. + */ + protected countSuccessfulRolls(attachments: Item[], traderId: string): number; + /** + * Marks the most valuable attachments for deletion based on the number of successful rolls made. + * + * @param attachments The array of attachment items. + * @param successfulRolls The number of successful rolls. + * @param toDelete The array that accumulates the IDs of the items to be deleted. + */ + protected attachmentDeletionByValue(attachments: EnrichedItem[], successfulRolls: number, toDelete: Set): void; /** * Remove items from the insured items that should not be returned to the player. * @@ -144,6 +168,22 @@ export declare class InsuranceController { * @returns void */ protected removeItemsFromInsurance(insured: Insurance, toDelete: Set): void; + /** + * Adopts orphaned items by resetting them as base-level items. Helpful in situations where a parent has been + * deleted from insurance, but any insured items within the parent should remain. This method will remove the + * reference from the children to the parent and set item properties to main-level values. + * + * @param insured Insurance object containing items. + */ + protected adoptOrphanedItems(insured: Insurance): void; + /** + * Fetches the parentId property of an item with a slotId "hideout". Not sure if this is actually dynamic, but this + * method should be a reliable way to fetch it, if it ever does change. + * + * @param items Array of items to search through. + * @returns The parentId of an item with slotId 'hideout'. Empty string if not found. + */ + protected fetchHideoutItemParent(items: Item[]): string; /** * Handle sending the insurance message to the user that potentially contains the valid insurance items. * @@ -154,15 +194,14 @@ export declare class InsuranceController { */ protected sendMail(sessionID: string, insurance: Insurance, noItems: boolean): void; /** - * Determines whether a valid insured item should be removed from the player's inventory based on a random roll and + * Determines whether a insured item should be removed from the player's inventory based on a random roll and * trader-specific return chance. * - * @param insuredItem The insured item being evaluated for removal. * @param traderId The ID of the trader who insured the item. - * @param itemsBeingDeleted List of items that are already slated for removal. + * @param insuredItem Optional. The item to roll for. Only used for logging. * @returns true if the insured item should be removed from inventory, false otherwise. */ - protected rollForItemDelete(insuredItem: Item, traderId: string, itemsBeingDeleted: Set): boolean; + protected rollForDelete(traderId: string, insuredItem?: Item): boolean; /** * Handle Insure event * Add insurance to an item @@ -183,3 +222,8 @@ export declare class InsuranceController { */ cost(request: IGetInsuranceCostRequestData, sessionID: string): IGetInsuranceCostResponseData; } +interface EnrichedItem extends Item { + name: string; + maxPrice: number; +} +export {}; diff --git a/TypeScript/19UseExternalLibraries/types/di/Serializer.d.ts b/TypeScript/19UseExternalLibraries/types/di/Serializer.d.ts index 2617007..b760b8b 100644 --- a/TypeScript/19UseExternalLibraries/types/di/Serializer.d.ts +++ b/TypeScript/19UseExternalLibraries/types/di/Serializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export declare class Serializer { serialize(sessionID: string, req: IncomingMessage, resp: ServerResponse, body: any): void; canHandle(something: string): boolean; diff --git a/TypeScript/19UseExternalLibraries/types/helpers/ItemHelper.d.ts b/TypeScript/19UseExternalLibraries/types/helpers/ItemHelper.d.ts index 6f1511c..5920d8a 100644 --- a/TypeScript/19UseExternalLibraries/types/helpers/ItemHelper.d.ts +++ b/TypeScript/19UseExternalLibraries/types/helpers/ItemHelper.d.ts @@ -225,6 +225,48 @@ declare class ItemHelper { * @returns true if item is flagged as quest item */ isQuestItem(tpl: string): boolean; + /** + * Checks to see if the item is *actually* moddable in-raid. Checks include the items existence in the database, the + * parent items existence in the database, the existence (and value) of the items RaidModdable property, and that + * the parents slot-required property exists, matches that of the item, and it's value. + * + * Note: this function does not preform any checks to see if the item and parent are *actually* related. + * + * @param item The item to be checked + * @param parent The parent of the item to be checked + * @returns True if the item is actually moddable, false if it is not, and null if the check cannot be performed. + */ + isRaidModdable(item: Item, parent: Item): boolean | null; + /** + * Retrieves the main parent item for a given attachment item. + * + * This method traverses up the hierarchy of items starting from a given `itemId`, until it finds the main parent + * item that is not an attached attachment itself. In other words, if you pass it an item id of a suppressor, it + * will traverse up the muzzle brake, barrel, upper receiver, and return the gun that the suppressor is ultimately + * attached to, even if that gun is located within multiple containers. + * + * It's important to note that traversal is expensive, so this method requires that you pass it a Map of the items + * to traverse, where the keys are the item IDs and the values are the corresponding Item objects. This alleviates + * some of the performance concerns, as it allows for quick lookups of items by ID. + * + * To generate the map: + * ``` + * const itemsMap = new Map(); + * items.forEach(item => itemsMap.set(item._id, item)); + * ``` + * + * @param itemId - The unique identifier of the item for which to find the main parent. + * @param itemsMap - A Map containing item IDs mapped to their corresponding Item objects for quick lookup. + * @returns The Item object representing the top-most parent of the given item, or `null` if no such parent exists. + */ + getAttachmentMainParent(itemId: string, itemsMap: Map): Item | null; + /** + * Determines if an item is an attachment that is currently attached to it's parent item. + * + * @param item The item to check. + * @returns true if the item is attached attachment, otherwise false. + */ + isAttachmentAttached(item: Item): boolean; /** * Get the inventory size of an item * @param items Item with children diff --git a/TypeScript/19UseExternalLibraries/types/loaders/PreAkiModLoader.d.ts b/TypeScript/19UseExternalLibraries/types/loaders/PreAkiModLoader.d.ts index 1e24b96..c0868b7 100644 --- a/TypeScript/19UseExternalLibraries/types/loaders/PreAkiModLoader.d.ts +++ b/TypeScript/19UseExternalLibraries/types/loaders/PreAkiModLoader.d.ts @@ -66,6 +66,10 @@ export declare class PreAkiModLoader implements IModLoader { protected isModCombatibleWithAki(mod: IPackageJsonData): boolean; protected executeMods(container: DependencyContainer): Promise; sortModsLoadOrder(): string[]; + /** + * Compile mod and add into class property "imported" + * @param mod Name of mod to compile/add + */ protected addMod(mod: string): Promise; protected autoInstallDependencies(modPath: string, pkg: IPackageJsonData): void; protected areModDependenciesFulfilled(pkg: IPackageJsonData, loadedMods: Record): boolean; diff --git a/TypeScript/19UseExternalLibraries/types/models/external/HttpFramework.d.ts b/TypeScript/19UseExternalLibraries/types/models/external/HttpFramework.d.ts index 64a37d6..fda8732 100644 --- a/TypeScript/19UseExternalLibraries/types/models/external/HttpFramework.d.ts +++ b/TypeScript/19UseExternalLibraries/types/models/external/HttpFramework.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export type HandleFn = (_: string, req: IncomingMessage, resp: ServerResponse) => void; /** * Associates handlers, HTTP methods and a base url to a listener using a proxy diff --git a/TypeScript/19UseExternalLibraries/types/models/spt/mod/IPackageJsonData.d.ts b/TypeScript/19UseExternalLibraries/types/models/spt/mod/IPackageJsonData.d.ts index 06f7454..f58d7cc 100644 --- a/TypeScript/19UseExternalLibraries/types/models/spt/mod/IPackageJsonData.d.ts +++ b/TypeScript/19UseExternalLibraries/types/models/spt/mod/IPackageJsonData.d.ts @@ -6,6 +6,9 @@ export interface IPackageJsonData { author: string; version: string; akiVersion: string; + /** We deliberately purge this data */ + scripts: Record; + devDependencies: Record; licence: string; main: string; isBundleMod: boolean; diff --git a/TypeScript/19UseExternalLibraries/types/routers/HttpRouter.d.ts b/TypeScript/19UseExternalLibraries/types/routers/HttpRouter.d.ts index f75a47d..46f847a 100644 --- a/TypeScript/19UseExternalLibraries/types/routers/HttpRouter.d.ts +++ b/TypeScript/19UseExternalLibraries/types/routers/HttpRouter.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage } from "http"; +import { IncomingMessage } from "node:http"; import { DynamicRouter, Router, StaticRouter } from "../di/Router"; export declare class HttpRouter { protected staticRouters: StaticRouter[]; diff --git a/TypeScript/19UseExternalLibraries/types/routers/ImageRouter.d.ts b/TypeScript/19UseExternalLibraries/types/routers/ImageRouter.d.ts index 675441c..fd03c59 100644 --- a/TypeScript/19UseExternalLibraries/types/routers/ImageRouter.d.ts +++ b/TypeScript/19UseExternalLibraries/types/routers/ImageRouter.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { ImageRouteService } from "../services/mod/image/ImageRouteService"; import { HttpFileUtil } from "../utils/HttpFileUtil"; import { VFS } from "../utils/VFS"; diff --git a/TypeScript/19UseExternalLibraries/types/routers/serializers/BundleSerializer.d.ts b/TypeScript/19UseExternalLibraries/types/routers/serializers/BundleSerializer.d.ts index ca4d8b6..db41142 100644 --- a/TypeScript/19UseExternalLibraries/types/routers/serializers/BundleSerializer.d.ts +++ b/TypeScript/19UseExternalLibraries/types/routers/serializers/BundleSerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { BundleLoader } from "../../loaders/BundleLoader"; import { ILogger } from "../../models/spt/utils/ILogger"; diff --git a/TypeScript/19UseExternalLibraries/types/routers/serializers/ImageSerializer.d.ts b/TypeScript/19UseExternalLibraries/types/routers/serializers/ImageSerializer.d.ts index 5de48ff..62ce84d 100644 --- a/TypeScript/19UseExternalLibraries/types/routers/serializers/ImageSerializer.d.ts +++ b/TypeScript/19UseExternalLibraries/types/routers/serializers/ImageSerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { ImageRouter } from "../ImageRouter"; export declare class ImageSerializer extends Serializer { diff --git a/TypeScript/19UseExternalLibraries/types/routers/serializers/NotifySerializer.d.ts b/TypeScript/19UseExternalLibraries/types/routers/serializers/NotifySerializer.d.ts index 1d179b2..e92d6e1 100644 --- a/TypeScript/19UseExternalLibraries/types/routers/serializers/NotifySerializer.d.ts +++ b/TypeScript/19UseExternalLibraries/types/routers/serializers/NotifySerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { NotifierController } from "../../controllers/NotifierController"; import { Serializer } from "../../di/Serializer"; import { HttpServerHelper } from "../../helpers/HttpServerHelper"; diff --git a/TypeScript/19UseExternalLibraries/types/servers/HttpServer.d.ts b/TypeScript/19UseExternalLibraries/types/servers/HttpServer.d.ts index 97e0705..c73eb3c 100644 --- a/TypeScript/19UseExternalLibraries/types/servers/HttpServer.d.ts +++ b/TypeScript/19UseExternalLibraries/types/servers/HttpServer.d.ts @@ -1,5 +1,5 @@ /// -import http, { IncomingMessage, ServerResponse } from "http"; +import http, { IncomingMessage, ServerResponse } from "node:http"; import { ApplicationContext } from "../context/ApplicationContext"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; import { IHttpConfig } from "../models/spt/config/IHttpConfig"; diff --git a/TypeScript/19UseExternalLibraries/types/servers/WebSocketServer.d.ts b/TypeScript/19UseExternalLibraries/types/servers/WebSocketServer.d.ts index fffbea2..b4c6158 100644 --- a/TypeScript/19UseExternalLibraries/types/servers/WebSocketServer.d.ts +++ b/TypeScript/19UseExternalLibraries/types/servers/WebSocketServer.d.ts @@ -1,5 +1,5 @@ /// -import http, { IncomingMessage } from "http"; +import http, { IncomingMessage } from "node:http"; import WebSocket from "ws"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; import { INotification } from "../models/eft/notifier/INotifier"; diff --git a/TypeScript/19UseExternalLibraries/types/servers/http/AkiHttpListener.d.ts b/TypeScript/19UseExternalLibraries/types/servers/http/AkiHttpListener.d.ts index c72e18f..e4ac80c 100644 --- a/TypeScript/19UseExternalLibraries/types/servers/http/AkiHttpListener.d.ts +++ b/TypeScript/19UseExternalLibraries/types/servers/http/AkiHttpListener.d.ts @@ -1,6 +1,6 @@ /// /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { ILogger } from "../../models/spt/utils/ILogger"; import { HttpRouter } from "../../routers/HttpRouter"; diff --git a/TypeScript/19UseExternalLibraries/types/servers/http/IHttpListener.d.ts b/TypeScript/19UseExternalLibraries/types/servers/http/IHttpListener.d.ts index 758bb5a..29d5fce 100644 --- a/TypeScript/19UseExternalLibraries/types/servers/http/IHttpListener.d.ts +++ b/TypeScript/19UseExternalLibraries/types/servers/http/IHttpListener.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export interface IHttpListener { canHandle(sessionId: string, req: IncomingMessage): boolean; handle(sessionId: string, req: IncomingMessage, resp: ServerResponse): void; diff --git a/TypeScript/19UseExternalLibraries/types/services/mod/httpListener/HttpListenerMod.d.ts b/TypeScript/19UseExternalLibraries/types/services/mod/httpListener/HttpListenerMod.d.ts index 2cdfbda..afe4574 100644 --- a/TypeScript/19UseExternalLibraries/types/services/mod/httpListener/HttpListenerMod.d.ts +++ b/TypeScript/19UseExternalLibraries/types/services/mod/httpListener/HttpListenerMod.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { IHttpListener } from "../../../servers/http/IHttpListener"; export declare class HttpListenerMod implements IHttpListener { private canHandleOverride; diff --git a/TypeScript/19UseExternalLibraries/types/services/mod/httpListener/HttpListenerModService.d.ts b/TypeScript/19UseExternalLibraries/types/services/mod/httpListener/HttpListenerModService.d.ts index 9dd3473..23abfbe 100644 --- a/TypeScript/19UseExternalLibraries/types/services/mod/httpListener/HttpListenerModService.d.ts +++ b/TypeScript/19UseExternalLibraries/types/services/mod/httpListener/HttpListenerModService.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { DependencyContainer } from "tsyringe"; export declare class HttpListenerModService { protected container: DependencyContainer; diff --git a/TypeScript/19UseExternalLibraries/types/utils/App.d.ts b/TypeScript/19UseExternalLibraries/types/utils/App.d.ts index dd8f24c..5e759ad 100644 --- a/TypeScript/19UseExternalLibraries/types/utils/App.d.ts +++ b/TypeScript/19UseExternalLibraries/types/utils/App.d.ts @@ -12,7 +12,6 @@ export declare class App { protected onLoadComponents: OnLoad[]; protected onUpdateComponents: OnUpdate[]; protected onUpdateLastRun: {}; - protected os: any; constructor(logger: ILogger, timeUtil: TimeUtil, localisationService: LocalisationService, encodingUtil: EncodingUtil, onLoadComponents: OnLoad[], onUpdateComponents: OnUpdate[]); load(): Promise; protected update(onUpdateComponents: OnUpdate[]): Promise; diff --git a/TypeScript/19UseExternalLibraries/types/utils/HashUtil.d.ts b/TypeScript/19UseExternalLibraries/types/utils/HashUtil.d.ts index c017ca8..27204cb 100644 --- a/TypeScript/19UseExternalLibraries/types/utils/HashUtil.d.ts +++ b/TypeScript/19UseExternalLibraries/types/utils/HashUtil.d.ts @@ -1,5 +1,5 @@ /// -import crypto from "crypto"; +import crypto from "node:crypto"; import { TimeUtil } from "./TimeUtil"; export declare class HashUtil { protected timeUtil: TimeUtil; diff --git a/TypeScript/19UseExternalLibraries/types/utils/HttpFileUtil.d.ts b/TypeScript/19UseExternalLibraries/types/utils/HttpFileUtil.d.ts index afc8409..6a386ce 100644 --- a/TypeScript/19UseExternalLibraries/types/utils/HttpFileUtil.d.ts +++ b/TypeScript/19UseExternalLibraries/types/utils/HttpFileUtil.d.ts @@ -1,5 +1,5 @@ /// -import { ServerResponse } from "http"; +import { ServerResponse } from "node:http"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; export declare class HttpFileUtil { protected httpServerHelper: HttpServerHelper; diff --git a/TypeScript/19UseExternalLibraries/types/utils/VFS.d.ts b/TypeScript/19UseExternalLibraries/types/utils/VFS.d.ts index 2cb09fa..3911c4b 100644 --- a/TypeScript/19UseExternalLibraries/types/utils/VFS.d.ts +++ b/TypeScript/19UseExternalLibraries/types/utils/VFS.d.ts @@ -1,6 +1,6 @@ /// /// -import fs from "fs"; +import fs from "node:fs"; import "reflect-metadata"; import { IAsyncQueue } from "../models/spt/utils/IAsyncQueue"; import { IUUidGenerator } from "../models/spt/utils/IUuidGenerator"; diff --git a/TypeScript/19UseExternalLibraries/types/utils/Watermark.d.ts b/TypeScript/19UseExternalLibraries/types/utils/Watermark.d.ts index fa63205..864e9b6 100644 --- a/TypeScript/19UseExternalLibraries/types/utils/Watermark.d.ts +++ b/TypeScript/19UseExternalLibraries/types/utils/Watermark.d.ts @@ -4,12 +4,10 @@ import { ConfigServer } from "../servers/ConfigServer"; import { LocalisationService } from "../services/LocalisationService"; export declare class WatermarkLocale { protected localisationService: LocalisationService; + protected description: string[]; + protected warning: string[]; + protected modding: string[]; constructor(localisationService: LocalisationService); - protected watermark: { - description: string[]; - warning: string[]; - modding: string[]; - }; getDescription(): string[]; getWarning(): string[]; getModding(): string[]; diff --git a/TypeScript/19UseExternalLibraries/types/utils/logging/AbstractWinstonLogger.d.ts b/TypeScript/19UseExternalLibraries/types/utils/logging/AbstractWinstonLogger.d.ts index 1ae1100..74767a2 100644 --- a/TypeScript/19UseExternalLibraries/types/utils/logging/AbstractWinstonLogger.d.ts +++ b/TypeScript/19UseExternalLibraries/types/utils/logging/AbstractWinstonLogger.d.ts @@ -1,5 +1,5 @@ /// -import fs from "fs"; +import fs from "node:fs"; import winston from "winston"; import { Daum } from "../../models/eft/itemEvent/IItemEventRouterRequest"; import { LogBackgroundColor } from "../../models/spt/logging/LogBackgroundColor"; diff --git a/TypeScript/1LogToConsole/types/controllers/GameController.d.ts b/TypeScript/1LogToConsole/types/controllers/GameController.d.ts index 73596ff..74123b2 100644 --- a/TypeScript/1LogToConsole/types/controllers/GameController.d.ts +++ b/TypeScript/1LogToConsole/types/controllers/GameController.d.ts @@ -49,7 +49,6 @@ export declare class GameController { protected giftService: GiftService; protected applicationContext: ApplicationContext; protected configServer: ConfigServer; - protected os: any; protected httpConfig: IHttpConfig; protected coreConfig: ICoreConfig; protected locationConfig: ILocationConfig; diff --git a/TypeScript/1LogToConsole/types/controllers/InsuranceController.d.ts b/TypeScript/1LogToConsole/types/controllers/InsuranceController.d.ts index fb41610..fc3229b 100644 --- a/TypeScript/1LogToConsole/types/controllers/InsuranceController.d.ts +++ b/TypeScript/1LogToConsole/types/controllers/InsuranceController.d.ts @@ -4,7 +4,6 @@ import { ProfileHelper } from "../helpers/ProfileHelper"; import { TraderHelper } from "../helpers/TraderHelper"; import { IPmcData } from "../models/eft/common/IPmcData"; import { Item } from "../models/eft/common/tables/IItem"; -import { ITemplateItem } from "../models/eft/common/tables/ITemplateItem"; import { IGetInsuranceCostRequestData } from "../models/eft/insurance/IGetInsuranceCostRequestData"; import { IGetInsuranceCostResponseData } from "../models/eft/insurance/IGetInsuranceCostResponseData"; import { IInsureRequestData } from "../models/eft/insurance/IInsureRequestData"; @@ -75,67 +74,92 @@ export declare class InsuranceController { */ protected removeInsurancePackageFromProfile(sessionID: string, packageInfo: ISystemData): void; /** - * Build an array of items to delete from the insured items. + * Finds the items that should be deleted based on the given Insurance object. * - * This method orchestrates several steps: - * - Filters items based on their presence in the database and their raid moddability. - * - Sorts base and independent child items to consider for deletion. - * - Groups child items by their parent for later evaluation. - * - Evaluates grouped child items to decide which should be deleted, based on their value and a random roll. - * - * @param insured - The insured items to build a removal array from. - * @returns An array of IDs representing items that should be deleted. + * @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(insured: Insurance): Set; /** - * Filters an item based on its existence in the database, raid moddability, and slot requirements. + * Populate a Map object of items for quick lookup by their ID. * - * @param item The item to be filtered. - * @param parentItemDbDetails The database details of the parent item, or null if the item has no parent. - * @param itemDbDetails A tuple where the first element is a boolean indicating if the item exists in the database, - * and the second element is the item details if it does. - * @returns true if the item exists in the database and neither of the following conditions are met: - * - The item has the RaidModdable property set to false. - * - The item is attached to a required slot in its parent item. - * Otherwise, returns false. + * @param insured The insurance object containing the items to populate the map with. + * @returns A Map where the keys are the item IDs and the values are the corresponding Item objects. */ - protected filterByRaidModdability(item: Item, parentItemDbDetails: ITemplateItem | null, itemDbDetails: [boolean, ITemplateItem]): boolean; + protected populateItemsMap(insured: Insurance): Map; /** - * Determines if an item is either a base item or a child item that is not equipped to its parent. + * 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 item The item to check. - * @returns true if the item is a base or an independent child item, otherwise false. + * @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. */ - protected isBaseOrIndependentChild(item: Item): boolean; + protected populateParentAttachmentsMap(insured: Insurance, itemsMap: Map): Map; /** - * Makes a roll to determine if a given item should be deleted. If the roll is successful, the item's ID is added - * to the `toDelete` array. + * 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. * - * @param item The item for which the roll is made. - * @param traderId The ID of the trader to consider in the rollForItemDelete method. - * @param toDelete The array accumulating the IDs of items to be deleted. - * @returns true if the item is marked for deletion, otherwise false. - */ - protected makeRollAndMarkForDeletion(item: Item, traderId: string, toDelete: Set): boolean; - /** - * Groups child items by their parent IDs in a Map data structure. - * - * @param item The child item to be grouped by its parent. - * @param childrenGroupedByParent The Map that holds arrays of children items grouped by their parent IDs. + * @param insured The insurance object containing the items to evaluate. + * @param toDelete A Set to keep track of items marked for deletion. * @returns void */ - protected groupChildrenByParent(item: Item, childrenGroupedByParent: Map): void; + protected processRegularItems(insured: Insurance, toDelete: Set): void; /** - * Sorts the array of children items in descending order by their maximum price. For each child, a roll is made to - * determine if it should be deleted. The method then deletes the most valuable children based on the number of - * successful rolls made. + * Process parent items and their attachments, updating the toDelete Set accordingly. * - * @param children The array of children items to sort and filter. - * @param traderId The ID of the trader to consider in the rollForItemDelete method. + * This method iterates over a map of parent items to their attachments and performs evaluations on each. + * It marks items for deletion based on certain conditions and updates the toDelete Set accordingly. + * + * @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. + */ + protected processAttachments(mainParentToAttachmentsMap: Map, itemsMap: Map, traderId: string, toDelete: Set): void; + /** + * 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. + * + * @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. * @returns void */ - protected sortAndFilterChildren(children: Item[], traderId: string, toDelete: Set): void; + protected processAttachmentByParent(attachments: Item[], traderId: string, toDelete: Set): void; + /** + * Sorts the attachment items by their max price in descending order. + * + * @param attachments The array of attachments items. + * @returns An array of items enriched with their max price and common locale-name. + */ + protected sortAttachmentsByPrice(attachments: Item[]): EnrichedItem[]; + /** + * Logs the details of each attachment item. + * + * @param attachments The array of attachment items. + */ + protected logAttachmentsDetails(attachments: EnrichedItem[]): void; + /** + * Counts the number of successful rolls for the attachment items. + * + * @param attachments The array of attachment items. + * @param traderId The ID of the trader that has insured these attachments. + * @returns The number of successful rolls. + */ + protected countSuccessfulRolls(attachments: Item[], traderId: string): number; + /** + * Marks the most valuable attachments for deletion based on the number of successful rolls made. + * + * @param attachments The array of attachment items. + * @param successfulRolls The number of successful rolls. + * @param toDelete The array that accumulates the IDs of the items to be deleted. + */ + protected attachmentDeletionByValue(attachments: EnrichedItem[], successfulRolls: number, toDelete: Set): void; /** * Remove items from the insured items that should not be returned to the player. * @@ -144,6 +168,22 @@ export declare class InsuranceController { * @returns void */ protected removeItemsFromInsurance(insured: Insurance, toDelete: Set): void; + /** + * Adopts orphaned items by resetting them as base-level items. Helpful in situations where a parent has been + * deleted from insurance, but any insured items within the parent should remain. This method will remove the + * reference from the children to the parent and set item properties to main-level values. + * + * @param insured Insurance object containing items. + */ + protected adoptOrphanedItems(insured: Insurance): void; + /** + * Fetches the parentId property of an item with a slotId "hideout". Not sure if this is actually dynamic, but this + * method should be a reliable way to fetch it, if it ever does change. + * + * @param items Array of items to search through. + * @returns The parentId of an item with slotId 'hideout'. Empty string if not found. + */ + protected fetchHideoutItemParent(items: Item[]): string; /** * Handle sending the insurance message to the user that potentially contains the valid insurance items. * @@ -154,15 +194,14 @@ export declare class InsuranceController { */ protected sendMail(sessionID: string, insurance: Insurance, noItems: boolean): void; /** - * Determines whether a valid insured item should be removed from the player's inventory based on a random roll and + * Determines whether a insured item should be removed from the player's inventory based on a random roll and * trader-specific return chance. * - * @param insuredItem The insured item being evaluated for removal. * @param traderId The ID of the trader who insured the item. - * @param itemsBeingDeleted List of items that are already slated for removal. + * @param insuredItem Optional. The item to roll for. Only used for logging. * @returns true if the insured item should be removed from inventory, false otherwise. */ - protected rollForItemDelete(insuredItem: Item, traderId: string, itemsBeingDeleted: Set): boolean; + protected rollForDelete(traderId: string, insuredItem?: Item): boolean; /** * Handle Insure event * Add insurance to an item @@ -183,3 +222,8 @@ export declare class InsuranceController { */ cost(request: IGetInsuranceCostRequestData, sessionID: string): IGetInsuranceCostResponseData; } +interface EnrichedItem extends Item { + name: string; + maxPrice: number; +} +export {}; diff --git a/TypeScript/1LogToConsole/types/di/Serializer.d.ts b/TypeScript/1LogToConsole/types/di/Serializer.d.ts index 2617007..b760b8b 100644 --- a/TypeScript/1LogToConsole/types/di/Serializer.d.ts +++ b/TypeScript/1LogToConsole/types/di/Serializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export declare class Serializer { serialize(sessionID: string, req: IncomingMessage, resp: ServerResponse, body: any): void; canHandle(something: string): boolean; diff --git a/TypeScript/1LogToConsole/types/helpers/ItemHelper.d.ts b/TypeScript/1LogToConsole/types/helpers/ItemHelper.d.ts index 6f1511c..5920d8a 100644 --- a/TypeScript/1LogToConsole/types/helpers/ItemHelper.d.ts +++ b/TypeScript/1LogToConsole/types/helpers/ItemHelper.d.ts @@ -225,6 +225,48 @@ declare class ItemHelper { * @returns true if item is flagged as quest item */ isQuestItem(tpl: string): boolean; + /** + * Checks to see if the item is *actually* moddable in-raid. Checks include the items existence in the database, the + * parent items existence in the database, the existence (and value) of the items RaidModdable property, and that + * the parents slot-required property exists, matches that of the item, and it's value. + * + * Note: this function does not preform any checks to see if the item and parent are *actually* related. + * + * @param item The item to be checked + * @param parent The parent of the item to be checked + * @returns True if the item is actually moddable, false if it is not, and null if the check cannot be performed. + */ + isRaidModdable(item: Item, parent: Item): boolean | null; + /** + * Retrieves the main parent item for a given attachment item. + * + * This method traverses up the hierarchy of items starting from a given `itemId`, until it finds the main parent + * item that is not an attached attachment itself. In other words, if you pass it an item id of a suppressor, it + * will traverse up the muzzle brake, barrel, upper receiver, and return the gun that the suppressor is ultimately + * attached to, even if that gun is located within multiple containers. + * + * It's important to note that traversal is expensive, so this method requires that you pass it a Map of the items + * to traverse, where the keys are the item IDs and the values are the corresponding Item objects. This alleviates + * some of the performance concerns, as it allows for quick lookups of items by ID. + * + * To generate the map: + * ``` + * const itemsMap = new Map(); + * items.forEach(item => itemsMap.set(item._id, item)); + * ``` + * + * @param itemId - The unique identifier of the item for which to find the main parent. + * @param itemsMap - A Map containing item IDs mapped to their corresponding Item objects for quick lookup. + * @returns The Item object representing the top-most parent of the given item, or `null` if no such parent exists. + */ + getAttachmentMainParent(itemId: string, itemsMap: Map): Item | null; + /** + * Determines if an item is an attachment that is currently attached to it's parent item. + * + * @param item The item to check. + * @returns true if the item is attached attachment, otherwise false. + */ + isAttachmentAttached(item: Item): boolean; /** * Get the inventory size of an item * @param items Item with children diff --git a/TypeScript/1LogToConsole/types/loaders/PreAkiModLoader.d.ts b/TypeScript/1LogToConsole/types/loaders/PreAkiModLoader.d.ts index 1e24b96..c0868b7 100644 --- a/TypeScript/1LogToConsole/types/loaders/PreAkiModLoader.d.ts +++ b/TypeScript/1LogToConsole/types/loaders/PreAkiModLoader.d.ts @@ -66,6 +66,10 @@ export declare class PreAkiModLoader implements IModLoader { protected isModCombatibleWithAki(mod: IPackageJsonData): boolean; protected executeMods(container: DependencyContainer): Promise; sortModsLoadOrder(): string[]; + /** + * Compile mod and add into class property "imported" + * @param mod Name of mod to compile/add + */ protected addMod(mod: string): Promise; protected autoInstallDependencies(modPath: string, pkg: IPackageJsonData): void; protected areModDependenciesFulfilled(pkg: IPackageJsonData, loadedMods: Record): boolean; diff --git a/TypeScript/1LogToConsole/types/models/external/HttpFramework.d.ts b/TypeScript/1LogToConsole/types/models/external/HttpFramework.d.ts index 64a37d6..fda8732 100644 --- a/TypeScript/1LogToConsole/types/models/external/HttpFramework.d.ts +++ b/TypeScript/1LogToConsole/types/models/external/HttpFramework.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export type HandleFn = (_: string, req: IncomingMessage, resp: ServerResponse) => void; /** * Associates handlers, HTTP methods and a base url to a listener using a proxy diff --git a/TypeScript/1LogToConsole/types/models/spt/mod/IPackageJsonData.d.ts b/TypeScript/1LogToConsole/types/models/spt/mod/IPackageJsonData.d.ts index 06f7454..f58d7cc 100644 --- a/TypeScript/1LogToConsole/types/models/spt/mod/IPackageJsonData.d.ts +++ b/TypeScript/1LogToConsole/types/models/spt/mod/IPackageJsonData.d.ts @@ -6,6 +6,9 @@ export interface IPackageJsonData { author: string; version: string; akiVersion: string; + /** We deliberately purge this data */ + scripts: Record; + devDependencies: Record; licence: string; main: string; isBundleMod: boolean; diff --git a/TypeScript/1LogToConsole/types/routers/HttpRouter.d.ts b/TypeScript/1LogToConsole/types/routers/HttpRouter.d.ts index f75a47d..46f847a 100644 --- a/TypeScript/1LogToConsole/types/routers/HttpRouter.d.ts +++ b/TypeScript/1LogToConsole/types/routers/HttpRouter.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage } from "http"; +import { IncomingMessage } from "node:http"; import { DynamicRouter, Router, StaticRouter } from "../di/Router"; export declare class HttpRouter { protected staticRouters: StaticRouter[]; diff --git a/TypeScript/1LogToConsole/types/routers/ImageRouter.d.ts b/TypeScript/1LogToConsole/types/routers/ImageRouter.d.ts index 675441c..fd03c59 100644 --- a/TypeScript/1LogToConsole/types/routers/ImageRouter.d.ts +++ b/TypeScript/1LogToConsole/types/routers/ImageRouter.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { ImageRouteService } from "../services/mod/image/ImageRouteService"; import { HttpFileUtil } from "../utils/HttpFileUtil"; import { VFS } from "../utils/VFS"; diff --git a/TypeScript/1LogToConsole/types/routers/serializers/BundleSerializer.d.ts b/TypeScript/1LogToConsole/types/routers/serializers/BundleSerializer.d.ts index ca4d8b6..db41142 100644 --- a/TypeScript/1LogToConsole/types/routers/serializers/BundleSerializer.d.ts +++ b/TypeScript/1LogToConsole/types/routers/serializers/BundleSerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { BundleLoader } from "../../loaders/BundleLoader"; import { ILogger } from "../../models/spt/utils/ILogger"; diff --git a/TypeScript/1LogToConsole/types/routers/serializers/ImageSerializer.d.ts b/TypeScript/1LogToConsole/types/routers/serializers/ImageSerializer.d.ts index 5de48ff..62ce84d 100644 --- a/TypeScript/1LogToConsole/types/routers/serializers/ImageSerializer.d.ts +++ b/TypeScript/1LogToConsole/types/routers/serializers/ImageSerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { ImageRouter } from "../ImageRouter"; export declare class ImageSerializer extends Serializer { diff --git a/TypeScript/1LogToConsole/types/routers/serializers/NotifySerializer.d.ts b/TypeScript/1LogToConsole/types/routers/serializers/NotifySerializer.d.ts index 1d179b2..e92d6e1 100644 --- a/TypeScript/1LogToConsole/types/routers/serializers/NotifySerializer.d.ts +++ b/TypeScript/1LogToConsole/types/routers/serializers/NotifySerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { NotifierController } from "../../controllers/NotifierController"; import { Serializer } from "../../di/Serializer"; import { HttpServerHelper } from "../../helpers/HttpServerHelper"; diff --git a/TypeScript/1LogToConsole/types/servers/HttpServer.d.ts b/TypeScript/1LogToConsole/types/servers/HttpServer.d.ts index 97e0705..c73eb3c 100644 --- a/TypeScript/1LogToConsole/types/servers/HttpServer.d.ts +++ b/TypeScript/1LogToConsole/types/servers/HttpServer.d.ts @@ -1,5 +1,5 @@ /// -import http, { IncomingMessage, ServerResponse } from "http"; +import http, { IncomingMessage, ServerResponse } from "node:http"; import { ApplicationContext } from "../context/ApplicationContext"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; import { IHttpConfig } from "../models/spt/config/IHttpConfig"; diff --git a/TypeScript/1LogToConsole/types/servers/WebSocketServer.d.ts b/TypeScript/1LogToConsole/types/servers/WebSocketServer.d.ts index fffbea2..b4c6158 100644 --- a/TypeScript/1LogToConsole/types/servers/WebSocketServer.d.ts +++ b/TypeScript/1LogToConsole/types/servers/WebSocketServer.d.ts @@ -1,5 +1,5 @@ /// -import http, { IncomingMessage } from "http"; +import http, { IncomingMessage } from "node:http"; import WebSocket from "ws"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; import { INotification } from "../models/eft/notifier/INotifier"; diff --git a/TypeScript/1LogToConsole/types/servers/http/AkiHttpListener.d.ts b/TypeScript/1LogToConsole/types/servers/http/AkiHttpListener.d.ts index c72e18f..e4ac80c 100644 --- a/TypeScript/1LogToConsole/types/servers/http/AkiHttpListener.d.ts +++ b/TypeScript/1LogToConsole/types/servers/http/AkiHttpListener.d.ts @@ -1,6 +1,6 @@ /// /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { ILogger } from "../../models/spt/utils/ILogger"; import { HttpRouter } from "../../routers/HttpRouter"; diff --git a/TypeScript/1LogToConsole/types/servers/http/IHttpListener.d.ts b/TypeScript/1LogToConsole/types/servers/http/IHttpListener.d.ts index 758bb5a..29d5fce 100644 --- a/TypeScript/1LogToConsole/types/servers/http/IHttpListener.d.ts +++ b/TypeScript/1LogToConsole/types/servers/http/IHttpListener.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export interface IHttpListener { canHandle(sessionId: string, req: IncomingMessage): boolean; handle(sessionId: string, req: IncomingMessage, resp: ServerResponse): void; diff --git a/TypeScript/1LogToConsole/types/services/mod/httpListener/HttpListenerMod.d.ts b/TypeScript/1LogToConsole/types/services/mod/httpListener/HttpListenerMod.d.ts index 2cdfbda..afe4574 100644 --- a/TypeScript/1LogToConsole/types/services/mod/httpListener/HttpListenerMod.d.ts +++ b/TypeScript/1LogToConsole/types/services/mod/httpListener/HttpListenerMod.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { IHttpListener } from "../../../servers/http/IHttpListener"; export declare class HttpListenerMod implements IHttpListener { private canHandleOverride; diff --git a/TypeScript/1LogToConsole/types/services/mod/httpListener/HttpListenerModService.d.ts b/TypeScript/1LogToConsole/types/services/mod/httpListener/HttpListenerModService.d.ts index 9dd3473..23abfbe 100644 --- a/TypeScript/1LogToConsole/types/services/mod/httpListener/HttpListenerModService.d.ts +++ b/TypeScript/1LogToConsole/types/services/mod/httpListener/HttpListenerModService.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { DependencyContainer } from "tsyringe"; export declare class HttpListenerModService { protected container: DependencyContainer; diff --git a/TypeScript/1LogToConsole/types/utils/App.d.ts b/TypeScript/1LogToConsole/types/utils/App.d.ts index dd8f24c..5e759ad 100644 --- a/TypeScript/1LogToConsole/types/utils/App.d.ts +++ b/TypeScript/1LogToConsole/types/utils/App.d.ts @@ -12,7 +12,6 @@ export declare class App { protected onLoadComponents: OnLoad[]; protected onUpdateComponents: OnUpdate[]; protected onUpdateLastRun: {}; - protected os: any; constructor(logger: ILogger, timeUtil: TimeUtil, localisationService: LocalisationService, encodingUtil: EncodingUtil, onLoadComponents: OnLoad[], onUpdateComponents: OnUpdate[]); load(): Promise; protected update(onUpdateComponents: OnUpdate[]): Promise; diff --git a/TypeScript/1LogToConsole/types/utils/HashUtil.d.ts b/TypeScript/1LogToConsole/types/utils/HashUtil.d.ts index c017ca8..27204cb 100644 --- a/TypeScript/1LogToConsole/types/utils/HashUtil.d.ts +++ b/TypeScript/1LogToConsole/types/utils/HashUtil.d.ts @@ -1,5 +1,5 @@ /// -import crypto from "crypto"; +import crypto from "node:crypto"; import { TimeUtil } from "./TimeUtil"; export declare class HashUtil { protected timeUtil: TimeUtil; diff --git a/TypeScript/1LogToConsole/types/utils/HttpFileUtil.d.ts b/TypeScript/1LogToConsole/types/utils/HttpFileUtil.d.ts index afc8409..6a386ce 100644 --- a/TypeScript/1LogToConsole/types/utils/HttpFileUtil.d.ts +++ b/TypeScript/1LogToConsole/types/utils/HttpFileUtil.d.ts @@ -1,5 +1,5 @@ /// -import { ServerResponse } from "http"; +import { ServerResponse } from "node:http"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; export declare class HttpFileUtil { protected httpServerHelper: HttpServerHelper; diff --git a/TypeScript/1LogToConsole/types/utils/VFS.d.ts b/TypeScript/1LogToConsole/types/utils/VFS.d.ts index 2cb09fa..3911c4b 100644 --- a/TypeScript/1LogToConsole/types/utils/VFS.d.ts +++ b/TypeScript/1LogToConsole/types/utils/VFS.d.ts @@ -1,6 +1,6 @@ /// /// -import fs from "fs"; +import fs from "node:fs"; import "reflect-metadata"; import { IAsyncQueue } from "../models/spt/utils/IAsyncQueue"; import { IUUidGenerator } from "../models/spt/utils/IUuidGenerator"; diff --git a/TypeScript/1LogToConsole/types/utils/Watermark.d.ts b/TypeScript/1LogToConsole/types/utils/Watermark.d.ts index fa63205..864e9b6 100644 --- a/TypeScript/1LogToConsole/types/utils/Watermark.d.ts +++ b/TypeScript/1LogToConsole/types/utils/Watermark.d.ts @@ -4,12 +4,10 @@ import { ConfigServer } from "../servers/ConfigServer"; import { LocalisationService } from "../services/LocalisationService"; export declare class WatermarkLocale { protected localisationService: LocalisationService; + protected description: string[]; + protected warning: string[]; + protected modding: string[]; constructor(localisationService: LocalisationService); - protected watermark: { - description: string[]; - warning: string[]; - modding: string[]; - }; getDescription(): string[]; getWarning(): string[]; getModding(): string[]; diff --git a/TypeScript/1LogToConsole/types/utils/logging/AbstractWinstonLogger.d.ts b/TypeScript/1LogToConsole/types/utils/logging/AbstractWinstonLogger.d.ts index 1ae1100..74767a2 100644 --- a/TypeScript/1LogToConsole/types/utils/logging/AbstractWinstonLogger.d.ts +++ b/TypeScript/1LogToConsole/types/utils/logging/AbstractWinstonLogger.d.ts @@ -1,5 +1,5 @@ /// -import fs from "fs"; +import fs from "node:fs"; import winston from "winston"; import { Daum } from "../../models/eft/itemEvent/IItemEventRouterRequest"; import { LogBackgroundColor } from "../../models/spt/logging/LogBackgroundColor"; diff --git a/TypeScript/2EditDatabase/types/controllers/GameController.d.ts b/TypeScript/2EditDatabase/types/controllers/GameController.d.ts index 73596ff..74123b2 100644 --- a/TypeScript/2EditDatabase/types/controllers/GameController.d.ts +++ b/TypeScript/2EditDatabase/types/controllers/GameController.d.ts @@ -49,7 +49,6 @@ export declare class GameController { protected giftService: GiftService; protected applicationContext: ApplicationContext; protected configServer: ConfigServer; - protected os: any; protected httpConfig: IHttpConfig; protected coreConfig: ICoreConfig; protected locationConfig: ILocationConfig; diff --git a/TypeScript/2EditDatabase/types/controllers/InsuranceController.d.ts b/TypeScript/2EditDatabase/types/controllers/InsuranceController.d.ts index fb41610..fc3229b 100644 --- a/TypeScript/2EditDatabase/types/controllers/InsuranceController.d.ts +++ b/TypeScript/2EditDatabase/types/controllers/InsuranceController.d.ts @@ -4,7 +4,6 @@ import { ProfileHelper } from "../helpers/ProfileHelper"; import { TraderHelper } from "../helpers/TraderHelper"; import { IPmcData } from "../models/eft/common/IPmcData"; import { Item } from "../models/eft/common/tables/IItem"; -import { ITemplateItem } from "../models/eft/common/tables/ITemplateItem"; import { IGetInsuranceCostRequestData } from "../models/eft/insurance/IGetInsuranceCostRequestData"; import { IGetInsuranceCostResponseData } from "../models/eft/insurance/IGetInsuranceCostResponseData"; import { IInsureRequestData } from "../models/eft/insurance/IInsureRequestData"; @@ -75,67 +74,92 @@ export declare class InsuranceController { */ protected removeInsurancePackageFromProfile(sessionID: string, packageInfo: ISystemData): void; /** - * Build an array of items to delete from the insured items. + * Finds the items that should be deleted based on the given Insurance object. * - * This method orchestrates several steps: - * - Filters items based on their presence in the database and their raid moddability. - * - Sorts base and independent child items to consider for deletion. - * - Groups child items by their parent for later evaluation. - * - Evaluates grouped child items to decide which should be deleted, based on their value and a random roll. - * - * @param insured - The insured items to build a removal array from. - * @returns An array of IDs representing items that should be deleted. + * @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(insured: Insurance): Set; /** - * Filters an item based on its existence in the database, raid moddability, and slot requirements. + * Populate a Map object of items for quick lookup by their ID. * - * @param item The item to be filtered. - * @param parentItemDbDetails The database details of the parent item, or null if the item has no parent. - * @param itemDbDetails A tuple where the first element is a boolean indicating if the item exists in the database, - * and the second element is the item details if it does. - * @returns true if the item exists in the database and neither of the following conditions are met: - * - The item has the RaidModdable property set to false. - * - The item is attached to a required slot in its parent item. - * Otherwise, returns false. + * @param insured The insurance object containing the items to populate the map with. + * @returns A Map where the keys are the item IDs and the values are the corresponding Item objects. */ - protected filterByRaidModdability(item: Item, parentItemDbDetails: ITemplateItem | null, itemDbDetails: [boolean, ITemplateItem]): boolean; + protected populateItemsMap(insured: Insurance): Map; /** - * Determines if an item is either a base item or a child item that is not equipped to its parent. + * 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 item The item to check. - * @returns true if the item is a base or an independent child item, otherwise false. + * @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. */ - protected isBaseOrIndependentChild(item: Item): boolean; + protected populateParentAttachmentsMap(insured: Insurance, itemsMap: Map): Map; /** - * Makes a roll to determine if a given item should be deleted. If the roll is successful, the item's ID is added - * to the `toDelete` array. + * 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. * - * @param item The item for which the roll is made. - * @param traderId The ID of the trader to consider in the rollForItemDelete method. - * @param toDelete The array accumulating the IDs of items to be deleted. - * @returns true if the item is marked for deletion, otherwise false. - */ - protected makeRollAndMarkForDeletion(item: Item, traderId: string, toDelete: Set): boolean; - /** - * Groups child items by their parent IDs in a Map data structure. - * - * @param item The child item to be grouped by its parent. - * @param childrenGroupedByParent The Map that holds arrays of children items grouped by their parent IDs. + * @param insured The insurance object containing the items to evaluate. + * @param toDelete A Set to keep track of items marked for deletion. * @returns void */ - protected groupChildrenByParent(item: Item, childrenGroupedByParent: Map): void; + protected processRegularItems(insured: Insurance, toDelete: Set): void; /** - * Sorts the array of children items in descending order by their maximum price. For each child, a roll is made to - * determine if it should be deleted. The method then deletes the most valuable children based on the number of - * successful rolls made. + * Process parent items and their attachments, updating the toDelete Set accordingly. * - * @param children The array of children items to sort and filter. - * @param traderId The ID of the trader to consider in the rollForItemDelete method. + * This method iterates over a map of parent items to their attachments and performs evaluations on each. + * It marks items for deletion based on certain conditions and updates the toDelete Set accordingly. + * + * @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. + */ + protected processAttachments(mainParentToAttachmentsMap: Map, itemsMap: Map, traderId: string, toDelete: Set): void; + /** + * 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. + * + * @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. * @returns void */ - protected sortAndFilterChildren(children: Item[], traderId: string, toDelete: Set): void; + protected processAttachmentByParent(attachments: Item[], traderId: string, toDelete: Set): void; + /** + * Sorts the attachment items by their max price in descending order. + * + * @param attachments The array of attachments items. + * @returns An array of items enriched with their max price and common locale-name. + */ + protected sortAttachmentsByPrice(attachments: Item[]): EnrichedItem[]; + /** + * Logs the details of each attachment item. + * + * @param attachments The array of attachment items. + */ + protected logAttachmentsDetails(attachments: EnrichedItem[]): void; + /** + * Counts the number of successful rolls for the attachment items. + * + * @param attachments The array of attachment items. + * @param traderId The ID of the trader that has insured these attachments. + * @returns The number of successful rolls. + */ + protected countSuccessfulRolls(attachments: Item[], traderId: string): number; + /** + * Marks the most valuable attachments for deletion based on the number of successful rolls made. + * + * @param attachments The array of attachment items. + * @param successfulRolls The number of successful rolls. + * @param toDelete The array that accumulates the IDs of the items to be deleted. + */ + protected attachmentDeletionByValue(attachments: EnrichedItem[], successfulRolls: number, toDelete: Set): void; /** * Remove items from the insured items that should not be returned to the player. * @@ -144,6 +168,22 @@ export declare class InsuranceController { * @returns void */ protected removeItemsFromInsurance(insured: Insurance, toDelete: Set): void; + /** + * Adopts orphaned items by resetting them as base-level items. Helpful in situations where a parent has been + * deleted from insurance, but any insured items within the parent should remain. This method will remove the + * reference from the children to the parent and set item properties to main-level values. + * + * @param insured Insurance object containing items. + */ + protected adoptOrphanedItems(insured: Insurance): void; + /** + * Fetches the parentId property of an item with a slotId "hideout". Not sure if this is actually dynamic, but this + * method should be a reliable way to fetch it, if it ever does change. + * + * @param items Array of items to search through. + * @returns The parentId of an item with slotId 'hideout'. Empty string if not found. + */ + protected fetchHideoutItemParent(items: Item[]): string; /** * Handle sending the insurance message to the user that potentially contains the valid insurance items. * @@ -154,15 +194,14 @@ export declare class InsuranceController { */ protected sendMail(sessionID: string, insurance: Insurance, noItems: boolean): void; /** - * Determines whether a valid insured item should be removed from the player's inventory based on a random roll and + * Determines whether a insured item should be removed from the player's inventory based on a random roll and * trader-specific return chance. * - * @param insuredItem The insured item being evaluated for removal. * @param traderId The ID of the trader who insured the item. - * @param itemsBeingDeleted List of items that are already slated for removal. + * @param insuredItem Optional. The item to roll for. Only used for logging. * @returns true if the insured item should be removed from inventory, false otherwise. */ - protected rollForItemDelete(insuredItem: Item, traderId: string, itemsBeingDeleted: Set): boolean; + protected rollForDelete(traderId: string, insuredItem?: Item): boolean; /** * Handle Insure event * Add insurance to an item @@ -183,3 +222,8 @@ export declare class InsuranceController { */ cost(request: IGetInsuranceCostRequestData, sessionID: string): IGetInsuranceCostResponseData; } +interface EnrichedItem extends Item { + name: string; + maxPrice: number; +} +export {}; diff --git a/TypeScript/2EditDatabase/types/di/Serializer.d.ts b/TypeScript/2EditDatabase/types/di/Serializer.d.ts index 2617007..b760b8b 100644 --- a/TypeScript/2EditDatabase/types/di/Serializer.d.ts +++ b/TypeScript/2EditDatabase/types/di/Serializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export declare class Serializer { serialize(sessionID: string, req: IncomingMessage, resp: ServerResponse, body: any): void; canHandle(something: string): boolean; diff --git a/TypeScript/2EditDatabase/types/helpers/ItemHelper.d.ts b/TypeScript/2EditDatabase/types/helpers/ItemHelper.d.ts index 6f1511c..5920d8a 100644 --- a/TypeScript/2EditDatabase/types/helpers/ItemHelper.d.ts +++ b/TypeScript/2EditDatabase/types/helpers/ItemHelper.d.ts @@ -225,6 +225,48 @@ declare class ItemHelper { * @returns true if item is flagged as quest item */ isQuestItem(tpl: string): boolean; + /** + * Checks to see if the item is *actually* moddable in-raid. Checks include the items existence in the database, the + * parent items existence in the database, the existence (and value) of the items RaidModdable property, and that + * the parents slot-required property exists, matches that of the item, and it's value. + * + * Note: this function does not preform any checks to see if the item and parent are *actually* related. + * + * @param item The item to be checked + * @param parent The parent of the item to be checked + * @returns True if the item is actually moddable, false if it is not, and null if the check cannot be performed. + */ + isRaidModdable(item: Item, parent: Item): boolean | null; + /** + * Retrieves the main parent item for a given attachment item. + * + * This method traverses up the hierarchy of items starting from a given `itemId`, until it finds the main parent + * item that is not an attached attachment itself. In other words, if you pass it an item id of a suppressor, it + * will traverse up the muzzle brake, barrel, upper receiver, and return the gun that the suppressor is ultimately + * attached to, even if that gun is located within multiple containers. + * + * It's important to note that traversal is expensive, so this method requires that you pass it a Map of the items + * to traverse, where the keys are the item IDs and the values are the corresponding Item objects. This alleviates + * some of the performance concerns, as it allows for quick lookups of items by ID. + * + * To generate the map: + * ``` + * const itemsMap = new Map(); + * items.forEach(item => itemsMap.set(item._id, item)); + * ``` + * + * @param itemId - The unique identifier of the item for which to find the main parent. + * @param itemsMap - A Map containing item IDs mapped to their corresponding Item objects for quick lookup. + * @returns The Item object representing the top-most parent of the given item, or `null` if no such parent exists. + */ + getAttachmentMainParent(itemId: string, itemsMap: Map): Item | null; + /** + * Determines if an item is an attachment that is currently attached to it's parent item. + * + * @param item The item to check. + * @returns true if the item is attached attachment, otherwise false. + */ + isAttachmentAttached(item: Item): boolean; /** * Get the inventory size of an item * @param items Item with children diff --git a/TypeScript/2EditDatabase/types/loaders/PreAkiModLoader.d.ts b/TypeScript/2EditDatabase/types/loaders/PreAkiModLoader.d.ts index 1e24b96..c0868b7 100644 --- a/TypeScript/2EditDatabase/types/loaders/PreAkiModLoader.d.ts +++ b/TypeScript/2EditDatabase/types/loaders/PreAkiModLoader.d.ts @@ -66,6 +66,10 @@ export declare class PreAkiModLoader implements IModLoader { protected isModCombatibleWithAki(mod: IPackageJsonData): boolean; protected executeMods(container: DependencyContainer): Promise; sortModsLoadOrder(): string[]; + /** + * Compile mod and add into class property "imported" + * @param mod Name of mod to compile/add + */ protected addMod(mod: string): Promise; protected autoInstallDependencies(modPath: string, pkg: IPackageJsonData): void; protected areModDependenciesFulfilled(pkg: IPackageJsonData, loadedMods: Record): boolean; diff --git a/TypeScript/2EditDatabase/types/models/external/HttpFramework.d.ts b/TypeScript/2EditDatabase/types/models/external/HttpFramework.d.ts index 64a37d6..fda8732 100644 --- a/TypeScript/2EditDatabase/types/models/external/HttpFramework.d.ts +++ b/TypeScript/2EditDatabase/types/models/external/HttpFramework.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export type HandleFn = (_: string, req: IncomingMessage, resp: ServerResponse) => void; /** * Associates handlers, HTTP methods and a base url to a listener using a proxy diff --git a/TypeScript/2EditDatabase/types/models/spt/mod/IPackageJsonData.d.ts b/TypeScript/2EditDatabase/types/models/spt/mod/IPackageJsonData.d.ts index 06f7454..f58d7cc 100644 --- a/TypeScript/2EditDatabase/types/models/spt/mod/IPackageJsonData.d.ts +++ b/TypeScript/2EditDatabase/types/models/spt/mod/IPackageJsonData.d.ts @@ -6,6 +6,9 @@ export interface IPackageJsonData { author: string; version: string; akiVersion: string; + /** We deliberately purge this data */ + scripts: Record; + devDependencies: Record; licence: string; main: string; isBundleMod: boolean; diff --git a/TypeScript/2EditDatabase/types/routers/HttpRouter.d.ts b/TypeScript/2EditDatabase/types/routers/HttpRouter.d.ts index f75a47d..46f847a 100644 --- a/TypeScript/2EditDatabase/types/routers/HttpRouter.d.ts +++ b/TypeScript/2EditDatabase/types/routers/HttpRouter.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage } from "http"; +import { IncomingMessage } from "node:http"; import { DynamicRouter, Router, StaticRouter } from "../di/Router"; export declare class HttpRouter { protected staticRouters: StaticRouter[]; diff --git a/TypeScript/2EditDatabase/types/routers/ImageRouter.d.ts b/TypeScript/2EditDatabase/types/routers/ImageRouter.d.ts index 675441c..fd03c59 100644 --- a/TypeScript/2EditDatabase/types/routers/ImageRouter.d.ts +++ b/TypeScript/2EditDatabase/types/routers/ImageRouter.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { ImageRouteService } from "../services/mod/image/ImageRouteService"; import { HttpFileUtil } from "../utils/HttpFileUtil"; import { VFS } from "../utils/VFS"; diff --git a/TypeScript/2EditDatabase/types/routers/serializers/BundleSerializer.d.ts b/TypeScript/2EditDatabase/types/routers/serializers/BundleSerializer.d.ts index ca4d8b6..db41142 100644 --- a/TypeScript/2EditDatabase/types/routers/serializers/BundleSerializer.d.ts +++ b/TypeScript/2EditDatabase/types/routers/serializers/BundleSerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { BundleLoader } from "../../loaders/BundleLoader"; import { ILogger } from "../../models/spt/utils/ILogger"; diff --git a/TypeScript/2EditDatabase/types/routers/serializers/ImageSerializer.d.ts b/TypeScript/2EditDatabase/types/routers/serializers/ImageSerializer.d.ts index 5de48ff..62ce84d 100644 --- a/TypeScript/2EditDatabase/types/routers/serializers/ImageSerializer.d.ts +++ b/TypeScript/2EditDatabase/types/routers/serializers/ImageSerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { ImageRouter } from "../ImageRouter"; export declare class ImageSerializer extends Serializer { diff --git a/TypeScript/2EditDatabase/types/routers/serializers/NotifySerializer.d.ts b/TypeScript/2EditDatabase/types/routers/serializers/NotifySerializer.d.ts index 1d179b2..e92d6e1 100644 --- a/TypeScript/2EditDatabase/types/routers/serializers/NotifySerializer.d.ts +++ b/TypeScript/2EditDatabase/types/routers/serializers/NotifySerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { NotifierController } from "../../controllers/NotifierController"; import { Serializer } from "../../di/Serializer"; import { HttpServerHelper } from "../../helpers/HttpServerHelper"; diff --git a/TypeScript/2EditDatabase/types/servers/HttpServer.d.ts b/TypeScript/2EditDatabase/types/servers/HttpServer.d.ts index 97e0705..c73eb3c 100644 --- a/TypeScript/2EditDatabase/types/servers/HttpServer.d.ts +++ b/TypeScript/2EditDatabase/types/servers/HttpServer.d.ts @@ -1,5 +1,5 @@ /// -import http, { IncomingMessage, ServerResponse } from "http"; +import http, { IncomingMessage, ServerResponse } from "node:http"; import { ApplicationContext } from "../context/ApplicationContext"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; import { IHttpConfig } from "../models/spt/config/IHttpConfig"; diff --git a/TypeScript/2EditDatabase/types/servers/WebSocketServer.d.ts b/TypeScript/2EditDatabase/types/servers/WebSocketServer.d.ts index fffbea2..b4c6158 100644 --- a/TypeScript/2EditDatabase/types/servers/WebSocketServer.d.ts +++ b/TypeScript/2EditDatabase/types/servers/WebSocketServer.d.ts @@ -1,5 +1,5 @@ /// -import http, { IncomingMessage } from "http"; +import http, { IncomingMessage } from "node:http"; import WebSocket from "ws"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; import { INotification } from "../models/eft/notifier/INotifier"; diff --git a/TypeScript/2EditDatabase/types/servers/http/AkiHttpListener.d.ts b/TypeScript/2EditDatabase/types/servers/http/AkiHttpListener.d.ts index c72e18f..e4ac80c 100644 --- a/TypeScript/2EditDatabase/types/servers/http/AkiHttpListener.d.ts +++ b/TypeScript/2EditDatabase/types/servers/http/AkiHttpListener.d.ts @@ -1,6 +1,6 @@ /// /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { ILogger } from "../../models/spt/utils/ILogger"; import { HttpRouter } from "../../routers/HttpRouter"; diff --git a/TypeScript/2EditDatabase/types/servers/http/IHttpListener.d.ts b/TypeScript/2EditDatabase/types/servers/http/IHttpListener.d.ts index 758bb5a..29d5fce 100644 --- a/TypeScript/2EditDatabase/types/servers/http/IHttpListener.d.ts +++ b/TypeScript/2EditDatabase/types/servers/http/IHttpListener.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export interface IHttpListener { canHandle(sessionId: string, req: IncomingMessage): boolean; handle(sessionId: string, req: IncomingMessage, resp: ServerResponse): void; diff --git a/TypeScript/2EditDatabase/types/services/mod/httpListener/HttpListenerMod.d.ts b/TypeScript/2EditDatabase/types/services/mod/httpListener/HttpListenerMod.d.ts index 2cdfbda..afe4574 100644 --- a/TypeScript/2EditDatabase/types/services/mod/httpListener/HttpListenerMod.d.ts +++ b/TypeScript/2EditDatabase/types/services/mod/httpListener/HttpListenerMod.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { IHttpListener } from "../../../servers/http/IHttpListener"; export declare class HttpListenerMod implements IHttpListener { private canHandleOverride; diff --git a/TypeScript/2EditDatabase/types/services/mod/httpListener/HttpListenerModService.d.ts b/TypeScript/2EditDatabase/types/services/mod/httpListener/HttpListenerModService.d.ts index 9dd3473..23abfbe 100644 --- a/TypeScript/2EditDatabase/types/services/mod/httpListener/HttpListenerModService.d.ts +++ b/TypeScript/2EditDatabase/types/services/mod/httpListener/HttpListenerModService.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { DependencyContainer } from "tsyringe"; export declare class HttpListenerModService { protected container: DependencyContainer; diff --git a/TypeScript/2EditDatabase/types/utils/App.d.ts b/TypeScript/2EditDatabase/types/utils/App.d.ts index dd8f24c..5e759ad 100644 --- a/TypeScript/2EditDatabase/types/utils/App.d.ts +++ b/TypeScript/2EditDatabase/types/utils/App.d.ts @@ -12,7 +12,6 @@ export declare class App { protected onLoadComponents: OnLoad[]; protected onUpdateComponents: OnUpdate[]; protected onUpdateLastRun: {}; - protected os: any; constructor(logger: ILogger, timeUtil: TimeUtil, localisationService: LocalisationService, encodingUtil: EncodingUtil, onLoadComponents: OnLoad[], onUpdateComponents: OnUpdate[]); load(): Promise; protected update(onUpdateComponents: OnUpdate[]): Promise; diff --git a/TypeScript/2EditDatabase/types/utils/HashUtil.d.ts b/TypeScript/2EditDatabase/types/utils/HashUtil.d.ts index c017ca8..27204cb 100644 --- a/TypeScript/2EditDatabase/types/utils/HashUtil.d.ts +++ b/TypeScript/2EditDatabase/types/utils/HashUtil.d.ts @@ -1,5 +1,5 @@ /// -import crypto from "crypto"; +import crypto from "node:crypto"; import { TimeUtil } from "./TimeUtil"; export declare class HashUtil { protected timeUtil: TimeUtil; diff --git a/TypeScript/2EditDatabase/types/utils/HttpFileUtil.d.ts b/TypeScript/2EditDatabase/types/utils/HttpFileUtil.d.ts index afc8409..6a386ce 100644 --- a/TypeScript/2EditDatabase/types/utils/HttpFileUtil.d.ts +++ b/TypeScript/2EditDatabase/types/utils/HttpFileUtil.d.ts @@ -1,5 +1,5 @@ /// -import { ServerResponse } from "http"; +import { ServerResponse } from "node:http"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; export declare class HttpFileUtil { protected httpServerHelper: HttpServerHelper; diff --git a/TypeScript/2EditDatabase/types/utils/VFS.d.ts b/TypeScript/2EditDatabase/types/utils/VFS.d.ts index 2cb09fa..3911c4b 100644 --- a/TypeScript/2EditDatabase/types/utils/VFS.d.ts +++ b/TypeScript/2EditDatabase/types/utils/VFS.d.ts @@ -1,6 +1,6 @@ /// /// -import fs from "fs"; +import fs from "node:fs"; import "reflect-metadata"; import { IAsyncQueue } from "../models/spt/utils/IAsyncQueue"; import { IUUidGenerator } from "../models/spt/utils/IUuidGenerator"; diff --git a/TypeScript/2EditDatabase/types/utils/Watermark.d.ts b/TypeScript/2EditDatabase/types/utils/Watermark.d.ts index fa63205..864e9b6 100644 --- a/TypeScript/2EditDatabase/types/utils/Watermark.d.ts +++ b/TypeScript/2EditDatabase/types/utils/Watermark.d.ts @@ -4,12 +4,10 @@ import { ConfigServer } from "../servers/ConfigServer"; import { LocalisationService } from "../services/LocalisationService"; export declare class WatermarkLocale { protected localisationService: LocalisationService; + protected description: string[]; + protected warning: string[]; + protected modding: string[]; constructor(localisationService: LocalisationService); - protected watermark: { - description: string[]; - warning: string[]; - modding: string[]; - }; getDescription(): string[]; getWarning(): string[]; getModding(): string[]; diff --git a/TypeScript/2EditDatabase/types/utils/logging/AbstractWinstonLogger.d.ts b/TypeScript/2EditDatabase/types/utils/logging/AbstractWinstonLogger.d.ts index 1ae1100..74767a2 100644 --- a/TypeScript/2EditDatabase/types/utils/logging/AbstractWinstonLogger.d.ts +++ b/TypeScript/2EditDatabase/types/utils/logging/AbstractWinstonLogger.d.ts @@ -1,5 +1,5 @@ /// -import fs from "fs"; +import fs from "node:fs"; import winston from "winston"; import { Daum } from "../../models/eft/itemEvent/IItemEventRouterRequest"; import { LogBackgroundColor } from "../../models/spt/logging/LogBackgroundColor"; diff --git a/TypeScript/3GetSptConfigFile/types/controllers/GameController.d.ts b/TypeScript/3GetSptConfigFile/types/controllers/GameController.d.ts index 73596ff..74123b2 100644 --- a/TypeScript/3GetSptConfigFile/types/controllers/GameController.d.ts +++ b/TypeScript/3GetSptConfigFile/types/controllers/GameController.d.ts @@ -49,7 +49,6 @@ export declare class GameController { protected giftService: GiftService; protected applicationContext: ApplicationContext; protected configServer: ConfigServer; - protected os: any; protected httpConfig: IHttpConfig; protected coreConfig: ICoreConfig; protected locationConfig: ILocationConfig; diff --git a/TypeScript/3GetSptConfigFile/types/controllers/InsuranceController.d.ts b/TypeScript/3GetSptConfigFile/types/controllers/InsuranceController.d.ts index fb41610..fc3229b 100644 --- a/TypeScript/3GetSptConfigFile/types/controllers/InsuranceController.d.ts +++ b/TypeScript/3GetSptConfigFile/types/controllers/InsuranceController.d.ts @@ -4,7 +4,6 @@ import { ProfileHelper } from "../helpers/ProfileHelper"; import { TraderHelper } from "../helpers/TraderHelper"; import { IPmcData } from "../models/eft/common/IPmcData"; import { Item } from "../models/eft/common/tables/IItem"; -import { ITemplateItem } from "../models/eft/common/tables/ITemplateItem"; import { IGetInsuranceCostRequestData } from "../models/eft/insurance/IGetInsuranceCostRequestData"; import { IGetInsuranceCostResponseData } from "../models/eft/insurance/IGetInsuranceCostResponseData"; import { IInsureRequestData } from "../models/eft/insurance/IInsureRequestData"; @@ -75,67 +74,92 @@ export declare class InsuranceController { */ protected removeInsurancePackageFromProfile(sessionID: string, packageInfo: ISystemData): void; /** - * Build an array of items to delete from the insured items. + * Finds the items that should be deleted based on the given Insurance object. * - * This method orchestrates several steps: - * - Filters items based on their presence in the database and their raid moddability. - * - Sorts base and independent child items to consider for deletion. - * - Groups child items by their parent for later evaluation. - * - Evaluates grouped child items to decide which should be deleted, based on their value and a random roll. - * - * @param insured - The insured items to build a removal array from. - * @returns An array of IDs representing items that should be deleted. + * @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(insured: Insurance): Set; /** - * Filters an item based on its existence in the database, raid moddability, and slot requirements. + * Populate a Map object of items for quick lookup by their ID. * - * @param item The item to be filtered. - * @param parentItemDbDetails The database details of the parent item, or null if the item has no parent. - * @param itemDbDetails A tuple where the first element is a boolean indicating if the item exists in the database, - * and the second element is the item details if it does. - * @returns true if the item exists in the database and neither of the following conditions are met: - * - The item has the RaidModdable property set to false. - * - The item is attached to a required slot in its parent item. - * Otherwise, returns false. + * @param insured The insurance object containing the items to populate the map with. + * @returns A Map where the keys are the item IDs and the values are the corresponding Item objects. */ - protected filterByRaidModdability(item: Item, parentItemDbDetails: ITemplateItem | null, itemDbDetails: [boolean, ITemplateItem]): boolean; + protected populateItemsMap(insured: Insurance): Map; /** - * Determines if an item is either a base item or a child item that is not equipped to its parent. + * 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 item The item to check. - * @returns true if the item is a base or an independent child item, otherwise false. + * @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. */ - protected isBaseOrIndependentChild(item: Item): boolean; + protected populateParentAttachmentsMap(insured: Insurance, itemsMap: Map): Map; /** - * Makes a roll to determine if a given item should be deleted. If the roll is successful, the item's ID is added - * to the `toDelete` array. + * 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. * - * @param item The item for which the roll is made. - * @param traderId The ID of the trader to consider in the rollForItemDelete method. - * @param toDelete The array accumulating the IDs of items to be deleted. - * @returns true if the item is marked for deletion, otherwise false. - */ - protected makeRollAndMarkForDeletion(item: Item, traderId: string, toDelete: Set): boolean; - /** - * Groups child items by their parent IDs in a Map data structure. - * - * @param item The child item to be grouped by its parent. - * @param childrenGroupedByParent The Map that holds arrays of children items grouped by their parent IDs. + * @param insured The insurance object containing the items to evaluate. + * @param toDelete A Set to keep track of items marked for deletion. * @returns void */ - protected groupChildrenByParent(item: Item, childrenGroupedByParent: Map): void; + protected processRegularItems(insured: Insurance, toDelete: Set): void; /** - * Sorts the array of children items in descending order by their maximum price. For each child, a roll is made to - * determine if it should be deleted. The method then deletes the most valuable children based on the number of - * successful rolls made. + * Process parent items and their attachments, updating the toDelete Set accordingly. * - * @param children The array of children items to sort and filter. - * @param traderId The ID of the trader to consider in the rollForItemDelete method. + * This method iterates over a map of parent items to their attachments and performs evaluations on each. + * It marks items for deletion based on certain conditions and updates the toDelete Set accordingly. + * + * @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. + */ + protected processAttachments(mainParentToAttachmentsMap: Map, itemsMap: Map, traderId: string, toDelete: Set): void; + /** + * 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. + * + * @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. * @returns void */ - protected sortAndFilterChildren(children: Item[], traderId: string, toDelete: Set): void; + protected processAttachmentByParent(attachments: Item[], traderId: string, toDelete: Set): void; + /** + * Sorts the attachment items by their max price in descending order. + * + * @param attachments The array of attachments items. + * @returns An array of items enriched with their max price and common locale-name. + */ + protected sortAttachmentsByPrice(attachments: Item[]): EnrichedItem[]; + /** + * Logs the details of each attachment item. + * + * @param attachments The array of attachment items. + */ + protected logAttachmentsDetails(attachments: EnrichedItem[]): void; + /** + * Counts the number of successful rolls for the attachment items. + * + * @param attachments The array of attachment items. + * @param traderId The ID of the trader that has insured these attachments. + * @returns The number of successful rolls. + */ + protected countSuccessfulRolls(attachments: Item[], traderId: string): number; + /** + * Marks the most valuable attachments for deletion based on the number of successful rolls made. + * + * @param attachments The array of attachment items. + * @param successfulRolls The number of successful rolls. + * @param toDelete The array that accumulates the IDs of the items to be deleted. + */ + protected attachmentDeletionByValue(attachments: EnrichedItem[], successfulRolls: number, toDelete: Set): void; /** * Remove items from the insured items that should not be returned to the player. * @@ -144,6 +168,22 @@ export declare class InsuranceController { * @returns void */ protected removeItemsFromInsurance(insured: Insurance, toDelete: Set): void; + /** + * Adopts orphaned items by resetting them as base-level items. Helpful in situations where a parent has been + * deleted from insurance, but any insured items within the parent should remain. This method will remove the + * reference from the children to the parent and set item properties to main-level values. + * + * @param insured Insurance object containing items. + */ + protected adoptOrphanedItems(insured: Insurance): void; + /** + * Fetches the parentId property of an item with a slotId "hideout". Not sure if this is actually dynamic, but this + * method should be a reliable way to fetch it, if it ever does change. + * + * @param items Array of items to search through. + * @returns The parentId of an item with slotId 'hideout'. Empty string if not found. + */ + protected fetchHideoutItemParent(items: Item[]): string; /** * Handle sending the insurance message to the user that potentially contains the valid insurance items. * @@ -154,15 +194,14 @@ export declare class InsuranceController { */ protected sendMail(sessionID: string, insurance: Insurance, noItems: boolean): void; /** - * Determines whether a valid insured item should be removed from the player's inventory based on a random roll and + * Determines whether a insured item should be removed from the player's inventory based on a random roll and * trader-specific return chance. * - * @param insuredItem The insured item being evaluated for removal. * @param traderId The ID of the trader who insured the item. - * @param itemsBeingDeleted List of items that are already slated for removal. + * @param insuredItem Optional. The item to roll for. Only used for logging. * @returns true if the insured item should be removed from inventory, false otherwise. */ - protected rollForItemDelete(insuredItem: Item, traderId: string, itemsBeingDeleted: Set): boolean; + protected rollForDelete(traderId: string, insuredItem?: Item): boolean; /** * Handle Insure event * Add insurance to an item @@ -183,3 +222,8 @@ export declare class InsuranceController { */ cost(request: IGetInsuranceCostRequestData, sessionID: string): IGetInsuranceCostResponseData; } +interface EnrichedItem extends Item { + name: string; + maxPrice: number; +} +export {}; diff --git a/TypeScript/3GetSptConfigFile/types/di/Serializer.d.ts b/TypeScript/3GetSptConfigFile/types/di/Serializer.d.ts index 2617007..b760b8b 100644 --- a/TypeScript/3GetSptConfigFile/types/di/Serializer.d.ts +++ b/TypeScript/3GetSptConfigFile/types/di/Serializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export declare class Serializer { serialize(sessionID: string, req: IncomingMessage, resp: ServerResponse, body: any): void; canHandle(something: string): boolean; diff --git a/TypeScript/3GetSptConfigFile/types/helpers/ItemHelper.d.ts b/TypeScript/3GetSptConfigFile/types/helpers/ItemHelper.d.ts index 6f1511c..5920d8a 100644 --- a/TypeScript/3GetSptConfigFile/types/helpers/ItemHelper.d.ts +++ b/TypeScript/3GetSptConfigFile/types/helpers/ItemHelper.d.ts @@ -225,6 +225,48 @@ declare class ItemHelper { * @returns true if item is flagged as quest item */ isQuestItem(tpl: string): boolean; + /** + * Checks to see if the item is *actually* moddable in-raid. Checks include the items existence in the database, the + * parent items existence in the database, the existence (and value) of the items RaidModdable property, and that + * the parents slot-required property exists, matches that of the item, and it's value. + * + * Note: this function does not preform any checks to see if the item and parent are *actually* related. + * + * @param item The item to be checked + * @param parent The parent of the item to be checked + * @returns True if the item is actually moddable, false if it is not, and null if the check cannot be performed. + */ + isRaidModdable(item: Item, parent: Item): boolean | null; + /** + * Retrieves the main parent item for a given attachment item. + * + * This method traverses up the hierarchy of items starting from a given `itemId`, until it finds the main parent + * item that is not an attached attachment itself. In other words, if you pass it an item id of a suppressor, it + * will traverse up the muzzle brake, barrel, upper receiver, and return the gun that the suppressor is ultimately + * attached to, even if that gun is located within multiple containers. + * + * It's important to note that traversal is expensive, so this method requires that you pass it a Map of the items + * to traverse, where the keys are the item IDs and the values are the corresponding Item objects. This alleviates + * some of the performance concerns, as it allows for quick lookups of items by ID. + * + * To generate the map: + * ``` + * const itemsMap = new Map(); + * items.forEach(item => itemsMap.set(item._id, item)); + * ``` + * + * @param itemId - The unique identifier of the item for which to find the main parent. + * @param itemsMap - A Map containing item IDs mapped to their corresponding Item objects for quick lookup. + * @returns The Item object representing the top-most parent of the given item, or `null` if no such parent exists. + */ + getAttachmentMainParent(itemId: string, itemsMap: Map): Item | null; + /** + * Determines if an item is an attachment that is currently attached to it's parent item. + * + * @param item The item to check. + * @returns true if the item is attached attachment, otherwise false. + */ + isAttachmentAttached(item: Item): boolean; /** * Get the inventory size of an item * @param items Item with children diff --git a/TypeScript/3GetSptConfigFile/types/loaders/PreAkiModLoader.d.ts b/TypeScript/3GetSptConfigFile/types/loaders/PreAkiModLoader.d.ts index 1e24b96..c0868b7 100644 --- a/TypeScript/3GetSptConfigFile/types/loaders/PreAkiModLoader.d.ts +++ b/TypeScript/3GetSptConfigFile/types/loaders/PreAkiModLoader.d.ts @@ -66,6 +66,10 @@ export declare class PreAkiModLoader implements IModLoader { protected isModCombatibleWithAki(mod: IPackageJsonData): boolean; protected executeMods(container: DependencyContainer): Promise; sortModsLoadOrder(): string[]; + /** + * Compile mod and add into class property "imported" + * @param mod Name of mod to compile/add + */ protected addMod(mod: string): Promise; protected autoInstallDependencies(modPath: string, pkg: IPackageJsonData): void; protected areModDependenciesFulfilled(pkg: IPackageJsonData, loadedMods: Record): boolean; diff --git a/TypeScript/3GetSptConfigFile/types/models/external/HttpFramework.d.ts b/TypeScript/3GetSptConfigFile/types/models/external/HttpFramework.d.ts index 64a37d6..fda8732 100644 --- a/TypeScript/3GetSptConfigFile/types/models/external/HttpFramework.d.ts +++ b/TypeScript/3GetSptConfigFile/types/models/external/HttpFramework.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export type HandleFn = (_: string, req: IncomingMessage, resp: ServerResponse) => void; /** * Associates handlers, HTTP methods and a base url to a listener using a proxy diff --git a/TypeScript/3GetSptConfigFile/types/models/spt/mod/IPackageJsonData.d.ts b/TypeScript/3GetSptConfigFile/types/models/spt/mod/IPackageJsonData.d.ts index 06f7454..f58d7cc 100644 --- a/TypeScript/3GetSptConfigFile/types/models/spt/mod/IPackageJsonData.d.ts +++ b/TypeScript/3GetSptConfigFile/types/models/spt/mod/IPackageJsonData.d.ts @@ -6,6 +6,9 @@ export interface IPackageJsonData { author: string; version: string; akiVersion: string; + /** We deliberately purge this data */ + scripts: Record; + devDependencies: Record; licence: string; main: string; isBundleMod: boolean; diff --git a/TypeScript/3GetSptConfigFile/types/routers/HttpRouter.d.ts b/TypeScript/3GetSptConfigFile/types/routers/HttpRouter.d.ts index f75a47d..46f847a 100644 --- a/TypeScript/3GetSptConfigFile/types/routers/HttpRouter.d.ts +++ b/TypeScript/3GetSptConfigFile/types/routers/HttpRouter.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage } from "http"; +import { IncomingMessage } from "node:http"; import { DynamicRouter, Router, StaticRouter } from "../di/Router"; export declare class HttpRouter { protected staticRouters: StaticRouter[]; diff --git a/TypeScript/3GetSptConfigFile/types/routers/ImageRouter.d.ts b/TypeScript/3GetSptConfigFile/types/routers/ImageRouter.d.ts index 675441c..fd03c59 100644 --- a/TypeScript/3GetSptConfigFile/types/routers/ImageRouter.d.ts +++ b/TypeScript/3GetSptConfigFile/types/routers/ImageRouter.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { ImageRouteService } from "../services/mod/image/ImageRouteService"; import { HttpFileUtil } from "../utils/HttpFileUtil"; import { VFS } from "../utils/VFS"; diff --git a/TypeScript/3GetSptConfigFile/types/routers/serializers/BundleSerializer.d.ts b/TypeScript/3GetSptConfigFile/types/routers/serializers/BundleSerializer.d.ts index ca4d8b6..db41142 100644 --- a/TypeScript/3GetSptConfigFile/types/routers/serializers/BundleSerializer.d.ts +++ b/TypeScript/3GetSptConfigFile/types/routers/serializers/BundleSerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { BundleLoader } from "../../loaders/BundleLoader"; import { ILogger } from "../../models/spt/utils/ILogger"; diff --git a/TypeScript/3GetSptConfigFile/types/routers/serializers/ImageSerializer.d.ts b/TypeScript/3GetSptConfigFile/types/routers/serializers/ImageSerializer.d.ts index 5de48ff..62ce84d 100644 --- a/TypeScript/3GetSptConfigFile/types/routers/serializers/ImageSerializer.d.ts +++ b/TypeScript/3GetSptConfigFile/types/routers/serializers/ImageSerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { ImageRouter } from "../ImageRouter"; export declare class ImageSerializer extends Serializer { diff --git a/TypeScript/3GetSptConfigFile/types/routers/serializers/NotifySerializer.d.ts b/TypeScript/3GetSptConfigFile/types/routers/serializers/NotifySerializer.d.ts index 1d179b2..e92d6e1 100644 --- a/TypeScript/3GetSptConfigFile/types/routers/serializers/NotifySerializer.d.ts +++ b/TypeScript/3GetSptConfigFile/types/routers/serializers/NotifySerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { NotifierController } from "../../controllers/NotifierController"; import { Serializer } from "../../di/Serializer"; import { HttpServerHelper } from "../../helpers/HttpServerHelper"; diff --git a/TypeScript/3GetSptConfigFile/types/servers/HttpServer.d.ts b/TypeScript/3GetSptConfigFile/types/servers/HttpServer.d.ts index 97e0705..c73eb3c 100644 --- a/TypeScript/3GetSptConfigFile/types/servers/HttpServer.d.ts +++ b/TypeScript/3GetSptConfigFile/types/servers/HttpServer.d.ts @@ -1,5 +1,5 @@ /// -import http, { IncomingMessage, ServerResponse } from "http"; +import http, { IncomingMessage, ServerResponse } from "node:http"; import { ApplicationContext } from "../context/ApplicationContext"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; import { IHttpConfig } from "../models/spt/config/IHttpConfig"; diff --git a/TypeScript/3GetSptConfigFile/types/servers/WebSocketServer.d.ts b/TypeScript/3GetSptConfigFile/types/servers/WebSocketServer.d.ts index fffbea2..b4c6158 100644 --- a/TypeScript/3GetSptConfigFile/types/servers/WebSocketServer.d.ts +++ b/TypeScript/3GetSptConfigFile/types/servers/WebSocketServer.d.ts @@ -1,5 +1,5 @@ /// -import http, { IncomingMessage } from "http"; +import http, { IncomingMessage } from "node:http"; import WebSocket from "ws"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; import { INotification } from "../models/eft/notifier/INotifier"; diff --git a/TypeScript/3GetSptConfigFile/types/servers/http/AkiHttpListener.d.ts b/TypeScript/3GetSptConfigFile/types/servers/http/AkiHttpListener.d.ts index c72e18f..e4ac80c 100644 --- a/TypeScript/3GetSptConfigFile/types/servers/http/AkiHttpListener.d.ts +++ b/TypeScript/3GetSptConfigFile/types/servers/http/AkiHttpListener.d.ts @@ -1,6 +1,6 @@ /// /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { ILogger } from "../../models/spt/utils/ILogger"; import { HttpRouter } from "../../routers/HttpRouter"; diff --git a/TypeScript/3GetSptConfigFile/types/servers/http/IHttpListener.d.ts b/TypeScript/3GetSptConfigFile/types/servers/http/IHttpListener.d.ts index 758bb5a..29d5fce 100644 --- a/TypeScript/3GetSptConfigFile/types/servers/http/IHttpListener.d.ts +++ b/TypeScript/3GetSptConfigFile/types/servers/http/IHttpListener.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export interface IHttpListener { canHandle(sessionId: string, req: IncomingMessage): boolean; handle(sessionId: string, req: IncomingMessage, resp: ServerResponse): void; diff --git a/TypeScript/3GetSptConfigFile/types/services/mod/httpListener/HttpListenerMod.d.ts b/TypeScript/3GetSptConfigFile/types/services/mod/httpListener/HttpListenerMod.d.ts index 2cdfbda..afe4574 100644 --- a/TypeScript/3GetSptConfigFile/types/services/mod/httpListener/HttpListenerMod.d.ts +++ b/TypeScript/3GetSptConfigFile/types/services/mod/httpListener/HttpListenerMod.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { IHttpListener } from "../../../servers/http/IHttpListener"; export declare class HttpListenerMod implements IHttpListener { private canHandleOverride; diff --git a/TypeScript/3GetSptConfigFile/types/services/mod/httpListener/HttpListenerModService.d.ts b/TypeScript/3GetSptConfigFile/types/services/mod/httpListener/HttpListenerModService.d.ts index 9dd3473..23abfbe 100644 --- a/TypeScript/3GetSptConfigFile/types/services/mod/httpListener/HttpListenerModService.d.ts +++ b/TypeScript/3GetSptConfigFile/types/services/mod/httpListener/HttpListenerModService.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { DependencyContainer } from "tsyringe"; export declare class HttpListenerModService { protected container: DependencyContainer; diff --git a/TypeScript/3GetSptConfigFile/types/utils/App.d.ts b/TypeScript/3GetSptConfigFile/types/utils/App.d.ts index dd8f24c..5e759ad 100644 --- a/TypeScript/3GetSptConfigFile/types/utils/App.d.ts +++ b/TypeScript/3GetSptConfigFile/types/utils/App.d.ts @@ -12,7 +12,6 @@ export declare class App { protected onLoadComponents: OnLoad[]; protected onUpdateComponents: OnUpdate[]; protected onUpdateLastRun: {}; - protected os: any; constructor(logger: ILogger, timeUtil: TimeUtil, localisationService: LocalisationService, encodingUtil: EncodingUtil, onLoadComponents: OnLoad[], onUpdateComponents: OnUpdate[]); load(): Promise; protected update(onUpdateComponents: OnUpdate[]): Promise; diff --git a/TypeScript/3GetSptConfigFile/types/utils/HashUtil.d.ts b/TypeScript/3GetSptConfigFile/types/utils/HashUtil.d.ts index c017ca8..27204cb 100644 --- a/TypeScript/3GetSptConfigFile/types/utils/HashUtil.d.ts +++ b/TypeScript/3GetSptConfigFile/types/utils/HashUtil.d.ts @@ -1,5 +1,5 @@ /// -import crypto from "crypto"; +import crypto from "node:crypto"; import { TimeUtil } from "./TimeUtil"; export declare class HashUtil { protected timeUtil: TimeUtil; diff --git a/TypeScript/3GetSptConfigFile/types/utils/HttpFileUtil.d.ts b/TypeScript/3GetSptConfigFile/types/utils/HttpFileUtil.d.ts index afc8409..6a386ce 100644 --- a/TypeScript/3GetSptConfigFile/types/utils/HttpFileUtil.d.ts +++ b/TypeScript/3GetSptConfigFile/types/utils/HttpFileUtil.d.ts @@ -1,5 +1,5 @@ /// -import { ServerResponse } from "http"; +import { ServerResponse } from "node:http"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; export declare class HttpFileUtil { protected httpServerHelper: HttpServerHelper; diff --git a/TypeScript/3GetSptConfigFile/types/utils/VFS.d.ts b/TypeScript/3GetSptConfigFile/types/utils/VFS.d.ts index 2cb09fa..3911c4b 100644 --- a/TypeScript/3GetSptConfigFile/types/utils/VFS.d.ts +++ b/TypeScript/3GetSptConfigFile/types/utils/VFS.d.ts @@ -1,6 +1,6 @@ /// /// -import fs from "fs"; +import fs from "node:fs"; import "reflect-metadata"; import { IAsyncQueue } from "../models/spt/utils/IAsyncQueue"; import { IUUidGenerator } from "../models/spt/utils/IUuidGenerator"; diff --git a/TypeScript/3GetSptConfigFile/types/utils/Watermark.d.ts b/TypeScript/3GetSptConfigFile/types/utils/Watermark.d.ts index fa63205..864e9b6 100644 --- a/TypeScript/3GetSptConfigFile/types/utils/Watermark.d.ts +++ b/TypeScript/3GetSptConfigFile/types/utils/Watermark.d.ts @@ -4,12 +4,10 @@ import { ConfigServer } from "../servers/ConfigServer"; import { LocalisationService } from "../services/LocalisationService"; export declare class WatermarkLocale { protected localisationService: LocalisationService; + protected description: string[]; + protected warning: string[]; + protected modding: string[]; constructor(localisationService: LocalisationService); - protected watermark: { - description: string[]; - warning: string[]; - modding: string[]; - }; getDescription(): string[]; getWarning(): string[]; getModding(): string[]; diff --git a/TypeScript/3GetSptConfigFile/types/utils/logging/AbstractWinstonLogger.d.ts b/TypeScript/3GetSptConfigFile/types/utils/logging/AbstractWinstonLogger.d.ts index 1ae1100..74767a2 100644 --- a/TypeScript/3GetSptConfigFile/types/utils/logging/AbstractWinstonLogger.d.ts +++ b/TypeScript/3GetSptConfigFile/types/utils/logging/AbstractWinstonLogger.d.ts @@ -1,5 +1,5 @@ /// -import fs from "fs"; +import fs from "node:fs"; import winston from "winston"; import { Daum } from "../../models/eft/itemEvent/IItemEventRouterRequest"; import { LogBackgroundColor } from "../../models/spt/logging/LogBackgroundColor"; diff --git a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/controllers/GameController.d.ts b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/controllers/GameController.d.ts index 73596ff..74123b2 100644 --- a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/controllers/GameController.d.ts +++ b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/controllers/GameController.d.ts @@ -49,7 +49,6 @@ export declare class GameController { protected giftService: GiftService; protected applicationContext: ApplicationContext; protected configServer: ConfigServer; - protected os: any; protected httpConfig: IHttpConfig; protected coreConfig: ICoreConfig; protected locationConfig: ILocationConfig; diff --git a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/controllers/InsuranceController.d.ts b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/controllers/InsuranceController.d.ts index fb41610..fc3229b 100644 --- a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/controllers/InsuranceController.d.ts +++ b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/controllers/InsuranceController.d.ts @@ -4,7 +4,6 @@ import { ProfileHelper } from "../helpers/ProfileHelper"; import { TraderHelper } from "../helpers/TraderHelper"; import { IPmcData } from "../models/eft/common/IPmcData"; import { Item } from "../models/eft/common/tables/IItem"; -import { ITemplateItem } from "../models/eft/common/tables/ITemplateItem"; import { IGetInsuranceCostRequestData } from "../models/eft/insurance/IGetInsuranceCostRequestData"; import { IGetInsuranceCostResponseData } from "../models/eft/insurance/IGetInsuranceCostResponseData"; import { IInsureRequestData } from "../models/eft/insurance/IInsureRequestData"; @@ -75,67 +74,92 @@ export declare class InsuranceController { */ protected removeInsurancePackageFromProfile(sessionID: string, packageInfo: ISystemData): void; /** - * Build an array of items to delete from the insured items. + * Finds the items that should be deleted based on the given Insurance object. * - * This method orchestrates several steps: - * - Filters items based on their presence in the database and their raid moddability. - * - Sorts base and independent child items to consider for deletion. - * - Groups child items by their parent for later evaluation. - * - Evaluates grouped child items to decide which should be deleted, based on their value and a random roll. - * - * @param insured - The insured items to build a removal array from. - * @returns An array of IDs representing items that should be deleted. + * @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(insured: Insurance): Set; /** - * Filters an item based on its existence in the database, raid moddability, and slot requirements. + * Populate a Map object of items for quick lookup by their ID. * - * @param item The item to be filtered. - * @param parentItemDbDetails The database details of the parent item, or null if the item has no parent. - * @param itemDbDetails A tuple where the first element is a boolean indicating if the item exists in the database, - * and the second element is the item details if it does. - * @returns true if the item exists in the database and neither of the following conditions are met: - * - The item has the RaidModdable property set to false. - * - The item is attached to a required slot in its parent item. - * Otherwise, returns false. + * @param insured The insurance object containing the items to populate the map with. + * @returns A Map where the keys are the item IDs and the values are the corresponding Item objects. */ - protected filterByRaidModdability(item: Item, parentItemDbDetails: ITemplateItem | null, itemDbDetails: [boolean, ITemplateItem]): boolean; + protected populateItemsMap(insured: Insurance): Map; /** - * Determines if an item is either a base item or a child item that is not equipped to its parent. + * 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 item The item to check. - * @returns true if the item is a base or an independent child item, otherwise false. + * @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. */ - protected isBaseOrIndependentChild(item: Item): boolean; + protected populateParentAttachmentsMap(insured: Insurance, itemsMap: Map): Map; /** - * Makes a roll to determine if a given item should be deleted. If the roll is successful, the item's ID is added - * to the `toDelete` array. + * 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. * - * @param item The item for which the roll is made. - * @param traderId The ID of the trader to consider in the rollForItemDelete method. - * @param toDelete The array accumulating the IDs of items to be deleted. - * @returns true if the item is marked for deletion, otherwise false. - */ - protected makeRollAndMarkForDeletion(item: Item, traderId: string, toDelete: Set): boolean; - /** - * Groups child items by their parent IDs in a Map data structure. - * - * @param item The child item to be grouped by its parent. - * @param childrenGroupedByParent The Map that holds arrays of children items grouped by their parent IDs. + * @param insured The insurance object containing the items to evaluate. + * @param toDelete A Set to keep track of items marked for deletion. * @returns void */ - protected groupChildrenByParent(item: Item, childrenGroupedByParent: Map): void; + protected processRegularItems(insured: Insurance, toDelete: Set): void; /** - * Sorts the array of children items in descending order by their maximum price. For each child, a roll is made to - * determine if it should be deleted. The method then deletes the most valuable children based on the number of - * successful rolls made. + * Process parent items and their attachments, updating the toDelete Set accordingly. * - * @param children The array of children items to sort and filter. - * @param traderId The ID of the trader to consider in the rollForItemDelete method. + * This method iterates over a map of parent items to their attachments and performs evaluations on each. + * It marks items for deletion based on certain conditions and updates the toDelete Set accordingly. + * + * @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. + */ + protected processAttachments(mainParentToAttachmentsMap: Map, itemsMap: Map, traderId: string, toDelete: Set): void; + /** + * 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. + * + * @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. * @returns void */ - protected sortAndFilterChildren(children: Item[], traderId: string, toDelete: Set): void; + protected processAttachmentByParent(attachments: Item[], traderId: string, toDelete: Set): void; + /** + * Sorts the attachment items by their max price in descending order. + * + * @param attachments The array of attachments items. + * @returns An array of items enriched with their max price and common locale-name. + */ + protected sortAttachmentsByPrice(attachments: Item[]): EnrichedItem[]; + /** + * Logs the details of each attachment item. + * + * @param attachments The array of attachment items. + */ + protected logAttachmentsDetails(attachments: EnrichedItem[]): void; + /** + * Counts the number of successful rolls for the attachment items. + * + * @param attachments The array of attachment items. + * @param traderId The ID of the trader that has insured these attachments. + * @returns The number of successful rolls. + */ + protected countSuccessfulRolls(attachments: Item[], traderId: string): number; + /** + * Marks the most valuable attachments for deletion based on the number of successful rolls made. + * + * @param attachments The array of attachment items. + * @param successfulRolls The number of successful rolls. + * @param toDelete The array that accumulates the IDs of the items to be deleted. + */ + protected attachmentDeletionByValue(attachments: EnrichedItem[], successfulRolls: number, toDelete: Set): void; /** * Remove items from the insured items that should not be returned to the player. * @@ -144,6 +168,22 @@ export declare class InsuranceController { * @returns void */ protected removeItemsFromInsurance(insured: Insurance, toDelete: Set): void; + /** + * Adopts orphaned items by resetting them as base-level items. Helpful in situations where a parent has been + * deleted from insurance, but any insured items within the parent should remain. This method will remove the + * reference from the children to the parent and set item properties to main-level values. + * + * @param insured Insurance object containing items. + */ + protected adoptOrphanedItems(insured: Insurance): void; + /** + * Fetches the parentId property of an item with a slotId "hideout". Not sure if this is actually dynamic, but this + * method should be a reliable way to fetch it, if it ever does change. + * + * @param items Array of items to search through. + * @returns The parentId of an item with slotId 'hideout'. Empty string if not found. + */ + protected fetchHideoutItemParent(items: Item[]): string; /** * Handle sending the insurance message to the user that potentially contains the valid insurance items. * @@ -154,15 +194,14 @@ export declare class InsuranceController { */ protected sendMail(sessionID: string, insurance: Insurance, noItems: boolean): void; /** - * Determines whether a valid insured item should be removed from the player's inventory based on a random roll and + * Determines whether a insured item should be removed from the player's inventory based on a random roll and * trader-specific return chance. * - * @param insuredItem The insured item being evaluated for removal. * @param traderId The ID of the trader who insured the item. - * @param itemsBeingDeleted List of items that are already slated for removal. + * @param insuredItem Optional. The item to roll for. Only used for logging. * @returns true if the insured item should be removed from inventory, false otherwise. */ - protected rollForItemDelete(insuredItem: Item, traderId: string, itemsBeingDeleted: Set): boolean; + protected rollForDelete(traderId: string, insuredItem?: Item): boolean; /** * Handle Insure event * Add insurance to an item @@ -183,3 +222,8 @@ export declare class InsuranceController { */ cost(request: IGetInsuranceCostRequestData, sessionID: string): IGetInsuranceCostResponseData; } +interface EnrichedItem extends Item { + name: string; + maxPrice: number; +} +export {}; diff --git a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/di/Serializer.d.ts b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/di/Serializer.d.ts index 2617007..b760b8b 100644 --- a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/di/Serializer.d.ts +++ b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/di/Serializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export declare class Serializer { serialize(sessionID: string, req: IncomingMessage, resp: ServerResponse, body: any): void; canHandle(something: string): boolean; diff --git a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/helpers/ItemHelper.d.ts b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/helpers/ItemHelper.d.ts index 6f1511c..5920d8a 100644 --- a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/helpers/ItemHelper.d.ts +++ b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/helpers/ItemHelper.d.ts @@ -225,6 +225,48 @@ declare class ItemHelper { * @returns true if item is flagged as quest item */ isQuestItem(tpl: string): boolean; + /** + * Checks to see if the item is *actually* moddable in-raid. Checks include the items existence in the database, the + * parent items existence in the database, the existence (and value) of the items RaidModdable property, and that + * the parents slot-required property exists, matches that of the item, and it's value. + * + * Note: this function does not preform any checks to see if the item and parent are *actually* related. + * + * @param item The item to be checked + * @param parent The parent of the item to be checked + * @returns True if the item is actually moddable, false if it is not, and null if the check cannot be performed. + */ + isRaidModdable(item: Item, parent: Item): boolean | null; + /** + * Retrieves the main parent item for a given attachment item. + * + * This method traverses up the hierarchy of items starting from a given `itemId`, until it finds the main parent + * item that is not an attached attachment itself. In other words, if you pass it an item id of a suppressor, it + * will traverse up the muzzle brake, barrel, upper receiver, and return the gun that the suppressor is ultimately + * attached to, even if that gun is located within multiple containers. + * + * It's important to note that traversal is expensive, so this method requires that you pass it a Map of the items + * to traverse, where the keys are the item IDs and the values are the corresponding Item objects. This alleviates + * some of the performance concerns, as it allows for quick lookups of items by ID. + * + * To generate the map: + * ``` + * const itemsMap = new Map(); + * items.forEach(item => itemsMap.set(item._id, item)); + * ``` + * + * @param itemId - The unique identifier of the item for which to find the main parent. + * @param itemsMap - A Map containing item IDs mapped to their corresponding Item objects for quick lookup. + * @returns The Item object representing the top-most parent of the given item, or `null` if no such parent exists. + */ + getAttachmentMainParent(itemId: string, itemsMap: Map): Item | null; + /** + * Determines if an item is an attachment that is currently attached to it's parent item. + * + * @param item The item to check. + * @returns true if the item is attached attachment, otherwise false. + */ + isAttachmentAttached(item: Item): boolean; /** * Get the inventory size of an item * @param items Item with children diff --git a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/loaders/PreAkiModLoader.d.ts b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/loaders/PreAkiModLoader.d.ts index 1e24b96..c0868b7 100644 --- a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/loaders/PreAkiModLoader.d.ts +++ b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/loaders/PreAkiModLoader.d.ts @@ -66,6 +66,10 @@ export declare class PreAkiModLoader implements IModLoader { protected isModCombatibleWithAki(mod: IPackageJsonData): boolean; protected executeMods(container: DependencyContainer): Promise; sortModsLoadOrder(): string[]; + /** + * Compile mod and add into class property "imported" + * @param mod Name of mod to compile/add + */ protected addMod(mod: string): Promise; protected autoInstallDependencies(modPath: string, pkg: IPackageJsonData): void; protected areModDependenciesFulfilled(pkg: IPackageJsonData, loadedMods: Record): boolean; diff --git a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/models/external/HttpFramework.d.ts b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/models/external/HttpFramework.d.ts index 64a37d6..fda8732 100644 --- a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/models/external/HttpFramework.d.ts +++ b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/models/external/HttpFramework.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export type HandleFn = (_: string, req: IncomingMessage, resp: ServerResponse) => void; /** * Associates handlers, HTTP methods and a base url to a listener using a proxy diff --git a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/models/spt/mod/IPackageJsonData.d.ts b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/models/spt/mod/IPackageJsonData.d.ts index 06f7454..f58d7cc 100644 --- a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/models/spt/mod/IPackageJsonData.d.ts +++ b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/models/spt/mod/IPackageJsonData.d.ts @@ -6,6 +6,9 @@ export interface IPackageJsonData { author: string; version: string; akiVersion: string; + /** We deliberately purge this data */ + scripts: Record; + devDependencies: Record; licence: string; main: string; isBundleMod: boolean; diff --git a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/routers/HttpRouter.d.ts b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/routers/HttpRouter.d.ts index f75a47d..46f847a 100644 --- a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/routers/HttpRouter.d.ts +++ b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/routers/HttpRouter.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage } from "http"; +import { IncomingMessage } from "node:http"; import { DynamicRouter, Router, StaticRouter } from "../di/Router"; export declare class HttpRouter { protected staticRouters: StaticRouter[]; diff --git a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/routers/ImageRouter.d.ts b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/routers/ImageRouter.d.ts index 675441c..fd03c59 100644 --- a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/routers/ImageRouter.d.ts +++ b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/routers/ImageRouter.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { ImageRouteService } from "../services/mod/image/ImageRouteService"; import { HttpFileUtil } from "../utils/HttpFileUtil"; import { VFS } from "../utils/VFS"; diff --git a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/routers/serializers/BundleSerializer.d.ts b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/routers/serializers/BundleSerializer.d.ts index ca4d8b6..db41142 100644 --- a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/routers/serializers/BundleSerializer.d.ts +++ b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/routers/serializers/BundleSerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { BundleLoader } from "../../loaders/BundleLoader"; import { ILogger } from "../../models/spt/utils/ILogger"; diff --git a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/routers/serializers/ImageSerializer.d.ts b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/routers/serializers/ImageSerializer.d.ts index 5de48ff..62ce84d 100644 --- a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/routers/serializers/ImageSerializer.d.ts +++ b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/routers/serializers/ImageSerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { ImageRouter } from "../ImageRouter"; export declare class ImageSerializer extends Serializer { diff --git a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/routers/serializers/NotifySerializer.d.ts b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/routers/serializers/NotifySerializer.d.ts index 1d179b2..e92d6e1 100644 --- a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/routers/serializers/NotifySerializer.d.ts +++ b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/routers/serializers/NotifySerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { NotifierController } from "../../controllers/NotifierController"; import { Serializer } from "../../di/Serializer"; import { HttpServerHelper } from "../../helpers/HttpServerHelper"; diff --git a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/servers/HttpServer.d.ts b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/servers/HttpServer.d.ts index 97e0705..c73eb3c 100644 --- a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/servers/HttpServer.d.ts +++ b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/servers/HttpServer.d.ts @@ -1,5 +1,5 @@ /// -import http, { IncomingMessage, ServerResponse } from "http"; +import http, { IncomingMessage, ServerResponse } from "node:http"; import { ApplicationContext } from "../context/ApplicationContext"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; import { IHttpConfig } from "../models/spt/config/IHttpConfig"; diff --git a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/servers/WebSocketServer.d.ts b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/servers/WebSocketServer.d.ts index fffbea2..b4c6158 100644 --- a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/servers/WebSocketServer.d.ts +++ b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/servers/WebSocketServer.d.ts @@ -1,5 +1,5 @@ /// -import http, { IncomingMessage } from "http"; +import http, { IncomingMessage } from "node:http"; import WebSocket from "ws"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; import { INotification } from "../models/eft/notifier/INotifier"; diff --git a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/servers/http/AkiHttpListener.d.ts b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/servers/http/AkiHttpListener.d.ts index c72e18f..e4ac80c 100644 --- a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/servers/http/AkiHttpListener.d.ts +++ b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/servers/http/AkiHttpListener.d.ts @@ -1,6 +1,6 @@ /// /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { ILogger } from "../../models/spt/utils/ILogger"; import { HttpRouter } from "../../routers/HttpRouter"; diff --git a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/servers/http/IHttpListener.d.ts b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/servers/http/IHttpListener.d.ts index 758bb5a..29d5fce 100644 --- a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/servers/http/IHttpListener.d.ts +++ b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/servers/http/IHttpListener.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export interface IHttpListener { canHandle(sessionId: string, req: IncomingMessage): boolean; handle(sessionId: string, req: IncomingMessage, resp: ServerResponse): void; diff --git a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/services/mod/httpListener/HttpListenerMod.d.ts b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/services/mod/httpListener/HttpListenerMod.d.ts index 2cdfbda..afe4574 100644 --- a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/services/mod/httpListener/HttpListenerMod.d.ts +++ b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/services/mod/httpListener/HttpListenerMod.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { IHttpListener } from "../../../servers/http/IHttpListener"; export declare class HttpListenerMod implements IHttpListener { private canHandleOverride; diff --git a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/services/mod/httpListener/HttpListenerModService.d.ts b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/services/mod/httpListener/HttpListenerModService.d.ts index 9dd3473..23abfbe 100644 --- a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/services/mod/httpListener/HttpListenerModService.d.ts +++ b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/services/mod/httpListener/HttpListenerModService.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { DependencyContainer } from "tsyringe"; export declare class HttpListenerModService { protected container: DependencyContainer; diff --git a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/utils/App.d.ts b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/utils/App.d.ts index dd8f24c..5e759ad 100644 --- a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/utils/App.d.ts +++ b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/utils/App.d.ts @@ -12,7 +12,6 @@ export declare class App { protected onLoadComponents: OnLoad[]; protected onUpdateComponents: OnUpdate[]; protected onUpdateLastRun: {}; - protected os: any; constructor(logger: ILogger, timeUtil: TimeUtil, localisationService: LocalisationService, encodingUtil: EncodingUtil, onLoadComponents: OnLoad[], onUpdateComponents: OnUpdate[]); load(): Promise; protected update(onUpdateComponents: OnUpdate[]): Promise; diff --git a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/utils/HashUtil.d.ts b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/utils/HashUtil.d.ts index c017ca8..27204cb 100644 --- a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/utils/HashUtil.d.ts +++ b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/utils/HashUtil.d.ts @@ -1,5 +1,5 @@ /// -import crypto from "crypto"; +import crypto from "node:crypto"; import { TimeUtil } from "./TimeUtil"; export declare class HashUtil { protected timeUtil: TimeUtil; diff --git a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/utils/HttpFileUtil.d.ts b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/utils/HttpFileUtil.d.ts index afc8409..6a386ce 100644 --- a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/utils/HttpFileUtil.d.ts +++ b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/utils/HttpFileUtil.d.ts @@ -1,5 +1,5 @@ /// -import { ServerResponse } from "http"; +import { ServerResponse } from "node:http"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; export declare class HttpFileUtil { protected httpServerHelper: HttpServerHelper; diff --git a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/utils/VFS.d.ts b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/utils/VFS.d.ts index 2cb09fa..3911c4b 100644 --- a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/utils/VFS.d.ts +++ b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/utils/VFS.d.ts @@ -1,6 +1,6 @@ /// /// -import fs from "fs"; +import fs from "node:fs"; import "reflect-metadata"; import { IAsyncQueue } from "../models/spt/utils/IAsyncQueue"; import { IUUidGenerator } from "../models/spt/utils/IUuidGenerator"; diff --git a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/utils/Watermark.d.ts b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/utils/Watermark.d.ts index fa63205..864e9b6 100644 --- a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/utils/Watermark.d.ts +++ b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/utils/Watermark.d.ts @@ -4,12 +4,10 @@ import { ConfigServer } from "../servers/ConfigServer"; import { LocalisationService } from "../services/LocalisationService"; export declare class WatermarkLocale { protected localisationService: LocalisationService; + protected description: string[]; + protected warning: string[]; + protected modding: string[]; constructor(localisationService: LocalisationService); - protected watermark: { - description: string[]; - warning: string[]; - modding: string[]; - }; getDescription(): string[]; getWarning(): string[]; getModding(): string[]; diff --git a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/utils/logging/AbstractWinstonLogger.d.ts b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/utils/logging/AbstractWinstonLogger.d.ts index 1ae1100..74767a2 100644 --- a/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/utils/logging/AbstractWinstonLogger.d.ts +++ b/TypeScript/4.1UseACustomJson5OrJsonCConfigFile/types/utils/logging/AbstractWinstonLogger.d.ts @@ -1,5 +1,5 @@ /// -import fs from "fs"; +import fs from "node:fs"; import winston from "winston"; import { Daum } from "../../models/eft/itemEvent/IItemEventRouterRequest"; import { LogBackgroundColor } from "../../models/spt/logging/LogBackgroundColor"; diff --git a/TypeScript/4UseACustomConfigFile/types/controllers/GameController.d.ts b/TypeScript/4UseACustomConfigFile/types/controllers/GameController.d.ts index 73596ff..74123b2 100644 --- a/TypeScript/4UseACustomConfigFile/types/controllers/GameController.d.ts +++ b/TypeScript/4UseACustomConfigFile/types/controllers/GameController.d.ts @@ -49,7 +49,6 @@ export declare class GameController { protected giftService: GiftService; protected applicationContext: ApplicationContext; protected configServer: ConfigServer; - protected os: any; protected httpConfig: IHttpConfig; protected coreConfig: ICoreConfig; protected locationConfig: ILocationConfig; diff --git a/TypeScript/4UseACustomConfigFile/types/controllers/InsuranceController.d.ts b/TypeScript/4UseACustomConfigFile/types/controllers/InsuranceController.d.ts index fb41610..fc3229b 100644 --- a/TypeScript/4UseACustomConfigFile/types/controllers/InsuranceController.d.ts +++ b/TypeScript/4UseACustomConfigFile/types/controllers/InsuranceController.d.ts @@ -4,7 +4,6 @@ import { ProfileHelper } from "../helpers/ProfileHelper"; import { TraderHelper } from "../helpers/TraderHelper"; import { IPmcData } from "../models/eft/common/IPmcData"; import { Item } from "../models/eft/common/tables/IItem"; -import { ITemplateItem } from "../models/eft/common/tables/ITemplateItem"; import { IGetInsuranceCostRequestData } from "../models/eft/insurance/IGetInsuranceCostRequestData"; import { IGetInsuranceCostResponseData } from "../models/eft/insurance/IGetInsuranceCostResponseData"; import { IInsureRequestData } from "../models/eft/insurance/IInsureRequestData"; @@ -75,67 +74,92 @@ export declare class InsuranceController { */ protected removeInsurancePackageFromProfile(sessionID: string, packageInfo: ISystemData): void; /** - * Build an array of items to delete from the insured items. + * Finds the items that should be deleted based on the given Insurance object. * - * This method orchestrates several steps: - * - Filters items based on their presence in the database and their raid moddability. - * - Sorts base and independent child items to consider for deletion. - * - Groups child items by their parent for later evaluation. - * - Evaluates grouped child items to decide which should be deleted, based on their value and a random roll. - * - * @param insured - The insured items to build a removal array from. - * @returns An array of IDs representing items that should be deleted. + * @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(insured: Insurance): Set; /** - * Filters an item based on its existence in the database, raid moddability, and slot requirements. + * Populate a Map object of items for quick lookup by their ID. * - * @param item The item to be filtered. - * @param parentItemDbDetails The database details of the parent item, or null if the item has no parent. - * @param itemDbDetails A tuple where the first element is a boolean indicating if the item exists in the database, - * and the second element is the item details if it does. - * @returns true if the item exists in the database and neither of the following conditions are met: - * - The item has the RaidModdable property set to false. - * - The item is attached to a required slot in its parent item. - * Otherwise, returns false. + * @param insured The insurance object containing the items to populate the map with. + * @returns A Map where the keys are the item IDs and the values are the corresponding Item objects. */ - protected filterByRaidModdability(item: Item, parentItemDbDetails: ITemplateItem | null, itemDbDetails: [boolean, ITemplateItem]): boolean; + protected populateItemsMap(insured: Insurance): Map; /** - * Determines if an item is either a base item or a child item that is not equipped to its parent. + * 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 item The item to check. - * @returns true if the item is a base or an independent child item, otherwise false. + * @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. */ - protected isBaseOrIndependentChild(item: Item): boolean; + protected populateParentAttachmentsMap(insured: Insurance, itemsMap: Map): Map; /** - * Makes a roll to determine if a given item should be deleted. If the roll is successful, the item's ID is added - * to the `toDelete` array. + * 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. * - * @param item The item for which the roll is made. - * @param traderId The ID of the trader to consider in the rollForItemDelete method. - * @param toDelete The array accumulating the IDs of items to be deleted. - * @returns true if the item is marked for deletion, otherwise false. - */ - protected makeRollAndMarkForDeletion(item: Item, traderId: string, toDelete: Set): boolean; - /** - * Groups child items by their parent IDs in a Map data structure. - * - * @param item The child item to be grouped by its parent. - * @param childrenGroupedByParent The Map that holds arrays of children items grouped by their parent IDs. + * @param insured The insurance object containing the items to evaluate. + * @param toDelete A Set to keep track of items marked for deletion. * @returns void */ - protected groupChildrenByParent(item: Item, childrenGroupedByParent: Map): void; + protected processRegularItems(insured: Insurance, toDelete: Set): void; /** - * Sorts the array of children items in descending order by their maximum price. For each child, a roll is made to - * determine if it should be deleted. The method then deletes the most valuable children based on the number of - * successful rolls made. + * Process parent items and their attachments, updating the toDelete Set accordingly. * - * @param children The array of children items to sort and filter. - * @param traderId The ID of the trader to consider in the rollForItemDelete method. + * This method iterates over a map of parent items to their attachments and performs evaluations on each. + * It marks items for deletion based on certain conditions and updates the toDelete Set accordingly. + * + * @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. + */ + protected processAttachments(mainParentToAttachmentsMap: Map, itemsMap: Map, traderId: string, toDelete: Set): void; + /** + * 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. + * + * @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. * @returns void */ - protected sortAndFilterChildren(children: Item[], traderId: string, toDelete: Set): void; + protected processAttachmentByParent(attachments: Item[], traderId: string, toDelete: Set): void; + /** + * Sorts the attachment items by their max price in descending order. + * + * @param attachments The array of attachments items. + * @returns An array of items enriched with their max price and common locale-name. + */ + protected sortAttachmentsByPrice(attachments: Item[]): EnrichedItem[]; + /** + * Logs the details of each attachment item. + * + * @param attachments The array of attachment items. + */ + protected logAttachmentsDetails(attachments: EnrichedItem[]): void; + /** + * Counts the number of successful rolls for the attachment items. + * + * @param attachments The array of attachment items. + * @param traderId The ID of the trader that has insured these attachments. + * @returns The number of successful rolls. + */ + protected countSuccessfulRolls(attachments: Item[], traderId: string): number; + /** + * Marks the most valuable attachments for deletion based on the number of successful rolls made. + * + * @param attachments The array of attachment items. + * @param successfulRolls The number of successful rolls. + * @param toDelete The array that accumulates the IDs of the items to be deleted. + */ + protected attachmentDeletionByValue(attachments: EnrichedItem[], successfulRolls: number, toDelete: Set): void; /** * Remove items from the insured items that should not be returned to the player. * @@ -144,6 +168,22 @@ export declare class InsuranceController { * @returns void */ protected removeItemsFromInsurance(insured: Insurance, toDelete: Set): void; + /** + * Adopts orphaned items by resetting them as base-level items. Helpful in situations where a parent has been + * deleted from insurance, but any insured items within the parent should remain. This method will remove the + * reference from the children to the parent and set item properties to main-level values. + * + * @param insured Insurance object containing items. + */ + protected adoptOrphanedItems(insured: Insurance): void; + /** + * Fetches the parentId property of an item with a slotId "hideout". Not sure if this is actually dynamic, but this + * method should be a reliable way to fetch it, if it ever does change. + * + * @param items Array of items to search through. + * @returns The parentId of an item with slotId 'hideout'. Empty string if not found. + */ + protected fetchHideoutItemParent(items: Item[]): string; /** * Handle sending the insurance message to the user that potentially contains the valid insurance items. * @@ -154,15 +194,14 @@ export declare class InsuranceController { */ protected sendMail(sessionID: string, insurance: Insurance, noItems: boolean): void; /** - * Determines whether a valid insured item should be removed from the player's inventory based on a random roll and + * Determines whether a insured item should be removed from the player's inventory based on a random roll and * trader-specific return chance. * - * @param insuredItem The insured item being evaluated for removal. * @param traderId The ID of the trader who insured the item. - * @param itemsBeingDeleted List of items that are already slated for removal. + * @param insuredItem Optional. The item to roll for. Only used for logging. * @returns true if the insured item should be removed from inventory, false otherwise. */ - protected rollForItemDelete(insuredItem: Item, traderId: string, itemsBeingDeleted: Set): boolean; + protected rollForDelete(traderId: string, insuredItem?: Item): boolean; /** * Handle Insure event * Add insurance to an item @@ -183,3 +222,8 @@ export declare class InsuranceController { */ cost(request: IGetInsuranceCostRequestData, sessionID: string): IGetInsuranceCostResponseData; } +interface EnrichedItem extends Item { + name: string; + maxPrice: number; +} +export {}; diff --git a/TypeScript/4UseACustomConfigFile/types/di/Serializer.d.ts b/TypeScript/4UseACustomConfigFile/types/di/Serializer.d.ts index 2617007..b760b8b 100644 --- a/TypeScript/4UseACustomConfigFile/types/di/Serializer.d.ts +++ b/TypeScript/4UseACustomConfigFile/types/di/Serializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export declare class Serializer { serialize(sessionID: string, req: IncomingMessage, resp: ServerResponse, body: any): void; canHandle(something: string): boolean; diff --git a/TypeScript/4UseACustomConfigFile/types/helpers/ItemHelper.d.ts b/TypeScript/4UseACustomConfigFile/types/helpers/ItemHelper.d.ts index 6f1511c..5920d8a 100644 --- a/TypeScript/4UseACustomConfigFile/types/helpers/ItemHelper.d.ts +++ b/TypeScript/4UseACustomConfigFile/types/helpers/ItemHelper.d.ts @@ -225,6 +225,48 @@ declare class ItemHelper { * @returns true if item is flagged as quest item */ isQuestItem(tpl: string): boolean; + /** + * Checks to see if the item is *actually* moddable in-raid. Checks include the items existence in the database, the + * parent items existence in the database, the existence (and value) of the items RaidModdable property, and that + * the parents slot-required property exists, matches that of the item, and it's value. + * + * Note: this function does not preform any checks to see if the item and parent are *actually* related. + * + * @param item The item to be checked + * @param parent The parent of the item to be checked + * @returns True if the item is actually moddable, false if it is not, and null if the check cannot be performed. + */ + isRaidModdable(item: Item, parent: Item): boolean | null; + /** + * Retrieves the main parent item for a given attachment item. + * + * This method traverses up the hierarchy of items starting from a given `itemId`, until it finds the main parent + * item that is not an attached attachment itself. In other words, if you pass it an item id of a suppressor, it + * will traverse up the muzzle brake, barrel, upper receiver, and return the gun that the suppressor is ultimately + * attached to, even if that gun is located within multiple containers. + * + * It's important to note that traversal is expensive, so this method requires that you pass it a Map of the items + * to traverse, where the keys are the item IDs and the values are the corresponding Item objects. This alleviates + * some of the performance concerns, as it allows for quick lookups of items by ID. + * + * To generate the map: + * ``` + * const itemsMap = new Map(); + * items.forEach(item => itemsMap.set(item._id, item)); + * ``` + * + * @param itemId - The unique identifier of the item for which to find the main parent. + * @param itemsMap - A Map containing item IDs mapped to their corresponding Item objects for quick lookup. + * @returns The Item object representing the top-most parent of the given item, or `null` if no such parent exists. + */ + getAttachmentMainParent(itemId: string, itemsMap: Map): Item | null; + /** + * Determines if an item is an attachment that is currently attached to it's parent item. + * + * @param item The item to check. + * @returns true if the item is attached attachment, otherwise false. + */ + isAttachmentAttached(item: Item): boolean; /** * Get the inventory size of an item * @param items Item with children diff --git a/TypeScript/4UseACustomConfigFile/types/loaders/PreAkiModLoader.d.ts b/TypeScript/4UseACustomConfigFile/types/loaders/PreAkiModLoader.d.ts index 1e24b96..c0868b7 100644 --- a/TypeScript/4UseACustomConfigFile/types/loaders/PreAkiModLoader.d.ts +++ b/TypeScript/4UseACustomConfigFile/types/loaders/PreAkiModLoader.d.ts @@ -66,6 +66,10 @@ export declare class PreAkiModLoader implements IModLoader { protected isModCombatibleWithAki(mod: IPackageJsonData): boolean; protected executeMods(container: DependencyContainer): Promise; sortModsLoadOrder(): string[]; + /** + * Compile mod and add into class property "imported" + * @param mod Name of mod to compile/add + */ protected addMod(mod: string): Promise; protected autoInstallDependencies(modPath: string, pkg: IPackageJsonData): void; protected areModDependenciesFulfilled(pkg: IPackageJsonData, loadedMods: Record): boolean; diff --git a/TypeScript/4UseACustomConfigFile/types/models/external/HttpFramework.d.ts b/TypeScript/4UseACustomConfigFile/types/models/external/HttpFramework.d.ts index 64a37d6..fda8732 100644 --- a/TypeScript/4UseACustomConfigFile/types/models/external/HttpFramework.d.ts +++ b/TypeScript/4UseACustomConfigFile/types/models/external/HttpFramework.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export type HandleFn = (_: string, req: IncomingMessage, resp: ServerResponse) => void; /** * Associates handlers, HTTP methods and a base url to a listener using a proxy diff --git a/TypeScript/4UseACustomConfigFile/types/models/spt/mod/IPackageJsonData.d.ts b/TypeScript/4UseACustomConfigFile/types/models/spt/mod/IPackageJsonData.d.ts index 06f7454..f58d7cc 100644 --- a/TypeScript/4UseACustomConfigFile/types/models/spt/mod/IPackageJsonData.d.ts +++ b/TypeScript/4UseACustomConfigFile/types/models/spt/mod/IPackageJsonData.d.ts @@ -6,6 +6,9 @@ export interface IPackageJsonData { author: string; version: string; akiVersion: string; + /** We deliberately purge this data */ + scripts: Record; + devDependencies: Record; licence: string; main: string; isBundleMod: boolean; diff --git a/TypeScript/4UseACustomConfigFile/types/routers/HttpRouter.d.ts b/TypeScript/4UseACustomConfigFile/types/routers/HttpRouter.d.ts index f75a47d..46f847a 100644 --- a/TypeScript/4UseACustomConfigFile/types/routers/HttpRouter.d.ts +++ b/TypeScript/4UseACustomConfigFile/types/routers/HttpRouter.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage } from "http"; +import { IncomingMessage } from "node:http"; import { DynamicRouter, Router, StaticRouter } from "../di/Router"; export declare class HttpRouter { protected staticRouters: StaticRouter[]; diff --git a/TypeScript/4UseACustomConfigFile/types/routers/ImageRouter.d.ts b/TypeScript/4UseACustomConfigFile/types/routers/ImageRouter.d.ts index 675441c..fd03c59 100644 --- a/TypeScript/4UseACustomConfigFile/types/routers/ImageRouter.d.ts +++ b/TypeScript/4UseACustomConfigFile/types/routers/ImageRouter.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { ImageRouteService } from "../services/mod/image/ImageRouteService"; import { HttpFileUtil } from "../utils/HttpFileUtil"; import { VFS } from "../utils/VFS"; diff --git a/TypeScript/4UseACustomConfigFile/types/routers/serializers/BundleSerializer.d.ts b/TypeScript/4UseACustomConfigFile/types/routers/serializers/BundleSerializer.d.ts index ca4d8b6..db41142 100644 --- a/TypeScript/4UseACustomConfigFile/types/routers/serializers/BundleSerializer.d.ts +++ b/TypeScript/4UseACustomConfigFile/types/routers/serializers/BundleSerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { BundleLoader } from "../../loaders/BundleLoader"; import { ILogger } from "../../models/spt/utils/ILogger"; diff --git a/TypeScript/4UseACustomConfigFile/types/routers/serializers/ImageSerializer.d.ts b/TypeScript/4UseACustomConfigFile/types/routers/serializers/ImageSerializer.d.ts index 5de48ff..62ce84d 100644 --- a/TypeScript/4UseACustomConfigFile/types/routers/serializers/ImageSerializer.d.ts +++ b/TypeScript/4UseACustomConfigFile/types/routers/serializers/ImageSerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { ImageRouter } from "../ImageRouter"; export declare class ImageSerializer extends Serializer { diff --git a/TypeScript/4UseACustomConfigFile/types/routers/serializers/NotifySerializer.d.ts b/TypeScript/4UseACustomConfigFile/types/routers/serializers/NotifySerializer.d.ts index 1d179b2..e92d6e1 100644 --- a/TypeScript/4UseACustomConfigFile/types/routers/serializers/NotifySerializer.d.ts +++ b/TypeScript/4UseACustomConfigFile/types/routers/serializers/NotifySerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { NotifierController } from "../../controllers/NotifierController"; import { Serializer } from "../../di/Serializer"; import { HttpServerHelper } from "../../helpers/HttpServerHelper"; diff --git a/TypeScript/4UseACustomConfigFile/types/servers/HttpServer.d.ts b/TypeScript/4UseACustomConfigFile/types/servers/HttpServer.d.ts index 97e0705..c73eb3c 100644 --- a/TypeScript/4UseACustomConfigFile/types/servers/HttpServer.d.ts +++ b/TypeScript/4UseACustomConfigFile/types/servers/HttpServer.d.ts @@ -1,5 +1,5 @@ /// -import http, { IncomingMessage, ServerResponse } from "http"; +import http, { IncomingMessage, ServerResponse } from "node:http"; import { ApplicationContext } from "../context/ApplicationContext"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; import { IHttpConfig } from "../models/spt/config/IHttpConfig"; diff --git a/TypeScript/4UseACustomConfigFile/types/servers/WebSocketServer.d.ts b/TypeScript/4UseACustomConfigFile/types/servers/WebSocketServer.d.ts index fffbea2..b4c6158 100644 --- a/TypeScript/4UseACustomConfigFile/types/servers/WebSocketServer.d.ts +++ b/TypeScript/4UseACustomConfigFile/types/servers/WebSocketServer.d.ts @@ -1,5 +1,5 @@ /// -import http, { IncomingMessage } from "http"; +import http, { IncomingMessage } from "node:http"; import WebSocket from "ws"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; import { INotification } from "../models/eft/notifier/INotifier"; diff --git a/TypeScript/4UseACustomConfigFile/types/servers/http/AkiHttpListener.d.ts b/TypeScript/4UseACustomConfigFile/types/servers/http/AkiHttpListener.d.ts index c72e18f..e4ac80c 100644 --- a/TypeScript/4UseACustomConfigFile/types/servers/http/AkiHttpListener.d.ts +++ b/TypeScript/4UseACustomConfigFile/types/servers/http/AkiHttpListener.d.ts @@ -1,6 +1,6 @@ /// /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { ILogger } from "../../models/spt/utils/ILogger"; import { HttpRouter } from "../../routers/HttpRouter"; diff --git a/TypeScript/4UseACustomConfigFile/types/servers/http/IHttpListener.d.ts b/TypeScript/4UseACustomConfigFile/types/servers/http/IHttpListener.d.ts index 758bb5a..29d5fce 100644 --- a/TypeScript/4UseACustomConfigFile/types/servers/http/IHttpListener.d.ts +++ b/TypeScript/4UseACustomConfigFile/types/servers/http/IHttpListener.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export interface IHttpListener { canHandle(sessionId: string, req: IncomingMessage): boolean; handle(sessionId: string, req: IncomingMessage, resp: ServerResponse): void; diff --git a/TypeScript/4UseACustomConfigFile/types/services/mod/httpListener/HttpListenerMod.d.ts b/TypeScript/4UseACustomConfigFile/types/services/mod/httpListener/HttpListenerMod.d.ts index 2cdfbda..afe4574 100644 --- a/TypeScript/4UseACustomConfigFile/types/services/mod/httpListener/HttpListenerMod.d.ts +++ b/TypeScript/4UseACustomConfigFile/types/services/mod/httpListener/HttpListenerMod.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { IHttpListener } from "../../../servers/http/IHttpListener"; export declare class HttpListenerMod implements IHttpListener { private canHandleOverride; diff --git a/TypeScript/4UseACustomConfigFile/types/services/mod/httpListener/HttpListenerModService.d.ts b/TypeScript/4UseACustomConfigFile/types/services/mod/httpListener/HttpListenerModService.d.ts index 9dd3473..23abfbe 100644 --- a/TypeScript/4UseACustomConfigFile/types/services/mod/httpListener/HttpListenerModService.d.ts +++ b/TypeScript/4UseACustomConfigFile/types/services/mod/httpListener/HttpListenerModService.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { DependencyContainer } from "tsyringe"; export declare class HttpListenerModService { protected container: DependencyContainer; diff --git a/TypeScript/4UseACustomConfigFile/types/utils/App.d.ts b/TypeScript/4UseACustomConfigFile/types/utils/App.d.ts index dd8f24c..5e759ad 100644 --- a/TypeScript/4UseACustomConfigFile/types/utils/App.d.ts +++ b/TypeScript/4UseACustomConfigFile/types/utils/App.d.ts @@ -12,7 +12,6 @@ export declare class App { protected onLoadComponents: OnLoad[]; protected onUpdateComponents: OnUpdate[]; protected onUpdateLastRun: {}; - protected os: any; constructor(logger: ILogger, timeUtil: TimeUtil, localisationService: LocalisationService, encodingUtil: EncodingUtil, onLoadComponents: OnLoad[], onUpdateComponents: OnUpdate[]); load(): Promise; protected update(onUpdateComponents: OnUpdate[]): Promise; diff --git a/TypeScript/4UseACustomConfigFile/types/utils/HashUtil.d.ts b/TypeScript/4UseACustomConfigFile/types/utils/HashUtil.d.ts index c017ca8..27204cb 100644 --- a/TypeScript/4UseACustomConfigFile/types/utils/HashUtil.d.ts +++ b/TypeScript/4UseACustomConfigFile/types/utils/HashUtil.d.ts @@ -1,5 +1,5 @@ /// -import crypto from "crypto"; +import crypto from "node:crypto"; import { TimeUtil } from "./TimeUtil"; export declare class HashUtil { protected timeUtil: TimeUtil; diff --git a/TypeScript/4UseACustomConfigFile/types/utils/HttpFileUtil.d.ts b/TypeScript/4UseACustomConfigFile/types/utils/HttpFileUtil.d.ts index afc8409..6a386ce 100644 --- a/TypeScript/4UseACustomConfigFile/types/utils/HttpFileUtil.d.ts +++ b/TypeScript/4UseACustomConfigFile/types/utils/HttpFileUtil.d.ts @@ -1,5 +1,5 @@ /// -import { ServerResponse } from "http"; +import { ServerResponse } from "node:http"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; export declare class HttpFileUtil { protected httpServerHelper: HttpServerHelper; diff --git a/TypeScript/4UseACustomConfigFile/types/utils/VFS.d.ts b/TypeScript/4UseACustomConfigFile/types/utils/VFS.d.ts index 2cb09fa..3911c4b 100644 --- a/TypeScript/4UseACustomConfigFile/types/utils/VFS.d.ts +++ b/TypeScript/4UseACustomConfigFile/types/utils/VFS.d.ts @@ -1,6 +1,6 @@ /// /// -import fs from "fs"; +import fs from "node:fs"; import "reflect-metadata"; import { IAsyncQueue } from "../models/spt/utils/IAsyncQueue"; import { IUUidGenerator } from "../models/spt/utils/IUuidGenerator"; diff --git a/TypeScript/4UseACustomConfigFile/types/utils/Watermark.d.ts b/TypeScript/4UseACustomConfigFile/types/utils/Watermark.d.ts index fa63205..864e9b6 100644 --- a/TypeScript/4UseACustomConfigFile/types/utils/Watermark.d.ts +++ b/TypeScript/4UseACustomConfigFile/types/utils/Watermark.d.ts @@ -4,12 +4,10 @@ import { ConfigServer } from "../servers/ConfigServer"; import { LocalisationService } from "../services/LocalisationService"; export declare class WatermarkLocale { protected localisationService: LocalisationService; + protected description: string[]; + protected warning: string[]; + protected modding: string[]; constructor(localisationService: LocalisationService); - protected watermark: { - description: string[]; - warning: string[]; - modding: string[]; - }; getDescription(): string[]; getWarning(): string[]; getModding(): string[]; diff --git a/TypeScript/4UseACustomConfigFile/types/utils/logging/AbstractWinstonLogger.d.ts b/TypeScript/4UseACustomConfigFile/types/utils/logging/AbstractWinstonLogger.d.ts index 1ae1100..74767a2 100644 --- a/TypeScript/4UseACustomConfigFile/types/utils/logging/AbstractWinstonLogger.d.ts +++ b/TypeScript/4UseACustomConfigFile/types/utils/logging/AbstractWinstonLogger.d.ts @@ -1,5 +1,5 @@ /// -import fs from "fs"; +import fs from "node:fs"; import winston from "winston"; import { Daum } from "../../models/eft/itemEvent/IItemEventRouterRequest"; import { LogBackgroundColor } from "../../models/spt/logging/LogBackgroundColor"; diff --git a/TypeScript/5ReplaceMethod/types/controllers/GameController.d.ts b/TypeScript/5ReplaceMethod/types/controllers/GameController.d.ts index 73596ff..74123b2 100644 --- a/TypeScript/5ReplaceMethod/types/controllers/GameController.d.ts +++ b/TypeScript/5ReplaceMethod/types/controllers/GameController.d.ts @@ -49,7 +49,6 @@ export declare class GameController { protected giftService: GiftService; protected applicationContext: ApplicationContext; protected configServer: ConfigServer; - protected os: any; protected httpConfig: IHttpConfig; protected coreConfig: ICoreConfig; protected locationConfig: ILocationConfig; diff --git a/TypeScript/5ReplaceMethod/types/controllers/InsuranceController.d.ts b/TypeScript/5ReplaceMethod/types/controllers/InsuranceController.d.ts index fb41610..fc3229b 100644 --- a/TypeScript/5ReplaceMethod/types/controllers/InsuranceController.d.ts +++ b/TypeScript/5ReplaceMethod/types/controllers/InsuranceController.d.ts @@ -4,7 +4,6 @@ import { ProfileHelper } from "../helpers/ProfileHelper"; import { TraderHelper } from "../helpers/TraderHelper"; import { IPmcData } from "../models/eft/common/IPmcData"; import { Item } from "../models/eft/common/tables/IItem"; -import { ITemplateItem } from "../models/eft/common/tables/ITemplateItem"; import { IGetInsuranceCostRequestData } from "../models/eft/insurance/IGetInsuranceCostRequestData"; import { IGetInsuranceCostResponseData } from "../models/eft/insurance/IGetInsuranceCostResponseData"; import { IInsureRequestData } from "../models/eft/insurance/IInsureRequestData"; @@ -75,67 +74,92 @@ export declare class InsuranceController { */ protected removeInsurancePackageFromProfile(sessionID: string, packageInfo: ISystemData): void; /** - * Build an array of items to delete from the insured items. + * Finds the items that should be deleted based on the given Insurance object. * - * This method orchestrates several steps: - * - Filters items based on their presence in the database and their raid moddability. - * - Sorts base and independent child items to consider for deletion. - * - Groups child items by their parent for later evaluation. - * - Evaluates grouped child items to decide which should be deleted, based on their value and a random roll. - * - * @param insured - The insured items to build a removal array from. - * @returns An array of IDs representing items that should be deleted. + * @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(insured: Insurance): Set; /** - * Filters an item based on its existence in the database, raid moddability, and slot requirements. + * Populate a Map object of items for quick lookup by their ID. * - * @param item The item to be filtered. - * @param parentItemDbDetails The database details of the parent item, or null if the item has no parent. - * @param itemDbDetails A tuple where the first element is a boolean indicating if the item exists in the database, - * and the second element is the item details if it does. - * @returns true if the item exists in the database and neither of the following conditions are met: - * - The item has the RaidModdable property set to false. - * - The item is attached to a required slot in its parent item. - * Otherwise, returns false. + * @param insured The insurance object containing the items to populate the map with. + * @returns A Map where the keys are the item IDs and the values are the corresponding Item objects. */ - protected filterByRaidModdability(item: Item, parentItemDbDetails: ITemplateItem | null, itemDbDetails: [boolean, ITemplateItem]): boolean; + protected populateItemsMap(insured: Insurance): Map; /** - * Determines if an item is either a base item or a child item that is not equipped to its parent. + * 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 item The item to check. - * @returns true if the item is a base or an independent child item, otherwise false. + * @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. */ - protected isBaseOrIndependentChild(item: Item): boolean; + protected populateParentAttachmentsMap(insured: Insurance, itemsMap: Map): Map; /** - * Makes a roll to determine if a given item should be deleted. If the roll is successful, the item's ID is added - * to the `toDelete` array. + * 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. * - * @param item The item for which the roll is made. - * @param traderId The ID of the trader to consider in the rollForItemDelete method. - * @param toDelete The array accumulating the IDs of items to be deleted. - * @returns true if the item is marked for deletion, otherwise false. - */ - protected makeRollAndMarkForDeletion(item: Item, traderId: string, toDelete: Set): boolean; - /** - * Groups child items by their parent IDs in a Map data structure. - * - * @param item The child item to be grouped by its parent. - * @param childrenGroupedByParent The Map that holds arrays of children items grouped by their parent IDs. + * @param insured The insurance object containing the items to evaluate. + * @param toDelete A Set to keep track of items marked for deletion. * @returns void */ - protected groupChildrenByParent(item: Item, childrenGroupedByParent: Map): void; + protected processRegularItems(insured: Insurance, toDelete: Set): void; /** - * Sorts the array of children items in descending order by their maximum price. For each child, a roll is made to - * determine if it should be deleted. The method then deletes the most valuable children based on the number of - * successful rolls made. + * Process parent items and their attachments, updating the toDelete Set accordingly. * - * @param children The array of children items to sort and filter. - * @param traderId The ID of the trader to consider in the rollForItemDelete method. + * This method iterates over a map of parent items to their attachments and performs evaluations on each. + * It marks items for deletion based on certain conditions and updates the toDelete Set accordingly. + * + * @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. + */ + protected processAttachments(mainParentToAttachmentsMap: Map, itemsMap: Map, traderId: string, toDelete: Set): void; + /** + * 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. + * + * @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. * @returns void */ - protected sortAndFilterChildren(children: Item[], traderId: string, toDelete: Set): void; + protected processAttachmentByParent(attachments: Item[], traderId: string, toDelete: Set): void; + /** + * Sorts the attachment items by their max price in descending order. + * + * @param attachments The array of attachments items. + * @returns An array of items enriched with their max price and common locale-name. + */ + protected sortAttachmentsByPrice(attachments: Item[]): EnrichedItem[]; + /** + * Logs the details of each attachment item. + * + * @param attachments The array of attachment items. + */ + protected logAttachmentsDetails(attachments: EnrichedItem[]): void; + /** + * Counts the number of successful rolls for the attachment items. + * + * @param attachments The array of attachment items. + * @param traderId The ID of the trader that has insured these attachments. + * @returns The number of successful rolls. + */ + protected countSuccessfulRolls(attachments: Item[], traderId: string): number; + /** + * Marks the most valuable attachments for deletion based on the number of successful rolls made. + * + * @param attachments The array of attachment items. + * @param successfulRolls The number of successful rolls. + * @param toDelete The array that accumulates the IDs of the items to be deleted. + */ + protected attachmentDeletionByValue(attachments: EnrichedItem[], successfulRolls: number, toDelete: Set): void; /** * Remove items from the insured items that should not be returned to the player. * @@ -144,6 +168,22 @@ export declare class InsuranceController { * @returns void */ protected removeItemsFromInsurance(insured: Insurance, toDelete: Set): void; + /** + * Adopts orphaned items by resetting them as base-level items. Helpful in situations where a parent has been + * deleted from insurance, but any insured items within the parent should remain. This method will remove the + * reference from the children to the parent and set item properties to main-level values. + * + * @param insured Insurance object containing items. + */ + protected adoptOrphanedItems(insured: Insurance): void; + /** + * Fetches the parentId property of an item with a slotId "hideout". Not sure if this is actually dynamic, but this + * method should be a reliable way to fetch it, if it ever does change. + * + * @param items Array of items to search through. + * @returns The parentId of an item with slotId 'hideout'. Empty string if not found. + */ + protected fetchHideoutItemParent(items: Item[]): string; /** * Handle sending the insurance message to the user that potentially contains the valid insurance items. * @@ -154,15 +194,14 @@ export declare class InsuranceController { */ protected sendMail(sessionID: string, insurance: Insurance, noItems: boolean): void; /** - * Determines whether a valid insured item should be removed from the player's inventory based on a random roll and + * Determines whether a insured item should be removed from the player's inventory based on a random roll and * trader-specific return chance. * - * @param insuredItem The insured item being evaluated for removal. * @param traderId The ID of the trader who insured the item. - * @param itemsBeingDeleted List of items that are already slated for removal. + * @param insuredItem Optional. The item to roll for. Only used for logging. * @returns true if the insured item should be removed from inventory, false otherwise. */ - protected rollForItemDelete(insuredItem: Item, traderId: string, itemsBeingDeleted: Set): boolean; + protected rollForDelete(traderId: string, insuredItem?: Item): boolean; /** * Handle Insure event * Add insurance to an item @@ -183,3 +222,8 @@ export declare class InsuranceController { */ cost(request: IGetInsuranceCostRequestData, sessionID: string): IGetInsuranceCostResponseData; } +interface EnrichedItem extends Item { + name: string; + maxPrice: number; +} +export {}; diff --git a/TypeScript/5ReplaceMethod/types/di/Serializer.d.ts b/TypeScript/5ReplaceMethod/types/di/Serializer.d.ts index 2617007..b760b8b 100644 --- a/TypeScript/5ReplaceMethod/types/di/Serializer.d.ts +++ b/TypeScript/5ReplaceMethod/types/di/Serializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export declare class Serializer { serialize(sessionID: string, req: IncomingMessage, resp: ServerResponse, body: any): void; canHandle(something: string): boolean; diff --git a/TypeScript/5ReplaceMethod/types/helpers/ItemHelper.d.ts b/TypeScript/5ReplaceMethod/types/helpers/ItemHelper.d.ts index 6f1511c..5920d8a 100644 --- a/TypeScript/5ReplaceMethod/types/helpers/ItemHelper.d.ts +++ b/TypeScript/5ReplaceMethod/types/helpers/ItemHelper.d.ts @@ -225,6 +225,48 @@ declare class ItemHelper { * @returns true if item is flagged as quest item */ isQuestItem(tpl: string): boolean; + /** + * Checks to see if the item is *actually* moddable in-raid. Checks include the items existence in the database, the + * parent items existence in the database, the existence (and value) of the items RaidModdable property, and that + * the parents slot-required property exists, matches that of the item, and it's value. + * + * Note: this function does not preform any checks to see if the item and parent are *actually* related. + * + * @param item The item to be checked + * @param parent The parent of the item to be checked + * @returns True if the item is actually moddable, false if it is not, and null if the check cannot be performed. + */ + isRaidModdable(item: Item, parent: Item): boolean | null; + /** + * Retrieves the main parent item for a given attachment item. + * + * This method traverses up the hierarchy of items starting from a given `itemId`, until it finds the main parent + * item that is not an attached attachment itself. In other words, if you pass it an item id of a suppressor, it + * will traverse up the muzzle brake, barrel, upper receiver, and return the gun that the suppressor is ultimately + * attached to, even if that gun is located within multiple containers. + * + * It's important to note that traversal is expensive, so this method requires that you pass it a Map of the items + * to traverse, where the keys are the item IDs and the values are the corresponding Item objects. This alleviates + * some of the performance concerns, as it allows for quick lookups of items by ID. + * + * To generate the map: + * ``` + * const itemsMap = new Map(); + * items.forEach(item => itemsMap.set(item._id, item)); + * ``` + * + * @param itemId - The unique identifier of the item for which to find the main parent. + * @param itemsMap - A Map containing item IDs mapped to their corresponding Item objects for quick lookup. + * @returns The Item object representing the top-most parent of the given item, or `null` if no such parent exists. + */ + getAttachmentMainParent(itemId: string, itemsMap: Map): Item | null; + /** + * Determines if an item is an attachment that is currently attached to it's parent item. + * + * @param item The item to check. + * @returns true if the item is attached attachment, otherwise false. + */ + isAttachmentAttached(item: Item): boolean; /** * Get the inventory size of an item * @param items Item with children diff --git a/TypeScript/5ReplaceMethod/types/loaders/PreAkiModLoader.d.ts b/TypeScript/5ReplaceMethod/types/loaders/PreAkiModLoader.d.ts index 1e24b96..c0868b7 100644 --- a/TypeScript/5ReplaceMethod/types/loaders/PreAkiModLoader.d.ts +++ b/TypeScript/5ReplaceMethod/types/loaders/PreAkiModLoader.d.ts @@ -66,6 +66,10 @@ export declare class PreAkiModLoader implements IModLoader { protected isModCombatibleWithAki(mod: IPackageJsonData): boolean; protected executeMods(container: DependencyContainer): Promise; sortModsLoadOrder(): string[]; + /** + * Compile mod and add into class property "imported" + * @param mod Name of mod to compile/add + */ protected addMod(mod: string): Promise; protected autoInstallDependencies(modPath: string, pkg: IPackageJsonData): void; protected areModDependenciesFulfilled(pkg: IPackageJsonData, loadedMods: Record): boolean; diff --git a/TypeScript/5ReplaceMethod/types/models/external/HttpFramework.d.ts b/TypeScript/5ReplaceMethod/types/models/external/HttpFramework.d.ts index 64a37d6..fda8732 100644 --- a/TypeScript/5ReplaceMethod/types/models/external/HttpFramework.d.ts +++ b/TypeScript/5ReplaceMethod/types/models/external/HttpFramework.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export type HandleFn = (_: string, req: IncomingMessage, resp: ServerResponse) => void; /** * Associates handlers, HTTP methods and a base url to a listener using a proxy diff --git a/TypeScript/5ReplaceMethod/types/models/spt/mod/IPackageJsonData.d.ts b/TypeScript/5ReplaceMethod/types/models/spt/mod/IPackageJsonData.d.ts index 06f7454..f58d7cc 100644 --- a/TypeScript/5ReplaceMethod/types/models/spt/mod/IPackageJsonData.d.ts +++ b/TypeScript/5ReplaceMethod/types/models/spt/mod/IPackageJsonData.d.ts @@ -6,6 +6,9 @@ export interface IPackageJsonData { author: string; version: string; akiVersion: string; + /** We deliberately purge this data */ + scripts: Record; + devDependencies: Record; licence: string; main: string; isBundleMod: boolean; diff --git a/TypeScript/5ReplaceMethod/types/routers/HttpRouter.d.ts b/TypeScript/5ReplaceMethod/types/routers/HttpRouter.d.ts index f75a47d..46f847a 100644 --- a/TypeScript/5ReplaceMethod/types/routers/HttpRouter.d.ts +++ b/TypeScript/5ReplaceMethod/types/routers/HttpRouter.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage } from "http"; +import { IncomingMessage } from "node:http"; import { DynamicRouter, Router, StaticRouter } from "../di/Router"; export declare class HttpRouter { protected staticRouters: StaticRouter[]; diff --git a/TypeScript/5ReplaceMethod/types/routers/ImageRouter.d.ts b/TypeScript/5ReplaceMethod/types/routers/ImageRouter.d.ts index 675441c..fd03c59 100644 --- a/TypeScript/5ReplaceMethod/types/routers/ImageRouter.d.ts +++ b/TypeScript/5ReplaceMethod/types/routers/ImageRouter.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { ImageRouteService } from "../services/mod/image/ImageRouteService"; import { HttpFileUtil } from "../utils/HttpFileUtil"; import { VFS } from "../utils/VFS"; diff --git a/TypeScript/5ReplaceMethod/types/routers/serializers/BundleSerializer.d.ts b/TypeScript/5ReplaceMethod/types/routers/serializers/BundleSerializer.d.ts index ca4d8b6..db41142 100644 --- a/TypeScript/5ReplaceMethod/types/routers/serializers/BundleSerializer.d.ts +++ b/TypeScript/5ReplaceMethod/types/routers/serializers/BundleSerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { BundleLoader } from "../../loaders/BundleLoader"; import { ILogger } from "../../models/spt/utils/ILogger"; diff --git a/TypeScript/5ReplaceMethod/types/routers/serializers/ImageSerializer.d.ts b/TypeScript/5ReplaceMethod/types/routers/serializers/ImageSerializer.d.ts index 5de48ff..62ce84d 100644 --- a/TypeScript/5ReplaceMethod/types/routers/serializers/ImageSerializer.d.ts +++ b/TypeScript/5ReplaceMethod/types/routers/serializers/ImageSerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { ImageRouter } from "../ImageRouter"; export declare class ImageSerializer extends Serializer { diff --git a/TypeScript/5ReplaceMethod/types/routers/serializers/NotifySerializer.d.ts b/TypeScript/5ReplaceMethod/types/routers/serializers/NotifySerializer.d.ts index 1d179b2..e92d6e1 100644 --- a/TypeScript/5ReplaceMethod/types/routers/serializers/NotifySerializer.d.ts +++ b/TypeScript/5ReplaceMethod/types/routers/serializers/NotifySerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { NotifierController } from "../../controllers/NotifierController"; import { Serializer } from "../../di/Serializer"; import { HttpServerHelper } from "../../helpers/HttpServerHelper"; diff --git a/TypeScript/5ReplaceMethod/types/servers/HttpServer.d.ts b/TypeScript/5ReplaceMethod/types/servers/HttpServer.d.ts index 97e0705..c73eb3c 100644 --- a/TypeScript/5ReplaceMethod/types/servers/HttpServer.d.ts +++ b/TypeScript/5ReplaceMethod/types/servers/HttpServer.d.ts @@ -1,5 +1,5 @@ /// -import http, { IncomingMessage, ServerResponse } from "http"; +import http, { IncomingMessage, ServerResponse } from "node:http"; import { ApplicationContext } from "../context/ApplicationContext"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; import { IHttpConfig } from "../models/spt/config/IHttpConfig"; diff --git a/TypeScript/5ReplaceMethod/types/servers/WebSocketServer.d.ts b/TypeScript/5ReplaceMethod/types/servers/WebSocketServer.d.ts index fffbea2..b4c6158 100644 --- a/TypeScript/5ReplaceMethod/types/servers/WebSocketServer.d.ts +++ b/TypeScript/5ReplaceMethod/types/servers/WebSocketServer.d.ts @@ -1,5 +1,5 @@ /// -import http, { IncomingMessage } from "http"; +import http, { IncomingMessage } from "node:http"; import WebSocket from "ws"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; import { INotification } from "../models/eft/notifier/INotifier"; diff --git a/TypeScript/5ReplaceMethod/types/servers/http/AkiHttpListener.d.ts b/TypeScript/5ReplaceMethod/types/servers/http/AkiHttpListener.d.ts index c72e18f..e4ac80c 100644 --- a/TypeScript/5ReplaceMethod/types/servers/http/AkiHttpListener.d.ts +++ b/TypeScript/5ReplaceMethod/types/servers/http/AkiHttpListener.d.ts @@ -1,6 +1,6 @@ /// /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { ILogger } from "../../models/spt/utils/ILogger"; import { HttpRouter } from "../../routers/HttpRouter"; diff --git a/TypeScript/5ReplaceMethod/types/servers/http/IHttpListener.d.ts b/TypeScript/5ReplaceMethod/types/servers/http/IHttpListener.d.ts index 758bb5a..29d5fce 100644 --- a/TypeScript/5ReplaceMethod/types/servers/http/IHttpListener.d.ts +++ b/TypeScript/5ReplaceMethod/types/servers/http/IHttpListener.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export interface IHttpListener { canHandle(sessionId: string, req: IncomingMessage): boolean; handle(sessionId: string, req: IncomingMessage, resp: ServerResponse): void; diff --git a/TypeScript/5ReplaceMethod/types/services/mod/httpListener/HttpListenerMod.d.ts b/TypeScript/5ReplaceMethod/types/services/mod/httpListener/HttpListenerMod.d.ts index 2cdfbda..afe4574 100644 --- a/TypeScript/5ReplaceMethod/types/services/mod/httpListener/HttpListenerMod.d.ts +++ b/TypeScript/5ReplaceMethod/types/services/mod/httpListener/HttpListenerMod.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { IHttpListener } from "../../../servers/http/IHttpListener"; export declare class HttpListenerMod implements IHttpListener { private canHandleOverride; diff --git a/TypeScript/5ReplaceMethod/types/services/mod/httpListener/HttpListenerModService.d.ts b/TypeScript/5ReplaceMethod/types/services/mod/httpListener/HttpListenerModService.d.ts index 9dd3473..23abfbe 100644 --- a/TypeScript/5ReplaceMethod/types/services/mod/httpListener/HttpListenerModService.d.ts +++ b/TypeScript/5ReplaceMethod/types/services/mod/httpListener/HttpListenerModService.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { DependencyContainer } from "tsyringe"; export declare class HttpListenerModService { protected container: DependencyContainer; diff --git a/TypeScript/5ReplaceMethod/types/utils/App.d.ts b/TypeScript/5ReplaceMethod/types/utils/App.d.ts index dd8f24c..5e759ad 100644 --- a/TypeScript/5ReplaceMethod/types/utils/App.d.ts +++ b/TypeScript/5ReplaceMethod/types/utils/App.d.ts @@ -12,7 +12,6 @@ export declare class App { protected onLoadComponents: OnLoad[]; protected onUpdateComponents: OnUpdate[]; protected onUpdateLastRun: {}; - protected os: any; constructor(logger: ILogger, timeUtil: TimeUtil, localisationService: LocalisationService, encodingUtil: EncodingUtil, onLoadComponents: OnLoad[], onUpdateComponents: OnUpdate[]); load(): Promise; protected update(onUpdateComponents: OnUpdate[]): Promise; diff --git a/TypeScript/5ReplaceMethod/types/utils/HashUtil.d.ts b/TypeScript/5ReplaceMethod/types/utils/HashUtil.d.ts index c017ca8..27204cb 100644 --- a/TypeScript/5ReplaceMethod/types/utils/HashUtil.d.ts +++ b/TypeScript/5ReplaceMethod/types/utils/HashUtil.d.ts @@ -1,5 +1,5 @@ /// -import crypto from "crypto"; +import crypto from "node:crypto"; import { TimeUtil } from "./TimeUtil"; export declare class HashUtil { protected timeUtil: TimeUtil; diff --git a/TypeScript/5ReplaceMethod/types/utils/HttpFileUtil.d.ts b/TypeScript/5ReplaceMethod/types/utils/HttpFileUtil.d.ts index afc8409..6a386ce 100644 --- a/TypeScript/5ReplaceMethod/types/utils/HttpFileUtil.d.ts +++ b/TypeScript/5ReplaceMethod/types/utils/HttpFileUtil.d.ts @@ -1,5 +1,5 @@ /// -import { ServerResponse } from "http"; +import { ServerResponse } from "node:http"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; export declare class HttpFileUtil { protected httpServerHelper: HttpServerHelper; diff --git a/TypeScript/5ReplaceMethod/types/utils/VFS.d.ts b/TypeScript/5ReplaceMethod/types/utils/VFS.d.ts index 2cb09fa..3911c4b 100644 --- a/TypeScript/5ReplaceMethod/types/utils/VFS.d.ts +++ b/TypeScript/5ReplaceMethod/types/utils/VFS.d.ts @@ -1,6 +1,6 @@ /// /// -import fs from "fs"; +import fs from "node:fs"; import "reflect-metadata"; import { IAsyncQueue } from "../models/spt/utils/IAsyncQueue"; import { IUUidGenerator } from "../models/spt/utils/IUuidGenerator"; diff --git a/TypeScript/5ReplaceMethod/types/utils/Watermark.d.ts b/TypeScript/5ReplaceMethod/types/utils/Watermark.d.ts index fa63205..864e9b6 100644 --- a/TypeScript/5ReplaceMethod/types/utils/Watermark.d.ts +++ b/TypeScript/5ReplaceMethod/types/utils/Watermark.d.ts @@ -4,12 +4,10 @@ import { ConfigServer } from "../servers/ConfigServer"; import { LocalisationService } from "../services/LocalisationService"; export declare class WatermarkLocale { protected localisationService: LocalisationService; + protected description: string[]; + protected warning: string[]; + protected modding: string[]; constructor(localisationService: LocalisationService); - protected watermark: { - description: string[]; - warning: string[]; - modding: string[]; - }; getDescription(): string[]; getWarning(): string[]; getModding(): string[]; diff --git a/TypeScript/5ReplaceMethod/types/utils/logging/AbstractWinstonLogger.d.ts b/TypeScript/5ReplaceMethod/types/utils/logging/AbstractWinstonLogger.d.ts index 1ae1100..74767a2 100644 --- a/TypeScript/5ReplaceMethod/types/utils/logging/AbstractWinstonLogger.d.ts +++ b/TypeScript/5ReplaceMethod/types/utils/logging/AbstractWinstonLogger.d.ts @@ -1,5 +1,5 @@ /// -import fs from "fs"; +import fs from "node:fs"; import winston from "winston"; import { Daum } from "../../models/eft/itemEvent/IItemEventRouterRequest"; import { LogBackgroundColor } from "../../models/spt/logging/LogBackgroundColor"; diff --git a/TypeScript/6ReferenceAnotherClass/types/controllers/GameController.d.ts b/TypeScript/6ReferenceAnotherClass/types/controllers/GameController.d.ts index 73596ff..74123b2 100644 --- a/TypeScript/6ReferenceAnotherClass/types/controllers/GameController.d.ts +++ b/TypeScript/6ReferenceAnotherClass/types/controllers/GameController.d.ts @@ -49,7 +49,6 @@ export declare class GameController { protected giftService: GiftService; protected applicationContext: ApplicationContext; protected configServer: ConfigServer; - protected os: any; protected httpConfig: IHttpConfig; protected coreConfig: ICoreConfig; protected locationConfig: ILocationConfig; diff --git a/TypeScript/6ReferenceAnotherClass/types/controllers/InsuranceController.d.ts b/TypeScript/6ReferenceAnotherClass/types/controllers/InsuranceController.d.ts index fb41610..fc3229b 100644 --- a/TypeScript/6ReferenceAnotherClass/types/controllers/InsuranceController.d.ts +++ b/TypeScript/6ReferenceAnotherClass/types/controllers/InsuranceController.d.ts @@ -4,7 +4,6 @@ import { ProfileHelper } from "../helpers/ProfileHelper"; import { TraderHelper } from "../helpers/TraderHelper"; import { IPmcData } from "../models/eft/common/IPmcData"; import { Item } from "../models/eft/common/tables/IItem"; -import { ITemplateItem } from "../models/eft/common/tables/ITemplateItem"; import { IGetInsuranceCostRequestData } from "../models/eft/insurance/IGetInsuranceCostRequestData"; import { IGetInsuranceCostResponseData } from "../models/eft/insurance/IGetInsuranceCostResponseData"; import { IInsureRequestData } from "../models/eft/insurance/IInsureRequestData"; @@ -75,67 +74,92 @@ export declare class InsuranceController { */ protected removeInsurancePackageFromProfile(sessionID: string, packageInfo: ISystemData): void; /** - * Build an array of items to delete from the insured items. + * Finds the items that should be deleted based on the given Insurance object. * - * This method orchestrates several steps: - * - Filters items based on their presence in the database and their raid moddability. - * - Sorts base and independent child items to consider for deletion. - * - Groups child items by their parent for later evaluation. - * - Evaluates grouped child items to decide which should be deleted, based on their value and a random roll. - * - * @param insured - The insured items to build a removal array from. - * @returns An array of IDs representing items that should be deleted. + * @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(insured: Insurance): Set; /** - * Filters an item based on its existence in the database, raid moddability, and slot requirements. + * Populate a Map object of items for quick lookup by their ID. * - * @param item The item to be filtered. - * @param parentItemDbDetails The database details of the parent item, or null if the item has no parent. - * @param itemDbDetails A tuple where the first element is a boolean indicating if the item exists in the database, - * and the second element is the item details if it does. - * @returns true if the item exists in the database and neither of the following conditions are met: - * - The item has the RaidModdable property set to false. - * - The item is attached to a required slot in its parent item. - * Otherwise, returns false. + * @param insured The insurance object containing the items to populate the map with. + * @returns A Map where the keys are the item IDs and the values are the corresponding Item objects. */ - protected filterByRaidModdability(item: Item, parentItemDbDetails: ITemplateItem | null, itemDbDetails: [boolean, ITemplateItem]): boolean; + protected populateItemsMap(insured: Insurance): Map; /** - * Determines if an item is either a base item or a child item that is not equipped to its parent. + * 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 item The item to check. - * @returns true if the item is a base or an independent child item, otherwise false. + * @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. */ - protected isBaseOrIndependentChild(item: Item): boolean; + protected populateParentAttachmentsMap(insured: Insurance, itemsMap: Map): Map; /** - * Makes a roll to determine if a given item should be deleted. If the roll is successful, the item's ID is added - * to the `toDelete` array. + * 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. * - * @param item The item for which the roll is made. - * @param traderId The ID of the trader to consider in the rollForItemDelete method. - * @param toDelete The array accumulating the IDs of items to be deleted. - * @returns true if the item is marked for deletion, otherwise false. - */ - protected makeRollAndMarkForDeletion(item: Item, traderId: string, toDelete: Set): boolean; - /** - * Groups child items by their parent IDs in a Map data structure. - * - * @param item The child item to be grouped by its parent. - * @param childrenGroupedByParent The Map that holds arrays of children items grouped by their parent IDs. + * @param insured The insurance object containing the items to evaluate. + * @param toDelete A Set to keep track of items marked for deletion. * @returns void */ - protected groupChildrenByParent(item: Item, childrenGroupedByParent: Map): void; + protected processRegularItems(insured: Insurance, toDelete: Set): void; /** - * Sorts the array of children items in descending order by their maximum price. For each child, a roll is made to - * determine if it should be deleted. The method then deletes the most valuable children based on the number of - * successful rolls made. + * Process parent items and their attachments, updating the toDelete Set accordingly. * - * @param children The array of children items to sort and filter. - * @param traderId The ID of the trader to consider in the rollForItemDelete method. + * This method iterates over a map of parent items to their attachments and performs evaluations on each. + * It marks items for deletion based on certain conditions and updates the toDelete Set accordingly. + * + * @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. + */ + protected processAttachments(mainParentToAttachmentsMap: Map, itemsMap: Map, traderId: string, toDelete: Set): void; + /** + * 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. + * + * @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. * @returns void */ - protected sortAndFilterChildren(children: Item[], traderId: string, toDelete: Set): void; + protected processAttachmentByParent(attachments: Item[], traderId: string, toDelete: Set): void; + /** + * Sorts the attachment items by their max price in descending order. + * + * @param attachments The array of attachments items. + * @returns An array of items enriched with their max price and common locale-name. + */ + protected sortAttachmentsByPrice(attachments: Item[]): EnrichedItem[]; + /** + * Logs the details of each attachment item. + * + * @param attachments The array of attachment items. + */ + protected logAttachmentsDetails(attachments: EnrichedItem[]): void; + /** + * Counts the number of successful rolls for the attachment items. + * + * @param attachments The array of attachment items. + * @param traderId The ID of the trader that has insured these attachments. + * @returns The number of successful rolls. + */ + protected countSuccessfulRolls(attachments: Item[], traderId: string): number; + /** + * Marks the most valuable attachments for deletion based on the number of successful rolls made. + * + * @param attachments The array of attachment items. + * @param successfulRolls The number of successful rolls. + * @param toDelete The array that accumulates the IDs of the items to be deleted. + */ + protected attachmentDeletionByValue(attachments: EnrichedItem[], successfulRolls: number, toDelete: Set): void; /** * Remove items from the insured items that should not be returned to the player. * @@ -144,6 +168,22 @@ export declare class InsuranceController { * @returns void */ protected removeItemsFromInsurance(insured: Insurance, toDelete: Set): void; + /** + * Adopts orphaned items by resetting them as base-level items. Helpful in situations where a parent has been + * deleted from insurance, but any insured items within the parent should remain. This method will remove the + * reference from the children to the parent and set item properties to main-level values. + * + * @param insured Insurance object containing items. + */ + protected adoptOrphanedItems(insured: Insurance): void; + /** + * Fetches the parentId property of an item with a slotId "hideout". Not sure if this is actually dynamic, but this + * method should be a reliable way to fetch it, if it ever does change. + * + * @param items Array of items to search through. + * @returns The parentId of an item with slotId 'hideout'. Empty string if not found. + */ + protected fetchHideoutItemParent(items: Item[]): string; /** * Handle sending the insurance message to the user that potentially contains the valid insurance items. * @@ -154,15 +194,14 @@ export declare class InsuranceController { */ protected sendMail(sessionID: string, insurance: Insurance, noItems: boolean): void; /** - * Determines whether a valid insured item should be removed from the player's inventory based on a random roll and + * Determines whether a insured item should be removed from the player's inventory based on a random roll and * trader-specific return chance. * - * @param insuredItem The insured item being evaluated for removal. * @param traderId The ID of the trader who insured the item. - * @param itemsBeingDeleted List of items that are already slated for removal. + * @param insuredItem Optional. The item to roll for. Only used for logging. * @returns true if the insured item should be removed from inventory, false otherwise. */ - protected rollForItemDelete(insuredItem: Item, traderId: string, itemsBeingDeleted: Set): boolean; + protected rollForDelete(traderId: string, insuredItem?: Item): boolean; /** * Handle Insure event * Add insurance to an item @@ -183,3 +222,8 @@ export declare class InsuranceController { */ cost(request: IGetInsuranceCostRequestData, sessionID: string): IGetInsuranceCostResponseData; } +interface EnrichedItem extends Item { + name: string; + maxPrice: number; +} +export {}; diff --git a/TypeScript/6ReferenceAnotherClass/types/di/Serializer.d.ts b/TypeScript/6ReferenceAnotherClass/types/di/Serializer.d.ts index 2617007..b760b8b 100644 --- a/TypeScript/6ReferenceAnotherClass/types/di/Serializer.d.ts +++ b/TypeScript/6ReferenceAnotherClass/types/di/Serializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export declare class Serializer { serialize(sessionID: string, req: IncomingMessage, resp: ServerResponse, body: any): void; canHandle(something: string): boolean; diff --git a/TypeScript/6ReferenceAnotherClass/types/helpers/ItemHelper.d.ts b/TypeScript/6ReferenceAnotherClass/types/helpers/ItemHelper.d.ts index 6f1511c..5920d8a 100644 --- a/TypeScript/6ReferenceAnotherClass/types/helpers/ItemHelper.d.ts +++ b/TypeScript/6ReferenceAnotherClass/types/helpers/ItemHelper.d.ts @@ -225,6 +225,48 @@ declare class ItemHelper { * @returns true if item is flagged as quest item */ isQuestItem(tpl: string): boolean; + /** + * Checks to see if the item is *actually* moddable in-raid. Checks include the items existence in the database, the + * parent items existence in the database, the existence (and value) of the items RaidModdable property, and that + * the parents slot-required property exists, matches that of the item, and it's value. + * + * Note: this function does not preform any checks to see if the item and parent are *actually* related. + * + * @param item The item to be checked + * @param parent The parent of the item to be checked + * @returns True if the item is actually moddable, false if it is not, and null if the check cannot be performed. + */ + isRaidModdable(item: Item, parent: Item): boolean | null; + /** + * Retrieves the main parent item for a given attachment item. + * + * This method traverses up the hierarchy of items starting from a given `itemId`, until it finds the main parent + * item that is not an attached attachment itself. In other words, if you pass it an item id of a suppressor, it + * will traverse up the muzzle brake, barrel, upper receiver, and return the gun that the suppressor is ultimately + * attached to, even if that gun is located within multiple containers. + * + * It's important to note that traversal is expensive, so this method requires that you pass it a Map of the items + * to traverse, where the keys are the item IDs and the values are the corresponding Item objects. This alleviates + * some of the performance concerns, as it allows for quick lookups of items by ID. + * + * To generate the map: + * ``` + * const itemsMap = new Map(); + * items.forEach(item => itemsMap.set(item._id, item)); + * ``` + * + * @param itemId - The unique identifier of the item for which to find the main parent. + * @param itemsMap - A Map containing item IDs mapped to their corresponding Item objects for quick lookup. + * @returns The Item object representing the top-most parent of the given item, or `null` if no such parent exists. + */ + getAttachmentMainParent(itemId: string, itemsMap: Map): Item | null; + /** + * Determines if an item is an attachment that is currently attached to it's parent item. + * + * @param item The item to check. + * @returns true if the item is attached attachment, otherwise false. + */ + isAttachmentAttached(item: Item): boolean; /** * Get the inventory size of an item * @param items Item with children diff --git a/TypeScript/6ReferenceAnotherClass/types/loaders/PreAkiModLoader.d.ts b/TypeScript/6ReferenceAnotherClass/types/loaders/PreAkiModLoader.d.ts index 1e24b96..c0868b7 100644 --- a/TypeScript/6ReferenceAnotherClass/types/loaders/PreAkiModLoader.d.ts +++ b/TypeScript/6ReferenceAnotherClass/types/loaders/PreAkiModLoader.d.ts @@ -66,6 +66,10 @@ export declare class PreAkiModLoader implements IModLoader { protected isModCombatibleWithAki(mod: IPackageJsonData): boolean; protected executeMods(container: DependencyContainer): Promise; sortModsLoadOrder(): string[]; + /** + * Compile mod and add into class property "imported" + * @param mod Name of mod to compile/add + */ protected addMod(mod: string): Promise; protected autoInstallDependencies(modPath: string, pkg: IPackageJsonData): void; protected areModDependenciesFulfilled(pkg: IPackageJsonData, loadedMods: Record): boolean; diff --git a/TypeScript/6ReferenceAnotherClass/types/models/external/HttpFramework.d.ts b/TypeScript/6ReferenceAnotherClass/types/models/external/HttpFramework.d.ts index 64a37d6..fda8732 100644 --- a/TypeScript/6ReferenceAnotherClass/types/models/external/HttpFramework.d.ts +++ b/TypeScript/6ReferenceAnotherClass/types/models/external/HttpFramework.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export type HandleFn = (_: string, req: IncomingMessage, resp: ServerResponse) => void; /** * Associates handlers, HTTP methods and a base url to a listener using a proxy diff --git a/TypeScript/6ReferenceAnotherClass/types/models/spt/mod/IPackageJsonData.d.ts b/TypeScript/6ReferenceAnotherClass/types/models/spt/mod/IPackageJsonData.d.ts index 06f7454..f58d7cc 100644 --- a/TypeScript/6ReferenceAnotherClass/types/models/spt/mod/IPackageJsonData.d.ts +++ b/TypeScript/6ReferenceAnotherClass/types/models/spt/mod/IPackageJsonData.d.ts @@ -6,6 +6,9 @@ export interface IPackageJsonData { author: string; version: string; akiVersion: string; + /** We deliberately purge this data */ + scripts: Record; + devDependencies: Record; licence: string; main: string; isBundleMod: boolean; diff --git a/TypeScript/6ReferenceAnotherClass/types/routers/HttpRouter.d.ts b/TypeScript/6ReferenceAnotherClass/types/routers/HttpRouter.d.ts index f75a47d..46f847a 100644 --- a/TypeScript/6ReferenceAnotherClass/types/routers/HttpRouter.d.ts +++ b/TypeScript/6ReferenceAnotherClass/types/routers/HttpRouter.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage } from "http"; +import { IncomingMessage } from "node:http"; import { DynamicRouter, Router, StaticRouter } from "../di/Router"; export declare class HttpRouter { protected staticRouters: StaticRouter[]; diff --git a/TypeScript/6ReferenceAnotherClass/types/routers/ImageRouter.d.ts b/TypeScript/6ReferenceAnotherClass/types/routers/ImageRouter.d.ts index 675441c..fd03c59 100644 --- a/TypeScript/6ReferenceAnotherClass/types/routers/ImageRouter.d.ts +++ b/TypeScript/6ReferenceAnotherClass/types/routers/ImageRouter.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { ImageRouteService } from "../services/mod/image/ImageRouteService"; import { HttpFileUtil } from "../utils/HttpFileUtil"; import { VFS } from "../utils/VFS"; diff --git a/TypeScript/6ReferenceAnotherClass/types/routers/serializers/BundleSerializer.d.ts b/TypeScript/6ReferenceAnotherClass/types/routers/serializers/BundleSerializer.d.ts index ca4d8b6..db41142 100644 --- a/TypeScript/6ReferenceAnotherClass/types/routers/serializers/BundleSerializer.d.ts +++ b/TypeScript/6ReferenceAnotherClass/types/routers/serializers/BundleSerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { BundleLoader } from "../../loaders/BundleLoader"; import { ILogger } from "../../models/spt/utils/ILogger"; diff --git a/TypeScript/6ReferenceAnotherClass/types/routers/serializers/ImageSerializer.d.ts b/TypeScript/6ReferenceAnotherClass/types/routers/serializers/ImageSerializer.d.ts index 5de48ff..62ce84d 100644 --- a/TypeScript/6ReferenceAnotherClass/types/routers/serializers/ImageSerializer.d.ts +++ b/TypeScript/6ReferenceAnotherClass/types/routers/serializers/ImageSerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { ImageRouter } from "../ImageRouter"; export declare class ImageSerializer extends Serializer { diff --git a/TypeScript/6ReferenceAnotherClass/types/routers/serializers/NotifySerializer.d.ts b/TypeScript/6ReferenceAnotherClass/types/routers/serializers/NotifySerializer.d.ts index 1d179b2..e92d6e1 100644 --- a/TypeScript/6ReferenceAnotherClass/types/routers/serializers/NotifySerializer.d.ts +++ b/TypeScript/6ReferenceAnotherClass/types/routers/serializers/NotifySerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { NotifierController } from "../../controllers/NotifierController"; import { Serializer } from "../../di/Serializer"; import { HttpServerHelper } from "../../helpers/HttpServerHelper"; diff --git a/TypeScript/6ReferenceAnotherClass/types/servers/HttpServer.d.ts b/TypeScript/6ReferenceAnotherClass/types/servers/HttpServer.d.ts index 97e0705..c73eb3c 100644 --- a/TypeScript/6ReferenceAnotherClass/types/servers/HttpServer.d.ts +++ b/TypeScript/6ReferenceAnotherClass/types/servers/HttpServer.d.ts @@ -1,5 +1,5 @@ /// -import http, { IncomingMessage, ServerResponse } from "http"; +import http, { IncomingMessage, ServerResponse } from "node:http"; import { ApplicationContext } from "../context/ApplicationContext"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; import { IHttpConfig } from "../models/spt/config/IHttpConfig"; diff --git a/TypeScript/6ReferenceAnotherClass/types/servers/WebSocketServer.d.ts b/TypeScript/6ReferenceAnotherClass/types/servers/WebSocketServer.d.ts index fffbea2..b4c6158 100644 --- a/TypeScript/6ReferenceAnotherClass/types/servers/WebSocketServer.d.ts +++ b/TypeScript/6ReferenceAnotherClass/types/servers/WebSocketServer.d.ts @@ -1,5 +1,5 @@ /// -import http, { IncomingMessage } from "http"; +import http, { IncomingMessage } from "node:http"; import WebSocket from "ws"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; import { INotification } from "../models/eft/notifier/INotifier"; diff --git a/TypeScript/6ReferenceAnotherClass/types/servers/http/AkiHttpListener.d.ts b/TypeScript/6ReferenceAnotherClass/types/servers/http/AkiHttpListener.d.ts index c72e18f..e4ac80c 100644 --- a/TypeScript/6ReferenceAnotherClass/types/servers/http/AkiHttpListener.d.ts +++ b/TypeScript/6ReferenceAnotherClass/types/servers/http/AkiHttpListener.d.ts @@ -1,6 +1,6 @@ /// /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { ILogger } from "../../models/spt/utils/ILogger"; import { HttpRouter } from "../../routers/HttpRouter"; diff --git a/TypeScript/6ReferenceAnotherClass/types/servers/http/IHttpListener.d.ts b/TypeScript/6ReferenceAnotherClass/types/servers/http/IHttpListener.d.ts index 758bb5a..29d5fce 100644 --- a/TypeScript/6ReferenceAnotherClass/types/servers/http/IHttpListener.d.ts +++ b/TypeScript/6ReferenceAnotherClass/types/servers/http/IHttpListener.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export interface IHttpListener { canHandle(sessionId: string, req: IncomingMessage): boolean; handle(sessionId: string, req: IncomingMessage, resp: ServerResponse): void; diff --git a/TypeScript/6ReferenceAnotherClass/types/services/mod/httpListener/HttpListenerMod.d.ts b/TypeScript/6ReferenceAnotherClass/types/services/mod/httpListener/HttpListenerMod.d.ts index 2cdfbda..afe4574 100644 --- a/TypeScript/6ReferenceAnotherClass/types/services/mod/httpListener/HttpListenerMod.d.ts +++ b/TypeScript/6ReferenceAnotherClass/types/services/mod/httpListener/HttpListenerMod.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { IHttpListener } from "../../../servers/http/IHttpListener"; export declare class HttpListenerMod implements IHttpListener { private canHandleOverride; diff --git a/TypeScript/6ReferenceAnotherClass/types/services/mod/httpListener/HttpListenerModService.d.ts b/TypeScript/6ReferenceAnotherClass/types/services/mod/httpListener/HttpListenerModService.d.ts index 9dd3473..23abfbe 100644 --- a/TypeScript/6ReferenceAnotherClass/types/services/mod/httpListener/HttpListenerModService.d.ts +++ b/TypeScript/6ReferenceAnotherClass/types/services/mod/httpListener/HttpListenerModService.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { DependencyContainer } from "tsyringe"; export declare class HttpListenerModService { protected container: DependencyContainer; diff --git a/TypeScript/6ReferenceAnotherClass/types/utils/App.d.ts b/TypeScript/6ReferenceAnotherClass/types/utils/App.d.ts index dd8f24c..5e759ad 100644 --- a/TypeScript/6ReferenceAnotherClass/types/utils/App.d.ts +++ b/TypeScript/6ReferenceAnotherClass/types/utils/App.d.ts @@ -12,7 +12,6 @@ export declare class App { protected onLoadComponents: OnLoad[]; protected onUpdateComponents: OnUpdate[]; protected onUpdateLastRun: {}; - protected os: any; constructor(logger: ILogger, timeUtil: TimeUtil, localisationService: LocalisationService, encodingUtil: EncodingUtil, onLoadComponents: OnLoad[], onUpdateComponents: OnUpdate[]); load(): Promise; protected update(onUpdateComponents: OnUpdate[]): Promise; diff --git a/TypeScript/6ReferenceAnotherClass/types/utils/HashUtil.d.ts b/TypeScript/6ReferenceAnotherClass/types/utils/HashUtil.d.ts index c017ca8..27204cb 100644 --- a/TypeScript/6ReferenceAnotherClass/types/utils/HashUtil.d.ts +++ b/TypeScript/6ReferenceAnotherClass/types/utils/HashUtil.d.ts @@ -1,5 +1,5 @@ /// -import crypto from "crypto"; +import crypto from "node:crypto"; import { TimeUtil } from "./TimeUtil"; export declare class HashUtil { protected timeUtil: TimeUtil; diff --git a/TypeScript/6ReferenceAnotherClass/types/utils/HttpFileUtil.d.ts b/TypeScript/6ReferenceAnotherClass/types/utils/HttpFileUtil.d.ts index afc8409..6a386ce 100644 --- a/TypeScript/6ReferenceAnotherClass/types/utils/HttpFileUtil.d.ts +++ b/TypeScript/6ReferenceAnotherClass/types/utils/HttpFileUtil.d.ts @@ -1,5 +1,5 @@ /// -import { ServerResponse } from "http"; +import { ServerResponse } from "node:http"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; export declare class HttpFileUtil { protected httpServerHelper: HttpServerHelper; diff --git a/TypeScript/6ReferenceAnotherClass/types/utils/VFS.d.ts b/TypeScript/6ReferenceAnotherClass/types/utils/VFS.d.ts index 2cb09fa..3911c4b 100644 --- a/TypeScript/6ReferenceAnotherClass/types/utils/VFS.d.ts +++ b/TypeScript/6ReferenceAnotherClass/types/utils/VFS.d.ts @@ -1,6 +1,6 @@ /// /// -import fs from "fs"; +import fs from "node:fs"; import "reflect-metadata"; import { IAsyncQueue } from "../models/spt/utils/IAsyncQueue"; import { IUUidGenerator } from "../models/spt/utils/IUuidGenerator"; diff --git a/TypeScript/6ReferenceAnotherClass/types/utils/Watermark.d.ts b/TypeScript/6ReferenceAnotherClass/types/utils/Watermark.d.ts index fa63205..864e9b6 100644 --- a/TypeScript/6ReferenceAnotherClass/types/utils/Watermark.d.ts +++ b/TypeScript/6ReferenceAnotherClass/types/utils/Watermark.d.ts @@ -4,12 +4,10 @@ import { ConfigServer } from "../servers/ConfigServer"; import { LocalisationService } from "../services/LocalisationService"; export declare class WatermarkLocale { protected localisationService: LocalisationService; + protected description: string[]; + protected warning: string[]; + protected modding: string[]; constructor(localisationService: LocalisationService); - protected watermark: { - description: string[]; - warning: string[]; - modding: string[]; - }; getDescription(): string[]; getWarning(): string[]; getModding(): string[]; diff --git a/TypeScript/6ReferenceAnotherClass/types/utils/logging/AbstractWinstonLogger.d.ts b/TypeScript/6ReferenceAnotherClass/types/utils/logging/AbstractWinstonLogger.d.ts index 1ae1100..74767a2 100644 --- a/TypeScript/6ReferenceAnotherClass/types/utils/logging/AbstractWinstonLogger.d.ts +++ b/TypeScript/6ReferenceAnotherClass/types/utils/logging/AbstractWinstonLogger.d.ts @@ -1,5 +1,5 @@ /// -import fs from "fs"; +import fs from "node:fs"; import winston from "winston"; import { Daum } from "../../models/eft/itemEvent/IItemEventRouterRequest"; import { LogBackgroundColor } from "../../models/spt/logging/LogBackgroundColor"; diff --git a/TypeScript/7OnLoadHook/types/controllers/GameController.d.ts b/TypeScript/7OnLoadHook/types/controllers/GameController.d.ts index 73596ff..74123b2 100644 --- a/TypeScript/7OnLoadHook/types/controllers/GameController.d.ts +++ b/TypeScript/7OnLoadHook/types/controllers/GameController.d.ts @@ -49,7 +49,6 @@ export declare class GameController { protected giftService: GiftService; protected applicationContext: ApplicationContext; protected configServer: ConfigServer; - protected os: any; protected httpConfig: IHttpConfig; protected coreConfig: ICoreConfig; protected locationConfig: ILocationConfig; diff --git a/TypeScript/7OnLoadHook/types/controllers/InsuranceController.d.ts b/TypeScript/7OnLoadHook/types/controllers/InsuranceController.d.ts index fb41610..fc3229b 100644 --- a/TypeScript/7OnLoadHook/types/controllers/InsuranceController.d.ts +++ b/TypeScript/7OnLoadHook/types/controllers/InsuranceController.d.ts @@ -4,7 +4,6 @@ import { ProfileHelper } from "../helpers/ProfileHelper"; import { TraderHelper } from "../helpers/TraderHelper"; import { IPmcData } from "../models/eft/common/IPmcData"; import { Item } from "../models/eft/common/tables/IItem"; -import { ITemplateItem } from "../models/eft/common/tables/ITemplateItem"; import { IGetInsuranceCostRequestData } from "../models/eft/insurance/IGetInsuranceCostRequestData"; import { IGetInsuranceCostResponseData } from "../models/eft/insurance/IGetInsuranceCostResponseData"; import { IInsureRequestData } from "../models/eft/insurance/IInsureRequestData"; @@ -75,67 +74,92 @@ export declare class InsuranceController { */ protected removeInsurancePackageFromProfile(sessionID: string, packageInfo: ISystemData): void; /** - * Build an array of items to delete from the insured items. + * Finds the items that should be deleted based on the given Insurance object. * - * This method orchestrates several steps: - * - Filters items based on their presence in the database and their raid moddability. - * - Sorts base and independent child items to consider for deletion. - * - Groups child items by their parent for later evaluation. - * - Evaluates grouped child items to decide which should be deleted, based on their value and a random roll. - * - * @param insured - The insured items to build a removal array from. - * @returns An array of IDs representing items that should be deleted. + * @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(insured: Insurance): Set; /** - * Filters an item based on its existence in the database, raid moddability, and slot requirements. + * Populate a Map object of items for quick lookup by their ID. * - * @param item The item to be filtered. - * @param parentItemDbDetails The database details of the parent item, or null if the item has no parent. - * @param itemDbDetails A tuple where the first element is a boolean indicating if the item exists in the database, - * and the second element is the item details if it does. - * @returns true if the item exists in the database and neither of the following conditions are met: - * - The item has the RaidModdable property set to false. - * - The item is attached to a required slot in its parent item. - * Otherwise, returns false. + * @param insured The insurance object containing the items to populate the map with. + * @returns A Map where the keys are the item IDs and the values are the corresponding Item objects. */ - protected filterByRaidModdability(item: Item, parentItemDbDetails: ITemplateItem | null, itemDbDetails: [boolean, ITemplateItem]): boolean; + protected populateItemsMap(insured: Insurance): Map; /** - * Determines if an item is either a base item or a child item that is not equipped to its parent. + * 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 item The item to check. - * @returns true if the item is a base or an independent child item, otherwise false. + * @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. */ - protected isBaseOrIndependentChild(item: Item): boolean; + protected populateParentAttachmentsMap(insured: Insurance, itemsMap: Map): Map; /** - * Makes a roll to determine if a given item should be deleted. If the roll is successful, the item's ID is added - * to the `toDelete` array. + * 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. * - * @param item The item for which the roll is made. - * @param traderId The ID of the trader to consider in the rollForItemDelete method. - * @param toDelete The array accumulating the IDs of items to be deleted. - * @returns true if the item is marked for deletion, otherwise false. - */ - protected makeRollAndMarkForDeletion(item: Item, traderId: string, toDelete: Set): boolean; - /** - * Groups child items by their parent IDs in a Map data structure. - * - * @param item The child item to be grouped by its parent. - * @param childrenGroupedByParent The Map that holds arrays of children items grouped by their parent IDs. + * @param insured The insurance object containing the items to evaluate. + * @param toDelete A Set to keep track of items marked for deletion. * @returns void */ - protected groupChildrenByParent(item: Item, childrenGroupedByParent: Map): void; + protected processRegularItems(insured: Insurance, toDelete: Set): void; /** - * Sorts the array of children items in descending order by their maximum price. For each child, a roll is made to - * determine if it should be deleted. The method then deletes the most valuable children based on the number of - * successful rolls made. + * Process parent items and their attachments, updating the toDelete Set accordingly. * - * @param children The array of children items to sort and filter. - * @param traderId The ID of the trader to consider in the rollForItemDelete method. + * This method iterates over a map of parent items to their attachments and performs evaluations on each. + * It marks items for deletion based on certain conditions and updates the toDelete Set accordingly. + * + * @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. + */ + protected processAttachments(mainParentToAttachmentsMap: Map, itemsMap: Map, traderId: string, toDelete: Set): void; + /** + * 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. + * + * @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. * @returns void */ - protected sortAndFilterChildren(children: Item[], traderId: string, toDelete: Set): void; + protected processAttachmentByParent(attachments: Item[], traderId: string, toDelete: Set): void; + /** + * Sorts the attachment items by their max price in descending order. + * + * @param attachments The array of attachments items. + * @returns An array of items enriched with their max price and common locale-name. + */ + protected sortAttachmentsByPrice(attachments: Item[]): EnrichedItem[]; + /** + * Logs the details of each attachment item. + * + * @param attachments The array of attachment items. + */ + protected logAttachmentsDetails(attachments: EnrichedItem[]): void; + /** + * Counts the number of successful rolls for the attachment items. + * + * @param attachments The array of attachment items. + * @param traderId The ID of the trader that has insured these attachments. + * @returns The number of successful rolls. + */ + protected countSuccessfulRolls(attachments: Item[], traderId: string): number; + /** + * Marks the most valuable attachments for deletion based on the number of successful rolls made. + * + * @param attachments The array of attachment items. + * @param successfulRolls The number of successful rolls. + * @param toDelete The array that accumulates the IDs of the items to be deleted. + */ + protected attachmentDeletionByValue(attachments: EnrichedItem[], successfulRolls: number, toDelete: Set): void; /** * Remove items from the insured items that should not be returned to the player. * @@ -144,6 +168,22 @@ export declare class InsuranceController { * @returns void */ protected removeItemsFromInsurance(insured: Insurance, toDelete: Set): void; + /** + * Adopts orphaned items by resetting them as base-level items. Helpful in situations where a parent has been + * deleted from insurance, but any insured items within the parent should remain. This method will remove the + * reference from the children to the parent and set item properties to main-level values. + * + * @param insured Insurance object containing items. + */ + protected adoptOrphanedItems(insured: Insurance): void; + /** + * Fetches the parentId property of an item with a slotId "hideout". Not sure if this is actually dynamic, but this + * method should be a reliable way to fetch it, if it ever does change. + * + * @param items Array of items to search through. + * @returns The parentId of an item with slotId 'hideout'. Empty string if not found. + */ + protected fetchHideoutItemParent(items: Item[]): string; /** * Handle sending the insurance message to the user that potentially contains the valid insurance items. * @@ -154,15 +194,14 @@ export declare class InsuranceController { */ protected sendMail(sessionID: string, insurance: Insurance, noItems: boolean): void; /** - * Determines whether a valid insured item should be removed from the player's inventory based on a random roll and + * Determines whether a insured item should be removed from the player's inventory based on a random roll and * trader-specific return chance. * - * @param insuredItem The insured item being evaluated for removal. * @param traderId The ID of the trader who insured the item. - * @param itemsBeingDeleted List of items that are already slated for removal. + * @param insuredItem Optional. The item to roll for. Only used for logging. * @returns true if the insured item should be removed from inventory, false otherwise. */ - protected rollForItemDelete(insuredItem: Item, traderId: string, itemsBeingDeleted: Set): boolean; + protected rollForDelete(traderId: string, insuredItem?: Item): boolean; /** * Handle Insure event * Add insurance to an item @@ -183,3 +222,8 @@ export declare class InsuranceController { */ cost(request: IGetInsuranceCostRequestData, sessionID: string): IGetInsuranceCostResponseData; } +interface EnrichedItem extends Item { + name: string; + maxPrice: number; +} +export {}; diff --git a/TypeScript/7OnLoadHook/types/di/Serializer.d.ts b/TypeScript/7OnLoadHook/types/di/Serializer.d.ts index 2617007..b760b8b 100644 --- a/TypeScript/7OnLoadHook/types/di/Serializer.d.ts +++ b/TypeScript/7OnLoadHook/types/di/Serializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export declare class Serializer { serialize(sessionID: string, req: IncomingMessage, resp: ServerResponse, body: any): void; canHandle(something: string): boolean; diff --git a/TypeScript/7OnLoadHook/types/helpers/ItemHelper.d.ts b/TypeScript/7OnLoadHook/types/helpers/ItemHelper.d.ts index 6f1511c..5920d8a 100644 --- a/TypeScript/7OnLoadHook/types/helpers/ItemHelper.d.ts +++ b/TypeScript/7OnLoadHook/types/helpers/ItemHelper.d.ts @@ -225,6 +225,48 @@ declare class ItemHelper { * @returns true if item is flagged as quest item */ isQuestItem(tpl: string): boolean; + /** + * Checks to see if the item is *actually* moddable in-raid. Checks include the items existence in the database, the + * parent items existence in the database, the existence (and value) of the items RaidModdable property, and that + * the parents slot-required property exists, matches that of the item, and it's value. + * + * Note: this function does not preform any checks to see if the item and parent are *actually* related. + * + * @param item The item to be checked + * @param parent The parent of the item to be checked + * @returns True if the item is actually moddable, false if it is not, and null if the check cannot be performed. + */ + isRaidModdable(item: Item, parent: Item): boolean | null; + /** + * Retrieves the main parent item for a given attachment item. + * + * This method traverses up the hierarchy of items starting from a given `itemId`, until it finds the main parent + * item that is not an attached attachment itself. In other words, if you pass it an item id of a suppressor, it + * will traverse up the muzzle brake, barrel, upper receiver, and return the gun that the suppressor is ultimately + * attached to, even if that gun is located within multiple containers. + * + * It's important to note that traversal is expensive, so this method requires that you pass it a Map of the items + * to traverse, where the keys are the item IDs and the values are the corresponding Item objects. This alleviates + * some of the performance concerns, as it allows for quick lookups of items by ID. + * + * To generate the map: + * ``` + * const itemsMap = new Map(); + * items.forEach(item => itemsMap.set(item._id, item)); + * ``` + * + * @param itemId - The unique identifier of the item for which to find the main parent. + * @param itemsMap - A Map containing item IDs mapped to their corresponding Item objects for quick lookup. + * @returns The Item object representing the top-most parent of the given item, or `null` if no such parent exists. + */ + getAttachmentMainParent(itemId: string, itemsMap: Map): Item | null; + /** + * Determines if an item is an attachment that is currently attached to it's parent item. + * + * @param item The item to check. + * @returns true if the item is attached attachment, otherwise false. + */ + isAttachmentAttached(item: Item): boolean; /** * Get the inventory size of an item * @param items Item with children diff --git a/TypeScript/7OnLoadHook/types/loaders/PreAkiModLoader.d.ts b/TypeScript/7OnLoadHook/types/loaders/PreAkiModLoader.d.ts index 1e24b96..c0868b7 100644 --- a/TypeScript/7OnLoadHook/types/loaders/PreAkiModLoader.d.ts +++ b/TypeScript/7OnLoadHook/types/loaders/PreAkiModLoader.d.ts @@ -66,6 +66,10 @@ export declare class PreAkiModLoader implements IModLoader { protected isModCombatibleWithAki(mod: IPackageJsonData): boolean; protected executeMods(container: DependencyContainer): Promise; sortModsLoadOrder(): string[]; + /** + * Compile mod and add into class property "imported" + * @param mod Name of mod to compile/add + */ protected addMod(mod: string): Promise; protected autoInstallDependencies(modPath: string, pkg: IPackageJsonData): void; protected areModDependenciesFulfilled(pkg: IPackageJsonData, loadedMods: Record): boolean; diff --git a/TypeScript/7OnLoadHook/types/models/external/HttpFramework.d.ts b/TypeScript/7OnLoadHook/types/models/external/HttpFramework.d.ts index 64a37d6..fda8732 100644 --- a/TypeScript/7OnLoadHook/types/models/external/HttpFramework.d.ts +++ b/TypeScript/7OnLoadHook/types/models/external/HttpFramework.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export type HandleFn = (_: string, req: IncomingMessage, resp: ServerResponse) => void; /** * Associates handlers, HTTP methods and a base url to a listener using a proxy diff --git a/TypeScript/7OnLoadHook/types/models/spt/mod/IPackageJsonData.d.ts b/TypeScript/7OnLoadHook/types/models/spt/mod/IPackageJsonData.d.ts index 06f7454..f58d7cc 100644 --- a/TypeScript/7OnLoadHook/types/models/spt/mod/IPackageJsonData.d.ts +++ b/TypeScript/7OnLoadHook/types/models/spt/mod/IPackageJsonData.d.ts @@ -6,6 +6,9 @@ export interface IPackageJsonData { author: string; version: string; akiVersion: string; + /** We deliberately purge this data */ + scripts: Record; + devDependencies: Record; licence: string; main: string; isBundleMod: boolean; diff --git a/TypeScript/7OnLoadHook/types/routers/HttpRouter.d.ts b/TypeScript/7OnLoadHook/types/routers/HttpRouter.d.ts index f75a47d..46f847a 100644 --- a/TypeScript/7OnLoadHook/types/routers/HttpRouter.d.ts +++ b/TypeScript/7OnLoadHook/types/routers/HttpRouter.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage } from "http"; +import { IncomingMessage } from "node:http"; import { DynamicRouter, Router, StaticRouter } from "../di/Router"; export declare class HttpRouter { protected staticRouters: StaticRouter[]; diff --git a/TypeScript/7OnLoadHook/types/routers/ImageRouter.d.ts b/TypeScript/7OnLoadHook/types/routers/ImageRouter.d.ts index 675441c..fd03c59 100644 --- a/TypeScript/7OnLoadHook/types/routers/ImageRouter.d.ts +++ b/TypeScript/7OnLoadHook/types/routers/ImageRouter.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { ImageRouteService } from "../services/mod/image/ImageRouteService"; import { HttpFileUtil } from "../utils/HttpFileUtil"; import { VFS } from "../utils/VFS"; diff --git a/TypeScript/7OnLoadHook/types/routers/serializers/BundleSerializer.d.ts b/TypeScript/7OnLoadHook/types/routers/serializers/BundleSerializer.d.ts index ca4d8b6..db41142 100644 --- a/TypeScript/7OnLoadHook/types/routers/serializers/BundleSerializer.d.ts +++ b/TypeScript/7OnLoadHook/types/routers/serializers/BundleSerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { BundleLoader } from "../../loaders/BundleLoader"; import { ILogger } from "../../models/spt/utils/ILogger"; diff --git a/TypeScript/7OnLoadHook/types/routers/serializers/ImageSerializer.d.ts b/TypeScript/7OnLoadHook/types/routers/serializers/ImageSerializer.d.ts index 5de48ff..62ce84d 100644 --- a/TypeScript/7OnLoadHook/types/routers/serializers/ImageSerializer.d.ts +++ b/TypeScript/7OnLoadHook/types/routers/serializers/ImageSerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { ImageRouter } from "../ImageRouter"; export declare class ImageSerializer extends Serializer { diff --git a/TypeScript/7OnLoadHook/types/routers/serializers/NotifySerializer.d.ts b/TypeScript/7OnLoadHook/types/routers/serializers/NotifySerializer.d.ts index 1d179b2..e92d6e1 100644 --- a/TypeScript/7OnLoadHook/types/routers/serializers/NotifySerializer.d.ts +++ b/TypeScript/7OnLoadHook/types/routers/serializers/NotifySerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { NotifierController } from "../../controllers/NotifierController"; import { Serializer } from "../../di/Serializer"; import { HttpServerHelper } from "../../helpers/HttpServerHelper"; diff --git a/TypeScript/7OnLoadHook/types/servers/HttpServer.d.ts b/TypeScript/7OnLoadHook/types/servers/HttpServer.d.ts index 97e0705..c73eb3c 100644 --- a/TypeScript/7OnLoadHook/types/servers/HttpServer.d.ts +++ b/TypeScript/7OnLoadHook/types/servers/HttpServer.d.ts @@ -1,5 +1,5 @@ /// -import http, { IncomingMessage, ServerResponse } from "http"; +import http, { IncomingMessage, ServerResponse } from "node:http"; import { ApplicationContext } from "../context/ApplicationContext"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; import { IHttpConfig } from "../models/spt/config/IHttpConfig"; diff --git a/TypeScript/7OnLoadHook/types/servers/WebSocketServer.d.ts b/TypeScript/7OnLoadHook/types/servers/WebSocketServer.d.ts index fffbea2..b4c6158 100644 --- a/TypeScript/7OnLoadHook/types/servers/WebSocketServer.d.ts +++ b/TypeScript/7OnLoadHook/types/servers/WebSocketServer.d.ts @@ -1,5 +1,5 @@ /// -import http, { IncomingMessage } from "http"; +import http, { IncomingMessage } from "node:http"; import WebSocket from "ws"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; import { INotification } from "../models/eft/notifier/INotifier"; diff --git a/TypeScript/7OnLoadHook/types/servers/http/AkiHttpListener.d.ts b/TypeScript/7OnLoadHook/types/servers/http/AkiHttpListener.d.ts index c72e18f..e4ac80c 100644 --- a/TypeScript/7OnLoadHook/types/servers/http/AkiHttpListener.d.ts +++ b/TypeScript/7OnLoadHook/types/servers/http/AkiHttpListener.d.ts @@ -1,6 +1,6 @@ /// /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { ILogger } from "../../models/spt/utils/ILogger"; import { HttpRouter } from "../../routers/HttpRouter"; diff --git a/TypeScript/7OnLoadHook/types/servers/http/IHttpListener.d.ts b/TypeScript/7OnLoadHook/types/servers/http/IHttpListener.d.ts index 758bb5a..29d5fce 100644 --- a/TypeScript/7OnLoadHook/types/servers/http/IHttpListener.d.ts +++ b/TypeScript/7OnLoadHook/types/servers/http/IHttpListener.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export interface IHttpListener { canHandle(sessionId: string, req: IncomingMessage): boolean; handle(sessionId: string, req: IncomingMessage, resp: ServerResponse): void; diff --git a/TypeScript/7OnLoadHook/types/services/mod/httpListener/HttpListenerMod.d.ts b/TypeScript/7OnLoadHook/types/services/mod/httpListener/HttpListenerMod.d.ts index 2cdfbda..afe4574 100644 --- a/TypeScript/7OnLoadHook/types/services/mod/httpListener/HttpListenerMod.d.ts +++ b/TypeScript/7OnLoadHook/types/services/mod/httpListener/HttpListenerMod.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { IHttpListener } from "../../../servers/http/IHttpListener"; export declare class HttpListenerMod implements IHttpListener { private canHandleOverride; diff --git a/TypeScript/7OnLoadHook/types/services/mod/httpListener/HttpListenerModService.d.ts b/TypeScript/7OnLoadHook/types/services/mod/httpListener/HttpListenerModService.d.ts index 9dd3473..23abfbe 100644 --- a/TypeScript/7OnLoadHook/types/services/mod/httpListener/HttpListenerModService.d.ts +++ b/TypeScript/7OnLoadHook/types/services/mod/httpListener/HttpListenerModService.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { DependencyContainer } from "tsyringe"; export declare class HttpListenerModService { protected container: DependencyContainer; diff --git a/TypeScript/7OnLoadHook/types/utils/App.d.ts b/TypeScript/7OnLoadHook/types/utils/App.d.ts index dd8f24c..5e759ad 100644 --- a/TypeScript/7OnLoadHook/types/utils/App.d.ts +++ b/TypeScript/7OnLoadHook/types/utils/App.d.ts @@ -12,7 +12,6 @@ export declare class App { protected onLoadComponents: OnLoad[]; protected onUpdateComponents: OnUpdate[]; protected onUpdateLastRun: {}; - protected os: any; constructor(logger: ILogger, timeUtil: TimeUtil, localisationService: LocalisationService, encodingUtil: EncodingUtil, onLoadComponents: OnLoad[], onUpdateComponents: OnUpdate[]); load(): Promise; protected update(onUpdateComponents: OnUpdate[]): Promise; diff --git a/TypeScript/7OnLoadHook/types/utils/HashUtil.d.ts b/TypeScript/7OnLoadHook/types/utils/HashUtil.d.ts index c017ca8..27204cb 100644 --- a/TypeScript/7OnLoadHook/types/utils/HashUtil.d.ts +++ b/TypeScript/7OnLoadHook/types/utils/HashUtil.d.ts @@ -1,5 +1,5 @@ /// -import crypto from "crypto"; +import crypto from "node:crypto"; import { TimeUtil } from "./TimeUtil"; export declare class HashUtil { protected timeUtil: TimeUtil; diff --git a/TypeScript/7OnLoadHook/types/utils/HttpFileUtil.d.ts b/TypeScript/7OnLoadHook/types/utils/HttpFileUtil.d.ts index afc8409..6a386ce 100644 --- a/TypeScript/7OnLoadHook/types/utils/HttpFileUtil.d.ts +++ b/TypeScript/7OnLoadHook/types/utils/HttpFileUtil.d.ts @@ -1,5 +1,5 @@ /// -import { ServerResponse } from "http"; +import { ServerResponse } from "node:http"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; export declare class HttpFileUtil { protected httpServerHelper: HttpServerHelper; diff --git a/TypeScript/7OnLoadHook/types/utils/VFS.d.ts b/TypeScript/7OnLoadHook/types/utils/VFS.d.ts index 2cb09fa..3911c4b 100644 --- a/TypeScript/7OnLoadHook/types/utils/VFS.d.ts +++ b/TypeScript/7OnLoadHook/types/utils/VFS.d.ts @@ -1,6 +1,6 @@ /// /// -import fs from "fs"; +import fs from "node:fs"; import "reflect-metadata"; import { IAsyncQueue } from "../models/spt/utils/IAsyncQueue"; import { IUUidGenerator } from "../models/spt/utils/IUuidGenerator"; diff --git a/TypeScript/7OnLoadHook/types/utils/Watermark.d.ts b/TypeScript/7OnLoadHook/types/utils/Watermark.d.ts index fa63205..864e9b6 100644 --- a/TypeScript/7OnLoadHook/types/utils/Watermark.d.ts +++ b/TypeScript/7OnLoadHook/types/utils/Watermark.d.ts @@ -4,12 +4,10 @@ import { ConfigServer } from "../servers/ConfigServer"; import { LocalisationService } from "../services/LocalisationService"; export declare class WatermarkLocale { protected localisationService: LocalisationService; + protected description: string[]; + protected warning: string[]; + protected modding: string[]; constructor(localisationService: LocalisationService); - protected watermark: { - description: string[]; - warning: string[]; - modding: string[]; - }; getDescription(): string[]; getWarning(): string[]; getModding(): string[]; diff --git a/TypeScript/7OnLoadHook/types/utils/logging/AbstractWinstonLogger.d.ts b/TypeScript/7OnLoadHook/types/utils/logging/AbstractWinstonLogger.d.ts index 1ae1100..74767a2 100644 --- a/TypeScript/7OnLoadHook/types/utils/logging/AbstractWinstonLogger.d.ts +++ b/TypeScript/7OnLoadHook/types/utils/logging/AbstractWinstonLogger.d.ts @@ -1,5 +1,5 @@ /// -import fs from "fs"; +import fs from "node:fs"; import winston from "winston"; import { Daum } from "../../models/eft/itemEvent/IItemEventRouterRequest"; import { LogBackgroundColor } from "../../models/spt/logging/LogBackgroundColor"; diff --git a/TypeScript/8OnUpdateHook/types/controllers/GameController.d.ts b/TypeScript/8OnUpdateHook/types/controllers/GameController.d.ts index 73596ff..74123b2 100644 --- a/TypeScript/8OnUpdateHook/types/controllers/GameController.d.ts +++ b/TypeScript/8OnUpdateHook/types/controllers/GameController.d.ts @@ -49,7 +49,6 @@ export declare class GameController { protected giftService: GiftService; protected applicationContext: ApplicationContext; protected configServer: ConfigServer; - protected os: any; protected httpConfig: IHttpConfig; protected coreConfig: ICoreConfig; protected locationConfig: ILocationConfig; diff --git a/TypeScript/8OnUpdateHook/types/controllers/InsuranceController.d.ts b/TypeScript/8OnUpdateHook/types/controllers/InsuranceController.d.ts index fb41610..fc3229b 100644 --- a/TypeScript/8OnUpdateHook/types/controllers/InsuranceController.d.ts +++ b/TypeScript/8OnUpdateHook/types/controllers/InsuranceController.d.ts @@ -4,7 +4,6 @@ import { ProfileHelper } from "../helpers/ProfileHelper"; import { TraderHelper } from "../helpers/TraderHelper"; import { IPmcData } from "../models/eft/common/IPmcData"; import { Item } from "../models/eft/common/tables/IItem"; -import { ITemplateItem } from "../models/eft/common/tables/ITemplateItem"; import { IGetInsuranceCostRequestData } from "../models/eft/insurance/IGetInsuranceCostRequestData"; import { IGetInsuranceCostResponseData } from "../models/eft/insurance/IGetInsuranceCostResponseData"; import { IInsureRequestData } from "../models/eft/insurance/IInsureRequestData"; @@ -75,67 +74,92 @@ export declare class InsuranceController { */ protected removeInsurancePackageFromProfile(sessionID: string, packageInfo: ISystemData): void; /** - * Build an array of items to delete from the insured items. + * Finds the items that should be deleted based on the given Insurance object. * - * This method orchestrates several steps: - * - Filters items based on their presence in the database and their raid moddability. - * - Sorts base and independent child items to consider for deletion. - * - Groups child items by their parent for later evaluation. - * - Evaluates grouped child items to decide which should be deleted, based on their value and a random roll. - * - * @param insured - The insured items to build a removal array from. - * @returns An array of IDs representing items that should be deleted. + * @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(insured: Insurance): Set; /** - * Filters an item based on its existence in the database, raid moddability, and slot requirements. + * Populate a Map object of items for quick lookup by their ID. * - * @param item The item to be filtered. - * @param parentItemDbDetails The database details of the parent item, or null if the item has no parent. - * @param itemDbDetails A tuple where the first element is a boolean indicating if the item exists in the database, - * and the second element is the item details if it does. - * @returns true if the item exists in the database and neither of the following conditions are met: - * - The item has the RaidModdable property set to false. - * - The item is attached to a required slot in its parent item. - * Otherwise, returns false. + * @param insured The insurance object containing the items to populate the map with. + * @returns A Map where the keys are the item IDs and the values are the corresponding Item objects. */ - protected filterByRaidModdability(item: Item, parentItemDbDetails: ITemplateItem | null, itemDbDetails: [boolean, ITemplateItem]): boolean; + protected populateItemsMap(insured: Insurance): Map; /** - * Determines if an item is either a base item or a child item that is not equipped to its parent. + * 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 item The item to check. - * @returns true if the item is a base or an independent child item, otherwise false. + * @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. */ - protected isBaseOrIndependentChild(item: Item): boolean; + protected populateParentAttachmentsMap(insured: Insurance, itemsMap: Map): Map; /** - * Makes a roll to determine if a given item should be deleted. If the roll is successful, the item's ID is added - * to the `toDelete` array. + * 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. * - * @param item The item for which the roll is made. - * @param traderId The ID of the trader to consider in the rollForItemDelete method. - * @param toDelete The array accumulating the IDs of items to be deleted. - * @returns true if the item is marked for deletion, otherwise false. - */ - protected makeRollAndMarkForDeletion(item: Item, traderId: string, toDelete: Set): boolean; - /** - * Groups child items by their parent IDs in a Map data structure. - * - * @param item The child item to be grouped by its parent. - * @param childrenGroupedByParent The Map that holds arrays of children items grouped by their parent IDs. + * @param insured The insurance object containing the items to evaluate. + * @param toDelete A Set to keep track of items marked for deletion. * @returns void */ - protected groupChildrenByParent(item: Item, childrenGroupedByParent: Map): void; + protected processRegularItems(insured: Insurance, toDelete: Set): void; /** - * Sorts the array of children items in descending order by their maximum price. For each child, a roll is made to - * determine if it should be deleted. The method then deletes the most valuable children based on the number of - * successful rolls made. + * Process parent items and their attachments, updating the toDelete Set accordingly. * - * @param children The array of children items to sort and filter. - * @param traderId The ID of the trader to consider in the rollForItemDelete method. + * This method iterates over a map of parent items to their attachments and performs evaluations on each. + * It marks items for deletion based on certain conditions and updates the toDelete Set accordingly. + * + * @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. + */ + protected processAttachments(mainParentToAttachmentsMap: Map, itemsMap: Map, traderId: string, toDelete: Set): void; + /** + * 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. + * + * @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. * @returns void */ - protected sortAndFilterChildren(children: Item[], traderId: string, toDelete: Set): void; + protected processAttachmentByParent(attachments: Item[], traderId: string, toDelete: Set): void; + /** + * Sorts the attachment items by their max price in descending order. + * + * @param attachments The array of attachments items. + * @returns An array of items enriched with their max price and common locale-name. + */ + protected sortAttachmentsByPrice(attachments: Item[]): EnrichedItem[]; + /** + * Logs the details of each attachment item. + * + * @param attachments The array of attachment items. + */ + protected logAttachmentsDetails(attachments: EnrichedItem[]): void; + /** + * Counts the number of successful rolls for the attachment items. + * + * @param attachments The array of attachment items. + * @param traderId The ID of the trader that has insured these attachments. + * @returns The number of successful rolls. + */ + protected countSuccessfulRolls(attachments: Item[], traderId: string): number; + /** + * Marks the most valuable attachments for deletion based on the number of successful rolls made. + * + * @param attachments The array of attachment items. + * @param successfulRolls The number of successful rolls. + * @param toDelete The array that accumulates the IDs of the items to be deleted. + */ + protected attachmentDeletionByValue(attachments: EnrichedItem[], successfulRolls: number, toDelete: Set): void; /** * Remove items from the insured items that should not be returned to the player. * @@ -144,6 +168,22 @@ export declare class InsuranceController { * @returns void */ protected removeItemsFromInsurance(insured: Insurance, toDelete: Set): void; + /** + * Adopts orphaned items by resetting them as base-level items. Helpful in situations where a parent has been + * deleted from insurance, but any insured items within the parent should remain. This method will remove the + * reference from the children to the parent and set item properties to main-level values. + * + * @param insured Insurance object containing items. + */ + protected adoptOrphanedItems(insured: Insurance): void; + /** + * Fetches the parentId property of an item with a slotId "hideout". Not sure if this is actually dynamic, but this + * method should be a reliable way to fetch it, if it ever does change. + * + * @param items Array of items to search through. + * @returns The parentId of an item with slotId 'hideout'. Empty string if not found. + */ + protected fetchHideoutItemParent(items: Item[]): string; /** * Handle sending the insurance message to the user that potentially contains the valid insurance items. * @@ -154,15 +194,14 @@ export declare class InsuranceController { */ protected sendMail(sessionID: string, insurance: Insurance, noItems: boolean): void; /** - * Determines whether a valid insured item should be removed from the player's inventory based on a random roll and + * Determines whether a insured item should be removed from the player's inventory based on a random roll and * trader-specific return chance. * - * @param insuredItem The insured item being evaluated for removal. * @param traderId The ID of the trader who insured the item. - * @param itemsBeingDeleted List of items that are already slated for removal. + * @param insuredItem Optional. The item to roll for. Only used for logging. * @returns true if the insured item should be removed from inventory, false otherwise. */ - protected rollForItemDelete(insuredItem: Item, traderId: string, itemsBeingDeleted: Set): boolean; + protected rollForDelete(traderId: string, insuredItem?: Item): boolean; /** * Handle Insure event * Add insurance to an item @@ -183,3 +222,8 @@ export declare class InsuranceController { */ cost(request: IGetInsuranceCostRequestData, sessionID: string): IGetInsuranceCostResponseData; } +interface EnrichedItem extends Item { + name: string; + maxPrice: number; +} +export {}; diff --git a/TypeScript/8OnUpdateHook/types/di/Serializer.d.ts b/TypeScript/8OnUpdateHook/types/di/Serializer.d.ts index 2617007..b760b8b 100644 --- a/TypeScript/8OnUpdateHook/types/di/Serializer.d.ts +++ b/TypeScript/8OnUpdateHook/types/di/Serializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export declare class Serializer { serialize(sessionID: string, req: IncomingMessage, resp: ServerResponse, body: any): void; canHandle(something: string): boolean; diff --git a/TypeScript/8OnUpdateHook/types/helpers/ItemHelper.d.ts b/TypeScript/8OnUpdateHook/types/helpers/ItemHelper.d.ts index 6f1511c..5920d8a 100644 --- a/TypeScript/8OnUpdateHook/types/helpers/ItemHelper.d.ts +++ b/TypeScript/8OnUpdateHook/types/helpers/ItemHelper.d.ts @@ -225,6 +225,48 @@ declare class ItemHelper { * @returns true if item is flagged as quest item */ isQuestItem(tpl: string): boolean; + /** + * Checks to see if the item is *actually* moddable in-raid. Checks include the items existence in the database, the + * parent items existence in the database, the existence (and value) of the items RaidModdable property, and that + * the parents slot-required property exists, matches that of the item, and it's value. + * + * Note: this function does not preform any checks to see if the item and parent are *actually* related. + * + * @param item The item to be checked + * @param parent The parent of the item to be checked + * @returns True if the item is actually moddable, false if it is not, and null if the check cannot be performed. + */ + isRaidModdable(item: Item, parent: Item): boolean | null; + /** + * Retrieves the main parent item for a given attachment item. + * + * This method traverses up the hierarchy of items starting from a given `itemId`, until it finds the main parent + * item that is not an attached attachment itself. In other words, if you pass it an item id of a suppressor, it + * will traverse up the muzzle brake, barrel, upper receiver, and return the gun that the suppressor is ultimately + * attached to, even if that gun is located within multiple containers. + * + * It's important to note that traversal is expensive, so this method requires that you pass it a Map of the items + * to traverse, where the keys are the item IDs and the values are the corresponding Item objects. This alleviates + * some of the performance concerns, as it allows for quick lookups of items by ID. + * + * To generate the map: + * ``` + * const itemsMap = new Map(); + * items.forEach(item => itemsMap.set(item._id, item)); + * ``` + * + * @param itemId - The unique identifier of the item for which to find the main parent. + * @param itemsMap - A Map containing item IDs mapped to their corresponding Item objects for quick lookup. + * @returns The Item object representing the top-most parent of the given item, or `null` if no such parent exists. + */ + getAttachmentMainParent(itemId: string, itemsMap: Map): Item | null; + /** + * Determines if an item is an attachment that is currently attached to it's parent item. + * + * @param item The item to check. + * @returns true if the item is attached attachment, otherwise false. + */ + isAttachmentAttached(item: Item): boolean; /** * Get the inventory size of an item * @param items Item with children diff --git a/TypeScript/8OnUpdateHook/types/loaders/PreAkiModLoader.d.ts b/TypeScript/8OnUpdateHook/types/loaders/PreAkiModLoader.d.ts index 1e24b96..c0868b7 100644 --- a/TypeScript/8OnUpdateHook/types/loaders/PreAkiModLoader.d.ts +++ b/TypeScript/8OnUpdateHook/types/loaders/PreAkiModLoader.d.ts @@ -66,6 +66,10 @@ export declare class PreAkiModLoader implements IModLoader { protected isModCombatibleWithAki(mod: IPackageJsonData): boolean; protected executeMods(container: DependencyContainer): Promise; sortModsLoadOrder(): string[]; + /** + * Compile mod and add into class property "imported" + * @param mod Name of mod to compile/add + */ protected addMod(mod: string): Promise; protected autoInstallDependencies(modPath: string, pkg: IPackageJsonData): void; protected areModDependenciesFulfilled(pkg: IPackageJsonData, loadedMods: Record): boolean; diff --git a/TypeScript/8OnUpdateHook/types/models/external/HttpFramework.d.ts b/TypeScript/8OnUpdateHook/types/models/external/HttpFramework.d.ts index 64a37d6..fda8732 100644 --- a/TypeScript/8OnUpdateHook/types/models/external/HttpFramework.d.ts +++ b/TypeScript/8OnUpdateHook/types/models/external/HttpFramework.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export type HandleFn = (_: string, req: IncomingMessage, resp: ServerResponse) => void; /** * Associates handlers, HTTP methods and a base url to a listener using a proxy diff --git a/TypeScript/8OnUpdateHook/types/models/spt/mod/IPackageJsonData.d.ts b/TypeScript/8OnUpdateHook/types/models/spt/mod/IPackageJsonData.d.ts index 06f7454..f58d7cc 100644 --- a/TypeScript/8OnUpdateHook/types/models/spt/mod/IPackageJsonData.d.ts +++ b/TypeScript/8OnUpdateHook/types/models/spt/mod/IPackageJsonData.d.ts @@ -6,6 +6,9 @@ export interface IPackageJsonData { author: string; version: string; akiVersion: string; + /** We deliberately purge this data */ + scripts: Record; + devDependencies: Record; licence: string; main: string; isBundleMod: boolean; diff --git a/TypeScript/8OnUpdateHook/types/routers/HttpRouter.d.ts b/TypeScript/8OnUpdateHook/types/routers/HttpRouter.d.ts index f75a47d..46f847a 100644 --- a/TypeScript/8OnUpdateHook/types/routers/HttpRouter.d.ts +++ b/TypeScript/8OnUpdateHook/types/routers/HttpRouter.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage } from "http"; +import { IncomingMessage } from "node:http"; import { DynamicRouter, Router, StaticRouter } from "../di/Router"; export declare class HttpRouter { protected staticRouters: StaticRouter[]; diff --git a/TypeScript/8OnUpdateHook/types/routers/ImageRouter.d.ts b/TypeScript/8OnUpdateHook/types/routers/ImageRouter.d.ts index 675441c..fd03c59 100644 --- a/TypeScript/8OnUpdateHook/types/routers/ImageRouter.d.ts +++ b/TypeScript/8OnUpdateHook/types/routers/ImageRouter.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { ImageRouteService } from "../services/mod/image/ImageRouteService"; import { HttpFileUtil } from "../utils/HttpFileUtil"; import { VFS } from "../utils/VFS"; diff --git a/TypeScript/8OnUpdateHook/types/routers/serializers/BundleSerializer.d.ts b/TypeScript/8OnUpdateHook/types/routers/serializers/BundleSerializer.d.ts index ca4d8b6..db41142 100644 --- a/TypeScript/8OnUpdateHook/types/routers/serializers/BundleSerializer.d.ts +++ b/TypeScript/8OnUpdateHook/types/routers/serializers/BundleSerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { BundleLoader } from "../../loaders/BundleLoader"; import { ILogger } from "../../models/spt/utils/ILogger"; diff --git a/TypeScript/8OnUpdateHook/types/routers/serializers/ImageSerializer.d.ts b/TypeScript/8OnUpdateHook/types/routers/serializers/ImageSerializer.d.ts index 5de48ff..62ce84d 100644 --- a/TypeScript/8OnUpdateHook/types/routers/serializers/ImageSerializer.d.ts +++ b/TypeScript/8OnUpdateHook/types/routers/serializers/ImageSerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { ImageRouter } from "../ImageRouter"; export declare class ImageSerializer extends Serializer { diff --git a/TypeScript/8OnUpdateHook/types/routers/serializers/NotifySerializer.d.ts b/TypeScript/8OnUpdateHook/types/routers/serializers/NotifySerializer.d.ts index 1d179b2..e92d6e1 100644 --- a/TypeScript/8OnUpdateHook/types/routers/serializers/NotifySerializer.d.ts +++ b/TypeScript/8OnUpdateHook/types/routers/serializers/NotifySerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { NotifierController } from "../../controllers/NotifierController"; import { Serializer } from "../../di/Serializer"; import { HttpServerHelper } from "../../helpers/HttpServerHelper"; diff --git a/TypeScript/8OnUpdateHook/types/servers/HttpServer.d.ts b/TypeScript/8OnUpdateHook/types/servers/HttpServer.d.ts index 97e0705..c73eb3c 100644 --- a/TypeScript/8OnUpdateHook/types/servers/HttpServer.d.ts +++ b/TypeScript/8OnUpdateHook/types/servers/HttpServer.d.ts @@ -1,5 +1,5 @@ /// -import http, { IncomingMessage, ServerResponse } from "http"; +import http, { IncomingMessage, ServerResponse } from "node:http"; import { ApplicationContext } from "../context/ApplicationContext"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; import { IHttpConfig } from "../models/spt/config/IHttpConfig"; diff --git a/TypeScript/8OnUpdateHook/types/servers/WebSocketServer.d.ts b/TypeScript/8OnUpdateHook/types/servers/WebSocketServer.d.ts index fffbea2..b4c6158 100644 --- a/TypeScript/8OnUpdateHook/types/servers/WebSocketServer.d.ts +++ b/TypeScript/8OnUpdateHook/types/servers/WebSocketServer.d.ts @@ -1,5 +1,5 @@ /// -import http, { IncomingMessage } from "http"; +import http, { IncomingMessage } from "node:http"; import WebSocket from "ws"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; import { INotification } from "../models/eft/notifier/INotifier"; diff --git a/TypeScript/8OnUpdateHook/types/servers/http/AkiHttpListener.d.ts b/TypeScript/8OnUpdateHook/types/servers/http/AkiHttpListener.d.ts index c72e18f..e4ac80c 100644 --- a/TypeScript/8OnUpdateHook/types/servers/http/AkiHttpListener.d.ts +++ b/TypeScript/8OnUpdateHook/types/servers/http/AkiHttpListener.d.ts @@ -1,6 +1,6 @@ /// /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { ILogger } from "../../models/spt/utils/ILogger"; import { HttpRouter } from "../../routers/HttpRouter"; diff --git a/TypeScript/8OnUpdateHook/types/servers/http/IHttpListener.d.ts b/TypeScript/8OnUpdateHook/types/servers/http/IHttpListener.d.ts index 758bb5a..29d5fce 100644 --- a/TypeScript/8OnUpdateHook/types/servers/http/IHttpListener.d.ts +++ b/TypeScript/8OnUpdateHook/types/servers/http/IHttpListener.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export interface IHttpListener { canHandle(sessionId: string, req: IncomingMessage): boolean; handle(sessionId: string, req: IncomingMessage, resp: ServerResponse): void; diff --git a/TypeScript/8OnUpdateHook/types/services/mod/httpListener/HttpListenerMod.d.ts b/TypeScript/8OnUpdateHook/types/services/mod/httpListener/HttpListenerMod.d.ts index 2cdfbda..afe4574 100644 --- a/TypeScript/8OnUpdateHook/types/services/mod/httpListener/HttpListenerMod.d.ts +++ b/TypeScript/8OnUpdateHook/types/services/mod/httpListener/HttpListenerMod.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { IHttpListener } from "../../../servers/http/IHttpListener"; export declare class HttpListenerMod implements IHttpListener { private canHandleOverride; diff --git a/TypeScript/8OnUpdateHook/types/services/mod/httpListener/HttpListenerModService.d.ts b/TypeScript/8OnUpdateHook/types/services/mod/httpListener/HttpListenerModService.d.ts index 9dd3473..23abfbe 100644 --- a/TypeScript/8OnUpdateHook/types/services/mod/httpListener/HttpListenerModService.d.ts +++ b/TypeScript/8OnUpdateHook/types/services/mod/httpListener/HttpListenerModService.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { DependencyContainer } from "tsyringe"; export declare class HttpListenerModService { protected container: DependencyContainer; diff --git a/TypeScript/8OnUpdateHook/types/utils/App.d.ts b/TypeScript/8OnUpdateHook/types/utils/App.d.ts index dd8f24c..5e759ad 100644 --- a/TypeScript/8OnUpdateHook/types/utils/App.d.ts +++ b/TypeScript/8OnUpdateHook/types/utils/App.d.ts @@ -12,7 +12,6 @@ export declare class App { protected onLoadComponents: OnLoad[]; protected onUpdateComponents: OnUpdate[]; protected onUpdateLastRun: {}; - protected os: any; constructor(logger: ILogger, timeUtil: TimeUtil, localisationService: LocalisationService, encodingUtil: EncodingUtil, onLoadComponents: OnLoad[], onUpdateComponents: OnUpdate[]); load(): Promise; protected update(onUpdateComponents: OnUpdate[]): Promise; diff --git a/TypeScript/8OnUpdateHook/types/utils/HashUtil.d.ts b/TypeScript/8OnUpdateHook/types/utils/HashUtil.d.ts index c017ca8..27204cb 100644 --- a/TypeScript/8OnUpdateHook/types/utils/HashUtil.d.ts +++ b/TypeScript/8OnUpdateHook/types/utils/HashUtil.d.ts @@ -1,5 +1,5 @@ /// -import crypto from "crypto"; +import crypto from "node:crypto"; import { TimeUtil } from "./TimeUtil"; export declare class HashUtil { protected timeUtil: TimeUtil; diff --git a/TypeScript/8OnUpdateHook/types/utils/HttpFileUtil.d.ts b/TypeScript/8OnUpdateHook/types/utils/HttpFileUtil.d.ts index afc8409..6a386ce 100644 --- a/TypeScript/8OnUpdateHook/types/utils/HttpFileUtil.d.ts +++ b/TypeScript/8OnUpdateHook/types/utils/HttpFileUtil.d.ts @@ -1,5 +1,5 @@ /// -import { ServerResponse } from "http"; +import { ServerResponse } from "node:http"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; export declare class HttpFileUtil { protected httpServerHelper: HttpServerHelper; diff --git a/TypeScript/8OnUpdateHook/types/utils/VFS.d.ts b/TypeScript/8OnUpdateHook/types/utils/VFS.d.ts index 2cb09fa..3911c4b 100644 --- a/TypeScript/8OnUpdateHook/types/utils/VFS.d.ts +++ b/TypeScript/8OnUpdateHook/types/utils/VFS.d.ts @@ -1,6 +1,6 @@ /// /// -import fs from "fs"; +import fs from "node:fs"; import "reflect-metadata"; import { IAsyncQueue } from "../models/spt/utils/IAsyncQueue"; import { IUUidGenerator } from "../models/spt/utils/IUuidGenerator"; diff --git a/TypeScript/8OnUpdateHook/types/utils/Watermark.d.ts b/TypeScript/8OnUpdateHook/types/utils/Watermark.d.ts index fa63205..864e9b6 100644 --- a/TypeScript/8OnUpdateHook/types/utils/Watermark.d.ts +++ b/TypeScript/8OnUpdateHook/types/utils/Watermark.d.ts @@ -4,12 +4,10 @@ import { ConfigServer } from "../servers/ConfigServer"; import { LocalisationService } from "../services/LocalisationService"; export declare class WatermarkLocale { protected localisationService: LocalisationService; + protected description: string[]; + protected warning: string[]; + protected modding: string[]; constructor(localisationService: LocalisationService); - protected watermark: { - description: string[]; - warning: string[]; - modding: string[]; - }; getDescription(): string[]; getWarning(): string[]; getModding(): string[]; diff --git a/TypeScript/8OnUpdateHook/types/utils/logging/AbstractWinstonLogger.d.ts b/TypeScript/8OnUpdateHook/types/utils/logging/AbstractWinstonLogger.d.ts index 1ae1100..74767a2 100644 --- a/TypeScript/8OnUpdateHook/types/utils/logging/AbstractWinstonLogger.d.ts +++ b/TypeScript/8OnUpdateHook/types/utils/logging/AbstractWinstonLogger.d.ts @@ -1,5 +1,5 @@ /// -import fs from "fs"; +import fs from "node:fs"; import winston from "winston"; import { Daum } from "../../models/eft/itemEvent/IItemEventRouterRequest"; import { LogBackgroundColor } from "../../models/spt/logging/LogBackgroundColor"; diff --git a/TypeScript/9RouterHooks/types/controllers/GameController.d.ts b/TypeScript/9RouterHooks/types/controllers/GameController.d.ts index 73596ff..74123b2 100644 --- a/TypeScript/9RouterHooks/types/controllers/GameController.d.ts +++ b/TypeScript/9RouterHooks/types/controllers/GameController.d.ts @@ -49,7 +49,6 @@ export declare class GameController { protected giftService: GiftService; protected applicationContext: ApplicationContext; protected configServer: ConfigServer; - protected os: any; protected httpConfig: IHttpConfig; protected coreConfig: ICoreConfig; protected locationConfig: ILocationConfig; diff --git a/TypeScript/9RouterHooks/types/controllers/InsuranceController.d.ts b/TypeScript/9RouterHooks/types/controllers/InsuranceController.d.ts index fb41610..fc3229b 100644 --- a/TypeScript/9RouterHooks/types/controllers/InsuranceController.d.ts +++ b/TypeScript/9RouterHooks/types/controllers/InsuranceController.d.ts @@ -4,7 +4,6 @@ import { ProfileHelper } from "../helpers/ProfileHelper"; import { TraderHelper } from "../helpers/TraderHelper"; import { IPmcData } from "../models/eft/common/IPmcData"; import { Item } from "../models/eft/common/tables/IItem"; -import { ITemplateItem } from "../models/eft/common/tables/ITemplateItem"; import { IGetInsuranceCostRequestData } from "../models/eft/insurance/IGetInsuranceCostRequestData"; import { IGetInsuranceCostResponseData } from "../models/eft/insurance/IGetInsuranceCostResponseData"; import { IInsureRequestData } from "../models/eft/insurance/IInsureRequestData"; @@ -75,67 +74,92 @@ export declare class InsuranceController { */ protected removeInsurancePackageFromProfile(sessionID: string, packageInfo: ISystemData): void; /** - * Build an array of items to delete from the insured items. + * Finds the items that should be deleted based on the given Insurance object. * - * This method orchestrates several steps: - * - Filters items based on their presence in the database and their raid moddability. - * - Sorts base and independent child items to consider for deletion. - * - Groups child items by their parent for later evaluation. - * - Evaluates grouped child items to decide which should be deleted, based on their value and a random roll. - * - * @param insured - The insured items to build a removal array from. - * @returns An array of IDs representing items that should be deleted. + * @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(insured: Insurance): Set; /** - * Filters an item based on its existence in the database, raid moddability, and slot requirements. + * Populate a Map object of items for quick lookup by their ID. * - * @param item The item to be filtered. - * @param parentItemDbDetails The database details of the parent item, or null if the item has no parent. - * @param itemDbDetails A tuple where the first element is a boolean indicating if the item exists in the database, - * and the second element is the item details if it does. - * @returns true if the item exists in the database and neither of the following conditions are met: - * - The item has the RaidModdable property set to false. - * - The item is attached to a required slot in its parent item. - * Otherwise, returns false. + * @param insured The insurance object containing the items to populate the map with. + * @returns A Map where the keys are the item IDs and the values are the corresponding Item objects. */ - protected filterByRaidModdability(item: Item, parentItemDbDetails: ITemplateItem | null, itemDbDetails: [boolean, ITemplateItem]): boolean; + protected populateItemsMap(insured: Insurance): Map; /** - * Determines if an item is either a base item or a child item that is not equipped to its parent. + * 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 item The item to check. - * @returns true if the item is a base or an independent child item, otherwise false. + * @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. */ - protected isBaseOrIndependentChild(item: Item): boolean; + protected populateParentAttachmentsMap(insured: Insurance, itemsMap: Map): Map; /** - * Makes a roll to determine if a given item should be deleted. If the roll is successful, the item's ID is added - * to the `toDelete` array. + * 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. * - * @param item The item for which the roll is made. - * @param traderId The ID of the trader to consider in the rollForItemDelete method. - * @param toDelete The array accumulating the IDs of items to be deleted. - * @returns true if the item is marked for deletion, otherwise false. - */ - protected makeRollAndMarkForDeletion(item: Item, traderId: string, toDelete: Set): boolean; - /** - * Groups child items by their parent IDs in a Map data structure. - * - * @param item The child item to be grouped by its parent. - * @param childrenGroupedByParent The Map that holds arrays of children items grouped by their parent IDs. + * @param insured The insurance object containing the items to evaluate. + * @param toDelete A Set to keep track of items marked for deletion. * @returns void */ - protected groupChildrenByParent(item: Item, childrenGroupedByParent: Map): void; + protected processRegularItems(insured: Insurance, toDelete: Set): void; /** - * Sorts the array of children items in descending order by their maximum price. For each child, a roll is made to - * determine if it should be deleted. The method then deletes the most valuable children based on the number of - * successful rolls made. + * Process parent items and their attachments, updating the toDelete Set accordingly. * - * @param children The array of children items to sort and filter. - * @param traderId The ID of the trader to consider in the rollForItemDelete method. + * This method iterates over a map of parent items to their attachments and performs evaluations on each. + * It marks items for deletion based on certain conditions and updates the toDelete Set accordingly. + * + * @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. + */ + protected processAttachments(mainParentToAttachmentsMap: Map, itemsMap: Map, traderId: string, toDelete: Set): void; + /** + * 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. + * + * @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. * @returns void */ - protected sortAndFilterChildren(children: Item[], traderId: string, toDelete: Set): void; + protected processAttachmentByParent(attachments: Item[], traderId: string, toDelete: Set): void; + /** + * Sorts the attachment items by their max price in descending order. + * + * @param attachments The array of attachments items. + * @returns An array of items enriched with their max price and common locale-name. + */ + protected sortAttachmentsByPrice(attachments: Item[]): EnrichedItem[]; + /** + * Logs the details of each attachment item. + * + * @param attachments The array of attachment items. + */ + protected logAttachmentsDetails(attachments: EnrichedItem[]): void; + /** + * Counts the number of successful rolls for the attachment items. + * + * @param attachments The array of attachment items. + * @param traderId The ID of the trader that has insured these attachments. + * @returns The number of successful rolls. + */ + protected countSuccessfulRolls(attachments: Item[], traderId: string): number; + /** + * Marks the most valuable attachments for deletion based on the number of successful rolls made. + * + * @param attachments The array of attachment items. + * @param successfulRolls The number of successful rolls. + * @param toDelete The array that accumulates the IDs of the items to be deleted. + */ + protected attachmentDeletionByValue(attachments: EnrichedItem[], successfulRolls: number, toDelete: Set): void; /** * Remove items from the insured items that should not be returned to the player. * @@ -144,6 +168,22 @@ export declare class InsuranceController { * @returns void */ protected removeItemsFromInsurance(insured: Insurance, toDelete: Set): void; + /** + * Adopts orphaned items by resetting them as base-level items. Helpful in situations where a parent has been + * deleted from insurance, but any insured items within the parent should remain. This method will remove the + * reference from the children to the parent and set item properties to main-level values. + * + * @param insured Insurance object containing items. + */ + protected adoptOrphanedItems(insured: Insurance): void; + /** + * Fetches the parentId property of an item with a slotId "hideout". Not sure if this is actually dynamic, but this + * method should be a reliable way to fetch it, if it ever does change. + * + * @param items Array of items to search through. + * @returns The parentId of an item with slotId 'hideout'. Empty string if not found. + */ + protected fetchHideoutItemParent(items: Item[]): string; /** * Handle sending the insurance message to the user that potentially contains the valid insurance items. * @@ -154,15 +194,14 @@ export declare class InsuranceController { */ protected sendMail(sessionID: string, insurance: Insurance, noItems: boolean): void; /** - * Determines whether a valid insured item should be removed from the player's inventory based on a random roll and + * Determines whether a insured item should be removed from the player's inventory based on a random roll and * trader-specific return chance. * - * @param insuredItem The insured item being evaluated for removal. * @param traderId The ID of the trader who insured the item. - * @param itemsBeingDeleted List of items that are already slated for removal. + * @param insuredItem Optional. The item to roll for. Only used for logging. * @returns true if the insured item should be removed from inventory, false otherwise. */ - protected rollForItemDelete(insuredItem: Item, traderId: string, itemsBeingDeleted: Set): boolean; + protected rollForDelete(traderId: string, insuredItem?: Item): boolean; /** * Handle Insure event * Add insurance to an item @@ -183,3 +222,8 @@ export declare class InsuranceController { */ cost(request: IGetInsuranceCostRequestData, sessionID: string): IGetInsuranceCostResponseData; } +interface EnrichedItem extends Item { + name: string; + maxPrice: number; +} +export {}; diff --git a/TypeScript/9RouterHooks/types/di/Serializer.d.ts b/TypeScript/9RouterHooks/types/di/Serializer.d.ts index 2617007..b760b8b 100644 --- a/TypeScript/9RouterHooks/types/di/Serializer.d.ts +++ b/TypeScript/9RouterHooks/types/di/Serializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export declare class Serializer { serialize(sessionID: string, req: IncomingMessage, resp: ServerResponse, body: any): void; canHandle(something: string): boolean; diff --git a/TypeScript/9RouterHooks/types/helpers/ItemHelper.d.ts b/TypeScript/9RouterHooks/types/helpers/ItemHelper.d.ts index 6f1511c..5920d8a 100644 --- a/TypeScript/9RouterHooks/types/helpers/ItemHelper.d.ts +++ b/TypeScript/9RouterHooks/types/helpers/ItemHelper.d.ts @@ -225,6 +225,48 @@ declare class ItemHelper { * @returns true if item is flagged as quest item */ isQuestItem(tpl: string): boolean; + /** + * Checks to see if the item is *actually* moddable in-raid. Checks include the items existence in the database, the + * parent items existence in the database, the existence (and value) of the items RaidModdable property, and that + * the parents slot-required property exists, matches that of the item, and it's value. + * + * Note: this function does not preform any checks to see if the item and parent are *actually* related. + * + * @param item The item to be checked + * @param parent The parent of the item to be checked + * @returns True if the item is actually moddable, false if it is not, and null if the check cannot be performed. + */ + isRaidModdable(item: Item, parent: Item): boolean | null; + /** + * Retrieves the main parent item for a given attachment item. + * + * This method traverses up the hierarchy of items starting from a given `itemId`, until it finds the main parent + * item that is not an attached attachment itself. In other words, if you pass it an item id of a suppressor, it + * will traverse up the muzzle brake, barrel, upper receiver, and return the gun that the suppressor is ultimately + * attached to, even if that gun is located within multiple containers. + * + * It's important to note that traversal is expensive, so this method requires that you pass it a Map of the items + * to traverse, where the keys are the item IDs and the values are the corresponding Item objects. This alleviates + * some of the performance concerns, as it allows for quick lookups of items by ID. + * + * To generate the map: + * ``` + * const itemsMap = new Map(); + * items.forEach(item => itemsMap.set(item._id, item)); + * ``` + * + * @param itemId - The unique identifier of the item for which to find the main parent. + * @param itemsMap - A Map containing item IDs mapped to their corresponding Item objects for quick lookup. + * @returns The Item object representing the top-most parent of the given item, or `null` if no such parent exists. + */ + getAttachmentMainParent(itemId: string, itemsMap: Map): Item | null; + /** + * Determines if an item is an attachment that is currently attached to it's parent item. + * + * @param item The item to check. + * @returns true if the item is attached attachment, otherwise false. + */ + isAttachmentAttached(item: Item): boolean; /** * Get the inventory size of an item * @param items Item with children diff --git a/TypeScript/9RouterHooks/types/loaders/PreAkiModLoader.d.ts b/TypeScript/9RouterHooks/types/loaders/PreAkiModLoader.d.ts index 1e24b96..c0868b7 100644 --- a/TypeScript/9RouterHooks/types/loaders/PreAkiModLoader.d.ts +++ b/TypeScript/9RouterHooks/types/loaders/PreAkiModLoader.d.ts @@ -66,6 +66,10 @@ export declare class PreAkiModLoader implements IModLoader { protected isModCombatibleWithAki(mod: IPackageJsonData): boolean; protected executeMods(container: DependencyContainer): Promise; sortModsLoadOrder(): string[]; + /** + * Compile mod and add into class property "imported" + * @param mod Name of mod to compile/add + */ protected addMod(mod: string): Promise; protected autoInstallDependencies(modPath: string, pkg: IPackageJsonData): void; protected areModDependenciesFulfilled(pkg: IPackageJsonData, loadedMods: Record): boolean; diff --git a/TypeScript/9RouterHooks/types/models/external/HttpFramework.d.ts b/TypeScript/9RouterHooks/types/models/external/HttpFramework.d.ts index 64a37d6..fda8732 100644 --- a/TypeScript/9RouterHooks/types/models/external/HttpFramework.d.ts +++ b/TypeScript/9RouterHooks/types/models/external/HttpFramework.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export type HandleFn = (_: string, req: IncomingMessage, resp: ServerResponse) => void; /** * Associates handlers, HTTP methods and a base url to a listener using a proxy diff --git a/TypeScript/9RouterHooks/types/models/spt/mod/IPackageJsonData.d.ts b/TypeScript/9RouterHooks/types/models/spt/mod/IPackageJsonData.d.ts index 06f7454..f58d7cc 100644 --- a/TypeScript/9RouterHooks/types/models/spt/mod/IPackageJsonData.d.ts +++ b/TypeScript/9RouterHooks/types/models/spt/mod/IPackageJsonData.d.ts @@ -6,6 +6,9 @@ export interface IPackageJsonData { author: string; version: string; akiVersion: string; + /** We deliberately purge this data */ + scripts: Record; + devDependencies: Record; licence: string; main: string; isBundleMod: boolean; diff --git a/TypeScript/9RouterHooks/types/routers/HttpRouter.d.ts b/TypeScript/9RouterHooks/types/routers/HttpRouter.d.ts index f75a47d..46f847a 100644 --- a/TypeScript/9RouterHooks/types/routers/HttpRouter.d.ts +++ b/TypeScript/9RouterHooks/types/routers/HttpRouter.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage } from "http"; +import { IncomingMessage } from "node:http"; import { DynamicRouter, Router, StaticRouter } from "../di/Router"; export declare class HttpRouter { protected staticRouters: StaticRouter[]; diff --git a/TypeScript/9RouterHooks/types/routers/ImageRouter.d.ts b/TypeScript/9RouterHooks/types/routers/ImageRouter.d.ts index 675441c..fd03c59 100644 --- a/TypeScript/9RouterHooks/types/routers/ImageRouter.d.ts +++ b/TypeScript/9RouterHooks/types/routers/ImageRouter.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { ImageRouteService } from "../services/mod/image/ImageRouteService"; import { HttpFileUtil } from "../utils/HttpFileUtil"; import { VFS } from "../utils/VFS"; diff --git a/TypeScript/9RouterHooks/types/routers/serializers/BundleSerializer.d.ts b/TypeScript/9RouterHooks/types/routers/serializers/BundleSerializer.d.ts index ca4d8b6..db41142 100644 --- a/TypeScript/9RouterHooks/types/routers/serializers/BundleSerializer.d.ts +++ b/TypeScript/9RouterHooks/types/routers/serializers/BundleSerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { BundleLoader } from "../../loaders/BundleLoader"; import { ILogger } from "../../models/spt/utils/ILogger"; diff --git a/TypeScript/9RouterHooks/types/routers/serializers/ImageSerializer.d.ts b/TypeScript/9RouterHooks/types/routers/serializers/ImageSerializer.d.ts index 5de48ff..62ce84d 100644 --- a/TypeScript/9RouterHooks/types/routers/serializers/ImageSerializer.d.ts +++ b/TypeScript/9RouterHooks/types/routers/serializers/ImageSerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { ImageRouter } from "../ImageRouter"; export declare class ImageSerializer extends Serializer { diff --git a/TypeScript/9RouterHooks/types/routers/serializers/NotifySerializer.d.ts b/TypeScript/9RouterHooks/types/routers/serializers/NotifySerializer.d.ts index 1d179b2..e92d6e1 100644 --- a/TypeScript/9RouterHooks/types/routers/serializers/NotifySerializer.d.ts +++ b/TypeScript/9RouterHooks/types/routers/serializers/NotifySerializer.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { NotifierController } from "../../controllers/NotifierController"; import { Serializer } from "../../di/Serializer"; import { HttpServerHelper } from "../../helpers/HttpServerHelper"; diff --git a/TypeScript/9RouterHooks/types/servers/HttpServer.d.ts b/TypeScript/9RouterHooks/types/servers/HttpServer.d.ts index 97e0705..c73eb3c 100644 --- a/TypeScript/9RouterHooks/types/servers/HttpServer.d.ts +++ b/TypeScript/9RouterHooks/types/servers/HttpServer.d.ts @@ -1,5 +1,5 @@ /// -import http, { IncomingMessage, ServerResponse } from "http"; +import http, { IncomingMessage, ServerResponse } from "node:http"; import { ApplicationContext } from "../context/ApplicationContext"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; import { IHttpConfig } from "../models/spt/config/IHttpConfig"; diff --git a/TypeScript/9RouterHooks/types/servers/WebSocketServer.d.ts b/TypeScript/9RouterHooks/types/servers/WebSocketServer.d.ts index fffbea2..b4c6158 100644 --- a/TypeScript/9RouterHooks/types/servers/WebSocketServer.d.ts +++ b/TypeScript/9RouterHooks/types/servers/WebSocketServer.d.ts @@ -1,5 +1,5 @@ /// -import http, { IncomingMessage } from "http"; +import http, { IncomingMessage } from "node:http"; import WebSocket from "ws"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; import { INotification } from "../models/eft/notifier/INotifier"; diff --git a/TypeScript/9RouterHooks/types/servers/http/AkiHttpListener.d.ts b/TypeScript/9RouterHooks/types/servers/http/AkiHttpListener.d.ts index c72e18f..e4ac80c 100644 --- a/TypeScript/9RouterHooks/types/servers/http/AkiHttpListener.d.ts +++ b/TypeScript/9RouterHooks/types/servers/http/AkiHttpListener.d.ts @@ -1,6 +1,6 @@ /// /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { Serializer } from "../../di/Serializer"; import { ILogger } from "../../models/spt/utils/ILogger"; import { HttpRouter } from "../../routers/HttpRouter"; diff --git a/TypeScript/9RouterHooks/types/servers/http/IHttpListener.d.ts b/TypeScript/9RouterHooks/types/servers/http/IHttpListener.d.ts index 758bb5a..29d5fce 100644 --- a/TypeScript/9RouterHooks/types/servers/http/IHttpListener.d.ts +++ b/TypeScript/9RouterHooks/types/servers/http/IHttpListener.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export interface IHttpListener { canHandle(sessionId: string, req: IncomingMessage): boolean; handle(sessionId: string, req: IncomingMessage, resp: ServerResponse): void; diff --git a/TypeScript/9RouterHooks/types/services/mod/httpListener/HttpListenerMod.d.ts b/TypeScript/9RouterHooks/types/services/mod/httpListener/HttpListenerMod.d.ts index 2cdfbda..afe4574 100644 --- a/TypeScript/9RouterHooks/types/services/mod/httpListener/HttpListenerMod.d.ts +++ b/TypeScript/9RouterHooks/types/services/mod/httpListener/HttpListenerMod.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { IHttpListener } from "../../../servers/http/IHttpListener"; export declare class HttpListenerMod implements IHttpListener { private canHandleOverride; diff --git a/TypeScript/9RouterHooks/types/services/mod/httpListener/HttpListenerModService.d.ts b/TypeScript/9RouterHooks/types/services/mod/httpListener/HttpListenerModService.d.ts index 9dd3473..23abfbe 100644 --- a/TypeScript/9RouterHooks/types/services/mod/httpListener/HttpListenerModService.d.ts +++ b/TypeScript/9RouterHooks/types/services/mod/httpListener/HttpListenerModService.d.ts @@ -1,5 +1,5 @@ /// -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { DependencyContainer } from "tsyringe"; export declare class HttpListenerModService { protected container: DependencyContainer; diff --git a/TypeScript/9RouterHooks/types/utils/App.d.ts b/TypeScript/9RouterHooks/types/utils/App.d.ts index dd8f24c..5e759ad 100644 --- a/TypeScript/9RouterHooks/types/utils/App.d.ts +++ b/TypeScript/9RouterHooks/types/utils/App.d.ts @@ -12,7 +12,6 @@ export declare class App { protected onLoadComponents: OnLoad[]; protected onUpdateComponents: OnUpdate[]; protected onUpdateLastRun: {}; - protected os: any; constructor(logger: ILogger, timeUtil: TimeUtil, localisationService: LocalisationService, encodingUtil: EncodingUtil, onLoadComponents: OnLoad[], onUpdateComponents: OnUpdate[]); load(): Promise; protected update(onUpdateComponents: OnUpdate[]): Promise; diff --git a/TypeScript/9RouterHooks/types/utils/HashUtil.d.ts b/TypeScript/9RouterHooks/types/utils/HashUtil.d.ts index c017ca8..27204cb 100644 --- a/TypeScript/9RouterHooks/types/utils/HashUtil.d.ts +++ b/TypeScript/9RouterHooks/types/utils/HashUtil.d.ts @@ -1,5 +1,5 @@ /// -import crypto from "crypto"; +import crypto from "node:crypto"; import { TimeUtil } from "./TimeUtil"; export declare class HashUtil { protected timeUtil: TimeUtil; diff --git a/TypeScript/9RouterHooks/types/utils/HttpFileUtil.d.ts b/TypeScript/9RouterHooks/types/utils/HttpFileUtil.d.ts index afc8409..6a386ce 100644 --- a/TypeScript/9RouterHooks/types/utils/HttpFileUtil.d.ts +++ b/TypeScript/9RouterHooks/types/utils/HttpFileUtil.d.ts @@ -1,5 +1,5 @@ /// -import { ServerResponse } from "http"; +import { ServerResponse } from "node:http"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; export declare class HttpFileUtil { protected httpServerHelper: HttpServerHelper; diff --git a/TypeScript/9RouterHooks/types/utils/VFS.d.ts b/TypeScript/9RouterHooks/types/utils/VFS.d.ts index 2cb09fa..3911c4b 100644 --- a/TypeScript/9RouterHooks/types/utils/VFS.d.ts +++ b/TypeScript/9RouterHooks/types/utils/VFS.d.ts @@ -1,6 +1,6 @@ /// /// -import fs from "fs"; +import fs from "node:fs"; import "reflect-metadata"; import { IAsyncQueue } from "../models/spt/utils/IAsyncQueue"; import { IUUidGenerator } from "../models/spt/utils/IUuidGenerator"; diff --git a/TypeScript/9RouterHooks/types/utils/Watermark.d.ts b/TypeScript/9RouterHooks/types/utils/Watermark.d.ts index fa63205..864e9b6 100644 --- a/TypeScript/9RouterHooks/types/utils/Watermark.d.ts +++ b/TypeScript/9RouterHooks/types/utils/Watermark.d.ts @@ -4,12 +4,10 @@ import { ConfigServer } from "../servers/ConfigServer"; import { LocalisationService } from "../services/LocalisationService"; export declare class WatermarkLocale { protected localisationService: LocalisationService; + protected description: string[]; + protected warning: string[]; + protected modding: string[]; constructor(localisationService: LocalisationService); - protected watermark: { - description: string[]; - warning: string[]; - modding: string[]; - }; getDescription(): string[]; getWarning(): string[]; getModding(): string[]; diff --git a/TypeScript/9RouterHooks/types/utils/logging/AbstractWinstonLogger.d.ts b/TypeScript/9RouterHooks/types/utils/logging/AbstractWinstonLogger.d.ts index 1ae1100..74767a2 100644 --- a/TypeScript/9RouterHooks/types/utils/logging/AbstractWinstonLogger.d.ts +++ b/TypeScript/9RouterHooks/types/utils/logging/AbstractWinstonLogger.d.ts @@ -1,5 +1,5 @@ /// -import fs from "fs"; +import fs from "node:fs"; import winston from "winston"; import { Daum } from "../../models/eft/itemEvent/IItemEventRouterRequest"; import { LogBackgroundColor } from "../../models/spt/logging/LogBackgroundColor";