Add skittish behavior (runaway from punch) and fix ocelot

This commit is contained in:
jordan4ibanez 2021-04-23 17:10:44 -04:00
parent 8daf197fb8
commit af4c42fea7
5 changed files with 67 additions and 18 deletions

View file

@ -337,6 +337,7 @@ function mobs:register_mob(name, def)
fall_slow = def.fall_slow, fall_slow = def.fall_slow,
projectile_cooldown_min = def.projectile_cooldown_min or 2, projectile_cooldown_min = def.projectile_cooldown_min or 2,
projectile_cooldown_max = def.projectile_cooldown_max or 6, projectile_cooldown_max = def.projectile_cooldown_max or 6,
skittish = def.skittish,
--end j4i stuff --end j4i stuff
-- MCL2 extensions -- MCL2 extensions

View file

@ -67,13 +67,26 @@ local land_state_list_wandering = {"stand", "walk"}
local land_state_switch = function(self, dtime) local land_state_switch = function(self, dtime)
--do math after sure not attacking or running away
self.state_timer = self.state_timer - dtime
--only run away
if self.skittish and self.state == "run" then
self.run_timer = self.run_timer - dtime
if self.run_timer > 0 then
return
end
--continue
end
--only attack
if self.hostile and self.attacking then if self.hostile and self.attacking then
self.state = "attack" self.state = "attack"
return return
end end
--do math after sure not attacking
self.state_timer = self.state_timer - dtime
if self.state_timer <= 0 then if self.state_timer <= 0 then
self.state_timer = math.random(4,10) + math.random() self.state_timer = math.random(4,10) + math.random()
@ -185,7 +198,37 @@ local land_state_execution = function(self,dtime)
elseif self.state == "run" then elseif self.state == "run" then
print("run") --do animation
mobs.set_mob_animation(self, "run")
--enable rotation locking
mobs.movement_rotation_lock(self)
--check for nodes to jump over
local node_in_front_of = mobs.jump_check(self)
if node_in_front_of == 1 then
mobs.jump(self)
--turn if on the edge of cliff
--(this is written like this because unlike
--jump_check which simply tells the mob to jump
--this requires a mob to turn, removing the
--ease of a full implementation for it in a single
--function)
elseif node_in_front_of == 2 or (self.fear_height ~= 0 and cliff_check(self,dtime)) then
--turn 45 degrees if so
quick_rotate(self,dtime)
--stop the mob so it doesn't fall off
mobs.set_velocity(self,0)
end
--only move forward if path is clear
if node_in_front_of == 0 or node_in_front_of == 1 then
--set the velocity of the mob
mobs.set_velocity(self,self.run_velocity)
end
elseif self.state == "attack" then elseif self.state == "attack" then

View file

@ -1,5 +1,6 @@
local minetest_after = minetest.after local minetest_after = minetest.after
local minetest_sound_play = minetest.sound_play local minetest_sound_play = minetest.sound_play
local minetest_dir_to_yaw = minetest.dir_to_yaw
local math_floor = math.floor local math_floor = math.floor
local math_min = math.min local math_min = math.min
@ -63,21 +64,24 @@ mobs.mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
return return
end end
--neutral passive mobs switch to neutral hostile --turn skittish mobs away and RUN
if self.neutral then if self.skittish then
--drop in variables for attacking (stops crash) self.state = "run"
self.attacking = hitter
self.punch_timer = 0
self.hostile = true self.run_timer = 5 --arbitrary 5 seconds
--hostile_cooldown timer is initialized here
self.hostile_cooldown_timer = self.hostile_cooldown
--initialize the group attack (check for other mobs in area, make them neutral hostile) local pos1 = self.object:get_pos()
if self.group_attack then pos1.y = 0
mobs.group_attack_initialization(self) local pos2 = hitter:get_pos()
end pos2.y = 0
local dir = vector_direction(pos2,pos1)
local yaw = minetest_dir_to_yaw(dir)
self.yaw = yaw
end end

View file

@ -18,7 +18,6 @@ mobs:register_mob("mobs_mc:iron_golem", {
rotate = 270, rotate = 270,
hp_min = 100, hp_min = 100,
hp_max = 100, hp_max = 100,
rotate = 270,
protect = true, protect = true,
neutral = true, neutral = true,
breath_max = -1, breath_max = -1,

View file

@ -30,6 +30,8 @@ local ocelot = {
type = "animal", type = "animal",
spawn_class = "passive", spawn_class = "passive",
can_despawn = true, can_despawn = true,
rotate = 270,
skittish = true,
hp_min = 10, hp_min = 10,
hp_max = 10, hp_max = 10,
xp_min = 1, xp_min = 1,