Fix hot/cold damage.

This commit is contained in:
Duane Robertson 2016-05-16 03:37:28 -05:00
parent 0780d8dd67
commit 18b8401334
2 changed files with 61 additions and 17 deletions

View file

@ -413,6 +413,22 @@ do_env_damage = function(self)
end end
end end
local minp = vector.subtract(pos, 1.5)
local maxp = vector.add(pos, 1.5)
if self.lava_damage > 0 then
local counts = minetest.find_nodes_in_area(minp, maxp, {"group:surface_hot"})
if #counts > 0 then
self.health = self.health - self.lava_damage
effect(pos, 5, "fire_basic_flame.png")
end
end
if self.cold_damage > 0 then
local counts = minetest.find_nodes_in_area(minp, maxp, {"group:surface_cold"})
if #counts > 0 then
self.health = self.health - self.cold_damage
end
end
check_for_death(self) check_for_death(self)
end end
@ -2119,6 +2135,7 @@ minetest.register_entity(name, {
light_damage = def.light_damage or 0, light_damage = def.light_damage or 0,
water_damage = def.water_damage or 0, water_damage = def.water_damage or 0,
lava_damage = def.lava_damage or 0, lava_damage = def.lava_damage or 0,
cold_damage = def.cold_damage or 1,
fall_damage = def.fall_damage or 1, fall_damage = def.fall_damage or 1,
fall_speed = def.fall_speed or -10, -- must be lower than -2 (default: -10) fall_speed = def.fall_speed or -10, -- must be lower than -2 (default: -10)
drops = def.drops or {}, drops = def.drops or {},

View file

@ -8,6 +8,14 @@
local light_max = 12 local light_max = 12
minetest.override_item("default:river_water_source", {light_source = 8})
minetest.override_item("default:river_water_flowing", {light_source = 8})
minetest.override_item("default:water_source", {light_source = 8})
minetest.override_item("default:water_flowing", {light_source = 8})
minetest.add_group("default:ice", {surface_cold = 3})
--minetest.override_item("default:ice", {damage_per_second = 1})
minetest.register_node("fun_caves:huge_mushroom_cap", { minetest.register_node("fun_caves:huge_mushroom_cap", {
description = "Huge Mushroom Cap", description = "Huge Mushroom Cap",
tiles = {"vmg_mushroom_giant_cap.png", "vmg_mushroom_giant_under.png", "vmg_mushroom_giant_cap.png"}, tiles = {"vmg_mushroom_giant_cap.png", "vmg_mushroom_giant_under.png", "vmg_mushroom_giant_cap.png"},
@ -367,7 +375,7 @@ minetest.register_node("fun_caves:glow_obsidian_2", {
description = "Hot Glow Obsidian", description = "Hot Glow Obsidian",
tiles = {"caverealms_glow_obsidian2.png"}, tiles = {"caverealms_glow_obsidian2.png"},
is_ground_content = true, is_ground_content = true,
groups = {stone=2, crumbly=1, hot=1}, groups = {stone=2, crumbly=1, surface_hot=3, igniter=1},
damage_per_second = 1, damage_per_second = 1,
light_source = 9, light_source = 9,
sounds = default.node_sound_stone_defaults({ sounds = default.node_sound_stone_defaults({
@ -411,7 +419,7 @@ minetest.register_node("fun_caves:hot_cobble", {
description = "Hot Cobble", description = "Hot Cobble",
tiles = {"caverealms_hot_cobble.png"}, tiles = {"caverealms_hot_cobble.png"},
is_ground_content = true, is_ground_content = true,
groups = {crumbly=2, hot=1}, groups = {crumbly=2, surface_hot=3},
damage_per_second = 1, damage_per_second = 1,
light_source = 6, light_source = 6,
sounds = default.node_sound_stone_defaults({ sounds = default.node_sound_stone_defaults({
@ -419,23 +427,41 @@ minetest.register_node("fun_caves:hot_cobble", {
}), }),
}) })
minetest.register_abm({ local last_dps_check = 0
nodenames = {"group:hot"}, minetest.register_globalstep(function(dtime)
interval = 2, if last_dps_check < 20 then
chance = 1, last_dps_check = last_dps_check + 1
action = function(pos, node, active_object_count, active_object_count_wider) else
for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, 0.95)) do last_dps_check = 0
if not minetest.registered_nodes[node.name] then for id, player in pairs(minetest.get_connected_players()) do
return local minp = vector.subtract(player:getpos(), 0.5)
end local maxp = vector.add(player:getpos(), 0.5)
local dps = minetest.registered_nodes[node.name]["damage_per_second"] local counts = minetest.find_nodes_in_area(minp, maxp, {"group:surface_hot", "group:surface_cold"})
if object.set_hp and object.get_hp and dps then if #counts > 3 then
--print("damage. "..object:get_hp().." hit points left") player:set_hp(player:get_hp() - 1)
object:set_hp(object:get_hp() - dps)
end end
end end
end})
-- This just won't work.
--
--for id, ent in pairs(minetest.luaentities) do
-- if ent.object and not string.find(ent.name, "__built") then
-- local minp = vector.subtract(ent.object:getpos(), 1)
-- local maxp = vector.add(ent.object:getpos(), 1)
-- local counts = minetest.find_nodes_in_area(minp, maxp, {"group:hot"})
-- if #counts > 3 then
-- ent.object:set_hp(ent.object:get_hp() - 1)
-- ent.old_health = ent.health
-- ent.health = ent.health - 1
-- print(ent.name.." suffers, "..ent.object:get_hp().."/"..ent.health.." left")
-- --if ent.object:get_hp() < 1 then
-- -- print(dump(ent))
-- --end
-- end
-- end
--end
end
end)
-- mushroom growth -- mushroom growth
minetest.register_abm({ minetest.register_abm({
@ -609,7 +635,8 @@ for i in ipairs(spike_size) do
inventory_image = "fun_caves_hot_spike.png", inventory_image = "fun_caves_hot_spike.png",
wield_image = "fun_caves_hot_spike.png", wield_image = "fun_caves_hot_spike.png",
is_ground_content = true, is_ground_content = true,
groups = {cracky=3, oddly_breakable_by_hand=1}, groups = {cracky=3, oddly_breakable_by_hand=1, hot=3},
damage_per_second = 1,
sounds = default.node_sound_stone_defaults(), sounds = default.node_sound_stone_defaults(),
light_source = 3, light_source = 3,
paramtype = "light", paramtype = "light",