From ad576a937a47c27700688b8464529b1b30fe37db Mon Sep 17 00:00:00 2001 From: Dev Date: Mon, 24 Jul 2023 15:52:55 +0100 Subject: [PATCH] Comment improvements --- project/src/controllers/LocationController.ts | 12 ++- project/src/helpers/ContainerHelper.ts | 92 +++++++++++-------- project/src/helpers/DurabilityLimitsHelper.ts | 26 ++++++ project/src/helpers/HandbookHelper.ts | 20 ++-- project/src/helpers/HideoutHelper.ts | 5 + project/src/helpers/HttpServerHelper.ts | 9 ++ project/src/helpers/InRaidHelper.ts | 2 +- project/src/helpers/InventoryHelper.ts | 5 +- 8 files changed, 120 insertions(+), 51 deletions(-) diff --git a/project/src/controllers/LocationController.ts b/project/src/controllers/LocationController.ts index d1c72a30..9634e371 100644 --- a/project/src/controllers/LocationController.ts +++ b/project/src/controllers/LocationController.ts @@ -58,8 +58,12 @@ export class LocationController return this.generate(name); } - /* generates a random location preset to use for local session */ - private generate(name: string): ILocationBase + /** + * Generate a maps base location without loot + * @param name Map name + * @returns ILocationBase + */ + protected generate(name: string): ILocationBase { const location: ILocation = this.databaseServer.getTables().locations[name]; const output: ILocationBase = this.jsonUtil.clone(location.base); @@ -101,7 +105,7 @@ export class LocationController this.logger.success(this.localisationService.getText("location-containers_generated_success", staticContainerCount)); - // dyanmic loot + // Dyanmic loot const dynamicLootDist: ILooseLoot = this.jsonUtil.clone(location.looseLoot); const dynamicLoot: SpawnpointTemplate[] = this.locationGenerator.generateDynamicLoot(dynamicLootDist, staticAmmoDist, name); for (const dli of dynamicLoot) @@ -109,7 +113,7 @@ export class LocationController output.Loot.push(dli); } - // done generating + // Done generating this.logger.success(this.localisationService.getText("location-dynamic_items_spawned_success", dynamicLoot.length)); this.logger.success(this.localisationService.getText("location-generated_success", name)); diff --git a/project/src/helpers/ContainerHelper.ts b/project/src/helpers/ContainerHelper.ts index a243762d..7ebd8d19 100644 --- a/project/src/helpers/ContainerHelper.ts +++ b/project/src/helpers/ContainerHelper.ts @@ -18,44 +18,12 @@ export class FindSlotResult @injectable() export class ContainerHelper { - protected locateSlot(container2D: number[][], containerX: number, containerY: number, x: number, y: number, itemW: number, itemH: number): boolean - { - let foundSlot = true; - - for (let itemY = 0; itemY < itemH; itemY++) - { - if (foundSlot && y + itemH - 1 > containerY - 1) - { - foundSlot = false; - break; - } - - for (let itemX = 0; itemX < itemW; itemX++) - { - if (foundSlot && x + itemW - 1 > containerX - 1) - { - foundSlot = false; - break; - } - - if (container2D[y + itemY][x + itemX] !== 0) - { - foundSlot = false; - break; - } - } - - if (!foundSlot) - { - break; - } - } - - return foundSlot; - } - - /* Finds a slot for an item in a given 2D container map - * Output: { success: boolean, x: number, y: number, rotation: boolean } + /** + * Finds a slot for an item in a given 2D container map + * @param container2D Array of container with slots filled/free + * @param itemWidth Width of item + * @param itemHeight Height of item + * @returns Location to place item in container */ public findSlotForItem(container2D: number[][], itemWidth: number, itemHeight: number): FindSlotResult { @@ -98,6 +66,54 @@ export class ContainerHelper return new FindSlotResult(); } + /** + * Find a slot inside a container an item can be placed in + * @param container2D Container to find space in + * @param containerX Container x size + * @param containerY Container y size + * @param x ??? + * @param y ??? + * @param itemW Items width + * @param itemH Items height + * @returns True - slot found + */ + protected locateSlot(container2D: number[][], containerX: number, containerY: number, x: number, y: number, itemW: number, itemH: number): boolean + { + let foundSlot = true; + + for (let itemY = 0; itemY < itemH; itemY++) + { + if (foundSlot && y + itemH - 1 > containerY - 1) + { + foundSlot = false; + break; + } + + // Does item fit x-ways + for (let itemX = 0; itemX < itemW; itemX++) + { + if (foundSlot && x + itemW - 1 > containerX - 1) + { + foundSlot = false; + break; + } + + if (container2D[y + itemY][x + itemX] !== 0) + { + foundSlot = false; + break; + } + } + + if (!foundSlot) + { + break; + } + } + + return foundSlot; + } + /** * Find a free slot for an item to be placed at * @param container2D Container to palce item in diff --git a/project/src/helpers/DurabilityLimitsHelper.ts b/project/src/helpers/DurabilityLimitsHelper.ts index 8248df7f..43ae519d 100644 --- a/project/src/helpers/DurabilityLimitsHelper.ts +++ b/project/src/helpers/DurabilityLimitsHelper.ts @@ -21,6 +21,12 @@ export class DurabilityLimitsHelper this.botConfig = this.configServer.getConfig(ConfigTypes.BOT); } + /** + * Get max durability for a weapon based on bot role + * @param itemTemplate UNUSED - Item to get durability for + * @param botRole Role of bot to get max durability for + * @returns Max durability of weapon + */ public getRandomizedMaxWeaponDurability(itemTemplate: ITemplateItem, botRole: string): number { if (botRole && this.botHelper.isBotPmc(botRole)) @@ -41,6 +47,12 @@ export class DurabilityLimitsHelper return this.generateMaxWeaponDurability(botRole); } + /** + * Get max durability value for armor based on bot role + * @param itemTemplate Item to get max durability for + * @param botRole Role of bot to get max durability for + * @returns max durability + */ public getRandomizedMaxArmorDurability(itemTemplate: ITemplateItem, botRole: string): number { const itemMaxDurability = itemTemplate._props.MaxDurability; @@ -63,6 +75,13 @@ export class DurabilityLimitsHelper return itemMaxDurability; } + /** + * Get randomised current weapon durability by bot role + * @param itemTemplate Unused - Item to get current durability of + * @param botRole Role of bot to get current durability for + * @param maxDurability Max durability of weapon + * @returns Current weapon durability + */ public getRandomizedWeaponDurability(itemTemplate: ITemplateItem, botRole: string, maxDurability: number): number { if (botRole && (this.botHelper.isBotPmc(botRole))) @@ -83,6 +102,13 @@ export class DurabilityLimitsHelper return this.generateWeaponDurability(botRole, maxDurability); } + /** + * Get randomised current armor durability by bot role + * @param itemTemplate Unused - Item to get current durability of + * @param botRole Role of bot to get current durability for + * @param maxDurability Max durability of armor + * @returns Current armor durability + */ public getRandomizedArmorDurability(itemTemplate: ITemplateItem, botRole: string, maxDurability: number): number { if (botRole && (this.botHelper.isBotPmc(botRole))) diff --git a/project/src/helpers/HandbookHelper.ts b/project/src/helpers/HandbookHelper.ts index d217dab6..1ff9c876 100644 --- a/project/src/helpers/HandbookHelper.ts +++ b/project/src/helpers/HandbookHelper.ts @@ -36,6 +36,9 @@ export class HandbookHelper constructor(@inject("DatabaseServer") protected databaseServer: DatabaseServer) {} + /** + * Create an in-memory cache of all items with associated handbook price in handbookPriceCache class + */ public hydrateLookup(): void { const handbookDb = this.databaseServer.getTables().templates.handbook; @@ -94,13 +97,13 @@ export class HandbookHelper } /** - * all items in template with the given parent category - * @param x + * Get all items in template with the given parent category + * @param parentId * @returns string array */ - public templatesWithParent(x: string): string[] + public templatesWithParent(parentId: string): string[] { - return this.handbookPriceCache.items.byParent.get(x) ?? []; + return this.handbookPriceCache.items.byParent.get(parentId) ?? []; } /** @@ -113,9 +116,14 @@ export class HandbookHelper return this.handbookPriceCache.categories.byId.has(category); } - public childrenCategories(x: string): string[] + /** + * Get all items associated with a categories parent + * @param categoryParent + * @returns string array + */ + public childrenCategories(categoryParent: string): string[] { - return this.handbookPriceCache.categories.byParent.get(x) ?? []; + return this.handbookPriceCache.categories.byParent.get(categoryParent) ?? []; } /** diff --git a/project/src/helpers/HideoutHelper.ts b/project/src/helpers/HideoutHelper.ts index c913c99b..b8c87cd1 100644 --- a/project/src/helpers/HideoutHelper.ts +++ b/project/src/helpers/HideoutHelper.ts @@ -104,6 +104,11 @@ export class HideoutHelper }; } + /** + * Is the provided object a Production type + * @param productive + * @returns + */ public isProductionType(productive: Productive): productive is Production { return (productive as Production).Progress !== undefined || (productive as Production).RecipeId !== undefined; diff --git a/project/src/helpers/HttpServerHelper.ts b/project/src/helpers/HttpServerHelper.ts index 2ec28137..4054d5c1 100644 --- a/project/src/helpers/HttpServerHelper.ts +++ b/project/src/helpers/HttpServerHelper.ts @@ -33,16 +33,25 @@ export class HttpServerHelper return this.mime[key]; } + /** + * Combine ip and port into url + * @returns url + */ public buildUrl(): string { return `${this.httpConfig.ip}:${this.httpConfig.port}`; } + /** + * Prepend http to the url:port + * @returns URI + */ public getBackendUrl(): string { return `http://${this.buildUrl()}`; } + /** Get websocket url + port */ public getWebsocketUrl(): string { return `ws://${this.buildUrl()}`; diff --git a/project/src/helpers/InRaidHelper.ts b/project/src/helpers/InRaidHelper.ts index ec72147e..09d13d83 100644 --- a/project/src/helpers/InRaidHelper.ts +++ b/project/src/helpers/InRaidHelper.ts @@ -39,7 +39,7 @@ export class InRaidHelper } /** - * Should quest items be removed from player inventory on death + * Lookup quest item loss from lostOnDeath config * @returns True if items should be removed from inventory */ public removeQuestItemsOnDeath(): boolean diff --git a/project/src/helpers/InventoryHelper.ts b/project/src/helpers/InventoryHelper.ts index 52dd0137..39368612 100644 --- a/project/src/helpers/InventoryHelper.ts +++ b/project/src/helpers/InventoryHelper.ts @@ -203,11 +203,10 @@ export class InventoryHelper { return this.httpResponse.appendErrorToOutput(output, this.localisationService.getText("inventory-no_stash_space")); } - } } - // Successfully found slot for every item, run callback, catch if it fails (e.g. payMoney() might fail) + // Successfully found slot for every item (stash or sorting table), run callback, catch if it fails (e.g. payMoney() might fail) try { if (typeof callback === "function") @@ -217,6 +216,7 @@ export class InventoryHelper } catch (err) { + // Callback failed const message = typeof err === "string" ? err : this.localisationService.getText("http-unknown_error"); @@ -344,6 +344,7 @@ export class InventoryHelper { const itemLocation = {}; + // Item already has location property, use it if (itemLib[tmpKey]["location"] !== undefined) { itemLocation["location"] = itemLib[tmpKey]["location"];