diff --git a/abms.lua b/abms.lua index c04df5a..f4e74a9 100644 --- a/abms.lua +++ b/abms.lua @@ -58,6 +58,7 @@ spike_soil['fun_caves:black_sand'] = true -- all the fun_caves globalstep functions ------------------------------------------------------------ local hot_stuff = {"group:surface_hot"} +local traps = {"group:trap"} local cold_stuff = {"group:surface_cold"} local poison_stuff = {"group:poison"} local gravity_off = {gravity = 0.1} @@ -99,6 +100,8 @@ local function firework() end end +local sparking = {} + minetest.register_globalstep(function(dtime) if not (dtime and type(dtime) == 'number') then return @@ -113,6 +116,162 @@ minetest.register_globalstep(function(dtime) return end + -- Trap check + if last_dps_check and time - last_dps_check < 1 then + return + end + + local minetest_find_nodes_in_area = minetest.find_nodes_in_area + local players = minetest.get_connected_players() + if not (players and type(players) == 'table') then + return + end + + for i = 1, #players do + local player = players[i] + local pos = player:getpos() + pos = vector.round(pos) + local player_name = player:get_player_name() + + local minp = vector.subtract(pos, 2) + local maxp = vector.add(pos, 2) + local counts = minetest_find_nodes_in_area(minp, maxp, traps) + if counts and type(counts) == 'table' and #counts > 0 then + for _, tpos in ipairs(counts) do + local node = minetest.get_node_or_nil(tpos) + if not node then + return + end + if node.name == 'fun_caves:stone_with_coal_trap' then + minetest.set_node(tpos, {name="fire:basic_flame"}) + + local hp = player:get_hp() + if hp > 0 then + player:set_hp(hp - 1) + end + elseif node.name == 'fun_caves:stone_with_diamond_trap' then + fun_caves.diamond_trap(tpos, player) + elseif node.name == 'fun_caves:stone_with_gold_trap' then + fun_caves.gold_trap(tpos, player) + elseif node.name == 'fun_caves:mossycobble_trap' then + player:set_physics_override({speed = 0.1}) + minetest.after(1, function() -- this effect is temporary + object:set_physics_override({speed = 1}) -- we'll just set it to 1 and be done. + end) + elseif node.name == 'fun_caves:ice_trap' then + fun_caves.ice_trap(tpos, player) + elseif node.name == 'fun_caves:stone_with_copper_trap' or node.name == 'fun_caves:stone_with_iron_trap' then + if not sparking[player_name] then + sparking[player_name] = true + fun_caves.copper_trap(tpos, player) + + minetest.after(1, function() + sparking[player_name] = nil + end) + end + else + minetest.remove_node(tpos) + end + end + end + + -- Execute only after an interval. + if last_dps_check and time - last_dps_check > dps_delay then + if pos.y >= 11168 and pos.y <= 15168 then + if not players_in_orbit[player_name] then + player:set_physics_override(gravity_off) + player:set_sky("#000000", "plain") + players_in_orbit[player_name] = true + end + elseif players_in_orbit[player_name] then + player:set_sky("#000000", "regular") + minetest.after(20, function() + player:set_physics_override(gravity_on) + end) + players_in_orbit[player_name] = false + end + + -- environmental damage + if fun_caves.DEBUG and player:get_hp() < 20 then + -- Regenerate the player while testing. + print("HP: "..player:get_hp()) + player:set_hp(20) + return + else + local minp = vector.subtract(pos, 0.5) + local maxp = vector.add(pos, 0.5) + + -- Remove status effects. + local status = fun_caves.db.status[player_name] + for status_name, status_param in pairs(status) do + local def = fun_caves.registered_status[status_name] + if not def then + print('Fun Caves: Error - unregistered status ' .. status_name) + break + end + + local remove + if type(status_param.remove) == 'number' then + if status_param.remove < time then + remove = true + end + elseif def.remove then + remove = def.remove(player) + else + print('Fun Caves: Error in status remove for ' .. status_name) + end + + if remove then + fun_caves.remove_status(player_name, status_name) + elseif def.during then + def.during(player) + end + end + + if fun_caves.db.status[player_name]['breathe'] then + player:set_breath(11) + end + + -- ... from standing on or near hot objects. + local counts = minetest_find_nodes_in_area(minp, maxp, hot_stuff) + if not (counts and type(counts) == 'table') then + return + end + + if #counts > 1 then + player:set_hp(player:get_hp() - 1) + end + + -- ... from standing on or near poison. + local counts = minetest_find_nodes_in_area(minp, maxp, poison_stuff) + if not (counts and type(counts) == 'table') then + return + end + + if #counts > 1 then + player:set_hp(player:get_hp() - 1) + end + + -- ... from standing on or near cold objects (less often). + if dps_count % cold_delay == 0 then + counts = minetest_find_nodes_in_area(minp, maxp, cold_stuff) + if not (counts and type(counts) == 'table') then + return + end + + if #counts > 1 then + player:set_hp(player:get_hp() - 1) + end + end + + -- ... from hunger (even less often). + if dps_count % hunger_delay == 0 and fun_caves.hunger_change then + fun_caves.hunger_change(player, -1) + end + end + end + end + -- Execute only after an interval. if last_dps_check and time - last_dps_check < dps_delay then return @@ -147,111 +306,6 @@ minetest.register_globalstep(function(dtime) end end - local minetest_find_nodes_in_area = minetest.find_nodes_in_area - local players = minetest.get_connected_players() - if not (players and type(players) == 'table') then - return - end - - for i = 1, #players do - local player = players[i] - local pos = player:getpos() - local player_name = player:get_player_name() - - if pos.y >= 11168 and pos.y <= 15168 then - if not players_in_orbit[player_name] then - player:set_physics_override(gravity_off) - player:set_sky("#000000", "plain") - players_in_orbit[player_name] = true - end - elseif players_in_orbit[player_name] then - player:set_sky("#000000", "regular") - minetest.after(20, function() - player:set_physics_override(gravity_on) - end) - players_in_orbit[player_name] = false - end - - -- environmental damage - if fun_caves.DEBUG and player:get_hp() < 20 then - -- Regenerate the player while testing. - print("HP: "..player:get_hp()) - player:set_hp(20) - return - else - local minp = vector.subtract(pos, 0.5) - local maxp = vector.add(pos, 0.5) - - -- Remove status effects. - local status = fun_caves.db.status[player_name] - for status_name, status_param in pairs(status) do - local def = fun_caves.registered_status[status_name] - if not def then - print('Fun Caves: Error - unregistered status ' .. status_name) - break - end - - local remove - if type(status_param.remove) == 'number' then - if status_param.remove < time then - remove = true - end - elseif def.remove then - remove = def.remove(player) - else - print('Fun Caves: Error in status remove for ' .. status_name) - end - - if remove then - fun_caves.remove_status(player_name, status_name) - elseif def.during then - def.during(player) - end - end - - if fun_caves.db.status[player_name]['breathe'] then - player:set_breath(11) - end - - -- ... from standing on or near hot objects. - local counts = minetest_find_nodes_in_area(minp, maxp, hot_stuff) - if not (counts and type(counts) == 'table') then - return - end - - if #counts > 1 then - player:set_hp(player:get_hp() - 1) - end - - -- ... from standing on or near poison. - local counts = minetest_find_nodes_in_area(minp, maxp, poison_stuff) - if not (counts and type(counts) == 'table') then - return - end - - if #counts > 1 then - player:set_hp(player:get_hp() - 1) - end - - -- ... from standing on or near cold objects (less often). - if dps_count % cold_delay == 0 then - counts = minetest_find_nodes_in_area(minp, maxp, cold_stuff) - if not (counts and type(counts) == 'table') then - return - end - - if #counts > 1 then - player:set_hp(player:get_hp() - 1) - end - end - - -- ... from hunger (even less often). - if dps_count % hunger_delay == 0 and fun_caves.hunger_change then - fun_caves.hunger_change(player, -1) - end - end - end - -- Set this outside of the player loop, to affect everyone. if dps_count % hunger_delay == 0 then dps_count = hunger_delay @@ -285,8 +339,8 @@ minetest.register_abm({ minetest.register_abm({ nodenames = {"fun_caves:hot_cobble",}, neighbors = {"group:water"}, - interval = 5, - chance = 60, + interval = time_factor, + chance = 30, catch_up = false, action = function(pos, node) if not (pos and node) then @@ -302,8 +356,8 @@ minetest.register_abm({ -- Exploding fungal fruit minetest.register_abm({ nodenames = {"fun_caves:fungal_tree_fruit"}, - interval = 2 * time_factor, - chance = 150, + interval = 12 * time_factor, + chance = 400, catch_up = false, action = function(pos, node) if not (pos and node) then @@ -333,8 +387,8 @@ minetest.register_abm({ minetest.register_abm({ nodenames = {"fire:basic_flame"}, - interval = time_factor, - chance = 100, + interval = 2 * time_factor, + chance = 50, action = function(p0, node, _, _) minetest.remove_node(p0) end, @@ -342,8 +396,8 @@ minetest.register_abm({ minetest.register_abm({ nodenames = {"fun_caves:coffer"}, - interval = 2, - chance = 50, + interval = 5, + chance = 20, catch_up = false, action = function(p0, node, _, _) minetest.remove_node(p0) @@ -354,71 +408,75 @@ minetest.register_abm({ -- creation ------------------------------------------------------------ -minetest.register_abm({ - nodenames = {"fun_caves:dungeon_floor_1"}, - neighbors = {'air'}, - interval = 5 * time_factor, - chance = 500, - catch_up = false, - action = function(pos, node, aoc, active_object_count_wider) - if not (pos and node) or active_object_count_wider > dungeon_monster_density then - return - end - - for i = 1, 2 do - pos.y = pos.y + 1 - local node = minetest.get_node_or_nil(pos) - if not node or node.name ~= "air" then +if fun_caves.dungeon_spawns and #fun_caves.dungeon_spawns > 0 then + print('go monster') + minetest.register_abm({ + nodenames = {"fun_caves:dungeon_floor_1"}, + neighbors = {'air'}, + interval = 7 * time_factor, + chance = 350, + catch_up = false, + action = function(pos, node, aoc, active_object_count_wider) + if not (pos and node) or active_object_count_wider > dungeon_monster_density then return end - end - local target_level = math.max(2, math.ceil((pos.y - 3 ^ math.random(9)) / -200)) + for i = 1, 2 do + pos.y = pos.y + 1 + local node = minetest.get_node_or_nil(pos) + if not node or node.name ~= "air" then + return + end + end - local desc - for i = 1, 100 do - desc = fun_caves.dungeon_spawns[math.random(#fun_caves.dungeon_spawns)] - if desc.level <= target_level then - break - else - desc = nil + local target_level = math.max(2, math.ceil((pos.y - 3 ^ math.random(9)) / -200)) + + local desc + for i = 1, 100 do + desc = fun_caves.dungeon_spawns[math.random(#fun_caves.dungeon_spawns)] + if desc.level <= target_level then + break + else + desc = nil + end + end + + 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 end + }) +end - 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 - end -}) - +if false then minetest.register_abm({ nodenames = {"fun_caves:dungeon_floor_1"}, neighbors = {'air'}, - interval = 10 * time_factor, - chance = 2000, + interval = 20 * time_factor, + chance = 1000, catch_up = false, action = function(pos, node) if not (pos and node) then @@ -438,8 +496,8 @@ minetest.register_abm({ minetest.register_abm({ nodenames = {"fun_caves:dungeon_wall_1"}, neighbors = {'air'}, - interval = 1 * time_factor, - chance = 1000, + interval = 4 * time_factor, + chance = 250, catch_up = false, action = function(pos, node) if not (pos and node) then @@ -475,6 +533,7 @@ minetest.register_abm({ minetest.set_node(pos, {name = 'default:torch', param2 = p2}) end }) +end -- This puts the burdon on fires, which shouldn't be happening much. minetest.register_abm({ @@ -494,8 +553,8 @@ minetest.register_abm({ minetest.register_abm({ nodenames = {"default:leaves"}, neighbors = {'air'}, - interval = 5 * time_factor, - chance = 1000, + interval = 10 * time_factor, + chance = 500, catch_up = false, action = function(pos, node) if not (pos and node) then @@ -512,8 +571,8 @@ minetest.register_abm({ minetest.register_abm({ nodenames = {"default:apple"}, - interval = time_factor, - chance = 100, + interval = 2 * time_factor, + chance = 50, catch_up = false, action = function(pos, node) if not (pos and node) then @@ -543,8 +602,8 @@ local no_tree_grow = {'fun_caves:bark', 'fun_caves:leaves'} local wood_nodes = {{name = 'fun_caves:diamondwood'}, {name = 'fun_caves:ironwood'}, {name = 'fun_caves:sap'}, {name = 'fun_caves:tree'}} minetest.register_abm({ neighbors = {'air'}, - interval = 5 * time_factor, - chance = 900, + interval = 10 * time_factor, + chance = 450, catch_up = false, action = function(pos, node) if not (pos and node) then @@ -612,8 +671,8 @@ minetest.register_abm({ minetest.register_abm({ nodenames = fungal_tree_leaves, neighbors = {"air", "group:liquid"}, - interval = math.ceil(time_factor / 2), - chance = 100, + interval = 4 * time_factor, + chance = 200, catch_up = false, action = function(pos, node) if not (pos and node) then @@ -661,8 +720,8 @@ local huge_mushroom_cap_node = {name = 'fun_caves:huge_mushroom_cap'} minetest.register_abm({ nodenames = {"fun_caves:giant_mushroom_stem"}, neighbors = {'air'}, - interval = time_factor, - chance = 300, + interval = 4 * time_factor, + chance = 200, action = function(pos, node) if not (pos and node) then return @@ -688,8 +747,8 @@ end minetest.register_abm({ nodenames = {"default:dirt"}, neighbors = {'fun_caves:stone_with_lichen', 'fun_caves:stone_with_algae', 'fun_caves:giant_mushroom_stem'}, - interval = time_factor, - chance = 300, + interval = 10 * time_factor, + chance = 500, catch_up = false, action = function(pos, node) if not (pos and node and pos.y < 0) then @@ -713,8 +772,8 @@ minetest.register_abm({ local giant_mushroom_stem_node = {name = 'fun_caves:giant_mushroom_stem'} minetest.register_abm({ nodenames = mushrooms, - interval = 5 * time_factor, - chance = 750, + interval = 20 * time_factor, + chance = 700, catch_up = false, action = function(pos, node) if not (pos and node and pos.y < 0) then @@ -743,7 +802,7 @@ minetest.register_abm({ local giant_mushroom_cap_node = {name = "fun_caves:giant_mushroom_cap"} minetest.register_abm({ nodenames = {"fun_caves:huge_mushroom_cap"}, - interval = 9 * time_factor, + interval = 40 * time_factor, chance = 2000, catch_up = false, action = function(pos, node) @@ -773,8 +832,8 @@ minetest.register_abm({ -- Spike spread and death minetest.register_abm({ nodenames = fun_caves.hot_spikes, - interval = time_factor, - chance = 900, + interval = 40 * time_factor, + chance = 2000, action = function(pos, node) if not (pos and node and pos.y < 0) then return @@ -821,11 +880,11 @@ local last_meteor_strike = 0 minetest.register_abm({ nodenames = {"default:dirt_with_grass", "default:dirt_with_dry_grass", 'default:dirt_with_snow'}, neighbors = {"air", 'default:snow'}, - interval = 25 * time_factor, + interval = 150 * time_factor, catch_up = false, - chance = 32767, + chance = 5500, action = function(pos, node) - if not (pos and node) then + if not (pos and node and pos.y > 0) then return end @@ -865,8 +924,8 @@ minetest.register_abm({ -- Remove old craters. minetest.register_abm({ nodenames = {"fun_caves:meteorite_crater"}, - interval = 3 * time_factor, - chance = 330, + interval = 5 * time_factor, + chance = 200, action = function(pos, node) if not (pos and node) then return diff --git a/dungeon.lua b/dungeon.lua index 3b4f4bb..5abc69c 100644 --- a/dungeon.lua +++ b/dungeon.lua @@ -196,7 +196,7 @@ newnode.on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) local ready = meta:get_string('formspec') if treasures and ready == '' then - if math.random(10) == 1 then + if math.random(10) == 1 and fun_caves.dungeon_spawns and #fun_caves.dungeon_spawns > 0 then minetest.remove_node(pos) local desc = fun_caves.dungeon_spawns[math.random(#fun_caves.dungeon_spawns)] @@ -518,7 +518,7 @@ fun_caves.dungeon = function(minp_in, maxp_in, data, p2data, area, node, heightm if not leave_alone[data[ivm]] then if ry == 0 and (cy > 0 or not centered_in) then if content[cx][cy][cz] == 'room' then - local r = math.random(1000) + local r = math.random(100) if r == 1 then data[ivm] = node['fun_caves:stone_with_gold_trap'] elseif r == 2 then diff --git a/goblin.lua b/goblin.lua index a3682b5..f8872e0 100644 --- a/goblin.lua +++ b/goblin.lua @@ -404,37 +404,12 @@ minetest.register_node("fun_caves:mossycobble_trap", { description = "Messy Gobblestone", tiles = {"default_mossycobble.png"}, is_ground_content = false, - groups = {cracky = 2, stone = 1}, + groups = {cracky = 2, stone = 1, trap = 1}, sounds = default.node_sound_stone_defaults(), paramtype = "light", light_source = 4, }) ---[[ too bad we can't keep track of what physics are set too by other mods...]] -minetest.register_abm({ - nodenames = {"fun_caves:mossycobble_trap"}, - interval = 1, - chance = 1, - action = function(pos, node, active_object_count, active_object_count_wider) - if not pos then - return - end - - local objects = minetest.get_objects_inside_radius(pos, 0.95) - if not (objects and type(objects) == 'table') then - return - end - - for _, object in ipairs(objects) do -- IDKWTF this is but it works - if object:is_player() then - object:set_physics_override({speed = 0.1}) - minetest.after(1, function() -- this effect is temporary - object:set_physics_override({speed = 1}) -- we'll just set it to 1 and be done. - end) - end - end - end}) - minetest.register_craft({ type = "cooking", output = "default:stone", @@ -444,56 +419,15 @@ minetest.register_craft({ minetest.register_node("fun_caves:stone_with_coal_trap", { description = "Coal Trap", tiles = {"default_cobble.png^default_mineral_coal.png"}, - groups = {cracky = 3}, + groups = {cracky = 3, trap = 1}, drop = 'default:coal_lump', is_ground_content = false, sounds = default.node_sound_stone_defaults(), }) -minetest.register_abm({ - nodenames = {"fun_caves:stone_with_coal_trap"}, - interval = 1, - chance = 1, - action = function(pos, node, active_object_count, active_object_count_wider) - if not pos then - return - end - - local objects = minetest.get_objects_inside_radius(pos, 2) - if not (objects and type(objects) == 'table') then - return - end - - for _, object in ipairs(objects) do - if object:is_player() then - minetest.set_node(pos, {name="fire:basic_flame"}) - if object:get_hp() > 0 then - object:set_hp(object:get_hp()-2) - end - end - end - end -}) - -local singleplayer = minetest.is_singleplayer() -local setting = minetest.setting_getbool("enable_tnt") -local diamond_trap -if (not singleplayer and setting ~= true) or (singleplayer and setting == false) then - -- wimpier trap for non-tnt settings - diamond_trap = function(pos, player) - if not (pos and player) then - return - end - - minetest.set_node(pos, {name="default:lava_source"}) - if player:get_hp() > 0 then - player:set_hp(player:get_hp()-2) - minetest.sound_play("default_dig_crumbly", {pos = pos, gain = 0.5, max_hear_distance = 10}) - end - end -else +if minetest.registered_nodes['tnt:tnt_burning'] then -- 5... 4... 3... 2... 1... - diamond_trap = function(pos, player) + fun_caves.diamond_trap = function(pos, player) if not (pos and player) then return end @@ -505,12 +439,26 @@ else end minetest.sound_play("default_dig_crumbly", {pos = pos, gain = 0.5, max_hear_distance = 10}) end +else + -- wimpier trap for non-tnt settings + fun_caves.diamond_trap = function(pos, player) + if not (pos and player) then + return + end + + minetest.set_node(pos, {name="default:lava_source"}) + local hp = player:get_hp() + if hp > 0 then + player:set_hp(hp - 2) + minetest.sound_play("default_dig_crumbly", {pos = pos, gain = 0.5, max_hear_distance = 10}) + end + end end minetest.register_node("fun_caves:stone_with_diamond_trap", { description = "Diamond Trap", tiles = {"default_cobble.png^(default_mineral_diamond.png^[colorize:#000000:160)"}, - groups = {cracky = 3}, + groups = {cracky = 3, trap = 1}, drop = 'default:diamond', is_ground_content = false, sounds = default.node_sound_stone_defaults(), @@ -520,35 +468,13 @@ minetest.register_node("fun_caves:stone_with_diamond_trap", { end if math.random(3) == 1 then - diamond_trap(pos, digger) + fun_caves.diamond_trap(pos, digger) else minetest.node_dig(pos, node, digger) end end }) -minetest.register_abm({ - nodenames = {"fun_caves:stone_with_diamond_trap"}, - interval = 1, - chance = 1, - action = function(pos) - if not pos then - return - end - - local objects = minetest.get_objects_inside_radius(pos, 3) - if not (objects and type(objects) == 'table') then - return - end - - for _,object in ipairs(objects) do - if object:is_player() then - diamond_trap(pos, object) - end - end - end, -}) - newnode = fun_caves.clone_node("default:lava_source") newnode.description = "Molten Gold Source" @@ -581,19 +507,23 @@ bucket.register_liquid( {} ) -local gold_trap = function(pos, player) +fun_caves.gold_trap = function(pos, player) if not (pos and player) then return end minetest.set_node(pos, {name="fun_caves:molten_gold_source"}) minetest.sound_play("default_dig_crumbly", {pos = pos, gain = 0.5, max_hear_distance = 10}) + local hp = player:get_hp() + if hp > 0 then + player:set_hp(hp - 2) + end end minetest.register_node("fun_caves:stone_with_gold_trap", { description = "Gold Trap", tiles = {"default_cobble.png^(default_mineral_gold.png^[colorize:#000000:160)"}, - groups = {cracky = 3}, + groups = {cracky = 3, trap = 1}, drop = 'default:gold_lump', is_ground_content = false, sounds = default.node_sound_stone_defaults(), @@ -603,37 +533,15 @@ minetest.register_node("fun_caves:stone_with_gold_trap", { end if math.random(3) == 1 then - gold_trap(pos, digger) + fun_caves.gold_trap(pos, digger) else minetest.node_dig(pos, node, digger) end end }) -minetest.register_abm({ - nodenames = {"fun_caves:stone_with_gold_trap"}, - interval = 1, - chance = 1, - action = function(pos) - if not pos then - return - end - local objects = minetest.get_objects_inside_radius(pos, 2) - if not (objects and type(objects) == 'table') then - return - end - - for _,object in ipairs(objects) do - if object:is_player() then - gold_trap(pos, object) - end - end - end -}) - - -local ice_trap = function(pos, player) +fun_caves.ice_trap = function(pos, player) if not (pos and player) then return end @@ -659,7 +567,7 @@ end minetest.register_node("fun_caves:ice_trap", { description = "Ice Trap", tiles = {"default_ice.png^fun_caves_mineral_moonstone.png"}, - groups = {cracky = 3}, + groups = {cracky = 3, trap = 1}, drop = 'default:ice', is_ground_content = false, sounds = default.node_sound_stone_defaults(), @@ -669,35 +577,13 @@ minetest.register_node("fun_caves:ice_trap", { end if math.random(3) == 1 then - ice_trap(pos, digger) + fun_caves.ice_trap(pos, digger) else minetest.node_dig(pos, node, digger) end end }) -minetest.register_abm({ - nodenames = {"fun_caves:ice_trap"}, - interval = 1, - chance = 1, - action = function(pos) - if not pos then - return - end - - local objects = minetest.get_objects_inside_radius(pos, 2) - if not (objects and type(objects) == 'table') then - return - end - - for _,object in ipairs(objects) do - if object:is_player() then - ice_trap(pos, object) - end - end - end -}) - local function lightning_effects(pos, radius) if not (pos and radius) then @@ -721,13 +607,14 @@ local function lightning_effects(pos, radius) }) end -local copper_trap = function(pos, player) +fun_caves.copper_trap = function(pos, player) if not (pos and player) then return end - if player:get_hp() > 0 then - player:set_hp(player:get_hp()-1) + local hp = player:get_hp() + if hp > 0 then + player:set_hp(hp - 1) lightning_effects(pos, 3) minetest.sound_play("default_dig_crumbly", {pos = pos, gain = 0.5, max_hear_distance = 10}) end @@ -736,7 +623,7 @@ end minetest.register_node("fun_caves:stone_with_copper_trap", { description = "Copper Trap", tiles = {"default_cobble.png^(default_mineral_copper.png^[colorize:#000000:160)"}, - groups = {cracky = 3}, + groups = {cracky = 3, trap = 1}, drop = 'default:copper_lump', is_ground_content = false, sounds = default.node_sound_stone_defaults(), @@ -746,43 +633,20 @@ minetest.register_node("fun_caves:stone_with_copper_trap", { end if math.random(3) == 1 then - copper_trap(pos, digger) + fun_caves.copper_trap(pos, digger) else minetest.node_dig(pos, node, digger) end end }) ---[[ based on dwarves cactus]] -minetest.register_abm({ - nodenames = {"fun_caves:stone_with_copper_trap"}, - interval = 1, - chance = 2, - action = function(pos) - if not pos then - return - end - - local objects = minetest.get_objects_inside_radius(pos, 3) - if not (objects and type(objects) == 'table') then - return - end - - for _,object in ipairs(objects) do - if object:is_player() then - copper_trap(pos, object) - end - end - end -}) - -- summon a metallic goblin? -- pit of iron razors? minetest.register_node("fun_caves:stone_with_iron_trap", { description = "Iron Trap", tiles = {"default_cobble.png^(default_mineral_iron.png^[colorize:#000000:160)"}, - groups = {cracky = 3}, + groups = {cracky = 3, trap = 1}, drop = 'default:iron_lump', is_ground_content = false, sounds = default.node_sound_stone_defaults(), @@ -792,31 +656,9 @@ minetest.register_node("fun_caves:stone_with_iron_trap", { end if math.random(3) == 1 then - copper_trap(pos, digger) + fun_caves.copper_trap(pos, digger) else minetest.node_dig(pos, node, digger) end end }) - -minetest.register_abm({ - nodenames = {"fun_caves:stone_with_iron_trap"}, - interval = 2, - chance = 2, - action = function(pos, node, active_object_count, active_object_count_wider) - if not pos then - return - end - - local objects = minetest.get_objects_inside_radius(pos, 3) - if not (objects and type(objects) == 'table') then - return - end - - for _, object in ipairs(objects) do - if object:is_player() then - copper_trap(pos, object) - end - end - end -}) diff --git a/horror.lua b/horror.lua index e6747f7..a2d8de2 100644 --- a/horror.lua +++ b/horror.lua @@ -49,7 +49,7 @@ mobs:register_mob("fun_caves:manticore", { return end - if self.attack and math.random(3) == 1 then + if self.attack and math.random(3) == 1 and self.attack:is_player(self.attack) and minetest.line_of_sight(self.attack:getpos(), self.object:getpos(), stepsize) then local player_name = self.attack:get_player_name() if player_name and player_name ~= '' then minetest.chat_send_player(player_name, minetest.colorize('#FF0000', 'You\'ve been poisoned!')) diff --git a/init.lua b/init.lua index d0ce015..cd8825a 100644 --- a/init.lua +++ b/init.lua @@ -207,7 +207,6 @@ end --dofile(fun_caves.path .. "/recipe_list.lua") -dofile(fun_caves.path .. "/abms.lua") dofile(fun_caves.path .. "/nodes.lua") dofile(fun_caves.path .. "/deco.lua") dofile(fun_caves.path .. "/fungal_tree.lua") @@ -222,6 +221,8 @@ if minetest.get_modpath("mobs") and mobs and mobs.mod == "redo" then dofile(fun_caves.path .. "/mobs.lua") end +dofile(fun_caves.path .. "/abms.lua") + --fun_caves.print_recipes()