Add whitelist system to magazine filling function fillMagazineWithRandomCartridge()
. Fixes issues with kedr being filled with incompatible ammo
This commit is contained in:
parent
1c755a4bf4
commit
57855fd316
@ -1033,7 +1033,7 @@ export class LocationGenerator
|
|||||||
// it can handle revolver ammo (it's not restructured to be used here yet.)
|
// 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
|
// General: Make a WeaponController for Ragfair preset stuff and the generating weapons and ammo stuff from
|
||||||
// BotGenerator
|
// 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
|
// some weapon presets come without magazine; only fill the mag if it exists
|
||||||
if (magazine)
|
if (magazine)
|
||||||
{
|
{
|
||||||
@ -1047,6 +1047,8 @@ export class LocationGenerator
|
|||||||
magTemplate,
|
magTemplate,
|
||||||
staticAmmoDist,
|
staticAmmoDist,
|
||||||
weaponTemplate._props.ammoCaliber,
|
weaponTemplate._props.ammoCaliber,
|
||||||
|
0.25,
|
||||||
|
this.itemHelper.getItem(rootItem._tpl)[1],
|
||||||
);
|
);
|
||||||
|
|
||||||
// Replace existing magazine with above array
|
// Replace existing magazine with above array
|
||||||
|
@ -1054,6 +1054,7 @@ export class ItemHelper
|
|||||||
* @param staticAmmoDist Cartridge distribution
|
* @param staticAmmoDist Cartridge distribution
|
||||||
* @param caliber Caliber of cartridge to add to magazine
|
* @param caliber Caliber of cartridge to add to magazine
|
||||||
* @param minSizePercent % the magazine must be filled to
|
* @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(
|
public fillMagazineWithRandomCartridge(
|
||||||
magazine: Item[],
|
magazine: Item[],
|
||||||
@ -1061,6 +1062,7 @@ export class ItemHelper
|
|||||||
staticAmmoDist: Record<string, IStaticAmmoDetails[]>,
|
staticAmmoDist: Record<string, IStaticAmmoDetails[]>,
|
||||||
caliber: string = undefined,
|
caliber: string = undefined,
|
||||||
minSizePercent = 0.25,
|
minSizePercent = 0.25,
|
||||||
|
weapon: ITemplateItem = null,
|
||||||
): void
|
): void
|
||||||
{
|
{
|
||||||
let chosenCaliber = caliber || this.getRandomValidCaliber(magTemplate);
|
let chosenCaliber = caliber || this.getRandomValidCaliber(magTemplate);
|
||||||
@ -1072,7 +1074,11 @@ export class ItemHelper
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Chose a randomly weighted cartridge that fits
|
// 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);
|
this.fillMagazineWithCartridge(magazine, magTemplate, cartridgeTpl, minSizePercent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1179,9 +1185,14 @@ export class ItemHelper
|
|||||||
* Chose a randomly weighted cartridge that fits
|
* Chose a randomly weighted cartridge that fits
|
||||||
* @param caliber Desired caliber
|
* @param caliber Desired caliber
|
||||||
* @param staticAmmoDist Cartridges and thier weights
|
* @param staticAmmoDist Cartridges and thier weights
|
||||||
|
* @param cartridgeWhitelist OPTIONAL whitelist for cartridges
|
||||||
* @returns Tpl of cartridge
|
* @returns Tpl of cartridge
|
||||||
*/
|
*/
|
||||||
protected drawAmmoTpl(caliber: string, staticAmmoDist: Record<string, IStaticAmmoDetails[]>): string
|
protected drawAmmoTpl(
|
||||||
|
caliber: string,
|
||||||
|
staticAmmoDist: Record<string, IStaticAmmoDetails[]>,
|
||||||
|
cartridgeWhitelist: string[] = null,
|
||||||
|
): string
|
||||||
{
|
{
|
||||||
const ammoArray = new ProbabilityObjectArray<string>(this.mathUtil, this.jsonUtil);
|
const ammoArray = new ProbabilityObjectArray<string>(this.mathUtil, this.jsonUtil);
|
||||||
const ammos = staticAmmoDist[caliber];
|
const ammos = staticAmmoDist[caliber];
|
||||||
@ -1192,6 +1203,13 @@ export class ItemHelper
|
|||||||
|
|
||||||
for (const icd of ammos)
|
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));
|
ammoArray.push(new ProbabilityObject(icd.tpl, icd.relativeProbability));
|
||||||
}
|
}
|
||||||
return ammoArray.draw(1)[0];
|
return ammoArray.draw(1)[0];
|
||||||
|
Loading…
Reference in New Issue
Block a user