Added functionality to allow setting a minimum magazine size for bots based on bot level via config

This commit is contained in:
Dev 2024-11-04 11:39:53 +00:00
parent 574300d8cb
commit e844f52478
4 changed files with 94 additions and 3 deletions

View File

@ -1358,6 +1358,33 @@
"equipmentModsModifiers": {
"mod_nvg": 50
}
},
"minimumMagazineSize": {
"5447a9cd4bdc2dbd208b4567": 30,
"5926bb2186f7744b1c6c6e60": 30,
"5c07c60e0db834002330051f": 30,
"5bb2475ed4351e00853264e3": 30,
"5bf3e03b0db834001d2c4a9c": 30,
"5644bd2b4bdc2d3b4c8b4572": 30,
"63171672192e68c5460cebc5": 30,
"62e7c4fba689e8c9c50dfc38": 30,
"623063e994fc3f7b302a9696": 30,
"5c488a752e221602b412af63": 30,
"5fbcc1d9016cce60e8341ab3": 30,
"606587252535c57a13424cfd": 30,
"628a60ae6b1d481ff772e9c8": 30,
"5aafa857e5b5b00018480968": 20,
"5df8ce05b11454561e39243b": 20,
"5beed0f50db834001c062b12": 30,
"5ba26383d4351e00334c93d9": 30,
"5bd70322209c4d00d7167b8f": 30,
"5e00903ae9dc277128008b87": 25,
"5de7bd7bfd6b4e6e2276dc25": 30,
"58948c8e86f77409493f7266": 30,
"59984ab886f7743e98271174": 30,
"5fc3f2d5900b1d5091531e57": 30,
"5fb64bc92b1b027b1f50bcf2": 30,
"668e71a8dadf42204c032ce1": 30
}
},
{
@ -1432,6 +1459,33 @@
"equipmentModsModifiers": {
"mod_nvg": 90
}
},
"minimumMagazineSize": {
"5447a9cd4bdc2dbd208b4567": 30,
"5926bb2186f7744b1c6c6e60": 30,
"5c07c60e0db834002330051f": 30,
"5bb2475ed4351e00853264e3": 30,
"5bf3e03b0db834001d2c4a9c": 30,
"5644bd2b4bdc2d3b4c8b4572": 30,
"63171672192e68c5460cebc5": 30,
"62e7c4fba689e8c9c50dfc38": 30,
"623063e994fc3f7b302a9696": 30,
"5c488a752e221602b412af63": 30,
"5fbcc1d9016cce60e8341ab3": 30,
"606587252535c57a13424cfd": 30,
"628a60ae6b1d481ff772e9c8": 30,
"5aafa857e5b5b00018480968": 20,
"5df8ce05b11454561e39243b": 20,
"5beed0f50db834001c062b12": 30,
"5ba26383d4351e00334c93d9": 30,
"5bd70322209c4d00d7167b8f": 30,
"5e00903ae9dc277128008b87": 25,
"5de7bd7bfd6b4e6e2276dc25": 30,
"58948c8e86f77409493f7266": 30,
"59984ab886f7743e98271174": 30,
"5fc3f2d5900b1d5091531e57": 30,
"5fb64bc92b1b027b1f50bcf2": 30,
"668e71a8dadf42204c032ce1": 30
}
}
],

View File

@ -406,6 +406,7 @@ export class BotEquipmentModGenerator {
const modToSpawnRequest: IModToSpawnRequest = {
modSlot: modSlot,
isRandomisableSlot: isRandomisableSlot,
randomisationSettings: randomisationSettings,
botWeaponSightWhitelist: botWeaponSightWhitelist,
botEquipBlacklist: botEquipBlacklist,
itemModPool: compatibleModsPool,
@ -834,6 +835,16 @@ export class BotEquipmentModGenerator {
}
}
// Check if weapon has min magazine size limit
if (
request.modSlot === "mod_magazine" &&
request.isRandomisableSlot &&
request.randomisationSettings.minimumMagazineSize &&
request.randomisationSettings.minimumMagazineSize[request.weapon[0]._tpl]
) {
modPool = this.getFilterdMagazinePoolByCapacity(request, modPool);
}
// Pick random mod that's compatible
const chosenModResult = this.getCompatibleWeaponModTplForSlotFromPool(
request,
@ -877,6 +888,29 @@ export class BotEquipmentModGenerator {
return this.itemHelper.getItem(chosenModResult.chosenTpl);
}
/**
* Given the passed in array of magaizne tpls, look up the min size set in config and return only those that have that size or larger
* @param modSpawnRequest Request data
* @param modPool Pool of magazine tpls to filter
* @returns Filtered pool of magazine tpls
*/
protected getFilterdMagazinePoolByCapacity(modSpawnRequest: IModToSpawnRequest, modPool: string[]): string[] {
const weaponTpl = modSpawnRequest.weapon[0]._tpl;
const minMagazineSize = modSpawnRequest.randomisationSettings.minimumMagazineSize[weaponTpl];
const desiredMagazineTpls = modPool.filter((magTpl) => {
const magazineDb = this.itemHelper.getItem(magTpl)[1];
return magazineDb._props && magazineDb._props.Cartridges[0]._max_count >= minMagazineSize;
});
if (desiredMagazineTpls.length === 0) {
this.logger.warning(`Magazine size filter for ${weaponTpl} was too strict, ignoring filter`);
return modPool;
}
return desiredMagazineTpls;
}
/**
* Choose a weapon mod tpl for a given slot from a pool of choices
* Checks chosen tpl is compatible with all existing weapon items

View File

@ -2,13 +2,14 @@ import { IItem } from "@spt/models/eft/common/tables/IItem";
import { ITemplateItem } from "@spt/models/eft/common/tables/ITemplateItem";
import { ModSpawn } from "@spt/models/enums/ModSpawn";
import { IBotData, IWeaponStats } from "@spt/models/spt/bots/IGenerateWeaponRequest";
import { IEquipmentFilterDetails } from "@spt/models/spt/config/IBotConfig";
import { IEquipmentFilterDetails, IRandomisationDetails } from "@spt/models/spt/config/IBotConfig";
export interface IModToSpawnRequest {
/** Slot mod will fit into */
modSlot: string;
/** Will generate a randomised mod pool if true */
isRandomisableSlot: boolean;
randomisationSettings: IRandomisationDetails;
/** Parent slot the item will be a part of */
botWeaponSightWhitelist: Record<string, string[]>;
/** Blacklist to prevent mods from being picked */

View File

@ -167,6 +167,8 @@ export interface IRandomisationDetails {
/** Equipment mod chances */
equipmentMods?: Record<string, number>;
nighttimeChanges?: INighttimeChanges;
/** Key = weapon tpl, value = min size of magaizne allowed */
minimumMagazineSize?: Record<string, number>;
}
export interface INighttimeChanges {