diff --git a/TypeScript/10ScopesAndTypes/package.json b/TypeScript/10ScopesAndTypes/package.json index 4db1e0b..cf6dc45 100644 --- a/TypeScript/10ScopesAndTypes/package.json +++ b/TypeScript/10ScopesAndTypes/package.json @@ -4,7 +4,7 @@ "main": "src/mod.js", "license": "MIT", "author": "Chomp", - "akiVersion": "3.2.2", + "akiVersion": "3.2.3", "scripts": { "setup": "npm i", "build": "node ./packageBuild.ts" diff --git a/TypeScript/10ScopesAndTypes/types/generators/BotLootGenerator.d.ts b/TypeScript/10ScopesAndTypes/types/generators/BotLootGenerator.d.ts index 5a2d144..c1f5310 100644 --- a/TypeScript/10ScopesAndTypes/types/generators/BotLootGenerator.d.ts +++ b/TypeScript/10ScopesAndTypes/types/generators/BotLootGenerator.d.ts @@ -1,4 +1,5 @@ import { BotGeneratorHelper } from "../helpers/BotGeneratorHelper"; +import { BotWeaponGeneratorHelper } from "../helpers/BotWeaponGeneratorHelper"; import { HandbookHelper } from "../helpers/HandbookHelper"; import { Inventory as PmcInventory } from "../models/eft/common/tables/IBotBase"; import { Chances, Inventory, ItemMinMax, ModsChances } from "../models/eft/common/tables/IBotType"; @@ -20,10 +21,11 @@ export declare class BotLootGenerator { protected handbookHelper: HandbookHelper; protected botGeneratorHelper: BotGeneratorHelper; protected botWeaponGenerator: BotWeaponGenerator; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; protected botLootCacheService: BotLootCacheService; protected configServer: ConfigServer; protected botConfig: IBotConfig; - constructor(logger: ILogger, hashUtil: HashUtil, randomUtil: RandomUtil, databaseServer: DatabaseServer, handbookHelper: HandbookHelper, botGeneratorHelper: BotGeneratorHelper, botWeaponGenerator: BotWeaponGenerator, botLootCacheService: BotLootCacheService, configServer: ConfigServer); + constructor(logger: ILogger, hashUtil: HashUtil, randomUtil: RandomUtil, databaseServer: DatabaseServer, handbookHelper: HandbookHelper, botGeneratorHelper: BotGeneratorHelper, botWeaponGenerator: BotWeaponGenerator, botWeaponGeneratorHelper: BotWeaponGeneratorHelper, botLootCacheService: BotLootCacheService, configServer: ConfigServer); generateLoot(sessionId: string, templateInventory: Inventory, itemCounts: ItemMinMax, isPmc: boolean, botRole: string, botInventory: PmcInventory, equipmentChances: Chances): void; protected getRandomisedCount(min: number, max: number, nValue: number): number; /** diff --git a/TypeScript/10ScopesAndTypes/types/generators/BotWeaponGenerator.d.ts b/TypeScript/10ScopesAndTypes/types/generators/BotWeaponGenerator.d.ts index cba7afa..487901b 100644 --- a/TypeScript/10ScopesAndTypes/types/generators/BotWeaponGenerator.d.ts +++ b/TypeScript/10ScopesAndTypes/types/generators/BotWeaponGenerator.d.ts @@ -1,4 +1,5 @@ import { BotGeneratorHelper } from "../helpers/BotGeneratorHelper"; +import { BotWeaponGeneratorHelper } from "../helpers/BotWeaponGeneratorHelper"; import { ItemHelper } from "../helpers/ItemHelper"; import { WeightedRandomHelper } from "../helpers/WeightedRandomHelper"; import { MinMax } from "../models/common/MinMax"; @@ -14,6 +15,7 @@ import { DatabaseServer } from "../servers/DatabaseServer"; import { HashUtil } from "../utils/HashUtil"; import { JsonUtil } from "../utils/JsonUtil"; import { RandomUtil } from "../utils/RandomUtil"; +import { IInventoryMagGen } from "./weapongen/IInventoryMagGen"; export declare class BotWeaponGenerator { protected jsonUtil: JsonUtil; protected logger: ILogger; @@ -24,9 +26,11 @@ export declare class BotWeaponGenerator { protected botGeneratorHelper: BotGeneratorHelper; protected randomUtil: RandomUtil; protected configServer: ConfigServer; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + protected inventoryMagGenComponents: IInventoryMagGen[]; protected readonly modMagazineSlotId = "mod_magazine"; protected botConfig: IBotConfig; - constructor(jsonUtil: JsonUtil, logger: ILogger, hashUtil: HashUtil, databaseServer: DatabaseServer, itemHelper: ItemHelper, weightedRandomHelper: WeightedRandomHelper, botGeneratorHelper: BotGeneratorHelper, randomUtil: RandomUtil, configServer: ConfigServer); + constructor(jsonUtil: JsonUtil, logger: ILogger, hashUtil: HashUtil, databaseServer: DatabaseServer, itemHelper: ItemHelper, weightedRandomHelper: WeightedRandomHelper, botGeneratorHelper: BotGeneratorHelper, randomUtil: RandomUtil, configServer: ConfigServer, botWeaponGeneratorHelper: BotWeaponGeneratorHelper, inventoryMagGenComponents: IInventoryMagGen[]); /** * Pick a random weapon based on weightings and generate a functional weapon * @param equipmentSlot Primary/secondary/holster @@ -85,36 +89,12 @@ export declare class BotWeaponGenerator { /** * Generates extra magazines or bullets (if magazine is internal) and adds them to TacticalVest and Pockets. * Additionally, adds extra bullets to SecuredContainer - * @param weaponMods mods to attach to weapon - * @param weaponTemplate db template for weapon - * @param magCounts magazine count to add to inventory - * @param ammoTpl ammo templateId to add to magazines - * @param inventory inventory to add magazines to - * @param botRole the bot type we're getting generating extra mags for - * @returns + * @param generatedWeaponResult object with properties for generated weapon (weapon mods pool / weapon template / ammo tpl) + * @param magCounts Magazine count to add to inventory + * @param inventory Inventory to add magazines to + * @param botRole The bot type we're getting generating extra mags for */ - addExtraMagazinesToInventory(weaponMods: Item[], weaponTemplate: ITemplateItem, magCounts: MinMax, ammoTpl: string, inventory: PmcInventory, botRole: string): void; - /** - * Create a magazine using the parameters given - * @param magazineTpl Tpl of the magazine to create - * @param ammoTpl Ammo to add to magazine - * @param magTemplate template object of magazine - * @returns Item array - */ - protected createMagazine(magazineTpl: string, ammoTpl: string, magTemplate: ITemplateItem): Item[]; - /** - * Get a randomised number of bullets for a specific magazine - * @param magCounts min and max count of magazines - * @param magTemplate magazine to generate bullet count for - * @returns bullet count number - */ - protected getRandomisedBulletCount(magCounts: MinMax, magTemplate: ITemplateItem): number; - /** - * Get a randomised count of magazines - * @param magCounts min and max value returned value can be between - * @returns numberical value of magazine count - */ - protected getRandomisedMagazineCount(magCounts: MinMax): number; + addExtraMagazinesToInventory(generatedWeaponResult: GenerateWeaponResult, magCounts: MinMax, inventory: PmcInventory, botRole: string): void; /** * Add ammo to the secure container * @param stackCount How many stacks of ammo to add @@ -131,13 +111,6 @@ export declare class BotWeaponGenerator { * @returns magazine tpl string */ protected getMagazineTplFromWeaponTemplate(weaponMods: Item[], weaponTemplate: ITemplateItem, botRole: string): string; - /** - * Get a weapons default magazine template id - * @param weaponTemplate weapon to get default magazine for - * @returns tpl of magazine - */ - protected getWeaponsDefaultMagazineTpl(weaponTemplate: ITemplateItem): string; - protected addBulletsToVestAndPockets(ammoTpl: string, bulletCount: number, inventory: PmcInventory): void; /** * Finds and return a compatible ammo tpl based on the bots ammo weightings (x.json/inventory/equipment/ammo) * @param ammo a list of ammo tpls the weapon can use diff --git a/TypeScript/10ScopesAndTypes/types/generators/weapongen/IInventoryMagGen.d.ts b/TypeScript/10ScopesAndTypes/types/generators/weapongen/IInventoryMagGen.d.ts new file mode 100644 index 0000000..792f510 --- /dev/null +++ b/TypeScript/10ScopesAndTypes/types/generators/weapongen/IInventoryMagGen.d.ts @@ -0,0 +1,6 @@ +import { InventoryMagGen } from "./InventoryMagGen"; +export interface IInventoryMagGen { + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/10ScopesAndTypes/types/generators/weapongen/InventoryMagGen.d.ts b/TypeScript/10ScopesAndTypes/types/generators/weapongen/InventoryMagGen.d.ts new file mode 100644 index 0000000..30bf79f --- /dev/null +++ b/TypeScript/10ScopesAndTypes/types/generators/weapongen/InventoryMagGen.d.ts @@ -0,0 +1,16 @@ +import { MinMax } from "../../models/common/MinMax"; +import { Inventory } from "../../models/eft/common/tables/IBotBase"; +import { ITemplateItem } from "../../models/eft/common/tables/ITemplateItem"; +export declare class InventoryMagGen { + private magCounts; + private magazineTemplate; + private weaponTemplate; + private ammoTemplate; + private pmcInventory; + constructor(magCounts: MinMax, magazineTemplate: ITemplateItem, weaponTemplate: ITemplateItem, ammoTemplate: ITemplateItem, pmcInventory: Inventory); + getMagCount(): MinMax; + getMagazineTemplate(): ITemplateItem; + getWeaponTemplate(): ITemplateItem; + getAmmoTemplate(): ITemplateItem; + getPmcInventory(): Inventory; +} diff --git a/TypeScript/10ScopesAndTypes/types/generators/weapongen/implementations/BarrelInventoryMagGen.d.ts b/TypeScript/10ScopesAndTypes/types/generators/weapongen/implementations/BarrelInventoryMagGen.d.ts new file mode 100644 index 0000000..b754d5f --- /dev/null +++ b/TypeScript/10ScopesAndTypes/types/generators/weapongen/implementations/BarrelInventoryMagGen.d.ts @@ -0,0 +1,12 @@ +import { BotWeaponGeneratorHelper } from "../../../helpers/BotWeaponGeneratorHelper"; +import { RandomUtil } from "../../../utils/RandomUtil"; +import { IInventoryMagGen } from "../IInventoryMagGen"; +import { InventoryMagGen } from "../InventoryMagGen"; +export declare class BarrelInventoryMagGen implements IInventoryMagGen { + protected randomUtil: RandomUtil; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + constructor(randomUtil: RandomUtil, botWeaponGeneratorHelper: BotWeaponGeneratorHelper); + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/10ScopesAndTypes/types/generators/weapongen/implementations/ExternalInventoryMagGen.d.ts b/TypeScript/10ScopesAndTypes/types/generators/weapongen/implementations/ExternalInventoryMagGen.d.ts new file mode 100644 index 0000000..4fcb1e2 --- /dev/null +++ b/TypeScript/10ScopesAndTypes/types/generators/weapongen/implementations/ExternalInventoryMagGen.d.ts @@ -0,0 +1,14 @@ +import { BotWeaponGeneratorHelper } from "../../../helpers/BotWeaponGeneratorHelper"; +import { ItemHelper } from "../../../helpers/ItemHelper"; +import { ILogger } from "../../../models/spt/utils/ILogger"; +import { IInventoryMagGen } from "../IInventoryMagGen"; +import { InventoryMagGen } from "../InventoryMagGen"; +export declare class ExternalInventoryMagGen implements IInventoryMagGen { + protected logger: ILogger; + protected itemHelper: ItemHelper; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + constructor(logger: ILogger, itemHelper: ItemHelper, botWeaponGeneratorHelper: BotWeaponGeneratorHelper); + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/10ScopesAndTypes/types/generators/weapongen/implementations/InternalMagazineInventoryMagGen.d.ts b/TypeScript/10ScopesAndTypes/types/generators/weapongen/implementations/InternalMagazineInventoryMagGen.d.ts new file mode 100644 index 0000000..4548a04 --- /dev/null +++ b/TypeScript/10ScopesAndTypes/types/generators/weapongen/implementations/InternalMagazineInventoryMagGen.d.ts @@ -0,0 +1,10 @@ +import { BotWeaponGeneratorHelper } from "../../../helpers/BotWeaponGeneratorHelper"; +import { IInventoryMagGen } from "../IInventoryMagGen"; +import { InventoryMagGen } from "../InventoryMagGen"; +export declare class InternalMagazineInventoryMagGen implements IInventoryMagGen { + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + constructor(botWeaponGeneratorHelper: BotWeaponGeneratorHelper); + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/10ScopesAndTypes/types/helpers/BotGeneratorHelper.d.ts b/TypeScript/10ScopesAndTypes/types/helpers/BotGeneratorHelper.d.ts index 09e5c8f..5e3e501 100644 --- a/TypeScript/10ScopesAndTypes/types/helpers/BotGeneratorHelper.d.ts +++ b/TypeScript/10ScopesAndTypes/types/helpers/BotGeneratorHelper.d.ts @@ -1,8 +1,7 @@ import { DurabilityLimitsHelper } from "../helpers/DurabilityLimitsHelper"; -import { Inventory as PmcInventory } from "../models/eft/common/tables/IBotBase"; import { Mods, ModsChances } from "../models/eft/common/tables/IBotType"; import { Item, Repairable, Upd } from "../models/eft/common/tables/IItem"; -import { Grid, ITemplateItem, Slot } from "../models/eft/common/tables/ITemplateItem"; +import { ITemplateItem, Slot } from "../models/eft/common/tables/ITemplateItem"; import { EquipmentFilterDetails, IBotConfig } from "../models/spt/config/IBotConfig"; import { ILogger } from "../models/spt/utils/ILogger"; import { ConfigServer } from "../servers/ConfigServer"; @@ -12,6 +11,7 @@ import { ItemFilterService } from "../services/ItemFilterService"; import { HashUtil } from "../utils/HashUtil"; import { JsonUtil } from "../utils/JsonUtil"; import { RandomUtil } from "../utils/RandomUtil"; +import { BotWeaponGeneratorHelper } from "./BotWeaponGeneratorHelper"; import { ContainerHelper } from "./ContainerHelper"; import { InventoryHelper } from "./InventoryHelper"; import { ItemHelper } from "./ItemHelper"; @@ -42,11 +42,11 @@ export declare class BotGeneratorHelper { protected botEquipmentFilterService: BotEquipmentFilterService; protected itemFilterService: ItemFilterService; protected profileHelper: ProfileHelper; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; protected configServer: ConfigServer; protected botConfig: IBotConfig; - constructor(logger: ILogger, jsonUtil: JsonUtil, hashUtil: HashUtil, randomUtil: RandomUtil, probabilityHelper: ProbabilityHelper, databaseServer: DatabaseServer, durabilityLimitsHelper: DurabilityLimitsHelper, itemHelper: ItemHelper, inventoryHelper: InventoryHelper, containerHelper: ContainerHelper, botEquipmentFilterService: BotEquipmentFilterService, itemFilterService: ItemFilterService, profileHelper: ProfileHelper, configServer: ConfigServer); + constructor(logger: ILogger, jsonUtil: JsonUtil, hashUtil: HashUtil, randomUtil: RandomUtil, probabilityHelper: ProbabilityHelper, databaseServer: DatabaseServer, durabilityLimitsHelper: DurabilityLimitsHelper, itemHelper: ItemHelper, inventoryHelper: InventoryHelper, containerHelper: ContainerHelper, botEquipmentFilterService: BotEquipmentFilterService, itemFilterService: ItemFilterService, profileHelper: ProfileHelper, botWeaponGeneratorHelper: BotWeaponGeneratorHelper, configServer: ConfigServer); /** - * TODO - very similar to generateModsForWeapon * Check mods are compatible and add to array * @param equipment Equipment item to add mods to * @param modPool Mod list to choose frm @@ -57,18 +57,30 @@ export declare class BotGeneratorHelper { */ generateModsForEquipment(equipment: Item[], modPool: Mods, parentId: string, parentTemplate: ITemplateItem, modSpawnChances: ModsChances): Item[]; /** - * TODO - very similar to generateModsForEquipment * @param sessionId session id * @param weapon Weapon to add mods to - * @param modPool pool of compatible mods to attach to gun + * @param modPool Pool of compatible mods to attach to weapon * @param weaponParentId parentId of weapon - * @param parentTemplate - * @param modSpawnChances - * @param ammoTpl ammo tpl to use when generating magazines/cartridges - * @param botRole role of bot weapon is generated for - * @returns Weapon with mods + * @param parentWeaponTemplate Weapon which mods will be generated on + * @param modSpawnChances Mod spawn chances + * @param ammoTpl Ammo tpl to use when generating magazines/cartridges + * @param botRole Role of bot weapon is generated for + * @returns Weapon + mods array */ - generateModsForWeapon(sessionId: string, weapon: Item[], modPool: Mods, weaponParentId: string, parentTemplate: ITemplateItem, modSpawnChances: ModsChances, ammoTpl: string, botRole: string): Item[]; + generateModsForWeapon(sessionId: string, weapon: Item[], modPool: Mods, weaponParentId: string, parentWeaponTemplate: ITemplateItem, modSpawnChances: ModsChances, ammoTpl: string, botRole: string): Item[]; + /** + * + * @param modSlot + * @param isRandomisableSlot + * @param modsParent + * @param botEquipBlacklist + * @param itemModPool + * @param weapon array with only weapon tpl in it, ready for mods to be added + * @param ammoTpl ammo tpl to use if slot requires a cartridge to be added (e.g. mod_magazine) + * @param parentTemplate + * @returns + */ + protected chooseModToPutIntoSlot(modSlot: string, isRandomisableSlot: boolean, modsParent: Slot, botEquipBlacklist: EquipmentFilterDetails, itemModPool: Record, weapon: Item[], ammoTpl: string, parentTemplate: ITemplateItem): [boolean, ITemplateItem]; /** * Find mod tpls of a provided type and add to modPool * @param desiredSlotName slot to look up and add we are adding tpls for (e.g mod_scope) @@ -79,15 +91,15 @@ export declare class BotGeneratorHelper { /** * Check if mod item is on limited list + has surpassed the limit set for it * @param botRole role the bot has e.g. assault - * @param modTpl mods tpl + * @param modTemplate mods template data * @param modLimits limits set for weapon being generated for this bot * @returns true if over item limit */ - protected modHasReachedItemLimit(botRole: string, modTpl: string, modLimits: BotModLimits): boolean; + protected modHasReachedItemLimit(botRole: string, modTemplate: ITemplateItem, modLimits: BotModLimits): boolean; /** - * Initalise mod limits to be used when generating the weapon + * Initalise mod limits to be used when generating a weapon * @param botRole "assault", "bossTagilla" or "pmc" - * @returns + * @returns BotModLimits object */ protected initModLimits(botRole: string): BotModLimits; /** @@ -114,7 +126,7 @@ export declare class BotGeneratorHelper { protected filterWeaponModsByBlacklist(allowedMods: string[], botEquipBlacklist: EquipmentFilterDetails, modSlot: string): string[]; /** * Check if the specific item type on the weapon has reached the set limit - * @param modTpl item to check is limited + * @param modTpl log mod tpl if over type limit * @param currentCount current number of this item on gun * @param maxLimit mod limit allowed * @param botRole role of bot we're checking weapon of @@ -124,16 +136,14 @@ export declare class BotGeneratorHelper { count: number; }, maxLimit: number, botRole: string): boolean; /** - * log errors if mod is not valid for a slot - * @param modTpl - * @param found - * @param itemSlot - * @param modTemplate - * @param modSlot - * @param parentTemplate + * Log errors if mod is not compatible with slot + * @param modToAdd template of mod to check + * @param itemSlot slot the item will be placed in + * @param modSlot slot the mod will fill + * @param parentTemplate tempalte of the mods parent item * @returns true if valid */ - protected isModValidForSlot(modTpl: string, found: boolean, itemSlot: Slot, modTemplate: ITemplateItem, modSlot: string, parentTemplate: ITemplateItem): boolean; + protected isModValidForSlot(modToAdd: [boolean, ITemplateItem], itemSlot: Slot, modSlot: string, parentTemplate: ITemplateItem): boolean; /** * Create a mod item with parameters as properties * @param modId _id @@ -144,12 +154,6 @@ export declare class BotGeneratorHelper { * @returns Item object */ protected createModItem(modId: string, modTpl: string, parentId: string, modSlot: string, modTemplate: ITemplateItem): Item; - /** - * Is this magazine cylinder related (revolvers and grenade launchers) - * @param magazineParentName the name of the magazines parent - * @returns true if it is cylinder related - */ - magazineIsCylinderRelated(magazineParentName: string): boolean; /** * randomly choose if a mod should be spawned, 100% for required mods OR mod is ammo slot * never return true for an item that has 0% spawn chance @@ -161,7 +165,7 @@ export declare class BotGeneratorHelper { protected shouldModBeSpawned(itemSlot: Slot, modSlot: string, modSpawnChances: ModsChances): boolean; /** * Get a list of containers that hold ammo - * e.g. mod_magazine + * e.g. mod_magazine / patron_in_weapon_000 * @returns string array */ protected getAmmoContainers(): string[]; @@ -214,6 +218,14 @@ export declare class BotGeneratorHelper { * @returns Repairable object */ protected generateArmorRepairableProperties(itemTemplate: ITemplateItem, botRole: string): Repairable; + /** + * Get a random mod from an items compatible mods Filter array + * @param modTpl + * @param parentSlot + * @param modSlot + * @param items + * @returns item tpl + */ protected getModTplFromItemDb(modTpl: string, parentSlot: Slot, modSlot: string, items: Item[]): string; /** * Can an item be added to an item without issue @@ -223,23 +235,6 @@ export declare class BotGeneratorHelper { * @returns true if possible */ isItemIncompatibleWithCurrentItems(items: Item[], tplToCheck: string, equipmentSlot: string): boolean; - /** - * Adds an item with all its childern into specified equipmentSlots, wherever it fits. - * @param equipmentSlots - * @param parentId - * @param parentTpl - * @param itemWithChildren - * @param inventory - * @returns a `boolean` indicating item was added - */ - addItemWithChildrenToEquipmentSlot(equipmentSlots: string[], parentId: string, parentTpl: string, itemWithChildren: Item[], inventory: PmcInventory): boolean; - /** - * is the provided item allowed inside a container - * @param slot location item wants to be placed in - * @param itemTpl item being placed - * @returns true if allowed - */ - protected itemAllowedInContainer(slot: Grid, itemTpl: string): boolean; } /** TODO - move into own class */ export declare class ExhaustableArray { diff --git a/TypeScript/10ScopesAndTypes/types/helpers/BotWeaponGeneratorHelper.d.ts b/TypeScript/10ScopesAndTypes/types/helpers/BotWeaponGeneratorHelper.d.ts new file mode 100644 index 0000000..7e25f56 --- /dev/null +++ b/TypeScript/10ScopesAndTypes/types/helpers/BotWeaponGeneratorHelper.d.ts @@ -0,0 +1,78 @@ +import { MinMax } from "../models/common/MinMax"; +import { Inventory } from "../models/eft/common/tables/IBotBase"; +import { Item } from "../models/eft/common/tables/IItem"; +import { Grid, ITemplateItem } from "../models/eft/common/tables/ITemplateItem"; +import { ILogger } from "../models/spt/utils/ILogger"; +import { DatabaseServer } from "../servers/DatabaseServer"; +import { HashUtil } from "../utils/HashUtil"; +import { RandomUtil } from "../utils/RandomUtil"; +import { ContainerHelper } from "./ContainerHelper"; +import { InventoryHelper } from "./InventoryHelper"; +import { ItemHelper } from "./ItemHelper"; +export declare class BotWeaponGeneratorHelper { + protected logger: ILogger; + protected databaseServer: DatabaseServer; + protected itemHelper: ItemHelper; + protected randomUtil: RandomUtil; + protected hashUtil: HashUtil; + protected inventoryHelper: InventoryHelper; + protected containerHelper: ContainerHelper; + constructor(logger: ILogger, databaseServer: DatabaseServer, itemHelper: ItemHelper, randomUtil: RandomUtil, hashUtil: HashUtil, inventoryHelper: InventoryHelper, containerHelper: ContainerHelper); + /** + * Get a randomised number of bullets for a specific magazine + * @param magCounts min and max count of magazines + * @param magTemplate magazine to generate bullet count for + * @returns bullet count number + */ + getRandomisedBulletCount(magCounts: MinMax, magTemplate: ITemplateItem): number; + /** + * Get a randomised count of magazines + * @param magCounts min and max value returned value can be between + * @returns numberical value of magazine count + */ + getRandomisedMagazineCount(magCounts: MinMax): number; + /** + * Is this magazine cylinder related (revolvers and grenade launchers) + * @param magazineParentName the name of the magazines parent + * @returns true if it is cylinder related + */ + magazineIsCylinderRelated(magazineParentName: string): boolean; + /** + * Create a magazine using the parameters given + * @param magazineTpl Tpl of the magazine to create + * @param ammoTpl Ammo to add to magazine + * @param magTemplate template object of magazine + * @returns Item array + */ + createMagazine(magazineTpl: string, ammoTpl: string, magTemplate: ITemplateItem): Item[]; + /** + * Add a specific number of cartrdiges to a bots inventory (vest/pocket) + * @param ammoTpl Ammo tpl to add to vest/pockets + * @param cartridgeCount number of cartridges to add to vest/pockets + * @param inventory bot inventory to add cartridges to + */ + addBulletsToVestAndPockets(ammoTpl: string, cartridgeCount: number, inventory: Inventory): void; + /** + * Get a weapons default magazine template id + * @param weaponTemplate weapon to get default magazine for + * @returns tpl of magazine + */ + getWeaponsDefaultMagazineTpl(weaponTemplate: ITemplateItem): string; + /** + * Adds an item with all its childern into specified equipmentSlots, wherever it fits. + * @param equipmentSlots + * @param parentId + * @param parentTpl + * @param itemWithChildren + * @param inventory + * @returns a `boolean` indicating item was added + */ + addItemWithChildrenToEquipmentSlot(equipmentSlots: string[], parentId: string, parentTpl: string, itemWithChildren: Item[], inventory: Inventory): boolean; + /** + * is the provided item allowed inside a container + * @param slot location item wants to be placed in + * @param itemTpl item being placed + * @returns true if allowed + */ + protected itemAllowedInContainer(slot: Grid, itemTpl: string): boolean; +} diff --git a/TypeScript/11BundleLoadingSample/package.json b/TypeScript/11BundleLoadingSample/package.json index c7c208b..cb06192 100644 --- a/TypeScript/11BundleLoadingSample/package.json +++ b/TypeScript/11BundleLoadingSample/package.json @@ -4,7 +4,7 @@ "author": "Chomp", "license": "MIT", "main": "src/mod.js", - "akiVersion": "3.2.2", + "akiVersion": "3.2.3", "isBundleMod": true, "scripts": { "setup": "npm i", diff --git a/TypeScript/11BundleLoadingSample/types/generators/BotLootGenerator.d.ts b/TypeScript/11BundleLoadingSample/types/generators/BotLootGenerator.d.ts index 5a2d144..c1f5310 100644 --- a/TypeScript/11BundleLoadingSample/types/generators/BotLootGenerator.d.ts +++ b/TypeScript/11BundleLoadingSample/types/generators/BotLootGenerator.d.ts @@ -1,4 +1,5 @@ import { BotGeneratorHelper } from "../helpers/BotGeneratorHelper"; +import { BotWeaponGeneratorHelper } from "../helpers/BotWeaponGeneratorHelper"; import { HandbookHelper } from "../helpers/HandbookHelper"; import { Inventory as PmcInventory } from "../models/eft/common/tables/IBotBase"; import { Chances, Inventory, ItemMinMax, ModsChances } from "../models/eft/common/tables/IBotType"; @@ -20,10 +21,11 @@ export declare class BotLootGenerator { protected handbookHelper: HandbookHelper; protected botGeneratorHelper: BotGeneratorHelper; protected botWeaponGenerator: BotWeaponGenerator; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; protected botLootCacheService: BotLootCacheService; protected configServer: ConfigServer; protected botConfig: IBotConfig; - constructor(logger: ILogger, hashUtil: HashUtil, randomUtil: RandomUtil, databaseServer: DatabaseServer, handbookHelper: HandbookHelper, botGeneratorHelper: BotGeneratorHelper, botWeaponGenerator: BotWeaponGenerator, botLootCacheService: BotLootCacheService, configServer: ConfigServer); + constructor(logger: ILogger, hashUtil: HashUtil, randomUtil: RandomUtil, databaseServer: DatabaseServer, handbookHelper: HandbookHelper, botGeneratorHelper: BotGeneratorHelper, botWeaponGenerator: BotWeaponGenerator, botWeaponGeneratorHelper: BotWeaponGeneratorHelper, botLootCacheService: BotLootCacheService, configServer: ConfigServer); generateLoot(sessionId: string, templateInventory: Inventory, itemCounts: ItemMinMax, isPmc: boolean, botRole: string, botInventory: PmcInventory, equipmentChances: Chances): void; protected getRandomisedCount(min: number, max: number, nValue: number): number; /** diff --git a/TypeScript/11BundleLoadingSample/types/generators/BotWeaponGenerator.d.ts b/TypeScript/11BundleLoadingSample/types/generators/BotWeaponGenerator.d.ts index cba7afa..487901b 100644 --- a/TypeScript/11BundleLoadingSample/types/generators/BotWeaponGenerator.d.ts +++ b/TypeScript/11BundleLoadingSample/types/generators/BotWeaponGenerator.d.ts @@ -1,4 +1,5 @@ import { BotGeneratorHelper } from "../helpers/BotGeneratorHelper"; +import { BotWeaponGeneratorHelper } from "../helpers/BotWeaponGeneratorHelper"; import { ItemHelper } from "../helpers/ItemHelper"; import { WeightedRandomHelper } from "../helpers/WeightedRandomHelper"; import { MinMax } from "../models/common/MinMax"; @@ -14,6 +15,7 @@ import { DatabaseServer } from "../servers/DatabaseServer"; import { HashUtil } from "../utils/HashUtil"; import { JsonUtil } from "../utils/JsonUtil"; import { RandomUtil } from "../utils/RandomUtil"; +import { IInventoryMagGen } from "./weapongen/IInventoryMagGen"; export declare class BotWeaponGenerator { protected jsonUtil: JsonUtil; protected logger: ILogger; @@ -24,9 +26,11 @@ export declare class BotWeaponGenerator { protected botGeneratorHelper: BotGeneratorHelper; protected randomUtil: RandomUtil; protected configServer: ConfigServer; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + protected inventoryMagGenComponents: IInventoryMagGen[]; protected readonly modMagazineSlotId = "mod_magazine"; protected botConfig: IBotConfig; - constructor(jsonUtil: JsonUtil, logger: ILogger, hashUtil: HashUtil, databaseServer: DatabaseServer, itemHelper: ItemHelper, weightedRandomHelper: WeightedRandomHelper, botGeneratorHelper: BotGeneratorHelper, randomUtil: RandomUtil, configServer: ConfigServer); + constructor(jsonUtil: JsonUtil, logger: ILogger, hashUtil: HashUtil, databaseServer: DatabaseServer, itemHelper: ItemHelper, weightedRandomHelper: WeightedRandomHelper, botGeneratorHelper: BotGeneratorHelper, randomUtil: RandomUtil, configServer: ConfigServer, botWeaponGeneratorHelper: BotWeaponGeneratorHelper, inventoryMagGenComponents: IInventoryMagGen[]); /** * Pick a random weapon based on weightings and generate a functional weapon * @param equipmentSlot Primary/secondary/holster @@ -85,36 +89,12 @@ export declare class BotWeaponGenerator { /** * Generates extra magazines or bullets (if magazine is internal) and adds them to TacticalVest and Pockets. * Additionally, adds extra bullets to SecuredContainer - * @param weaponMods mods to attach to weapon - * @param weaponTemplate db template for weapon - * @param magCounts magazine count to add to inventory - * @param ammoTpl ammo templateId to add to magazines - * @param inventory inventory to add magazines to - * @param botRole the bot type we're getting generating extra mags for - * @returns + * @param generatedWeaponResult object with properties for generated weapon (weapon mods pool / weapon template / ammo tpl) + * @param magCounts Magazine count to add to inventory + * @param inventory Inventory to add magazines to + * @param botRole The bot type we're getting generating extra mags for */ - addExtraMagazinesToInventory(weaponMods: Item[], weaponTemplate: ITemplateItem, magCounts: MinMax, ammoTpl: string, inventory: PmcInventory, botRole: string): void; - /** - * Create a magazine using the parameters given - * @param magazineTpl Tpl of the magazine to create - * @param ammoTpl Ammo to add to magazine - * @param magTemplate template object of magazine - * @returns Item array - */ - protected createMagazine(magazineTpl: string, ammoTpl: string, magTemplate: ITemplateItem): Item[]; - /** - * Get a randomised number of bullets for a specific magazine - * @param magCounts min and max count of magazines - * @param magTemplate magazine to generate bullet count for - * @returns bullet count number - */ - protected getRandomisedBulletCount(magCounts: MinMax, magTemplate: ITemplateItem): number; - /** - * Get a randomised count of magazines - * @param magCounts min and max value returned value can be between - * @returns numberical value of magazine count - */ - protected getRandomisedMagazineCount(magCounts: MinMax): number; + addExtraMagazinesToInventory(generatedWeaponResult: GenerateWeaponResult, magCounts: MinMax, inventory: PmcInventory, botRole: string): void; /** * Add ammo to the secure container * @param stackCount How many stacks of ammo to add @@ -131,13 +111,6 @@ export declare class BotWeaponGenerator { * @returns magazine tpl string */ protected getMagazineTplFromWeaponTemplate(weaponMods: Item[], weaponTemplate: ITemplateItem, botRole: string): string; - /** - * Get a weapons default magazine template id - * @param weaponTemplate weapon to get default magazine for - * @returns tpl of magazine - */ - protected getWeaponsDefaultMagazineTpl(weaponTemplate: ITemplateItem): string; - protected addBulletsToVestAndPockets(ammoTpl: string, bulletCount: number, inventory: PmcInventory): void; /** * Finds and return a compatible ammo tpl based on the bots ammo weightings (x.json/inventory/equipment/ammo) * @param ammo a list of ammo tpls the weapon can use diff --git a/TypeScript/11BundleLoadingSample/types/generators/weapongen/IInventoryMagGen.d.ts b/TypeScript/11BundleLoadingSample/types/generators/weapongen/IInventoryMagGen.d.ts new file mode 100644 index 0000000..792f510 --- /dev/null +++ b/TypeScript/11BundleLoadingSample/types/generators/weapongen/IInventoryMagGen.d.ts @@ -0,0 +1,6 @@ +import { InventoryMagGen } from "./InventoryMagGen"; +export interface IInventoryMagGen { + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/11BundleLoadingSample/types/generators/weapongen/InventoryMagGen.d.ts b/TypeScript/11BundleLoadingSample/types/generators/weapongen/InventoryMagGen.d.ts new file mode 100644 index 0000000..30bf79f --- /dev/null +++ b/TypeScript/11BundleLoadingSample/types/generators/weapongen/InventoryMagGen.d.ts @@ -0,0 +1,16 @@ +import { MinMax } from "../../models/common/MinMax"; +import { Inventory } from "../../models/eft/common/tables/IBotBase"; +import { ITemplateItem } from "../../models/eft/common/tables/ITemplateItem"; +export declare class InventoryMagGen { + private magCounts; + private magazineTemplate; + private weaponTemplate; + private ammoTemplate; + private pmcInventory; + constructor(magCounts: MinMax, magazineTemplate: ITemplateItem, weaponTemplate: ITemplateItem, ammoTemplate: ITemplateItem, pmcInventory: Inventory); + getMagCount(): MinMax; + getMagazineTemplate(): ITemplateItem; + getWeaponTemplate(): ITemplateItem; + getAmmoTemplate(): ITemplateItem; + getPmcInventory(): Inventory; +} diff --git a/TypeScript/11BundleLoadingSample/types/generators/weapongen/implementations/BarrelInventoryMagGen.d.ts b/TypeScript/11BundleLoadingSample/types/generators/weapongen/implementations/BarrelInventoryMagGen.d.ts new file mode 100644 index 0000000..b754d5f --- /dev/null +++ b/TypeScript/11BundleLoadingSample/types/generators/weapongen/implementations/BarrelInventoryMagGen.d.ts @@ -0,0 +1,12 @@ +import { BotWeaponGeneratorHelper } from "../../../helpers/BotWeaponGeneratorHelper"; +import { RandomUtil } from "../../../utils/RandomUtil"; +import { IInventoryMagGen } from "../IInventoryMagGen"; +import { InventoryMagGen } from "../InventoryMagGen"; +export declare class BarrelInventoryMagGen implements IInventoryMagGen { + protected randomUtil: RandomUtil; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + constructor(randomUtil: RandomUtil, botWeaponGeneratorHelper: BotWeaponGeneratorHelper); + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/11BundleLoadingSample/types/generators/weapongen/implementations/ExternalInventoryMagGen.d.ts b/TypeScript/11BundleLoadingSample/types/generators/weapongen/implementations/ExternalInventoryMagGen.d.ts new file mode 100644 index 0000000..4fcb1e2 --- /dev/null +++ b/TypeScript/11BundleLoadingSample/types/generators/weapongen/implementations/ExternalInventoryMagGen.d.ts @@ -0,0 +1,14 @@ +import { BotWeaponGeneratorHelper } from "../../../helpers/BotWeaponGeneratorHelper"; +import { ItemHelper } from "../../../helpers/ItemHelper"; +import { ILogger } from "../../../models/spt/utils/ILogger"; +import { IInventoryMagGen } from "../IInventoryMagGen"; +import { InventoryMagGen } from "../InventoryMagGen"; +export declare class ExternalInventoryMagGen implements IInventoryMagGen { + protected logger: ILogger; + protected itemHelper: ItemHelper; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + constructor(logger: ILogger, itemHelper: ItemHelper, botWeaponGeneratorHelper: BotWeaponGeneratorHelper); + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/11BundleLoadingSample/types/generators/weapongen/implementations/InternalMagazineInventoryMagGen.d.ts b/TypeScript/11BundleLoadingSample/types/generators/weapongen/implementations/InternalMagazineInventoryMagGen.d.ts new file mode 100644 index 0000000..4548a04 --- /dev/null +++ b/TypeScript/11BundleLoadingSample/types/generators/weapongen/implementations/InternalMagazineInventoryMagGen.d.ts @@ -0,0 +1,10 @@ +import { BotWeaponGeneratorHelper } from "../../../helpers/BotWeaponGeneratorHelper"; +import { IInventoryMagGen } from "../IInventoryMagGen"; +import { InventoryMagGen } from "../InventoryMagGen"; +export declare class InternalMagazineInventoryMagGen implements IInventoryMagGen { + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + constructor(botWeaponGeneratorHelper: BotWeaponGeneratorHelper); + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/11BundleLoadingSample/types/helpers/BotGeneratorHelper.d.ts b/TypeScript/11BundleLoadingSample/types/helpers/BotGeneratorHelper.d.ts index 09e5c8f..5e3e501 100644 --- a/TypeScript/11BundleLoadingSample/types/helpers/BotGeneratorHelper.d.ts +++ b/TypeScript/11BundleLoadingSample/types/helpers/BotGeneratorHelper.d.ts @@ -1,8 +1,7 @@ import { DurabilityLimitsHelper } from "../helpers/DurabilityLimitsHelper"; -import { Inventory as PmcInventory } from "../models/eft/common/tables/IBotBase"; import { Mods, ModsChances } from "../models/eft/common/tables/IBotType"; import { Item, Repairable, Upd } from "../models/eft/common/tables/IItem"; -import { Grid, ITemplateItem, Slot } from "../models/eft/common/tables/ITemplateItem"; +import { ITemplateItem, Slot } from "../models/eft/common/tables/ITemplateItem"; import { EquipmentFilterDetails, IBotConfig } from "../models/spt/config/IBotConfig"; import { ILogger } from "../models/spt/utils/ILogger"; import { ConfigServer } from "../servers/ConfigServer"; @@ -12,6 +11,7 @@ import { ItemFilterService } from "../services/ItemFilterService"; import { HashUtil } from "../utils/HashUtil"; import { JsonUtil } from "../utils/JsonUtil"; import { RandomUtil } from "../utils/RandomUtil"; +import { BotWeaponGeneratorHelper } from "./BotWeaponGeneratorHelper"; import { ContainerHelper } from "./ContainerHelper"; import { InventoryHelper } from "./InventoryHelper"; import { ItemHelper } from "./ItemHelper"; @@ -42,11 +42,11 @@ export declare class BotGeneratorHelper { protected botEquipmentFilterService: BotEquipmentFilterService; protected itemFilterService: ItemFilterService; protected profileHelper: ProfileHelper; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; protected configServer: ConfigServer; protected botConfig: IBotConfig; - constructor(logger: ILogger, jsonUtil: JsonUtil, hashUtil: HashUtil, randomUtil: RandomUtil, probabilityHelper: ProbabilityHelper, databaseServer: DatabaseServer, durabilityLimitsHelper: DurabilityLimitsHelper, itemHelper: ItemHelper, inventoryHelper: InventoryHelper, containerHelper: ContainerHelper, botEquipmentFilterService: BotEquipmentFilterService, itemFilterService: ItemFilterService, profileHelper: ProfileHelper, configServer: ConfigServer); + constructor(logger: ILogger, jsonUtil: JsonUtil, hashUtil: HashUtil, randomUtil: RandomUtil, probabilityHelper: ProbabilityHelper, databaseServer: DatabaseServer, durabilityLimitsHelper: DurabilityLimitsHelper, itemHelper: ItemHelper, inventoryHelper: InventoryHelper, containerHelper: ContainerHelper, botEquipmentFilterService: BotEquipmentFilterService, itemFilterService: ItemFilterService, profileHelper: ProfileHelper, botWeaponGeneratorHelper: BotWeaponGeneratorHelper, configServer: ConfigServer); /** - * TODO - very similar to generateModsForWeapon * Check mods are compatible and add to array * @param equipment Equipment item to add mods to * @param modPool Mod list to choose frm @@ -57,18 +57,30 @@ export declare class BotGeneratorHelper { */ generateModsForEquipment(equipment: Item[], modPool: Mods, parentId: string, parentTemplate: ITemplateItem, modSpawnChances: ModsChances): Item[]; /** - * TODO - very similar to generateModsForEquipment * @param sessionId session id * @param weapon Weapon to add mods to - * @param modPool pool of compatible mods to attach to gun + * @param modPool Pool of compatible mods to attach to weapon * @param weaponParentId parentId of weapon - * @param parentTemplate - * @param modSpawnChances - * @param ammoTpl ammo tpl to use when generating magazines/cartridges - * @param botRole role of bot weapon is generated for - * @returns Weapon with mods + * @param parentWeaponTemplate Weapon which mods will be generated on + * @param modSpawnChances Mod spawn chances + * @param ammoTpl Ammo tpl to use when generating magazines/cartridges + * @param botRole Role of bot weapon is generated for + * @returns Weapon + mods array */ - generateModsForWeapon(sessionId: string, weapon: Item[], modPool: Mods, weaponParentId: string, parentTemplate: ITemplateItem, modSpawnChances: ModsChances, ammoTpl: string, botRole: string): Item[]; + generateModsForWeapon(sessionId: string, weapon: Item[], modPool: Mods, weaponParentId: string, parentWeaponTemplate: ITemplateItem, modSpawnChances: ModsChances, ammoTpl: string, botRole: string): Item[]; + /** + * + * @param modSlot + * @param isRandomisableSlot + * @param modsParent + * @param botEquipBlacklist + * @param itemModPool + * @param weapon array with only weapon tpl in it, ready for mods to be added + * @param ammoTpl ammo tpl to use if slot requires a cartridge to be added (e.g. mod_magazine) + * @param parentTemplate + * @returns + */ + protected chooseModToPutIntoSlot(modSlot: string, isRandomisableSlot: boolean, modsParent: Slot, botEquipBlacklist: EquipmentFilterDetails, itemModPool: Record, weapon: Item[], ammoTpl: string, parentTemplate: ITemplateItem): [boolean, ITemplateItem]; /** * Find mod tpls of a provided type and add to modPool * @param desiredSlotName slot to look up and add we are adding tpls for (e.g mod_scope) @@ -79,15 +91,15 @@ export declare class BotGeneratorHelper { /** * Check if mod item is on limited list + has surpassed the limit set for it * @param botRole role the bot has e.g. assault - * @param modTpl mods tpl + * @param modTemplate mods template data * @param modLimits limits set for weapon being generated for this bot * @returns true if over item limit */ - protected modHasReachedItemLimit(botRole: string, modTpl: string, modLimits: BotModLimits): boolean; + protected modHasReachedItemLimit(botRole: string, modTemplate: ITemplateItem, modLimits: BotModLimits): boolean; /** - * Initalise mod limits to be used when generating the weapon + * Initalise mod limits to be used when generating a weapon * @param botRole "assault", "bossTagilla" or "pmc" - * @returns + * @returns BotModLimits object */ protected initModLimits(botRole: string): BotModLimits; /** @@ -114,7 +126,7 @@ export declare class BotGeneratorHelper { protected filterWeaponModsByBlacklist(allowedMods: string[], botEquipBlacklist: EquipmentFilterDetails, modSlot: string): string[]; /** * Check if the specific item type on the weapon has reached the set limit - * @param modTpl item to check is limited + * @param modTpl log mod tpl if over type limit * @param currentCount current number of this item on gun * @param maxLimit mod limit allowed * @param botRole role of bot we're checking weapon of @@ -124,16 +136,14 @@ export declare class BotGeneratorHelper { count: number; }, maxLimit: number, botRole: string): boolean; /** - * log errors if mod is not valid for a slot - * @param modTpl - * @param found - * @param itemSlot - * @param modTemplate - * @param modSlot - * @param parentTemplate + * Log errors if mod is not compatible with slot + * @param modToAdd template of mod to check + * @param itemSlot slot the item will be placed in + * @param modSlot slot the mod will fill + * @param parentTemplate tempalte of the mods parent item * @returns true if valid */ - protected isModValidForSlot(modTpl: string, found: boolean, itemSlot: Slot, modTemplate: ITemplateItem, modSlot: string, parentTemplate: ITemplateItem): boolean; + protected isModValidForSlot(modToAdd: [boolean, ITemplateItem], itemSlot: Slot, modSlot: string, parentTemplate: ITemplateItem): boolean; /** * Create a mod item with parameters as properties * @param modId _id @@ -144,12 +154,6 @@ export declare class BotGeneratorHelper { * @returns Item object */ protected createModItem(modId: string, modTpl: string, parentId: string, modSlot: string, modTemplate: ITemplateItem): Item; - /** - * Is this magazine cylinder related (revolvers and grenade launchers) - * @param magazineParentName the name of the magazines parent - * @returns true if it is cylinder related - */ - magazineIsCylinderRelated(magazineParentName: string): boolean; /** * randomly choose if a mod should be spawned, 100% for required mods OR mod is ammo slot * never return true for an item that has 0% spawn chance @@ -161,7 +165,7 @@ export declare class BotGeneratorHelper { protected shouldModBeSpawned(itemSlot: Slot, modSlot: string, modSpawnChances: ModsChances): boolean; /** * Get a list of containers that hold ammo - * e.g. mod_magazine + * e.g. mod_magazine / patron_in_weapon_000 * @returns string array */ protected getAmmoContainers(): string[]; @@ -214,6 +218,14 @@ export declare class BotGeneratorHelper { * @returns Repairable object */ protected generateArmorRepairableProperties(itemTemplate: ITemplateItem, botRole: string): Repairable; + /** + * Get a random mod from an items compatible mods Filter array + * @param modTpl + * @param parentSlot + * @param modSlot + * @param items + * @returns item tpl + */ protected getModTplFromItemDb(modTpl: string, parentSlot: Slot, modSlot: string, items: Item[]): string; /** * Can an item be added to an item without issue @@ -223,23 +235,6 @@ export declare class BotGeneratorHelper { * @returns true if possible */ isItemIncompatibleWithCurrentItems(items: Item[], tplToCheck: string, equipmentSlot: string): boolean; - /** - * Adds an item with all its childern into specified equipmentSlots, wherever it fits. - * @param equipmentSlots - * @param parentId - * @param parentTpl - * @param itemWithChildren - * @param inventory - * @returns a `boolean` indicating item was added - */ - addItemWithChildrenToEquipmentSlot(equipmentSlots: string[], parentId: string, parentTpl: string, itemWithChildren: Item[], inventory: PmcInventory): boolean; - /** - * is the provided item allowed inside a container - * @param slot location item wants to be placed in - * @param itemTpl item being placed - * @returns true if allowed - */ - protected itemAllowedInContainer(slot: Grid, itemTpl: string): boolean; } /** TODO - move into own class */ export declare class ExhaustableArray { diff --git a/TypeScript/11BundleLoadingSample/types/helpers/BotWeaponGeneratorHelper.d.ts b/TypeScript/11BundleLoadingSample/types/helpers/BotWeaponGeneratorHelper.d.ts new file mode 100644 index 0000000..7e25f56 --- /dev/null +++ b/TypeScript/11BundleLoadingSample/types/helpers/BotWeaponGeneratorHelper.d.ts @@ -0,0 +1,78 @@ +import { MinMax } from "../models/common/MinMax"; +import { Inventory } from "../models/eft/common/tables/IBotBase"; +import { Item } from "../models/eft/common/tables/IItem"; +import { Grid, ITemplateItem } from "../models/eft/common/tables/ITemplateItem"; +import { ILogger } from "../models/spt/utils/ILogger"; +import { DatabaseServer } from "../servers/DatabaseServer"; +import { HashUtil } from "../utils/HashUtil"; +import { RandomUtil } from "../utils/RandomUtil"; +import { ContainerHelper } from "./ContainerHelper"; +import { InventoryHelper } from "./InventoryHelper"; +import { ItemHelper } from "./ItemHelper"; +export declare class BotWeaponGeneratorHelper { + protected logger: ILogger; + protected databaseServer: DatabaseServer; + protected itemHelper: ItemHelper; + protected randomUtil: RandomUtil; + protected hashUtil: HashUtil; + protected inventoryHelper: InventoryHelper; + protected containerHelper: ContainerHelper; + constructor(logger: ILogger, databaseServer: DatabaseServer, itemHelper: ItemHelper, randomUtil: RandomUtil, hashUtil: HashUtil, inventoryHelper: InventoryHelper, containerHelper: ContainerHelper); + /** + * Get a randomised number of bullets for a specific magazine + * @param magCounts min and max count of magazines + * @param magTemplate magazine to generate bullet count for + * @returns bullet count number + */ + getRandomisedBulletCount(magCounts: MinMax, magTemplate: ITemplateItem): number; + /** + * Get a randomised count of magazines + * @param magCounts min and max value returned value can be between + * @returns numberical value of magazine count + */ + getRandomisedMagazineCount(magCounts: MinMax): number; + /** + * Is this magazine cylinder related (revolvers and grenade launchers) + * @param magazineParentName the name of the magazines parent + * @returns true if it is cylinder related + */ + magazineIsCylinderRelated(magazineParentName: string): boolean; + /** + * Create a magazine using the parameters given + * @param magazineTpl Tpl of the magazine to create + * @param ammoTpl Ammo to add to magazine + * @param magTemplate template object of magazine + * @returns Item array + */ + createMagazine(magazineTpl: string, ammoTpl: string, magTemplate: ITemplateItem): Item[]; + /** + * Add a specific number of cartrdiges to a bots inventory (vest/pocket) + * @param ammoTpl Ammo tpl to add to vest/pockets + * @param cartridgeCount number of cartridges to add to vest/pockets + * @param inventory bot inventory to add cartridges to + */ + addBulletsToVestAndPockets(ammoTpl: string, cartridgeCount: number, inventory: Inventory): void; + /** + * Get a weapons default magazine template id + * @param weaponTemplate weapon to get default magazine for + * @returns tpl of magazine + */ + getWeaponsDefaultMagazineTpl(weaponTemplate: ITemplateItem): string; + /** + * Adds an item with all its childern into specified equipmentSlots, wherever it fits. + * @param equipmentSlots + * @param parentId + * @param parentTpl + * @param itemWithChildren + * @param inventory + * @returns a `boolean` indicating item was added + */ + addItemWithChildrenToEquipmentSlot(equipmentSlots: string[], parentId: string, parentTpl: string, itemWithChildren: Item[], inventory: Inventory): boolean; + /** + * is the provided item allowed inside a container + * @param slot location item wants to be placed in + * @param itemTpl item being placed + * @returns true if allowed + */ + protected itemAllowedInContainer(slot: Grid, itemTpl: string): boolean; +} diff --git a/TypeScript/12ClassExtensionOverride/package.json b/TypeScript/12ClassExtensionOverride/package.json index bf5d23d..2b6ff81 100644 --- a/TypeScript/12ClassExtensionOverride/package.json +++ b/TypeScript/12ClassExtensionOverride/package.json @@ -4,7 +4,7 @@ "main": "src/mod.js", "license": "MIT", "author": "Chomp", - "akiVersion": "3.2.2", + "akiVersion": "3.2.3", "scripts": { "setup": "npm i", "build": "node ./packageBuild.ts" diff --git a/TypeScript/12ClassExtensionOverride/types/generators/BotLootGenerator.d.ts b/TypeScript/12ClassExtensionOverride/types/generators/BotLootGenerator.d.ts index 5a2d144..c1f5310 100644 --- a/TypeScript/12ClassExtensionOverride/types/generators/BotLootGenerator.d.ts +++ b/TypeScript/12ClassExtensionOverride/types/generators/BotLootGenerator.d.ts @@ -1,4 +1,5 @@ import { BotGeneratorHelper } from "../helpers/BotGeneratorHelper"; +import { BotWeaponGeneratorHelper } from "../helpers/BotWeaponGeneratorHelper"; import { HandbookHelper } from "../helpers/HandbookHelper"; import { Inventory as PmcInventory } from "../models/eft/common/tables/IBotBase"; import { Chances, Inventory, ItemMinMax, ModsChances } from "../models/eft/common/tables/IBotType"; @@ -20,10 +21,11 @@ export declare class BotLootGenerator { protected handbookHelper: HandbookHelper; protected botGeneratorHelper: BotGeneratorHelper; protected botWeaponGenerator: BotWeaponGenerator; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; protected botLootCacheService: BotLootCacheService; protected configServer: ConfigServer; protected botConfig: IBotConfig; - constructor(logger: ILogger, hashUtil: HashUtil, randomUtil: RandomUtil, databaseServer: DatabaseServer, handbookHelper: HandbookHelper, botGeneratorHelper: BotGeneratorHelper, botWeaponGenerator: BotWeaponGenerator, botLootCacheService: BotLootCacheService, configServer: ConfigServer); + constructor(logger: ILogger, hashUtil: HashUtil, randomUtil: RandomUtil, databaseServer: DatabaseServer, handbookHelper: HandbookHelper, botGeneratorHelper: BotGeneratorHelper, botWeaponGenerator: BotWeaponGenerator, botWeaponGeneratorHelper: BotWeaponGeneratorHelper, botLootCacheService: BotLootCacheService, configServer: ConfigServer); generateLoot(sessionId: string, templateInventory: Inventory, itemCounts: ItemMinMax, isPmc: boolean, botRole: string, botInventory: PmcInventory, equipmentChances: Chances): void; protected getRandomisedCount(min: number, max: number, nValue: number): number; /** diff --git a/TypeScript/12ClassExtensionOverride/types/generators/BotWeaponGenerator.d.ts b/TypeScript/12ClassExtensionOverride/types/generators/BotWeaponGenerator.d.ts index cba7afa..487901b 100644 --- a/TypeScript/12ClassExtensionOverride/types/generators/BotWeaponGenerator.d.ts +++ b/TypeScript/12ClassExtensionOverride/types/generators/BotWeaponGenerator.d.ts @@ -1,4 +1,5 @@ import { BotGeneratorHelper } from "../helpers/BotGeneratorHelper"; +import { BotWeaponGeneratorHelper } from "../helpers/BotWeaponGeneratorHelper"; import { ItemHelper } from "../helpers/ItemHelper"; import { WeightedRandomHelper } from "../helpers/WeightedRandomHelper"; import { MinMax } from "../models/common/MinMax"; @@ -14,6 +15,7 @@ import { DatabaseServer } from "../servers/DatabaseServer"; import { HashUtil } from "../utils/HashUtil"; import { JsonUtil } from "../utils/JsonUtil"; import { RandomUtil } from "../utils/RandomUtil"; +import { IInventoryMagGen } from "./weapongen/IInventoryMagGen"; export declare class BotWeaponGenerator { protected jsonUtil: JsonUtil; protected logger: ILogger; @@ -24,9 +26,11 @@ export declare class BotWeaponGenerator { protected botGeneratorHelper: BotGeneratorHelper; protected randomUtil: RandomUtil; protected configServer: ConfigServer; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + protected inventoryMagGenComponents: IInventoryMagGen[]; protected readonly modMagazineSlotId = "mod_magazine"; protected botConfig: IBotConfig; - constructor(jsonUtil: JsonUtil, logger: ILogger, hashUtil: HashUtil, databaseServer: DatabaseServer, itemHelper: ItemHelper, weightedRandomHelper: WeightedRandomHelper, botGeneratorHelper: BotGeneratorHelper, randomUtil: RandomUtil, configServer: ConfigServer); + constructor(jsonUtil: JsonUtil, logger: ILogger, hashUtil: HashUtil, databaseServer: DatabaseServer, itemHelper: ItemHelper, weightedRandomHelper: WeightedRandomHelper, botGeneratorHelper: BotGeneratorHelper, randomUtil: RandomUtil, configServer: ConfigServer, botWeaponGeneratorHelper: BotWeaponGeneratorHelper, inventoryMagGenComponents: IInventoryMagGen[]); /** * Pick a random weapon based on weightings and generate a functional weapon * @param equipmentSlot Primary/secondary/holster @@ -85,36 +89,12 @@ export declare class BotWeaponGenerator { /** * Generates extra magazines or bullets (if magazine is internal) and adds them to TacticalVest and Pockets. * Additionally, adds extra bullets to SecuredContainer - * @param weaponMods mods to attach to weapon - * @param weaponTemplate db template for weapon - * @param magCounts magazine count to add to inventory - * @param ammoTpl ammo templateId to add to magazines - * @param inventory inventory to add magazines to - * @param botRole the bot type we're getting generating extra mags for - * @returns + * @param generatedWeaponResult object with properties for generated weapon (weapon mods pool / weapon template / ammo tpl) + * @param magCounts Magazine count to add to inventory + * @param inventory Inventory to add magazines to + * @param botRole The bot type we're getting generating extra mags for */ - addExtraMagazinesToInventory(weaponMods: Item[], weaponTemplate: ITemplateItem, magCounts: MinMax, ammoTpl: string, inventory: PmcInventory, botRole: string): void; - /** - * Create a magazine using the parameters given - * @param magazineTpl Tpl of the magazine to create - * @param ammoTpl Ammo to add to magazine - * @param magTemplate template object of magazine - * @returns Item array - */ - protected createMagazine(magazineTpl: string, ammoTpl: string, magTemplate: ITemplateItem): Item[]; - /** - * Get a randomised number of bullets for a specific magazine - * @param magCounts min and max count of magazines - * @param magTemplate magazine to generate bullet count for - * @returns bullet count number - */ - protected getRandomisedBulletCount(magCounts: MinMax, magTemplate: ITemplateItem): number; - /** - * Get a randomised count of magazines - * @param magCounts min and max value returned value can be between - * @returns numberical value of magazine count - */ - protected getRandomisedMagazineCount(magCounts: MinMax): number; + addExtraMagazinesToInventory(generatedWeaponResult: GenerateWeaponResult, magCounts: MinMax, inventory: PmcInventory, botRole: string): void; /** * Add ammo to the secure container * @param stackCount How many stacks of ammo to add @@ -131,13 +111,6 @@ export declare class BotWeaponGenerator { * @returns magazine tpl string */ protected getMagazineTplFromWeaponTemplate(weaponMods: Item[], weaponTemplate: ITemplateItem, botRole: string): string; - /** - * Get a weapons default magazine template id - * @param weaponTemplate weapon to get default magazine for - * @returns tpl of magazine - */ - protected getWeaponsDefaultMagazineTpl(weaponTemplate: ITemplateItem): string; - protected addBulletsToVestAndPockets(ammoTpl: string, bulletCount: number, inventory: PmcInventory): void; /** * Finds and return a compatible ammo tpl based on the bots ammo weightings (x.json/inventory/equipment/ammo) * @param ammo a list of ammo tpls the weapon can use diff --git a/TypeScript/12ClassExtensionOverride/types/generators/weapongen/IInventoryMagGen.d.ts b/TypeScript/12ClassExtensionOverride/types/generators/weapongen/IInventoryMagGen.d.ts new file mode 100644 index 0000000..792f510 --- /dev/null +++ b/TypeScript/12ClassExtensionOverride/types/generators/weapongen/IInventoryMagGen.d.ts @@ -0,0 +1,6 @@ +import { InventoryMagGen } from "./InventoryMagGen"; +export interface IInventoryMagGen { + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/12ClassExtensionOverride/types/generators/weapongen/InventoryMagGen.d.ts b/TypeScript/12ClassExtensionOverride/types/generators/weapongen/InventoryMagGen.d.ts new file mode 100644 index 0000000..30bf79f --- /dev/null +++ b/TypeScript/12ClassExtensionOverride/types/generators/weapongen/InventoryMagGen.d.ts @@ -0,0 +1,16 @@ +import { MinMax } from "../../models/common/MinMax"; +import { Inventory } from "../../models/eft/common/tables/IBotBase"; +import { ITemplateItem } from "../../models/eft/common/tables/ITemplateItem"; +export declare class InventoryMagGen { + private magCounts; + private magazineTemplate; + private weaponTemplate; + private ammoTemplate; + private pmcInventory; + constructor(magCounts: MinMax, magazineTemplate: ITemplateItem, weaponTemplate: ITemplateItem, ammoTemplate: ITemplateItem, pmcInventory: Inventory); + getMagCount(): MinMax; + getMagazineTemplate(): ITemplateItem; + getWeaponTemplate(): ITemplateItem; + getAmmoTemplate(): ITemplateItem; + getPmcInventory(): Inventory; +} diff --git a/TypeScript/12ClassExtensionOverride/types/generators/weapongen/implementations/BarrelInventoryMagGen.d.ts b/TypeScript/12ClassExtensionOverride/types/generators/weapongen/implementations/BarrelInventoryMagGen.d.ts new file mode 100644 index 0000000..b754d5f --- /dev/null +++ b/TypeScript/12ClassExtensionOverride/types/generators/weapongen/implementations/BarrelInventoryMagGen.d.ts @@ -0,0 +1,12 @@ +import { BotWeaponGeneratorHelper } from "../../../helpers/BotWeaponGeneratorHelper"; +import { RandomUtil } from "../../../utils/RandomUtil"; +import { IInventoryMagGen } from "../IInventoryMagGen"; +import { InventoryMagGen } from "../InventoryMagGen"; +export declare class BarrelInventoryMagGen implements IInventoryMagGen { + protected randomUtil: RandomUtil; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + constructor(randomUtil: RandomUtil, botWeaponGeneratorHelper: BotWeaponGeneratorHelper); + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/12ClassExtensionOverride/types/generators/weapongen/implementations/ExternalInventoryMagGen.d.ts b/TypeScript/12ClassExtensionOverride/types/generators/weapongen/implementations/ExternalInventoryMagGen.d.ts new file mode 100644 index 0000000..4fcb1e2 --- /dev/null +++ b/TypeScript/12ClassExtensionOverride/types/generators/weapongen/implementations/ExternalInventoryMagGen.d.ts @@ -0,0 +1,14 @@ +import { BotWeaponGeneratorHelper } from "../../../helpers/BotWeaponGeneratorHelper"; +import { ItemHelper } from "../../../helpers/ItemHelper"; +import { ILogger } from "../../../models/spt/utils/ILogger"; +import { IInventoryMagGen } from "../IInventoryMagGen"; +import { InventoryMagGen } from "../InventoryMagGen"; +export declare class ExternalInventoryMagGen implements IInventoryMagGen { + protected logger: ILogger; + protected itemHelper: ItemHelper; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + constructor(logger: ILogger, itemHelper: ItemHelper, botWeaponGeneratorHelper: BotWeaponGeneratorHelper); + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/12ClassExtensionOverride/types/generators/weapongen/implementations/InternalMagazineInventoryMagGen.d.ts b/TypeScript/12ClassExtensionOverride/types/generators/weapongen/implementations/InternalMagazineInventoryMagGen.d.ts new file mode 100644 index 0000000..4548a04 --- /dev/null +++ b/TypeScript/12ClassExtensionOverride/types/generators/weapongen/implementations/InternalMagazineInventoryMagGen.d.ts @@ -0,0 +1,10 @@ +import { BotWeaponGeneratorHelper } from "../../../helpers/BotWeaponGeneratorHelper"; +import { IInventoryMagGen } from "../IInventoryMagGen"; +import { InventoryMagGen } from "../InventoryMagGen"; +export declare class InternalMagazineInventoryMagGen implements IInventoryMagGen { + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + constructor(botWeaponGeneratorHelper: BotWeaponGeneratorHelper); + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/12ClassExtensionOverride/types/helpers/BotGeneratorHelper.d.ts b/TypeScript/12ClassExtensionOverride/types/helpers/BotGeneratorHelper.d.ts index 09e5c8f..5e3e501 100644 --- a/TypeScript/12ClassExtensionOverride/types/helpers/BotGeneratorHelper.d.ts +++ b/TypeScript/12ClassExtensionOverride/types/helpers/BotGeneratorHelper.d.ts @@ -1,8 +1,7 @@ import { DurabilityLimitsHelper } from "../helpers/DurabilityLimitsHelper"; -import { Inventory as PmcInventory } from "../models/eft/common/tables/IBotBase"; import { Mods, ModsChances } from "../models/eft/common/tables/IBotType"; import { Item, Repairable, Upd } from "../models/eft/common/tables/IItem"; -import { Grid, ITemplateItem, Slot } from "../models/eft/common/tables/ITemplateItem"; +import { ITemplateItem, Slot } from "../models/eft/common/tables/ITemplateItem"; import { EquipmentFilterDetails, IBotConfig } from "../models/spt/config/IBotConfig"; import { ILogger } from "../models/spt/utils/ILogger"; import { ConfigServer } from "../servers/ConfigServer"; @@ -12,6 +11,7 @@ import { ItemFilterService } from "../services/ItemFilterService"; import { HashUtil } from "../utils/HashUtil"; import { JsonUtil } from "../utils/JsonUtil"; import { RandomUtil } from "../utils/RandomUtil"; +import { BotWeaponGeneratorHelper } from "./BotWeaponGeneratorHelper"; import { ContainerHelper } from "./ContainerHelper"; import { InventoryHelper } from "./InventoryHelper"; import { ItemHelper } from "./ItemHelper"; @@ -42,11 +42,11 @@ export declare class BotGeneratorHelper { protected botEquipmentFilterService: BotEquipmentFilterService; protected itemFilterService: ItemFilterService; protected profileHelper: ProfileHelper; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; protected configServer: ConfigServer; protected botConfig: IBotConfig; - constructor(logger: ILogger, jsonUtil: JsonUtil, hashUtil: HashUtil, randomUtil: RandomUtil, probabilityHelper: ProbabilityHelper, databaseServer: DatabaseServer, durabilityLimitsHelper: DurabilityLimitsHelper, itemHelper: ItemHelper, inventoryHelper: InventoryHelper, containerHelper: ContainerHelper, botEquipmentFilterService: BotEquipmentFilterService, itemFilterService: ItemFilterService, profileHelper: ProfileHelper, configServer: ConfigServer); + constructor(logger: ILogger, jsonUtil: JsonUtil, hashUtil: HashUtil, randomUtil: RandomUtil, probabilityHelper: ProbabilityHelper, databaseServer: DatabaseServer, durabilityLimitsHelper: DurabilityLimitsHelper, itemHelper: ItemHelper, inventoryHelper: InventoryHelper, containerHelper: ContainerHelper, botEquipmentFilterService: BotEquipmentFilterService, itemFilterService: ItemFilterService, profileHelper: ProfileHelper, botWeaponGeneratorHelper: BotWeaponGeneratorHelper, configServer: ConfigServer); /** - * TODO - very similar to generateModsForWeapon * Check mods are compatible and add to array * @param equipment Equipment item to add mods to * @param modPool Mod list to choose frm @@ -57,18 +57,30 @@ export declare class BotGeneratorHelper { */ generateModsForEquipment(equipment: Item[], modPool: Mods, parentId: string, parentTemplate: ITemplateItem, modSpawnChances: ModsChances): Item[]; /** - * TODO - very similar to generateModsForEquipment * @param sessionId session id * @param weapon Weapon to add mods to - * @param modPool pool of compatible mods to attach to gun + * @param modPool Pool of compatible mods to attach to weapon * @param weaponParentId parentId of weapon - * @param parentTemplate - * @param modSpawnChances - * @param ammoTpl ammo tpl to use when generating magazines/cartridges - * @param botRole role of bot weapon is generated for - * @returns Weapon with mods + * @param parentWeaponTemplate Weapon which mods will be generated on + * @param modSpawnChances Mod spawn chances + * @param ammoTpl Ammo tpl to use when generating magazines/cartridges + * @param botRole Role of bot weapon is generated for + * @returns Weapon + mods array */ - generateModsForWeapon(sessionId: string, weapon: Item[], modPool: Mods, weaponParentId: string, parentTemplate: ITemplateItem, modSpawnChances: ModsChances, ammoTpl: string, botRole: string): Item[]; + generateModsForWeapon(sessionId: string, weapon: Item[], modPool: Mods, weaponParentId: string, parentWeaponTemplate: ITemplateItem, modSpawnChances: ModsChances, ammoTpl: string, botRole: string): Item[]; + /** + * + * @param modSlot + * @param isRandomisableSlot + * @param modsParent + * @param botEquipBlacklist + * @param itemModPool + * @param weapon array with only weapon tpl in it, ready for mods to be added + * @param ammoTpl ammo tpl to use if slot requires a cartridge to be added (e.g. mod_magazine) + * @param parentTemplate + * @returns + */ + protected chooseModToPutIntoSlot(modSlot: string, isRandomisableSlot: boolean, modsParent: Slot, botEquipBlacklist: EquipmentFilterDetails, itemModPool: Record, weapon: Item[], ammoTpl: string, parentTemplate: ITemplateItem): [boolean, ITemplateItem]; /** * Find mod tpls of a provided type and add to modPool * @param desiredSlotName slot to look up and add we are adding tpls for (e.g mod_scope) @@ -79,15 +91,15 @@ export declare class BotGeneratorHelper { /** * Check if mod item is on limited list + has surpassed the limit set for it * @param botRole role the bot has e.g. assault - * @param modTpl mods tpl + * @param modTemplate mods template data * @param modLimits limits set for weapon being generated for this bot * @returns true if over item limit */ - protected modHasReachedItemLimit(botRole: string, modTpl: string, modLimits: BotModLimits): boolean; + protected modHasReachedItemLimit(botRole: string, modTemplate: ITemplateItem, modLimits: BotModLimits): boolean; /** - * Initalise mod limits to be used when generating the weapon + * Initalise mod limits to be used when generating a weapon * @param botRole "assault", "bossTagilla" or "pmc" - * @returns + * @returns BotModLimits object */ protected initModLimits(botRole: string): BotModLimits; /** @@ -114,7 +126,7 @@ export declare class BotGeneratorHelper { protected filterWeaponModsByBlacklist(allowedMods: string[], botEquipBlacklist: EquipmentFilterDetails, modSlot: string): string[]; /** * Check if the specific item type on the weapon has reached the set limit - * @param modTpl item to check is limited + * @param modTpl log mod tpl if over type limit * @param currentCount current number of this item on gun * @param maxLimit mod limit allowed * @param botRole role of bot we're checking weapon of @@ -124,16 +136,14 @@ export declare class BotGeneratorHelper { count: number; }, maxLimit: number, botRole: string): boolean; /** - * log errors if mod is not valid for a slot - * @param modTpl - * @param found - * @param itemSlot - * @param modTemplate - * @param modSlot - * @param parentTemplate + * Log errors if mod is not compatible with slot + * @param modToAdd template of mod to check + * @param itemSlot slot the item will be placed in + * @param modSlot slot the mod will fill + * @param parentTemplate tempalte of the mods parent item * @returns true if valid */ - protected isModValidForSlot(modTpl: string, found: boolean, itemSlot: Slot, modTemplate: ITemplateItem, modSlot: string, parentTemplate: ITemplateItem): boolean; + protected isModValidForSlot(modToAdd: [boolean, ITemplateItem], itemSlot: Slot, modSlot: string, parentTemplate: ITemplateItem): boolean; /** * Create a mod item with parameters as properties * @param modId _id @@ -144,12 +154,6 @@ export declare class BotGeneratorHelper { * @returns Item object */ protected createModItem(modId: string, modTpl: string, parentId: string, modSlot: string, modTemplate: ITemplateItem): Item; - /** - * Is this magazine cylinder related (revolvers and grenade launchers) - * @param magazineParentName the name of the magazines parent - * @returns true if it is cylinder related - */ - magazineIsCylinderRelated(magazineParentName: string): boolean; /** * randomly choose if a mod should be spawned, 100% for required mods OR mod is ammo slot * never return true for an item that has 0% spawn chance @@ -161,7 +165,7 @@ export declare class BotGeneratorHelper { protected shouldModBeSpawned(itemSlot: Slot, modSlot: string, modSpawnChances: ModsChances): boolean; /** * Get a list of containers that hold ammo - * e.g. mod_magazine + * e.g. mod_magazine / patron_in_weapon_000 * @returns string array */ protected getAmmoContainers(): string[]; @@ -214,6 +218,14 @@ export declare class BotGeneratorHelper { * @returns Repairable object */ protected generateArmorRepairableProperties(itemTemplate: ITemplateItem, botRole: string): Repairable; + /** + * Get a random mod from an items compatible mods Filter array + * @param modTpl + * @param parentSlot + * @param modSlot + * @param items + * @returns item tpl + */ protected getModTplFromItemDb(modTpl: string, parentSlot: Slot, modSlot: string, items: Item[]): string; /** * Can an item be added to an item without issue @@ -223,23 +235,6 @@ export declare class BotGeneratorHelper { * @returns true if possible */ isItemIncompatibleWithCurrentItems(items: Item[], tplToCheck: string, equipmentSlot: string): boolean; - /** - * Adds an item with all its childern into specified equipmentSlots, wherever it fits. - * @param equipmentSlots - * @param parentId - * @param parentTpl - * @param itemWithChildren - * @param inventory - * @returns a `boolean` indicating item was added - */ - addItemWithChildrenToEquipmentSlot(equipmentSlots: string[], parentId: string, parentTpl: string, itemWithChildren: Item[], inventory: PmcInventory): boolean; - /** - * is the provided item allowed inside a container - * @param slot location item wants to be placed in - * @param itemTpl item being placed - * @returns true if allowed - */ - protected itemAllowedInContainer(slot: Grid, itemTpl: string): boolean; } /** TODO - move into own class */ export declare class ExhaustableArray { diff --git a/TypeScript/12ClassExtensionOverride/types/helpers/BotWeaponGeneratorHelper.d.ts b/TypeScript/12ClassExtensionOverride/types/helpers/BotWeaponGeneratorHelper.d.ts new file mode 100644 index 0000000..7e25f56 --- /dev/null +++ b/TypeScript/12ClassExtensionOverride/types/helpers/BotWeaponGeneratorHelper.d.ts @@ -0,0 +1,78 @@ +import { MinMax } from "../models/common/MinMax"; +import { Inventory } from "../models/eft/common/tables/IBotBase"; +import { Item } from "../models/eft/common/tables/IItem"; +import { Grid, ITemplateItem } from "../models/eft/common/tables/ITemplateItem"; +import { ILogger } from "../models/spt/utils/ILogger"; +import { DatabaseServer } from "../servers/DatabaseServer"; +import { HashUtil } from "../utils/HashUtil"; +import { RandomUtil } from "../utils/RandomUtil"; +import { ContainerHelper } from "./ContainerHelper"; +import { InventoryHelper } from "./InventoryHelper"; +import { ItemHelper } from "./ItemHelper"; +export declare class BotWeaponGeneratorHelper { + protected logger: ILogger; + protected databaseServer: DatabaseServer; + protected itemHelper: ItemHelper; + protected randomUtil: RandomUtil; + protected hashUtil: HashUtil; + protected inventoryHelper: InventoryHelper; + protected containerHelper: ContainerHelper; + constructor(logger: ILogger, databaseServer: DatabaseServer, itemHelper: ItemHelper, randomUtil: RandomUtil, hashUtil: HashUtil, inventoryHelper: InventoryHelper, containerHelper: ContainerHelper); + /** + * Get a randomised number of bullets for a specific magazine + * @param magCounts min and max count of magazines + * @param magTemplate magazine to generate bullet count for + * @returns bullet count number + */ + getRandomisedBulletCount(magCounts: MinMax, magTemplate: ITemplateItem): number; + /** + * Get a randomised count of magazines + * @param magCounts min and max value returned value can be between + * @returns numberical value of magazine count + */ + getRandomisedMagazineCount(magCounts: MinMax): number; + /** + * Is this magazine cylinder related (revolvers and grenade launchers) + * @param magazineParentName the name of the magazines parent + * @returns true if it is cylinder related + */ + magazineIsCylinderRelated(magazineParentName: string): boolean; + /** + * Create a magazine using the parameters given + * @param magazineTpl Tpl of the magazine to create + * @param ammoTpl Ammo to add to magazine + * @param magTemplate template object of magazine + * @returns Item array + */ + createMagazine(magazineTpl: string, ammoTpl: string, magTemplate: ITemplateItem): Item[]; + /** + * Add a specific number of cartrdiges to a bots inventory (vest/pocket) + * @param ammoTpl Ammo tpl to add to vest/pockets + * @param cartridgeCount number of cartridges to add to vest/pockets + * @param inventory bot inventory to add cartridges to + */ + addBulletsToVestAndPockets(ammoTpl: string, cartridgeCount: number, inventory: Inventory): void; + /** + * Get a weapons default magazine template id + * @param weaponTemplate weapon to get default magazine for + * @returns tpl of magazine + */ + getWeaponsDefaultMagazineTpl(weaponTemplate: ITemplateItem): string; + /** + * Adds an item with all its childern into specified equipmentSlots, wherever it fits. + * @param equipmentSlots + * @param parentId + * @param parentTpl + * @param itemWithChildren + * @param inventory + * @returns a `boolean` indicating item was added + */ + addItemWithChildrenToEquipmentSlot(equipmentSlots: string[], parentId: string, parentTpl: string, itemWithChildren: Item[], inventory: Inventory): boolean; + /** + * is the provided item allowed inside a container + * @param slot location item wants to be placed in + * @param itemTpl item being placed + * @returns true if allowed + */ + protected itemAllowedInContainer(slot: Grid, itemTpl: string): boolean; +} diff --git a/TypeScript/13AddTrader/package.json b/TypeScript/13AddTrader/package.json index 55ccf95..cad6aab 100644 --- a/TypeScript/13AddTrader/package.json +++ b/TypeScript/13AddTrader/package.json @@ -4,7 +4,7 @@ "main": "src/mod.js", "license": "MIT", "author": "Shirito", - "akiVersion": "3.2.2", + "akiVersion": "3.2.3", "scripts": { "setup": "npm i", "build": "node ./packageBuild.ts" diff --git a/TypeScript/13AddTrader/types/generators/BotLootGenerator.d.ts b/TypeScript/13AddTrader/types/generators/BotLootGenerator.d.ts index 5a2d144..c1f5310 100644 --- a/TypeScript/13AddTrader/types/generators/BotLootGenerator.d.ts +++ b/TypeScript/13AddTrader/types/generators/BotLootGenerator.d.ts @@ -1,4 +1,5 @@ import { BotGeneratorHelper } from "../helpers/BotGeneratorHelper"; +import { BotWeaponGeneratorHelper } from "../helpers/BotWeaponGeneratorHelper"; import { HandbookHelper } from "../helpers/HandbookHelper"; import { Inventory as PmcInventory } from "../models/eft/common/tables/IBotBase"; import { Chances, Inventory, ItemMinMax, ModsChances } from "../models/eft/common/tables/IBotType"; @@ -20,10 +21,11 @@ export declare class BotLootGenerator { protected handbookHelper: HandbookHelper; protected botGeneratorHelper: BotGeneratorHelper; protected botWeaponGenerator: BotWeaponGenerator; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; protected botLootCacheService: BotLootCacheService; protected configServer: ConfigServer; protected botConfig: IBotConfig; - constructor(logger: ILogger, hashUtil: HashUtil, randomUtil: RandomUtil, databaseServer: DatabaseServer, handbookHelper: HandbookHelper, botGeneratorHelper: BotGeneratorHelper, botWeaponGenerator: BotWeaponGenerator, botLootCacheService: BotLootCacheService, configServer: ConfigServer); + constructor(logger: ILogger, hashUtil: HashUtil, randomUtil: RandomUtil, databaseServer: DatabaseServer, handbookHelper: HandbookHelper, botGeneratorHelper: BotGeneratorHelper, botWeaponGenerator: BotWeaponGenerator, botWeaponGeneratorHelper: BotWeaponGeneratorHelper, botLootCacheService: BotLootCacheService, configServer: ConfigServer); generateLoot(sessionId: string, templateInventory: Inventory, itemCounts: ItemMinMax, isPmc: boolean, botRole: string, botInventory: PmcInventory, equipmentChances: Chances): void; protected getRandomisedCount(min: number, max: number, nValue: number): number; /** diff --git a/TypeScript/13AddTrader/types/generators/BotWeaponGenerator.d.ts b/TypeScript/13AddTrader/types/generators/BotWeaponGenerator.d.ts index cba7afa..487901b 100644 --- a/TypeScript/13AddTrader/types/generators/BotWeaponGenerator.d.ts +++ b/TypeScript/13AddTrader/types/generators/BotWeaponGenerator.d.ts @@ -1,4 +1,5 @@ import { BotGeneratorHelper } from "../helpers/BotGeneratorHelper"; +import { BotWeaponGeneratorHelper } from "../helpers/BotWeaponGeneratorHelper"; import { ItemHelper } from "../helpers/ItemHelper"; import { WeightedRandomHelper } from "../helpers/WeightedRandomHelper"; import { MinMax } from "../models/common/MinMax"; @@ -14,6 +15,7 @@ import { DatabaseServer } from "../servers/DatabaseServer"; import { HashUtil } from "../utils/HashUtil"; import { JsonUtil } from "../utils/JsonUtil"; import { RandomUtil } from "../utils/RandomUtil"; +import { IInventoryMagGen } from "./weapongen/IInventoryMagGen"; export declare class BotWeaponGenerator { protected jsonUtil: JsonUtil; protected logger: ILogger; @@ -24,9 +26,11 @@ export declare class BotWeaponGenerator { protected botGeneratorHelper: BotGeneratorHelper; protected randomUtil: RandomUtil; protected configServer: ConfigServer; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + protected inventoryMagGenComponents: IInventoryMagGen[]; protected readonly modMagazineSlotId = "mod_magazine"; protected botConfig: IBotConfig; - constructor(jsonUtil: JsonUtil, logger: ILogger, hashUtil: HashUtil, databaseServer: DatabaseServer, itemHelper: ItemHelper, weightedRandomHelper: WeightedRandomHelper, botGeneratorHelper: BotGeneratorHelper, randomUtil: RandomUtil, configServer: ConfigServer); + constructor(jsonUtil: JsonUtil, logger: ILogger, hashUtil: HashUtil, databaseServer: DatabaseServer, itemHelper: ItemHelper, weightedRandomHelper: WeightedRandomHelper, botGeneratorHelper: BotGeneratorHelper, randomUtil: RandomUtil, configServer: ConfigServer, botWeaponGeneratorHelper: BotWeaponGeneratorHelper, inventoryMagGenComponents: IInventoryMagGen[]); /** * Pick a random weapon based on weightings and generate a functional weapon * @param equipmentSlot Primary/secondary/holster @@ -85,36 +89,12 @@ export declare class BotWeaponGenerator { /** * Generates extra magazines or bullets (if magazine is internal) and adds them to TacticalVest and Pockets. * Additionally, adds extra bullets to SecuredContainer - * @param weaponMods mods to attach to weapon - * @param weaponTemplate db template for weapon - * @param magCounts magazine count to add to inventory - * @param ammoTpl ammo templateId to add to magazines - * @param inventory inventory to add magazines to - * @param botRole the bot type we're getting generating extra mags for - * @returns + * @param generatedWeaponResult object with properties for generated weapon (weapon mods pool / weapon template / ammo tpl) + * @param magCounts Magazine count to add to inventory + * @param inventory Inventory to add magazines to + * @param botRole The bot type we're getting generating extra mags for */ - addExtraMagazinesToInventory(weaponMods: Item[], weaponTemplate: ITemplateItem, magCounts: MinMax, ammoTpl: string, inventory: PmcInventory, botRole: string): void; - /** - * Create a magazine using the parameters given - * @param magazineTpl Tpl of the magazine to create - * @param ammoTpl Ammo to add to magazine - * @param magTemplate template object of magazine - * @returns Item array - */ - protected createMagazine(magazineTpl: string, ammoTpl: string, magTemplate: ITemplateItem): Item[]; - /** - * Get a randomised number of bullets for a specific magazine - * @param magCounts min and max count of magazines - * @param magTemplate magazine to generate bullet count for - * @returns bullet count number - */ - protected getRandomisedBulletCount(magCounts: MinMax, magTemplate: ITemplateItem): number; - /** - * Get a randomised count of magazines - * @param magCounts min and max value returned value can be between - * @returns numberical value of magazine count - */ - protected getRandomisedMagazineCount(magCounts: MinMax): number; + addExtraMagazinesToInventory(generatedWeaponResult: GenerateWeaponResult, magCounts: MinMax, inventory: PmcInventory, botRole: string): void; /** * Add ammo to the secure container * @param stackCount How many stacks of ammo to add @@ -131,13 +111,6 @@ export declare class BotWeaponGenerator { * @returns magazine tpl string */ protected getMagazineTplFromWeaponTemplate(weaponMods: Item[], weaponTemplate: ITemplateItem, botRole: string): string; - /** - * Get a weapons default magazine template id - * @param weaponTemplate weapon to get default magazine for - * @returns tpl of magazine - */ - protected getWeaponsDefaultMagazineTpl(weaponTemplate: ITemplateItem): string; - protected addBulletsToVestAndPockets(ammoTpl: string, bulletCount: number, inventory: PmcInventory): void; /** * Finds and return a compatible ammo tpl based on the bots ammo weightings (x.json/inventory/equipment/ammo) * @param ammo a list of ammo tpls the weapon can use diff --git a/TypeScript/13AddTrader/types/generators/weapongen/IInventoryMagGen.d.ts b/TypeScript/13AddTrader/types/generators/weapongen/IInventoryMagGen.d.ts new file mode 100644 index 0000000..792f510 --- /dev/null +++ b/TypeScript/13AddTrader/types/generators/weapongen/IInventoryMagGen.d.ts @@ -0,0 +1,6 @@ +import { InventoryMagGen } from "./InventoryMagGen"; +export interface IInventoryMagGen { + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/13AddTrader/types/generators/weapongen/InventoryMagGen.d.ts b/TypeScript/13AddTrader/types/generators/weapongen/InventoryMagGen.d.ts new file mode 100644 index 0000000..30bf79f --- /dev/null +++ b/TypeScript/13AddTrader/types/generators/weapongen/InventoryMagGen.d.ts @@ -0,0 +1,16 @@ +import { MinMax } from "../../models/common/MinMax"; +import { Inventory } from "../../models/eft/common/tables/IBotBase"; +import { ITemplateItem } from "../../models/eft/common/tables/ITemplateItem"; +export declare class InventoryMagGen { + private magCounts; + private magazineTemplate; + private weaponTemplate; + private ammoTemplate; + private pmcInventory; + constructor(magCounts: MinMax, magazineTemplate: ITemplateItem, weaponTemplate: ITemplateItem, ammoTemplate: ITemplateItem, pmcInventory: Inventory); + getMagCount(): MinMax; + getMagazineTemplate(): ITemplateItem; + getWeaponTemplate(): ITemplateItem; + getAmmoTemplate(): ITemplateItem; + getPmcInventory(): Inventory; +} diff --git a/TypeScript/13AddTrader/types/generators/weapongen/implementations/BarrelInventoryMagGen.d.ts b/TypeScript/13AddTrader/types/generators/weapongen/implementations/BarrelInventoryMagGen.d.ts new file mode 100644 index 0000000..b754d5f --- /dev/null +++ b/TypeScript/13AddTrader/types/generators/weapongen/implementations/BarrelInventoryMagGen.d.ts @@ -0,0 +1,12 @@ +import { BotWeaponGeneratorHelper } from "../../../helpers/BotWeaponGeneratorHelper"; +import { RandomUtil } from "../../../utils/RandomUtil"; +import { IInventoryMagGen } from "../IInventoryMagGen"; +import { InventoryMagGen } from "../InventoryMagGen"; +export declare class BarrelInventoryMagGen implements IInventoryMagGen { + protected randomUtil: RandomUtil; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + constructor(randomUtil: RandomUtil, botWeaponGeneratorHelper: BotWeaponGeneratorHelper); + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/13AddTrader/types/generators/weapongen/implementations/ExternalInventoryMagGen.d.ts b/TypeScript/13AddTrader/types/generators/weapongen/implementations/ExternalInventoryMagGen.d.ts new file mode 100644 index 0000000..4fcb1e2 --- /dev/null +++ b/TypeScript/13AddTrader/types/generators/weapongen/implementations/ExternalInventoryMagGen.d.ts @@ -0,0 +1,14 @@ +import { BotWeaponGeneratorHelper } from "../../../helpers/BotWeaponGeneratorHelper"; +import { ItemHelper } from "../../../helpers/ItemHelper"; +import { ILogger } from "../../../models/spt/utils/ILogger"; +import { IInventoryMagGen } from "../IInventoryMagGen"; +import { InventoryMagGen } from "../InventoryMagGen"; +export declare class ExternalInventoryMagGen implements IInventoryMagGen { + protected logger: ILogger; + protected itemHelper: ItemHelper; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + constructor(logger: ILogger, itemHelper: ItemHelper, botWeaponGeneratorHelper: BotWeaponGeneratorHelper); + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/13AddTrader/types/generators/weapongen/implementations/InternalMagazineInventoryMagGen.d.ts b/TypeScript/13AddTrader/types/generators/weapongen/implementations/InternalMagazineInventoryMagGen.d.ts new file mode 100644 index 0000000..4548a04 --- /dev/null +++ b/TypeScript/13AddTrader/types/generators/weapongen/implementations/InternalMagazineInventoryMagGen.d.ts @@ -0,0 +1,10 @@ +import { BotWeaponGeneratorHelper } from "../../../helpers/BotWeaponGeneratorHelper"; +import { IInventoryMagGen } from "../IInventoryMagGen"; +import { InventoryMagGen } from "../InventoryMagGen"; +export declare class InternalMagazineInventoryMagGen implements IInventoryMagGen { + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + constructor(botWeaponGeneratorHelper: BotWeaponGeneratorHelper); + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/13AddTrader/types/helpers/BotGeneratorHelper.d.ts b/TypeScript/13AddTrader/types/helpers/BotGeneratorHelper.d.ts index 09e5c8f..5e3e501 100644 --- a/TypeScript/13AddTrader/types/helpers/BotGeneratorHelper.d.ts +++ b/TypeScript/13AddTrader/types/helpers/BotGeneratorHelper.d.ts @@ -1,8 +1,7 @@ import { DurabilityLimitsHelper } from "../helpers/DurabilityLimitsHelper"; -import { Inventory as PmcInventory } from "../models/eft/common/tables/IBotBase"; import { Mods, ModsChances } from "../models/eft/common/tables/IBotType"; import { Item, Repairable, Upd } from "../models/eft/common/tables/IItem"; -import { Grid, ITemplateItem, Slot } from "../models/eft/common/tables/ITemplateItem"; +import { ITemplateItem, Slot } from "../models/eft/common/tables/ITemplateItem"; import { EquipmentFilterDetails, IBotConfig } from "../models/spt/config/IBotConfig"; import { ILogger } from "../models/spt/utils/ILogger"; import { ConfigServer } from "../servers/ConfigServer"; @@ -12,6 +11,7 @@ import { ItemFilterService } from "../services/ItemFilterService"; import { HashUtil } from "../utils/HashUtil"; import { JsonUtil } from "../utils/JsonUtil"; import { RandomUtil } from "../utils/RandomUtil"; +import { BotWeaponGeneratorHelper } from "./BotWeaponGeneratorHelper"; import { ContainerHelper } from "./ContainerHelper"; import { InventoryHelper } from "./InventoryHelper"; import { ItemHelper } from "./ItemHelper"; @@ -42,11 +42,11 @@ export declare class BotGeneratorHelper { protected botEquipmentFilterService: BotEquipmentFilterService; protected itemFilterService: ItemFilterService; protected profileHelper: ProfileHelper; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; protected configServer: ConfigServer; protected botConfig: IBotConfig; - constructor(logger: ILogger, jsonUtil: JsonUtil, hashUtil: HashUtil, randomUtil: RandomUtil, probabilityHelper: ProbabilityHelper, databaseServer: DatabaseServer, durabilityLimitsHelper: DurabilityLimitsHelper, itemHelper: ItemHelper, inventoryHelper: InventoryHelper, containerHelper: ContainerHelper, botEquipmentFilterService: BotEquipmentFilterService, itemFilterService: ItemFilterService, profileHelper: ProfileHelper, configServer: ConfigServer); + constructor(logger: ILogger, jsonUtil: JsonUtil, hashUtil: HashUtil, randomUtil: RandomUtil, probabilityHelper: ProbabilityHelper, databaseServer: DatabaseServer, durabilityLimitsHelper: DurabilityLimitsHelper, itemHelper: ItemHelper, inventoryHelper: InventoryHelper, containerHelper: ContainerHelper, botEquipmentFilterService: BotEquipmentFilterService, itemFilterService: ItemFilterService, profileHelper: ProfileHelper, botWeaponGeneratorHelper: BotWeaponGeneratorHelper, configServer: ConfigServer); /** - * TODO - very similar to generateModsForWeapon * Check mods are compatible and add to array * @param equipment Equipment item to add mods to * @param modPool Mod list to choose frm @@ -57,18 +57,30 @@ export declare class BotGeneratorHelper { */ generateModsForEquipment(equipment: Item[], modPool: Mods, parentId: string, parentTemplate: ITemplateItem, modSpawnChances: ModsChances): Item[]; /** - * TODO - very similar to generateModsForEquipment * @param sessionId session id * @param weapon Weapon to add mods to - * @param modPool pool of compatible mods to attach to gun + * @param modPool Pool of compatible mods to attach to weapon * @param weaponParentId parentId of weapon - * @param parentTemplate - * @param modSpawnChances - * @param ammoTpl ammo tpl to use when generating magazines/cartridges - * @param botRole role of bot weapon is generated for - * @returns Weapon with mods + * @param parentWeaponTemplate Weapon which mods will be generated on + * @param modSpawnChances Mod spawn chances + * @param ammoTpl Ammo tpl to use when generating magazines/cartridges + * @param botRole Role of bot weapon is generated for + * @returns Weapon + mods array */ - generateModsForWeapon(sessionId: string, weapon: Item[], modPool: Mods, weaponParentId: string, parentTemplate: ITemplateItem, modSpawnChances: ModsChances, ammoTpl: string, botRole: string): Item[]; + generateModsForWeapon(sessionId: string, weapon: Item[], modPool: Mods, weaponParentId: string, parentWeaponTemplate: ITemplateItem, modSpawnChances: ModsChances, ammoTpl: string, botRole: string): Item[]; + /** + * + * @param modSlot + * @param isRandomisableSlot + * @param modsParent + * @param botEquipBlacklist + * @param itemModPool + * @param weapon array with only weapon tpl in it, ready for mods to be added + * @param ammoTpl ammo tpl to use if slot requires a cartridge to be added (e.g. mod_magazine) + * @param parentTemplate + * @returns + */ + protected chooseModToPutIntoSlot(modSlot: string, isRandomisableSlot: boolean, modsParent: Slot, botEquipBlacklist: EquipmentFilterDetails, itemModPool: Record, weapon: Item[], ammoTpl: string, parentTemplate: ITemplateItem): [boolean, ITemplateItem]; /** * Find mod tpls of a provided type and add to modPool * @param desiredSlotName slot to look up and add we are adding tpls for (e.g mod_scope) @@ -79,15 +91,15 @@ export declare class BotGeneratorHelper { /** * Check if mod item is on limited list + has surpassed the limit set for it * @param botRole role the bot has e.g. assault - * @param modTpl mods tpl + * @param modTemplate mods template data * @param modLimits limits set for weapon being generated for this bot * @returns true if over item limit */ - protected modHasReachedItemLimit(botRole: string, modTpl: string, modLimits: BotModLimits): boolean; + protected modHasReachedItemLimit(botRole: string, modTemplate: ITemplateItem, modLimits: BotModLimits): boolean; /** - * Initalise mod limits to be used when generating the weapon + * Initalise mod limits to be used when generating a weapon * @param botRole "assault", "bossTagilla" or "pmc" - * @returns + * @returns BotModLimits object */ protected initModLimits(botRole: string): BotModLimits; /** @@ -114,7 +126,7 @@ export declare class BotGeneratorHelper { protected filterWeaponModsByBlacklist(allowedMods: string[], botEquipBlacklist: EquipmentFilterDetails, modSlot: string): string[]; /** * Check if the specific item type on the weapon has reached the set limit - * @param modTpl item to check is limited + * @param modTpl log mod tpl if over type limit * @param currentCount current number of this item on gun * @param maxLimit mod limit allowed * @param botRole role of bot we're checking weapon of @@ -124,16 +136,14 @@ export declare class BotGeneratorHelper { count: number; }, maxLimit: number, botRole: string): boolean; /** - * log errors if mod is not valid for a slot - * @param modTpl - * @param found - * @param itemSlot - * @param modTemplate - * @param modSlot - * @param parentTemplate + * Log errors if mod is not compatible with slot + * @param modToAdd template of mod to check + * @param itemSlot slot the item will be placed in + * @param modSlot slot the mod will fill + * @param parentTemplate tempalte of the mods parent item * @returns true if valid */ - protected isModValidForSlot(modTpl: string, found: boolean, itemSlot: Slot, modTemplate: ITemplateItem, modSlot: string, parentTemplate: ITemplateItem): boolean; + protected isModValidForSlot(modToAdd: [boolean, ITemplateItem], itemSlot: Slot, modSlot: string, parentTemplate: ITemplateItem): boolean; /** * Create a mod item with parameters as properties * @param modId _id @@ -144,12 +154,6 @@ export declare class BotGeneratorHelper { * @returns Item object */ protected createModItem(modId: string, modTpl: string, parentId: string, modSlot: string, modTemplate: ITemplateItem): Item; - /** - * Is this magazine cylinder related (revolvers and grenade launchers) - * @param magazineParentName the name of the magazines parent - * @returns true if it is cylinder related - */ - magazineIsCylinderRelated(magazineParentName: string): boolean; /** * randomly choose if a mod should be spawned, 100% for required mods OR mod is ammo slot * never return true for an item that has 0% spawn chance @@ -161,7 +165,7 @@ export declare class BotGeneratorHelper { protected shouldModBeSpawned(itemSlot: Slot, modSlot: string, modSpawnChances: ModsChances): boolean; /** * Get a list of containers that hold ammo - * e.g. mod_magazine + * e.g. mod_magazine / patron_in_weapon_000 * @returns string array */ protected getAmmoContainers(): string[]; @@ -214,6 +218,14 @@ export declare class BotGeneratorHelper { * @returns Repairable object */ protected generateArmorRepairableProperties(itemTemplate: ITemplateItem, botRole: string): Repairable; + /** + * Get a random mod from an items compatible mods Filter array + * @param modTpl + * @param parentSlot + * @param modSlot + * @param items + * @returns item tpl + */ protected getModTplFromItemDb(modTpl: string, parentSlot: Slot, modSlot: string, items: Item[]): string; /** * Can an item be added to an item without issue @@ -223,23 +235,6 @@ export declare class BotGeneratorHelper { * @returns true if possible */ isItemIncompatibleWithCurrentItems(items: Item[], tplToCheck: string, equipmentSlot: string): boolean; - /** - * Adds an item with all its childern into specified equipmentSlots, wherever it fits. - * @param equipmentSlots - * @param parentId - * @param parentTpl - * @param itemWithChildren - * @param inventory - * @returns a `boolean` indicating item was added - */ - addItemWithChildrenToEquipmentSlot(equipmentSlots: string[], parentId: string, parentTpl: string, itemWithChildren: Item[], inventory: PmcInventory): boolean; - /** - * is the provided item allowed inside a container - * @param slot location item wants to be placed in - * @param itemTpl item being placed - * @returns true if allowed - */ - protected itemAllowedInContainer(slot: Grid, itemTpl: string): boolean; } /** TODO - move into own class */ export declare class ExhaustableArray { diff --git a/TypeScript/13AddTrader/types/helpers/BotWeaponGeneratorHelper.d.ts b/TypeScript/13AddTrader/types/helpers/BotWeaponGeneratorHelper.d.ts new file mode 100644 index 0000000..7e25f56 --- /dev/null +++ b/TypeScript/13AddTrader/types/helpers/BotWeaponGeneratorHelper.d.ts @@ -0,0 +1,78 @@ +import { MinMax } from "../models/common/MinMax"; +import { Inventory } from "../models/eft/common/tables/IBotBase"; +import { Item } from "../models/eft/common/tables/IItem"; +import { Grid, ITemplateItem } from "../models/eft/common/tables/ITemplateItem"; +import { ILogger } from "../models/spt/utils/ILogger"; +import { DatabaseServer } from "../servers/DatabaseServer"; +import { HashUtil } from "../utils/HashUtil"; +import { RandomUtil } from "../utils/RandomUtil"; +import { ContainerHelper } from "./ContainerHelper"; +import { InventoryHelper } from "./InventoryHelper"; +import { ItemHelper } from "./ItemHelper"; +export declare class BotWeaponGeneratorHelper { + protected logger: ILogger; + protected databaseServer: DatabaseServer; + protected itemHelper: ItemHelper; + protected randomUtil: RandomUtil; + protected hashUtil: HashUtil; + protected inventoryHelper: InventoryHelper; + protected containerHelper: ContainerHelper; + constructor(logger: ILogger, databaseServer: DatabaseServer, itemHelper: ItemHelper, randomUtil: RandomUtil, hashUtil: HashUtil, inventoryHelper: InventoryHelper, containerHelper: ContainerHelper); + /** + * Get a randomised number of bullets for a specific magazine + * @param magCounts min and max count of magazines + * @param magTemplate magazine to generate bullet count for + * @returns bullet count number + */ + getRandomisedBulletCount(magCounts: MinMax, magTemplate: ITemplateItem): number; + /** + * Get a randomised count of magazines + * @param magCounts min and max value returned value can be between + * @returns numberical value of magazine count + */ + getRandomisedMagazineCount(magCounts: MinMax): number; + /** + * Is this magazine cylinder related (revolvers and grenade launchers) + * @param magazineParentName the name of the magazines parent + * @returns true if it is cylinder related + */ + magazineIsCylinderRelated(magazineParentName: string): boolean; + /** + * Create a magazine using the parameters given + * @param magazineTpl Tpl of the magazine to create + * @param ammoTpl Ammo to add to magazine + * @param magTemplate template object of magazine + * @returns Item array + */ + createMagazine(magazineTpl: string, ammoTpl: string, magTemplate: ITemplateItem): Item[]; + /** + * Add a specific number of cartrdiges to a bots inventory (vest/pocket) + * @param ammoTpl Ammo tpl to add to vest/pockets + * @param cartridgeCount number of cartridges to add to vest/pockets + * @param inventory bot inventory to add cartridges to + */ + addBulletsToVestAndPockets(ammoTpl: string, cartridgeCount: number, inventory: Inventory): void; + /** + * Get a weapons default magazine template id + * @param weaponTemplate weapon to get default magazine for + * @returns tpl of magazine + */ + getWeaponsDefaultMagazineTpl(weaponTemplate: ITemplateItem): string; + /** + * Adds an item with all its childern into specified equipmentSlots, wherever it fits. + * @param equipmentSlots + * @param parentId + * @param parentTpl + * @param itemWithChildren + * @param inventory + * @returns a `boolean` indicating item was added + */ + addItemWithChildrenToEquipmentSlot(equipmentSlots: string[], parentId: string, parentTpl: string, itemWithChildren: Item[], inventory: Inventory): boolean; + /** + * is the provided item allowed inside a container + * @param slot location item wants to be placed in + * @param itemTpl item being placed + * @returns true if allowed + */ + protected itemAllowedInContainer(slot: Grid, itemTpl: string): boolean; +} diff --git a/TypeScript/14AfterDBLoadHook/package.json b/TypeScript/14AfterDBLoadHook/package.json index 1a75f92..2259b8d 100644 --- a/TypeScript/14AfterDBLoadHook/package.json +++ b/TypeScript/14AfterDBLoadHook/package.json @@ -4,7 +4,7 @@ "main": "src/mod.js", "license": "MIT", "author": "Chomp", - "akiVersion": "3.2.2", + "akiVersion": "3.2.3", "scripts": { "setup": "npm i", "build": "node ./packageBuild.ts" diff --git a/TypeScript/14AfterDBLoadHook/types/generators/BotLootGenerator.d.ts b/TypeScript/14AfterDBLoadHook/types/generators/BotLootGenerator.d.ts index 5a2d144..c1f5310 100644 --- a/TypeScript/14AfterDBLoadHook/types/generators/BotLootGenerator.d.ts +++ b/TypeScript/14AfterDBLoadHook/types/generators/BotLootGenerator.d.ts @@ -1,4 +1,5 @@ import { BotGeneratorHelper } from "../helpers/BotGeneratorHelper"; +import { BotWeaponGeneratorHelper } from "../helpers/BotWeaponGeneratorHelper"; import { HandbookHelper } from "../helpers/HandbookHelper"; import { Inventory as PmcInventory } from "../models/eft/common/tables/IBotBase"; import { Chances, Inventory, ItemMinMax, ModsChances } from "../models/eft/common/tables/IBotType"; @@ -20,10 +21,11 @@ export declare class BotLootGenerator { protected handbookHelper: HandbookHelper; protected botGeneratorHelper: BotGeneratorHelper; protected botWeaponGenerator: BotWeaponGenerator; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; protected botLootCacheService: BotLootCacheService; protected configServer: ConfigServer; protected botConfig: IBotConfig; - constructor(logger: ILogger, hashUtil: HashUtil, randomUtil: RandomUtil, databaseServer: DatabaseServer, handbookHelper: HandbookHelper, botGeneratorHelper: BotGeneratorHelper, botWeaponGenerator: BotWeaponGenerator, botLootCacheService: BotLootCacheService, configServer: ConfigServer); + constructor(logger: ILogger, hashUtil: HashUtil, randomUtil: RandomUtil, databaseServer: DatabaseServer, handbookHelper: HandbookHelper, botGeneratorHelper: BotGeneratorHelper, botWeaponGenerator: BotWeaponGenerator, botWeaponGeneratorHelper: BotWeaponGeneratorHelper, botLootCacheService: BotLootCacheService, configServer: ConfigServer); generateLoot(sessionId: string, templateInventory: Inventory, itemCounts: ItemMinMax, isPmc: boolean, botRole: string, botInventory: PmcInventory, equipmentChances: Chances): void; protected getRandomisedCount(min: number, max: number, nValue: number): number; /** diff --git a/TypeScript/14AfterDBLoadHook/types/generators/BotWeaponGenerator.d.ts b/TypeScript/14AfterDBLoadHook/types/generators/BotWeaponGenerator.d.ts index cba7afa..487901b 100644 --- a/TypeScript/14AfterDBLoadHook/types/generators/BotWeaponGenerator.d.ts +++ b/TypeScript/14AfterDBLoadHook/types/generators/BotWeaponGenerator.d.ts @@ -1,4 +1,5 @@ import { BotGeneratorHelper } from "../helpers/BotGeneratorHelper"; +import { BotWeaponGeneratorHelper } from "../helpers/BotWeaponGeneratorHelper"; import { ItemHelper } from "../helpers/ItemHelper"; import { WeightedRandomHelper } from "../helpers/WeightedRandomHelper"; import { MinMax } from "../models/common/MinMax"; @@ -14,6 +15,7 @@ import { DatabaseServer } from "../servers/DatabaseServer"; import { HashUtil } from "../utils/HashUtil"; import { JsonUtil } from "../utils/JsonUtil"; import { RandomUtil } from "../utils/RandomUtil"; +import { IInventoryMagGen } from "./weapongen/IInventoryMagGen"; export declare class BotWeaponGenerator { protected jsonUtil: JsonUtil; protected logger: ILogger; @@ -24,9 +26,11 @@ export declare class BotWeaponGenerator { protected botGeneratorHelper: BotGeneratorHelper; protected randomUtil: RandomUtil; protected configServer: ConfigServer; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + protected inventoryMagGenComponents: IInventoryMagGen[]; protected readonly modMagazineSlotId = "mod_magazine"; protected botConfig: IBotConfig; - constructor(jsonUtil: JsonUtil, logger: ILogger, hashUtil: HashUtil, databaseServer: DatabaseServer, itemHelper: ItemHelper, weightedRandomHelper: WeightedRandomHelper, botGeneratorHelper: BotGeneratorHelper, randomUtil: RandomUtil, configServer: ConfigServer); + constructor(jsonUtil: JsonUtil, logger: ILogger, hashUtil: HashUtil, databaseServer: DatabaseServer, itemHelper: ItemHelper, weightedRandomHelper: WeightedRandomHelper, botGeneratorHelper: BotGeneratorHelper, randomUtil: RandomUtil, configServer: ConfigServer, botWeaponGeneratorHelper: BotWeaponGeneratorHelper, inventoryMagGenComponents: IInventoryMagGen[]); /** * Pick a random weapon based on weightings and generate a functional weapon * @param equipmentSlot Primary/secondary/holster @@ -85,36 +89,12 @@ export declare class BotWeaponGenerator { /** * Generates extra magazines or bullets (if magazine is internal) and adds them to TacticalVest and Pockets. * Additionally, adds extra bullets to SecuredContainer - * @param weaponMods mods to attach to weapon - * @param weaponTemplate db template for weapon - * @param magCounts magazine count to add to inventory - * @param ammoTpl ammo templateId to add to magazines - * @param inventory inventory to add magazines to - * @param botRole the bot type we're getting generating extra mags for - * @returns + * @param generatedWeaponResult object with properties for generated weapon (weapon mods pool / weapon template / ammo tpl) + * @param magCounts Magazine count to add to inventory + * @param inventory Inventory to add magazines to + * @param botRole The bot type we're getting generating extra mags for */ - addExtraMagazinesToInventory(weaponMods: Item[], weaponTemplate: ITemplateItem, magCounts: MinMax, ammoTpl: string, inventory: PmcInventory, botRole: string): void; - /** - * Create a magazine using the parameters given - * @param magazineTpl Tpl of the magazine to create - * @param ammoTpl Ammo to add to magazine - * @param magTemplate template object of magazine - * @returns Item array - */ - protected createMagazine(magazineTpl: string, ammoTpl: string, magTemplate: ITemplateItem): Item[]; - /** - * Get a randomised number of bullets for a specific magazine - * @param magCounts min and max count of magazines - * @param magTemplate magazine to generate bullet count for - * @returns bullet count number - */ - protected getRandomisedBulletCount(magCounts: MinMax, magTemplate: ITemplateItem): number; - /** - * Get a randomised count of magazines - * @param magCounts min and max value returned value can be between - * @returns numberical value of magazine count - */ - protected getRandomisedMagazineCount(magCounts: MinMax): number; + addExtraMagazinesToInventory(generatedWeaponResult: GenerateWeaponResult, magCounts: MinMax, inventory: PmcInventory, botRole: string): void; /** * Add ammo to the secure container * @param stackCount How many stacks of ammo to add @@ -131,13 +111,6 @@ export declare class BotWeaponGenerator { * @returns magazine tpl string */ protected getMagazineTplFromWeaponTemplate(weaponMods: Item[], weaponTemplate: ITemplateItem, botRole: string): string; - /** - * Get a weapons default magazine template id - * @param weaponTemplate weapon to get default magazine for - * @returns tpl of magazine - */ - protected getWeaponsDefaultMagazineTpl(weaponTemplate: ITemplateItem): string; - protected addBulletsToVestAndPockets(ammoTpl: string, bulletCount: number, inventory: PmcInventory): void; /** * Finds and return a compatible ammo tpl based on the bots ammo weightings (x.json/inventory/equipment/ammo) * @param ammo a list of ammo tpls the weapon can use diff --git a/TypeScript/14AfterDBLoadHook/types/generators/weapongen/IInventoryMagGen.d.ts b/TypeScript/14AfterDBLoadHook/types/generators/weapongen/IInventoryMagGen.d.ts new file mode 100644 index 0000000..792f510 --- /dev/null +++ b/TypeScript/14AfterDBLoadHook/types/generators/weapongen/IInventoryMagGen.d.ts @@ -0,0 +1,6 @@ +import { InventoryMagGen } from "./InventoryMagGen"; +export interface IInventoryMagGen { + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/14AfterDBLoadHook/types/generators/weapongen/InventoryMagGen.d.ts b/TypeScript/14AfterDBLoadHook/types/generators/weapongen/InventoryMagGen.d.ts new file mode 100644 index 0000000..30bf79f --- /dev/null +++ b/TypeScript/14AfterDBLoadHook/types/generators/weapongen/InventoryMagGen.d.ts @@ -0,0 +1,16 @@ +import { MinMax } from "../../models/common/MinMax"; +import { Inventory } from "../../models/eft/common/tables/IBotBase"; +import { ITemplateItem } from "../../models/eft/common/tables/ITemplateItem"; +export declare class InventoryMagGen { + private magCounts; + private magazineTemplate; + private weaponTemplate; + private ammoTemplate; + private pmcInventory; + constructor(magCounts: MinMax, magazineTemplate: ITemplateItem, weaponTemplate: ITemplateItem, ammoTemplate: ITemplateItem, pmcInventory: Inventory); + getMagCount(): MinMax; + getMagazineTemplate(): ITemplateItem; + getWeaponTemplate(): ITemplateItem; + getAmmoTemplate(): ITemplateItem; + getPmcInventory(): Inventory; +} diff --git a/TypeScript/14AfterDBLoadHook/types/generators/weapongen/implementations/BarrelInventoryMagGen.d.ts b/TypeScript/14AfterDBLoadHook/types/generators/weapongen/implementations/BarrelInventoryMagGen.d.ts new file mode 100644 index 0000000..b754d5f --- /dev/null +++ b/TypeScript/14AfterDBLoadHook/types/generators/weapongen/implementations/BarrelInventoryMagGen.d.ts @@ -0,0 +1,12 @@ +import { BotWeaponGeneratorHelper } from "../../../helpers/BotWeaponGeneratorHelper"; +import { RandomUtil } from "../../../utils/RandomUtil"; +import { IInventoryMagGen } from "../IInventoryMagGen"; +import { InventoryMagGen } from "../InventoryMagGen"; +export declare class BarrelInventoryMagGen implements IInventoryMagGen { + protected randomUtil: RandomUtil; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + constructor(randomUtil: RandomUtil, botWeaponGeneratorHelper: BotWeaponGeneratorHelper); + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/14AfterDBLoadHook/types/generators/weapongen/implementations/ExternalInventoryMagGen.d.ts b/TypeScript/14AfterDBLoadHook/types/generators/weapongen/implementations/ExternalInventoryMagGen.d.ts new file mode 100644 index 0000000..4fcb1e2 --- /dev/null +++ b/TypeScript/14AfterDBLoadHook/types/generators/weapongen/implementations/ExternalInventoryMagGen.d.ts @@ -0,0 +1,14 @@ +import { BotWeaponGeneratorHelper } from "../../../helpers/BotWeaponGeneratorHelper"; +import { ItemHelper } from "../../../helpers/ItemHelper"; +import { ILogger } from "../../../models/spt/utils/ILogger"; +import { IInventoryMagGen } from "../IInventoryMagGen"; +import { InventoryMagGen } from "../InventoryMagGen"; +export declare class ExternalInventoryMagGen implements IInventoryMagGen { + protected logger: ILogger; + protected itemHelper: ItemHelper; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + constructor(logger: ILogger, itemHelper: ItemHelper, botWeaponGeneratorHelper: BotWeaponGeneratorHelper); + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/14AfterDBLoadHook/types/generators/weapongen/implementations/InternalMagazineInventoryMagGen.d.ts b/TypeScript/14AfterDBLoadHook/types/generators/weapongen/implementations/InternalMagazineInventoryMagGen.d.ts new file mode 100644 index 0000000..4548a04 --- /dev/null +++ b/TypeScript/14AfterDBLoadHook/types/generators/weapongen/implementations/InternalMagazineInventoryMagGen.d.ts @@ -0,0 +1,10 @@ +import { BotWeaponGeneratorHelper } from "../../../helpers/BotWeaponGeneratorHelper"; +import { IInventoryMagGen } from "../IInventoryMagGen"; +import { InventoryMagGen } from "../InventoryMagGen"; +export declare class InternalMagazineInventoryMagGen implements IInventoryMagGen { + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + constructor(botWeaponGeneratorHelper: BotWeaponGeneratorHelper); + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/14AfterDBLoadHook/types/helpers/BotGeneratorHelper.d.ts b/TypeScript/14AfterDBLoadHook/types/helpers/BotGeneratorHelper.d.ts index 09e5c8f..5e3e501 100644 --- a/TypeScript/14AfterDBLoadHook/types/helpers/BotGeneratorHelper.d.ts +++ b/TypeScript/14AfterDBLoadHook/types/helpers/BotGeneratorHelper.d.ts @@ -1,8 +1,7 @@ import { DurabilityLimitsHelper } from "../helpers/DurabilityLimitsHelper"; -import { Inventory as PmcInventory } from "../models/eft/common/tables/IBotBase"; import { Mods, ModsChances } from "../models/eft/common/tables/IBotType"; import { Item, Repairable, Upd } from "../models/eft/common/tables/IItem"; -import { Grid, ITemplateItem, Slot } from "../models/eft/common/tables/ITemplateItem"; +import { ITemplateItem, Slot } from "../models/eft/common/tables/ITemplateItem"; import { EquipmentFilterDetails, IBotConfig } from "../models/spt/config/IBotConfig"; import { ILogger } from "../models/spt/utils/ILogger"; import { ConfigServer } from "../servers/ConfigServer"; @@ -12,6 +11,7 @@ import { ItemFilterService } from "../services/ItemFilterService"; import { HashUtil } from "../utils/HashUtil"; import { JsonUtil } from "../utils/JsonUtil"; import { RandomUtil } from "../utils/RandomUtil"; +import { BotWeaponGeneratorHelper } from "./BotWeaponGeneratorHelper"; import { ContainerHelper } from "./ContainerHelper"; import { InventoryHelper } from "./InventoryHelper"; import { ItemHelper } from "./ItemHelper"; @@ -42,11 +42,11 @@ export declare class BotGeneratorHelper { protected botEquipmentFilterService: BotEquipmentFilterService; protected itemFilterService: ItemFilterService; protected profileHelper: ProfileHelper; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; protected configServer: ConfigServer; protected botConfig: IBotConfig; - constructor(logger: ILogger, jsonUtil: JsonUtil, hashUtil: HashUtil, randomUtil: RandomUtil, probabilityHelper: ProbabilityHelper, databaseServer: DatabaseServer, durabilityLimitsHelper: DurabilityLimitsHelper, itemHelper: ItemHelper, inventoryHelper: InventoryHelper, containerHelper: ContainerHelper, botEquipmentFilterService: BotEquipmentFilterService, itemFilterService: ItemFilterService, profileHelper: ProfileHelper, configServer: ConfigServer); + constructor(logger: ILogger, jsonUtil: JsonUtil, hashUtil: HashUtil, randomUtil: RandomUtil, probabilityHelper: ProbabilityHelper, databaseServer: DatabaseServer, durabilityLimitsHelper: DurabilityLimitsHelper, itemHelper: ItemHelper, inventoryHelper: InventoryHelper, containerHelper: ContainerHelper, botEquipmentFilterService: BotEquipmentFilterService, itemFilterService: ItemFilterService, profileHelper: ProfileHelper, botWeaponGeneratorHelper: BotWeaponGeneratorHelper, configServer: ConfigServer); /** - * TODO - very similar to generateModsForWeapon * Check mods are compatible and add to array * @param equipment Equipment item to add mods to * @param modPool Mod list to choose frm @@ -57,18 +57,30 @@ export declare class BotGeneratorHelper { */ generateModsForEquipment(equipment: Item[], modPool: Mods, parentId: string, parentTemplate: ITemplateItem, modSpawnChances: ModsChances): Item[]; /** - * TODO - very similar to generateModsForEquipment * @param sessionId session id * @param weapon Weapon to add mods to - * @param modPool pool of compatible mods to attach to gun + * @param modPool Pool of compatible mods to attach to weapon * @param weaponParentId parentId of weapon - * @param parentTemplate - * @param modSpawnChances - * @param ammoTpl ammo tpl to use when generating magazines/cartridges - * @param botRole role of bot weapon is generated for - * @returns Weapon with mods + * @param parentWeaponTemplate Weapon which mods will be generated on + * @param modSpawnChances Mod spawn chances + * @param ammoTpl Ammo tpl to use when generating magazines/cartridges + * @param botRole Role of bot weapon is generated for + * @returns Weapon + mods array */ - generateModsForWeapon(sessionId: string, weapon: Item[], modPool: Mods, weaponParentId: string, parentTemplate: ITemplateItem, modSpawnChances: ModsChances, ammoTpl: string, botRole: string): Item[]; + generateModsForWeapon(sessionId: string, weapon: Item[], modPool: Mods, weaponParentId: string, parentWeaponTemplate: ITemplateItem, modSpawnChances: ModsChances, ammoTpl: string, botRole: string): Item[]; + /** + * + * @param modSlot + * @param isRandomisableSlot + * @param modsParent + * @param botEquipBlacklist + * @param itemModPool + * @param weapon array with only weapon tpl in it, ready for mods to be added + * @param ammoTpl ammo tpl to use if slot requires a cartridge to be added (e.g. mod_magazine) + * @param parentTemplate + * @returns + */ + protected chooseModToPutIntoSlot(modSlot: string, isRandomisableSlot: boolean, modsParent: Slot, botEquipBlacklist: EquipmentFilterDetails, itemModPool: Record, weapon: Item[], ammoTpl: string, parentTemplate: ITemplateItem): [boolean, ITemplateItem]; /** * Find mod tpls of a provided type and add to modPool * @param desiredSlotName slot to look up and add we are adding tpls for (e.g mod_scope) @@ -79,15 +91,15 @@ export declare class BotGeneratorHelper { /** * Check if mod item is on limited list + has surpassed the limit set for it * @param botRole role the bot has e.g. assault - * @param modTpl mods tpl + * @param modTemplate mods template data * @param modLimits limits set for weapon being generated for this bot * @returns true if over item limit */ - protected modHasReachedItemLimit(botRole: string, modTpl: string, modLimits: BotModLimits): boolean; + protected modHasReachedItemLimit(botRole: string, modTemplate: ITemplateItem, modLimits: BotModLimits): boolean; /** - * Initalise mod limits to be used when generating the weapon + * Initalise mod limits to be used when generating a weapon * @param botRole "assault", "bossTagilla" or "pmc" - * @returns + * @returns BotModLimits object */ protected initModLimits(botRole: string): BotModLimits; /** @@ -114,7 +126,7 @@ export declare class BotGeneratorHelper { protected filterWeaponModsByBlacklist(allowedMods: string[], botEquipBlacklist: EquipmentFilterDetails, modSlot: string): string[]; /** * Check if the specific item type on the weapon has reached the set limit - * @param modTpl item to check is limited + * @param modTpl log mod tpl if over type limit * @param currentCount current number of this item on gun * @param maxLimit mod limit allowed * @param botRole role of bot we're checking weapon of @@ -124,16 +136,14 @@ export declare class BotGeneratorHelper { count: number; }, maxLimit: number, botRole: string): boolean; /** - * log errors if mod is not valid for a slot - * @param modTpl - * @param found - * @param itemSlot - * @param modTemplate - * @param modSlot - * @param parentTemplate + * Log errors if mod is not compatible with slot + * @param modToAdd template of mod to check + * @param itemSlot slot the item will be placed in + * @param modSlot slot the mod will fill + * @param parentTemplate tempalte of the mods parent item * @returns true if valid */ - protected isModValidForSlot(modTpl: string, found: boolean, itemSlot: Slot, modTemplate: ITemplateItem, modSlot: string, parentTemplate: ITemplateItem): boolean; + protected isModValidForSlot(modToAdd: [boolean, ITemplateItem], itemSlot: Slot, modSlot: string, parentTemplate: ITemplateItem): boolean; /** * Create a mod item with parameters as properties * @param modId _id @@ -144,12 +154,6 @@ export declare class BotGeneratorHelper { * @returns Item object */ protected createModItem(modId: string, modTpl: string, parentId: string, modSlot: string, modTemplate: ITemplateItem): Item; - /** - * Is this magazine cylinder related (revolvers and grenade launchers) - * @param magazineParentName the name of the magazines parent - * @returns true if it is cylinder related - */ - magazineIsCylinderRelated(magazineParentName: string): boolean; /** * randomly choose if a mod should be spawned, 100% for required mods OR mod is ammo slot * never return true for an item that has 0% spawn chance @@ -161,7 +165,7 @@ export declare class BotGeneratorHelper { protected shouldModBeSpawned(itemSlot: Slot, modSlot: string, modSpawnChances: ModsChances): boolean; /** * Get a list of containers that hold ammo - * e.g. mod_magazine + * e.g. mod_magazine / patron_in_weapon_000 * @returns string array */ protected getAmmoContainers(): string[]; @@ -214,6 +218,14 @@ export declare class BotGeneratorHelper { * @returns Repairable object */ protected generateArmorRepairableProperties(itemTemplate: ITemplateItem, botRole: string): Repairable; + /** + * Get a random mod from an items compatible mods Filter array + * @param modTpl + * @param parentSlot + * @param modSlot + * @param items + * @returns item tpl + */ protected getModTplFromItemDb(modTpl: string, parentSlot: Slot, modSlot: string, items: Item[]): string; /** * Can an item be added to an item without issue @@ -223,23 +235,6 @@ export declare class BotGeneratorHelper { * @returns true if possible */ isItemIncompatibleWithCurrentItems(items: Item[], tplToCheck: string, equipmentSlot: string): boolean; - /** - * Adds an item with all its childern into specified equipmentSlots, wherever it fits. - * @param equipmentSlots - * @param parentId - * @param parentTpl - * @param itemWithChildren - * @param inventory - * @returns a `boolean` indicating item was added - */ - addItemWithChildrenToEquipmentSlot(equipmentSlots: string[], parentId: string, parentTpl: string, itemWithChildren: Item[], inventory: PmcInventory): boolean; - /** - * is the provided item allowed inside a container - * @param slot location item wants to be placed in - * @param itemTpl item being placed - * @returns true if allowed - */ - protected itemAllowedInContainer(slot: Grid, itemTpl: string): boolean; } /** TODO - move into own class */ export declare class ExhaustableArray { diff --git a/TypeScript/14AfterDBLoadHook/types/helpers/BotWeaponGeneratorHelper.d.ts b/TypeScript/14AfterDBLoadHook/types/helpers/BotWeaponGeneratorHelper.d.ts new file mode 100644 index 0000000..7e25f56 --- /dev/null +++ b/TypeScript/14AfterDBLoadHook/types/helpers/BotWeaponGeneratorHelper.d.ts @@ -0,0 +1,78 @@ +import { MinMax } from "../models/common/MinMax"; +import { Inventory } from "../models/eft/common/tables/IBotBase"; +import { Item } from "../models/eft/common/tables/IItem"; +import { Grid, ITemplateItem } from "../models/eft/common/tables/ITemplateItem"; +import { ILogger } from "../models/spt/utils/ILogger"; +import { DatabaseServer } from "../servers/DatabaseServer"; +import { HashUtil } from "../utils/HashUtil"; +import { RandomUtil } from "../utils/RandomUtil"; +import { ContainerHelper } from "./ContainerHelper"; +import { InventoryHelper } from "./InventoryHelper"; +import { ItemHelper } from "./ItemHelper"; +export declare class BotWeaponGeneratorHelper { + protected logger: ILogger; + protected databaseServer: DatabaseServer; + protected itemHelper: ItemHelper; + protected randomUtil: RandomUtil; + protected hashUtil: HashUtil; + protected inventoryHelper: InventoryHelper; + protected containerHelper: ContainerHelper; + constructor(logger: ILogger, databaseServer: DatabaseServer, itemHelper: ItemHelper, randomUtil: RandomUtil, hashUtil: HashUtil, inventoryHelper: InventoryHelper, containerHelper: ContainerHelper); + /** + * Get a randomised number of bullets for a specific magazine + * @param magCounts min and max count of magazines + * @param magTemplate magazine to generate bullet count for + * @returns bullet count number + */ + getRandomisedBulletCount(magCounts: MinMax, magTemplate: ITemplateItem): number; + /** + * Get a randomised count of magazines + * @param magCounts min and max value returned value can be between + * @returns numberical value of magazine count + */ + getRandomisedMagazineCount(magCounts: MinMax): number; + /** + * Is this magazine cylinder related (revolvers and grenade launchers) + * @param magazineParentName the name of the magazines parent + * @returns true if it is cylinder related + */ + magazineIsCylinderRelated(magazineParentName: string): boolean; + /** + * Create a magazine using the parameters given + * @param magazineTpl Tpl of the magazine to create + * @param ammoTpl Ammo to add to magazine + * @param magTemplate template object of magazine + * @returns Item array + */ + createMagazine(magazineTpl: string, ammoTpl: string, magTemplate: ITemplateItem): Item[]; + /** + * Add a specific number of cartrdiges to a bots inventory (vest/pocket) + * @param ammoTpl Ammo tpl to add to vest/pockets + * @param cartridgeCount number of cartridges to add to vest/pockets + * @param inventory bot inventory to add cartridges to + */ + addBulletsToVestAndPockets(ammoTpl: string, cartridgeCount: number, inventory: Inventory): void; + /** + * Get a weapons default magazine template id + * @param weaponTemplate weapon to get default magazine for + * @returns tpl of magazine + */ + getWeaponsDefaultMagazineTpl(weaponTemplate: ITemplateItem): string; + /** + * Adds an item with all its childern into specified equipmentSlots, wherever it fits. + * @param equipmentSlots + * @param parentId + * @param parentTpl + * @param itemWithChildren + * @param inventory + * @returns a `boolean` indicating item was added + */ + addItemWithChildrenToEquipmentSlot(equipmentSlots: string[], parentId: string, parentTpl: string, itemWithChildren: Item[], inventory: Inventory): boolean; + /** + * is the provided item allowed inside a container + * @param slot location item wants to be placed in + * @param itemTpl item being placed + * @returns true if allowed + */ + protected itemAllowedInContainer(slot: Grid, itemTpl: string): boolean; +} diff --git a/TypeScript/1LogToConsole/package.json b/TypeScript/1LogToConsole/package.json index 2f6826d..dcfe59b 100644 --- a/TypeScript/1LogToConsole/package.json +++ b/TypeScript/1LogToConsole/package.json @@ -4,7 +4,7 @@ "main": "src/mod.js", "license": "MIT", "author": "Chomp", - "akiVersion": "3.2.2", + "akiVersion": "3.2.3", "scripts": { "setup": "npm i", "build": "node ./packageBuild.ts" diff --git a/TypeScript/1LogToConsole/types/generators/BotLootGenerator.d.ts b/TypeScript/1LogToConsole/types/generators/BotLootGenerator.d.ts index 5a2d144..c1f5310 100644 --- a/TypeScript/1LogToConsole/types/generators/BotLootGenerator.d.ts +++ b/TypeScript/1LogToConsole/types/generators/BotLootGenerator.d.ts @@ -1,4 +1,5 @@ import { BotGeneratorHelper } from "../helpers/BotGeneratorHelper"; +import { BotWeaponGeneratorHelper } from "../helpers/BotWeaponGeneratorHelper"; import { HandbookHelper } from "../helpers/HandbookHelper"; import { Inventory as PmcInventory } from "../models/eft/common/tables/IBotBase"; import { Chances, Inventory, ItemMinMax, ModsChances } from "../models/eft/common/tables/IBotType"; @@ -20,10 +21,11 @@ export declare class BotLootGenerator { protected handbookHelper: HandbookHelper; protected botGeneratorHelper: BotGeneratorHelper; protected botWeaponGenerator: BotWeaponGenerator; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; protected botLootCacheService: BotLootCacheService; protected configServer: ConfigServer; protected botConfig: IBotConfig; - constructor(logger: ILogger, hashUtil: HashUtil, randomUtil: RandomUtil, databaseServer: DatabaseServer, handbookHelper: HandbookHelper, botGeneratorHelper: BotGeneratorHelper, botWeaponGenerator: BotWeaponGenerator, botLootCacheService: BotLootCacheService, configServer: ConfigServer); + constructor(logger: ILogger, hashUtil: HashUtil, randomUtil: RandomUtil, databaseServer: DatabaseServer, handbookHelper: HandbookHelper, botGeneratorHelper: BotGeneratorHelper, botWeaponGenerator: BotWeaponGenerator, botWeaponGeneratorHelper: BotWeaponGeneratorHelper, botLootCacheService: BotLootCacheService, configServer: ConfigServer); generateLoot(sessionId: string, templateInventory: Inventory, itemCounts: ItemMinMax, isPmc: boolean, botRole: string, botInventory: PmcInventory, equipmentChances: Chances): void; protected getRandomisedCount(min: number, max: number, nValue: number): number; /** diff --git a/TypeScript/1LogToConsole/types/generators/BotWeaponGenerator.d.ts b/TypeScript/1LogToConsole/types/generators/BotWeaponGenerator.d.ts index cba7afa..487901b 100644 --- a/TypeScript/1LogToConsole/types/generators/BotWeaponGenerator.d.ts +++ b/TypeScript/1LogToConsole/types/generators/BotWeaponGenerator.d.ts @@ -1,4 +1,5 @@ import { BotGeneratorHelper } from "../helpers/BotGeneratorHelper"; +import { BotWeaponGeneratorHelper } from "../helpers/BotWeaponGeneratorHelper"; import { ItemHelper } from "../helpers/ItemHelper"; import { WeightedRandomHelper } from "../helpers/WeightedRandomHelper"; import { MinMax } from "../models/common/MinMax"; @@ -14,6 +15,7 @@ import { DatabaseServer } from "../servers/DatabaseServer"; import { HashUtil } from "../utils/HashUtil"; import { JsonUtil } from "../utils/JsonUtil"; import { RandomUtil } from "../utils/RandomUtil"; +import { IInventoryMagGen } from "./weapongen/IInventoryMagGen"; export declare class BotWeaponGenerator { protected jsonUtil: JsonUtil; protected logger: ILogger; @@ -24,9 +26,11 @@ export declare class BotWeaponGenerator { protected botGeneratorHelper: BotGeneratorHelper; protected randomUtil: RandomUtil; protected configServer: ConfigServer; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + protected inventoryMagGenComponents: IInventoryMagGen[]; protected readonly modMagazineSlotId = "mod_magazine"; protected botConfig: IBotConfig; - constructor(jsonUtil: JsonUtil, logger: ILogger, hashUtil: HashUtil, databaseServer: DatabaseServer, itemHelper: ItemHelper, weightedRandomHelper: WeightedRandomHelper, botGeneratorHelper: BotGeneratorHelper, randomUtil: RandomUtil, configServer: ConfigServer); + constructor(jsonUtil: JsonUtil, logger: ILogger, hashUtil: HashUtil, databaseServer: DatabaseServer, itemHelper: ItemHelper, weightedRandomHelper: WeightedRandomHelper, botGeneratorHelper: BotGeneratorHelper, randomUtil: RandomUtil, configServer: ConfigServer, botWeaponGeneratorHelper: BotWeaponGeneratorHelper, inventoryMagGenComponents: IInventoryMagGen[]); /** * Pick a random weapon based on weightings and generate a functional weapon * @param equipmentSlot Primary/secondary/holster @@ -85,36 +89,12 @@ export declare class BotWeaponGenerator { /** * Generates extra magazines or bullets (if magazine is internal) and adds them to TacticalVest and Pockets. * Additionally, adds extra bullets to SecuredContainer - * @param weaponMods mods to attach to weapon - * @param weaponTemplate db template for weapon - * @param magCounts magazine count to add to inventory - * @param ammoTpl ammo templateId to add to magazines - * @param inventory inventory to add magazines to - * @param botRole the bot type we're getting generating extra mags for - * @returns + * @param generatedWeaponResult object with properties for generated weapon (weapon mods pool / weapon template / ammo tpl) + * @param magCounts Magazine count to add to inventory + * @param inventory Inventory to add magazines to + * @param botRole The bot type we're getting generating extra mags for */ - addExtraMagazinesToInventory(weaponMods: Item[], weaponTemplate: ITemplateItem, magCounts: MinMax, ammoTpl: string, inventory: PmcInventory, botRole: string): void; - /** - * Create a magazine using the parameters given - * @param magazineTpl Tpl of the magazine to create - * @param ammoTpl Ammo to add to magazine - * @param magTemplate template object of magazine - * @returns Item array - */ - protected createMagazine(magazineTpl: string, ammoTpl: string, magTemplate: ITemplateItem): Item[]; - /** - * Get a randomised number of bullets for a specific magazine - * @param magCounts min and max count of magazines - * @param magTemplate magazine to generate bullet count for - * @returns bullet count number - */ - protected getRandomisedBulletCount(magCounts: MinMax, magTemplate: ITemplateItem): number; - /** - * Get a randomised count of magazines - * @param magCounts min and max value returned value can be between - * @returns numberical value of magazine count - */ - protected getRandomisedMagazineCount(magCounts: MinMax): number; + addExtraMagazinesToInventory(generatedWeaponResult: GenerateWeaponResult, magCounts: MinMax, inventory: PmcInventory, botRole: string): void; /** * Add ammo to the secure container * @param stackCount How many stacks of ammo to add @@ -131,13 +111,6 @@ export declare class BotWeaponGenerator { * @returns magazine tpl string */ protected getMagazineTplFromWeaponTemplate(weaponMods: Item[], weaponTemplate: ITemplateItem, botRole: string): string; - /** - * Get a weapons default magazine template id - * @param weaponTemplate weapon to get default magazine for - * @returns tpl of magazine - */ - protected getWeaponsDefaultMagazineTpl(weaponTemplate: ITemplateItem): string; - protected addBulletsToVestAndPockets(ammoTpl: string, bulletCount: number, inventory: PmcInventory): void; /** * Finds and return a compatible ammo tpl based on the bots ammo weightings (x.json/inventory/equipment/ammo) * @param ammo a list of ammo tpls the weapon can use diff --git a/TypeScript/1LogToConsole/types/generators/weapongen/IInventoryMagGen.d.ts b/TypeScript/1LogToConsole/types/generators/weapongen/IInventoryMagGen.d.ts new file mode 100644 index 0000000..792f510 --- /dev/null +++ b/TypeScript/1LogToConsole/types/generators/weapongen/IInventoryMagGen.d.ts @@ -0,0 +1,6 @@ +import { InventoryMagGen } from "./InventoryMagGen"; +export interface IInventoryMagGen { + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/1LogToConsole/types/generators/weapongen/InventoryMagGen.d.ts b/TypeScript/1LogToConsole/types/generators/weapongen/InventoryMagGen.d.ts new file mode 100644 index 0000000..30bf79f --- /dev/null +++ b/TypeScript/1LogToConsole/types/generators/weapongen/InventoryMagGen.d.ts @@ -0,0 +1,16 @@ +import { MinMax } from "../../models/common/MinMax"; +import { Inventory } from "../../models/eft/common/tables/IBotBase"; +import { ITemplateItem } from "../../models/eft/common/tables/ITemplateItem"; +export declare class InventoryMagGen { + private magCounts; + private magazineTemplate; + private weaponTemplate; + private ammoTemplate; + private pmcInventory; + constructor(magCounts: MinMax, magazineTemplate: ITemplateItem, weaponTemplate: ITemplateItem, ammoTemplate: ITemplateItem, pmcInventory: Inventory); + getMagCount(): MinMax; + getMagazineTemplate(): ITemplateItem; + getWeaponTemplate(): ITemplateItem; + getAmmoTemplate(): ITemplateItem; + getPmcInventory(): Inventory; +} diff --git a/TypeScript/1LogToConsole/types/generators/weapongen/implementations/BarrelInventoryMagGen.d.ts b/TypeScript/1LogToConsole/types/generators/weapongen/implementations/BarrelInventoryMagGen.d.ts new file mode 100644 index 0000000..b754d5f --- /dev/null +++ b/TypeScript/1LogToConsole/types/generators/weapongen/implementations/BarrelInventoryMagGen.d.ts @@ -0,0 +1,12 @@ +import { BotWeaponGeneratorHelper } from "../../../helpers/BotWeaponGeneratorHelper"; +import { RandomUtil } from "../../../utils/RandomUtil"; +import { IInventoryMagGen } from "../IInventoryMagGen"; +import { InventoryMagGen } from "../InventoryMagGen"; +export declare class BarrelInventoryMagGen implements IInventoryMagGen { + protected randomUtil: RandomUtil; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + constructor(randomUtil: RandomUtil, botWeaponGeneratorHelper: BotWeaponGeneratorHelper); + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/1LogToConsole/types/generators/weapongen/implementations/ExternalInventoryMagGen.d.ts b/TypeScript/1LogToConsole/types/generators/weapongen/implementations/ExternalInventoryMagGen.d.ts new file mode 100644 index 0000000..4fcb1e2 --- /dev/null +++ b/TypeScript/1LogToConsole/types/generators/weapongen/implementations/ExternalInventoryMagGen.d.ts @@ -0,0 +1,14 @@ +import { BotWeaponGeneratorHelper } from "../../../helpers/BotWeaponGeneratorHelper"; +import { ItemHelper } from "../../../helpers/ItemHelper"; +import { ILogger } from "../../../models/spt/utils/ILogger"; +import { IInventoryMagGen } from "../IInventoryMagGen"; +import { InventoryMagGen } from "../InventoryMagGen"; +export declare class ExternalInventoryMagGen implements IInventoryMagGen { + protected logger: ILogger; + protected itemHelper: ItemHelper; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + constructor(logger: ILogger, itemHelper: ItemHelper, botWeaponGeneratorHelper: BotWeaponGeneratorHelper); + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/1LogToConsole/types/generators/weapongen/implementations/InternalMagazineInventoryMagGen.d.ts b/TypeScript/1LogToConsole/types/generators/weapongen/implementations/InternalMagazineInventoryMagGen.d.ts new file mode 100644 index 0000000..4548a04 --- /dev/null +++ b/TypeScript/1LogToConsole/types/generators/weapongen/implementations/InternalMagazineInventoryMagGen.d.ts @@ -0,0 +1,10 @@ +import { BotWeaponGeneratorHelper } from "../../../helpers/BotWeaponGeneratorHelper"; +import { IInventoryMagGen } from "../IInventoryMagGen"; +import { InventoryMagGen } from "../InventoryMagGen"; +export declare class InternalMagazineInventoryMagGen implements IInventoryMagGen { + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + constructor(botWeaponGeneratorHelper: BotWeaponGeneratorHelper); + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/1LogToConsole/types/helpers/BotGeneratorHelper.d.ts b/TypeScript/1LogToConsole/types/helpers/BotGeneratorHelper.d.ts index 09e5c8f..5e3e501 100644 --- a/TypeScript/1LogToConsole/types/helpers/BotGeneratorHelper.d.ts +++ b/TypeScript/1LogToConsole/types/helpers/BotGeneratorHelper.d.ts @@ -1,8 +1,7 @@ import { DurabilityLimitsHelper } from "../helpers/DurabilityLimitsHelper"; -import { Inventory as PmcInventory } from "../models/eft/common/tables/IBotBase"; import { Mods, ModsChances } from "../models/eft/common/tables/IBotType"; import { Item, Repairable, Upd } from "../models/eft/common/tables/IItem"; -import { Grid, ITemplateItem, Slot } from "../models/eft/common/tables/ITemplateItem"; +import { ITemplateItem, Slot } from "../models/eft/common/tables/ITemplateItem"; import { EquipmentFilterDetails, IBotConfig } from "../models/spt/config/IBotConfig"; import { ILogger } from "../models/spt/utils/ILogger"; import { ConfigServer } from "../servers/ConfigServer"; @@ -12,6 +11,7 @@ import { ItemFilterService } from "../services/ItemFilterService"; import { HashUtil } from "../utils/HashUtil"; import { JsonUtil } from "../utils/JsonUtil"; import { RandomUtil } from "../utils/RandomUtil"; +import { BotWeaponGeneratorHelper } from "./BotWeaponGeneratorHelper"; import { ContainerHelper } from "./ContainerHelper"; import { InventoryHelper } from "./InventoryHelper"; import { ItemHelper } from "./ItemHelper"; @@ -42,11 +42,11 @@ export declare class BotGeneratorHelper { protected botEquipmentFilterService: BotEquipmentFilterService; protected itemFilterService: ItemFilterService; protected profileHelper: ProfileHelper; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; protected configServer: ConfigServer; protected botConfig: IBotConfig; - constructor(logger: ILogger, jsonUtil: JsonUtil, hashUtil: HashUtil, randomUtil: RandomUtil, probabilityHelper: ProbabilityHelper, databaseServer: DatabaseServer, durabilityLimitsHelper: DurabilityLimitsHelper, itemHelper: ItemHelper, inventoryHelper: InventoryHelper, containerHelper: ContainerHelper, botEquipmentFilterService: BotEquipmentFilterService, itemFilterService: ItemFilterService, profileHelper: ProfileHelper, configServer: ConfigServer); + constructor(logger: ILogger, jsonUtil: JsonUtil, hashUtil: HashUtil, randomUtil: RandomUtil, probabilityHelper: ProbabilityHelper, databaseServer: DatabaseServer, durabilityLimitsHelper: DurabilityLimitsHelper, itemHelper: ItemHelper, inventoryHelper: InventoryHelper, containerHelper: ContainerHelper, botEquipmentFilterService: BotEquipmentFilterService, itemFilterService: ItemFilterService, profileHelper: ProfileHelper, botWeaponGeneratorHelper: BotWeaponGeneratorHelper, configServer: ConfigServer); /** - * TODO - very similar to generateModsForWeapon * Check mods are compatible and add to array * @param equipment Equipment item to add mods to * @param modPool Mod list to choose frm @@ -57,18 +57,30 @@ export declare class BotGeneratorHelper { */ generateModsForEquipment(equipment: Item[], modPool: Mods, parentId: string, parentTemplate: ITemplateItem, modSpawnChances: ModsChances): Item[]; /** - * TODO - very similar to generateModsForEquipment * @param sessionId session id * @param weapon Weapon to add mods to - * @param modPool pool of compatible mods to attach to gun + * @param modPool Pool of compatible mods to attach to weapon * @param weaponParentId parentId of weapon - * @param parentTemplate - * @param modSpawnChances - * @param ammoTpl ammo tpl to use when generating magazines/cartridges - * @param botRole role of bot weapon is generated for - * @returns Weapon with mods + * @param parentWeaponTemplate Weapon which mods will be generated on + * @param modSpawnChances Mod spawn chances + * @param ammoTpl Ammo tpl to use when generating magazines/cartridges + * @param botRole Role of bot weapon is generated for + * @returns Weapon + mods array */ - generateModsForWeapon(sessionId: string, weapon: Item[], modPool: Mods, weaponParentId: string, parentTemplate: ITemplateItem, modSpawnChances: ModsChances, ammoTpl: string, botRole: string): Item[]; + generateModsForWeapon(sessionId: string, weapon: Item[], modPool: Mods, weaponParentId: string, parentWeaponTemplate: ITemplateItem, modSpawnChances: ModsChances, ammoTpl: string, botRole: string): Item[]; + /** + * + * @param modSlot + * @param isRandomisableSlot + * @param modsParent + * @param botEquipBlacklist + * @param itemModPool + * @param weapon array with only weapon tpl in it, ready for mods to be added + * @param ammoTpl ammo tpl to use if slot requires a cartridge to be added (e.g. mod_magazine) + * @param parentTemplate + * @returns + */ + protected chooseModToPutIntoSlot(modSlot: string, isRandomisableSlot: boolean, modsParent: Slot, botEquipBlacklist: EquipmentFilterDetails, itemModPool: Record, weapon: Item[], ammoTpl: string, parentTemplate: ITemplateItem): [boolean, ITemplateItem]; /** * Find mod tpls of a provided type and add to modPool * @param desiredSlotName slot to look up and add we are adding tpls for (e.g mod_scope) @@ -79,15 +91,15 @@ export declare class BotGeneratorHelper { /** * Check if mod item is on limited list + has surpassed the limit set for it * @param botRole role the bot has e.g. assault - * @param modTpl mods tpl + * @param modTemplate mods template data * @param modLimits limits set for weapon being generated for this bot * @returns true if over item limit */ - protected modHasReachedItemLimit(botRole: string, modTpl: string, modLimits: BotModLimits): boolean; + protected modHasReachedItemLimit(botRole: string, modTemplate: ITemplateItem, modLimits: BotModLimits): boolean; /** - * Initalise mod limits to be used when generating the weapon + * Initalise mod limits to be used when generating a weapon * @param botRole "assault", "bossTagilla" or "pmc" - * @returns + * @returns BotModLimits object */ protected initModLimits(botRole: string): BotModLimits; /** @@ -114,7 +126,7 @@ export declare class BotGeneratorHelper { protected filterWeaponModsByBlacklist(allowedMods: string[], botEquipBlacklist: EquipmentFilterDetails, modSlot: string): string[]; /** * Check if the specific item type on the weapon has reached the set limit - * @param modTpl item to check is limited + * @param modTpl log mod tpl if over type limit * @param currentCount current number of this item on gun * @param maxLimit mod limit allowed * @param botRole role of bot we're checking weapon of @@ -124,16 +136,14 @@ export declare class BotGeneratorHelper { count: number; }, maxLimit: number, botRole: string): boolean; /** - * log errors if mod is not valid for a slot - * @param modTpl - * @param found - * @param itemSlot - * @param modTemplate - * @param modSlot - * @param parentTemplate + * Log errors if mod is not compatible with slot + * @param modToAdd template of mod to check + * @param itemSlot slot the item will be placed in + * @param modSlot slot the mod will fill + * @param parentTemplate tempalte of the mods parent item * @returns true if valid */ - protected isModValidForSlot(modTpl: string, found: boolean, itemSlot: Slot, modTemplate: ITemplateItem, modSlot: string, parentTemplate: ITemplateItem): boolean; + protected isModValidForSlot(modToAdd: [boolean, ITemplateItem], itemSlot: Slot, modSlot: string, parentTemplate: ITemplateItem): boolean; /** * Create a mod item with parameters as properties * @param modId _id @@ -144,12 +154,6 @@ export declare class BotGeneratorHelper { * @returns Item object */ protected createModItem(modId: string, modTpl: string, parentId: string, modSlot: string, modTemplate: ITemplateItem): Item; - /** - * Is this magazine cylinder related (revolvers and grenade launchers) - * @param magazineParentName the name of the magazines parent - * @returns true if it is cylinder related - */ - magazineIsCylinderRelated(magazineParentName: string): boolean; /** * randomly choose if a mod should be spawned, 100% for required mods OR mod is ammo slot * never return true for an item that has 0% spawn chance @@ -161,7 +165,7 @@ export declare class BotGeneratorHelper { protected shouldModBeSpawned(itemSlot: Slot, modSlot: string, modSpawnChances: ModsChances): boolean; /** * Get a list of containers that hold ammo - * e.g. mod_magazine + * e.g. mod_magazine / patron_in_weapon_000 * @returns string array */ protected getAmmoContainers(): string[]; @@ -214,6 +218,14 @@ export declare class BotGeneratorHelper { * @returns Repairable object */ protected generateArmorRepairableProperties(itemTemplate: ITemplateItem, botRole: string): Repairable; + /** + * Get a random mod from an items compatible mods Filter array + * @param modTpl + * @param parentSlot + * @param modSlot + * @param items + * @returns item tpl + */ protected getModTplFromItemDb(modTpl: string, parentSlot: Slot, modSlot: string, items: Item[]): string; /** * Can an item be added to an item without issue @@ -223,23 +235,6 @@ export declare class BotGeneratorHelper { * @returns true if possible */ isItemIncompatibleWithCurrentItems(items: Item[], tplToCheck: string, equipmentSlot: string): boolean; - /** - * Adds an item with all its childern into specified equipmentSlots, wherever it fits. - * @param equipmentSlots - * @param parentId - * @param parentTpl - * @param itemWithChildren - * @param inventory - * @returns a `boolean` indicating item was added - */ - addItemWithChildrenToEquipmentSlot(equipmentSlots: string[], parentId: string, parentTpl: string, itemWithChildren: Item[], inventory: PmcInventory): boolean; - /** - * is the provided item allowed inside a container - * @param slot location item wants to be placed in - * @param itemTpl item being placed - * @returns true if allowed - */ - protected itemAllowedInContainer(slot: Grid, itemTpl: string): boolean; } /** TODO - move into own class */ export declare class ExhaustableArray { diff --git a/TypeScript/1LogToConsole/types/helpers/BotWeaponGeneratorHelper.d.ts b/TypeScript/1LogToConsole/types/helpers/BotWeaponGeneratorHelper.d.ts new file mode 100644 index 0000000..7e25f56 --- /dev/null +++ b/TypeScript/1LogToConsole/types/helpers/BotWeaponGeneratorHelper.d.ts @@ -0,0 +1,78 @@ +import { MinMax } from "../models/common/MinMax"; +import { Inventory } from "../models/eft/common/tables/IBotBase"; +import { Item } from "../models/eft/common/tables/IItem"; +import { Grid, ITemplateItem } from "../models/eft/common/tables/ITemplateItem"; +import { ILogger } from "../models/spt/utils/ILogger"; +import { DatabaseServer } from "../servers/DatabaseServer"; +import { HashUtil } from "../utils/HashUtil"; +import { RandomUtil } from "../utils/RandomUtil"; +import { ContainerHelper } from "./ContainerHelper"; +import { InventoryHelper } from "./InventoryHelper"; +import { ItemHelper } from "./ItemHelper"; +export declare class BotWeaponGeneratorHelper { + protected logger: ILogger; + protected databaseServer: DatabaseServer; + protected itemHelper: ItemHelper; + protected randomUtil: RandomUtil; + protected hashUtil: HashUtil; + protected inventoryHelper: InventoryHelper; + protected containerHelper: ContainerHelper; + constructor(logger: ILogger, databaseServer: DatabaseServer, itemHelper: ItemHelper, randomUtil: RandomUtil, hashUtil: HashUtil, inventoryHelper: InventoryHelper, containerHelper: ContainerHelper); + /** + * Get a randomised number of bullets for a specific magazine + * @param magCounts min and max count of magazines + * @param magTemplate magazine to generate bullet count for + * @returns bullet count number + */ + getRandomisedBulletCount(magCounts: MinMax, magTemplate: ITemplateItem): number; + /** + * Get a randomised count of magazines + * @param magCounts min and max value returned value can be between + * @returns numberical value of magazine count + */ + getRandomisedMagazineCount(magCounts: MinMax): number; + /** + * Is this magazine cylinder related (revolvers and grenade launchers) + * @param magazineParentName the name of the magazines parent + * @returns true if it is cylinder related + */ + magazineIsCylinderRelated(magazineParentName: string): boolean; + /** + * Create a magazine using the parameters given + * @param magazineTpl Tpl of the magazine to create + * @param ammoTpl Ammo to add to magazine + * @param magTemplate template object of magazine + * @returns Item array + */ + createMagazine(magazineTpl: string, ammoTpl: string, magTemplate: ITemplateItem): Item[]; + /** + * Add a specific number of cartrdiges to a bots inventory (vest/pocket) + * @param ammoTpl Ammo tpl to add to vest/pockets + * @param cartridgeCount number of cartridges to add to vest/pockets + * @param inventory bot inventory to add cartridges to + */ + addBulletsToVestAndPockets(ammoTpl: string, cartridgeCount: number, inventory: Inventory): void; + /** + * Get a weapons default magazine template id + * @param weaponTemplate weapon to get default magazine for + * @returns tpl of magazine + */ + getWeaponsDefaultMagazineTpl(weaponTemplate: ITemplateItem): string; + /** + * Adds an item with all its childern into specified equipmentSlots, wherever it fits. + * @param equipmentSlots + * @param parentId + * @param parentTpl + * @param itemWithChildren + * @param inventory + * @returns a `boolean` indicating item was added + */ + addItemWithChildrenToEquipmentSlot(equipmentSlots: string[], parentId: string, parentTpl: string, itemWithChildren: Item[], inventory: Inventory): boolean; + /** + * is the provided item allowed inside a container + * @param slot location item wants to be placed in + * @param itemTpl item being placed + * @returns true if allowed + */ + protected itemAllowedInContainer(slot: Grid, itemTpl: string): boolean; +} diff --git a/TypeScript/2EditDatabase/package.json b/TypeScript/2EditDatabase/package.json index fc98fe3..da3ea71 100644 --- a/TypeScript/2EditDatabase/package.json +++ b/TypeScript/2EditDatabase/package.json @@ -4,7 +4,7 @@ "main": "src/mod.js", "license": "MIT", "author": "Chomp", - "akiVersion": "3.2.2", + "akiVersion": "3.2.3", "scripts": { "setup": "npm i", "build": "node ./packageBuild.ts" diff --git a/TypeScript/2EditDatabase/types/generators/BotLootGenerator.d.ts b/TypeScript/2EditDatabase/types/generators/BotLootGenerator.d.ts index 5a2d144..c1f5310 100644 --- a/TypeScript/2EditDatabase/types/generators/BotLootGenerator.d.ts +++ b/TypeScript/2EditDatabase/types/generators/BotLootGenerator.d.ts @@ -1,4 +1,5 @@ import { BotGeneratorHelper } from "../helpers/BotGeneratorHelper"; +import { BotWeaponGeneratorHelper } from "../helpers/BotWeaponGeneratorHelper"; import { HandbookHelper } from "../helpers/HandbookHelper"; import { Inventory as PmcInventory } from "../models/eft/common/tables/IBotBase"; import { Chances, Inventory, ItemMinMax, ModsChances } from "../models/eft/common/tables/IBotType"; @@ -20,10 +21,11 @@ export declare class BotLootGenerator { protected handbookHelper: HandbookHelper; protected botGeneratorHelper: BotGeneratorHelper; protected botWeaponGenerator: BotWeaponGenerator; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; protected botLootCacheService: BotLootCacheService; protected configServer: ConfigServer; protected botConfig: IBotConfig; - constructor(logger: ILogger, hashUtil: HashUtil, randomUtil: RandomUtil, databaseServer: DatabaseServer, handbookHelper: HandbookHelper, botGeneratorHelper: BotGeneratorHelper, botWeaponGenerator: BotWeaponGenerator, botLootCacheService: BotLootCacheService, configServer: ConfigServer); + constructor(logger: ILogger, hashUtil: HashUtil, randomUtil: RandomUtil, databaseServer: DatabaseServer, handbookHelper: HandbookHelper, botGeneratorHelper: BotGeneratorHelper, botWeaponGenerator: BotWeaponGenerator, botWeaponGeneratorHelper: BotWeaponGeneratorHelper, botLootCacheService: BotLootCacheService, configServer: ConfigServer); generateLoot(sessionId: string, templateInventory: Inventory, itemCounts: ItemMinMax, isPmc: boolean, botRole: string, botInventory: PmcInventory, equipmentChances: Chances): void; protected getRandomisedCount(min: number, max: number, nValue: number): number; /** diff --git a/TypeScript/2EditDatabase/types/generators/BotWeaponGenerator.d.ts b/TypeScript/2EditDatabase/types/generators/BotWeaponGenerator.d.ts index cba7afa..487901b 100644 --- a/TypeScript/2EditDatabase/types/generators/BotWeaponGenerator.d.ts +++ b/TypeScript/2EditDatabase/types/generators/BotWeaponGenerator.d.ts @@ -1,4 +1,5 @@ import { BotGeneratorHelper } from "../helpers/BotGeneratorHelper"; +import { BotWeaponGeneratorHelper } from "../helpers/BotWeaponGeneratorHelper"; import { ItemHelper } from "../helpers/ItemHelper"; import { WeightedRandomHelper } from "../helpers/WeightedRandomHelper"; import { MinMax } from "../models/common/MinMax"; @@ -14,6 +15,7 @@ import { DatabaseServer } from "../servers/DatabaseServer"; import { HashUtil } from "../utils/HashUtil"; import { JsonUtil } from "../utils/JsonUtil"; import { RandomUtil } from "../utils/RandomUtil"; +import { IInventoryMagGen } from "./weapongen/IInventoryMagGen"; export declare class BotWeaponGenerator { protected jsonUtil: JsonUtil; protected logger: ILogger; @@ -24,9 +26,11 @@ export declare class BotWeaponGenerator { protected botGeneratorHelper: BotGeneratorHelper; protected randomUtil: RandomUtil; protected configServer: ConfigServer; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + protected inventoryMagGenComponents: IInventoryMagGen[]; protected readonly modMagazineSlotId = "mod_magazine"; protected botConfig: IBotConfig; - constructor(jsonUtil: JsonUtil, logger: ILogger, hashUtil: HashUtil, databaseServer: DatabaseServer, itemHelper: ItemHelper, weightedRandomHelper: WeightedRandomHelper, botGeneratorHelper: BotGeneratorHelper, randomUtil: RandomUtil, configServer: ConfigServer); + constructor(jsonUtil: JsonUtil, logger: ILogger, hashUtil: HashUtil, databaseServer: DatabaseServer, itemHelper: ItemHelper, weightedRandomHelper: WeightedRandomHelper, botGeneratorHelper: BotGeneratorHelper, randomUtil: RandomUtil, configServer: ConfigServer, botWeaponGeneratorHelper: BotWeaponGeneratorHelper, inventoryMagGenComponents: IInventoryMagGen[]); /** * Pick a random weapon based on weightings and generate a functional weapon * @param equipmentSlot Primary/secondary/holster @@ -85,36 +89,12 @@ export declare class BotWeaponGenerator { /** * Generates extra magazines or bullets (if magazine is internal) and adds them to TacticalVest and Pockets. * Additionally, adds extra bullets to SecuredContainer - * @param weaponMods mods to attach to weapon - * @param weaponTemplate db template for weapon - * @param magCounts magazine count to add to inventory - * @param ammoTpl ammo templateId to add to magazines - * @param inventory inventory to add magazines to - * @param botRole the bot type we're getting generating extra mags for - * @returns + * @param generatedWeaponResult object with properties for generated weapon (weapon mods pool / weapon template / ammo tpl) + * @param magCounts Magazine count to add to inventory + * @param inventory Inventory to add magazines to + * @param botRole The bot type we're getting generating extra mags for */ - addExtraMagazinesToInventory(weaponMods: Item[], weaponTemplate: ITemplateItem, magCounts: MinMax, ammoTpl: string, inventory: PmcInventory, botRole: string): void; - /** - * Create a magazine using the parameters given - * @param magazineTpl Tpl of the magazine to create - * @param ammoTpl Ammo to add to magazine - * @param magTemplate template object of magazine - * @returns Item array - */ - protected createMagazine(magazineTpl: string, ammoTpl: string, magTemplate: ITemplateItem): Item[]; - /** - * Get a randomised number of bullets for a specific magazine - * @param magCounts min and max count of magazines - * @param magTemplate magazine to generate bullet count for - * @returns bullet count number - */ - protected getRandomisedBulletCount(magCounts: MinMax, magTemplate: ITemplateItem): number; - /** - * Get a randomised count of magazines - * @param magCounts min and max value returned value can be between - * @returns numberical value of magazine count - */ - protected getRandomisedMagazineCount(magCounts: MinMax): number; + addExtraMagazinesToInventory(generatedWeaponResult: GenerateWeaponResult, magCounts: MinMax, inventory: PmcInventory, botRole: string): void; /** * Add ammo to the secure container * @param stackCount How many stacks of ammo to add @@ -131,13 +111,6 @@ export declare class BotWeaponGenerator { * @returns magazine tpl string */ protected getMagazineTplFromWeaponTemplate(weaponMods: Item[], weaponTemplate: ITemplateItem, botRole: string): string; - /** - * Get a weapons default magazine template id - * @param weaponTemplate weapon to get default magazine for - * @returns tpl of magazine - */ - protected getWeaponsDefaultMagazineTpl(weaponTemplate: ITemplateItem): string; - protected addBulletsToVestAndPockets(ammoTpl: string, bulletCount: number, inventory: PmcInventory): void; /** * Finds and return a compatible ammo tpl based on the bots ammo weightings (x.json/inventory/equipment/ammo) * @param ammo a list of ammo tpls the weapon can use diff --git a/TypeScript/2EditDatabase/types/generators/weapongen/IInventoryMagGen.d.ts b/TypeScript/2EditDatabase/types/generators/weapongen/IInventoryMagGen.d.ts new file mode 100644 index 0000000..792f510 --- /dev/null +++ b/TypeScript/2EditDatabase/types/generators/weapongen/IInventoryMagGen.d.ts @@ -0,0 +1,6 @@ +import { InventoryMagGen } from "./InventoryMagGen"; +export interface IInventoryMagGen { + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/2EditDatabase/types/generators/weapongen/InventoryMagGen.d.ts b/TypeScript/2EditDatabase/types/generators/weapongen/InventoryMagGen.d.ts new file mode 100644 index 0000000..30bf79f --- /dev/null +++ b/TypeScript/2EditDatabase/types/generators/weapongen/InventoryMagGen.d.ts @@ -0,0 +1,16 @@ +import { MinMax } from "../../models/common/MinMax"; +import { Inventory } from "../../models/eft/common/tables/IBotBase"; +import { ITemplateItem } from "../../models/eft/common/tables/ITemplateItem"; +export declare class InventoryMagGen { + private magCounts; + private magazineTemplate; + private weaponTemplate; + private ammoTemplate; + private pmcInventory; + constructor(magCounts: MinMax, magazineTemplate: ITemplateItem, weaponTemplate: ITemplateItem, ammoTemplate: ITemplateItem, pmcInventory: Inventory); + getMagCount(): MinMax; + getMagazineTemplate(): ITemplateItem; + getWeaponTemplate(): ITemplateItem; + getAmmoTemplate(): ITemplateItem; + getPmcInventory(): Inventory; +} diff --git a/TypeScript/2EditDatabase/types/generators/weapongen/implementations/BarrelInventoryMagGen.d.ts b/TypeScript/2EditDatabase/types/generators/weapongen/implementations/BarrelInventoryMagGen.d.ts new file mode 100644 index 0000000..b754d5f --- /dev/null +++ b/TypeScript/2EditDatabase/types/generators/weapongen/implementations/BarrelInventoryMagGen.d.ts @@ -0,0 +1,12 @@ +import { BotWeaponGeneratorHelper } from "../../../helpers/BotWeaponGeneratorHelper"; +import { RandomUtil } from "../../../utils/RandomUtil"; +import { IInventoryMagGen } from "../IInventoryMagGen"; +import { InventoryMagGen } from "../InventoryMagGen"; +export declare class BarrelInventoryMagGen implements IInventoryMagGen { + protected randomUtil: RandomUtil; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + constructor(randomUtil: RandomUtil, botWeaponGeneratorHelper: BotWeaponGeneratorHelper); + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/2EditDatabase/types/generators/weapongen/implementations/ExternalInventoryMagGen.d.ts b/TypeScript/2EditDatabase/types/generators/weapongen/implementations/ExternalInventoryMagGen.d.ts new file mode 100644 index 0000000..4fcb1e2 --- /dev/null +++ b/TypeScript/2EditDatabase/types/generators/weapongen/implementations/ExternalInventoryMagGen.d.ts @@ -0,0 +1,14 @@ +import { BotWeaponGeneratorHelper } from "../../../helpers/BotWeaponGeneratorHelper"; +import { ItemHelper } from "../../../helpers/ItemHelper"; +import { ILogger } from "../../../models/spt/utils/ILogger"; +import { IInventoryMagGen } from "../IInventoryMagGen"; +import { InventoryMagGen } from "../InventoryMagGen"; +export declare class ExternalInventoryMagGen implements IInventoryMagGen { + protected logger: ILogger; + protected itemHelper: ItemHelper; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + constructor(logger: ILogger, itemHelper: ItemHelper, botWeaponGeneratorHelper: BotWeaponGeneratorHelper); + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/2EditDatabase/types/generators/weapongen/implementations/InternalMagazineInventoryMagGen.d.ts b/TypeScript/2EditDatabase/types/generators/weapongen/implementations/InternalMagazineInventoryMagGen.d.ts new file mode 100644 index 0000000..4548a04 --- /dev/null +++ b/TypeScript/2EditDatabase/types/generators/weapongen/implementations/InternalMagazineInventoryMagGen.d.ts @@ -0,0 +1,10 @@ +import { BotWeaponGeneratorHelper } from "../../../helpers/BotWeaponGeneratorHelper"; +import { IInventoryMagGen } from "../IInventoryMagGen"; +import { InventoryMagGen } from "../InventoryMagGen"; +export declare class InternalMagazineInventoryMagGen implements IInventoryMagGen { + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + constructor(botWeaponGeneratorHelper: BotWeaponGeneratorHelper); + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/2EditDatabase/types/helpers/BotGeneratorHelper.d.ts b/TypeScript/2EditDatabase/types/helpers/BotGeneratorHelper.d.ts index 09e5c8f..5e3e501 100644 --- a/TypeScript/2EditDatabase/types/helpers/BotGeneratorHelper.d.ts +++ b/TypeScript/2EditDatabase/types/helpers/BotGeneratorHelper.d.ts @@ -1,8 +1,7 @@ import { DurabilityLimitsHelper } from "../helpers/DurabilityLimitsHelper"; -import { Inventory as PmcInventory } from "../models/eft/common/tables/IBotBase"; import { Mods, ModsChances } from "../models/eft/common/tables/IBotType"; import { Item, Repairable, Upd } from "../models/eft/common/tables/IItem"; -import { Grid, ITemplateItem, Slot } from "../models/eft/common/tables/ITemplateItem"; +import { ITemplateItem, Slot } from "../models/eft/common/tables/ITemplateItem"; import { EquipmentFilterDetails, IBotConfig } from "../models/spt/config/IBotConfig"; import { ILogger } from "../models/spt/utils/ILogger"; import { ConfigServer } from "../servers/ConfigServer"; @@ -12,6 +11,7 @@ import { ItemFilterService } from "../services/ItemFilterService"; import { HashUtil } from "../utils/HashUtil"; import { JsonUtil } from "../utils/JsonUtil"; import { RandomUtil } from "../utils/RandomUtil"; +import { BotWeaponGeneratorHelper } from "./BotWeaponGeneratorHelper"; import { ContainerHelper } from "./ContainerHelper"; import { InventoryHelper } from "./InventoryHelper"; import { ItemHelper } from "./ItemHelper"; @@ -42,11 +42,11 @@ export declare class BotGeneratorHelper { protected botEquipmentFilterService: BotEquipmentFilterService; protected itemFilterService: ItemFilterService; protected profileHelper: ProfileHelper; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; protected configServer: ConfigServer; protected botConfig: IBotConfig; - constructor(logger: ILogger, jsonUtil: JsonUtil, hashUtil: HashUtil, randomUtil: RandomUtil, probabilityHelper: ProbabilityHelper, databaseServer: DatabaseServer, durabilityLimitsHelper: DurabilityLimitsHelper, itemHelper: ItemHelper, inventoryHelper: InventoryHelper, containerHelper: ContainerHelper, botEquipmentFilterService: BotEquipmentFilterService, itemFilterService: ItemFilterService, profileHelper: ProfileHelper, configServer: ConfigServer); + constructor(logger: ILogger, jsonUtil: JsonUtil, hashUtil: HashUtil, randomUtil: RandomUtil, probabilityHelper: ProbabilityHelper, databaseServer: DatabaseServer, durabilityLimitsHelper: DurabilityLimitsHelper, itemHelper: ItemHelper, inventoryHelper: InventoryHelper, containerHelper: ContainerHelper, botEquipmentFilterService: BotEquipmentFilterService, itemFilterService: ItemFilterService, profileHelper: ProfileHelper, botWeaponGeneratorHelper: BotWeaponGeneratorHelper, configServer: ConfigServer); /** - * TODO - very similar to generateModsForWeapon * Check mods are compatible and add to array * @param equipment Equipment item to add mods to * @param modPool Mod list to choose frm @@ -57,18 +57,30 @@ export declare class BotGeneratorHelper { */ generateModsForEquipment(equipment: Item[], modPool: Mods, parentId: string, parentTemplate: ITemplateItem, modSpawnChances: ModsChances): Item[]; /** - * TODO - very similar to generateModsForEquipment * @param sessionId session id * @param weapon Weapon to add mods to - * @param modPool pool of compatible mods to attach to gun + * @param modPool Pool of compatible mods to attach to weapon * @param weaponParentId parentId of weapon - * @param parentTemplate - * @param modSpawnChances - * @param ammoTpl ammo tpl to use when generating magazines/cartridges - * @param botRole role of bot weapon is generated for - * @returns Weapon with mods + * @param parentWeaponTemplate Weapon which mods will be generated on + * @param modSpawnChances Mod spawn chances + * @param ammoTpl Ammo tpl to use when generating magazines/cartridges + * @param botRole Role of bot weapon is generated for + * @returns Weapon + mods array */ - generateModsForWeapon(sessionId: string, weapon: Item[], modPool: Mods, weaponParentId: string, parentTemplate: ITemplateItem, modSpawnChances: ModsChances, ammoTpl: string, botRole: string): Item[]; + generateModsForWeapon(sessionId: string, weapon: Item[], modPool: Mods, weaponParentId: string, parentWeaponTemplate: ITemplateItem, modSpawnChances: ModsChances, ammoTpl: string, botRole: string): Item[]; + /** + * + * @param modSlot + * @param isRandomisableSlot + * @param modsParent + * @param botEquipBlacklist + * @param itemModPool + * @param weapon array with only weapon tpl in it, ready for mods to be added + * @param ammoTpl ammo tpl to use if slot requires a cartridge to be added (e.g. mod_magazine) + * @param parentTemplate + * @returns + */ + protected chooseModToPutIntoSlot(modSlot: string, isRandomisableSlot: boolean, modsParent: Slot, botEquipBlacklist: EquipmentFilterDetails, itemModPool: Record, weapon: Item[], ammoTpl: string, parentTemplate: ITemplateItem): [boolean, ITemplateItem]; /** * Find mod tpls of a provided type and add to modPool * @param desiredSlotName slot to look up and add we are adding tpls for (e.g mod_scope) @@ -79,15 +91,15 @@ export declare class BotGeneratorHelper { /** * Check if mod item is on limited list + has surpassed the limit set for it * @param botRole role the bot has e.g. assault - * @param modTpl mods tpl + * @param modTemplate mods template data * @param modLimits limits set for weapon being generated for this bot * @returns true if over item limit */ - protected modHasReachedItemLimit(botRole: string, modTpl: string, modLimits: BotModLimits): boolean; + protected modHasReachedItemLimit(botRole: string, modTemplate: ITemplateItem, modLimits: BotModLimits): boolean; /** - * Initalise mod limits to be used when generating the weapon + * Initalise mod limits to be used when generating a weapon * @param botRole "assault", "bossTagilla" or "pmc" - * @returns + * @returns BotModLimits object */ protected initModLimits(botRole: string): BotModLimits; /** @@ -114,7 +126,7 @@ export declare class BotGeneratorHelper { protected filterWeaponModsByBlacklist(allowedMods: string[], botEquipBlacklist: EquipmentFilterDetails, modSlot: string): string[]; /** * Check if the specific item type on the weapon has reached the set limit - * @param modTpl item to check is limited + * @param modTpl log mod tpl if over type limit * @param currentCount current number of this item on gun * @param maxLimit mod limit allowed * @param botRole role of bot we're checking weapon of @@ -124,16 +136,14 @@ export declare class BotGeneratorHelper { count: number; }, maxLimit: number, botRole: string): boolean; /** - * log errors if mod is not valid for a slot - * @param modTpl - * @param found - * @param itemSlot - * @param modTemplate - * @param modSlot - * @param parentTemplate + * Log errors if mod is not compatible with slot + * @param modToAdd template of mod to check + * @param itemSlot slot the item will be placed in + * @param modSlot slot the mod will fill + * @param parentTemplate tempalte of the mods parent item * @returns true if valid */ - protected isModValidForSlot(modTpl: string, found: boolean, itemSlot: Slot, modTemplate: ITemplateItem, modSlot: string, parentTemplate: ITemplateItem): boolean; + protected isModValidForSlot(modToAdd: [boolean, ITemplateItem], itemSlot: Slot, modSlot: string, parentTemplate: ITemplateItem): boolean; /** * Create a mod item with parameters as properties * @param modId _id @@ -144,12 +154,6 @@ export declare class BotGeneratorHelper { * @returns Item object */ protected createModItem(modId: string, modTpl: string, parentId: string, modSlot: string, modTemplate: ITemplateItem): Item; - /** - * Is this magazine cylinder related (revolvers and grenade launchers) - * @param magazineParentName the name of the magazines parent - * @returns true if it is cylinder related - */ - magazineIsCylinderRelated(magazineParentName: string): boolean; /** * randomly choose if a mod should be spawned, 100% for required mods OR mod is ammo slot * never return true for an item that has 0% spawn chance @@ -161,7 +165,7 @@ export declare class BotGeneratorHelper { protected shouldModBeSpawned(itemSlot: Slot, modSlot: string, modSpawnChances: ModsChances): boolean; /** * Get a list of containers that hold ammo - * e.g. mod_magazine + * e.g. mod_magazine / patron_in_weapon_000 * @returns string array */ protected getAmmoContainers(): string[]; @@ -214,6 +218,14 @@ export declare class BotGeneratorHelper { * @returns Repairable object */ protected generateArmorRepairableProperties(itemTemplate: ITemplateItem, botRole: string): Repairable; + /** + * Get a random mod from an items compatible mods Filter array + * @param modTpl + * @param parentSlot + * @param modSlot + * @param items + * @returns item tpl + */ protected getModTplFromItemDb(modTpl: string, parentSlot: Slot, modSlot: string, items: Item[]): string; /** * Can an item be added to an item without issue @@ -223,23 +235,6 @@ export declare class BotGeneratorHelper { * @returns true if possible */ isItemIncompatibleWithCurrentItems(items: Item[], tplToCheck: string, equipmentSlot: string): boolean; - /** - * Adds an item with all its childern into specified equipmentSlots, wherever it fits. - * @param equipmentSlots - * @param parentId - * @param parentTpl - * @param itemWithChildren - * @param inventory - * @returns a `boolean` indicating item was added - */ - addItemWithChildrenToEquipmentSlot(equipmentSlots: string[], parentId: string, parentTpl: string, itemWithChildren: Item[], inventory: PmcInventory): boolean; - /** - * is the provided item allowed inside a container - * @param slot location item wants to be placed in - * @param itemTpl item being placed - * @returns true if allowed - */ - protected itemAllowedInContainer(slot: Grid, itemTpl: string): boolean; } /** TODO - move into own class */ export declare class ExhaustableArray { diff --git a/TypeScript/2EditDatabase/types/helpers/BotWeaponGeneratorHelper.d.ts b/TypeScript/2EditDatabase/types/helpers/BotWeaponGeneratorHelper.d.ts new file mode 100644 index 0000000..7e25f56 --- /dev/null +++ b/TypeScript/2EditDatabase/types/helpers/BotWeaponGeneratorHelper.d.ts @@ -0,0 +1,78 @@ +import { MinMax } from "../models/common/MinMax"; +import { Inventory } from "../models/eft/common/tables/IBotBase"; +import { Item } from "../models/eft/common/tables/IItem"; +import { Grid, ITemplateItem } from "../models/eft/common/tables/ITemplateItem"; +import { ILogger } from "../models/spt/utils/ILogger"; +import { DatabaseServer } from "../servers/DatabaseServer"; +import { HashUtil } from "../utils/HashUtil"; +import { RandomUtil } from "../utils/RandomUtil"; +import { ContainerHelper } from "./ContainerHelper"; +import { InventoryHelper } from "./InventoryHelper"; +import { ItemHelper } from "./ItemHelper"; +export declare class BotWeaponGeneratorHelper { + protected logger: ILogger; + protected databaseServer: DatabaseServer; + protected itemHelper: ItemHelper; + protected randomUtil: RandomUtil; + protected hashUtil: HashUtil; + protected inventoryHelper: InventoryHelper; + protected containerHelper: ContainerHelper; + constructor(logger: ILogger, databaseServer: DatabaseServer, itemHelper: ItemHelper, randomUtil: RandomUtil, hashUtil: HashUtil, inventoryHelper: InventoryHelper, containerHelper: ContainerHelper); + /** + * Get a randomised number of bullets for a specific magazine + * @param magCounts min and max count of magazines + * @param magTemplate magazine to generate bullet count for + * @returns bullet count number + */ + getRandomisedBulletCount(magCounts: MinMax, magTemplate: ITemplateItem): number; + /** + * Get a randomised count of magazines + * @param magCounts min and max value returned value can be between + * @returns numberical value of magazine count + */ + getRandomisedMagazineCount(magCounts: MinMax): number; + /** + * Is this magazine cylinder related (revolvers and grenade launchers) + * @param magazineParentName the name of the magazines parent + * @returns true if it is cylinder related + */ + magazineIsCylinderRelated(magazineParentName: string): boolean; + /** + * Create a magazine using the parameters given + * @param magazineTpl Tpl of the magazine to create + * @param ammoTpl Ammo to add to magazine + * @param magTemplate template object of magazine + * @returns Item array + */ + createMagazine(magazineTpl: string, ammoTpl: string, magTemplate: ITemplateItem): Item[]; + /** + * Add a specific number of cartrdiges to a bots inventory (vest/pocket) + * @param ammoTpl Ammo tpl to add to vest/pockets + * @param cartridgeCount number of cartridges to add to vest/pockets + * @param inventory bot inventory to add cartridges to + */ + addBulletsToVestAndPockets(ammoTpl: string, cartridgeCount: number, inventory: Inventory): void; + /** + * Get a weapons default magazine template id + * @param weaponTemplate weapon to get default magazine for + * @returns tpl of magazine + */ + getWeaponsDefaultMagazineTpl(weaponTemplate: ITemplateItem): string; + /** + * Adds an item with all its childern into specified equipmentSlots, wherever it fits. + * @param equipmentSlots + * @param parentId + * @param parentTpl + * @param itemWithChildren + * @param inventory + * @returns a `boolean` indicating item was added + */ + addItemWithChildrenToEquipmentSlot(equipmentSlots: string[], parentId: string, parentTpl: string, itemWithChildren: Item[], inventory: Inventory): boolean; + /** + * is the provided item allowed inside a container + * @param slot location item wants to be placed in + * @param itemTpl item being placed + * @returns true if allowed + */ + protected itemAllowedInContainer(slot: Grid, itemTpl: string): boolean; +} diff --git a/TypeScript/3GetSptConfigFile/package.json b/TypeScript/3GetSptConfigFile/package.json index 5bb25fe..f037e8f 100644 --- a/TypeScript/3GetSptConfigFile/package.json +++ b/TypeScript/3GetSptConfigFile/package.json @@ -4,7 +4,7 @@ "main": "src/mod.js", "license": "MIT", "author": "Chomp", - "akiVersion": "3.2.2", + "akiVersion": "3.2.3", "scripts": { "setup": "npm i", "build": "node ./packageBuild.ts" diff --git a/TypeScript/3GetSptConfigFile/types/generators/BotLootGenerator.d.ts b/TypeScript/3GetSptConfigFile/types/generators/BotLootGenerator.d.ts index 5a2d144..c1f5310 100644 --- a/TypeScript/3GetSptConfigFile/types/generators/BotLootGenerator.d.ts +++ b/TypeScript/3GetSptConfigFile/types/generators/BotLootGenerator.d.ts @@ -1,4 +1,5 @@ import { BotGeneratorHelper } from "../helpers/BotGeneratorHelper"; +import { BotWeaponGeneratorHelper } from "../helpers/BotWeaponGeneratorHelper"; import { HandbookHelper } from "../helpers/HandbookHelper"; import { Inventory as PmcInventory } from "../models/eft/common/tables/IBotBase"; import { Chances, Inventory, ItemMinMax, ModsChances } from "../models/eft/common/tables/IBotType"; @@ -20,10 +21,11 @@ export declare class BotLootGenerator { protected handbookHelper: HandbookHelper; protected botGeneratorHelper: BotGeneratorHelper; protected botWeaponGenerator: BotWeaponGenerator; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; protected botLootCacheService: BotLootCacheService; protected configServer: ConfigServer; protected botConfig: IBotConfig; - constructor(logger: ILogger, hashUtil: HashUtil, randomUtil: RandomUtil, databaseServer: DatabaseServer, handbookHelper: HandbookHelper, botGeneratorHelper: BotGeneratorHelper, botWeaponGenerator: BotWeaponGenerator, botLootCacheService: BotLootCacheService, configServer: ConfigServer); + constructor(logger: ILogger, hashUtil: HashUtil, randomUtil: RandomUtil, databaseServer: DatabaseServer, handbookHelper: HandbookHelper, botGeneratorHelper: BotGeneratorHelper, botWeaponGenerator: BotWeaponGenerator, botWeaponGeneratorHelper: BotWeaponGeneratorHelper, botLootCacheService: BotLootCacheService, configServer: ConfigServer); generateLoot(sessionId: string, templateInventory: Inventory, itemCounts: ItemMinMax, isPmc: boolean, botRole: string, botInventory: PmcInventory, equipmentChances: Chances): void; protected getRandomisedCount(min: number, max: number, nValue: number): number; /** diff --git a/TypeScript/3GetSptConfigFile/types/generators/BotWeaponGenerator.d.ts b/TypeScript/3GetSptConfigFile/types/generators/BotWeaponGenerator.d.ts index cba7afa..487901b 100644 --- a/TypeScript/3GetSptConfigFile/types/generators/BotWeaponGenerator.d.ts +++ b/TypeScript/3GetSptConfigFile/types/generators/BotWeaponGenerator.d.ts @@ -1,4 +1,5 @@ import { BotGeneratorHelper } from "../helpers/BotGeneratorHelper"; +import { BotWeaponGeneratorHelper } from "../helpers/BotWeaponGeneratorHelper"; import { ItemHelper } from "../helpers/ItemHelper"; import { WeightedRandomHelper } from "../helpers/WeightedRandomHelper"; import { MinMax } from "../models/common/MinMax"; @@ -14,6 +15,7 @@ import { DatabaseServer } from "../servers/DatabaseServer"; import { HashUtil } from "../utils/HashUtil"; import { JsonUtil } from "../utils/JsonUtil"; import { RandomUtil } from "../utils/RandomUtil"; +import { IInventoryMagGen } from "./weapongen/IInventoryMagGen"; export declare class BotWeaponGenerator { protected jsonUtil: JsonUtil; protected logger: ILogger; @@ -24,9 +26,11 @@ export declare class BotWeaponGenerator { protected botGeneratorHelper: BotGeneratorHelper; protected randomUtil: RandomUtil; protected configServer: ConfigServer; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + protected inventoryMagGenComponents: IInventoryMagGen[]; protected readonly modMagazineSlotId = "mod_magazine"; protected botConfig: IBotConfig; - constructor(jsonUtil: JsonUtil, logger: ILogger, hashUtil: HashUtil, databaseServer: DatabaseServer, itemHelper: ItemHelper, weightedRandomHelper: WeightedRandomHelper, botGeneratorHelper: BotGeneratorHelper, randomUtil: RandomUtil, configServer: ConfigServer); + constructor(jsonUtil: JsonUtil, logger: ILogger, hashUtil: HashUtil, databaseServer: DatabaseServer, itemHelper: ItemHelper, weightedRandomHelper: WeightedRandomHelper, botGeneratorHelper: BotGeneratorHelper, randomUtil: RandomUtil, configServer: ConfigServer, botWeaponGeneratorHelper: BotWeaponGeneratorHelper, inventoryMagGenComponents: IInventoryMagGen[]); /** * Pick a random weapon based on weightings and generate a functional weapon * @param equipmentSlot Primary/secondary/holster @@ -85,36 +89,12 @@ export declare class BotWeaponGenerator { /** * Generates extra magazines or bullets (if magazine is internal) and adds them to TacticalVest and Pockets. * Additionally, adds extra bullets to SecuredContainer - * @param weaponMods mods to attach to weapon - * @param weaponTemplate db template for weapon - * @param magCounts magazine count to add to inventory - * @param ammoTpl ammo templateId to add to magazines - * @param inventory inventory to add magazines to - * @param botRole the bot type we're getting generating extra mags for - * @returns + * @param generatedWeaponResult object with properties for generated weapon (weapon mods pool / weapon template / ammo tpl) + * @param magCounts Magazine count to add to inventory + * @param inventory Inventory to add magazines to + * @param botRole The bot type we're getting generating extra mags for */ - addExtraMagazinesToInventory(weaponMods: Item[], weaponTemplate: ITemplateItem, magCounts: MinMax, ammoTpl: string, inventory: PmcInventory, botRole: string): void; - /** - * Create a magazine using the parameters given - * @param magazineTpl Tpl of the magazine to create - * @param ammoTpl Ammo to add to magazine - * @param magTemplate template object of magazine - * @returns Item array - */ - protected createMagazine(magazineTpl: string, ammoTpl: string, magTemplate: ITemplateItem): Item[]; - /** - * Get a randomised number of bullets for a specific magazine - * @param magCounts min and max count of magazines - * @param magTemplate magazine to generate bullet count for - * @returns bullet count number - */ - protected getRandomisedBulletCount(magCounts: MinMax, magTemplate: ITemplateItem): number; - /** - * Get a randomised count of magazines - * @param magCounts min and max value returned value can be between - * @returns numberical value of magazine count - */ - protected getRandomisedMagazineCount(magCounts: MinMax): number; + addExtraMagazinesToInventory(generatedWeaponResult: GenerateWeaponResult, magCounts: MinMax, inventory: PmcInventory, botRole: string): void; /** * Add ammo to the secure container * @param stackCount How many stacks of ammo to add @@ -131,13 +111,6 @@ export declare class BotWeaponGenerator { * @returns magazine tpl string */ protected getMagazineTplFromWeaponTemplate(weaponMods: Item[], weaponTemplate: ITemplateItem, botRole: string): string; - /** - * Get a weapons default magazine template id - * @param weaponTemplate weapon to get default magazine for - * @returns tpl of magazine - */ - protected getWeaponsDefaultMagazineTpl(weaponTemplate: ITemplateItem): string; - protected addBulletsToVestAndPockets(ammoTpl: string, bulletCount: number, inventory: PmcInventory): void; /** * Finds and return a compatible ammo tpl based on the bots ammo weightings (x.json/inventory/equipment/ammo) * @param ammo a list of ammo tpls the weapon can use diff --git a/TypeScript/3GetSptConfigFile/types/generators/weapongen/IInventoryMagGen.d.ts b/TypeScript/3GetSptConfigFile/types/generators/weapongen/IInventoryMagGen.d.ts new file mode 100644 index 0000000..792f510 --- /dev/null +++ b/TypeScript/3GetSptConfigFile/types/generators/weapongen/IInventoryMagGen.d.ts @@ -0,0 +1,6 @@ +import { InventoryMagGen } from "./InventoryMagGen"; +export interface IInventoryMagGen { + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/3GetSptConfigFile/types/generators/weapongen/InventoryMagGen.d.ts b/TypeScript/3GetSptConfigFile/types/generators/weapongen/InventoryMagGen.d.ts new file mode 100644 index 0000000..30bf79f --- /dev/null +++ b/TypeScript/3GetSptConfigFile/types/generators/weapongen/InventoryMagGen.d.ts @@ -0,0 +1,16 @@ +import { MinMax } from "../../models/common/MinMax"; +import { Inventory } from "../../models/eft/common/tables/IBotBase"; +import { ITemplateItem } from "../../models/eft/common/tables/ITemplateItem"; +export declare class InventoryMagGen { + private magCounts; + private magazineTemplate; + private weaponTemplate; + private ammoTemplate; + private pmcInventory; + constructor(magCounts: MinMax, magazineTemplate: ITemplateItem, weaponTemplate: ITemplateItem, ammoTemplate: ITemplateItem, pmcInventory: Inventory); + getMagCount(): MinMax; + getMagazineTemplate(): ITemplateItem; + getWeaponTemplate(): ITemplateItem; + getAmmoTemplate(): ITemplateItem; + getPmcInventory(): Inventory; +} diff --git a/TypeScript/3GetSptConfigFile/types/generators/weapongen/implementations/BarrelInventoryMagGen.d.ts b/TypeScript/3GetSptConfigFile/types/generators/weapongen/implementations/BarrelInventoryMagGen.d.ts new file mode 100644 index 0000000..b754d5f --- /dev/null +++ b/TypeScript/3GetSptConfigFile/types/generators/weapongen/implementations/BarrelInventoryMagGen.d.ts @@ -0,0 +1,12 @@ +import { BotWeaponGeneratorHelper } from "../../../helpers/BotWeaponGeneratorHelper"; +import { RandomUtil } from "../../../utils/RandomUtil"; +import { IInventoryMagGen } from "../IInventoryMagGen"; +import { InventoryMagGen } from "../InventoryMagGen"; +export declare class BarrelInventoryMagGen implements IInventoryMagGen { + protected randomUtil: RandomUtil; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + constructor(randomUtil: RandomUtil, botWeaponGeneratorHelper: BotWeaponGeneratorHelper); + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/3GetSptConfigFile/types/generators/weapongen/implementations/ExternalInventoryMagGen.d.ts b/TypeScript/3GetSptConfigFile/types/generators/weapongen/implementations/ExternalInventoryMagGen.d.ts new file mode 100644 index 0000000..4fcb1e2 --- /dev/null +++ b/TypeScript/3GetSptConfigFile/types/generators/weapongen/implementations/ExternalInventoryMagGen.d.ts @@ -0,0 +1,14 @@ +import { BotWeaponGeneratorHelper } from "../../../helpers/BotWeaponGeneratorHelper"; +import { ItemHelper } from "../../../helpers/ItemHelper"; +import { ILogger } from "../../../models/spt/utils/ILogger"; +import { IInventoryMagGen } from "../IInventoryMagGen"; +import { InventoryMagGen } from "../InventoryMagGen"; +export declare class ExternalInventoryMagGen implements IInventoryMagGen { + protected logger: ILogger; + protected itemHelper: ItemHelper; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + constructor(logger: ILogger, itemHelper: ItemHelper, botWeaponGeneratorHelper: BotWeaponGeneratorHelper); + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/3GetSptConfigFile/types/generators/weapongen/implementations/InternalMagazineInventoryMagGen.d.ts b/TypeScript/3GetSptConfigFile/types/generators/weapongen/implementations/InternalMagazineInventoryMagGen.d.ts new file mode 100644 index 0000000..4548a04 --- /dev/null +++ b/TypeScript/3GetSptConfigFile/types/generators/weapongen/implementations/InternalMagazineInventoryMagGen.d.ts @@ -0,0 +1,10 @@ +import { BotWeaponGeneratorHelper } from "../../../helpers/BotWeaponGeneratorHelper"; +import { IInventoryMagGen } from "../IInventoryMagGen"; +import { InventoryMagGen } from "../InventoryMagGen"; +export declare class InternalMagazineInventoryMagGen implements IInventoryMagGen { + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + constructor(botWeaponGeneratorHelper: BotWeaponGeneratorHelper); + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/3GetSptConfigFile/types/helpers/BotGeneratorHelper.d.ts b/TypeScript/3GetSptConfigFile/types/helpers/BotGeneratorHelper.d.ts index 09e5c8f..5e3e501 100644 --- a/TypeScript/3GetSptConfigFile/types/helpers/BotGeneratorHelper.d.ts +++ b/TypeScript/3GetSptConfigFile/types/helpers/BotGeneratorHelper.d.ts @@ -1,8 +1,7 @@ import { DurabilityLimitsHelper } from "../helpers/DurabilityLimitsHelper"; -import { Inventory as PmcInventory } from "../models/eft/common/tables/IBotBase"; import { Mods, ModsChances } from "../models/eft/common/tables/IBotType"; import { Item, Repairable, Upd } from "../models/eft/common/tables/IItem"; -import { Grid, ITemplateItem, Slot } from "../models/eft/common/tables/ITemplateItem"; +import { ITemplateItem, Slot } from "../models/eft/common/tables/ITemplateItem"; import { EquipmentFilterDetails, IBotConfig } from "../models/spt/config/IBotConfig"; import { ILogger } from "../models/spt/utils/ILogger"; import { ConfigServer } from "../servers/ConfigServer"; @@ -12,6 +11,7 @@ import { ItemFilterService } from "../services/ItemFilterService"; import { HashUtil } from "../utils/HashUtil"; import { JsonUtil } from "../utils/JsonUtil"; import { RandomUtil } from "../utils/RandomUtil"; +import { BotWeaponGeneratorHelper } from "./BotWeaponGeneratorHelper"; import { ContainerHelper } from "./ContainerHelper"; import { InventoryHelper } from "./InventoryHelper"; import { ItemHelper } from "./ItemHelper"; @@ -42,11 +42,11 @@ export declare class BotGeneratorHelper { protected botEquipmentFilterService: BotEquipmentFilterService; protected itemFilterService: ItemFilterService; protected profileHelper: ProfileHelper; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; protected configServer: ConfigServer; protected botConfig: IBotConfig; - constructor(logger: ILogger, jsonUtil: JsonUtil, hashUtil: HashUtil, randomUtil: RandomUtil, probabilityHelper: ProbabilityHelper, databaseServer: DatabaseServer, durabilityLimitsHelper: DurabilityLimitsHelper, itemHelper: ItemHelper, inventoryHelper: InventoryHelper, containerHelper: ContainerHelper, botEquipmentFilterService: BotEquipmentFilterService, itemFilterService: ItemFilterService, profileHelper: ProfileHelper, configServer: ConfigServer); + constructor(logger: ILogger, jsonUtil: JsonUtil, hashUtil: HashUtil, randomUtil: RandomUtil, probabilityHelper: ProbabilityHelper, databaseServer: DatabaseServer, durabilityLimitsHelper: DurabilityLimitsHelper, itemHelper: ItemHelper, inventoryHelper: InventoryHelper, containerHelper: ContainerHelper, botEquipmentFilterService: BotEquipmentFilterService, itemFilterService: ItemFilterService, profileHelper: ProfileHelper, botWeaponGeneratorHelper: BotWeaponGeneratorHelper, configServer: ConfigServer); /** - * TODO - very similar to generateModsForWeapon * Check mods are compatible and add to array * @param equipment Equipment item to add mods to * @param modPool Mod list to choose frm @@ -57,18 +57,30 @@ export declare class BotGeneratorHelper { */ generateModsForEquipment(equipment: Item[], modPool: Mods, parentId: string, parentTemplate: ITemplateItem, modSpawnChances: ModsChances): Item[]; /** - * TODO - very similar to generateModsForEquipment * @param sessionId session id * @param weapon Weapon to add mods to - * @param modPool pool of compatible mods to attach to gun + * @param modPool Pool of compatible mods to attach to weapon * @param weaponParentId parentId of weapon - * @param parentTemplate - * @param modSpawnChances - * @param ammoTpl ammo tpl to use when generating magazines/cartridges - * @param botRole role of bot weapon is generated for - * @returns Weapon with mods + * @param parentWeaponTemplate Weapon which mods will be generated on + * @param modSpawnChances Mod spawn chances + * @param ammoTpl Ammo tpl to use when generating magazines/cartridges + * @param botRole Role of bot weapon is generated for + * @returns Weapon + mods array */ - generateModsForWeapon(sessionId: string, weapon: Item[], modPool: Mods, weaponParentId: string, parentTemplate: ITemplateItem, modSpawnChances: ModsChances, ammoTpl: string, botRole: string): Item[]; + generateModsForWeapon(sessionId: string, weapon: Item[], modPool: Mods, weaponParentId: string, parentWeaponTemplate: ITemplateItem, modSpawnChances: ModsChances, ammoTpl: string, botRole: string): Item[]; + /** + * + * @param modSlot + * @param isRandomisableSlot + * @param modsParent + * @param botEquipBlacklist + * @param itemModPool + * @param weapon array with only weapon tpl in it, ready for mods to be added + * @param ammoTpl ammo tpl to use if slot requires a cartridge to be added (e.g. mod_magazine) + * @param parentTemplate + * @returns + */ + protected chooseModToPutIntoSlot(modSlot: string, isRandomisableSlot: boolean, modsParent: Slot, botEquipBlacklist: EquipmentFilterDetails, itemModPool: Record, weapon: Item[], ammoTpl: string, parentTemplate: ITemplateItem): [boolean, ITemplateItem]; /** * Find mod tpls of a provided type and add to modPool * @param desiredSlotName slot to look up and add we are adding tpls for (e.g mod_scope) @@ -79,15 +91,15 @@ export declare class BotGeneratorHelper { /** * Check if mod item is on limited list + has surpassed the limit set for it * @param botRole role the bot has e.g. assault - * @param modTpl mods tpl + * @param modTemplate mods template data * @param modLimits limits set for weapon being generated for this bot * @returns true if over item limit */ - protected modHasReachedItemLimit(botRole: string, modTpl: string, modLimits: BotModLimits): boolean; + protected modHasReachedItemLimit(botRole: string, modTemplate: ITemplateItem, modLimits: BotModLimits): boolean; /** - * Initalise mod limits to be used when generating the weapon + * Initalise mod limits to be used when generating a weapon * @param botRole "assault", "bossTagilla" or "pmc" - * @returns + * @returns BotModLimits object */ protected initModLimits(botRole: string): BotModLimits; /** @@ -114,7 +126,7 @@ export declare class BotGeneratorHelper { protected filterWeaponModsByBlacklist(allowedMods: string[], botEquipBlacklist: EquipmentFilterDetails, modSlot: string): string[]; /** * Check if the specific item type on the weapon has reached the set limit - * @param modTpl item to check is limited + * @param modTpl log mod tpl if over type limit * @param currentCount current number of this item on gun * @param maxLimit mod limit allowed * @param botRole role of bot we're checking weapon of @@ -124,16 +136,14 @@ export declare class BotGeneratorHelper { count: number; }, maxLimit: number, botRole: string): boolean; /** - * log errors if mod is not valid for a slot - * @param modTpl - * @param found - * @param itemSlot - * @param modTemplate - * @param modSlot - * @param parentTemplate + * Log errors if mod is not compatible with slot + * @param modToAdd template of mod to check + * @param itemSlot slot the item will be placed in + * @param modSlot slot the mod will fill + * @param parentTemplate tempalte of the mods parent item * @returns true if valid */ - protected isModValidForSlot(modTpl: string, found: boolean, itemSlot: Slot, modTemplate: ITemplateItem, modSlot: string, parentTemplate: ITemplateItem): boolean; + protected isModValidForSlot(modToAdd: [boolean, ITemplateItem], itemSlot: Slot, modSlot: string, parentTemplate: ITemplateItem): boolean; /** * Create a mod item with parameters as properties * @param modId _id @@ -144,12 +154,6 @@ export declare class BotGeneratorHelper { * @returns Item object */ protected createModItem(modId: string, modTpl: string, parentId: string, modSlot: string, modTemplate: ITemplateItem): Item; - /** - * Is this magazine cylinder related (revolvers and grenade launchers) - * @param magazineParentName the name of the magazines parent - * @returns true if it is cylinder related - */ - magazineIsCylinderRelated(magazineParentName: string): boolean; /** * randomly choose if a mod should be spawned, 100% for required mods OR mod is ammo slot * never return true for an item that has 0% spawn chance @@ -161,7 +165,7 @@ export declare class BotGeneratorHelper { protected shouldModBeSpawned(itemSlot: Slot, modSlot: string, modSpawnChances: ModsChances): boolean; /** * Get a list of containers that hold ammo - * e.g. mod_magazine + * e.g. mod_magazine / patron_in_weapon_000 * @returns string array */ protected getAmmoContainers(): string[]; @@ -214,6 +218,14 @@ export declare class BotGeneratorHelper { * @returns Repairable object */ protected generateArmorRepairableProperties(itemTemplate: ITemplateItem, botRole: string): Repairable; + /** + * Get a random mod from an items compatible mods Filter array + * @param modTpl + * @param parentSlot + * @param modSlot + * @param items + * @returns item tpl + */ protected getModTplFromItemDb(modTpl: string, parentSlot: Slot, modSlot: string, items: Item[]): string; /** * Can an item be added to an item without issue @@ -223,23 +235,6 @@ export declare class BotGeneratorHelper { * @returns true if possible */ isItemIncompatibleWithCurrentItems(items: Item[], tplToCheck: string, equipmentSlot: string): boolean; - /** - * Adds an item with all its childern into specified equipmentSlots, wherever it fits. - * @param equipmentSlots - * @param parentId - * @param parentTpl - * @param itemWithChildren - * @param inventory - * @returns a `boolean` indicating item was added - */ - addItemWithChildrenToEquipmentSlot(equipmentSlots: string[], parentId: string, parentTpl: string, itemWithChildren: Item[], inventory: PmcInventory): boolean; - /** - * is the provided item allowed inside a container - * @param slot location item wants to be placed in - * @param itemTpl item being placed - * @returns true if allowed - */ - protected itemAllowedInContainer(slot: Grid, itemTpl: string): boolean; } /** TODO - move into own class */ export declare class ExhaustableArray { diff --git a/TypeScript/3GetSptConfigFile/types/helpers/BotWeaponGeneratorHelper.d.ts b/TypeScript/3GetSptConfigFile/types/helpers/BotWeaponGeneratorHelper.d.ts new file mode 100644 index 0000000..7e25f56 --- /dev/null +++ b/TypeScript/3GetSptConfigFile/types/helpers/BotWeaponGeneratorHelper.d.ts @@ -0,0 +1,78 @@ +import { MinMax } from "../models/common/MinMax"; +import { Inventory } from "../models/eft/common/tables/IBotBase"; +import { Item } from "../models/eft/common/tables/IItem"; +import { Grid, ITemplateItem } from "../models/eft/common/tables/ITemplateItem"; +import { ILogger } from "../models/spt/utils/ILogger"; +import { DatabaseServer } from "../servers/DatabaseServer"; +import { HashUtil } from "../utils/HashUtil"; +import { RandomUtil } from "../utils/RandomUtil"; +import { ContainerHelper } from "./ContainerHelper"; +import { InventoryHelper } from "./InventoryHelper"; +import { ItemHelper } from "./ItemHelper"; +export declare class BotWeaponGeneratorHelper { + protected logger: ILogger; + protected databaseServer: DatabaseServer; + protected itemHelper: ItemHelper; + protected randomUtil: RandomUtil; + protected hashUtil: HashUtil; + protected inventoryHelper: InventoryHelper; + protected containerHelper: ContainerHelper; + constructor(logger: ILogger, databaseServer: DatabaseServer, itemHelper: ItemHelper, randomUtil: RandomUtil, hashUtil: HashUtil, inventoryHelper: InventoryHelper, containerHelper: ContainerHelper); + /** + * Get a randomised number of bullets for a specific magazine + * @param magCounts min and max count of magazines + * @param magTemplate magazine to generate bullet count for + * @returns bullet count number + */ + getRandomisedBulletCount(magCounts: MinMax, magTemplate: ITemplateItem): number; + /** + * Get a randomised count of magazines + * @param magCounts min and max value returned value can be between + * @returns numberical value of magazine count + */ + getRandomisedMagazineCount(magCounts: MinMax): number; + /** + * Is this magazine cylinder related (revolvers and grenade launchers) + * @param magazineParentName the name of the magazines parent + * @returns true if it is cylinder related + */ + magazineIsCylinderRelated(magazineParentName: string): boolean; + /** + * Create a magazine using the parameters given + * @param magazineTpl Tpl of the magazine to create + * @param ammoTpl Ammo to add to magazine + * @param magTemplate template object of magazine + * @returns Item array + */ + createMagazine(magazineTpl: string, ammoTpl: string, magTemplate: ITemplateItem): Item[]; + /** + * Add a specific number of cartrdiges to a bots inventory (vest/pocket) + * @param ammoTpl Ammo tpl to add to vest/pockets + * @param cartridgeCount number of cartridges to add to vest/pockets + * @param inventory bot inventory to add cartridges to + */ + addBulletsToVestAndPockets(ammoTpl: string, cartridgeCount: number, inventory: Inventory): void; + /** + * Get a weapons default magazine template id + * @param weaponTemplate weapon to get default magazine for + * @returns tpl of magazine + */ + getWeaponsDefaultMagazineTpl(weaponTemplate: ITemplateItem): string; + /** + * Adds an item with all its childern into specified equipmentSlots, wherever it fits. + * @param equipmentSlots + * @param parentId + * @param parentTpl + * @param itemWithChildren + * @param inventory + * @returns a `boolean` indicating item was added + */ + addItemWithChildrenToEquipmentSlot(equipmentSlots: string[], parentId: string, parentTpl: string, itemWithChildren: Item[], inventory: Inventory): boolean; + /** + * is the provided item allowed inside a container + * @param slot location item wants to be placed in + * @param itemTpl item being placed + * @returns true if allowed + */ + protected itemAllowedInContainer(slot: Grid, itemTpl: string): boolean; +} diff --git a/TypeScript/4UseACustomConfigFile/package.json b/TypeScript/4UseACustomConfigFile/package.json index 045d631..ccf504c 100644 --- a/TypeScript/4UseACustomConfigFile/package.json +++ b/TypeScript/4UseACustomConfigFile/package.json @@ -4,7 +4,7 @@ "main": "src/mod.js", "license": "MIT", "author": "Chomp", - "akiVersion": "3.2.2", + "akiVersion": "3.2.3", "scripts": { "setup": "npm i", "build": "node ./packageBuild.ts" diff --git a/TypeScript/4UseACustomConfigFile/types/generators/BotLootGenerator.d.ts b/TypeScript/4UseACustomConfigFile/types/generators/BotLootGenerator.d.ts index 5a2d144..c1f5310 100644 --- a/TypeScript/4UseACustomConfigFile/types/generators/BotLootGenerator.d.ts +++ b/TypeScript/4UseACustomConfigFile/types/generators/BotLootGenerator.d.ts @@ -1,4 +1,5 @@ import { BotGeneratorHelper } from "../helpers/BotGeneratorHelper"; +import { BotWeaponGeneratorHelper } from "../helpers/BotWeaponGeneratorHelper"; import { HandbookHelper } from "../helpers/HandbookHelper"; import { Inventory as PmcInventory } from "../models/eft/common/tables/IBotBase"; import { Chances, Inventory, ItemMinMax, ModsChances } from "../models/eft/common/tables/IBotType"; @@ -20,10 +21,11 @@ export declare class BotLootGenerator { protected handbookHelper: HandbookHelper; protected botGeneratorHelper: BotGeneratorHelper; protected botWeaponGenerator: BotWeaponGenerator; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; protected botLootCacheService: BotLootCacheService; protected configServer: ConfigServer; protected botConfig: IBotConfig; - constructor(logger: ILogger, hashUtil: HashUtil, randomUtil: RandomUtil, databaseServer: DatabaseServer, handbookHelper: HandbookHelper, botGeneratorHelper: BotGeneratorHelper, botWeaponGenerator: BotWeaponGenerator, botLootCacheService: BotLootCacheService, configServer: ConfigServer); + constructor(logger: ILogger, hashUtil: HashUtil, randomUtil: RandomUtil, databaseServer: DatabaseServer, handbookHelper: HandbookHelper, botGeneratorHelper: BotGeneratorHelper, botWeaponGenerator: BotWeaponGenerator, botWeaponGeneratorHelper: BotWeaponGeneratorHelper, botLootCacheService: BotLootCacheService, configServer: ConfigServer); generateLoot(sessionId: string, templateInventory: Inventory, itemCounts: ItemMinMax, isPmc: boolean, botRole: string, botInventory: PmcInventory, equipmentChances: Chances): void; protected getRandomisedCount(min: number, max: number, nValue: number): number; /** diff --git a/TypeScript/4UseACustomConfigFile/types/generators/BotWeaponGenerator.d.ts b/TypeScript/4UseACustomConfigFile/types/generators/BotWeaponGenerator.d.ts index cba7afa..487901b 100644 --- a/TypeScript/4UseACustomConfigFile/types/generators/BotWeaponGenerator.d.ts +++ b/TypeScript/4UseACustomConfigFile/types/generators/BotWeaponGenerator.d.ts @@ -1,4 +1,5 @@ import { BotGeneratorHelper } from "../helpers/BotGeneratorHelper"; +import { BotWeaponGeneratorHelper } from "../helpers/BotWeaponGeneratorHelper"; import { ItemHelper } from "../helpers/ItemHelper"; import { WeightedRandomHelper } from "../helpers/WeightedRandomHelper"; import { MinMax } from "../models/common/MinMax"; @@ -14,6 +15,7 @@ import { DatabaseServer } from "../servers/DatabaseServer"; import { HashUtil } from "../utils/HashUtil"; import { JsonUtil } from "../utils/JsonUtil"; import { RandomUtil } from "../utils/RandomUtil"; +import { IInventoryMagGen } from "./weapongen/IInventoryMagGen"; export declare class BotWeaponGenerator { protected jsonUtil: JsonUtil; protected logger: ILogger; @@ -24,9 +26,11 @@ export declare class BotWeaponGenerator { protected botGeneratorHelper: BotGeneratorHelper; protected randomUtil: RandomUtil; protected configServer: ConfigServer; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + protected inventoryMagGenComponents: IInventoryMagGen[]; protected readonly modMagazineSlotId = "mod_magazine"; protected botConfig: IBotConfig; - constructor(jsonUtil: JsonUtil, logger: ILogger, hashUtil: HashUtil, databaseServer: DatabaseServer, itemHelper: ItemHelper, weightedRandomHelper: WeightedRandomHelper, botGeneratorHelper: BotGeneratorHelper, randomUtil: RandomUtil, configServer: ConfigServer); + constructor(jsonUtil: JsonUtil, logger: ILogger, hashUtil: HashUtil, databaseServer: DatabaseServer, itemHelper: ItemHelper, weightedRandomHelper: WeightedRandomHelper, botGeneratorHelper: BotGeneratorHelper, randomUtil: RandomUtil, configServer: ConfigServer, botWeaponGeneratorHelper: BotWeaponGeneratorHelper, inventoryMagGenComponents: IInventoryMagGen[]); /** * Pick a random weapon based on weightings and generate a functional weapon * @param equipmentSlot Primary/secondary/holster @@ -85,36 +89,12 @@ export declare class BotWeaponGenerator { /** * Generates extra magazines or bullets (if magazine is internal) and adds them to TacticalVest and Pockets. * Additionally, adds extra bullets to SecuredContainer - * @param weaponMods mods to attach to weapon - * @param weaponTemplate db template for weapon - * @param magCounts magazine count to add to inventory - * @param ammoTpl ammo templateId to add to magazines - * @param inventory inventory to add magazines to - * @param botRole the bot type we're getting generating extra mags for - * @returns + * @param generatedWeaponResult object with properties for generated weapon (weapon mods pool / weapon template / ammo tpl) + * @param magCounts Magazine count to add to inventory + * @param inventory Inventory to add magazines to + * @param botRole The bot type we're getting generating extra mags for */ - addExtraMagazinesToInventory(weaponMods: Item[], weaponTemplate: ITemplateItem, magCounts: MinMax, ammoTpl: string, inventory: PmcInventory, botRole: string): void; - /** - * Create a magazine using the parameters given - * @param magazineTpl Tpl of the magazine to create - * @param ammoTpl Ammo to add to magazine - * @param magTemplate template object of magazine - * @returns Item array - */ - protected createMagazine(magazineTpl: string, ammoTpl: string, magTemplate: ITemplateItem): Item[]; - /** - * Get a randomised number of bullets for a specific magazine - * @param magCounts min and max count of magazines - * @param magTemplate magazine to generate bullet count for - * @returns bullet count number - */ - protected getRandomisedBulletCount(magCounts: MinMax, magTemplate: ITemplateItem): number; - /** - * Get a randomised count of magazines - * @param magCounts min and max value returned value can be between - * @returns numberical value of magazine count - */ - protected getRandomisedMagazineCount(magCounts: MinMax): number; + addExtraMagazinesToInventory(generatedWeaponResult: GenerateWeaponResult, magCounts: MinMax, inventory: PmcInventory, botRole: string): void; /** * Add ammo to the secure container * @param stackCount How many stacks of ammo to add @@ -131,13 +111,6 @@ export declare class BotWeaponGenerator { * @returns magazine tpl string */ protected getMagazineTplFromWeaponTemplate(weaponMods: Item[], weaponTemplate: ITemplateItem, botRole: string): string; - /** - * Get a weapons default magazine template id - * @param weaponTemplate weapon to get default magazine for - * @returns tpl of magazine - */ - protected getWeaponsDefaultMagazineTpl(weaponTemplate: ITemplateItem): string; - protected addBulletsToVestAndPockets(ammoTpl: string, bulletCount: number, inventory: PmcInventory): void; /** * Finds and return a compatible ammo tpl based on the bots ammo weightings (x.json/inventory/equipment/ammo) * @param ammo a list of ammo tpls the weapon can use diff --git a/TypeScript/4UseACustomConfigFile/types/generators/weapongen/IInventoryMagGen.d.ts b/TypeScript/4UseACustomConfigFile/types/generators/weapongen/IInventoryMagGen.d.ts new file mode 100644 index 0000000..792f510 --- /dev/null +++ b/TypeScript/4UseACustomConfigFile/types/generators/weapongen/IInventoryMagGen.d.ts @@ -0,0 +1,6 @@ +import { InventoryMagGen } from "./InventoryMagGen"; +export interface IInventoryMagGen { + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/4UseACustomConfigFile/types/generators/weapongen/InventoryMagGen.d.ts b/TypeScript/4UseACustomConfigFile/types/generators/weapongen/InventoryMagGen.d.ts new file mode 100644 index 0000000..30bf79f --- /dev/null +++ b/TypeScript/4UseACustomConfigFile/types/generators/weapongen/InventoryMagGen.d.ts @@ -0,0 +1,16 @@ +import { MinMax } from "../../models/common/MinMax"; +import { Inventory } from "../../models/eft/common/tables/IBotBase"; +import { ITemplateItem } from "../../models/eft/common/tables/ITemplateItem"; +export declare class InventoryMagGen { + private magCounts; + private magazineTemplate; + private weaponTemplate; + private ammoTemplate; + private pmcInventory; + constructor(magCounts: MinMax, magazineTemplate: ITemplateItem, weaponTemplate: ITemplateItem, ammoTemplate: ITemplateItem, pmcInventory: Inventory); + getMagCount(): MinMax; + getMagazineTemplate(): ITemplateItem; + getWeaponTemplate(): ITemplateItem; + getAmmoTemplate(): ITemplateItem; + getPmcInventory(): Inventory; +} diff --git a/TypeScript/4UseACustomConfigFile/types/generators/weapongen/implementations/BarrelInventoryMagGen.d.ts b/TypeScript/4UseACustomConfigFile/types/generators/weapongen/implementations/BarrelInventoryMagGen.d.ts new file mode 100644 index 0000000..b754d5f --- /dev/null +++ b/TypeScript/4UseACustomConfigFile/types/generators/weapongen/implementations/BarrelInventoryMagGen.d.ts @@ -0,0 +1,12 @@ +import { BotWeaponGeneratorHelper } from "../../../helpers/BotWeaponGeneratorHelper"; +import { RandomUtil } from "../../../utils/RandomUtil"; +import { IInventoryMagGen } from "../IInventoryMagGen"; +import { InventoryMagGen } from "../InventoryMagGen"; +export declare class BarrelInventoryMagGen implements IInventoryMagGen { + protected randomUtil: RandomUtil; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + constructor(randomUtil: RandomUtil, botWeaponGeneratorHelper: BotWeaponGeneratorHelper); + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/4UseACustomConfigFile/types/generators/weapongen/implementations/ExternalInventoryMagGen.d.ts b/TypeScript/4UseACustomConfigFile/types/generators/weapongen/implementations/ExternalInventoryMagGen.d.ts new file mode 100644 index 0000000..4fcb1e2 --- /dev/null +++ b/TypeScript/4UseACustomConfigFile/types/generators/weapongen/implementations/ExternalInventoryMagGen.d.ts @@ -0,0 +1,14 @@ +import { BotWeaponGeneratorHelper } from "../../../helpers/BotWeaponGeneratorHelper"; +import { ItemHelper } from "../../../helpers/ItemHelper"; +import { ILogger } from "../../../models/spt/utils/ILogger"; +import { IInventoryMagGen } from "../IInventoryMagGen"; +import { InventoryMagGen } from "../InventoryMagGen"; +export declare class ExternalInventoryMagGen implements IInventoryMagGen { + protected logger: ILogger; + protected itemHelper: ItemHelper; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + constructor(logger: ILogger, itemHelper: ItemHelper, botWeaponGeneratorHelper: BotWeaponGeneratorHelper); + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/4UseACustomConfigFile/types/generators/weapongen/implementations/InternalMagazineInventoryMagGen.d.ts b/TypeScript/4UseACustomConfigFile/types/generators/weapongen/implementations/InternalMagazineInventoryMagGen.d.ts new file mode 100644 index 0000000..4548a04 --- /dev/null +++ b/TypeScript/4UseACustomConfigFile/types/generators/weapongen/implementations/InternalMagazineInventoryMagGen.d.ts @@ -0,0 +1,10 @@ +import { BotWeaponGeneratorHelper } from "../../../helpers/BotWeaponGeneratorHelper"; +import { IInventoryMagGen } from "../IInventoryMagGen"; +import { InventoryMagGen } from "../InventoryMagGen"; +export declare class InternalMagazineInventoryMagGen implements IInventoryMagGen { + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + constructor(botWeaponGeneratorHelper: BotWeaponGeneratorHelper); + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/4UseACustomConfigFile/types/helpers/BotGeneratorHelper.d.ts b/TypeScript/4UseACustomConfigFile/types/helpers/BotGeneratorHelper.d.ts index 09e5c8f..5e3e501 100644 --- a/TypeScript/4UseACustomConfigFile/types/helpers/BotGeneratorHelper.d.ts +++ b/TypeScript/4UseACustomConfigFile/types/helpers/BotGeneratorHelper.d.ts @@ -1,8 +1,7 @@ import { DurabilityLimitsHelper } from "../helpers/DurabilityLimitsHelper"; -import { Inventory as PmcInventory } from "../models/eft/common/tables/IBotBase"; import { Mods, ModsChances } from "../models/eft/common/tables/IBotType"; import { Item, Repairable, Upd } from "../models/eft/common/tables/IItem"; -import { Grid, ITemplateItem, Slot } from "../models/eft/common/tables/ITemplateItem"; +import { ITemplateItem, Slot } from "../models/eft/common/tables/ITemplateItem"; import { EquipmentFilterDetails, IBotConfig } from "../models/spt/config/IBotConfig"; import { ILogger } from "../models/spt/utils/ILogger"; import { ConfigServer } from "../servers/ConfigServer"; @@ -12,6 +11,7 @@ import { ItemFilterService } from "../services/ItemFilterService"; import { HashUtil } from "../utils/HashUtil"; import { JsonUtil } from "../utils/JsonUtil"; import { RandomUtil } from "../utils/RandomUtil"; +import { BotWeaponGeneratorHelper } from "./BotWeaponGeneratorHelper"; import { ContainerHelper } from "./ContainerHelper"; import { InventoryHelper } from "./InventoryHelper"; import { ItemHelper } from "./ItemHelper"; @@ -42,11 +42,11 @@ export declare class BotGeneratorHelper { protected botEquipmentFilterService: BotEquipmentFilterService; protected itemFilterService: ItemFilterService; protected profileHelper: ProfileHelper; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; protected configServer: ConfigServer; protected botConfig: IBotConfig; - constructor(logger: ILogger, jsonUtil: JsonUtil, hashUtil: HashUtil, randomUtil: RandomUtil, probabilityHelper: ProbabilityHelper, databaseServer: DatabaseServer, durabilityLimitsHelper: DurabilityLimitsHelper, itemHelper: ItemHelper, inventoryHelper: InventoryHelper, containerHelper: ContainerHelper, botEquipmentFilterService: BotEquipmentFilterService, itemFilterService: ItemFilterService, profileHelper: ProfileHelper, configServer: ConfigServer); + constructor(logger: ILogger, jsonUtil: JsonUtil, hashUtil: HashUtil, randomUtil: RandomUtil, probabilityHelper: ProbabilityHelper, databaseServer: DatabaseServer, durabilityLimitsHelper: DurabilityLimitsHelper, itemHelper: ItemHelper, inventoryHelper: InventoryHelper, containerHelper: ContainerHelper, botEquipmentFilterService: BotEquipmentFilterService, itemFilterService: ItemFilterService, profileHelper: ProfileHelper, botWeaponGeneratorHelper: BotWeaponGeneratorHelper, configServer: ConfigServer); /** - * TODO - very similar to generateModsForWeapon * Check mods are compatible and add to array * @param equipment Equipment item to add mods to * @param modPool Mod list to choose frm @@ -57,18 +57,30 @@ export declare class BotGeneratorHelper { */ generateModsForEquipment(equipment: Item[], modPool: Mods, parentId: string, parentTemplate: ITemplateItem, modSpawnChances: ModsChances): Item[]; /** - * TODO - very similar to generateModsForEquipment * @param sessionId session id * @param weapon Weapon to add mods to - * @param modPool pool of compatible mods to attach to gun + * @param modPool Pool of compatible mods to attach to weapon * @param weaponParentId parentId of weapon - * @param parentTemplate - * @param modSpawnChances - * @param ammoTpl ammo tpl to use when generating magazines/cartridges - * @param botRole role of bot weapon is generated for - * @returns Weapon with mods + * @param parentWeaponTemplate Weapon which mods will be generated on + * @param modSpawnChances Mod spawn chances + * @param ammoTpl Ammo tpl to use when generating magazines/cartridges + * @param botRole Role of bot weapon is generated for + * @returns Weapon + mods array */ - generateModsForWeapon(sessionId: string, weapon: Item[], modPool: Mods, weaponParentId: string, parentTemplate: ITemplateItem, modSpawnChances: ModsChances, ammoTpl: string, botRole: string): Item[]; + generateModsForWeapon(sessionId: string, weapon: Item[], modPool: Mods, weaponParentId: string, parentWeaponTemplate: ITemplateItem, modSpawnChances: ModsChances, ammoTpl: string, botRole: string): Item[]; + /** + * + * @param modSlot + * @param isRandomisableSlot + * @param modsParent + * @param botEquipBlacklist + * @param itemModPool + * @param weapon array with only weapon tpl in it, ready for mods to be added + * @param ammoTpl ammo tpl to use if slot requires a cartridge to be added (e.g. mod_magazine) + * @param parentTemplate + * @returns + */ + protected chooseModToPutIntoSlot(modSlot: string, isRandomisableSlot: boolean, modsParent: Slot, botEquipBlacklist: EquipmentFilterDetails, itemModPool: Record, weapon: Item[], ammoTpl: string, parentTemplate: ITemplateItem): [boolean, ITemplateItem]; /** * Find mod tpls of a provided type and add to modPool * @param desiredSlotName slot to look up and add we are adding tpls for (e.g mod_scope) @@ -79,15 +91,15 @@ export declare class BotGeneratorHelper { /** * Check if mod item is on limited list + has surpassed the limit set for it * @param botRole role the bot has e.g. assault - * @param modTpl mods tpl + * @param modTemplate mods template data * @param modLimits limits set for weapon being generated for this bot * @returns true if over item limit */ - protected modHasReachedItemLimit(botRole: string, modTpl: string, modLimits: BotModLimits): boolean; + protected modHasReachedItemLimit(botRole: string, modTemplate: ITemplateItem, modLimits: BotModLimits): boolean; /** - * Initalise mod limits to be used when generating the weapon + * Initalise mod limits to be used when generating a weapon * @param botRole "assault", "bossTagilla" or "pmc" - * @returns + * @returns BotModLimits object */ protected initModLimits(botRole: string): BotModLimits; /** @@ -114,7 +126,7 @@ export declare class BotGeneratorHelper { protected filterWeaponModsByBlacklist(allowedMods: string[], botEquipBlacklist: EquipmentFilterDetails, modSlot: string): string[]; /** * Check if the specific item type on the weapon has reached the set limit - * @param modTpl item to check is limited + * @param modTpl log mod tpl if over type limit * @param currentCount current number of this item on gun * @param maxLimit mod limit allowed * @param botRole role of bot we're checking weapon of @@ -124,16 +136,14 @@ export declare class BotGeneratorHelper { count: number; }, maxLimit: number, botRole: string): boolean; /** - * log errors if mod is not valid for a slot - * @param modTpl - * @param found - * @param itemSlot - * @param modTemplate - * @param modSlot - * @param parentTemplate + * Log errors if mod is not compatible with slot + * @param modToAdd template of mod to check + * @param itemSlot slot the item will be placed in + * @param modSlot slot the mod will fill + * @param parentTemplate tempalte of the mods parent item * @returns true if valid */ - protected isModValidForSlot(modTpl: string, found: boolean, itemSlot: Slot, modTemplate: ITemplateItem, modSlot: string, parentTemplate: ITemplateItem): boolean; + protected isModValidForSlot(modToAdd: [boolean, ITemplateItem], itemSlot: Slot, modSlot: string, parentTemplate: ITemplateItem): boolean; /** * Create a mod item with parameters as properties * @param modId _id @@ -144,12 +154,6 @@ export declare class BotGeneratorHelper { * @returns Item object */ protected createModItem(modId: string, modTpl: string, parentId: string, modSlot: string, modTemplate: ITemplateItem): Item; - /** - * Is this magazine cylinder related (revolvers and grenade launchers) - * @param magazineParentName the name of the magazines parent - * @returns true if it is cylinder related - */ - magazineIsCylinderRelated(magazineParentName: string): boolean; /** * randomly choose if a mod should be spawned, 100% for required mods OR mod is ammo slot * never return true for an item that has 0% spawn chance @@ -161,7 +165,7 @@ export declare class BotGeneratorHelper { protected shouldModBeSpawned(itemSlot: Slot, modSlot: string, modSpawnChances: ModsChances): boolean; /** * Get a list of containers that hold ammo - * e.g. mod_magazine + * e.g. mod_magazine / patron_in_weapon_000 * @returns string array */ protected getAmmoContainers(): string[]; @@ -214,6 +218,14 @@ export declare class BotGeneratorHelper { * @returns Repairable object */ protected generateArmorRepairableProperties(itemTemplate: ITemplateItem, botRole: string): Repairable; + /** + * Get a random mod from an items compatible mods Filter array + * @param modTpl + * @param parentSlot + * @param modSlot + * @param items + * @returns item tpl + */ protected getModTplFromItemDb(modTpl: string, parentSlot: Slot, modSlot: string, items: Item[]): string; /** * Can an item be added to an item without issue @@ -223,23 +235,6 @@ export declare class BotGeneratorHelper { * @returns true if possible */ isItemIncompatibleWithCurrentItems(items: Item[], tplToCheck: string, equipmentSlot: string): boolean; - /** - * Adds an item with all its childern into specified equipmentSlots, wherever it fits. - * @param equipmentSlots - * @param parentId - * @param parentTpl - * @param itemWithChildren - * @param inventory - * @returns a `boolean` indicating item was added - */ - addItemWithChildrenToEquipmentSlot(equipmentSlots: string[], parentId: string, parentTpl: string, itemWithChildren: Item[], inventory: PmcInventory): boolean; - /** - * is the provided item allowed inside a container - * @param slot location item wants to be placed in - * @param itemTpl item being placed - * @returns true if allowed - */ - protected itemAllowedInContainer(slot: Grid, itemTpl: string): boolean; } /** TODO - move into own class */ export declare class ExhaustableArray { diff --git a/TypeScript/4UseACustomConfigFile/types/helpers/BotWeaponGeneratorHelper.d.ts b/TypeScript/4UseACustomConfigFile/types/helpers/BotWeaponGeneratorHelper.d.ts new file mode 100644 index 0000000..7e25f56 --- /dev/null +++ b/TypeScript/4UseACustomConfigFile/types/helpers/BotWeaponGeneratorHelper.d.ts @@ -0,0 +1,78 @@ +import { MinMax } from "../models/common/MinMax"; +import { Inventory } from "../models/eft/common/tables/IBotBase"; +import { Item } from "../models/eft/common/tables/IItem"; +import { Grid, ITemplateItem } from "../models/eft/common/tables/ITemplateItem"; +import { ILogger } from "../models/spt/utils/ILogger"; +import { DatabaseServer } from "../servers/DatabaseServer"; +import { HashUtil } from "../utils/HashUtil"; +import { RandomUtil } from "../utils/RandomUtil"; +import { ContainerHelper } from "./ContainerHelper"; +import { InventoryHelper } from "./InventoryHelper"; +import { ItemHelper } from "./ItemHelper"; +export declare class BotWeaponGeneratorHelper { + protected logger: ILogger; + protected databaseServer: DatabaseServer; + protected itemHelper: ItemHelper; + protected randomUtil: RandomUtil; + protected hashUtil: HashUtil; + protected inventoryHelper: InventoryHelper; + protected containerHelper: ContainerHelper; + constructor(logger: ILogger, databaseServer: DatabaseServer, itemHelper: ItemHelper, randomUtil: RandomUtil, hashUtil: HashUtil, inventoryHelper: InventoryHelper, containerHelper: ContainerHelper); + /** + * Get a randomised number of bullets for a specific magazine + * @param magCounts min and max count of magazines + * @param magTemplate magazine to generate bullet count for + * @returns bullet count number + */ + getRandomisedBulletCount(magCounts: MinMax, magTemplate: ITemplateItem): number; + /** + * Get a randomised count of magazines + * @param magCounts min and max value returned value can be between + * @returns numberical value of magazine count + */ + getRandomisedMagazineCount(magCounts: MinMax): number; + /** + * Is this magazine cylinder related (revolvers and grenade launchers) + * @param magazineParentName the name of the magazines parent + * @returns true if it is cylinder related + */ + magazineIsCylinderRelated(magazineParentName: string): boolean; + /** + * Create a magazine using the parameters given + * @param magazineTpl Tpl of the magazine to create + * @param ammoTpl Ammo to add to magazine + * @param magTemplate template object of magazine + * @returns Item array + */ + createMagazine(magazineTpl: string, ammoTpl: string, magTemplate: ITemplateItem): Item[]; + /** + * Add a specific number of cartrdiges to a bots inventory (vest/pocket) + * @param ammoTpl Ammo tpl to add to vest/pockets + * @param cartridgeCount number of cartridges to add to vest/pockets + * @param inventory bot inventory to add cartridges to + */ + addBulletsToVestAndPockets(ammoTpl: string, cartridgeCount: number, inventory: Inventory): void; + /** + * Get a weapons default magazine template id + * @param weaponTemplate weapon to get default magazine for + * @returns tpl of magazine + */ + getWeaponsDefaultMagazineTpl(weaponTemplate: ITemplateItem): string; + /** + * Adds an item with all its childern into specified equipmentSlots, wherever it fits. + * @param equipmentSlots + * @param parentId + * @param parentTpl + * @param itemWithChildren + * @param inventory + * @returns a `boolean` indicating item was added + */ + addItemWithChildrenToEquipmentSlot(equipmentSlots: string[], parentId: string, parentTpl: string, itemWithChildren: Item[], inventory: Inventory): boolean; + /** + * is the provided item allowed inside a container + * @param slot location item wants to be placed in + * @param itemTpl item being placed + * @returns true if allowed + */ + protected itemAllowedInContainer(slot: Grid, itemTpl: string): boolean; +} diff --git a/TypeScript/5ReplaceMethod/package.json b/TypeScript/5ReplaceMethod/package.json index f782acb..a65e021 100644 --- a/TypeScript/5ReplaceMethod/package.json +++ b/TypeScript/5ReplaceMethod/package.json @@ -4,7 +4,7 @@ "main": "src/mod.js", "license": "MIT", "author": "Chomp", - "akiVersion": "3.2.2", + "akiVersion": "3.2.3", "scripts": { "setup": "npm i", "build": "node ./packageBuild.ts" diff --git a/TypeScript/5ReplaceMethod/types/generators/BotLootGenerator.d.ts b/TypeScript/5ReplaceMethod/types/generators/BotLootGenerator.d.ts index 5a2d144..c1f5310 100644 --- a/TypeScript/5ReplaceMethod/types/generators/BotLootGenerator.d.ts +++ b/TypeScript/5ReplaceMethod/types/generators/BotLootGenerator.d.ts @@ -1,4 +1,5 @@ import { BotGeneratorHelper } from "../helpers/BotGeneratorHelper"; +import { BotWeaponGeneratorHelper } from "../helpers/BotWeaponGeneratorHelper"; import { HandbookHelper } from "../helpers/HandbookHelper"; import { Inventory as PmcInventory } from "../models/eft/common/tables/IBotBase"; import { Chances, Inventory, ItemMinMax, ModsChances } from "../models/eft/common/tables/IBotType"; @@ -20,10 +21,11 @@ export declare class BotLootGenerator { protected handbookHelper: HandbookHelper; protected botGeneratorHelper: BotGeneratorHelper; protected botWeaponGenerator: BotWeaponGenerator; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; protected botLootCacheService: BotLootCacheService; protected configServer: ConfigServer; protected botConfig: IBotConfig; - constructor(logger: ILogger, hashUtil: HashUtil, randomUtil: RandomUtil, databaseServer: DatabaseServer, handbookHelper: HandbookHelper, botGeneratorHelper: BotGeneratorHelper, botWeaponGenerator: BotWeaponGenerator, botLootCacheService: BotLootCacheService, configServer: ConfigServer); + constructor(logger: ILogger, hashUtil: HashUtil, randomUtil: RandomUtil, databaseServer: DatabaseServer, handbookHelper: HandbookHelper, botGeneratorHelper: BotGeneratorHelper, botWeaponGenerator: BotWeaponGenerator, botWeaponGeneratorHelper: BotWeaponGeneratorHelper, botLootCacheService: BotLootCacheService, configServer: ConfigServer); generateLoot(sessionId: string, templateInventory: Inventory, itemCounts: ItemMinMax, isPmc: boolean, botRole: string, botInventory: PmcInventory, equipmentChances: Chances): void; protected getRandomisedCount(min: number, max: number, nValue: number): number; /** diff --git a/TypeScript/5ReplaceMethod/types/generators/BotWeaponGenerator.d.ts b/TypeScript/5ReplaceMethod/types/generators/BotWeaponGenerator.d.ts index cba7afa..487901b 100644 --- a/TypeScript/5ReplaceMethod/types/generators/BotWeaponGenerator.d.ts +++ b/TypeScript/5ReplaceMethod/types/generators/BotWeaponGenerator.d.ts @@ -1,4 +1,5 @@ import { BotGeneratorHelper } from "../helpers/BotGeneratorHelper"; +import { BotWeaponGeneratorHelper } from "../helpers/BotWeaponGeneratorHelper"; import { ItemHelper } from "../helpers/ItemHelper"; import { WeightedRandomHelper } from "../helpers/WeightedRandomHelper"; import { MinMax } from "../models/common/MinMax"; @@ -14,6 +15,7 @@ import { DatabaseServer } from "../servers/DatabaseServer"; import { HashUtil } from "../utils/HashUtil"; import { JsonUtil } from "../utils/JsonUtil"; import { RandomUtil } from "../utils/RandomUtil"; +import { IInventoryMagGen } from "./weapongen/IInventoryMagGen"; export declare class BotWeaponGenerator { protected jsonUtil: JsonUtil; protected logger: ILogger; @@ -24,9 +26,11 @@ export declare class BotWeaponGenerator { protected botGeneratorHelper: BotGeneratorHelper; protected randomUtil: RandomUtil; protected configServer: ConfigServer; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + protected inventoryMagGenComponents: IInventoryMagGen[]; protected readonly modMagazineSlotId = "mod_magazine"; protected botConfig: IBotConfig; - constructor(jsonUtil: JsonUtil, logger: ILogger, hashUtil: HashUtil, databaseServer: DatabaseServer, itemHelper: ItemHelper, weightedRandomHelper: WeightedRandomHelper, botGeneratorHelper: BotGeneratorHelper, randomUtil: RandomUtil, configServer: ConfigServer); + constructor(jsonUtil: JsonUtil, logger: ILogger, hashUtil: HashUtil, databaseServer: DatabaseServer, itemHelper: ItemHelper, weightedRandomHelper: WeightedRandomHelper, botGeneratorHelper: BotGeneratorHelper, randomUtil: RandomUtil, configServer: ConfigServer, botWeaponGeneratorHelper: BotWeaponGeneratorHelper, inventoryMagGenComponents: IInventoryMagGen[]); /** * Pick a random weapon based on weightings and generate a functional weapon * @param equipmentSlot Primary/secondary/holster @@ -85,36 +89,12 @@ export declare class BotWeaponGenerator { /** * Generates extra magazines or bullets (if magazine is internal) and adds them to TacticalVest and Pockets. * Additionally, adds extra bullets to SecuredContainer - * @param weaponMods mods to attach to weapon - * @param weaponTemplate db template for weapon - * @param magCounts magazine count to add to inventory - * @param ammoTpl ammo templateId to add to magazines - * @param inventory inventory to add magazines to - * @param botRole the bot type we're getting generating extra mags for - * @returns + * @param generatedWeaponResult object with properties for generated weapon (weapon mods pool / weapon template / ammo tpl) + * @param magCounts Magazine count to add to inventory + * @param inventory Inventory to add magazines to + * @param botRole The bot type we're getting generating extra mags for */ - addExtraMagazinesToInventory(weaponMods: Item[], weaponTemplate: ITemplateItem, magCounts: MinMax, ammoTpl: string, inventory: PmcInventory, botRole: string): void; - /** - * Create a magazine using the parameters given - * @param magazineTpl Tpl of the magazine to create - * @param ammoTpl Ammo to add to magazine - * @param magTemplate template object of magazine - * @returns Item array - */ - protected createMagazine(magazineTpl: string, ammoTpl: string, magTemplate: ITemplateItem): Item[]; - /** - * Get a randomised number of bullets for a specific magazine - * @param magCounts min and max count of magazines - * @param magTemplate magazine to generate bullet count for - * @returns bullet count number - */ - protected getRandomisedBulletCount(magCounts: MinMax, magTemplate: ITemplateItem): number; - /** - * Get a randomised count of magazines - * @param magCounts min and max value returned value can be between - * @returns numberical value of magazine count - */ - protected getRandomisedMagazineCount(magCounts: MinMax): number; + addExtraMagazinesToInventory(generatedWeaponResult: GenerateWeaponResult, magCounts: MinMax, inventory: PmcInventory, botRole: string): void; /** * Add ammo to the secure container * @param stackCount How many stacks of ammo to add @@ -131,13 +111,6 @@ export declare class BotWeaponGenerator { * @returns magazine tpl string */ protected getMagazineTplFromWeaponTemplate(weaponMods: Item[], weaponTemplate: ITemplateItem, botRole: string): string; - /** - * Get a weapons default magazine template id - * @param weaponTemplate weapon to get default magazine for - * @returns tpl of magazine - */ - protected getWeaponsDefaultMagazineTpl(weaponTemplate: ITemplateItem): string; - protected addBulletsToVestAndPockets(ammoTpl: string, bulletCount: number, inventory: PmcInventory): void; /** * Finds and return a compatible ammo tpl based on the bots ammo weightings (x.json/inventory/equipment/ammo) * @param ammo a list of ammo tpls the weapon can use diff --git a/TypeScript/5ReplaceMethod/types/generators/weapongen/IInventoryMagGen.d.ts b/TypeScript/5ReplaceMethod/types/generators/weapongen/IInventoryMagGen.d.ts new file mode 100644 index 0000000..792f510 --- /dev/null +++ b/TypeScript/5ReplaceMethod/types/generators/weapongen/IInventoryMagGen.d.ts @@ -0,0 +1,6 @@ +import { InventoryMagGen } from "./InventoryMagGen"; +export interface IInventoryMagGen { + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/5ReplaceMethod/types/generators/weapongen/InventoryMagGen.d.ts b/TypeScript/5ReplaceMethod/types/generators/weapongen/InventoryMagGen.d.ts new file mode 100644 index 0000000..30bf79f --- /dev/null +++ b/TypeScript/5ReplaceMethod/types/generators/weapongen/InventoryMagGen.d.ts @@ -0,0 +1,16 @@ +import { MinMax } from "../../models/common/MinMax"; +import { Inventory } from "../../models/eft/common/tables/IBotBase"; +import { ITemplateItem } from "../../models/eft/common/tables/ITemplateItem"; +export declare class InventoryMagGen { + private magCounts; + private magazineTemplate; + private weaponTemplate; + private ammoTemplate; + private pmcInventory; + constructor(magCounts: MinMax, magazineTemplate: ITemplateItem, weaponTemplate: ITemplateItem, ammoTemplate: ITemplateItem, pmcInventory: Inventory); + getMagCount(): MinMax; + getMagazineTemplate(): ITemplateItem; + getWeaponTemplate(): ITemplateItem; + getAmmoTemplate(): ITemplateItem; + getPmcInventory(): Inventory; +} diff --git a/TypeScript/5ReplaceMethod/types/generators/weapongen/implementations/BarrelInventoryMagGen.d.ts b/TypeScript/5ReplaceMethod/types/generators/weapongen/implementations/BarrelInventoryMagGen.d.ts new file mode 100644 index 0000000..b754d5f --- /dev/null +++ b/TypeScript/5ReplaceMethod/types/generators/weapongen/implementations/BarrelInventoryMagGen.d.ts @@ -0,0 +1,12 @@ +import { BotWeaponGeneratorHelper } from "../../../helpers/BotWeaponGeneratorHelper"; +import { RandomUtil } from "../../../utils/RandomUtil"; +import { IInventoryMagGen } from "../IInventoryMagGen"; +import { InventoryMagGen } from "../InventoryMagGen"; +export declare class BarrelInventoryMagGen implements IInventoryMagGen { + protected randomUtil: RandomUtil; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + constructor(randomUtil: RandomUtil, botWeaponGeneratorHelper: BotWeaponGeneratorHelper); + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/5ReplaceMethod/types/generators/weapongen/implementations/ExternalInventoryMagGen.d.ts b/TypeScript/5ReplaceMethod/types/generators/weapongen/implementations/ExternalInventoryMagGen.d.ts new file mode 100644 index 0000000..4fcb1e2 --- /dev/null +++ b/TypeScript/5ReplaceMethod/types/generators/weapongen/implementations/ExternalInventoryMagGen.d.ts @@ -0,0 +1,14 @@ +import { BotWeaponGeneratorHelper } from "../../../helpers/BotWeaponGeneratorHelper"; +import { ItemHelper } from "../../../helpers/ItemHelper"; +import { ILogger } from "../../../models/spt/utils/ILogger"; +import { IInventoryMagGen } from "../IInventoryMagGen"; +import { InventoryMagGen } from "../InventoryMagGen"; +export declare class ExternalInventoryMagGen implements IInventoryMagGen { + protected logger: ILogger; + protected itemHelper: ItemHelper; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + constructor(logger: ILogger, itemHelper: ItemHelper, botWeaponGeneratorHelper: BotWeaponGeneratorHelper); + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/5ReplaceMethod/types/generators/weapongen/implementations/InternalMagazineInventoryMagGen.d.ts b/TypeScript/5ReplaceMethod/types/generators/weapongen/implementations/InternalMagazineInventoryMagGen.d.ts new file mode 100644 index 0000000..4548a04 --- /dev/null +++ b/TypeScript/5ReplaceMethod/types/generators/weapongen/implementations/InternalMagazineInventoryMagGen.d.ts @@ -0,0 +1,10 @@ +import { BotWeaponGeneratorHelper } from "../../../helpers/BotWeaponGeneratorHelper"; +import { IInventoryMagGen } from "../IInventoryMagGen"; +import { InventoryMagGen } from "../InventoryMagGen"; +export declare class InternalMagazineInventoryMagGen implements IInventoryMagGen { + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + constructor(botWeaponGeneratorHelper: BotWeaponGeneratorHelper); + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/5ReplaceMethod/types/helpers/BotGeneratorHelper.d.ts b/TypeScript/5ReplaceMethod/types/helpers/BotGeneratorHelper.d.ts index 09e5c8f..5e3e501 100644 --- a/TypeScript/5ReplaceMethod/types/helpers/BotGeneratorHelper.d.ts +++ b/TypeScript/5ReplaceMethod/types/helpers/BotGeneratorHelper.d.ts @@ -1,8 +1,7 @@ import { DurabilityLimitsHelper } from "../helpers/DurabilityLimitsHelper"; -import { Inventory as PmcInventory } from "../models/eft/common/tables/IBotBase"; import { Mods, ModsChances } from "../models/eft/common/tables/IBotType"; import { Item, Repairable, Upd } from "../models/eft/common/tables/IItem"; -import { Grid, ITemplateItem, Slot } from "../models/eft/common/tables/ITemplateItem"; +import { ITemplateItem, Slot } from "../models/eft/common/tables/ITemplateItem"; import { EquipmentFilterDetails, IBotConfig } from "../models/spt/config/IBotConfig"; import { ILogger } from "../models/spt/utils/ILogger"; import { ConfigServer } from "../servers/ConfigServer"; @@ -12,6 +11,7 @@ import { ItemFilterService } from "../services/ItemFilterService"; import { HashUtil } from "../utils/HashUtil"; import { JsonUtil } from "../utils/JsonUtil"; import { RandomUtil } from "../utils/RandomUtil"; +import { BotWeaponGeneratorHelper } from "./BotWeaponGeneratorHelper"; import { ContainerHelper } from "./ContainerHelper"; import { InventoryHelper } from "./InventoryHelper"; import { ItemHelper } from "./ItemHelper"; @@ -42,11 +42,11 @@ export declare class BotGeneratorHelper { protected botEquipmentFilterService: BotEquipmentFilterService; protected itemFilterService: ItemFilterService; protected profileHelper: ProfileHelper; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; protected configServer: ConfigServer; protected botConfig: IBotConfig; - constructor(logger: ILogger, jsonUtil: JsonUtil, hashUtil: HashUtil, randomUtil: RandomUtil, probabilityHelper: ProbabilityHelper, databaseServer: DatabaseServer, durabilityLimitsHelper: DurabilityLimitsHelper, itemHelper: ItemHelper, inventoryHelper: InventoryHelper, containerHelper: ContainerHelper, botEquipmentFilterService: BotEquipmentFilterService, itemFilterService: ItemFilterService, profileHelper: ProfileHelper, configServer: ConfigServer); + constructor(logger: ILogger, jsonUtil: JsonUtil, hashUtil: HashUtil, randomUtil: RandomUtil, probabilityHelper: ProbabilityHelper, databaseServer: DatabaseServer, durabilityLimitsHelper: DurabilityLimitsHelper, itemHelper: ItemHelper, inventoryHelper: InventoryHelper, containerHelper: ContainerHelper, botEquipmentFilterService: BotEquipmentFilterService, itemFilterService: ItemFilterService, profileHelper: ProfileHelper, botWeaponGeneratorHelper: BotWeaponGeneratorHelper, configServer: ConfigServer); /** - * TODO - very similar to generateModsForWeapon * Check mods are compatible and add to array * @param equipment Equipment item to add mods to * @param modPool Mod list to choose frm @@ -57,18 +57,30 @@ export declare class BotGeneratorHelper { */ generateModsForEquipment(equipment: Item[], modPool: Mods, parentId: string, parentTemplate: ITemplateItem, modSpawnChances: ModsChances): Item[]; /** - * TODO - very similar to generateModsForEquipment * @param sessionId session id * @param weapon Weapon to add mods to - * @param modPool pool of compatible mods to attach to gun + * @param modPool Pool of compatible mods to attach to weapon * @param weaponParentId parentId of weapon - * @param parentTemplate - * @param modSpawnChances - * @param ammoTpl ammo tpl to use when generating magazines/cartridges - * @param botRole role of bot weapon is generated for - * @returns Weapon with mods + * @param parentWeaponTemplate Weapon which mods will be generated on + * @param modSpawnChances Mod spawn chances + * @param ammoTpl Ammo tpl to use when generating magazines/cartridges + * @param botRole Role of bot weapon is generated for + * @returns Weapon + mods array */ - generateModsForWeapon(sessionId: string, weapon: Item[], modPool: Mods, weaponParentId: string, parentTemplate: ITemplateItem, modSpawnChances: ModsChances, ammoTpl: string, botRole: string): Item[]; + generateModsForWeapon(sessionId: string, weapon: Item[], modPool: Mods, weaponParentId: string, parentWeaponTemplate: ITemplateItem, modSpawnChances: ModsChances, ammoTpl: string, botRole: string): Item[]; + /** + * + * @param modSlot + * @param isRandomisableSlot + * @param modsParent + * @param botEquipBlacklist + * @param itemModPool + * @param weapon array with only weapon tpl in it, ready for mods to be added + * @param ammoTpl ammo tpl to use if slot requires a cartridge to be added (e.g. mod_magazine) + * @param parentTemplate + * @returns + */ + protected chooseModToPutIntoSlot(modSlot: string, isRandomisableSlot: boolean, modsParent: Slot, botEquipBlacklist: EquipmentFilterDetails, itemModPool: Record, weapon: Item[], ammoTpl: string, parentTemplate: ITemplateItem): [boolean, ITemplateItem]; /** * Find mod tpls of a provided type and add to modPool * @param desiredSlotName slot to look up and add we are adding tpls for (e.g mod_scope) @@ -79,15 +91,15 @@ export declare class BotGeneratorHelper { /** * Check if mod item is on limited list + has surpassed the limit set for it * @param botRole role the bot has e.g. assault - * @param modTpl mods tpl + * @param modTemplate mods template data * @param modLimits limits set for weapon being generated for this bot * @returns true if over item limit */ - protected modHasReachedItemLimit(botRole: string, modTpl: string, modLimits: BotModLimits): boolean; + protected modHasReachedItemLimit(botRole: string, modTemplate: ITemplateItem, modLimits: BotModLimits): boolean; /** - * Initalise mod limits to be used when generating the weapon + * Initalise mod limits to be used when generating a weapon * @param botRole "assault", "bossTagilla" or "pmc" - * @returns + * @returns BotModLimits object */ protected initModLimits(botRole: string): BotModLimits; /** @@ -114,7 +126,7 @@ export declare class BotGeneratorHelper { protected filterWeaponModsByBlacklist(allowedMods: string[], botEquipBlacklist: EquipmentFilterDetails, modSlot: string): string[]; /** * Check if the specific item type on the weapon has reached the set limit - * @param modTpl item to check is limited + * @param modTpl log mod tpl if over type limit * @param currentCount current number of this item on gun * @param maxLimit mod limit allowed * @param botRole role of bot we're checking weapon of @@ -124,16 +136,14 @@ export declare class BotGeneratorHelper { count: number; }, maxLimit: number, botRole: string): boolean; /** - * log errors if mod is not valid for a slot - * @param modTpl - * @param found - * @param itemSlot - * @param modTemplate - * @param modSlot - * @param parentTemplate + * Log errors if mod is not compatible with slot + * @param modToAdd template of mod to check + * @param itemSlot slot the item will be placed in + * @param modSlot slot the mod will fill + * @param parentTemplate tempalte of the mods parent item * @returns true if valid */ - protected isModValidForSlot(modTpl: string, found: boolean, itemSlot: Slot, modTemplate: ITemplateItem, modSlot: string, parentTemplate: ITemplateItem): boolean; + protected isModValidForSlot(modToAdd: [boolean, ITemplateItem], itemSlot: Slot, modSlot: string, parentTemplate: ITemplateItem): boolean; /** * Create a mod item with parameters as properties * @param modId _id @@ -144,12 +154,6 @@ export declare class BotGeneratorHelper { * @returns Item object */ protected createModItem(modId: string, modTpl: string, parentId: string, modSlot: string, modTemplate: ITemplateItem): Item; - /** - * Is this magazine cylinder related (revolvers and grenade launchers) - * @param magazineParentName the name of the magazines parent - * @returns true if it is cylinder related - */ - magazineIsCylinderRelated(magazineParentName: string): boolean; /** * randomly choose if a mod should be spawned, 100% for required mods OR mod is ammo slot * never return true for an item that has 0% spawn chance @@ -161,7 +165,7 @@ export declare class BotGeneratorHelper { protected shouldModBeSpawned(itemSlot: Slot, modSlot: string, modSpawnChances: ModsChances): boolean; /** * Get a list of containers that hold ammo - * e.g. mod_magazine + * e.g. mod_magazine / patron_in_weapon_000 * @returns string array */ protected getAmmoContainers(): string[]; @@ -214,6 +218,14 @@ export declare class BotGeneratorHelper { * @returns Repairable object */ protected generateArmorRepairableProperties(itemTemplate: ITemplateItem, botRole: string): Repairable; + /** + * Get a random mod from an items compatible mods Filter array + * @param modTpl + * @param parentSlot + * @param modSlot + * @param items + * @returns item tpl + */ protected getModTplFromItemDb(modTpl: string, parentSlot: Slot, modSlot: string, items: Item[]): string; /** * Can an item be added to an item without issue @@ -223,23 +235,6 @@ export declare class BotGeneratorHelper { * @returns true if possible */ isItemIncompatibleWithCurrentItems(items: Item[], tplToCheck: string, equipmentSlot: string): boolean; - /** - * Adds an item with all its childern into specified equipmentSlots, wherever it fits. - * @param equipmentSlots - * @param parentId - * @param parentTpl - * @param itemWithChildren - * @param inventory - * @returns a `boolean` indicating item was added - */ - addItemWithChildrenToEquipmentSlot(equipmentSlots: string[], parentId: string, parentTpl: string, itemWithChildren: Item[], inventory: PmcInventory): boolean; - /** - * is the provided item allowed inside a container - * @param slot location item wants to be placed in - * @param itemTpl item being placed - * @returns true if allowed - */ - protected itemAllowedInContainer(slot: Grid, itemTpl: string): boolean; } /** TODO - move into own class */ export declare class ExhaustableArray { diff --git a/TypeScript/5ReplaceMethod/types/helpers/BotWeaponGeneratorHelper.d.ts b/TypeScript/5ReplaceMethod/types/helpers/BotWeaponGeneratorHelper.d.ts new file mode 100644 index 0000000..7e25f56 --- /dev/null +++ b/TypeScript/5ReplaceMethod/types/helpers/BotWeaponGeneratorHelper.d.ts @@ -0,0 +1,78 @@ +import { MinMax } from "../models/common/MinMax"; +import { Inventory } from "../models/eft/common/tables/IBotBase"; +import { Item } from "../models/eft/common/tables/IItem"; +import { Grid, ITemplateItem } from "../models/eft/common/tables/ITemplateItem"; +import { ILogger } from "../models/spt/utils/ILogger"; +import { DatabaseServer } from "../servers/DatabaseServer"; +import { HashUtil } from "../utils/HashUtil"; +import { RandomUtil } from "../utils/RandomUtil"; +import { ContainerHelper } from "./ContainerHelper"; +import { InventoryHelper } from "./InventoryHelper"; +import { ItemHelper } from "./ItemHelper"; +export declare class BotWeaponGeneratorHelper { + protected logger: ILogger; + protected databaseServer: DatabaseServer; + protected itemHelper: ItemHelper; + protected randomUtil: RandomUtil; + protected hashUtil: HashUtil; + protected inventoryHelper: InventoryHelper; + protected containerHelper: ContainerHelper; + constructor(logger: ILogger, databaseServer: DatabaseServer, itemHelper: ItemHelper, randomUtil: RandomUtil, hashUtil: HashUtil, inventoryHelper: InventoryHelper, containerHelper: ContainerHelper); + /** + * Get a randomised number of bullets for a specific magazine + * @param magCounts min and max count of magazines + * @param magTemplate magazine to generate bullet count for + * @returns bullet count number + */ + getRandomisedBulletCount(magCounts: MinMax, magTemplate: ITemplateItem): number; + /** + * Get a randomised count of magazines + * @param magCounts min and max value returned value can be between + * @returns numberical value of magazine count + */ + getRandomisedMagazineCount(magCounts: MinMax): number; + /** + * Is this magazine cylinder related (revolvers and grenade launchers) + * @param magazineParentName the name of the magazines parent + * @returns true if it is cylinder related + */ + magazineIsCylinderRelated(magazineParentName: string): boolean; + /** + * Create a magazine using the parameters given + * @param magazineTpl Tpl of the magazine to create + * @param ammoTpl Ammo to add to magazine + * @param magTemplate template object of magazine + * @returns Item array + */ + createMagazine(magazineTpl: string, ammoTpl: string, magTemplate: ITemplateItem): Item[]; + /** + * Add a specific number of cartrdiges to a bots inventory (vest/pocket) + * @param ammoTpl Ammo tpl to add to vest/pockets + * @param cartridgeCount number of cartridges to add to vest/pockets + * @param inventory bot inventory to add cartridges to + */ + addBulletsToVestAndPockets(ammoTpl: string, cartridgeCount: number, inventory: Inventory): void; + /** + * Get a weapons default magazine template id + * @param weaponTemplate weapon to get default magazine for + * @returns tpl of magazine + */ + getWeaponsDefaultMagazineTpl(weaponTemplate: ITemplateItem): string; + /** + * Adds an item with all its childern into specified equipmentSlots, wherever it fits. + * @param equipmentSlots + * @param parentId + * @param parentTpl + * @param itemWithChildren + * @param inventory + * @returns a `boolean` indicating item was added + */ + addItemWithChildrenToEquipmentSlot(equipmentSlots: string[], parentId: string, parentTpl: string, itemWithChildren: Item[], inventory: Inventory): boolean; + /** + * is the provided item allowed inside a container + * @param slot location item wants to be placed in + * @param itemTpl item being placed + * @returns true if allowed + */ + protected itemAllowedInContainer(slot: Grid, itemTpl: string): boolean; +} diff --git a/TypeScript/6ReferenceAnotherClass/package.json b/TypeScript/6ReferenceAnotherClass/package.json index b05d0d1..da5e572 100644 --- a/TypeScript/6ReferenceAnotherClass/package.json +++ b/TypeScript/6ReferenceAnotherClass/package.json @@ -4,7 +4,7 @@ "main": "src/mod.js", "license": "MIT", "author": "Chomp", - "akiVersion": "3.2.2", + "akiVersion": "3.2.3", "scripts": { "setup": "npm i", "build": "node ./packageBuild.ts" diff --git a/TypeScript/6ReferenceAnotherClass/types/generators/BotLootGenerator.d.ts b/TypeScript/6ReferenceAnotherClass/types/generators/BotLootGenerator.d.ts index 5a2d144..c1f5310 100644 --- a/TypeScript/6ReferenceAnotherClass/types/generators/BotLootGenerator.d.ts +++ b/TypeScript/6ReferenceAnotherClass/types/generators/BotLootGenerator.d.ts @@ -1,4 +1,5 @@ import { BotGeneratorHelper } from "../helpers/BotGeneratorHelper"; +import { BotWeaponGeneratorHelper } from "../helpers/BotWeaponGeneratorHelper"; import { HandbookHelper } from "../helpers/HandbookHelper"; import { Inventory as PmcInventory } from "../models/eft/common/tables/IBotBase"; import { Chances, Inventory, ItemMinMax, ModsChances } from "../models/eft/common/tables/IBotType"; @@ -20,10 +21,11 @@ export declare class BotLootGenerator { protected handbookHelper: HandbookHelper; protected botGeneratorHelper: BotGeneratorHelper; protected botWeaponGenerator: BotWeaponGenerator; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; protected botLootCacheService: BotLootCacheService; protected configServer: ConfigServer; protected botConfig: IBotConfig; - constructor(logger: ILogger, hashUtil: HashUtil, randomUtil: RandomUtil, databaseServer: DatabaseServer, handbookHelper: HandbookHelper, botGeneratorHelper: BotGeneratorHelper, botWeaponGenerator: BotWeaponGenerator, botLootCacheService: BotLootCacheService, configServer: ConfigServer); + constructor(logger: ILogger, hashUtil: HashUtil, randomUtil: RandomUtil, databaseServer: DatabaseServer, handbookHelper: HandbookHelper, botGeneratorHelper: BotGeneratorHelper, botWeaponGenerator: BotWeaponGenerator, botWeaponGeneratorHelper: BotWeaponGeneratorHelper, botLootCacheService: BotLootCacheService, configServer: ConfigServer); generateLoot(sessionId: string, templateInventory: Inventory, itemCounts: ItemMinMax, isPmc: boolean, botRole: string, botInventory: PmcInventory, equipmentChances: Chances): void; protected getRandomisedCount(min: number, max: number, nValue: number): number; /** diff --git a/TypeScript/6ReferenceAnotherClass/types/generators/BotWeaponGenerator.d.ts b/TypeScript/6ReferenceAnotherClass/types/generators/BotWeaponGenerator.d.ts index cba7afa..487901b 100644 --- a/TypeScript/6ReferenceAnotherClass/types/generators/BotWeaponGenerator.d.ts +++ b/TypeScript/6ReferenceAnotherClass/types/generators/BotWeaponGenerator.d.ts @@ -1,4 +1,5 @@ import { BotGeneratorHelper } from "../helpers/BotGeneratorHelper"; +import { BotWeaponGeneratorHelper } from "../helpers/BotWeaponGeneratorHelper"; import { ItemHelper } from "../helpers/ItemHelper"; import { WeightedRandomHelper } from "../helpers/WeightedRandomHelper"; import { MinMax } from "../models/common/MinMax"; @@ -14,6 +15,7 @@ import { DatabaseServer } from "../servers/DatabaseServer"; import { HashUtil } from "../utils/HashUtil"; import { JsonUtil } from "../utils/JsonUtil"; import { RandomUtil } from "../utils/RandomUtil"; +import { IInventoryMagGen } from "./weapongen/IInventoryMagGen"; export declare class BotWeaponGenerator { protected jsonUtil: JsonUtil; protected logger: ILogger; @@ -24,9 +26,11 @@ export declare class BotWeaponGenerator { protected botGeneratorHelper: BotGeneratorHelper; protected randomUtil: RandomUtil; protected configServer: ConfigServer; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + protected inventoryMagGenComponents: IInventoryMagGen[]; protected readonly modMagazineSlotId = "mod_magazine"; protected botConfig: IBotConfig; - constructor(jsonUtil: JsonUtil, logger: ILogger, hashUtil: HashUtil, databaseServer: DatabaseServer, itemHelper: ItemHelper, weightedRandomHelper: WeightedRandomHelper, botGeneratorHelper: BotGeneratorHelper, randomUtil: RandomUtil, configServer: ConfigServer); + constructor(jsonUtil: JsonUtil, logger: ILogger, hashUtil: HashUtil, databaseServer: DatabaseServer, itemHelper: ItemHelper, weightedRandomHelper: WeightedRandomHelper, botGeneratorHelper: BotGeneratorHelper, randomUtil: RandomUtil, configServer: ConfigServer, botWeaponGeneratorHelper: BotWeaponGeneratorHelper, inventoryMagGenComponents: IInventoryMagGen[]); /** * Pick a random weapon based on weightings and generate a functional weapon * @param equipmentSlot Primary/secondary/holster @@ -85,36 +89,12 @@ export declare class BotWeaponGenerator { /** * Generates extra magazines or bullets (if magazine is internal) and adds them to TacticalVest and Pockets. * Additionally, adds extra bullets to SecuredContainer - * @param weaponMods mods to attach to weapon - * @param weaponTemplate db template for weapon - * @param magCounts magazine count to add to inventory - * @param ammoTpl ammo templateId to add to magazines - * @param inventory inventory to add magazines to - * @param botRole the bot type we're getting generating extra mags for - * @returns + * @param generatedWeaponResult object with properties for generated weapon (weapon mods pool / weapon template / ammo tpl) + * @param magCounts Magazine count to add to inventory + * @param inventory Inventory to add magazines to + * @param botRole The bot type we're getting generating extra mags for */ - addExtraMagazinesToInventory(weaponMods: Item[], weaponTemplate: ITemplateItem, magCounts: MinMax, ammoTpl: string, inventory: PmcInventory, botRole: string): void; - /** - * Create a magazine using the parameters given - * @param magazineTpl Tpl of the magazine to create - * @param ammoTpl Ammo to add to magazine - * @param magTemplate template object of magazine - * @returns Item array - */ - protected createMagazine(magazineTpl: string, ammoTpl: string, magTemplate: ITemplateItem): Item[]; - /** - * Get a randomised number of bullets for a specific magazine - * @param magCounts min and max count of magazines - * @param magTemplate magazine to generate bullet count for - * @returns bullet count number - */ - protected getRandomisedBulletCount(magCounts: MinMax, magTemplate: ITemplateItem): number; - /** - * Get a randomised count of magazines - * @param magCounts min and max value returned value can be between - * @returns numberical value of magazine count - */ - protected getRandomisedMagazineCount(magCounts: MinMax): number; + addExtraMagazinesToInventory(generatedWeaponResult: GenerateWeaponResult, magCounts: MinMax, inventory: PmcInventory, botRole: string): void; /** * Add ammo to the secure container * @param stackCount How many stacks of ammo to add @@ -131,13 +111,6 @@ export declare class BotWeaponGenerator { * @returns magazine tpl string */ protected getMagazineTplFromWeaponTemplate(weaponMods: Item[], weaponTemplate: ITemplateItem, botRole: string): string; - /** - * Get a weapons default magazine template id - * @param weaponTemplate weapon to get default magazine for - * @returns tpl of magazine - */ - protected getWeaponsDefaultMagazineTpl(weaponTemplate: ITemplateItem): string; - protected addBulletsToVestAndPockets(ammoTpl: string, bulletCount: number, inventory: PmcInventory): void; /** * Finds and return a compatible ammo tpl based on the bots ammo weightings (x.json/inventory/equipment/ammo) * @param ammo a list of ammo tpls the weapon can use diff --git a/TypeScript/6ReferenceAnotherClass/types/generators/weapongen/IInventoryMagGen.d.ts b/TypeScript/6ReferenceAnotherClass/types/generators/weapongen/IInventoryMagGen.d.ts new file mode 100644 index 0000000..792f510 --- /dev/null +++ b/TypeScript/6ReferenceAnotherClass/types/generators/weapongen/IInventoryMagGen.d.ts @@ -0,0 +1,6 @@ +import { InventoryMagGen } from "./InventoryMagGen"; +export interface IInventoryMagGen { + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/6ReferenceAnotherClass/types/generators/weapongen/InventoryMagGen.d.ts b/TypeScript/6ReferenceAnotherClass/types/generators/weapongen/InventoryMagGen.d.ts new file mode 100644 index 0000000..30bf79f --- /dev/null +++ b/TypeScript/6ReferenceAnotherClass/types/generators/weapongen/InventoryMagGen.d.ts @@ -0,0 +1,16 @@ +import { MinMax } from "../../models/common/MinMax"; +import { Inventory } from "../../models/eft/common/tables/IBotBase"; +import { ITemplateItem } from "../../models/eft/common/tables/ITemplateItem"; +export declare class InventoryMagGen { + private magCounts; + private magazineTemplate; + private weaponTemplate; + private ammoTemplate; + private pmcInventory; + constructor(magCounts: MinMax, magazineTemplate: ITemplateItem, weaponTemplate: ITemplateItem, ammoTemplate: ITemplateItem, pmcInventory: Inventory); + getMagCount(): MinMax; + getMagazineTemplate(): ITemplateItem; + getWeaponTemplate(): ITemplateItem; + getAmmoTemplate(): ITemplateItem; + getPmcInventory(): Inventory; +} diff --git a/TypeScript/6ReferenceAnotherClass/types/generators/weapongen/implementations/BarrelInventoryMagGen.d.ts b/TypeScript/6ReferenceAnotherClass/types/generators/weapongen/implementations/BarrelInventoryMagGen.d.ts new file mode 100644 index 0000000..b754d5f --- /dev/null +++ b/TypeScript/6ReferenceAnotherClass/types/generators/weapongen/implementations/BarrelInventoryMagGen.d.ts @@ -0,0 +1,12 @@ +import { BotWeaponGeneratorHelper } from "../../../helpers/BotWeaponGeneratorHelper"; +import { RandomUtil } from "../../../utils/RandomUtil"; +import { IInventoryMagGen } from "../IInventoryMagGen"; +import { InventoryMagGen } from "../InventoryMagGen"; +export declare class BarrelInventoryMagGen implements IInventoryMagGen { + protected randomUtil: RandomUtil; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + constructor(randomUtil: RandomUtil, botWeaponGeneratorHelper: BotWeaponGeneratorHelper); + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/6ReferenceAnotherClass/types/generators/weapongen/implementations/ExternalInventoryMagGen.d.ts b/TypeScript/6ReferenceAnotherClass/types/generators/weapongen/implementations/ExternalInventoryMagGen.d.ts new file mode 100644 index 0000000..4fcb1e2 --- /dev/null +++ b/TypeScript/6ReferenceAnotherClass/types/generators/weapongen/implementations/ExternalInventoryMagGen.d.ts @@ -0,0 +1,14 @@ +import { BotWeaponGeneratorHelper } from "../../../helpers/BotWeaponGeneratorHelper"; +import { ItemHelper } from "../../../helpers/ItemHelper"; +import { ILogger } from "../../../models/spt/utils/ILogger"; +import { IInventoryMagGen } from "../IInventoryMagGen"; +import { InventoryMagGen } from "../InventoryMagGen"; +export declare class ExternalInventoryMagGen implements IInventoryMagGen { + protected logger: ILogger; + protected itemHelper: ItemHelper; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + constructor(logger: ILogger, itemHelper: ItemHelper, botWeaponGeneratorHelper: BotWeaponGeneratorHelper); + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/6ReferenceAnotherClass/types/generators/weapongen/implementations/InternalMagazineInventoryMagGen.d.ts b/TypeScript/6ReferenceAnotherClass/types/generators/weapongen/implementations/InternalMagazineInventoryMagGen.d.ts new file mode 100644 index 0000000..4548a04 --- /dev/null +++ b/TypeScript/6ReferenceAnotherClass/types/generators/weapongen/implementations/InternalMagazineInventoryMagGen.d.ts @@ -0,0 +1,10 @@ +import { BotWeaponGeneratorHelper } from "../../../helpers/BotWeaponGeneratorHelper"; +import { IInventoryMagGen } from "../IInventoryMagGen"; +import { InventoryMagGen } from "../InventoryMagGen"; +export declare class InternalMagazineInventoryMagGen implements IInventoryMagGen { + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + constructor(botWeaponGeneratorHelper: BotWeaponGeneratorHelper); + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/6ReferenceAnotherClass/types/helpers/BotGeneratorHelper.d.ts b/TypeScript/6ReferenceAnotherClass/types/helpers/BotGeneratorHelper.d.ts index 09e5c8f..5e3e501 100644 --- a/TypeScript/6ReferenceAnotherClass/types/helpers/BotGeneratorHelper.d.ts +++ b/TypeScript/6ReferenceAnotherClass/types/helpers/BotGeneratorHelper.d.ts @@ -1,8 +1,7 @@ import { DurabilityLimitsHelper } from "../helpers/DurabilityLimitsHelper"; -import { Inventory as PmcInventory } from "../models/eft/common/tables/IBotBase"; import { Mods, ModsChances } from "../models/eft/common/tables/IBotType"; import { Item, Repairable, Upd } from "../models/eft/common/tables/IItem"; -import { Grid, ITemplateItem, Slot } from "../models/eft/common/tables/ITemplateItem"; +import { ITemplateItem, Slot } from "../models/eft/common/tables/ITemplateItem"; import { EquipmentFilterDetails, IBotConfig } from "../models/spt/config/IBotConfig"; import { ILogger } from "../models/spt/utils/ILogger"; import { ConfigServer } from "../servers/ConfigServer"; @@ -12,6 +11,7 @@ import { ItemFilterService } from "../services/ItemFilterService"; import { HashUtil } from "../utils/HashUtil"; import { JsonUtil } from "../utils/JsonUtil"; import { RandomUtil } from "../utils/RandomUtil"; +import { BotWeaponGeneratorHelper } from "./BotWeaponGeneratorHelper"; import { ContainerHelper } from "./ContainerHelper"; import { InventoryHelper } from "./InventoryHelper"; import { ItemHelper } from "./ItemHelper"; @@ -42,11 +42,11 @@ export declare class BotGeneratorHelper { protected botEquipmentFilterService: BotEquipmentFilterService; protected itemFilterService: ItemFilterService; protected profileHelper: ProfileHelper; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; protected configServer: ConfigServer; protected botConfig: IBotConfig; - constructor(logger: ILogger, jsonUtil: JsonUtil, hashUtil: HashUtil, randomUtil: RandomUtil, probabilityHelper: ProbabilityHelper, databaseServer: DatabaseServer, durabilityLimitsHelper: DurabilityLimitsHelper, itemHelper: ItemHelper, inventoryHelper: InventoryHelper, containerHelper: ContainerHelper, botEquipmentFilterService: BotEquipmentFilterService, itemFilterService: ItemFilterService, profileHelper: ProfileHelper, configServer: ConfigServer); + constructor(logger: ILogger, jsonUtil: JsonUtil, hashUtil: HashUtil, randomUtil: RandomUtil, probabilityHelper: ProbabilityHelper, databaseServer: DatabaseServer, durabilityLimitsHelper: DurabilityLimitsHelper, itemHelper: ItemHelper, inventoryHelper: InventoryHelper, containerHelper: ContainerHelper, botEquipmentFilterService: BotEquipmentFilterService, itemFilterService: ItemFilterService, profileHelper: ProfileHelper, botWeaponGeneratorHelper: BotWeaponGeneratorHelper, configServer: ConfigServer); /** - * TODO - very similar to generateModsForWeapon * Check mods are compatible and add to array * @param equipment Equipment item to add mods to * @param modPool Mod list to choose frm @@ -57,18 +57,30 @@ export declare class BotGeneratorHelper { */ generateModsForEquipment(equipment: Item[], modPool: Mods, parentId: string, parentTemplate: ITemplateItem, modSpawnChances: ModsChances): Item[]; /** - * TODO - very similar to generateModsForEquipment * @param sessionId session id * @param weapon Weapon to add mods to - * @param modPool pool of compatible mods to attach to gun + * @param modPool Pool of compatible mods to attach to weapon * @param weaponParentId parentId of weapon - * @param parentTemplate - * @param modSpawnChances - * @param ammoTpl ammo tpl to use when generating magazines/cartridges - * @param botRole role of bot weapon is generated for - * @returns Weapon with mods + * @param parentWeaponTemplate Weapon which mods will be generated on + * @param modSpawnChances Mod spawn chances + * @param ammoTpl Ammo tpl to use when generating magazines/cartridges + * @param botRole Role of bot weapon is generated for + * @returns Weapon + mods array */ - generateModsForWeapon(sessionId: string, weapon: Item[], modPool: Mods, weaponParentId: string, parentTemplate: ITemplateItem, modSpawnChances: ModsChances, ammoTpl: string, botRole: string): Item[]; + generateModsForWeapon(sessionId: string, weapon: Item[], modPool: Mods, weaponParentId: string, parentWeaponTemplate: ITemplateItem, modSpawnChances: ModsChances, ammoTpl: string, botRole: string): Item[]; + /** + * + * @param modSlot + * @param isRandomisableSlot + * @param modsParent + * @param botEquipBlacklist + * @param itemModPool + * @param weapon array with only weapon tpl in it, ready for mods to be added + * @param ammoTpl ammo tpl to use if slot requires a cartridge to be added (e.g. mod_magazine) + * @param parentTemplate + * @returns + */ + protected chooseModToPutIntoSlot(modSlot: string, isRandomisableSlot: boolean, modsParent: Slot, botEquipBlacklist: EquipmentFilterDetails, itemModPool: Record, weapon: Item[], ammoTpl: string, parentTemplate: ITemplateItem): [boolean, ITemplateItem]; /** * Find mod tpls of a provided type and add to modPool * @param desiredSlotName slot to look up and add we are adding tpls for (e.g mod_scope) @@ -79,15 +91,15 @@ export declare class BotGeneratorHelper { /** * Check if mod item is on limited list + has surpassed the limit set for it * @param botRole role the bot has e.g. assault - * @param modTpl mods tpl + * @param modTemplate mods template data * @param modLimits limits set for weapon being generated for this bot * @returns true if over item limit */ - protected modHasReachedItemLimit(botRole: string, modTpl: string, modLimits: BotModLimits): boolean; + protected modHasReachedItemLimit(botRole: string, modTemplate: ITemplateItem, modLimits: BotModLimits): boolean; /** - * Initalise mod limits to be used when generating the weapon + * Initalise mod limits to be used when generating a weapon * @param botRole "assault", "bossTagilla" or "pmc" - * @returns + * @returns BotModLimits object */ protected initModLimits(botRole: string): BotModLimits; /** @@ -114,7 +126,7 @@ export declare class BotGeneratorHelper { protected filterWeaponModsByBlacklist(allowedMods: string[], botEquipBlacklist: EquipmentFilterDetails, modSlot: string): string[]; /** * Check if the specific item type on the weapon has reached the set limit - * @param modTpl item to check is limited + * @param modTpl log mod tpl if over type limit * @param currentCount current number of this item on gun * @param maxLimit mod limit allowed * @param botRole role of bot we're checking weapon of @@ -124,16 +136,14 @@ export declare class BotGeneratorHelper { count: number; }, maxLimit: number, botRole: string): boolean; /** - * log errors if mod is not valid for a slot - * @param modTpl - * @param found - * @param itemSlot - * @param modTemplate - * @param modSlot - * @param parentTemplate + * Log errors if mod is not compatible with slot + * @param modToAdd template of mod to check + * @param itemSlot slot the item will be placed in + * @param modSlot slot the mod will fill + * @param parentTemplate tempalte of the mods parent item * @returns true if valid */ - protected isModValidForSlot(modTpl: string, found: boolean, itemSlot: Slot, modTemplate: ITemplateItem, modSlot: string, parentTemplate: ITemplateItem): boolean; + protected isModValidForSlot(modToAdd: [boolean, ITemplateItem], itemSlot: Slot, modSlot: string, parentTemplate: ITemplateItem): boolean; /** * Create a mod item with parameters as properties * @param modId _id @@ -144,12 +154,6 @@ export declare class BotGeneratorHelper { * @returns Item object */ protected createModItem(modId: string, modTpl: string, parentId: string, modSlot: string, modTemplate: ITemplateItem): Item; - /** - * Is this magazine cylinder related (revolvers and grenade launchers) - * @param magazineParentName the name of the magazines parent - * @returns true if it is cylinder related - */ - magazineIsCylinderRelated(magazineParentName: string): boolean; /** * randomly choose if a mod should be spawned, 100% for required mods OR mod is ammo slot * never return true for an item that has 0% spawn chance @@ -161,7 +165,7 @@ export declare class BotGeneratorHelper { protected shouldModBeSpawned(itemSlot: Slot, modSlot: string, modSpawnChances: ModsChances): boolean; /** * Get a list of containers that hold ammo - * e.g. mod_magazine + * e.g. mod_magazine / patron_in_weapon_000 * @returns string array */ protected getAmmoContainers(): string[]; @@ -214,6 +218,14 @@ export declare class BotGeneratorHelper { * @returns Repairable object */ protected generateArmorRepairableProperties(itemTemplate: ITemplateItem, botRole: string): Repairable; + /** + * Get a random mod from an items compatible mods Filter array + * @param modTpl + * @param parentSlot + * @param modSlot + * @param items + * @returns item tpl + */ protected getModTplFromItemDb(modTpl: string, parentSlot: Slot, modSlot: string, items: Item[]): string; /** * Can an item be added to an item without issue @@ -223,23 +235,6 @@ export declare class BotGeneratorHelper { * @returns true if possible */ isItemIncompatibleWithCurrentItems(items: Item[], tplToCheck: string, equipmentSlot: string): boolean; - /** - * Adds an item with all its childern into specified equipmentSlots, wherever it fits. - * @param equipmentSlots - * @param parentId - * @param parentTpl - * @param itemWithChildren - * @param inventory - * @returns a `boolean` indicating item was added - */ - addItemWithChildrenToEquipmentSlot(equipmentSlots: string[], parentId: string, parentTpl: string, itemWithChildren: Item[], inventory: PmcInventory): boolean; - /** - * is the provided item allowed inside a container - * @param slot location item wants to be placed in - * @param itemTpl item being placed - * @returns true if allowed - */ - protected itemAllowedInContainer(slot: Grid, itemTpl: string): boolean; } /** TODO - move into own class */ export declare class ExhaustableArray { diff --git a/TypeScript/6ReferenceAnotherClass/types/helpers/BotWeaponGeneratorHelper.d.ts b/TypeScript/6ReferenceAnotherClass/types/helpers/BotWeaponGeneratorHelper.d.ts new file mode 100644 index 0000000..7e25f56 --- /dev/null +++ b/TypeScript/6ReferenceAnotherClass/types/helpers/BotWeaponGeneratorHelper.d.ts @@ -0,0 +1,78 @@ +import { MinMax } from "../models/common/MinMax"; +import { Inventory } from "../models/eft/common/tables/IBotBase"; +import { Item } from "../models/eft/common/tables/IItem"; +import { Grid, ITemplateItem } from "../models/eft/common/tables/ITemplateItem"; +import { ILogger } from "../models/spt/utils/ILogger"; +import { DatabaseServer } from "../servers/DatabaseServer"; +import { HashUtil } from "../utils/HashUtil"; +import { RandomUtil } from "../utils/RandomUtil"; +import { ContainerHelper } from "./ContainerHelper"; +import { InventoryHelper } from "./InventoryHelper"; +import { ItemHelper } from "./ItemHelper"; +export declare class BotWeaponGeneratorHelper { + protected logger: ILogger; + protected databaseServer: DatabaseServer; + protected itemHelper: ItemHelper; + protected randomUtil: RandomUtil; + protected hashUtil: HashUtil; + protected inventoryHelper: InventoryHelper; + protected containerHelper: ContainerHelper; + constructor(logger: ILogger, databaseServer: DatabaseServer, itemHelper: ItemHelper, randomUtil: RandomUtil, hashUtil: HashUtil, inventoryHelper: InventoryHelper, containerHelper: ContainerHelper); + /** + * Get a randomised number of bullets for a specific magazine + * @param magCounts min and max count of magazines + * @param magTemplate magazine to generate bullet count for + * @returns bullet count number + */ + getRandomisedBulletCount(magCounts: MinMax, magTemplate: ITemplateItem): number; + /** + * Get a randomised count of magazines + * @param magCounts min and max value returned value can be between + * @returns numberical value of magazine count + */ + getRandomisedMagazineCount(magCounts: MinMax): number; + /** + * Is this magazine cylinder related (revolvers and grenade launchers) + * @param magazineParentName the name of the magazines parent + * @returns true if it is cylinder related + */ + magazineIsCylinderRelated(magazineParentName: string): boolean; + /** + * Create a magazine using the parameters given + * @param magazineTpl Tpl of the magazine to create + * @param ammoTpl Ammo to add to magazine + * @param magTemplate template object of magazine + * @returns Item array + */ + createMagazine(magazineTpl: string, ammoTpl: string, magTemplate: ITemplateItem): Item[]; + /** + * Add a specific number of cartrdiges to a bots inventory (vest/pocket) + * @param ammoTpl Ammo tpl to add to vest/pockets + * @param cartridgeCount number of cartridges to add to vest/pockets + * @param inventory bot inventory to add cartridges to + */ + addBulletsToVestAndPockets(ammoTpl: string, cartridgeCount: number, inventory: Inventory): void; + /** + * Get a weapons default magazine template id + * @param weaponTemplate weapon to get default magazine for + * @returns tpl of magazine + */ + getWeaponsDefaultMagazineTpl(weaponTemplate: ITemplateItem): string; + /** + * Adds an item with all its childern into specified equipmentSlots, wherever it fits. + * @param equipmentSlots + * @param parentId + * @param parentTpl + * @param itemWithChildren + * @param inventory + * @returns a `boolean` indicating item was added + */ + addItemWithChildrenToEquipmentSlot(equipmentSlots: string[], parentId: string, parentTpl: string, itemWithChildren: Item[], inventory: Inventory): boolean; + /** + * is the provided item allowed inside a container + * @param slot location item wants to be placed in + * @param itemTpl item being placed + * @returns true if allowed + */ + protected itemAllowedInContainer(slot: Grid, itemTpl: string): boolean; +} diff --git a/TypeScript/7OnLoadHook/package.json b/TypeScript/7OnLoadHook/package.json index a741c83..3e56229 100644 --- a/TypeScript/7OnLoadHook/package.json +++ b/TypeScript/7OnLoadHook/package.json @@ -4,7 +4,7 @@ "main": "src/mod.js", "license": "MIT", "author": "Chomp", - "akiVersion": "3.2.2", + "akiVersion": "3.2.3", "scripts": { "setup": "npm i", "build": "node ./packageBuild.ts" diff --git a/TypeScript/7OnLoadHook/types/generators/BotLootGenerator.d.ts b/TypeScript/7OnLoadHook/types/generators/BotLootGenerator.d.ts index 5a2d144..c1f5310 100644 --- a/TypeScript/7OnLoadHook/types/generators/BotLootGenerator.d.ts +++ b/TypeScript/7OnLoadHook/types/generators/BotLootGenerator.d.ts @@ -1,4 +1,5 @@ import { BotGeneratorHelper } from "../helpers/BotGeneratorHelper"; +import { BotWeaponGeneratorHelper } from "../helpers/BotWeaponGeneratorHelper"; import { HandbookHelper } from "../helpers/HandbookHelper"; import { Inventory as PmcInventory } from "../models/eft/common/tables/IBotBase"; import { Chances, Inventory, ItemMinMax, ModsChances } from "../models/eft/common/tables/IBotType"; @@ -20,10 +21,11 @@ export declare class BotLootGenerator { protected handbookHelper: HandbookHelper; protected botGeneratorHelper: BotGeneratorHelper; protected botWeaponGenerator: BotWeaponGenerator; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; protected botLootCacheService: BotLootCacheService; protected configServer: ConfigServer; protected botConfig: IBotConfig; - constructor(logger: ILogger, hashUtil: HashUtil, randomUtil: RandomUtil, databaseServer: DatabaseServer, handbookHelper: HandbookHelper, botGeneratorHelper: BotGeneratorHelper, botWeaponGenerator: BotWeaponGenerator, botLootCacheService: BotLootCacheService, configServer: ConfigServer); + constructor(logger: ILogger, hashUtil: HashUtil, randomUtil: RandomUtil, databaseServer: DatabaseServer, handbookHelper: HandbookHelper, botGeneratorHelper: BotGeneratorHelper, botWeaponGenerator: BotWeaponGenerator, botWeaponGeneratorHelper: BotWeaponGeneratorHelper, botLootCacheService: BotLootCacheService, configServer: ConfigServer); generateLoot(sessionId: string, templateInventory: Inventory, itemCounts: ItemMinMax, isPmc: boolean, botRole: string, botInventory: PmcInventory, equipmentChances: Chances): void; protected getRandomisedCount(min: number, max: number, nValue: number): number; /** diff --git a/TypeScript/7OnLoadHook/types/generators/BotWeaponGenerator.d.ts b/TypeScript/7OnLoadHook/types/generators/BotWeaponGenerator.d.ts index cba7afa..487901b 100644 --- a/TypeScript/7OnLoadHook/types/generators/BotWeaponGenerator.d.ts +++ b/TypeScript/7OnLoadHook/types/generators/BotWeaponGenerator.d.ts @@ -1,4 +1,5 @@ import { BotGeneratorHelper } from "../helpers/BotGeneratorHelper"; +import { BotWeaponGeneratorHelper } from "../helpers/BotWeaponGeneratorHelper"; import { ItemHelper } from "../helpers/ItemHelper"; import { WeightedRandomHelper } from "../helpers/WeightedRandomHelper"; import { MinMax } from "../models/common/MinMax"; @@ -14,6 +15,7 @@ import { DatabaseServer } from "../servers/DatabaseServer"; import { HashUtil } from "../utils/HashUtil"; import { JsonUtil } from "../utils/JsonUtil"; import { RandomUtil } from "../utils/RandomUtil"; +import { IInventoryMagGen } from "./weapongen/IInventoryMagGen"; export declare class BotWeaponGenerator { protected jsonUtil: JsonUtil; protected logger: ILogger; @@ -24,9 +26,11 @@ export declare class BotWeaponGenerator { protected botGeneratorHelper: BotGeneratorHelper; protected randomUtil: RandomUtil; protected configServer: ConfigServer; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + protected inventoryMagGenComponents: IInventoryMagGen[]; protected readonly modMagazineSlotId = "mod_magazine"; protected botConfig: IBotConfig; - constructor(jsonUtil: JsonUtil, logger: ILogger, hashUtil: HashUtil, databaseServer: DatabaseServer, itemHelper: ItemHelper, weightedRandomHelper: WeightedRandomHelper, botGeneratorHelper: BotGeneratorHelper, randomUtil: RandomUtil, configServer: ConfigServer); + constructor(jsonUtil: JsonUtil, logger: ILogger, hashUtil: HashUtil, databaseServer: DatabaseServer, itemHelper: ItemHelper, weightedRandomHelper: WeightedRandomHelper, botGeneratorHelper: BotGeneratorHelper, randomUtil: RandomUtil, configServer: ConfigServer, botWeaponGeneratorHelper: BotWeaponGeneratorHelper, inventoryMagGenComponents: IInventoryMagGen[]); /** * Pick a random weapon based on weightings and generate a functional weapon * @param equipmentSlot Primary/secondary/holster @@ -85,36 +89,12 @@ export declare class BotWeaponGenerator { /** * Generates extra magazines or bullets (if magazine is internal) and adds them to TacticalVest and Pockets. * Additionally, adds extra bullets to SecuredContainer - * @param weaponMods mods to attach to weapon - * @param weaponTemplate db template for weapon - * @param magCounts magazine count to add to inventory - * @param ammoTpl ammo templateId to add to magazines - * @param inventory inventory to add magazines to - * @param botRole the bot type we're getting generating extra mags for - * @returns + * @param generatedWeaponResult object with properties for generated weapon (weapon mods pool / weapon template / ammo tpl) + * @param magCounts Magazine count to add to inventory + * @param inventory Inventory to add magazines to + * @param botRole The bot type we're getting generating extra mags for */ - addExtraMagazinesToInventory(weaponMods: Item[], weaponTemplate: ITemplateItem, magCounts: MinMax, ammoTpl: string, inventory: PmcInventory, botRole: string): void; - /** - * Create a magazine using the parameters given - * @param magazineTpl Tpl of the magazine to create - * @param ammoTpl Ammo to add to magazine - * @param magTemplate template object of magazine - * @returns Item array - */ - protected createMagazine(magazineTpl: string, ammoTpl: string, magTemplate: ITemplateItem): Item[]; - /** - * Get a randomised number of bullets for a specific magazine - * @param magCounts min and max count of magazines - * @param magTemplate magazine to generate bullet count for - * @returns bullet count number - */ - protected getRandomisedBulletCount(magCounts: MinMax, magTemplate: ITemplateItem): number; - /** - * Get a randomised count of magazines - * @param magCounts min and max value returned value can be between - * @returns numberical value of magazine count - */ - protected getRandomisedMagazineCount(magCounts: MinMax): number; + addExtraMagazinesToInventory(generatedWeaponResult: GenerateWeaponResult, magCounts: MinMax, inventory: PmcInventory, botRole: string): void; /** * Add ammo to the secure container * @param stackCount How many stacks of ammo to add @@ -131,13 +111,6 @@ export declare class BotWeaponGenerator { * @returns magazine tpl string */ protected getMagazineTplFromWeaponTemplate(weaponMods: Item[], weaponTemplate: ITemplateItem, botRole: string): string; - /** - * Get a weapons default magazine template id - * @param weaponTemplate weapon to get default magazine for - * @returns tpl of magazine - */ - protected getWeaponsDefaultMagazineTpl(weaponTemplate: ITemplateItem): string; - protected addBulletsToVestAndPockets(ammoTpl: string, bulletCount: number, inventory: PmcInventory): void; /** * Finds and return a compatible ammo tpl based on the bots ammo weightings (x.json/inventory/equipment/ammo) * @param ammo a list of ammo tpls the weapon can use diff --git a/TypeScript/7OnLoadHook/types/generators/weapongen/IInventoryMagGen.d.ts b/TypeScript/7OnLoadHook/types/generators/weapongen/IInventoryMagGen.d.ts new file mode 100644 index 0000000..792f510 --- /dev/null +++ b/TypeScript/7OnLoadHook/types/generators/weapongen/IInventoryMagGen.d.ts @@ -0,0 +1,6 @@ +import { InventoryMagGen } from "./InventoryMagGen"; +export interface IInventoryMagGen { + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/7OnLoadHook/types/generators/weapongen/InventoryMagGen.d.ts b/TypeScript/7OnLoadHook/types/generators/weapongen/InventoryMagGen.d.ts new file mode 100644 index 0000000..30bf79f --- /dev/null +++ b/TypeScript/7OnLoadHook/types/generators/weapongen/InventoryMagGen.d.ts @@ -0,0 +1,16 @@ +import { MinMax } from "../../models/common/MinMax"; +import { Inventory } from "../../models/eft/common/tables/IBotBase"; +import { ITemplateItem } from "../../models/eft/common/tables/ITemplateItem"; +export declare class InventoryMagGen { + private magCounts; + private magazineTemplate; + private weaponTemplate; + private ammoTemplate; + private pmcInventory; + constructor(magCounts: MinMax, magazineTemplate: ITemplateItem, weaponTemplate: ITemplateItem, ammoTemplate: ITemplateItem, pmcInventory: Inventory); + getMagCount(): MinMax; + getMagazineTemplate(): ITemplateItem; + getWeaponTemplate(): ITemplateItem; + getAmmoTemplate(): ITemplateItem; + getPmcInventory(): Inventory; +} diff --git a/TypeScript/7OnLoadHook/types/generators/weapongen/implementations/BarrelInventoryMagGen.d.ts b/TypeScript/7OnLoadHook/types/generators/weapongen/implementations/BarrelInventoryMagGen.d.ts new file mode 100644 index 0000000..b754d5f --- /dev/null +++ b/TypeScript/7OnLoadHook/types/generators/weapongen/implementations/BarrelInventoryMagGen.d.ts @@ -0,0 +1,12 @@ +import { BotWeaponGeneratorHelper } from "../../../helpers/BotWeaponGeneratorHelper"; +import { RandomUtil } from "../../../utils/RandomUtil"; +import { IInventoryMagGen } from "../IInventoryMagGen"; +import { InventoryMagGen } from "../InventoryMagGen"; +export declare class BarrelInventoryMagGen implements IInventoryMagGen { + protected randomUtil: RandomUtil; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + constructor(randomUtil: RandomUtil, botWeaponGeneratorHelper: BotWeaponGeneratorHelper); + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/7OnLoadHook/types/generators/weapongen/implementations/ExternalInventoryMagGen.d.ts b/TypeScript/7OnLoadHook/types/generators/weapongen/implementations/ExternalInventoryMagGen.d.ts new file mode 100644 index 0000000..4fcb1e2 --- /dev/null +++ b/TypeScript/7OnLoadHook/types/generators/weapongen/implementations/ExternalInventoryMagGen.d.ts @@ -0,0 +1,14 @@ +import { BotWeaponGeneratorHelper } from "../../../helpers/BotWeaponGeneratorHelper"; +import { ItemHelper } from "../../../helpers/ItemHelper"; +import { ILogger } from "../../../models/spt/utils/ILogger"; +import { IInventoryMagGen } from "../IInventoryMagGen"; +import { InventoryMagGen } from "../InventoryMagGen"; +export declare class ExternalInventoryMagGen implements IInventoryMagGen { + protected logger: ILogger; + protected itemHelper: ItemHelper; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + constructor(logger: ILogger, itemHelper: ItemHelper, botWeaponGeneratorHelper: BotWeaponGeneratorHelper); + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/7OnLoadHook/types/generators/weapongen/implementations/InternalMagazineInventoryMagGen.d.ts b/TypeScript/7OnLoadHook/types/generators/weapongen/implementations/InternalMagazineInventoryMagGen.d.ts new file mode 100644 index 0000000..4548a04 --- /dev/null +++ b/TypeScript/7OnLoadHook/types/generators/weapongen/implementations/InternalMagazineInventoryMagGen.d.ts @@ -0,0 +1,10 @@ +import { BotWeaponGeneratorHelper } from "../../../helpers/BotWeaponGeneratorHelper"; +import { IInventoryMagGen } from "../IInventoryMagGen"; +import { InventoryMagGen } from "../InventoryMagGen"; +export declare class InternalMagazineInventoryMagGen implements IInventoryMagGen { + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + constructor(botWeaponGeneratorHelper: BotWeaponGeneratorHelper); + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/7OnLoadHook/types/helpers/BotGeneratorHelper.d.ts b/TypeScript/7OnLoadHook/types/helpers/BotGeneratorHelper.d.ts index 09e5c8f..5e3e501 100644 --- a/TypeScript/7OnLoadHook/types/helpers/BotGeneratorHelper.d.ts +++ b/TypeScript/7OnLoadHook/types/helpers/BotGeneratorHelper.d.ts @@ -1,8 +1,7 @@ import { DurabilityLimitsHelper } from "../helpers/DurabilityLimitsHelper"; -import { Inventory as PmcInventory } from "../models/eft/common/tables/IBotBase"; import { Mods, ModsChances } from "../models/eft/common/tables/IBotType"; import { Item, Repairable, Upd } from "../models/eft/common/tables/IItem"; -import { Grid, ITemplateItem, Slot } from "../models/eft/common/tables/ITemplateItem"; +import { ITemplateItem, Slot } from "../models/eft/common/tables/ITemplateItem"; import { EquipmentFilterDetails, IBotConfig } from "../models/spt/config/IBotConfig"; import { ILogger } from "../models/spt/utils/ILogger"; import { ConfigServer } from "../servers/ConfigServer"; @@ -12,6 +11,7 @@ import { ItemFilterService } from "../services/ItemFilterService"; import { HashUtil } from "../utils/HashUtil"; import { JsonUtil } from "../utils/JsonUtil"; import { RandomUtil } from "../utils/RandomUtil"; +import { BotWeaponGeneratorHelper } from "./BotWeaponGeneratorHelper"; import { ContainerHelper } from "./ContainerHelper"; import { InventoryHelper } from "./InventoryHelper"; import { ItemHelper } from "./ItemHelper"; @@ -42,11 +42,11 @@ export declare class BotGeneratorHelper { protected botEquipmentFilterService: BotEquipmentFilterService; protected itemFilterService: ItemFilterService; protected profileHelper: ProfileHelper; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; protected configServer: ConfigServer; protected botConfig: IBotConfig; - constructor(logger: ILogger, jsonUtil: JsonUtil, hashUtil: HashUtil, randomUtil: RandomUtil, probabilityHelper: ProbabilityHelper, databaseServer: DatabaseServer, durabilityLimitsHelper: DurabilityLimitsHelper, itemHelper: ItemHelper, inventoryHelper: InventoryHelper, containerHelper: ContainerHelper, botEquipmentFilterService: BotEquipmentFilterService, itemFilterService: ItemFilterService, profileHelper: ProfileHelper, configServer: ConfigServer); + constructor(logger: ILogger, jsonUtil: JsonUtil, hashUtil: HashUtil, randomUtil: RandomUtil, probabilityHelper: ProbabilityHelper, databaseServer: DatabaseServer, durabilityLimitsHelper: DurabilityLimitsHelper, itemHelper: ItemHelper, inventoryHelper: InventoryHelper, containerHelper: ContainerHelper, botEquipmentFilterService: BotEquipmentFilterService, itemFilterService: ItemFilterService, profileHelper: ProfileHelper, botWeaponGeneratorHelper: BotWeaponGeneratorHelper, configServer: ConfigServer); /** - * TODO - very similar to generateModsForWeapon * Check mods are compatible and add to array * @param equipment Equipment item to add mods to * @param modPool Mod list to choose frm @@ -57,18 +57,30 @@ export declare class BotGeneratorHelper { */ generateModsForEquipment(equipment: Item[], modPool: Mods, parentId: string, parentTemplate: ITemplateItem, modSpawnChances: ModsChances): Item[]; /** - * TODO - very similar to generateModsForEquipment * @param sessionId session id * @param weapon Weapon to add mods to - * @param modPool pool of compatible mods to attach to gun + * @param modPool Pool of compatible mods to attach to weapon * @param weaponParentId parentId of weapon - * @param parentTemplate - * @param modSpawnChances - * @param ammoTpl ammo tpl to use when generating magazines/cartridges - * @param botRole role of bot weapon is generated for - * @returns Weapon with mods + * @param parentWeaponTemplate Weapon which mods will be generated on + * @param modSpawnChances Mod spawn chances + * @param ammoTpl Ammo tpl to use when generating magazines/cartridges + * @param botRole Role of bot weapon is generated for + * @returns Weapon + mods array */ - generateModsForWeapon(sessionId: string, weapon: Item[], modPool: Mods, weaponParentId: string, parentTemplate: ITemplateItem, modSpawnChances: ModsChances, ammoTpl: string, botRole: string): Item[]; + generateModsForWeapon(sessionId: string, weapon: Item[], modPool: Mods, weaponParentId: string, parentWeaponTemplate: ITemplateItem, modSpawnChances: ModsChances, ammoTpl: string, botRole: string): Item[]; + /** + * + * @param modSlot + * @param isRandomisableSlot + * @param modsParent + * @param botEquipBlacklist + * @param itemModPool + * @param weapon array with only weapon tpl in it, ready for mods to be added + * @param ammoTpl ammo tpl to use if slot requires a cartridge to be added (e.g. mod_magazine) + * @param parentTemplate + * @returns + */ + protected chooseModToPutIntoSlot(modSlot: string, isRandomisableSlot: boolean, modsParent: Slot, botEquipBlacklist: EquipmentFilterDetails, itemModPool: Record, weapon: Item[], ammoTpl: string, parentTemplate: ITemplateItem): [boolean, ITemplateItem]; /** * Find mod tpls of a provided type and add to modPool * @param desiredSlotName slot to look up and add we are adding tpls for (e.g mod_scope) @@ -79,15 +91,15 @@ export declare class BotGeneratorHelper { /** * Check if mod item is on limited list + has surpassed the limit set for it * @param botRole role the bot has e.g. assault - * @param modTpl mods tpl + * @param modTemplate mods template data * @param modLimits limits set for weapon being generated for this bot * @returns true if over item limit */ - protected modHasReachedItemLimit(botRole: string, modTpl: string, modLimits: BotModLimits): boolean; + protected modHasReachedItemLimit(botRole: string, modTemplate: ITemplateItem, modLimits: BotModLimits): boolean; /** - * Initalise mod limits to be used when generating the weapon + * Initalise mod limits to be used when generating a weapon * @param botRole "assault", "bossTagilla" or "pmc" - * @returns + * @returns BotModLimits object */ protected initModLimits(botRole: string): BotModLimits; /** @@ -114,7 +126,7 @@ export declare class BotGeneratorHelper { protected filterWeaponModsByBlacklist(allowedMods: string[], botEquipBlacklist: EquipmentFilterDetails, modSlot: string): string[]; /** * Check if the specific item type on the weapon has reached the set limit - * @param modTpl item to check is limited + * @param modTpl log mod tpl if over type limit * @param currentCount current number of this item on gun * @param maxLimit mod limit allowed * @param botRole role of bot we're checking weapon of @@ -124,16 +136,14 @@ export declare class BotGeneratorHelper { count: number; }, maxLimit: number, botRole: string): boolean; /** - * log errors if mod is not valid for a slot - * @param modTpl - * @param found - * @param itemSlot - * @param modTemplate - * @param modSlot - * @param parentTemplate + * Log errors if mod is not compatible with slot + * @param modToAdd template of mod to check + * @param itemSlot slot the item will be placed in + * @param modSlot slot the mod will fill + * @param parentTemplate tempalte of the mods parent item * @returns true if valid */ - protected isModValidForSlot(modTpl: string, found: boolean, itemSlot: Slot, modTemplate: ITemplateItem, modSlot: string, parentTemplate: ITemplateItem): boolean; + protected isModValidForSlot(modToAdd: [boolean, ITemplateItem], itemSlot: Slot, modSlot: string, parentTemplate: ITemplateItem): boolean; /** * Create a mod item with parameters as properties * @param modId _id @@ -144,12 +154,6 @@ export declare class BotGeneratorHelper { * @returns Item object */ protected createModItem(modId: string, modTpl: string, parentId: string, modSlot: string, modTemplate: ITemplateItem): Item; - /** - * Is this magazine cylinder related (revolvers and grenade launchers) - * @param magazineParentName the name of the magazines parent - * @returns true if it is cylinder related - */ - magazineIsCylinderRelated(magazineParentName: string): boolean; /** * randomly choose if a mod should be spawned, 100% for required mods OR mod is ammo slot * never return true for an item that has 0% spawn chance @@ -161,7 +165,7 @@ export declare class BotGeneratorHelper { protected shouldModBeSpawned(itemSlot: Slot, modSlot: string, modSpawnChances: ModsChances): boolean; /** * Get a list of containers that hold ammo - * e.g. mod_magazine + * e.g. mod_magazine / patron_in_weapon_000 * @returns string array */ protected getAmmoContainers(): string[]; @@ -214,6 +218,14 @@ export declare class BotGeneratorHelper { * @returns Repairable object */ protected generateArmorRepairableProperties(itemTemplate: ITemplateItem, botRole: string): Repairable; + /** + * Get a random mod from an items compatible mods Filter array + * @param modTpl + * @param parentSlot + * @param modSlot + * @param items + * @returns item tpl + */ protected getModTplFromItemDb(modTpl: string, parentSlot: Slot, modSlot: string, items: Item[]): string; /** * Can an item be added to an item without issue @@ -223,23 +235,6 @@ export declare class BotGeneratorHelper { * @returns true if possible */ isItemIncompatibleWithCurrentItems(items: Item[], tplToCheck: string, equipmentSlot: string): boolean; - /** - * Adds an item with all its childern into specified equipmentSlots, wherever it fits. - * @param equipmentSlots - * @param parentId - * @param parentTpl - * @param itemWithChildren - * @param inventory - * @returns a `boolean` indicating item was added - */ - addItemWithChildrenToEquipmentSlot(equipmentSlots: string[], parentId: string, parentTpl: string, itemWithChildren: Item[], inventory: PmcInventory): boolean; - /** - * is the provided item allowed inside a container - * @param slot location item wants to be placed in - * @param itemTpl item being placed - * @returns true if allowed - */ - protected itemAllowedInContainer(slot: Grid, itemTpl: string): boolean; } /** TODO - move into own class */ export declare class ExhaustableArray { diff --git a/TypeScript/7OnLoadHook/types/helpers/BotWeaponGeneratorHelper.d.ts b/TypeScript/7OnLoadHook/types/helpers/BotWeaponGeneratorHelper.d.ts new file mode 100644 index 0000000..7e25f56 --- /dev/null +++ b/TypeScript/7OnLoadHook/types/helpers/BotWeaponGeneratorHelper.d.ts @@ -0,0 +1,78 @@ +import { MinMax } from "../models/common/MinMax"; +import { Inventory } from "../models/eft/common/tables/IBotBase"; +import { Item } from "../models/eft/common/tables/IItem"; +import { Grid, ITemplateItem } from "../models/eft/common/tables/ITemplateItem"; +import { ILogger } from "../models/spt/utils/ILogger"; +import { DatabaseServer } from "../servers/DatabaseServer"; +import { HashUtil } from "../utils/HashUtil"; +import { RandomUtil } from "../utils/RandomUtil"; +import { ContainerHelper } from "./ContainerHelper"; +import { InventoryHelper } from "./InventoryHelper"; +import { ItemHelper } from "./ItemHelper"; +export declare class BotWeaponGeneratorHelper { + protected logger: ILogger; + protected databaseServer: DatabaseServer; + protected itemHelper: ItemHelper; + protected randomUtil: RandomUtil; + protected hashUtil: HashUtil; + protected inventoryHelper: InventoryHelper; + protected containerHelper: ContainerHelper; + constructor(logger: ILogger, databaseServer: DatabaseServer, itemHelper: ItemHelper, randomUtil: RandomUtil, hashUtil: HashUtil, inventoryHelper: InventoryHelper, containerHelper: ContainerHelper); + /** + * Get a randomised number of bullets for a specific magazine + * @param magCounts min and max count of magazines + * @param magTemplate magazine to generate bullet count for + * @returns bullet count number + */ + getRandomisedBulletCount(magCounts: MinMax, magTemplate: ITemplateItem): number; + /** + * Get a randomised count of magazines + * @param magCounts min and max value returned value can be between + * @returns numberical value of magazine count + */ + getRandomisedMagazineCount(magCounts: MinMax): number; + /** + * Is this magazine cylinder related (revolvers and grenade launchers) + * @param magazineParentName the name of the magazines parent + * @returns true if it is cylinder related + */ + magazineIsCylinderRelated(magazineParentName: string): boolean; + /** + * Create a magazine using the parameters given + * @param magazineTpl Tpl of the magazine to create + * @param ammoTpl Ammo to add to magazine + * @param magTemplate template object of magazine + * @returns Item array + */ + createMagazine(magazineTpl: string, ammoTpl: string, magTemplate: ITemplateItem): Item[]; + /** + * Add a specific number of cartrdiges to a bots inventory (vest/pocket) + * @param ammoTpl Ammo tpl to add to vest/pockets + * @param cartridgeCount number of cartridges to add to vest/pockets + * @param inventory bot inventory to add cartridges to + */ + addBulletsToVestAndPockets(ammoTpl: string, cartridgeCount: number, inventory: Inventory): void; + /** + * Get a weapons default magazine template id + * @param weaponTemplate weapon to get default magazine for + * @returns tpl of magazine + */ + getWeaponsDefaultMagazineTpl(weaponTemplate: ITemplateItem): string; + /** + * Adds an item with all its childern into specified equipmentSlots, wherever it fits. + * @param equipmentSlots + * @param parentId + * @param parentTpl + * @param itemWithChildren + * @param inventory + * @returns a `boolean` indicating item was added + */ + addItemWithChildrenToEquipmentSlot(equipmentSlots: string[], parentId: string, parentTpl: string, itemWithChildren: Item[], inventory: Inventory): boolean; + /** + * is the provided item allowed inside a container + * @param slot location item wants to be placed in + * @param itemTpl item being placed + * @returns true if allowed + */ + protected itemAllowedInContainer(slot: Grid, itemTpl: string): boolean; +} diff --git a/TypeScript/8OnUpdateHook/package.json b/TypeScript/8OnUpdateHook/package.json index 370d2b5..2cb3a35 100644 --- a/TypeScript/8OnUpdateHook/package.json +++ b/TypeScript/8OnUpdateHook/package.json @@ -4,7 +4,7 @@ "main": "src/mod.js", "license": "MIT", "author": "Chomp", - "akiVersion": "3.2.2", + "akiVersion": "3.2.3", "scripts": { "setup": "npm i", "build": "node ./packageBuild.ts" diff --git a/TypeScript/8OnUpdateHook/types/generators/BotLootGenerator.d.ts b/TypeScript/8OnUpdateHook/types/generators/BotLootGenerator.d.ts index 5a2d144..c1f5310 100644 --- a/TypeScript/8OnUpdateHook/types/generators/BotLootGenerator.d.ts +++ b/TypeScript/8OnUpdateHook/types/generators/BotLootGenerator.d.ts @@ -1,4 +1,5 @@ import { BotGeneratorHelper } from "../helpers/BotGeneratorHelper"; +import { BotWeaponGeneratorHelper } from "../helpers/BotWeaponGeneratorHelper"; import { HandbookHelper } from "../helpers/HandbookHelper"; import { Inventory as PmcInventory } from "../models/eft/common/tables/IBotBase"; import { Chances, Inventory, ItemMinMax, ModsChances } from "../models/eft/common/tables/IBotType"; @@ -20,10 +21,11 @@ export declare class BotLootGenerator { protected handbookHelper: HandbookHelper; protected botGeneratorHelper: BotGeneratorHelper; protected botWeaponGenerator: BotWeaponGenerator; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; protected botLootCacheService: BotLootCacheService; protected configServer: ConfigServer; protected botConfig: IBotConfig; - constructor(logger: ILogger, hashUtil: HashUtil, randomUtil: RandomUtil, databaseServer: DatabaseServer, handbookHelper: HandbookHelper, botGeneratorHelper: BotGeneratorHelper, botWeaponGenerator: BotWeaponGenerator, botLootCacheService: BotLootCacheService, configServer: ConfigServer); + constructor(logger: ILogger, hashUtil: HashUtil, randomUtil: RandomUtil, databaseServer: DatabaseServer, handbookHelper: HandbookHelper, botGeneratorHelper: BotGeneratorHelper, botWeaponGenerator: BotWeaponGenerator, botWeaponGeneratorHelper: BotWeaponGeneratorHelper, botLootCacheService: BotLootCacheService, configServer: ConfigServer); generateLoot(sessionId: string, templateInventory: Inventory, itemCounts: ItemMinMax, isPmc: boolean, botRole: string, botInventory: PmcInventory, equipmentChances: Chances): void; protected getRandomisedCount(min: number, max: number, nValue: number): number; /** diff --git a/TypeScript/8OnUpdateHook/types/generators/BotWeaponGenerator.d.ts b/TypeScript/8OnUpdateHook/types/generators/BotWeaponGenerator.d.ts index cba7afa..487901b 100644 --- a/TypeScript/8OnUpdateHook/types/generators/BotWeaponGenerator.d.ts +++ b/TypeScript/8OnUpdateHook/types/generators/BotWeaponGenerator.d.ts @@ -1,4 +1,5 @@ import { BotGeneratorHelper } from "../helpers/BotGeneratorHelper"; +import { BotWeaponGeneratorHelper } from "../helpers/BotWeaponGeneratorHelper"; import { ItemHelper } from "../helpers/ItemHelper"; import { WeightedRandomHelper } from "../helpers/WeightedRandomHelper"; import { MinMax } from "../models/common/MinMax"; @@ -14,6 +15,7 @@ import { DatabaseServer } from "../servers/DatabaseServer"; import { HashUtil } from "../utils/HashUtil"; import { JsonUtil } from "../utils/JsonUtil"; import { RandomUtil } from "../utils/RandomUtil"; +import { IInventoryMagGen } from "./weapongen/IInventoryMagGen"; export declare class BotWeaponGenerator { protected jsonUtil: JsonUtil; protected logger: ILogger; @@ -24,9 +26,11 @@ export declare class BotWeaponGenerator { protected botGeneratorHelper: BotGeneratorHelper; protected randomUtil: RandomUtil; protected configServer: ConfigServer; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + protected inventoryMagGenComponents: IInventoryMagGen[]; protected readonly modMagazineSlotId = "mod_magazine"; protected botConfig: IBotConfig; - constructor(jsonUtil: JsonUtil, logger: ILogger, hashUtil: HashUtil, databaseServer: DatabaseServer, itemHelper: ItemHelper, weightedRandomHelper: WeightedRandomHelper, botGeneratorHelper: BotGeneratorHelper, randomUtil: RandomUtil, configServer: ConfigServer); + constructor(jsonUtil: JsonUtil, logger: ILogger, hashUtil: HashUtil, databaseServer: DatabaseServer, itemHelper: ItemHelper, weightedRandomHelper: WeightedRandomHelper, botGeneratorHelper: BotGeneratorHelper, randomUtil: RandomUtil, configServer: ConfigServer, botWeaponGeneratorHelper: BotWeaponGeneratorHelper, inventoryMagGenComponents: IInventoryMagGen[]); /** * Pick a random weapon based on weightings and generate a functional weapon * @param equipmentSlot Primary/secondary/holster @@ -85,36 +89,12 @@ export declare class BotWeaponGenerator { /** * Generates extra magazines or bullets (if magazine is internal) and adds them to TacticalVest and Pockets. * Additionally, adds extra bullets to SecuredContainer - * @param weaponMods mods to attach to weapon - * @param weaponTemplate db template for weapon - * @param magCounts magazine count to add to inventory - * @param ammoTpl ammo templateId to add to magazines - * @param inventory inventory to add magazines to - * @param botRole the bot type we're getting generating extra mags for - * @returns + * @param generatedWeaponResult object with properties for generated weapon (weapon mods pool / weapon template / ammo tpl) + * @param magCounts Magazine count to add to inventory + * @param inventory Inventory to add magazines to + * @param botRole The bot type we're getting generating extra mags for */ - addExtraMagazinesToInventory(weaponMods: Item[], weaponTemplate: ITemplateItem, magCounts: MinMax, ammoTpl: string, inventory: PmcInventory, botRole: string): void; - /** - * Create a magazine using the parameters given - * @param magazineTpl Tpl of the magazine to create - * @param ammoTpl Ammo to add to magazine - * @param magTemplate template object of magazine - * @returns Item array - */ - protected createMagazine(magazineTpl: string, ammoTpl: string, magTemplate: ITemplateItem): Item[]; - /** - * Get a randomised number of bullets for a specific magazine - * @param magCounts min and max count of magazines - * @param magTemplate magazine to generate bullet count for - * @returns bullet count number - */ - protected getRandomisedBulletCount(magCounts: MinMax, magTemplate: ITemplateItem): number; - /** - * Get a randomised count of magazines - * @param magCounts min and max value returned value can be between - * @returns numberical value of magazine count - */ - protected getRandomisedMagazineCount(magCounts: MinMax): number; + addExtraMagazinesToInventory(generatedWeaponResult: GenerateWeaponResult, magCounts: MinMax, inventory: PmcInventory, botRole: string): void; /** * Add ammo to the secure container * @param stackCount How many stacks of ammo to add @@ -131,13 +111,6 @@ export declare class BotWeaponGenerator { * @returns magazine tpl string */ protected getMagazineTplFromWeaponTemplate(weaponMods: Item[], weaponTemplate: ITemplateItem, botRole: string): string; - /** - * Get a weapons default magazine template id - * @param weaponTemplate weapon to get default magazine for - * @returns tpl of magazine - */ - protected getWeaponsDefaultMagazineTpl(weaponTemplate: ITemplateItem): string; - protected addBulletsToVestAndPockets(ammoTpl: string, bulletCount: number, inventory: PmcInventory): void; /** * Finds and return a compatible ammo tpl based on the bots ammo weightings (x.json/inventory/equipment/ammo) * @param ammo a list of ammo tpls the weapon can use diff --git a/TypeScript/8OnUpdateHook/types/generators/weapongen/IInventoryMagGen.d.ts b/TypeScript/8OnUpdateHook/types/generators/weapongen/IInventoryMagGen.d.ts new file mode 100644 index 0000000..792f510 --- /dev/null +++ b/TypeScript/8OnUpdateHook/types/generators/weapongen/IInventoryMagGen.d.ts @@ -0,0 +1,6 @@ +import { InventoryMagGen } from "./InventoryMagGen"; +export interface IInventoryMagGen { + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/8OnUpdateHook/types/generators/weapongen/InventoryMagGen.d.ts b/TypeScript/8OnUpdateHook/types/generators/weapongen/InventoryMagGen.d.ts new file mode 100644 index 0000000..30bf79f --- /dev/null +++ b/TypeScript/8OnUpdateHook/types/generators/weapongen/InventoryMagGen.d.ts @@ -0,0 +1,16 @@ +import { MinMax } from "../../models/common/MinMax"; +import { Inventory } from "../../models/eft/common/tables/IBotBase"; +import { ITemplateItem } from "../../models/eft/common/tables/ITemplateItem"; +export declare class InventoryMagGen { + private magCounts; + private magazineTemplate; + private weaponTemplate; + private ammoTemplate; + private pmcInventory; + constructor(magCounts: MinMax, magazineTemplate: ITemplateItem, weaponTemplate: ITemplateItem, ammoTemplate: ITemplateItem, pmcInventory: Inventory); + getMagCount(): MinMax; + getMagazineTemplate(): ITemplateItem; + getWeaponTemplate(): ITemplateItem; + getAmmoTemplate(): ITemplateItem; + getPmcInventory(): Inventory; +} diff --git a/TypeScript/8OnUpdateHook/types/generators/weapongen/implementations/BarrelInventoryMagGen.d.ts b/TypeScript/8OnUpdateHook/types/generators/weapongen/implementations/BarrelInventoryMagGen.d.ts new file mode 100644 index 0000000..b754d5f --- /dev/null +++ b/TypeScript/8OnUpdateHook/types/generators/weapongen/implementations/BarrelInventoryMagGen.d.ts @@ -0,0 +1,12 @@ +import { BotWeaponGeneratorHelper } from "../../../helpers/BotWeaponGeneratorHelper"; +import { RandomUtil } from "../../../utils/RandomUtil"; +import { IInventoryMagGen } from "../IInventoryMagGen"; +import { InventoryMagGen } from "../InventoryMagGen"; +export declare class BarrelInventoryMagGen implements IInventoryMagGen { + protected randomUtil: RandomUtil; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + constructor(randomUtil: RandomUtil, botWeaponGeneratorHelper: BotWeaponGeneratorHelper); + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/8OnUpdateHook/types/generators/weapongen/implementations/ExternalInventoryMagGen.d.ts b/TypeScript/8OnUpdateHook/types/generators/weapongen/implementations/ExternalInventoryMagGen.d.ts new file mode 100644 index 0000000..4fcb1e2 --- /dev/null +++ b/TypeScript/8OnUpdateHook/types/generators/weapongen/implementations/ExternalInventoryMagGen.d.ts @@ -0,0 +1,14 @@ +import { BotWeaponGeneratorHelper } from "../../../helpers/BotWeaponGeneratorHelper"; +import { ItemHelper } from "../../../helpers/ItemHelper"; +import { ILogger } from "../../../models/spt/utils/ILogger"; +import { IInventoryMagGen } from "../IInventoryMagGen"; +import { InventoryMagGen } from "../InventoryMagGen"; +export declare class ExternalInventoryMagGen implements IInventoryMagGen { + protected logger: ILogger; + protected itemHelper: ItemHelper; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + constructor(logger: ILogger, itemHelper: ItemHelper, botWeaponGeneratorHelper: BotWeaponGeneratorHelper); + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/8OnUpdateHook/types/generators/weapongen/implementations/InternalMagazineInventoryMagGen.d.ts b/TypeScript/8OnUpdateHook/types/generators/weapongen/implementations/InternalMagazineInventoryMagGen.d.ts new file mode 100644 index 0000000..4548a04 --- /dev/null +++ b/TypeScript/8OnUpdateHook/types/generators/weapongen/implementations/InternalMagazineInventoryMagGen.d.ts @@ -0,0 +1,10 @@ +import { BotWeaponGeneratorHelper } from "../../../helpers/BotWeaponGeneratorHelper"; +import { IInventoryMagGen } from "../IInventoryMagGen"; +import { InventoryMagGen } from "../InventoryMagGen"; +export declare class InternalMagazineInventoryMagGen implements IInventoryMagGen { + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + constructor(botWeaponGeneratorHelper: BotWeaponGeneratorHelper); + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/8OnUpdateHook/types/helpers/BotGeneratorHelper.d.ts b/TypeScript/8OnUpdateHook/types/helpers/BotGeneratorHelper.d.ts index 09e5c8f..5e3e501 100644 --- a/TypeScript/8OnUpdateHook/types/helpers/BotGeneratorHelper.d.ts +++ b/TypeScript/8OnUpdateHook/types/helpers/BotGeneratorHelper.d.ts @@ -1,8 +1,7 @@ import { DurabilityLimitsHelper } from "../helpers/DurabilityLimitsHelper"; -import { Inventory as PmcInventory } from "../models/eft/common/tables/IBotBase"; import { Mods, ModsChances } from "../models/eft/common/tables/IBotType"; import { Item, Repairable, Upd } from "../models/eft/common/tables/IItem"; -import { Grid, ITemplateItem, Slot } from "../models/eft/common/tables/ITemplateItem"; +import { ITemplateItem, Slot } from "../models/eft/common/tables/ITemplateItem"; import { EquipmentFilterDetails, IBotConfig } from "../models/spt/config/IBotConfig"; import { ILogger } from "../models/spt/utils/ILogger"; import { ConfigServer } from "../servers/ConfigServer"; @@ -12,6 +11,7 @@ import { ItemFilterService } from "../services/ItemFilterService"; import { HashUtil } from "../utils/HashUtil"; import { JsonUtil } from "../utils/JsonUtil"; import { RandomUtil } from "../utils/RandomUtil"; +import { BotWeaponGeneratorHelper } from "./BotWeaponGeneratorHelper"; import { ContainerHelper } from "./ContainerHelper"; import { InventoryHelper } from "./InventoryHelper"; import { ItemHelper } from "./ItemHelper"; @@ -42,11 +42,11 @@ export declare class BotGeneratorHelper { protected botEquipmentFilterService: BotEquipmentFilterService; protected itemFilterService: ItemFilterService; protected profileHelper: ProfileHelper; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; protected configServer: ConfigServer; protected botConfig: IBotConfig; - constructor(logger: ILogger, jsonUtil: JsonUtil, hashUtil: HashUtil, randomUtil: RandomUtil, probabilityHelper: ProbabilityHelper, databaseServer: DatabaseServer, durabilityLimitsHelper: DurabilityLimitsHelper, itemHelper: ItemHelper, inventoryHelper: InventoryHelper, containerHelper: ContainerHelper, botEquipmentFilterService: BotEquipmentFilterService, itemFilterService: ItemFilterService, profileHelper: ProfileHelper, configServer: ConfigServer); + constructor(logger: ILogger, jsonUtil: JsonUtil, hashUtil: HashUtil, randomUtil: RandomUtil, probabilityHelper: ProbabilityHelper, databaseServer: DatabaseServer, durabilityLimitsHelper: DurabilityLimitsHelper, itemHelper: ItemHelper, inventoryHelper: InventoryHelper, containerHelper: ContainerHelper, botEquipmentFilterService: BotEquipmentFilterService, itemFilterService: ItemFilterService, profileHelper: ProfileHelper, botWeaponGeneratorHelper: BotWeaponGeneratorHelper, configServer: ConfigServer); /** - * TODO - very similar to generateModsForWeapon * Check mods are compatible and add to array * @param equipment Equipment item to add mods to * @param modPool Mod list to choose frm @@ -57,18 +57,30 @@ export declare class BotGeneratorHelper { */ generateModsForEquipment(equipment: Item[], modPool: Mods, parentId: string, parentTemplate: ITemplateItem, modSpawnChances: ModsChances): Item[]; /** - * TODO - very similar to generateModsForEquipment * @param sessionId session id * @param weapon Weapon to add mods to - * @param modPool pool of compatible mods to attach to gun + * @param modPool Pool of compatible mods to attach to weapon * @param weaponParentId parentId of weapon - * @param parentTemplate - * @param modSpawnChances - * @param ammoTpl ammo tpl to use when generating magazines/cartridges - * @param botRole role of bot weapon is generated for - * @returns Weapon with mods + * @param parentWeaponTemplate Weapon which mods will be generated on + * @param modSpawnChances Mod spawn chances + * @param ammoTpl Ammo tpl to use when generating magazines/cartridges + * @param botRole Role of bot weapon is generated for + * @returns Weapon + mods array */ - generateModsForWeapon(sessionId: string, weapon: Item[], modPool: Mods, weaponParentId: string, parentTemplate: ITemplateItem, modSpawnChances: ModsChances, ammoTpl: string, botRole: string): Item[]; + generateModsForWeapon(sessionId: string, weapon: Item[], modPool: Mods, weaponParentId: string, parentWeaponTemplate: ITemplateItem, modSpawnChances: ModsChances, ammoTpl: string, botRole: string): Item[]; + /** + * + * @param modSlot + * @param isRandomisableSlot + * @param modsParent + * @param botEquipBlacklist + * @param itemModPool + * @param weapon array with only weapon tpl in it, ready for mods to be added + * @param ammoTpl ammo tpl to use if slot requires a cartridge to be added (e.g. mod_magazine) + * @param parentTemplate + * @returns + */ + protected chooseModToPutIntoSlot(modSlot: string, isRandomisableSlot: boolean, modsParent: Slot, botEquipBlacklist: EquipmentFilterDetails, itemModPool: Record, weapon: Item[], ammoTpl: string, parentTemplate: ITemplateItem): [boolean, ITemplateItem]; /** * Find mod tpls of a provided type and add to modPool * @param desiredSlotName slot to look up and add we are adding tpls for (e.g mod_scope) @@ -79,15 +91,15 @@ export declare class BotGeneratorHelper { /** * Check if mod item is on limited list + has surpassed the limit set for it * @param botRole role the bot has e.g. assault - * @param modTpl mods tpl + * @param modTemplate mods template data * @param modLimits limits set for weapon being generated for this bot * @returns true if over item limit */ - protected modHasReachedItemLimit(botRole: string, modTpl: string, modLimits: BotModLimits): boolean; + protected modHasReachedItemLimit(botRole: string, modTemplate: ITemplateItem, modLimits: BotModLimits): boolean; /** - * Initalise mod limits to be used when generating the weapon + * Initalise mod limits to be used when generating a weapon * @param botRole "assault", "bossTagilla" or "pmc" - * @returns + * @returns BotModLimits object */ protected initModLimits(botRole: string): BotModLimits; /** @@ -114,7 +126,7 @@ export declare class BotGeneratorHelper { protected filterWeaponModsByBlacklist(allowedMods: string[], botEquipBlacklist: EquipmentFilterDetails, modSlot: string): string[]; /** * Check if the specific item type on the weapon has reached the set limit - * @param modTpl item to check is limited + * @param modTpl log mod tpl if over type limit * @param currentCount current number of this item on gun * @param maxLimit mod limit allowed * @param botRole role of bot we're checking weapon of @@ -124,16 +136,14 @@ export declare class BotGeneratorHelper { count: number; }, maxLimit: number, botRole: string): boolean; /** - * log errors if mod is not valid for a slot - * @param modTpl - * @param found - * @param itemSlot - * @param modTemplate - * @param modSlot - * @param parentTemplate + * Log errors if mod is not compatible with slot + * @param modToAdd template of mod to check + * @param itemSlot slot the item will be placed in + * @param modSlot slot the mod will fill + * @param parentTemplate tempalte of the mods parent item * @returns true if valid */ - protected isModValidForSlot(modTpl: string, found: boolean, itemSlot: Slot, modTemplate: ITemplateItem, modSlot: string, parentTemplate: ITemplateItem): boolean; + protected isModValidForSlot(modToAdd: [boolean, ITemplateItem], itemSlot: Slot, modSlot: string, parentTemplate: ITemplateItem): boolean; /** * Create a mod item with parameters as properties * @param modId _id @@ -144,12 +154,6 @@ export declare class BotGeneratorHelper { * @returns Item object */ protected createModItem(modId: string, modTpl: string, parentId: string, modSlot: string, modTemplate: ITemplateItem): Item; - /** - * Is this magazine cylinder related (revolvers and grenade launchers) - * @param magazineParentName the name of the magazines parent - * @returns true if it is cylinder related - */ - magazineIsCylinderRelated(magazineParentName: string): boolean; /** * randomly choose if a mod should be spawned, 100% for required mods OR mod is ammo slot * never return true for an item that has 0% spawn chance @@ -161,7 +165,7 @@ export declare class BotGeneratorHelper { protected shouldModBeSpawned(itemSlot: Slot, modSlot: string, modSpawnChances: ModsChances): boolean; /** * Get a list of containers that hold ammo - * e.g. mod_magazine + * e.g. mod_magazine / patron_in_weapon_000 * @returns string array */ protected getAmmoContainers(): string[]; @@ -214,6 +218,14 @@ export declare class BotGeneratorHelper { * @returns Repairable object */ protected generateArmorRepairableProperties(itemTemplate: ITemplateItem, botRole: string): Repairable; + /** + * Get a random mod from an items compatible mods Filter array + * @param modTpl + * @param parentSlot + * @param modSlot + * @param items + * @returns item tpl + */ protected getModTplFromItemDb(modTpl: string, parentSlot: Slot, modSlot: string, items: Item[]): string; /** * Can an item be added to an item without issue @@ -223,23 +235,6 @@ export declare class BotGeneratorHelper { * @returns true if possible */ isItemIncompatibleWithCurrentItems(items: Item[], tplToCheck: string, equipmentSlot: string): boolean; - /** - * Adds an item with all its childern into specified equipmentSlots, wherever it fits. - * @param equipmentSlots - * @param parentId - * @param parentTpl - * @param itemWithChildren - * @param inventory - * @returns a `boolean` indicating item was added - */ - addItemWithChildrenToEquipmentSlot(equipmentSlots: string[], parentId: string, parentTpl: string, itemWithChildren: Item[], inventory: PmcInventory): boolean; - /** - * is the provided item allowed inside a container - * @param slot location item wants to be placed in - * @param itemTpl item being placed - * @returns true if allowed - */ - protected itemAllowedInContainer(slot: Grid, itemTpl: string): boolean; } /** TODO - move into own class */ export declare class ExhaustableArray { diff --git a/TypeScript/8OnUpdateHook/types/helpers/BotWeaponGeneratorHelper.d.ts b/TypeScript/8OnUpdateHook/types/helpers/BotWeaponGeneratorHelper.d.ts new file mode 100644 index 0000000..7e25f56 --- /dev/null +++ b/TypeScript/8OnUpdateHook/types/helpers/BotWeaponGeneratorHelper.d.ts @@ -0,0 +1,78 @@ +import { MinMax } from "../models/common/MinMax"; +import { Inventory } from "../models/eft/common/tables/IBotBase"; +import { Item } from "../models/eft/common/tables/IItem"; +import { Grid, ITemplateItem } from "../models/eft/common/tables/ITemplateItem"; +import { ILogger } from "../models/spt/utils/ILogger"; +import { DatabaseServer } from "../servers/DatabaseServer"; +import { HashUtil } from "../utils/HashUtil"; +import { RandomUtil } from "../utils/RandomUtil"; +import { ContainerHelper } from "./ContainerHelper"; +import { InventoryHelper } from "./InventoryHelper"; +import { ItemHelper } from "./ItemHelper"; +export declare class BotWeaponGeneratorHelper { + protected logger: ILogger; + protected databaseServer: DatabaseServer; + protected itemHelper: ItemHelper; + protected randomUtil: RandomUtil; + protected hashUtil: HashUtil; + protected inventoryHelper: InventoryHelper; + protected containerHelper: ContainerHelper; + constructor(logger: ILogger, databaseServer: DatabaseServer, itemHelper: ItemHelper, randomUtil: RandomUtil, hashUtil: HashUtil, inventoryHelper: InventoryHelper, containerHelper: ContainerHelper); + /** + * Get a randomised number of bullets for a specific magazine + * @param magCounts min and max count of magazines + * @param magTemplate magazine to generate bullet count for + * @returns bullet count number + */ + getRandomisedBulletCount(magCounts: MinMax, magTemplate: ITemplateItem): number; + /** + * Get a randomised count of magazines + * @param magCounts min and max value returned value can be between + * @returns numberical value of magazine count + */ + getRandomisedMagazineCount(magCounts: MinMax): number; + /** + * Is this magazine cylinder related (revolvers and grenade launchers) + * @param magazineParentName the name of the magazines parent + * @returns true if it is cylinder related + */ + magazineIsCylinderRelated(magazineParentName: string): boolean; + /** + * Create a magazine using the parameters given + * @param magazineTpl Tpl of the magazine to create + * @param ammoTpl Ammo to add to magazine + * @param magTemplate template object of magazine + * @returns Item array + */ + createMagazine(magazineTpl: string, ammoTpl: string, magTemplate: ITemplateItem): Item[]; + /** + * Add a specific number of cartrdiges to a bots inventory (vest/pocket) + * @param ammoTpl Ammo tpl to add to vest/pockets + * @param cartridgeCount number of cartridges to add to vest/pockets + * @param inventory bot inventory to add cartridges to + */ + addBulletsToVestAndPockets(ammoTpl: string, cartridgeCount: number, inventory: Inventory): void; + /** + * Get a weapons default magazine template id + * @param weaponTemplate weapon to get default magazine for + * @returns tpl of magazine + */ + getWeaponsDefaultMagazineTpl(weaponTemplate: ITemplateItem): string; + /** + * Adds an item with all its childern into specified equipmentSlots, wherever it fits. + * @param equipmentSlots + * @param parentId + * @param parentTpl + * @param itemWithChildren + * @param inventory + * @returns a `boolean` indicating item was added + */ + addItemWithChildrenToEquipmentSlot(equipmentSlots: string[], parentId: string, parentTpl: string, itemWithChildren: Item[], inventory: Inventory): boolean; + /** + * is the provided item allowed inside a container + * @param slot location item wants to be placed in + * @param itemTpl item being placed + * @returns true if allowed + */ + protected itemAllowedInContainer(slot: Grid, itemTpl: string): boolean; +} diff --git a/TypeScript/9RouterHooks/package.json b/TypeScript/9RouterHooks/package.json index b83f51f..0e2cf2e 100644 --- a/TypeScript/9RouterHooks/package.json +++ b/TypeScript/9RouterHooks/package.json @@ -4,7 +4,7 @@ "main": "src/mod.js", "license": "MIT", "author": "Chomp", - "akiVersion": "3.2.2", + "akiVersion": "3.2.3", "scripts": { "setup": "npm i", "build": "node ./packageBuild.ts" diff --git a/TypeScript/9RouterHooks/types/generators/BotLootGenerator.d.ts b/TypeScript/9RouterHooks/types/generators/BotLootGenerator.d.ts index 5a2d144..c1f5310 100644 --- a/TypeScript/9RouterHooks/types/generators/BotLootGenerator.d.ts +++ b/TypeScript/9RouterHooks/types/generators/BotLootGenerator.d.ts @@ -1,4 +1,5 @@ import { BotGeneratorHelper } from "../helpers/BotGeneratorHelper"; +import { BotWeaponGeneratorHelper } from "../helpers/BotWeaponGeneratorHelper"; import { HandbookHelper } from "../helpers/HandbookHelper"; import { Inventory as PmcInventory } from "../models/eft/common/tables/IBotBase"; import { Chances, Inventory, ItemMinMax, ModsChances } from "../models/eft/common/tables/IBotType"; @@ -20,10 +21,11 @@ export declare class BotLootGenerator { protected handbookHelper: HandbookHelper; protected botGeneratorHelper: BotGeneratorHelper; protected botWeaponGenerator: BotWeaponGenerator; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; protected botLootCacheService: BotLootCacheService; protected configServer: ConfigServer; protected botConfig: IBotConfig; - constructor(logger: ILogger, hashUtil: HashUtil, randomUtil: RandomUtil, databaseServer: DatabaseServer, handbookHelper: HandbookHelper, botGeneratorHelper: BotGeneratorHelper, botWeaponGenerator: BotWeaponGenerator, botLootCacheService: BotLootCacheService, configServer: ConfigServer); + constructor(logger: ILogger, hashUtil: HashUtil, randomUtil: RandomUtil, databaseServer: DatabaseServer, handbookHelper: HandbookHelper, botGeneratorHelper: BotGeneratorHelper, botWeaponGenerator: BotWeaponGenerator, botWeaponGeneratorHelper: BotWeaponGeneratorHelper, botLootCacheService: BotLootCacheService, configServer: ConfigServer); generateLoot(sessionId: string, templateInventory: Inventory, itemCounts: ItemMinMax, isPmc: boolean, botRole: string, botInventory: PmcInventory, equipmentChances: Chances): void; protected getRandomisedCount(min: number, max: number, nValue: number): number; /** diff --git a/TypeScript/9RouterHooks/types/generators/BotWeaponGenerator.d.ts b/TypeScript/9RouterHooks/types/generators/BotWeaponGenerator.d.ts index cba7afa..487901b 100644 --- a/TypeScript/9RouterHooks/types/generators/BotWeaponGenerator.d.ts +++ b/TypeScript/9RouterHooks/types/generators/BotWeaponGenerator.d.ts @@ -1,4 +1,5 @@ import { BotGeneratorHelper } from "../helpers/BotGeneratorHelper"; +import { BotWeaponGeneratorHelper } from "../helpers/BotWeaponGeneratorHelper"; import { ItemHelper } from "../helpers/ItemHelper"; import { WeightedRandomHelper } from "../helpers/WeightedRandomHelper"; import { MinMax } from "../models/common/MinMax"; @@ -14,6 +15,7 @@ import { DatabaseServer } from "../servers/DatabaseServer"; import { HashUtil } from "../utils/HashUtil"; import { JsonUtil } from "../utils/JsonUtil"; import { RandomUtil } from "../utils/RandomUtil"; +import { IInventoryMagGen } from "./weapongen/IInventoryMagGen"; export declare class BotWeaponGenerator { protected jsonUtil: JsonUtil; protected logger: ILogger; @@ -24,9 +26,11 @@ export declare class BotWeaponGenerator { protected botGeneratorHelper: BotGeneratorHelper; protected randomUtil: RandomUtil; protected configServer: ConfigServer; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + protected inventoryMagGenComponents: IInventoryMagGen[]; protected readonly modMagazineSlotId = "mod_magazine"; protected botConfig: IBotConfig; - constructor(jsonUtil: JsonUtil, logger: ILogger, hashUtil: HashUtil, databaseServer: DatabaseServer, itemHelper: ItemHelper, weightedRandomHelper: WeightedRandomHelper, botGeneratorHelper: BotGeneratorHelper, randomUtil: RandomUtil, configServer: ConfigServer); + constructor(jsonUtil: JsonUtil, logger: ILogger, hashUtil: HashUtil, databaseServer: DatabaseServer, itemHelper: ItemHelper, weightedRandomHelper: WeightedRandomHelper, botGeneratorHelper: BotGeneratorHelper, randomUtil: RandomUtil, configServer: ConfigServer, botWeaponGeneratorHelper: BotWeaponGeneratorHelper, inventoryMagGenComponents: IInventoryMagGen[]); /** * Pick a random weapon based on weightings and generate a functional weapon * @param equipmentSlot Primary/secondary/holster @@ -85,36 +89,12 @@ export declare class BotWeaponGenerator { /** * Generates extra magazines or bullets (if magazine is internal) and adds them to TacticalVest and Pockets. * Additionally, adds extra bullets to SecuredContainer - * @param weaponMods mods to attach to weapon - * @param weaponTemplate db template for weapon - * @param magCounts magazine count to add to inventory - * @param ammoTpl ammo templateId to add to magazines - * @param inventory inventory to add magazines to - * @param botRole the bot type we're getting generating extra mags for - * @returns + * @param generatedWeaponResult object with properties for generated weapon (weapon mods pool / weapon template / ammo tpl) + * @param magCounts Magazine count to add to inventory + * @param inventory Inventory to add magazines to + * @param botRole The bot type we're getting generating extra mags for */ - addExtraMagazinesToInventory(weaponMods: Item[], weaponTemplate: ITemplateItem, magCounts: MinMax, ammoTpl: string, inventory: PmcInventory, botRole: string): void; - /** - * Create a magazine using the parameters given - * @param magazineTpl Tpl of the magazine to create - * @param ammoTpl Ammo to add to magazine - * @param magTemplate template object of magazine - * @returns Item array - */ - protected createMagazine(magazineTpl: string, ammoTpl: string, magTemplate: ITemplateItem): Item[]; - /** - * Get a randomised number of bullets for a specific magazine - * @param magCounts min and max count of magazines - * @param magTemplate magazine to generate bullet count for - * @returns bullet count number - */ - protected getRandomisedBulletCount(magCounts: MinMax, magTemplate: ITemplateItem): number; - /** - * Get a randomised count of magazines - * @param magCounts min and max value returned value can be between - * @returns numberical value of magazine count - */ - protected getRandomisedMagazineCount(magCounts: MinMax): number; + addExtraMagazinesToInventory(generatedWeaponResult: GenerateWeaponResult, magCounts: MinMax, inventory: PmcInventory, botRole: string): void; /** * Add ammo to the secure container * @param stackCount How many stacks of ammo to add @@ -131,13 +111,6 @@ export declare class BotWeaponGenerator { * @returns magazine tpl string */ protected getMagazineTplFromWeaponTemplate(weaponMods: Item[], weaponTemplate: ITemplateItem, botRole: string): string; - /** - * Get a weapons default magazine template id - * @param weaponTemplate weapon to get default magazine for - * @returns tpl of magazine - */ - protected getWeaponsDefaultMagazineTpl(weaponTemplate: ITemplateItem): string; - protected addBulletsToVestAndPockets(ammoTpl: string, bulletCount: number, inventory: PmcInventory): void; /** * Finds and return a compatible ammo tpl based on the bots ammo weightings (x.json/inventory/equipment/ammo) * @param ammo a list of ammo tpls the weapon can use diff --git a/TypeScript/9RouterHooks/types/generators/weapongen/IInventoryMagGen.d.ts b/TypeScript/9RouterHooks/types/generators/weapongen/IInventoryMagGen.d.ts new file mode 100644 index 0000000..792f510 --- /dev/null +++ b/TypeScript/9RouterHooks/types/generators/weapongen/IInventoryMagGen.d.ts @@ -0,0 +1,6 @@ +import { InventoryMagGen } from "./InventoryMagGen"; +export interface IInventoryMagGen { + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/9RouterHooks/types/generators/weapongen/InventoryMagGen.d.ts b/TypeScript/9RouterHooks/types/generators/weapongen/InventoryMagGen.d.ts new file mode 100644 index 0000000..30bf79f --- /dev/null +++ b/TypeScript/9RouterHooks/types/generators/weapongen/InventoryMagGen.d.ts @@ -0,0 +1,16 @@ +import { MinMax } from "../../models/common/MinMax"; +import { Inventory } from "../../models/eft/common/tables/IBotBase"; +import { ITemplateItem } from "../../models/eft/common/tables/ITemplateItem"; +export declare class InventoryMagGen { + private magCounts; + private magazineTemplate; + private weaponTemplate; + private ammoTemplate; + private pmcInventory; + constructor(magCounts: MinMax, magazineTemplate: ITemplateItem, weaponTemplate: ITemplateItem, ammoTemplate: ITemplateItem, pmcInventory: Inventory); + getMagCount(): MinMax; + getMagazineTemplate(): ITemplateItem; + getWeaponTemplate(): ITemplateItem; + getAmmoTemplate(): ITemplateItem; + getPmcInventory(): Inventory; +} diff --git a/TypeScript/9RouterHooks/types/generators/weapongen/implementations/BarrelInventoryMagGen.d.ts b/TypeScript/9RouterHooks/types/generators/weapongen/implementations/BarrelInventoryMagGen.d.ts new file mode 100644 index 0000000..b754d5f --- /dev/null +++ b/TypeScript/9RouterHooks/types/generators/weapongen/implementations/BarrelInventoryMagGen.d.ts @@ -0,0 +1,12 @@ +import { BotWeaponGeneratorHelper } from "../../../helpers/BotWeaponGeneratorHelper"; +import { RandomUtil } from "../../../utils/RandomUtil"; +import { IInventoryMagGen } from "../IInventoryMagGen"; +import { InventoryMagGen } from "../InventoryMagGen"; +export declare class BarrelInventoryMagGen implements IInventoryMagGen { + protected randomUtil: RandomUtil; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + constructor(randomUtil: RandomUtil, botWeaponGeneratorHelper: BotWeaponGeneratorHelper); + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/9RouterHooks/types/generators/weapongen/implementations/ExternalInventoryMagGen.d.ts b/TypeScript/9RouterHooks/types/generators/weapongen/implementations/ExternalInventoryMagGen.d.ts new file mode 100644 index 0000000..4fcb1e2 --- /dev/null +++ b/TypeScript/9RouterHooks/types/generators/weapongen/implementations/ExternalInventoryMagGen.d.ts @@ -0,0 +1,14 @@ +import { BotWeaponGeneratorHelper } from "../../../helpers/BotWeaponGeneratorHelper"; +import { ItemHelper } from "../../../helpers/ItemHelper"; +import { ILogger } from "../../../models/spt/utils/ILogger"; +import { IInventoryMagGen } from "../IInventoryMagGen"; +import { InventoryMagGen } from "../InventoryMagGen"; +export declare class ExternalInventoryMagGen implements IInventoryMagGen { + protected logger: ILogger; + protected itemHelper: ItemHelper; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + constructor(logger: ILogger, itemHelper: ItemHelper, botWeaponGeneratorHelper: BotWeaponGeneratorHelper); + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/9RouterHooks/types/generators/weapongen/implementations/InternalMagazineInventoryMagGen.d.ts b/TypeScript/9RouterHooks/types/generators/weapongen/implementations/InternalMagazineInventoryMagGen.d.ts new file mode 100644 index 0000000..4548a04 --- /dev/null +++ b/TypeScript/9RouterHooks/types/generators/weapongen/implementations/InternalMagazineInventoryMagGen.d.ts @@ -0,0 +1,10 @@ +import { BotWeaponGeneratorHelper } from "../../../helpers/BotWeaponGeneratorHelper"; +import { IInventoryMagGen } from "../IInventoryMagGen"; +import { InventoryMagGen } from "../InventoryMagGen"; +export declare class InternalMagazineInventoryMagGen implements IInventoryMagGen { + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; + constructor(botWeaponGeneratorHelper: BotWeaponGeneratorHelper); + getPriority(): number; + canHandleInventoryMagGen(inventoryMagGen: InventoryMagGen): boolean; + process(inventoryMagGen: InventoryMagGen): void; +} diff --git a/TypeScript/9RouterHooks/types/helpers/BotGeneratorHelper.d.ts b/TypeScript/9RouterHooks/types/helpers/BotGeneratorHelper.d.ts index 09e5c8f..5e3e501 100644 --- a/TypeScript/9RouterHooks/types/helpers/BotGeneratorHelper.d.ts +++ b/TypeScript/9RouterHooks/types/helpers/BotGeneratorHelper.d.ts @@ -1,8 +1,7 @@ import { DurabilityLimitsHelper } from "../helpers/DurabilityLimitsHelper"; -import { Inventory as PmcInventory } from "../models/eft/common/tables/IBotBase"; import { Mods, ModsChances } from "../models/eft/common/tables/IBotType"; import { Item, Repairable, Upd } from "../models/eft/common/tables/IItem"; -import { Grid, ITemplateItem, Slot } from "../models/eft/common/tables/ITemplateItem"; +import { ITemplateItem, Slot } from "../models/eft/common/tables/ITemplateItem"; import { EquipmentFilterDetails, IBotConfig } from "../models/spt/config/IBotConfig"; import { ILogger } from "../models/spt/utils/ILogger"; import { ConfigServer } from "../servers/ConfigServer"; @@ -12,6 +11,7 @@ import { ItemFilterService } from "../services/ItemFilterService"; import { HashUtil } from "../utils/HashUtil"; import { JsonUtil } from "../utils/JsonUtil"; import { RandomUtil } from "../utils/RandomUtil"; +import { BotWeaponGeneratorHelper } from "./BotWeaponGeneratorHelper"; import { ContainerHelper } from "./ContainerHelper"; import { InventoryHelper } from "./InventoryHelper"; import { ItemHelper } from "./ItemHelper"; @@ -42,11 +42,11 @@ export declare class BotGeneratorHelper { protected botEquipmentFilterService: BotEquipmentFilterService; protected itemFilterService: ItemFilterService; protected profileHelper: ProfileHelper; + protected botWeaponGeneratorHelper: BotWeaponGeneratorHelper; protected configServer: ConfigServer; protected botConfig: IBotConfig; - constructor(logger: ILogger, jsonUtil: JsonUtil, hashUtil: HashUtil, randomUtil: RandomUtil, probabilityHelper: ProbabilityHelper, databaseServer: DatabaseServer, durabilityLimitsHelper: DurabilityLimitsHelper, itemHelper: ItemHelper, inventoryHelper: InventoryHelper, containerHelper: ContainerHelper, botEquipmentFilterService: BotEquipmentFilterService, itemFilterService: ItemFilterService, profileHelper: ProfileHelper, configServer: ConfigServer); + constructor(logger: ILogger, jsonUtil: JsonUtil, hashUtil: HashUtil, randomUtil: RandomUtil, probabilityHelper: ProbabilityHelper, databaseServer: DatabaseServer, durabilityLimitsHelper: DurabilityLimitsHelper, itemHelper: ItemHelper, inventoryHelper: InventoryHelper, containerHelper: ContainerHelper, botEquipmentFilterService: BotEquipmentFilterService, itemFilterService: ItemFilterService, profileHelper: ProfileHelper, botWeaponGeneratorHelper: BotWeaponGeneratorHelper, configServer: ConfigServer); /** - * TODO - very similar to generateModsForWeapon * Check mods are compatible and add to array * @param equipment Equipment item to add mods to * @param modPool Mod list to choose frm @@ -57,18 +57,30 @@ export declare class BotGeneratorHelper { */ generateModsForEquipment(equipment: Item[], modPool: Mods, parentId: string, parentTemplate: ITemplateItem, modSpawnChances: ModsChances): Item[]; /** - * TODO - very similar to generateModsForEquipment * @param sessionId session id * @param weapon Weapon to add mods to - * @param modPool pool of compatible mods to attach to gun + * @param modPool Pool of compatible mods to attach to weapon * @param weaponParentId parentId of weapon - * @param parentTemplate - * @param modSpawnChances - * @param ammoTpl ammo tpl to use when generating magazines/cartridges - * @param botRole role of bot weapon is generated for - * @returns Weapon with mods + * @param parentWeaponTemplate Weapon which mods will be generated on + * @param modSpawnChances Mod spawn chances + * @param ammoTpl Ammo tpl to use when generating magazines/cartridges + * @param botRole Role of bot weapon is generated for + * @returns Weapon + mods array */ - generateModsForWeapon(sessionId: string, weapon: Item[], modPool: Mods, weaponParentId: string, parentTemplate: ITemplateItem, modSpawnChances: ModsChances, ammoTpl: string, botRole: string): Item[]; + generateModsForWeapon(sessionId: string, weapon: Item[], modPool: Mods, weaponParentId: string, parentWeaponTemplate: ITemplateItem, modSpawnChances: ModsChances, ammoTpl: string, botRole: string): Item[]; + /** + * + * @param modSlot + * @param isRandomisableSlot + * @param modsParent + * @param botEquipBlacklist + * @param itemModPool + * @param weapon array with only weapon tpl in it, ready for mods to be added + * @param ammoTpl ammo tpl to use if slot requires a cartridge to be added (e.g. mod_magazine) + * @param parentTemplate + * @returns + */ + protected chooseModToPutIntoSlot(modSlot: string, isRandomisableSlot: boolean, modsParent: Slot, botEquipBlacklist: EquipmentFilterDetails, itemModPool: Record, weapon: Item[], ammoTpl: string, parentTemplate: ITemplateItem): [boolean, ITemplateItem]; /** * Find mod tpls of a provided type and add to modPool * @param desiredSlotName slot to look up and add we are adding tpls for (e.g mod_scope) @@ -79,15 +91,15 @@ export declare class BotGeneratorHelper { /** * Check if mod item is on limited list + has surpassed the limit set for it * @param botRole role the bot has e.g. assault - * @param modTpl mods tpl + * @param modTemplate mods template data * @param modLimits limits set for weapon being generated for this bot * @returns true if over item limit */ - protected modHasReachedItemLimit(botRole: string, modTpl: string, modLimits: BotModLimits): boolean; + protected modHasReachedItemLimit(botRole: string, modTemplate: ITemplateItem, modLimits: BotModLimits): boolean; /** - * Initalise mod limits to be used when generating the weapon + * Initalise mod limits to be used when generating a weapon * @param botRole "assault", "bossTagilla" or "pmc" - * @returns + * @returns BotModLimits object */ protected initModLimits(botRole: string): BotModLimits; /** @@ -114,7 +126,7 @@ export declare class BotGeneratorHelper { protected filterWeaponModsByBlacklist(allowedMods: string[], botEquipBlacklist: EquipmentFilterDetails, modSlot: string): string[]; /** * Check if the specific item type on the weapon has reached the set limit - * @param modTpl item to check is limited + * @param modTpl log mod tpl if over type limit * @param currentCount current number of this item on gun * @param maxLimit mod limit allowed * @param botRole role of bot we're checking weapon of @@ -124,16 +136,14 @@ export declare class BotGeneratorHelper { count: number; }, maxLimit: number, botRole: string): boolean; /** - * log errors if mod is not valid for a slot - * @param modTpl - * @param found - * @param itemSlot - * @param modTemplate - * @param modSlot - * @param parentTemplate + * Log errors if mod is not compatible with slot + * @param modToAdd template of mod to check + * @param itemSlot slot the item will be placed in + * @param modSlot slot the mod will fill + * @param parentTemplate tempalte of the mods parent item * @returns true if valid */ - protected isModValidForSlot(modTpl: string, found: boolean, itemSlot: Slot, modTemplate: ITemplateItem, modSlot: string, parentTemplate: ITemplateItem): boolean; + protected isModValidForSlot(modToAdd: [boolean, ITemplateItem], itemSlot: Slot, modSlot: string, parentTemplate: ITemplateItem): boolean; /** * Create a mod item with parameters as properties * @param modId _id @@ -144,12 +154,6 @@ export declare class BotGeneratorHelper { * @returns Item object */ protected createModItem(modId: string, modTpl: string, parentId: string, modSlot: string, modTemplate: ITemplateItem): Item; - /** - * Is this magazine cylinder related (revolvers and grenade launchers) - * @param magazineParentName the name of the magazines parent - * @returns true if it is cylinder related - */ - magazineIsCylinderRelated(magazineParentName: string): boolean; /** * randomly choose if a mod should be spawned, 100% for required mods OR mod is ammo slot * never return true for an item that has 0% spawn chance @@ -161,7 +165,7 @@ export declare class BotGeneratorHelper { protected shouldModBeSpawned(itemSlot: Slot, modSlot: string, modSpawnChances: ModsChances): boolean; /** * Get a list of containers that hold ammo - * e.g. mod_magazine + * e.g. mod_magazine / patron_in_weapon_000 * @returns string array */ protected getAmmoContainers(): string[]; @@ -214,6 +218,14 @@ export declare class BotGeneratorHelper { * @returns Repairable object */ protected generateArmorRepairableProperties(itemTemplate: ITemplateItem, botRole: string): Repairable; + /** + * Get a random mod from an items compatible mods Filter array + * @param modTpl + * @param parentSlot + * @param modSlot + * @param items + * @returns item tpl + */ protected getModTplFromItemDb(modTpl: string, parentSlot: Slot, modSlot: string, items: Item[]): string; /** * Can an item be added to an item without issue @@ -223,23 +235,6 @@ export declare class BotGeneratorHelper { * @returns true if possible */ isItemIncompatibleWithCurrentItems(items: Item[], tplToCheck: string, equipmentSlot: string): boolean; - /** - * Adds an item with all its childern into specified equipmentSlots, wherever it fits. - * @param equipmentSlots - * @param parentId - * @param parentTpl - * @param itemWithChildren - * @param inventory - * @returns a `boolean` indicating item was added - */ - addItemWithChildrenToEquipmentSlot(equipmentSlots: string[], parentId: string, parentTpl: string, itemWithChildren: Item[], inventory: PmcInventory): boolean; - /** - * is the provided item allowed inside a container - * @param slot location item wants to be placed in - * @param itemTpl item being placed - * @returns true if allowed - */ - protected itemAllowedInContainer(slot: Grid, itemTpl: string): boolean; } /** TODO - move into own class */ export declare class ExhaustableArray { diff --git a/TypeScript/9RouterHooks/types/helpers/BotWeaponGeneratorHelper.d.ts b/TypeScript/9RouterHooks/types/helpers/BotWeaponGeneratorHelper.d.ts new file mode 100644 index 0000000..7e25f56 --- /dev/null +++ b/TypeScript/9RouterHooks/types/helpers/BotWeaponGeneratorHelper.d.ts @@ -0,0 +1,78 @@ +import { MinMax } from "../models/common/MinMax"; +import { Inventory } from "../models/eft/common/tables/IBotBase"; +import { Item } from "../models/eft/common/tables/IItem"; +import { Grid, ITemplateItem } from "../models/eft/common/tables/ITemplateItem"; +import { ILogger } from "../models/spt/utils/ILogger"; +import { DatabaseServer } from "../servers/DatabaseServer"; +import { HashUtil } from "../utils/HashUtil"; +import { RandomUtil } from "../utils/RandomUtil"; +import { ContainerHelper } from "./ContainerHelper"; +import { InventoryHelper } from "./InventoryHelper"; +import { ItemHelper } from "./ItemHelper"; +export declare class BotWeaponGeneratorHelper { + protected logger: ILogger; + protected databaseServer: DatabaseServer; + protected itemHelper: ItemHelper; + protected randomUtil: RandomUtil; + protected hashUtil: HashUtil; + protected inventoryHelper: InventoryHelper; + protected containerHelper: ContainerHelper; + constructor(logger: ILogger, databaseServer: DatabaseServer, itemHelper: ItemHelper, randomUtil: RandomUtil, hashUtil: HashUtil, inventoryHelper: InventoryHelper, containerHelper: ContainerHelper); + /** + * Get a randomised number of bullets for a specific magazine + * @param magCounts min and max count of magazines + * @param magTemplate magazine to generate bullet count for + * @returns bullet count number + */ + getRandomisedBulletCount(magCounts: MinMax, magTemplate: ITemplateItem): number; + /** + * Get a randomised count of magazines + * @param magCounts min and max value returned value can be between + * @returns numberical value of magazine count + */ + getRandomisedMagazineCount(magCounts: MinMax): number; + /** + * Is this magazine cylinder related (revolvers and grenade launchers) + * @param magazineParentName the name of the magazines parent + * @returns true if it is cylinder related + */ + magazineIsCylinderRelated(magazineParentName: string): boolean; + /** + * Create a magazine using the parameters given + * @param magazineTpl Tpl of the magazine to create + * @param ammoTpl Ammo to add to magazine + * @param magTemplate template object of magazine + * @returns Item array + */ + createMagazine(magazineTpl: string, ammoTpl: string, magTemplate: ITemplateItem): Item[]; + /** + * Add a specific number of cartrdiges to a bots inventory (vest/pocket) + * @param ammoTpl Ammo tpl to add to vest/pockets + * @param cartridgeCount number of cartridges to add to vest/pockets + * @param inventory bot inventory to add cartridges to + */ + addBulletsToVestAndPockets(ammoTpl: string, cartridgeCount: number, inventory: Inventory): void; + /** + * Get a weapons default magazine template id + * @param weaponTemplate weapon to get default magazine for + * @returns tpl of magazine + */ + getWeaponsDefaultMagazineTpl(weaponTemplate: ITemplateItem): string; + /** + * Adds an item with all its childern into specified equipmentSlots, wherever it fits. + * @param equipmentSlots + * @param parentId + * @param parentTpl + * @param itemWithChildren + * @param inventory + * @returns a `boolean` indicating item was added + */ + addItemWithChildrenToEquipmentSlot(equipmentSlots: string[], parentId: string, parentTpl: string, itemWithChildren: Item[], inventory: Inventory): boolean; + /** + * is the provided item allowed inside a container + * @param slot location item wants to be placed in + * @param itemTpl item being placed + * @returns true if allowed + */ + protected itemAllowedInContainer(slot: Grid, itemTpl: string): boolean; +}