From f182dd902a1a089a30194e84d9e1f6909fec3838 Mon Sep 17 00:00:00 2001 From: Duane Date: Sat, 6 Aug 2016 09:54:38 -0500 Subject: [PATCH] Add monster-summoning chest. --- dungeon.lua | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/dungeon.lua b/dungeon.lua index 144c621..3b4f4bb 100644 --- a/dungeon.lua +++ b/dungeon.lua @@ -196,7 +196,38 @@ newnode.on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) local ready = meta:get_string('formspec') if treasures and ready == '' then - if math.random(20) == 1 then + if math.random(10) == 1 then + minetest.remove_node(pos) + + local desc = fun_caves.dungeon_spawns[math.random(#fun_caves.dungeon_spawns)] + + if not desc then + return + end + + local obj = minetest.add_entity(pos, desc.name) + if not obj then + return + end + local mob = obj:get_luaentity() + if not mob then + return + end + + if mob.hp_max and mob.object and mob.health and mob.damage then + local factor = 1 + (math.max(math.abs(pos.x), math.abs(pos.y), math.abs(pos.z)) / 6200) + mob.started_in_dungeon = true + factor = factor * 1.5 + mob.hp_max = math.floor(mob.hp_max * factor) + mob.damage = math.floor(mob.damage * factor) + mob.health = math.floor(mob.health * factor) + mob.object:set_hp(mob.health) + mob.initial_promotion = true + check_for_death(mob) + + --print('Dungeon quality '..desc.name..': '..mob.health..' health, '..mob.damage..' damage') + end + elseif math.random(20) == 1 then local player_name = clicker:get_player_name() if not player_name or player_name == '' or not fun_caves.set_status then return