master
runs 2020-05-13 18:55:27 +02:00
parent 55e638ad1e
commit 905d91a79a
4 changed files with 106 additions and 6 deletions

View File

@ -261,7 +261,7 @@ function petz.bh_attack_player(self, pos, prty, player)
elseif self.can_fly then
mobkit.hq_flyhunt(self, prty, player)
else
mobkit.hq_hunt(self, prty, player) -- try to repel them
petz.hq_hunt(self, prty, player) -- try to repel them
end
return true
else
@ -284,6 +284,104 @@ function petz.bh_attack_player(self, pos, prty, player)
end
end
function petz.hq_hunt(self,prty,tgtobj)
local func = function(self)
if not mobkit.is_alive(tgtobj) then return true end
if mobkit.is_queue_empty_low(self) and self.isonground then
local pos = mobkit.get_stand_pos(self)
local opos = tgtobj:get_pos()
local dist = vector.distance(pos,opos)
if dist > self.view_range then
return true
elseif dist > 3 then
mobkit.goto_next_waypoint(self,opos)
else
petz.hq_attack(self,prty+1,tgtobj)
end
end
end
mobkit.queue_high(self,func,prty)
end
function petz.is_pos_in_box(self, pos,bpos,box)
if not self.collisionbox_offset then
self.collisionbox_offset = {x=0, y=0, z= 0}
end
return pos.x > bpos.x+box[1]+(self.collisionbox_offset.x or 0) and pos.x < bpos.x+box[4]+(self.collisionbox_offset.x or 0) and
pos.y > bpos.y+box[2]+(self.collisionbox_offset.y or 0) and pos.y < bpos.y+box[5]+(self.collisionbox_offset.y or 0) and
pos.z > bpos.z+box[3]+(self.collisionbox_offset.z or 0) and pos.z < bpos.z+box[6]+(self.collisionbox_offset.z or 0)
end
function petz.hq_attack(self,prty,tgtobj)
local func = function(self)
if not mobkit.is_alive(tgtobj) then return true end
if mobkit.is_queue_empty_low(self) then
local pos = mobkit.get_stand_pos(self)
-- local tpos = tgtobj:get_pos()
local tpos = mobkit.get_stand_pos(tgtobj)
local dist = vector.distance(pos,tpos)
if dist > 3 then
return true
else
mobkit.lq_turn2pos(self,tpos)
local height = tgtobj:is_player() and 0.35 or tgtobj:get_luaentity().height*0.6
if tpos.y+height>pos.y then
petz.lq_jumpattack(self,tpos.y+height-pos.y,tgtobj)
else
mobkit.lq_dumbwalk(self,mobkit.pos_shift(tpos,{x=math.random()-0.5,z=math.random()-0.5}))
end
end
end
end
mobkit.queue_high(self,func,prty)
end
function petz.lq_jumpattack(self,height,target)
local phase=1
local timer=0.5
local tgtbox = target:get_properties().collisionbox
local func=function(self)
if not mobkit.is_alive(target) then return true end
if self.isonground then
if phase==1 then -- collision bug workaround
local vel = self.object:get_velocity()
vel.y = -mobkit.gravity*math.sqrt(height*2/-mobkit.gravity)
self.object:set_velocity(vel)
mobkit.make_sound(self,'charge')
phase=2
else
mobkit.lq_idle(self,0.3)
return true
end
elseif phase==2 then
local dir = minetest.yaw_to_dir(self.object:get_yaw())
local vy = self.object:get_velocity().y
dir=vector.multiply(dir,6)
dir.y=vy
self.object:set_velocity(dir)
phase=3
elseif phase==3 then -- in air
local tgtpos = target:get_pos()
local pos = self.object:get_pos()
-- calculate attack spot
local yaw = self.object:get_yaw()
local dir = minetest.yaw_to_dir(yaw)
local apos = mobkit.pos_translate2d(pos,yaw,self.attack.range)
if petz.is_pos_in_box(self,apos,tgtpos,tgtbox) then --bite
target:punch(self.object,1,self.attack)
-- bounce off
local vy = self.object:get_velocity().y
self.object:set_velocity({x=dir.x*-3,y=vy,z=dir.z*-3})
-- play attack sound if defined
mobkit.make_sound(self,'attack')
phase=4
end
end
end
mobkit.queue_low(self,func)
end
petz.bh_afraid= function(self, pos)
petz.lookback(self, pos)
local x = self.object:get_velocity().x

View File

@ -268,7 +268,7 @@ function petz.predator_brain(self)
local prey = mobkit.get_closest_entity(self, preys[i]) -- look for prey
if prey then
--minetest.chat_send_player("singleplayer", "got it")
mobkit.hq_hunt(self, 12, prey) -- and chase it
petz.hq_hunt(self, 12, prey) -- and chase it
return
end
end
@ -557,7 +557,7 @@ function petz.semiaquatic_brain(self)
if petz.isinliquid(self) then
mobkit.hq_aqua_attack(self, 10, player, 6) -- get revenge
else
mobkit.hq_hunt(self, 10, player)
petz.hq_hunt(self, 10, player)
end
end
end
@ -634,7 +634,7 @@ function petz.monster_brain(self)
if prey then
self.max_speed = 2.5
--minetest.chat_send_player("singleplayer", "got it")
mobkit.hq_hunt(self, 12, prey) -- and chase it
petz.hq_hunt(self, 12, prey) -- and chase it
return
end
end
@ -654,7 +654,7 @@ function petz.monster_brain(self)
local player_pos = player:get_pos()
if vector.distance(pos, player_pos) <= self.view_range then -- if player close
self.max_speed = 2.5
mobkit.hq_hunt(self, 10, player)
petz.hq_hunt(self, 10, player)
return
end
end

View File

@ -4,7 +4,7 @@
local S = ...
local pet_name = "grizzly"
local scale_model = 2.8
local scale_model = 2.2
petz.grizzly = {}
local mesh = 'petz_grizzly.b3d'
local textures= {"petz_grizzly.png", "petz_grizzly2.png"}
@ -32,6 +32,7 @@ minetest.register_entity("petz:"..pet_name,{
stepheight = 0.1, --EVIL!
collide_with_objects = true,
collisionbox = collisionbox,
collisionbox_offset = {x=0.75, y =0.0, z=0.75},
visual = petz.settings.visual,
mesh = mesh,
textures = textures,

View File

@ -31,6 +31,7 @@ minetest.register_entity("petz:"..pet_name,{
stepheight = 0.1, --EVIL!
collide_with_objects = true,
collisionbox = collisionbox,
collisionbox_offset = {x=0, y =0.5, z=0},
visual = petz.settings.visual,
mesh = mesh,
textures = textures,