Fix potential crash when few loot items are registered
authorsfan5 <sfan5@live.de>
Tue, 16 Jul 2019 21:18:27 +0000 (23:18 +0200)
committersfan5 <sfan5@live.de>
Tue, 16 Jul 2019 21:29:29 +0000 (23:29 +0200)
mods/dungeon_loot/mapgen.lua

index 4a19f3cf17f0423c73e970858d9a9782f854cd52..624e9a855e9539a8fb7149cd8513220c79820e09 100644 (file)
@@ -76,8 +76,8 @@ local function populate_chest(pos, rand, dungeontype)
 
        local item_list = dungeon_loot._internal_get_loot(pos.y, dungeontype)
        -- take random (partial) sample of all possible items
-       assert(#item_list >= dungeon_loot.STACKS_PER_CHEST_MAX)
-       item_list = random_sample(rand, item_list, dungeon_loot.STACKS_PER_CHEST_MAX)
+       local sample_n = math.min(#item_list, dungeon_loot.STACKS_PER_CHEST_MAX)
+       item_list = random_sample(rand, item_list, sample_n)
 
        -- apply chances / randomized amounts and collect resulting items
        local items = {}