diff --git a/project/src/generators/BotGenerator.ts b/project/src/generators/BotGenerator.ts index 67f2ecf7..02a8e8f9 100644 --- a/project/src/generators/BotGenerator.ts +++ b/project/src/generators/BotGenerator.ts @@ -4,9 +4,7 @@ import { BotDifficultyHelper } from "../helpers/BotDifficultyHelper"; import { BotHelper } from "../helpers/BotHelper"; import { ProfileHelper } from "../helpers/ProfileHelper"; import { WeightedRandomHelper } from "../helpers/WeightedRandomHelper"; -import { - Common, Health as PmcHealth, IBotBase, Info, Mastering, Skills -} from "../models/eft/common/tables/IBotBase"; +import { Health as PmcHealth, IBaseSkill, IBotBase, Info, Skills as botSkills } from "../models/eft/common/tables/IBotBase"; import { Health, IBotType } from "../models/eft/common/tables/IBotType"; import { Item, Upd } from "../models/eft/common/tables/IItem"; import { BaseClasses } from "../models/enums/BaseClasses"; @@ -197,7 +195,9 @@ export class BotGenerator return name; } - const pmcNames = [...this.databaseServer.getTables().bots.types["usec"].firstName, ...this.databaseServer.getTables().bots.types["bear"].firstName]; + const pmcNames = [ + ...this.databaseServer.getTables().bots.types["usec"].firstName, + ...this.databaseServer.getTables().bots.types["bear"].firstName]; return `${name} (${this.randomUtil.getArrayValue(pmcNames)})`; } @@ -295,47 +295,36 @@ export class BotGenerator return newHealth; } - protected generateSkills(skillsObj: Skills): Skills + /** + * Get a bots skills with randomsied progress value between the min and max values + * @param botSkills + * @returns + */ + protected generateSkills(botSkills: botSkills): botSkills { - const skills = []; - const masteries = []; - - // Skills - if (skillsObj.Common) - { - for (const skillId in skillsObj.Common) - { - const skill: Common = { - Id: skillId, - Progress: this.randomUtil.getInt(skillsObj.Common[skillId].min, skillsObj.Common[skillId].max) - }; - - skills.push(skill); - } - } - - // Masteries - if (skillsObj.Mastering) - { - for (const masteringId in skillsObj.Mastering) - { - const mastery: Mastering = { - Id: masteringId, - Progress: this.randomUtil.getInt(skillsObj.Mastering[masteringId].min, skillsObj.Mastering[masteringId].max) - }; - masteries.push(mastery); - } - } - - const skillsToReturn: Skills = { - Common: skills, - Mastering: masteries, + const skillsToReturn: botSkills = { + Common: this.getSkillsWithRandomisedProgressValue(botSkills.Common), + Mastering: this.getSkillsWithRandomisedProgressValue(botSkills.Mastering), Points: 0 }; return skillsToReturn; } + /** + * Randomise the progress value of passed in skills based on the min/max value + * @param skills Skills to randomise + * @returns Skills with randomised progress values as an array + */ + protected getSkillsWithRandomisedProgressValue(skills: IBaseSkill[]): IBaseSkill[] + { + // Create a new array of skills with randomised progress value + return skills.map((skill) => ({ + Id: skill.Id, + Progress: this.randomUtil.getInt(skill.min, skill.max) + })); + } + /** @@ -355,11 +344,11 @@ export class BotGenerator protected generateInventoryID(profile: IBotBase): IBotBase { const defaultInventory = "55d7217a4bdc2d86028b456d"; - const itemsByParentHash = {}; - const inventoryItemHash = {}; - let inventoryId = ""; - + const itemsByParentHash: Record = {}; + const inventoryItemHash: Record = {}; + // Generate inventoryItem list + let inventoryId = ""; for (const item of profile.Inventory.items) { inventoryItemHash[item._id] = item; diff --git a/project/src/models/eft/common/tables/IBotBase.ts b/project/src/models/eft/common/tables/IBotBase.ts index 76be8317..3d51cf90 100644 --- a/project/src/models/eft/common/tables/IBotBase.ts +++ b/project/src/models/eft/common/tables/IBotBase.ts @@ -157,24 +157,23 @@ export interface Skills Points: number } -export interface Common +export interface IBaseSkill { Id: string Progress: number - PointsEarnedDuringSession?: number - LastAccess?: number max?: number min?: number } -export interface Mastering +export interface Common extends IBaseSkill { - Id: string - Progress: number - max?: number - min?: number + PointsEarnedDuringSession?: number + LastAccess?: number } +export interface Mastering extends IBaseSkill +{} + export interface Stats { CarriedQuestItems: string[]