Refactor: improve generateSkills() function
This commit is contained in:
parent
415b73d674
commit
a6838e9312
@ -4,9 +4,7 @@ import { BotDifficultyHelper } from "../helpers/BotDifficultyHelper";
|
|||||||
import { BotHelper } from "../helpers/BotHelper";
|
import { BotHelper } from "../helpers/BotHelper";
|
||||||
import { ProfileHelper } from "../helpers/ProfileHelper";
|
import { ProfileHelper } from "../helpers/ProfileHelper";
|
||||||
import { WeightedRandomHelper } from "../helpers/WeightedRandomHelper";
|
import { WeightedRandomHelper } from "../helpers/WeightedRandomHelper";
|
||||||
import {
|
import { Health as PmcHealth, IBaseSkill, IBotBase, Info, Skills as botSkills } from "../models/eft/common/tables/IBotBase";
|
||||||
Common, Health as PmcHealth, IBotBase, Info, Mastering, Skills
|
|
||||||
} from "../models/eft/common/tables/IBotBase";
|
|
||||||
import { Health, IBotType } from "../models/eft/common/tables/IBotType";
|
import { Health, IBotType } from "../models/eft/common/tables/IBotType";
|
||||||
import { Item, Upd } from "../models/eft/common/tables/IItem";
|
import { Item, Upd } from "../models/eft/common/tables/IItem";
|
||||||
import { BaseClasses } from "../models/enums/BaseClasses";
|
import { BaseClasses } from "../models/enums/BaseClasses";
|
||||||
@ -197,7 +195,9 @@ export class BotGenerator
|
|||||||
return name;
|
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)})`;
|
return `${name} (${this.randomUtil.getArrayValue(pmcNames)})`;
|
||||||
}
|
}
|
||||||
@ -295,47 +295,36 @@ export class BotGenerator
|
|||||||
return newHealth;
|
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 skillsToReturn: botSkills = {
|
||||||
const masteries = [];
|
Common: this.getSkillsWithRandomisedProgressValue(botSkills.Common),
|
||||||
|
Mastering: this.getSkillsWithRandomisedProgressValue(botSkills.Mastering),
|
||||||
// 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,
|
|
||||||
Points: 0
|
Points: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
return skillsToReturn;
|
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
|
protected generateInventoryID(profile: IBotBase): IBotBase
|
||||||
{
|
{
|
||||||
const defaultInventory = "55d7217a4bdc2d86028b456d";
|
const defaultInventory = "55d7217a4bdc2d86028b456d";
|
||||||
const itemsByParentHash = {};
|
const itemsByParentHash: Record<string, Item[]> = {};
|
||||||
const inventoryItemHash = {};
|
const inventoryItemHash: Record<string, Item> = {};
|
||||||
let inventoryId = "";
|
|
||||||
|
|
||||||
// Generate inventoryItem list
|
// Generate inventoryItem list
|
||||||
|
let inventoryId = "";
|
||||||
for (const item of profile.Inventory.items)
|
for (const item of profile.Inventory.items)
|
||||||
{
|
{
|
||||||
inventoryItemHash[item._id] = item;
|
inventoryItemHash[item._id] = item;
|
||||||
|
@ -157,24 +157,23 @@ export interface Skills
|
|||||||
Points: number
|
Points: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Common
|
export interface IBaseSkill
|
||||||
{
|
{
|
||||||
Id: string
|
Id: string
|
||||||
Progress: number
|
Progress: number
|
||||||
PointsEarnedDuringSession?: number
|
|
||||||
LastAccess?: number
|
|
||||||
max?: number
|
max?: number
|
||||||
min?: number
|
min?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Mastering
|
export interface Common extends IBaseSkill
|
||||||
{
|
{
|
||||||
Id: string
|
PointsEarnedDuringSession?: number
|
||||||
Progress: number
|
LastAccess?: number
|
||||||
max?: number
|
|
||||||
min?: number
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface Mastering extends IBaseSkill
|
||||||
|
{}
|
||||||
|
|
||||||
export interface Stats
|
export interface Stats
|
||||||
{
|
{
|
||||||
CarriedQuestItems: string[]
|
CarriedQuestItems: string[]
|
||||||
|
Loading…
Reference in New Issue
Block a user