diff --git a/project/src/generators/LocationGenerator.ts b/project/src/generators/LocationGenerator.ts index 380ac931..2cfddc8a 100644 --- a/project/src/generators/LocationGenerator.ts +++ b/project/src/generators/LocationGenerator.ts @@ -1033,7 +1033,7 @@ export class LocationGenerator // it can handle revolver ammo (it's not restructured to be used here yet.) // General: Make a WeaponController for Ragfair preset stuff and the generating weapons and ammo stuff from // BotGenerator - const magazine = items.filter((x) => x.slotId === "mod_magazine")[0]; + const magazine = items.filter((item) => item.slotId === "mod_magazine")[0]; // some weapon presets come without magazine; only fill the mag if it exists if (magazine) { @@ -1047,6 +1047,8 @@ export class LocationGenerator magTemplate, staticAmmoDist, weaponTemplate._props.ammoCaliber, + 0.25, + this.itemHelper.getItem(rootItem._tpl)[1], ); // Replace existing magazine with above array diff --git a/project/src/helpers/ItemHelper.ts b/project/src/helpers/ItemHelper.ts index 7045e8dc..3291e4c0 100644 --- a/project/src/helpers/ItemHelper.ts +++ b/project/src/helpers/ItemHelper.ts @@ -1054,6 +1054,7 @@ export class ItemHelper * @param staticAmmoDist Cartridge distribution * @param caliber Caliber of cartridge to add to magazine * @param minSizePercent % the magazine must be filled to + * @param weapon Weapon the magazine will be used for (if passed in uses Chamber as whitelist) */ public fillMagazineWithRandomCartridge( magazine: Item[], @@ -1061,6 +1062,7 @@ export class ItemHelper staticAmmoDist: Record, caliber: string = undefined, minSizePercent = 0.25, + weapon: ITemplateItem = null, ): void { let chosenCaliber = caliber || this.getRandomValidCaliber(magTemplate); @@ -1072,7 +1074,11 @@ export class ItemHelper } // Chose a randomly weighted cartridge that fits - const cartridgeTpl = this.drawAmmoTpl(chosenCaliber, staticAmmoDist); + const cartridgeTpl = this.drawAmmoTpl( + chosenCaliber, + staticAmmoDist, + weapon?._props?.Chambers[0]?._props?.filters[0]?.Filter, + ); this.fillMagazineWithCartridge(magazine, magTemplate, cartridgeTpl, minSizePercent); } @@ -1179,9 +1185,14 @@ export class ItemHelper * Chose a randomly weighted cartridge that fits * @param caliber Desired caliber * @param staticAmmoDist Cartridges and thier weights + * @param cartridgeWhitelist OPTIONAL whitelist for cartridges * @returns Tpl of cartridge */ - protected drawAmmoTpl(caliber: string, staticAmmoDist: Record): string + protected drawAmmoTpl( + caliber: string, + staticAmmoDist: Record, + cartridgeWhitelist: string[] = null, + ): string { const ammoArray = new ProbabilityObjectArray(this.mathUtil, this.jsonUtil); const ammos = staticAmmoDist[caliber]; @@ -1192,6 +1203,13 @@ export class ItemHelper for (const icd of ammos) { + // Whitelist exists and tpl not inside it, skip + // Fixes 9x18mm kedr issues + if (cartridgeWhitelist && !cartridgeWhitelist.includes(icd.tpl)) + { + continue; + } + ammoArray.push(new ProbabilityObject(icd.tpl, icd.relativeProbability)); } return ammoArray.draw(1)[0];