WC: Fix error when too few artifacts are defined

Previously the lua could stop working when there were less than 9 artifacts defined in [world_conquest_data]
This commit is contained in:
gfgtdf 2023-10-17 00:34:25 +02:00 committed by GitHub
parent 8bbaba898d
commit d5b7972c6f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -8,9 +8,11 @@ function wc2_invest.add_items(side_num, num_items)
local items_left = stringx.split(side.variables["wc2.items_left"] or "")
local items_available = stringx.split(side.variables["wc2.items"] or "")
for j = 1, num_items do
local i = mathx.random(#items_left)
table.insert(items_available, items_left[i])
table.remove(items_left, i)
if #items_left > 0 then
local i = mathx.random(#items_left)
table.insert(items_available, items_left[i])
table.remove(items_left, i)
end
end
side.variables["wc2.items_left"] = table.concat(items_left, ",")