Extra error checking.

This commit is contained in:
Duane 2016-07-15 02:58:33 -05:00
parent aa999e2ed5
commit bf26b8bee1
25 changed files with 897 additions and 314 deletions

116
mobs.lua
View file

@ -1,12 +1,19 @@
-- search/replace -- lets mobs change the terrain
-- used for goblin traps and torch thieving
fun_caves.search_replace = function(pos, search_rate, replace_what, replace_with)
if not (pos and search_rate and replace_what and replace_with and type(search_rate) == 'number' and type(replace_what) == 'string' and type(replace_with) == 'string') then
return
end
if math.random(search_rate) == 1 then
local p1 = vector.subtract(pos, 1)
local p2 = vector.add(pos, 1)
--look for nodes
local nodelist = minetest.find_nodes_in_area(p1, p2, replace_what)
if not (nodelist and type(nodelist) == 'table') then
return
end
if #nodelist > 0 then
for _, new_pos in pairs(nodelist) do
@ -18,6 +25,10 @@ fun_caves.search_replace = function(pos, search_rate, replace_what, replace_with
end
function fun_caves.climb(self)
if not self then
return
end
if self.state == "stand" and math.random() < 0.2 then
if self.fall_speed == 2 then
self.fall_speed = -2
@ -31,44 +42,61 @@ end
-- causes mobs to take damage from hot/cold surfaces
fun_caves.surface_damage = function(self, cold_natured)
--if not self.fun_caves_damage_timer then
-- self.fun_caves_damage_timer = 0
--end
if not self then
return
end
--self.fun_caves_damage_timer = self.fun_caves_damage_timer + 1
--if self.fun_caves_damage_timer > 30 then
-- self.fun_caves_damage_timer = 0
local pos = self.object:getpos()
local minp = vector.subtract(pos, 1.5)
local maxp = vector.add(pos, 1.5)
local counts = 0
if self.lava_damage > 1 then
counts = minetest.find_nodes_in_area(minp, maxp, {"group:surface_hot"})
if #counts > 0 then
self.health = self.health - math.floor(self.lava_damage / 2)
effect(pos, 5, "fire_basic_flame.png")
end
local pos = self.object:getpos()
if not pos then
return
end
local minp = vector.subtract(pos, 1.5)
local maxp = vector.add(pos, 1.5)
local counts = 0
if self.lava_damage > 1 then
counts = minetest.find_nodes_in_area(minp, maxp, {"group:surface_hot"})
if not (counts and type(counts) == 'table') then
return
end
if not cold_natured then
counts = minetest.find_nodes_in_area(minp, maxp, {"group:surface_cold"})
if #counts > 0 then
self.health = self.health - 1
end
if #counts > 0 then
self.health = self.health - math.floor(self.lava_damage / 2)
effect(pos, 5, "fire_basic_flame.png")
end
end
if not cold_natured then
counts = minetest.find_nodes_in_area(minp, maxp, {"group:surface_cold"})
if not (counts and type(counts) == 'table') then
return
end
check_for_death(self)
--end
if #counts > 0 then
self.health = self.health - 1
end
end
check_for_death(self)
end
-- executed in a mob's do_custom() to regulate their actions
-- if false, do nothing
local custom_delay = 2000000
fun_caves.custom_ready = function(self, delay)
if not self then
return
end
local time = minetest.get_us_time()
if not (time and type(time) == 'number') then
return
end
if not delay then
delay = custom_delay
end
if not self.custom_time or time - self.custom_time > delay then
self.custom_time = time
return true
@ -156,12 +184,17 @@ for _, mob in pairs(mob_stats) do
end
local function fun_caves_punch(self, puncher, time_from_last_punch, tool_capabilities, dir)
if not self then
return
end
if puncher and puncher.get_player_name then
local player_name = puncher:get_player_name()
if player_name and player_name ~= '' and fun_caves.db.status[player_name] and fun_caves.db.status[player_name].damage_elixir and tool_capabilities and tool_capabilities.damage_groups and tool_capabilities.damage_groups.fleshy then
if player_name and type(player_name) == 'string' and player_name ~= '' and fun_caves.db.status[player_name] and fun_caves.db.status[player_name].damage_elixir and tool_capabilities and tool_capabilities.damage_groups and tool_capabilities.damage_groups.fleshy then
tool_capabilities.damage_groups.fleshy = tool_capabilities.damage_groups.fleshy + fun_caves.db.status[player_name].damage_elixir.bonus
end
end
self.on_punch_orig(self, puncher, time_from_last_punch, tool_capabilities, dir)
end
@ -214,6 +247,10 @@ if minetest.registered_entities["dmobs:dragon"] and minetest.registered_entities
local m = table.copy(minetest.registered_entities["mobs_yeti:snowball"])
m.hit_player = function(self, player)
if not (self and player) then
return
end
player:punch(self.object, 1.0, {
full_punch_interval = 1.0,
damage_groups = {fleshy = 8},
@ -221,6 +258,10 @@ if minetest.registered_entities["dmobs:dragon"] and minetest.registered_entities
end
m.hit_mob = function(self, player)
if not (self and player) then
return
end
player:punch(self.object, 1.0, {
full_punch_interval = 1.0,
damage_groups = {fleshy = 8},
@ -236,7 +277,7 @@ if minetest.registered_entities["dmobs:fox"] then
-- fire_walk overwrites bones, under some circumstances.
-- Keep it disabled until it's definitely working.
local function fire_walk(self)
if not fun_caves.custom_ready(self, 1000000) then
if not (self and fun_caves.custom_ready(self, 1000000)) then
return
end
@ -246,6 +287,10 @@ if minetest.registered_entities["dmobs:fox"] then
--look for nodes
local nodelist = minetest.find_nodes_in_area(p1, p2, "air")
if not (nodelist and type(nodelist) == 'table') then
return
end
for n in pairs(nodelist) do
--minetest.set_node(pos, {name='fire:basic_flame'})
end
@ -310,7 +355,7 @@ mobs:register_mob("fun_caves:star", {
fall_damage = 0,
lifetimer = 360,
do_custom = function(self)
if not fun_caves.custom_ready(self) then
if not (self and fun_caves.custom_ready(self)) then
return
end
@ -326,7 +371,7 @@ mobs:spawn_specific("fun_caves:star", {'default:stone', 'fun_caves:asteroid_wate
if minetest.registered_entities["mobs:bee"] then
local function bee_summon(self)
if self.state ~= 'attack' then
if not (self and self.state == 'attack') then
return
end
@ -345,11 +390,14 @@ if minetest.registered_entities["mobs:bee"] then
--look for nodes
local nodelist = minetest.find_nodes_in_area(p1, p2, "air")
if not (nodelist and type(nodelist) == 'table') then
return
end
if #nodelist > 0 then
for key,value in pairs(nodelist) do
minetest.add_entity(value, "fun_caves:killer_bee_drone")
print("A bee summons reinforcement.")
print("Fun Caves: A bee summons reinforcement.")
return -- only one at a time
end
end
@ -357,7 +405,7 @@ if minetest.registered_entities["mobs:bee"] then
end
local function bee_do(self)
if not fun_caves.custom_ready(self) then
if not (self and fun_caves.custom_ready(self)) then
return
end
@ -513,7 +561,7 @@ if minetest.registered_entities["mobs_monster:spider"] then
}
m.water_damage = 0
m.do_custom = function(self)
if not fun_caves.custom_ready(self) then
if not (self and fun_caves.custom_ready(self)) then
return
end
@ -540,7 +588,7 @@ if minetest.registered_entities["mobs_monster:spider"] then
}
m.water_damage = 0
m.do_custom = function(self)
if not fun_caves.custom_ready(self) then
if not (self and fun_caves.custom_ready(self)) then
return
end
@ -573,7 +621,7 @@ if minetest.registered_entities["mobs_monster:spider"] then
{name = "farming:cotton", chance = 2, min = 1, max = 2},
}
m.do_custom = function(self)
if not fun_caves.custom_ready(self) then
if not (self and fun_caves.custom_ready(self)) then
return
end
@ -608,6 +656,10 @@ if minetest.registered_entities["mobs_monster:spider"] then
m.jump = false
m.drops = { {name = "mobs:meat_raw", chance = 1, min = 1, max = 1}, }
m.do_custom = function(self)
if not self then
return
end
if not self.fun_caves_damage_timer then
self.fun_caves_damage_timer = 0
end