Merge pull request 'Give mobs 6 seconds of memory to prevent strange behavior when player hides behind something' (#1639) from jordan4ibanez/MineClone2:mineclone5 into mineclone5
Reviewed-on: MineClone2/MineClone2#1639
This commit is contained in:
commit
b937b20158
|
@ -328,6 +328,9 @@ function mobs:register_mob(name, def)
|
|||
|
||||
minimum_follow_distance = def.minimum_follow_distance or 0.5, --make mobs not freak out when underneath
|
||||
|
||||
memory = 0, -- memory timer if chasing/following
|
||||
fly_random_while_attack = def.fly_random_while_attack,
|
||||
|
||||
--for spiders
|
||||
always_climb = def.always_climb,
|
||||
|
||||
|
|
|
@ -481,7 +481,7 @@ local swim_state_execution = function(self,dtime)
|
|||
self.yaw = (math_random() * (math.pi * 2))
|
||||
|
||||
--create a truly random pitch, since there is no easy access to pitch math that I can find
|
||||
self.pitch = math_random() * random_pitch_multiplier[math_random(1,2)]
|
||||
self.pitch = math_random() * math.random(1,3) * random_pitch_multiplier[math_random(1,2)]
|
||||
end
|
||||
|
||||
--do animation
|
||||
|
@ -626,7 +626,7 @@ local fly_state_execution = function(self,dtime)
|
|||
self.yaw = (math_random() * (math.pi * 2))
|
||||
|
||||
--create a truly random pitch, since there is no easy access to pitch math that I can find
|
||||
self.pitch = math_random() * random_pitch_multiplier[math_random(1,2)]
|
||||
self.pitch = math_random() * math.random(1,3) * random_pitch_multiplier[math_random(1,2)]
|
||||
end
|
||||
|
||||
--do animation
|
||||
|
@ -899,16 +899,32 @@ mobs.mob_step = function(self, dtime)
|
|||
--go get the closest player
|
||||
if attacking then
|
||||
|
||||
self.memory = 6 --6 seconds of memory
|
||||
|
||||
--set initial punch timer
|
||||
if self.attacking == nil then
|
||||
if self.attack_type == "punch" then
|
||||
self.punch_timer = -1
|
||||
end
|
||||
end
|
||||
|
||||
self.attacking = attacking
|
||||
|
||||
--no player in area
|
||||
elseif self.memory > 0 then
|
||||
--try to remember
|
||||
self.memory = self.memory - dtime
|
||||
--get if memory player is within viewing range
|
||||
if self.attacking and self.attacking:is_player() then
|
||||
local distance = vector_distance(self.object:get_pos(), self.attacking:get_pos())
|
||||
if distance > self.view_range then
|
||||
self.memory = 0
|
||||
end
|
||||
--out of viewing range, forget em
|
||||
else
|
||||
self.memory = 0
|
||||
end
|
||||
|
||||
if self.memory <= 0 then
|
||||
|
||||
--reset states when coming out of hostile state
|
||||
if self.attacking ~= nil then
|
||||
|
@ -916,6 +932,8 @@ mobs.mob_step = function(self, dtime)
|
|||
end
|
||||
|
||||
self.attacking = nil
|
||||
self.memory = 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -279,6 +279,8 @@ ______ _ _ _ _
|
|||
|__/
|
||||
]]--
|
||||
|
||||
local random_pitch_multiplier = {-1,1}
|
||||
|
||||
mobs.projectile_attack_fly = function(self, dtime)
|
||||
|
||||
--this needs an exception
|
||||
|
@ -287,19 +289,42 @@ mobs.projectile_attack_fly = function(self, dtime)
|
|||
return
|
||||
end
|
||||
|
||||
--this is specifically for random ghast movement
|
||||
if self.fly_random_while_attack then
|
||||
|
||||
--enable rotation locking
|
||||
mobs.movement_rotation_lock(self)
|
||||
|
||||
self.walk_timer = self.walk_timer - dtime
|
||||
|
||||
--reset the walk timer
|
||||
if self.walk_timer <= 0 then
|
||||
--re-randomize the walk timer
|
||||
self.walk_timer = math.random(1,6) + math.random()
|
||||
--set the mob into a random direction
|
||||
self.yaw = (math_random() * (math.pi * 2))
|
||||
--create a truly random pitch, since there is no easy access to pitch math that I can find
|
||||
self.pitch = math_random() * math.random(1,3) * random_pitch_multiplier[math_random(1,2)]
|
||||
end
|
||||
|
||||
mobs.set_fly_velocity(self, self.run_velocity)
|
||||
|
||||
else
|
||||
|
||||
mobs.set_yaw_while_attacking(self)
|
||||
|
||||
local distance_from_attacking = vector_distance(self.object:get_pos(), self.attacking:get_pos())
|
||||
|
||||
if distance_from_attacking >= self.reach then
|
||||
mobs.set_yaw_while_attacking(self)
|
||||
mobs.set_pitch_while_attacking(self)
|
||||
mobs.set_fly_velocity(self, self.run_velocity)
|
||||
mobs.set_mob_animation(self,"run")
|
||||
else
|
||||
mobs.set_yaw_while_attacking(self)
|
||||
mobs.set_pitch_while_attacking(self)
|
||||
mobs.set_fly_velocity(self, 0)
|
||||
mobs.set_mob_animation(self,"stand")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--do this to not load data into other mobs
|
||||
|
@ -313,6 +338,11 @@ mobs.projectile_attack_fly = function(self, dtime)
|
|||
|
||||
--shoot
|
||||
if self.projectile_timer <= 0 then
|
||||
|
||||
if self.fly_random_while_attack then
|
||||
mobs.set_yaw_while_attacking(self)
|
||||
self.walk_timer = 0
|
||||
end
|
||||
--reset timer
|
||||
self.projectile_timer = math_random(self.projectile_cooldown_min, self.projectile_cooldown_max)
|
||||
mobs.shoot_projectile(self)
|
||||
|
|
|
@ -15,6 +15,7 @@ mobs:register_mob("mobs_mc:ghast", {
|
|||
spawn_class = "hostile",
|
||||
group_attack = true,
|
||||
hostile = true,
|
||||
fly_random_while_attack = true,
|
||||
hp_min = 10,
|
||||
hp_max = 10,
|
||||
rotate = 270,
|
||||
|
|
Loading…
Reference in New Issue