Fix potential crash when few loot items are registered

This commit is contained in:
sfan5 2019-07-16 23:18:27 +02:00
parent c3403936d3
commit 773011fd85

View File

@ -76,8 +76,8 @@ local function populate_chest(pos, rand, dungeontype)
local item_list = dungeon_loot._internal_get_loot(pos.y, dungeontype) local item_list = dungeon_loot._internal_get_loot(pos.y, dungeontype)
-- take random (partial) sample of all possible items -- take random (partial) sample of all possible items
assert(#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, dungeon_loot.STACKS_PER_CHEST_MAX) item_list = random_sample(rand, item_list, sample_n)
-- apply chances / randomized amounts and collect resulting items -- apply chances / randomized amounts and collect resulting items
local items = {} local items = {}