Ajout de la régénération des items toutes les 30 minutes

- Les coffres deviennent indestructibles
- Ajout d'un timer de 30 minutes pour le régénération des items
This commit is contained in:
sys4-fr 2018-12-23 13:01:43 +01:00
parent 99349cc616
commit 7b281bec47
3 changed files with 152 additions and 99 deletions

199
init.lua
View File

@ -1,4 +1,5 @@
pyramids = {}
pyramids.max_time = 60 * 30
local random = math.random
dofile(minetest.get_modpath("tsm_pyramids").."/mummy.lua")
@ -17,31 +18,29 @@ local chest_stuff = {
}
function pyramids.fill_chest(pos)
minetest.after(2, function()
local n = minetest.get_node(pos)
if n and n.name and n.name == "default:chest" then
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
inv:set_size("main", 8*4)
if random(1,10) < 7 then return end
local stacks = {}
if minetest.get_modpath("treasurer") ~= nil then
stacks = treasurer.select_random_treasures(3,1,5,{"armes", "armures", "precieux"})
else
for i=0,2,1 do
local stuff = chest_stuff[random(1,#chest_stuff)]
if stuff.name == "farming:bread" and not minetest.get_modpath("farming") then stuff = chest_stuff[1] end
table.insert(stacks, {name=stuff.name, count = random(1,stuff.max)})
end
local n = minetest.get_node(pos)
if n and n.name and n.name == "tsm_pyramids:chest" then
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
inv:set_size("main", 8*4)
inv:set_list("main", { [1] = "", [32] = "" })
if random(1,10) < 7 then return end
local stacks = {}
if minetest.get_modpath("treasurer") ~= nil then
stacks = treasurer.select_random_treasures(3,1,5,{"armes", "armures", "precieux"})
else
for i=0,2,1 do
local stuff = chest_stuff[random(1,#chest_stuff)]
if stuff.name == "farming:bread" and not minetest.get_modpath("farming") then stuff = chest_stuff[1] end
table.insert(stacks, {name=stuff.name, count = random(1,stuff.max)})
end
for s=1,#stacks do
if not inv:contains_item("main", stacks[s]) then
inv:set_stack("main", random(1,32), stacks[s])
end
end
end
end)
for s=1,#stacks do
if not inv:contains_item("main", stacks[s]) then
inv:set_stack("main", random(1,32), stacks[s])
end
end
end
end
local function add_spawner(pos)
@ -134,82 +133,86 @@ local function ground(pos, old)
end
minetest.register_on_generated(function(minp, maxp, seed)
if maxp.y < 0 then return end
math.randomseed(seed)
local cnt = 0
minetest.register_on_generated(
function(minp, maxp, seed)
minetest.after(
3, function(minp, maxp, seed)
if maxp.y < 0 then return end
math.randomseed(seed)
local cnt = 0
local perlin1 = minetest.env:get_perlin(perl1.SEED1, perl1.OCTA1, perl1.PERS1, perl1.SCAL1)
local noise1 = perlin1:get2d({x=minp.x,y=minp.y})--,z=minp.z})
if noise1 > 0.25 or noise1 < -0.26 then
local mpos = {x=random(minp.x,maxp.x), y=random(minp.y,maxp.y), z=random(minp.z,maxp.z)}
local sands = {"default:desert_sand"}
local p2
local sand
for s=1, #sands do
sand = sands[s]
p2 = minetest.find_node_near(mpos, 25, sand)
while p2 == nil and cnt < 5 do
cnt = cnt+1
mpos = {x=random(minp.x,maxp.x), y=random(minp.y,maxp.y), z=random(minp.z,maxp.z)}
p2 = minetest.find_node_near(mpos, 25, sand)
end
if p2 ~= nil then
break
end
end
if p2 == nil then return end
if p2.y < 0 then return end
local perlin1 = minetest.env:get_perlin(perl1.SEED1, perl1.OCTA1, perl1.PERS1, perl1.SCAL1)
local noise1 = perlin1:get2d({x=minp.x,y=minp.y})--,z=minp.z})
if noise1 > 0.25 or noise1 < -0.26 then
local mpos = {x=random(minp.x,maxp.x), y=random(minp.y,maxp.y), z=random(minp.z,maxp.z)}
local sands = {"default:desert_sand"}
local p2
local sand
for s=1, #sands do
sand = sands[s]
p2 = minetest.find_node_near(mpos, 25, sand)
while p2 == nil and cnt < 5 do
cnt = cnt+1
mpos = {x=random(minp.x,maxp.x), y=random(minp.y,maxp.y), z=random(minp.z,maxp.z)}
p2 = minetest.find_node_near(mpos, 25, sand)
end
if p2 ~= nil then
break
end
end
if p2 == nil then return end
if p2.y < 0 then return end
local off = 0
local opos1 = {x=p2.x+22,y=p2.y-1,z=p2.z+22}
local opos2 = {x=p2.x+22,y=p2.y-1,z=p2.z}
local opos3 = {x=p2.x,y=p2.y-1,z=p2.z+22}
local opos1_n = minetest.get_node_or_nil(opos1)
local opos2_n = minetest.get_node_or_nil(opos2)
local opos3_n = minetest.get_node_or_nil(opos3)
if opos1_n and opos1_n.name and opos1_n.name == "air" then
p2 = ground(opos1, p2)
end
if opos2_n and opos2_n.name and opos2_n.name == "air" then
p2 = ground(opos2, p2)
end
if opos3_n and opos3_n.name and opos3_n.name == "air" then
p2 = ground(opos3, p2)
end
p2.y = p2.y - 3
if p2.y < 0 then p2.y = 0 end
if minetest.find_node_near(p2, 25, {"default:water_source"}) ~= nil or
minetest.find_node_near(p2, 22, {"default:dirt_with_grass"}) ~= nil or
minetest.find_node_near(p2, 52, {"maptools:sandstone_brick"}) ~= nil or
minetest.find_node_near(p2, 52, {"maptools:desert_sandstone_brick"}) ~= nil or
minetest.find_node_near(p2, 52, {"maptools:silver_sandstone_brick"}) ~= nil or
minetest.find_node_near(p2, 52, {"sandplus:desert_sandstonebrick"}) ~= nil
then return end
if random(0,10) > 7 then
return
end
local p_type = random(1, 3)
local p_pot = {
[1] = {"maptools:sandstone_brick", "default:sandstone", "default:sandstone", "default:sand"},
[2] = {"maptools:desert_sandstone_brick", "default:desert_sandstone", "default:desert_stone", "default:desert_sand"},
[3] = {"maptools:silver_sandstone_brick", "default:silver_sandstone", "default:silver_sandstone", "default:silver_sand"}
}
if sand == "default:desert_sand" then
if minetest.get_modpath("sandplus") then
minetest.after(0.8, make, p2, "sandplus:desert_sandstonebrick", "sandplus:desert_sandstone", "default:desert_stone", "default:desert_sand")
else
minetest.after(0.8, make, p2, p_pot[p_type][1], p_pot[p_type][2], p_pot[p_type][3], p_pot[p_type][4])
end
else
minetest.after(0.8, make, p2, "default:sandstonebrick", "default:sandstone", "default:sandstone", "default:sand")
end
end
end)
local off = 0
local opos1 = {x=p2.x+22,y=p2.y-1,z=p2.z+22}
local opos2 = {x=p2.x+22,y=p2.y-1,z=p2.z}
local opos3 = {x=p2.x,y=p2.y-1,z=p2.z+22}
local opos1_n = minetest.get_node_or_nil(opos1)
local opos2_n = minetest.get_node_or_nil(opos2)
local opos3_n = minetest.get_node_or_nil(opos3)
if opos1_n and opos1_n.name and opos1_n.name == "air" then
p2 = ground(opos1, p2)
end
if opos2_n and opos2_n.name and opos2_n.name == "air" then
p2 = ground(opos2, p2)
end
if opos3_n and opos3_n.name and opos3_n.name == "air" then
p2 = ground(opos3, p2)
end
p2.y = p2.y - 3
if p2.y < 0 then p2.y = 0 end
if minetest.find_node_near(p2, 25, {"default:water_source"}) ~= nil or
minetest.find_node_near(p2, 22, {"default:dirt_with_grass"}) ~= nil or
minetest.find_node_near(p2, 52, {"maptools:sandstone_brick"}) ~= nil or
minetest.find_node_near(p2, 52, {"maptools:desert_sandstone_brick"}) ~= nil or
minetest.find_node_near(p2, 52, {"maptools:silver_sandstone_brick"}) ~= nil or
minetest.find_node_near(p2, 52, {"sandplus:desert_sandstonebrick"}) ~= nil
then return end
if random(0,10) > 7 then
return
end
local p_type = random(1, 3)
local p_pot = {
[1] = {"maptools:sandstone_brick", "default:sandstone", "default:sandstone", "default:sand"},
[2] = {"maptools:desert_sandstone_brick", "default:desert_sandstone", "default:desert_stone", "default:desert_sand"},
[3] = {"maptools:silver_sandstone_brick", "default:silver_sandstone", "default:silver_sandstone", "default:silver_sand"}
}
if sand == "default:desert_sand" then
if minetest.get_modpath("sandplus") then
minetest.after(0.8, make, p2, "sandplus:desert_sandstonebrick", "sandplus:desert_sandstone", "default:desert_stone", "default:desert_sand")
else
minetest.after(0.8, make, p2, p_pot[p_type][1], p_pot[p_type][2], p_pot[p_type][3], p_pot[p_type][4])
end
else
minetest.after(0.8, make, p2, "default:sandstonebrick", "default:sandstone", "default:sandstone", "default:sand")
end
end
end, minp, maxp, seed)
end)
-- Add backwards-compability for nodes from the original pyramids mod
if minetest.get_modpath("pyramids") == nil then

