Comment improvements

This commit is contained in:
Dev 2023-07-24 15:52:55 +01:00
parent 5c6aafea51
commit ad576a937a
8 changed files with 120 additions and 51 deletions

View File

@ -58,8 +58,12 @@ export class LocationController
return this.generate(name); 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 location: ILocation = this.databaseServer.getTables().locations[name];
const output: ILocationBase = this.jsonUtil.clone(location.base); 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)); this.logger.success(this.localisationService.getText("location-containers_generated_success", staticContainerCount));
// dyanmic loot // Dyanmic loot
const dynamicLootDist: ILooseLoot = this.jsonUtil.clone(location.looseLoot); const dynamicLootDist: ILooseLoot = this.jsonUtil.clone(location.looseLoot);
const dynamicLoot: SpawnpointTemplate[] = this.locationGenerator.generateDynamicLoot(dynamicLootDist, staticAmmoDist, name); const dynamicLoot: SpawnpointTemplate[] = this.locationGenerator.generateDynamicLoot(dynamicLootDist, staticAmmoDist, name);
for (const dli of dynamicLoot) for (const dli of dynamicLoot)
@ -109,7 +113,7 @@ export class LocationController
output.Loot.push(dli); 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-dynamic_items_spawned_success", dynamicLoot.length));
this.logger.success(this.localisationService.getText("location-generated_success", name)); this.logger.success(this.localisationService.getText("location-generated_success", name));

View File

@ -18,44 +18,12 @@ export class FindSlotResult
@injectable() @injectable()
export class ContainerHelper export class ContainerHelper
{ {
protected locateSlot(container2D: number[][], containerX: number, containerY: number, x: number, y: number, itemW: number, itemH: number): boolean /**
{ * Finds a slot for an item in a given 2D container map
let foundSlot = true; * @param container2D Array of container with slots filled/free
* @param itemWidth Width of item
for (let itemY = 0; itemY < itemH; itemY++) * @param itemHeight Height of item
{ * @returns Location to place item in container
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 }
*/ */
public findSlotForItem(container2D: number[][], itemWidth: number, itemHeight: number): FindSlotResult public findSlotForItem(container2D: number[][], itemWidth: number, itemHeight: number): FindSlotResult
{ {
@ -98,6 +66,54 @@ export class ContainerHelper
return new FindSlotResult(); 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 * Find a free slot for an item to be placed at
* @param container2D Container to palce item in * @param container2D Container to palce item in

View File

@ -21,6 +21,12 @@ export class DurabilityLimitsHelper
this.botConfig = this.configServer.getConfig(ConfigTypes.BOT); 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 public getRandomizedMaxWeaponDurability(itemTemplate: ITemplateItem, botRole: string): number
{ {
if (botRole && this.botHelper.isBotPmc(botRole)) if (botRole && this.botHelper.isBotPmc(botRole))
@ -41,6 +47,12 @@ export class DurabilityLimitsHelper
return this.generateMaxWeaponDurability(botRole); 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 public getRandomizedMaxArmorDurability(itemTemplate: ITemplateItem, botRole: string): number
{ {
const itemMaxDurability = itemTemplate._props.MaxDurability; const itemMaxDurability = itemTemplate._props.MaxDurability;
@ -63,6 +75,13 @@ export class DurabilityLimitsHelper
return itemMaxDurability; 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 public getRandomizedWeaponDurability(itemTemplate: ITemplateItem, botRole: string, maxDurability: number): number
{ {
if (botRole && (this.botHelper.isBotPmc(botRole))) if (botRole && (this.botHelper.isBotPmc(botRole)))
@ -83,6 +102,13 @@ export class DurabilityLimitsHelper
return this.generateWeaponDurability(botRole, maxDurability); 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 public getRandomizedArmorDurability(itemTemplate: ITemplateItem, botRole: string, maxDurability: number): number
{ {
if (botRole && (this.botHelper.isBotPmc(botRole))) if (botRole && (this.botHelper.isBotPmc(botRole)))

View File

@ -36,6 +36,9 @@ export class HandbookHelper
constructor(@inject("DatabaseServer") protected databaseServer: DatabaseServer) constructor(@inject("DatabaseServer") protected databaseServer: DatabaseServer)
{} {}
/**
* Create an in-memory cache of all items with associated handbook price in handbookPriceCache class
*/
public hydrateLookup(): void public hydrateLookup(): void
{ {
const handbookDb = this.databaseServer.getTables().templates.handbook; const handbookDb = this.databaseServer.getTables().templates.handbook;
@ -94,13 +97,13 @@ export class HandbookHelper
} }
/** /**
* all items in template with the given parent category * Get all items in template with the given parent category
* @param x * @param parentId
* @returns string array * @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); 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) ?? [];
} }
/** /**

View File

@ -104,6 +104,11 @@ export class HideoutHelper
}; };
} }
/**
* Is the provided object a Production type
* @param productive
* @returns
*/
public isProductionType(productive: Productive): productive is Production public isProductionType(productive: Productive): productive is Production
{ {
return (productive as Production).Progress !== undefined || (productive as Production).RecipeId !== undefined; return (productive as Production).Progress !== undefined || (productive as Production).RecipeId !== undefined;

View File

@ -33,16 +33,25 @@ export class HttpServerHelper
return this.mime[key]; return this.mime[key];
} }
/**
* Combine ip and port into url
* @returns url
*/
public buildUrl(): string public buildUrl(): string
{ {
return `${this.httpConfig.ip}:${this.httpConfig.port}`; return `${this.httpConfig.ip}:${this.httpConfig.port}`;
} }
/**
* Prepend http to the url:port
* @returns URI
*/
public getBackendUrl(): string public getBackendUrl(): string
{ {
return `http://${this.buildUrl()}`; return `http://${this.buildUrl()}`;
} }
/** Get websocket url + port */
public getWebsocketUrl(): string public getWebsocketUrl(): string
{ {
return `ws://${this.buildUrl()}`; return `ws://${this.buildUrl()}`;

View File

@ -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 * @returns True if items should be removed from inventory
*/ */
public removeQuestItemsOnDeath(): boolean public removeQuestItemsOnDeath(): boolean

View File

@ -203,11 +203,10 @@ export class InventoryHelper
{ {
return this.httpResponse.appendErrorToOutput(output, this.localisationService.getText("inventory-no_stash_space")); 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 try
{ {
if (typeof callback === "function") if (typeof callback === "function")
@ -217,6 +216,7 @@ export class InventoryHelper
} }
catch (err) catch (err)
{ {
// Callback failed
const message = typeof err === "string" const message = typeof err === "string"
? err ? err
: this.localisationService.getText("http-unknown_error"); : this.localisationService.getText("http-unknown_error");
@ -344,6 +344,7 @@ export class InventoryHelper
{ {
const itemLocation = {}; const itemLocation = {};
// Item already has location property, use it
if (itemLib[tmpKey]["location"] !== undefined) if (itemLib[tmpKey]["location"] !== undefined)
{ {
itemLocation["location"] = itemLib[tmpKey]["location"]; itemLocation["location"] = itemLib[tmpKey]["location"];