Mobs drown instead of taking direct water damage

This commit is contained in:
Wuzzy 2019-09-25 13:43:57 +02:00
parent 725602a72e
commit d86f602b9f
7 changed files with 49 additions and 20 deletions

View File

@ -168,6 +168,8 @@ function mobs:register_mob(name, def)
lifetimer = def.lifetimer or 180, -- 3 minutes
hp_min = def.hp_min or 5,
hp_max = def.hp_max or 10,
breath_max = def.breath_max or -1, -- how many seconds the mob can breathe in drowning nodes. -1 = no drowning damage
breath = def.breath_max,
physical = true,
collides_with_objects = def.collides_with_objects or true,
collisionbox = def.collisionbox,
@ -517,22 +519,6 @@ function mobs:register_mob(name, def)
local nodef = minetest.registered_nodes[nod.name]
pos.y = pos.y + 1
-- water
if self.water_damage ~= 0
and nodef.groups.water then
self.object:set_hp(self.object:get_hp() - self.water_damage)
effect(pos, 5, "bubble.png")
if check_for_death(self) then return end
end
-- lava or fire
if self.lava_damage ~= 0
and nodef.groups.lava then
self.object:set_hp(self.object:get_hp() - self.lava_damage)
effect(pos, 5, "mobs_flame.png", 8)
if check_for_death(self) then return end
end
-- node damage
if self.takes_node_damage == true
and nodef.damage_per_second > 0 then
@ -545,6 +531,43 @@ function mobs:register_mob(name, def)
if check_for_death(self) then return end
end
-- drowning damage
if self.breath_max ~= - 1 then
if not self.breath then
self.breath = self.breath_max
end
if nodef.drowning > 0 then
self.breath = self.breath - 1
if self.breath < 0 then
self.breath = 0
self.object:set_hp(self.object:get_hp() - nodef.drowning)
effect(pos, 5, "bubble.png")
end
if check_for_death(self) then return end
else
self.breath = self.breath + 1
if self.breath > self.breath_max then
self.breath = self.breath_max
end
end
end
-- water damage
if self.water_damage ~= 0
and nodef.groups.water then
self.object:set_hp(self.object:get_hp() - self.water_damage)
effect(pos, 5, "bubble.png")
if check_for_death(self) then return end
end
-- lava damage
if self.lava_damage ~= 0
and nodef.groups.lava then
self.object:set_hp(self.object:get_hp() - self.lava_damage)
effect(pos, 5, "mobs_flame.png", 8)
if check_for_death(self) then return end
end
end
local do_jump = function(self)

View File

@ -13,6 +13,7 @@ mobs:register_mob(
damage = 2,
hp_min = 16,
hp_max = 20,
breath_max = 5,
armor = 200,
collisionbox = {-0.5, -1, -0.5, 0.5, 0.1, 0.5},
visual = "mesh",
@ -37,7 +38,7 @@ mobs:register_mob(
{name = "mobs:pork_raw",
chance = 1, min = 1, max = 4},
},
water_damage = 1,
water_damage = 0,
lava_damage = 5,
light_damage = 0,
animation = {

View File

@ -11,6 +11,7 @@ mobs:register_mob(
attack_type = "explode",
hp_min = 10,
hp_max = 15,
breath_max = 20,
armor = 200,
collisionbox = {-0.4, 0, -0.4, 0.4, 0.7, 0.4},
visual = "mesh",
@ -34,7 +35,7 @@ mobs:register_mob(
{name = "tnt:tnt",
chance = 1, min = 1, max = 3},
},
water_damage = 1,
water_damage = 0,
lava_damage = 5,
light_damage = 0,
takes_node_damage = false,

View File

@ -90,6 +90,7 @@ for _, npc_type_table in pairs(npc_types) do
attacks_monsters = true,
hp_min = 10,
hp_max = 20,
breath_max = 11,
armor = 80,
collisionbox = {-0.35,-1.0,-0.35, 0.35,0.8,0.35},
visual = "mesh",

View File

@ -10,6 +10,7 @@ mobs:register_mob(
passive = true,
hp_min = 10,
hp_max = 14,
breath_max = 5,
armor = 200,
collisionbox = {-0.5, -1, -0.5, 0.5, 0.1, 0.5},
visual = "mesh",
@ -37,7 +38,7 @@ mobs:register_mob(
{name = "mobs:wool",
chance = 1, min = 1, max = 2},
},
water_damage = 1,
water_damage = 0,
lava_damage = 5,
light_damage = 0,
animation = {

View File

@ -9,6 +9,7 @@ mobs:register_mob(
passive = false,
attack_type = "dogfight",
damage = 1,
breath_max = 7,
hp_min = 16,
hp_max = 22,
armor = 130,
@ -34,7 +35,7 @@ mobs:register_mob(
{name = "mobs:meat_raw",
chance = 1, min = 1, max = 2},
},
water_damage = 1,
water_damage = 0,
lava_damage = 7,
light_damage = 0,
animation = {

View File

@ -11,6 +11,7 @@ mobs:register_mob(
damage = 3,
hp_min = 8,
hp_max = 16,
breath_max = -1,
armor = 200,
collisionbox = {-0.3, 0, -0.3, 0.3, 1.5, 0.3},
visual = "mesh",