Fix some weapons not having their chamber loaded with a cartridge during weapon generation
weapons: weapon_izhmeh_mr43_sawed_off_12g weapon_izhmash_mp18_multi `addCartridgeToChamber` assumed the only id a chamber could have was `patron_in_weapon` this is wrong, it can also have `patron_in_weapon_000` and `patron_in_weapon_001` it also assumed weapons only have one chamber Some weapons can have multiple chambers Some weapons can have 1 chamber but have the id `patron_in_weapon_000` not `patron_in_weapon`
This commit is contained in:
parent
231a52f8be
commit
c801dba0b7
@ -206,14 +206,15 @@ export class BotWeaponGenerator
|
|||||||
this.fillExistingMagazines(weaponWithModsArray, magazine, ammoTpl);
|
this.fillExistingMagazines(weaponWithModsArray, magazine, ammoTpl);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add cartridge to gun chamber if weapon has slot for it
|
// Add cartridge(s) to gun chamber(s)
|
||||||
if (
|
if (
|
||||||
weaponItemTemplate._props.Chambers?.length === 1
|
weaponItemTemplate._props.Chambers?.length > 0
|
||||||
&& weaponItemTemplate._props.Chambers[0]?._name === "patron_in_weapon"
|
|
||||||
&& weaponItemTemplate._props.Chambers[0]?._props?.filters[0]?.Filter?.includes(ammoTpl)
|
&& weaponItemTemplate._props.Chambers[0]?._props?.filters[0]?.Filter?.includes(ammoTpl)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
this.addCartridgeToChamber(weaponWithModsArray, ammoTpl, "patron_in_weapon");
|
// Guns have variety of possible Chamber ids, patron_in_weapon/patron_in_weapon_000/patron_in_weapon_001
|
||||||
|
const chamberSlotNames = weaponItemTemplate._props.Chambers.map(x => x._name);
|
||||||
|
this.addCartridgeToChamber(weaponWithModsArray, ammoTpl, chamberSlotNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fill UBGL if found
|
// Fill UBGL if found
|
||||||
@ -236,31 +237,34 @@ export class BotWeaponGenerator
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Insert a cartridge into a weapon
|
* Insert a cartridge(s) into a weapon
|
||||||
|
* Handles all chambers - patron_in_weapon, patron_in_weapon_000 etc
|
||||||
* @param weaponWithModsArray Weapon and mods
|
* @param weaponWithModsArray Weapon and mods
|
||||||
* @param ammoTpl Cartridge to add to weapon
|
* @param ammoTpl Cartridge to add to weapon
|
||||||
* @param desiredSlotId name of slot, e.g. patron_in_weapon
|
* @param chamberSlotIds name of slots to create or add ammo to
|
||||||
*/
|
*/
|
||||||
protected addCartridgeToChamber(weaponWithModsArray: Item[], ammoTpl: string, desiredSlotId: string): void
|
protected addCartridgeToChamber(weaponWithModsArray: Item[], ammoTpl: string, chamberSlotIds: string[]): void
|
||||||
{
|
{
|
||||||
// Check for slot first
|
for (const slotId of chamberSlotIds)
|
||||||
const existingItemWithSlot = weaponWithModsArray.find((x) => x.slotId === desiredSlotId);
|
|
||||||
if (!existingItemWithSlot)
|
|
||||||
{
|
{
|
||||||
// Not found, add fresh
|
const existingItemWithSlot = weaponWithModsArray.find((x) => x.slotId === slotId);
|
||||||
weaponWithModsArray.push({
|
if (!existingItemWithSlot)
|
||||||
_id: this.hashUtil.generate(),
|
{
|
||||||
_tpl: ammoTpl,
|
// Not found, add new slot to weapon
|
||||||
parentId: weaponWithModsArray[0]._id,
|
weaponWithModsArray.push({
|
||||||
slotId: desiredSlotId,
|
_id: this.hashUtil.generate(),
|
||||||
upd: { StackObjectsCount: 1 },
|
_tpl: ammoTpl,
|
||||||
});
|
parentId: weaponWithModsArray[0]._id,
|
||||||
}
|
slotId: slotId,
|
||||||
else
|
upd: { StackObjectsCount: 1 },
|
||||||
{
|
});
|
||||||
// Already exists, update values
|
}
|
||||||
existingItemWithSlot.upd = { StackObjectsCount: 1 };
|
else
|
||||||
existingItemWithSlot._tpl = ammoTpl;
|
{
|
||||||
|
// Already exists, update values
|
||||||
|
existingItemWithSlot._tpl = ammoTpl;
|
||||||
|
existingItemWithSlot.upd = { StackObjectsCount: 1 };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -613,7 +617,7 @@ export class BotWeaponGenerator
|
|||||||
{
|
{
|
||||||
const possibleAmmo = this.weightedRandomHelper.getWeightedValue<string>(compatibleCartridges);
|
const possibleAmmo = this.weightedRandomHelper.getWeightedValue<string>(compatibleCartridges);
|
||||||
|
|
||||||
// Check compatibility
|
// Weapon has chamber but does not support cartridge
|
||||||
if (weaponTemplate._props.Chambers[0]
|
if (weaponTemplate._props.Chambers[0]
|
||||||
&& !weaponTemplate._props.Chambers[0]._props.filters[0].Filter.includes(possibleAmmo)
|
&& !weaponTemplate._props.Chambers[0]._props.filters[0].Filter.includes(possibleAmmo)
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user