Ajoute remplissage des coffres 30 minutes après ouverture

et modifie les items générés par ceux de nalc_trm
This commit is contained in:
Sys Quatre 2019-12-27 01:22:46 +01:00
parent 63572c5c23
commit 1eb0bc363e
3 changed files with 49 additions and 5 deletions

View File

@ -67,13 +67,16 @@ end
function tsm_pyramids.fill_chest(pos, stype, flood_sand, treasure_chance)
local sand = "default:sand"
local n = minetest.get_node(pos)
local meta = minetest.get_meta(pos)
if not treasure_chance then
treasure_chance = 100
end
if stype == "desert_sandstone" or stype == "desert_stone" then
if meta:get_string("tsm_pyramids:stype") == "desert_sandstone" or
meta:get_string("tsm_pyramids:stype") == "desert_stone" or
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)
@ -81,13 +84,13 @@ function tsm_pyramids.fill_chest(pos, stype, flood_sand, treasure_chance)
inv:set_size("main", 8*4)
local stacks = {}
-- Fill with sand in sand-flooded pyramids
if flood_sand then
if meta:get_int("tsm_pyramids:sanded") == 1 or flood_sand then
table.insert(stacks, {name=sand, count = math.random(1,32)})
end
-- Add treasures
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"})
stacks = treasurer.select_random_treasures(3,1,5,{"armes", "armures", "precieux", "nourriture"})
else
for i=0,2,1 do
local stuff = chest_stuff.normal[math.random(1,#chest_stuff.normal)]

View File

@ -97,3 +97,30 @@ register_trap_stone("desert_trap",
"default_desert_sandstone_brick.png",
{ items = { { items = { "default:desert_sand" }, rarity = 1 }, { items = { "default:desert_sand" }, rarity = 2 }, } })
local chest = minetest.registered_nodes["default:chest"]
local def_on_rightclick = chest.on_rightclick
local def_on_timer = chest.on_timer
minetest.override_item(
"default:chest",
{
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
if minetest.get_meta(pos):get_string("tsm_pyramids:stype") ~= "" then
local timer = minetest.get_node_timer(pos)
if not timer:is_started() then
timer:start(1800) -- remplissages des coffres toutes les 30 minutes
end
end
return def_on_rightclick(pos, node, clicker, itemstack, pointed_thing)
end,
on_timer = function(pos, elapsed)
if minetest.get_meta(pos):get_string("tsm_pyramids:stype") ~= "" then
minetest.log("action", "[DEBUG] chest refilling")
tsm_pyramids.fill_chest(pos)
return false
else
if def_on_timer then return def_on_timer(pos, elapsed) else return false end
end
end,
})
minetest.register_alias("tsm_pyramids:chest", "default:chest")

View File

@ -960,6 +960,7 @@ function tsm_pyramids.make_room(pos, stype, room_id, rotations)
end
tries = tries + 1
end
local sanded = room.flood_sand ~= false and stype ~= "desert_stone" and math.random(1,8) == 1
local chests = {}
local column_style
if stype == "desert_stone" then
@ -1002,6 +1003,13 @@ function tsm_pyramids.make_room(pos, stype, room_id, rotations)
local nn = replace(n_str, iy, code_table, deco, column_style)
minetest.set_node(cpos, {name=nn, param2=p2})
if nn == "default:chest" then
local meta = minetest.get_meta(cpos)
meta:set_string("tsm_pyramids:stype", stype)
if sanded then
meta:set_int("tsm_pyramids:sanded", 1)
else
meta:set_int("tsm_pyramids:sanded", 0)
end
table.insert(chests, cpos)
end
end
@ -1045,6 +1053,13 @@ function tsm_pyramids.make_room(pos, stype, room_id, rotations)
local nn = code_table[n_str]
minetest.set_node(cpos, {name=nn, param2=p2})
if nn == "default:chest" then
local meta = minetest.get_meta(cpos)
meta:set_string("tsm_pyramids:stype", stype)
if sanded then
meta:set_int("tsm_pyramids:sanded", 1)
else
meta:set_int("tsm_pyramids:sanded", 0)
end
table.insert(chests, cpos)
end
end
@ -1053,7 +1068,6 @@ function tsm_pyramids.make_room(pos, stype, room_id, rotations)
else
minetest.log("error", "Invalid pyramid room style! room type ID="..r)
end
local sanded = room.flood_sand ~= false and stype ~= "desert_stone" and math.random(1,8) == 1
if #chests > 0 then
-- Make at least 8 attempts to fill chests
local filled = 0