Restructure on_step a bit

This commit is contained in:
cora 2022-11-11 23:57:17 +01:00
parent 3c6d79ecb3
commit 4909ef6ff7
2 changed files with 50 additions and 49 deletions

View file

@ -297,6 +297,8 @@ function mob_class:mob_activate(staticdata, def, dtime)
end end
end end
-- main mob function -- main mob function
function mob_class:on_step(dtime) function mob_class:on_step(dtime)
self.lifetimer = self.lifetimer - dtime self.lifetimer = self.lifetimer - dtime
@ -315,7 +317,30 @@ function mob_class:on_step(dtime)
if self:falling(pos) then return end if self:falling(pos) then return end
self:check_suspend() self:check_suspend()
self:check_aggro(dtime) self:check_water_flow()
local yaw = 0
if self:is_at_water_danger() and self.state ~= "attack" then
if math.random(1, 10) <= 6 then
self:set_velocity(0)
self.state = "stand"
self:set_animation( "stand")
yaw = yaw + math.random(-0.5, 0.5)
yaw = self:set_yaw( yaw, 8)
end
else
if self.move_in_group ~= false then
self:check_herd(dtime)
end
end
if self:is_at_cliff_or_danger() then
self:set_velocity(0)
self.state = "stand"
self:set_animation( "stand")
local yaw = self.object:get_yaw() or 0
yaw = self:set_yaw( yaw + 0.78, 8)
end
if not self.fire_resistant then if not self.fire_resistant then
mcl_burning.tick(self.object, dtime, self) mcl_burning.tick(self.object, dtime, self)
@ -341,6 +366,15 @@ function mob_class:on_step(dtime)
self:check_smooth_rotation() self:check_smooth_rotation()
self:check_head_swivel() self:check_head_swivel()
self:do_jump()
self:set_armor_texture()
self:check_runaway_from()
self:monster_attack()
self:npc_attack()
self:check_breeding()
self:check_aggro(dtime)
-- run custom function (defined in mob lua file) -- run custom function (defined in mob lua file)
if self.do_custom then if self.do_custom then
@ -397,10 +431,6 @@ function mob_class:on_step(dtime)
self:replace(pos) self:replace(pos)
end end
self:monster_attack()
self:npc_attack()
self:check_breeding()
if self:do_states(dtime) then if self:do_states(dtime) then
return return
end end
@ -408,34 +438,6 @@ function mob_class:on_step(dtime)
if not self.object:get_luaentity() then if not self.object:get_luaentity() then
return false return false
end end
self:do_jump()
self:set_armor_texture()
self:check_runaway_from()
local yaw = 0
if self:is_at_water_danger() and self.state ~= "attack" then
if math.random(1, 10) <= 6 then
self:set_velocity(0)
self.state = "stand"
self:set_animation( "stand")
yaw = yaw + math.random(-0.5, 0.5)
yaw = self:set_yaw( yaw, 8)
end
else
if self.move_in_group ~= false then
self:check_herd(dtime)
end
end
self:check_water_flow()
if self:is_at_cliff_or_danger() then
self:set_velocity(0)
self.state = "stand"
self:set_animation( "stand")
local yaw = self.object:get_yaw() or 0
yaw = self:set_yaw( yaw + 0.78, 8)
end
end end
local timer = 0 local timer = 0

View file

@ -552,9 +552,21 @@ function mob_class:check_for_death(cause, cmi_cause)
return true return true
end end
-- Deal light damage to mob, returns true if mob died
function mob_class:deal_light_damage(pos, damage)
if not ((mcl_weather.rain.raining or mcl_weather.state == "snow") and mcl_weather.is_outdoor(pos)) then
self.health = self.health - damage
mcl_mobs.effect(pos, 5, "mcl_particles_smoke.png")
if self:check_for_death("light", {type = "light"}) then
return true
end
end
end
-- environmental damage (water, lava, fire, light etc.) -- environmental damage (water, lava, fire, light etc.)
function mob_class:do_env_damage() function mob_class:do_env_damage()
-- feed/tame text timer (so mob 'full' messages dont spam chat) -- feed/tame text timer (so mob 'full' messages dont spam chat)
if self.htimer > 0 then if self.htimer > 0 then
self.htimer = self.htimer - 1 self.htimer = self.htimer - 1
@ -580,19 +592,6 @@ function mob_class:do_env_damage()
return true return true
end end
-- Deal light damage to mob, returns true if mob died
local function deal_light_damage(self, pos, damage)
if not ((mcl_weather.rain.raining or mcl_weather.state == "snow") and mcl_weather.is_outdoor(pos)) then
self.health = self.health - damage
mcl_mobs.effect(pos, 5, "mcl_particles_smoke.png")
if self:check_for_death("light", {type = "light"}) then
return true
end
end
end
local sunlight = 10 local sunlight = 10
if within_limits(pos,0) then if within_limits(pos,0) then
sunlight = minetest.get_natural_light(pos, self.time_of_day) sunlight = minetest.get_natural_light(pos, self.time_of_day)
@ -600,7 +599,7 @@ function mob_class:do_env_damage()
-- bright light harms mob -- bright light harms mob
if self.light_damage ~= 0 and (sunlight or 0) > 12 then if self.light_damage ~= 0 and (sunlight or 0) > 12 then
if deal_light_damage(self, pos, self.light_damage) then if self:deal_light_damage(pos, self.light_damage) then
return true return true
end end
end end
@ -610,7 +609,7 @@ function mob_class:do_env_damage()
if self.ignited_by_sunlight then if self.ignited_by_sunlight then
mcl_burning.set_on_fire(self.object, 10) mcl_burning.set_on_fire(self.object, 10)
else else
deal_light_damage(self, pos, self.sunlight_damage) self:deal_light_damage(pos, self.sunlight_damage)
return true return true
end end
end end