1 -- Preciousness scaling numbers
2 local h_min
= -256 -- Minimum height. At this height and below, the preciousness is at its peak
3 local h_max
= -20 -- Max. height. At this height and above, the preciousness is at its lowest level
5 minetest
.set_gen_notify("dungeon")
6 minetest
.register_on_generated(function(minp
, maxp
, seed
)
7 local g
= minetest
.get_mapgen_object("gennotify")
8 if g
and g
.dungeon
and #g
.dungeon
> 3 then
9 minetest
.after(3, function(d
)
10 if d
== nil or #d
< 1 then
14 local p
= d
[math
.random(1, #d
)]
15 if minetest
.get_node({x
=p
.x
, y
=p
.y
-1, z
=p
.z
}).name
~= "air" then
16 minetest
.set_node(p
, {name
= "default:chest"})
18 -- calculate preciousness of treasures based on height. higher = more precious
19 local height
= math
.abs(h_min
) - math
.abs(h_max
)
20 local y_norm
= (p
.y
+1) - h_min
21 local scale
= 1 - (y_norm
/height
)
23 -- We will select randomly 1-2 out of 5 possible treasure groups: light, crafting component, building block, and melee weapon
25 { 4, 0, scale
*2+3, "light" }, -- precousness: 0..5
26 { 6, 0, 2, "crafting_component" }, -- 0..2
27 { 6, 0, 5, "building_block" }, -- 0..5
28 { 1, scale
*2, scale
*5, "melee_weapon" }, -- 0..5
29 { 3, 0, 3, "food" }, -- 0..3
32 local meta
= minetest
.get_meta(p
)
33 local inv
= meta
:get_inventory()
34 local treasures_added
= 0
35 for j
=1, math
.random(1, 2) do
36 local r
= math
.random(1, #groups
)
37 local treasures
= treasurer
.select_random_treasures(groups
[r
][1], groups
[r
][2], groups
[r
][3], { groups
[r
][4] })
38 treasures_added
= treasures_added
+ #treasures
40 inv
:add_item("main", treasures
[t
])
43 -- No treasures found? Maybe add one random treasure from default group
44 if treasures_added
<= 0 then
45 if math
.random(1,2) then
46 local treasures
= treasurer
.select_random_treasures(1, 0, 4)
48 inv
:add_item("main", treasures
[t
])
54 end, table.copy(g
.dungeon
))