Fix issues with incorrectly configured airdrops (!280)

- Don't try to add items to the airdrop if the filtered item list is empty
- If we somehow get into `findAndAddRandomPresetToLoot` with an empty list, don't try to output the id of undefined

Co-authored-by: DrakiaXYZ <565558+TheDgtl@users.noreply.github.com>
Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/280
Co-authored-by: DrakiaXYZ <drakiaxyz@noreply.dev.sp-tarkov.com>
Co-committed-by: DrakiaXYZ <drakiaxyz@noreply.dev.sp-tarkov.com>
This commit is contained in:
DrakiaXYZ 2024-04-08 17:39:08 +00:00 committed by chomp
parent f73802ec17
commit 2404e7a5ab

View File

@ -99,6 +99,8 @@ export class LootGenerator
&& options.itemTypeWhitelist.includes(x[1]._parent) && options.itemTypeWhitelist.includes(x[1]._parent)
); );
if (items.length > 0)
{
const randomisedItemCount = this.randomUtil.getInt(options.itemCount.min, options.itemCount.max); const randomisedItemCount = this.randomUtil.getInt(options.itemCount.min, options.itemCount.max);
for (let index = 0; index < randomisedItemCount; index++) for (let index = 0; index < randomisedItemCount; index++)
{ {
@ -107,6 +109,7 @@ export class LootGenerator
index--; index--;
} }
} }
}
const globalDefaultPresets = Object.values(this.presetHelper.getDefaultPresets()); const globalDefaultPresets = Object.values(this.presetHelper.getDefaultPresets());
const itemBlacklistArray = Array.from(itemBlacklist); const itemBlacklistArray = Array.from(itemBlacklist);
@ -122,16 +125,24 @@ export class LootGenerator
this.itemHelper.isOfBaseclass(preset._encyclopedia, BaseClasses.WEAPON) this.itemHelper.isOfBaseclass(preset._encyclopedia, BaseClasses.WEAPON)
); );
if (weaponDefaultPresets.length > 0)
{
for (let index = 0; index < randomisedWeaponPresetCount; index++) for (let index = 0; index < randomisedWeaponPresetCount; index++)
{ {
if ( if (
!this.findAndAddRandomPresetToLoot(weaponDefaultPresets, itemTypeCounts, itemBlacklistArray, result) !this.findAndAddRandomPresetToLoot(
weaponDefaultPresets,
itemTypeCounts,
itemBlacklistArray,
result,
)
) )
{ {
index--; index--;
} }
} }
} }
}
// Filter default presets to just armors and then filter again by protection level // Filter default presets to just armors and then filter again by protection level
const randomisedArmorPresetCount = this.randomUtil.getInt( const randomisedArmorPresetCount = this.randomUtil.getInt(
@ -146,6 +157,9 @@ export class LootGenerator
const levelFilteredArmorPresets = armorDefaultPresets.filter((armor) => const levelFilteredArmorPresets = armorDefaultPresets.filter((armor) =>
this.armorIsDesiredProtectionLevel(armor, options) this.armorIsDesiredProtectionLevel(armor, options)
); );
if (levelFilteredArmorPresets.length > 0)
{
for (let index = 0; index < randomisedArmorPresetCount; index++) for (let index = 0; index < randomisedArmorPresetCount; index++)
{ {
if ( if (
@ -161,6 +175,7 @@ export class LootGenerator
} }
} }
} }
}
return result; return result;
} }
@ -307,7 +322,7 @@ export class LootGenerator
const randomPreset = this.randomUtil.getArrayValue(globalDefaultPresets); const randomPreset = this.randomUtil.getArrayValue(globalDefaultPresets);
if (!randomPreset?._encyclopedia) if (!randomPreset?._encyclopedia)
{ {
this.logger.debug(`Airdrop - preset with id: ${randomPreset._id} lacks encyclopedia property, skipping`); this.logger.debug(`Airdrop - preset with id: ${randomPreset?._id} lacks encyclopedia property, skipping`);
return false; return false;
} }