Fix issue with PMCs generating with one cartridge in magazine + no cartridge in weapon chamber

This commit is contained in:
Dev 2023-07-24 21:24:55 +01:00
parent 085bf7fcb5
commit 777ca0c8ef
3 changed files with 74 additions and 16 deletions

View File

@ -11149,7 +11149,9 @@
},
"5f36a0e5fbf956000b716b65": {
"mod_barrel": [
"5f3e7801153b8571434a924c"
"5f3e7801153b8571434a924c",
"5e81c519cb2b95385c177551",
"5f3e77f59103d430b93f94c1"
],
"mod_catch": [
"5f3e777688ca2d00ad199d25"
@ -11158,7 +11160,9 @@
"5f3e76d86cda304dcc634054"
],
"mod_magazine": [
"5f3e77b26cda304dcc634057"
"5f3e77b26cda304dcc634057",
"5e81c4ca763d9f754677befa",
"5ef3448ab37dfd6af863525c"
],
"mod_mount_000": [
"5d2369418abbc306c62e0c80"
@ -11167,12 +11171,18 @@
"5f3e778efcd9b651187d7201"
],
"mod_reciever": [
"5f3e7823ddc4f03b010e2045"
"5f3e7823ddc4f03b010e2045",
"5e81edc13397a21db957f6a1"
],
"mod_trigger": [
"5f3e772a670e2a7b01739a52"
]
},
"5f3e77f59103d430b93f94c1": {
"mod_muzzle":[
"5fc4b97bab884124df0cd5e3"
]
},
"5f3e7823ddc4f03b010e2045": {
"mod_sight_front": [
"5f3e78a7fbf956000b716b8e"

View File

@ -11178,7 +11178,9 @@
},
"5f36a0e5fbf956000b716b65": {
"mod_barrel": [
"5f3e7801153b8571434a924c"
"5f3e7801153b8571434a924c",
"5e81c519cb2b95385c177551",
"5f3e77f59103d430b93f94c1"
],
"mod_catch": [
"5f3e777688ca2d00ad199d25"
@ -11187,7 +11189,9 @@
"5f3e76d86cda304dcc634054"
],
"mod_magazine": [
"5f3e77b26cda304dcc634057"
"5f3e77b26cda304dcc634057",
"5e81c4ca763d9f754677befa",
"5ef3448ab37dfd6af863525c"
],
"mod_mount_000": [
"5d2369418abbc306c62e0c80"
@ -11196,12 +11200,18 @@
"5f3e778efcd9b651187d7201"
],
"mod_reciever": [
"5f3e7823ddc4f03b010e2045"
"5f3e7823ddc4f03b010e2045",
"5e81edc13397a21db957f6a1"
],
"mod_trigger": [
"5f3e772a670e2a7b01739a52"
]
},
"5f3e77f59103d430b93f94c1": {
"mod_muzzle": [
"5fc4b97bab884124df0cd5e3"
]
},
"5f3e7823ddc4f03b010e2045": {
"mod_sight_front": [
"5f3e78a7fbf956000b716b8e"

View File

@ -139,6 +139,14 @@ export class BotWeaponGenerator
this.fillExistingMagazines(weaponWithModsArray, magazine, ammoTpl);
}
// Add cartridge to gun chamber if weapon has slot for it
if (weaponItemTemplate._props.Chambers?.length === 1
&& weaponItemTemplate._props.Chambers[0]?._name === "patron_in_weapon"
&& weaponItemTemplate._props.Chambers[0]?._props?.filters[0]?.Filter?.includes(ammoTpl))
{
this.addCartridgeToChamber(weaponWithModsArray, ammoTpl, "patron_in_weapon");
}
// Fill UBGL if found
const ubglMod = weaponWithModsArray.find(x => x.slotId === "mod_launcher");
let ubglAmmoTpl: string = undefined;
@ -158,6 +166,37 @@ export class BotWeaponGenerator
};
}
/**
* Insert a cartridge into a weapon
* @param weaponWithModsArray Weapon and mods
* @param ammoTpl Cartridge to add to weapon
* @param desiredSlotId name of slot, e.g. patron_in_weapon
*/
protected addCartridgeToChamber(weaponWithModsArray: Item[], ammoTpl: string, desiredSlotId: string): void
{
// Check for slot first
const existingItemWithSlot = weaponWithModsArray.find(x => x.slotId === desiredSlotId);
if (!existingItemWithSlot)
{
// Not found, add fresh
weaponWithModsArray.push({
_id: this.hashUtil.generate(),
_tpl: ammoTpl,
parentId: weaponWithModsArray[0]._id,
slotId: desiredSlotId,
upd: {StackObjectsCount: 1}
});
}
else
{
// ALready exists, update values
existingItemWithSlot.upd = {
StackObjectsCount: 1
};
existingItemWithSlot._tpl = ammoTpl;
}
}
/**
* Create array with weapon base as only element and
* add additional properties based on weapon type
@ -281,10 +320,9 @@ export class BotWeaponGenerator
*/
public addExtraMagazinesToInventory(generatedWeaponResult: GenerateWeaponResult, magCounts: MinMax, inventory: PmcInventory, botRole: string): void
{
const weaponMods = generatedWeaponResult.weapon;
const weaponAndMods = generatedWeaponResult.weapon;
const weaponTemplate = generatedWeaponResult.weaponTemplate;
const ammoTpl = generatedWeaponResult.chosenAmmoTpl;
const magazineTpl = this.getMagazineTplFromWeaponTemplate(weaponMods, weaponTemplate, botRole);
const magazineTpl = this.getMagazineTplFromWeaponTemplate(weaponAndMods, weaponTemplate, botRole);
const magTemplate = this.itemHelper.getItem(magazineTpl)[1];
if (!magTemplate)
@ -294,10 +332,10 @@ export class BotWeaponGenerator
return;
}
const ammoTemplate = this.itemHelper.getItem(ammoTpl)[1];
const ammoTemplate = this.itemHelper.getItem(generatedWeaponResult.chosenAmmoTpl)[1];
if (!ammoTemplate)
{
this.logger.error(this.localisationService.getText("bot-unable_to_find_ammo_item", ammoTpl));
this.logger.error(this.localisationService.getText("bot-unable_to_find_ammo_item", generatedWeaponResult.chosenAmmoTpl));
return;
}
@ -305,14 +343,14 @@ export class BotWeaponGenerator
// Has an UBGL
if (generatedWeaponResult.chosenUbglAmmoTpl)
{
this.addUbglGrenadesToBotInventory(weaponMods, generatedWeaponResult, inventory);
this.addUbglGrenadesToBotInventory(weaponAndMods, generatedWeaponResult, inventory);
}
const inventoryMagGenModel = new InventoryMagGen(magCounts, magTemplate, weaponTemplate, ammoTemplate, inventory);
this.inventoryMagGenComponents.find(v => v.canHandleInventoryMagGen(inventoryMagGenModel)).process(inventoryMagGenModel);
// Add x stacks of bullets to SecuredContainer (bots use a magic mag packing skill to reload instantly)
this.addAmmoToSecureContainer(this.botConfig.secureContainerAmmoStackCount, ammoTpl, 999, inventory);
this.addAmmoToSecureContainer(this.botConfig.secureContainerAmmoStackCount, generatedWeaponResult.chosenAmmoTpl, 999, inventory);
}
/**
@ -473,7 +511,7 @@ export class BotWeaponGenerator
return;
}
// Magazine, usually
const parentItem = this.itemHelper.getItem(magazineTemplate._parent)[1];
// the revolver shotgun uses a magazine with chambers, not cartridges ("camora_xxx")
@ -520,8 +558,8 @@ export class BotWeaponGenerator
const magazineCartridgeChildItem = weaponWithMods.find(m => m.parentId === magazine._id && m.slotId === "cartridges");
if (magazineCartridgeChildItem)
{
// Easier to delete and create below instaed of modifying existing item
weaponWithMods = weaponWithMods.slice(weaponWithMods.indexOf(magazineCartridgeChildItem), 1);
// Delete the existing cartridge object and create fresh below
weaponWithMods.splice(weaponWithMods.indexOf(magazineCartridgeChildItem), 1);
}
// Create array with just magazine