Guarantee 1 chest with treasures

This commit is contained in:
Wuzzy 2019-08-25 12:37:36 +02:00
parent 0efa3dd75e
commit 9d5dace4fb
2 changed files with 17 additions and 3 deletions

View File

@ -40,12 +40,16 @@ else
table.insert(chest_stuff, {name="farming:apple", max = 3}) table.insert(chest_stuff, {name="farming:apple", max = 3})
end end
function tsm_pyramids.fill_chest(pos, stype, flood_sand) function tsm_pyramids.fill_chest(pos, stype, flood_sand, treasure_chance)
local sand = "default:sand" local sand = "default:sand"
if not treasure_chance then
treasure_chance = 100
end
if stype == "desert_sandstone" or stype == "desert_stone" then if stype == "desert_sandstone" or stype == "desert_stone" then
sand = "default:desert_sand" sand = "default:desert_sand"
end end
local n = minetest.get_node(pos) local n = minetest.get_node(pos)
local treasure_added = false
if n and n.name and n.name == "default:chest" then if n and n.name and n.name == "default:chest" then
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
@ -56,13 +60,14 @@ function tsm_pyramids.fill_chest(pos, stype, flood_sand)
table.insert(stacks, {name=sand, count = math.random(1,32)}) table.insert(stacks, {name=sand, count = math.random(1,32)})
end end
-- Add treasures -- Add treasures
if math.random(1,10) >= 7 then if math.random(1,100) <= treasure_chance then
if minetest.get_modpath("treasurer") ~= nil then if minetest.get_modpath("treasurer") ~= nil then
stacks = treasurer.select_random_treasures(3,7,9,{"minetool", "food", "crafting_component"}) stacks = treasurer.select_random_treasures(3,7,9,{"minetool", "food", "crafting_component"})
else else
for i=0,2,1 do for i=0,2,1 do
local stuff = chest_stuff[math.random(1,#chest_stuff)] local stuff = chest_stuff[math.random(1,#chest_stuff)]
table.insert(stacks, {name=stuff.name, count = math.random(1,stuff.max)}) table.insert(stacks, {name=stuff.name, count = math.random(1,stuff.max)})
treasure_added = true
end end
end end
end end
@ -72,6 +77,7 @@ function tsm_pyramids.fill_chest(pos, stype, flood_sand)
end end
end end
end end
return treasure_added
end end
local function add_spawner(pos, mummy_offset) local function add_spawner(pos, mummy_offset)

View File

@ -1054,12 +1054,20 @@ function tsm_pyramids.make_room(pos, stype, room_id, rotations)
if #chests > 0 then if #chests > 0 then
-- Make at least 8 attempts to fill chests -- Make at least 8 attempts to fill chests
local filled = 0 local filled = 0
local chests_with_treasure = 0
while filled < 8 do while filled < 8 do
for c=1, #chests do for c=1, #chests do
tsm_pyramids.fill_chest(chests[c], stype, sanded) local has_treasure = tsm_pyramids.fill_chest(chests[c], stype, sanded, 30)
if has_treasure then
chests_with_treasure = chests_with_treasure + 1
end
filled = filled + 1 filled = filled + 1
end end
end end
-- If no chests were filled with treasure so far, fill a random chest guaranteed
if chests_with_treasure == 0 then
tsm_pyramids.fill_chests(chests[math.random(1, #chests)], stype, sanded, 100)
end
end end
if room.traps and math.random(1,4) then if room.traps and math.random(1,4) then
tsm_pyramids.make_traps(pos, stype, rotations, layout) tsm_pyramids.make_traps(pos, stype, rotations, layout)