View File

@ -65,3 +65,53 @@ minetest.register_node("tsm_pyramids:trap_2", {
sounds = default.node_sound_stone_defaults(),
drop = "",
})
local function get_chest_formspec(pos)
local spos = pos.x .. "," .. pos.y .. "," .. pos.z
local formspec =
"size[8,9]" ..
default.gui_bg ..
default.gui_bg_img ..
default.gui_slots ..
"list[nodemeta:" .. spos .. ";main;0,0.3;8,4;]" ..
"list[current_player;main;0,4.85;8,1;]" ..
"list[current_player;main;0,6.08;8,3;8]" ..
"listring[nodemeta:" .. spos .. ";main]" ..
"listring[current_player;main]" ..
default.get_hotbar_bg(0,4.85)
return formspec
end
local chestdef = minetest.registered_nodes["default:chest"]
minetest.register_node(
"tsm_pyramids:chest", {
description = "tsm_pyramids Chest auto refilled",
tiles = chestdef.tiles,
stack_max = 1000,
paramtype2 = "facedir",
is_ground_content = false,
on_construct = function(pos)
chestdef.on_construct(pos)
minetest.get_node_timer(pos):start(pyramids.max_time)
pyramids.fill_chest(pos)
end,
on_metadata_inventory_move = chestdef.on_metadata_inventory_move,
on_metadata_inventory_put = chestdef.on_metadata_inventory_put,
on_metadata_inventory_take = chestdef.on_metadata_inventory_take,
groups = {unbreakable = 1, not_in_creative_inventory = 1},
on_timer = function(pos, elapsed)
pyramids.fill_chest(pos)
return true
end,
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
if not default.can_interact_with_node(clicker, pos) then
return itemstack
end
minetest.after(
0.2,
minetest.show_formspec,
clicker:get_player_name(),
"default:chest", get_chest_formspec(pos))
end,
})

View File

@ -35,6 +35,7 @@ local function replace(str,iy)
if iy == 0 and str == "s" then out = "tsm_pyramids:" str = "sun" end
if iy == 3 and str == "s" then out = "tsm_pyramids:" str = "men" end
if str == "a" then out = "" end
if str == "c" then out = "tsm_pyramids:" end
if str == "s" then out = "maptools:" end
return out..code[str]
end
@ -57,7 +58,6 @@ function pyramids.make_room(pos)
local p2 = 0
if n_str == "c" then
if ix < 3 then p2 = 1 else p2 = 3 end
pyramids.fill_chest({x=loch.x+ix,y=loch.y-iy,z=loch.z+iz})
end
minetest.set_node({x=loch.x+ix,y=loch.y-iy,z=loch.z+iz}, {name=replace(n_str,iy), param2=p2})
end