forked from mtcontrib/tsm_pyramids
Guarantee 1 chest with treasures
This commit is contained in:
parent
0efa3dd75e
commit
9d5dace4fb
10
init.lua
10
init.lua
|
@ -40,12 +40,16 @@ else
|
|||
table.insert(chest_stuff, {name="farming:apple", max = 3})
|
||||
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"
|
||||
if not treasure_chance then
|
||||
treasure_chance = 100
|
||||
end
|
||||
if stype == "desert_sandstone" or stype == "desert_stone" then
|
||||
sand = "default:desert_sand"
|
||||
end
|
||||
local n = minetest.get_node(pos)
|
||||
local treasure_added = false
|
||||
if n and n.name and n.name == "default:chest" then
|
||||
local meta = minetest.get_meta(pos)
|
||||
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)})
|
||||
end
|
||||
-- Add treasures
|
||||
if math.random(1,10) >= 7 then
|
||||
if math.random(1,100) <= treasure_chance then
|
||||
if minetest.get_modpath("treasurer") ~= nil then
|
||||
stacks = treasurer.select_random_treasures(3,7,9,{"minetool", "food", "crafting_component"})
|
||||
else
|
||||
for i=0,2,1 do
|
||||
local stuff = chest_stuff[math.random(1,#chest_stuff)]
|
||||
table.insert(stacks, {name=stuff.name, count = math.random(1,stuff.max)})
|
||||
treasure_added = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -72,6 +77,7 @@ function tsm_pyramids.fill_chest(pos, stype, flood_sand)
|
|||
end
|
||||
end
|
||||
end
|
||||
return treasure_added
|
||||
end
|
||||
|
||||
local function add_spawner(pos, mummy_offset)
|
||||
|
|
10
room.lua
10
room.lua
|
@ -1054,12 +1054,20 @@ function tsm_pyramids.make_room(pos, stype, room_id, rotations)
|
|||
if #chests > 0 then
|
||||
-- Make at least 8 attempts to fill chests
|
||||
local filled = 0
|
||||
local chests_with_treasure = 0
|
||||
while filled < 8 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
|
||||
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
|
||||
if room.traps and math.random(1,4) then
|
||||
tsm_pyramids.make_traps(pos, stype, rotations, layout)
|
||||
|
|
Loading…
Reference in New Issue
Block a user