Fix issue with weapon mod generation flagging mod as incompatible even though it passes compatibility checks

Stop trying to fit a mod to a weapon after 8 blocked attempts
Created streamlined mod compatability checker function
This commit is contained in:
Dev 2024-01-29 22:41:08 +00:00
parent 58d620d424
commit f3ec237674
5 changed files with 18017 additions and 17830 deletions

View File

@ -31,7 +31,7 @@
"sectantWarrior": 10,
"gifter": 5,
"test": 30,
"exUsec": 30,
"exUsec": 25,
"arenaFighterEvent": 15,
"arenaFighter": 15,
"crazyAssaultEvent": 15,
@ -41,7 +41,7 @@
"followerBoarClose2": 10,
"followerKolontayAssault": 10,
"followerKolontaySecurity": 10,
"shooterBTR": 2,
"shooterBTR": 1,
"peacefullZryachiyEvent": 5,
"ravangeZryachiyEvent": 5,
"sectactPriestEvent": 10,
@ -1728,7 +1728,6 @@
"64abd93857958b4249003418": 10,
"64be79c487d1510151095552": 1,
"5648a7494bdc2d9d488b4583": 1,
"572b7adb24597762ae139821": 1,
"64be79e2bf8412471d0d9bcc": 1
},
"TacticalVest": {
@ -1743,6 +1742,7 @@
"5df8a42886f77412640e2e75": 60,
"5648a69d4bdc2ded0b8b457b": 55,
"5e4abc1f86f774069619fbaa": 1,
"572b7adb24597762ae139821": 1,
"6034d0230ca681766b6a0fb5": 1
},
"Headwear": {

View File

@ -71,12 +71,12 @@
"back_plate": 100,
"front_plate": 100,
"left_side_plate": 75,
"right_side_plate": 75,
"mod_equipment": 25,
"mod_equipment_000": 25,
"mod_equipment_001": 25,
"mod_equipment_002": 25,
"mod_nvg": 40
"mod_nvg": 40,
"right_side_plate": 75
},
"weaponMods": {
"mod_barrel": 100,
@ -3099,7 +3099,7 @@
"TacticalVest": {
"544a5caa4bdc2d1a388b4568": 38,
"5648a69d4bdc2ded0b8b457b": 38,
"572b7adb24597762ae139821": 38,
"572b7adb24597762ae139821": 5,
"5929a2a086f7744f4b234d43": 38,
"592c2d1a86f7746dbe2af32a": 38,
"59e7643b86f7742cbf2c109a": 38,
@ -3125,6 +3125,7 @@
"5e9db13186f7742f845ee9d3": 38,
"5f5f41f56760b4138443b352": 38,
"5fd4c60f875c30179f5d04c2": 15,
"6034d0230ca681766b6a0fb5": 2,
"603648ff5a45383c122086ac": 38,
"6040dd4ddcf9592f401632d2": 38,
"609e860ebd219504d8507525": 15,
@ -5404,9 +5405,6 @@
"5888996c24597754281f9419"
]
},
"638f1ff84822287cad04be9d": {
"mod_foregrip": ["5c7fc87d2e221644f31c0298", "5cda9bcfd7f00c0c0b53e900", "59f8a37386f7747af3328f06", "5a7dbfc1159bd40016548fde", "619386379fb0c665d5490dbe", "5c87ca002e221600114cb150", "588226d124597767ad33f787", "588226dd24597767ad33f789", "588226e62459776e3e094af7", "588226ef24597767af46e39c", "59fc48e086f77463b1118392", "5fce0cf655375d18a253eff0", "5cf4fb76d7f00c065703d3ac", "5b057b4f5acfc4771e1bd3e9", "5c791e872e2216001219c40a", "558032614bdc2de7118b4585", "58c157be86f77403c74b2bb6", "58c157c886f774032749fb06", "5f6340d3ca442212f4047eb2", "591af28e86f77414a27a9e1d", "5c1cd46f2e22164bef5cfedb", "5c1bc4812e22164bef5cfde7", "5c1bc5612e221602b5429350", "5c1bc5af2e221602b412949b", "5c1bc5fb2e221602b1779b32", "5c1bc7432e221602b412949d", "5c1bc7752e221602b1779b34", "64806bdd26c80811d408d37a", "64807a29e5ffe165600abc97", "648067db042be0705c0b3009", "65169d5b30425317755f8e25", "655df24fdf80b12750626d0a", "655dccfdbdcc6b5df71382b6"]
},
"588b56d02459771481110ae2": {
"mod_handguard": [
"638f1ff84822287cad04be9d",
@ -8128,6 +8126,11 @@
"5ae099925acfc4001a5fc7b3"
]
},
"5ae30db85acfc408fb139a05": {
"mod_handguard": [
"637f57a68d137b27f70c4968"
]
},
"5ae35b315acfc4001714e8b0": {
"mod_pistol_grip": [
"55d4b9964bdc2d1d4e8b456e",
@ -10855,14 +10858,6 @@
"5b7be47f5acfc400170e2dd2"
]
},
"647de824196bf69818044c93": {
"mod_handguard": ["647def638295ebcb5b02f05b"],
"mod_scope": ["57fd23e32459772d0805bcf1", "544909bb4bdc2d6f028b4577", "5d10b49bd7ad1a1a560708b0", "5c06595c0db834001a66af6c", "61605d88ffa6e502ac5e7eeb", "5c5952732e2216398b5abda2", "644a3df63b0b6f03e101e065"]
},
"638f2003bbd47aeb9e0ff637": {
"mod_foregrip": ["5c7fc87d2e221644f31c0298", "5cda9bcfd7f00c0c0b53e900", "59f8a37386f7747af3328f06", "5a7dbfc1159bd40016548fde", "619386379fb0c665d5490dbe", "5c87ca002e221600114cb150", "588226d124597767ad33f787", "588226dd24597767ad33f789", "588226e62459776e3e094af7", "588226ef24597767af46e39c", "59fc48e086f77463b1118392", "5fce0cf655375d18a253eff0", "5cf4fb76d7f00c065703d3ac", "5b057b4f5acfc4771e1bd3e9", "5c791e872e2216001219c40a", "558032614bdc2de7118b4585", "58c157be86f77403c74b2bb6", "58c157c886f774032749fb06", "5f6340d3ca442212f4047eb2", "591af28e86f77414a27a9e1d", "5c1cd46f2e22164bef5cfedb", "5c1bc4812e22164bef5cfde7", "5c1bc5612e221602b5429350", "5c1bc5af2e221602b412949b", "5c1bc5fb2e221602b1779b32", "5c1bc7432e221602b412949d", "5c1bc7752e221602b1779b34", "64806bdd26c80811d408d37a", "64807a29e5ffe165600abc97", "648067db042be0705c0b3009", "65169d5b30425317755f8e25", "655df24fdf80b12750626d0a", "655dccfdbdcc6b5df71382b6"],
"mod_tactical_003": ["5a800961159bd4315e3a1657", "57fd23e32459772d0805bcf1", "544909bb4bdc2d6f028b4577", "5c06595c0db834001a66af6c", "5cc9c20cd7f00c001336c65d", "5d2369418abbc306c62e0c80", "5b07dd285acfc4001754240d", "56def37dd2720bec348b456a", "5a7b483fe899ef0016170d15", "61605d88ffa6e502ac5e7eeb", "5a5f1ce64f39f90b401987bc", "560d657b4bdc2da74d8b4572", "5b3a337e5acfc4704b4a19a0", "5c5952732e2216398b5abda2", "57d17e212459775a1179a0f5", "626becf9582c3e319310b837", "6272370ee4013c5d7e31f418", "6272379924e29f06af4d5ecb", "644a3df63b0b6f03e101e065", "646f6322f43d0c5d62063715"]
},
"5c9a25172e2216000f20314e": {
"mod_handguard": [
"638f2003bbd47aeb9e0ff637"
@ -11572,9 +11567,6 @@
"5a7b483fe899ef0016170d15"
]
},
"637f589af5ef8c33840d36d3": {
"mod_foregrip": ["57cffb66245977632f391a99", "57cffcd624597763133760c5", "57cffcdd24597763f5110006"]
},
"5d00f63bd7ad1a59283b1c1e": {
"mod_handguard": [
"637f589af5ef8c33840d36d3",
@ -11618,10 +11610,6 @@
"5d120a28d7ad1a1c8962e295"
]
},
"637f57c532b66e7e320a6676": {
"mod_foregrip": ["5d123b7dd7ad1a004f01b262", "5d124c1ad7ad1a12227c53a7", "5d133067d7ad1a33013f95b4"],
"mod_tactical_003": ["5a800961159bd4315e3a1657", "57fd23e32459772d0805bcf1"]
},
"5d122e7bd7ad1a07102d6d7f": {
"mod_handguard": [
"637f57c532b66e7e320a6676"
@ -11926,11 +11914,6 @@
"5fc0fa957283c4046c58147e"
]
},
"5ae30db85acfc408fb139a05": {
"mod_handguard": [
"637f57a68d137b27f70c4968"
]
},
"5d4405f0a4b9361e6a4e6bd9": {
"mod_foregrip": [
"57cffb66245977632f391a99"
@ -16769,11 +16752,125 @@
"58c157c886f774032749fb06"
]
},
"637f57c532b66e7e320a6676": {
"mod_foregrip": [
"5d123b7dd7ad1a004f01b262",
"5d124c1ad7ad1a12227c53a7",
"5d133067d7ad1a33013f95b4"
],
"mod_tactical_003": [
"5a800961159bd4315e3a1657",
"57fd23e32459772d0805bcf1"
]
},
"637f589af5ef8c33840d36d3": {
"mod_foregrip": [
"57cffb66245977632f391a99",
"57cffcd624597763133760c5",
"57cffcdd24597763f5110006"
]
},
"6386300124a1dc425c00577a": {
"mod_stock": [
"5a0c59791526d8dba737bba7"
]
},
"638f1ff84822287cad04be9d": {
"mod_foregrip": [
"5c7fc87d2e221644f31c0298",
"5cda9bcfd7f00c0c0b53e900",
"59f8a37386f7747af3328f06",
"5a7dbfc1159bd40016548fde",
"619386379fb0c665d5490dbe",
"5c87ca002e221600114cb150",
"588226d124597767ad33f787",
"588226dd24597767ad33f789",
"588226e62459776e3e094af7",
"588226ef24597767af46e39c",
"59fc48e086f77463b1118392",
"5fce0cf655375d18a253eff0",
"5cf4fb76d7f00c065703d3ac",
"5b057b4f5acfc4771e1bd3e9",
"5c791e872e2216001219c40a",
"558032614bdc2de7118b4585",
"58c157be86f77403c74b2bb6",
"58c157c886f774032749fb06",
"5f6340d3ca442212f4047eb2",
"591af28e86f77414a27a9e1d",
"5c1cd46f2e22164bef5cfedb",
"5c1bc4812e22164bef5cfde7",
"5c1bc5612e221602b5429350",
"5c1bc5af2e221602b412949b",
"5c1bc5fb2e221602b1779b32",
"5c1bc7432e221602b412949d",
"5c1bc7752e221602b1779b34",
"64806bdd26c80811d408d37a",
"64807a29e5ffe165600abc97",
"648067db042be0705c0b3009",
"65169d5b30425317755f8e25",
"655df24fdf80b12750626d0a",
"655dccfdbdcc6b5df71382b6"
]
},
"638f2003bbd47aeb9e0ff637": {
"mod_foregrip": [
"5c7fc87d2e221644f31c0298",
"5cda9bcfd7f00c0c0b53e900",
"59f8a37386f7747af3328f06",
"5a7dbfc1159bd40016548fde",
"619386379fb0c665d5490dbe",
"5c87ca002e221600114cb150",
"588226d124597767ad33f787",
"588226dd24597767ad33f789",
"588226e62459776e3e094af7",
"588226ef24597767af46e39c",
"59fc48e086f77463b1118392",
"5fce0cf655375d18a253eff0",
"5cf4fb76d7f00c065703d3ac",
"5b057b4f5acfc4771e1bd3e9",
"5c791e872e2216001219c40a",
"558032614bdc2de7118b4585",
"58c157be86f77403c74b2bb6",
"58c157c886f774032749fb06",
"5f6340d3ca442212f4047eb2",
"591af28e86f77414a27a9e1d",
"5c1cd46f2e22164bef5cfedb",
"5c1bc4812e22164bef5cfde7",
"5c1bc5612e221602b5429350",
"5c1bc5af2e221602b412949b",
"5c1bc5fb2e221602b1779b32",
"5c1bc7432e221602b412949d",
"5c1bc7752e221602b1779b34",
"64806bdd26c80811d408d37a",
"64807a29e5ffe165600abc97",
"648067db042be0705c0b3009",
"65169d5b30425317755f8e25",
"655df24fdf80b12750626d0a",
"655dccfdbdcc6b5df71382b6"
],
"mod_tactical_003": [
"5a800961159bd4315e3a1657",
"57fd23e32459772d0805bcf1",
"544909bb4bdc2d6f028b4577",
"5c06595c0db834001a66af6c",
"5cc9c20cd7f00c001336c65d",
"5d2369418abbc306c62e0c80",
"5b07dd285acfc4001754240d",
"56def37dd2720bec348b456a",
"5a7b483fe899ef0016170d15",
"61605d88ffa6e502ac5e7eeb",
"5a5f1ce64f39f90b401987bc",
"560d657b4bdc2da74d8b4572",
"5b3a337e5acfc4704b4a19a0",
"5c5952732e2216398b5abda2",
"57d17e212459775a1179a0f5",
"626becf9582c3e319310b837",
"6272370ee4013c5d7e31f418",
"6272379924e29f06af4d5ecb",
"644a3df63b0b6f03e101e065",
"646f6322f43d0c5d62063715"
]
},
"639343fce101f4caa40a4ef3": {
"Back_plate": [
"656f9d5900d62bcd2e02407c",
@ -17049,6 +17146,20 @@
"64748d02d1c009260702b526"
]
},
"647de824196bf69818044c93": {
"mod_handguard": [
"647def638295ebcb5b02f05b"
],
"mod_scope": [
"57fd23e32459772d0805bcf1",
"544909bb4bdc2d6f028b4577",
"5d10b49bd7ad1a1a560708b0",
"5c06595c0db834001a66af6c",
"61605d88ffa6e502ac5e7eeb",
"5c5952732e2216398b5abda2",
"644a3df63b0b6f03e101e065"
]
},
"6491c6f6ef312a876705191b": {
"mod_foregrip": [
"5c1cd46f2e22164bef5cfedb"

View File

@ -3142,7 +3142,9 @@
"64a536392d2c4e6e970f4121": 25,
"64a5366719bab53bd203bf33": 25,
"64be7095047e826eae02b0c1": 5,
"64be7110bf597ba84a0a41ea": 15
"64be7110bf597ba84a0a41ea": 15,
"572b7adb24597762ae139821": 5,
"6034d0230ca681766b6a0fb5": 2
}
},
"items": {
@ -9627,21 +9629,7 @@
"5c07a8770db8340023300450",
"63f5ed14534b2c3d5479a677"
],
"mod_stock": [
"5a33ca0fc4a282000d72292f",
"5c0faeddd174af02a962601f",
"5649be884bdc2d79388b4577",
"5d120a10d7ad1a4e1026ba85",
"5b0800175acfc400153aebd4",
"5947e98b86f774778f1448bc",
"5947eab886f77475961d96c5",
"602e3f1254072b51b239f713",
"5c793fb92e221644f31bfb64",
"5c793fc42e221600114ca25d",
"591aef7986f774139d495f03",
"591af10186f774139d495f0e",
"627254cc9c563e6e442c398f"
],
"mod_stock": ["5a33ca0fc4a282000d72292f", "5c0faeddd174af02a962601f", "5649be884bdc2d79388b4577", "5d120a10d7ad1a4e1026ba85", "5b0800175acfc400153aebd4", "5947e98b86f774778f1448bc", "5947eab886f77475961d96c5", "602e3f1254072b51b239f713", "5c793fb92e221644f31bfb64", "5c793fc42e221600114ca25d", "591aef7986f774139d495f03", "591af10186f774139d495f0e", "627254cc9c563e6e442c398f", "638de3603a1a4031d8260b8c"],
"patron_in_weapon": [
"59e6920f86f77411d82aa167",
"59e6927d86f77411da468256",

View File

@ -772,9 +772,8 @@ export class BotEquipmentModGenerator
}
// Pick random mod that's compatible
const chosenModResult = this.chooseRandomCompatibleModTpl(modPool, parentSlot, modSpawnResult, weapon, modSlot);
if (chosenModResult.slotBlocked)
const chosenModResult = this.pickWeaponModTplForSlotFromPool(modPool, parentSlot, modSpawnResult, weapon, modSlot);
if (chosenModResult.slotBlocked && !parentSlot._required)
{
// Don't bother trying to fit mod, slot is completely blocked
return null;
@ -817,7 +816,7 @@ export class BotEquipmentModGenerator
return this.itemHelper.getItem(chosenModResult.chosenTpl);
}
protected chooseRandomCompatibleModTpl(
protected pickWeaponModTplForSlotFromPool(
modPool: string[],
parentSlot: Slot,
modSpawnResult: ModSpawn,
@ -833,6 +832,7 @@ export class BotEquipmentModGenerator
};
const modParentFilterList = parentSlot._props.filters[0].Filter;
let blockedAttemptCount = 0;
while (exhaustableModPool.hasValues())
{
chosenTpl = exhaustableModPool.getRandomValue();
@ -852,7 +852,7 @@ export class BotEquipmentModGenerator
continue;
}
chosenModResult = this.botGeneratorHelper.isItemIncompatibleWithCurrentItems(
chosenModResult = this.botGeneratorHelper.isWeaponModIncompatibleWithCurrentMods(
weapon,
chosenTpl,
modSlotname,
@ -860,13 +860,25 @@ export class BotEquipmentModGenerator
if (chosenModResult.slotBlocked)
{
// Give max of 8 attempts of picking an item ifs blocked by another item
if (blockedAttemptCount > 8)
{
this.logger.warning(`Attempted to find mod for slot: ${parentSlot._name} on weapon: ${weapon[0]._tpl} and blocked 8 times`);
blockedAttemptCount = 0;
break;
}
blockedAttemptCount++;
continue;
}
// Some mod combos will never work, make sure its not happened
if (!chosenModResult.incompatible && !this.weaponModComboIsIncompatible(weapon, chosenTpl))
{
chosenModResult.found = true;
chosenModResult.incompatible = false;
chosenModResult.chosenTpl = chosenTpl;
break;

View File

@ -276,6 +276,82 @@ export class BotGeneratorHelper
return { Durability: currentDurability, MaxDurability: maxDurability };
}
public isWeaponModIncompatibleWithCurrentMods(
itemsEquipped: Item[],
tplToCheck: string,
modSlot: string,
): IChooseRandomCompatibleModResult
{
// TODO: Can probably be optimized to cache itemTemplates as items are added to inventory
const equippedItemsDb = itemsEquipped.map((item) => this.databaseServer.getTables().templates.items[item._tpl]);
const itemToEquipDb = this.itemHelper.getItem(tplToCheck);
const itemToEquip = itemToEquipDb[1];
if (!itemToEquipDb[0])
{
this.logger.warning(
this.localisationService.getText("bot-invalid_item_compatibility_check", {
itemTpl: tplToCheck,
slot: modSlot,
}),
);
return {
incompatible: true,
found: false,
reason: `item: ${tplToCheck} does not exist in the database`
};
}
// No props property
if (!itemToEquip._props)
{
this.logger.warning(
this.localisationService.getText("bot-compatibility_check_missing_props", {
id: itemToEquip._id,
name: itemToEquip._name,
slot: modSlot,
}),
);
return {
incompatible: true,
found: false,
reason: `item: ${tplToCheck} does not have a _props field`
};
}
// Check if any of the current weapon mod templates have the incoming item defined as incompatible
const blockingItem = equippedItemsDb.find((x) => x._props.ConflictingItems?.includes(tplToCheck));
if (blockingItem)
{
return {
incompatible: true,
found: false,
reason:
`Cannot add: ${tplToCheck} ${itemToEquip._name} to slot: ${modSlot}. Blocked by: ${blockingItem._id} ${blockingItem._name}`,
slotBlocked: true,
};
}
// Check inverse to above, if the incoming item has any existing mods in its conflicting items array
const blockingModItem = itemsEquipped.find((item) => itemToEquip._props.ConflictingItems?.includes(item._tpl));
if (blockingModItem)
{
return {
incompatible: true,
found: false,
reason:
` Cannot add: ${tplToCheck} to slot: ${modSlot}. Would block existing item: ${blockingModItem._tpl} in slot: ${blockingModItem.slotId}`,
};
}
return {
incompatible: false,
reason: ""
};
}
/**
* Can item be added to another item without conflict
* @param itemsEquipped Items to check compatibilities with