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,
projectile_cooldown_min = def.projectile_cooldown_min or 2,
projectile_cooldown_max = def.projectile_cooldown_max or 6,
skittish = def.skittish,
--end j4i stuff
-- MCL2 extensions

View File

@ -67,13 +67,26 @@ local land_state_list_wandering = {"stand", "walk"}
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
self.state = "attack"
return
end
--do math after sure not attacking
self.state_timer = self.state_timer - dtime
if self.state_timer <= 0 then
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
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
@ -652,7 +695,7 @@ mobs.mob_step = function(self, dtime)
self.object:remove()
return false
end
--do death logic (animation, poof, explosion, etc)
if self.health <= 0 then

View File

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

View File

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

View File

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