1
0
Fork 0

Implement skeletons/strays

This commit is contained in:
jordan4ibanez 2021-04-21 12:42:34 -04:00
parent 99e808296b
commit c9f71d66f5
5 changed files with 83 additions and 2 deletions

View File

@ -324,6 +324,7 @@ function mobs:register_mob(name, def)
attacking = nil,
visual_size_origin = def.visual_size or {x = 1, y = 1, z = 1},
punch_timer_cooloff = def.punch_timer_cooloff or 0.5,
projectile_cooldown = projectile_cooldown or 2,
--end j4i stuff
-- MCL2 extensions

View File

@ -168,6 +168,10 @@ local land_state_execution = function(self,dtime)
mobs.punch_attack_walk(self,dtime)
elseif self.attack_type == "projectile" then
mobs.projectile_attack_walk(self,dtime)
end
end

View File

@ -2,6 +2,7 @@ local vector_direction = vector.direction
local minetest_dir_to_yaw = minetest.dir_to_yaw
local vector_distance = vector.distance
local vector_multiply = vector.multiply
--[[
_____ _ _
| ___| | | | |
@ -152,3 +153,57 @@ mobs.punch_attack = function(self)
self.attacking:add_velocity(dir)
end
--[[
______ _ _ _ _
| ___ \ (_) | | (_) |
| |_/ / __ ___ _ ___ ___| |_ _| | ___
| __/ '__/ _ \| |/ _ \/ __| __| | |/ _ \
| | | | | (_) | | __/ (__| |_| | | __/
\_| |_| \___/| |\___|\___|\__|_|_|\___|
_/ |
|__/
]]--
mobs.projectile_attack_walk = function(self,dtime)
--this needs an exception
if self.attacking == nil or not self.attacking:is_player() then
self.attacking = nil
return
end
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_velocity(self, self.run_velocity)
mobs.set_mob_animation(self,"run")
else
mobs.set_velocity(self,0)
mobs.set_mob_animation(self,"stand")
end
--do this to not load data into other mobs
if not self.projectile_timer then
self.projectile_timer = self.projectile_cooldown
end
if self.projectile_timer > 0 then
self.projectile_timer = self.projectile_timer - dtime
--shoot
if self.projectile_timer <= 0 then
--reset timer
self.projectile_timer = self.projectile_cooldown
mobs.shoot_projectile(self)
end
end
end

View File

@ -1,4 +1,5 @@
local math_floor = math.floor
local vector_direction = vector.direction
mobs.feed_tame = function(self)
return nil
@ -337,3 +338,21 @@ mobs.mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
end
]]--
end
--do internal per mob projectile calculations
mobs.shoot_projectile = function(self)
local pos1 = self.object:get_pos()
--add mob eye height
pos1.y = pos1.y + self.eye_height
local pos2 = self.attacking:get_pos()
--add player eye height
pos2.y = pos2.y + self.attacking:get_properties().eye_height
--get direction
local dir = vector_direction(pos1,pos2)
--call internal shoot_arrow function
self.shoot_arrow(self,pos1,dir)
end

View File

@ -22,6 +22,8 @@ local skeleton = {
xp_min = 6,
xp_max = 6,
breath_max = -1,
eye_height = 1.5,
projectile_cooldown = 1.5,
armor = {undead = 100, fleshy = 100},
collisionbox = {-0.3, -0.01, -0.3, 0.3, 1.98, 0.3},
pathfinding = 1,
@ -43,7 +45,7 @@ local skeleton = {
walk_velocity = 1.2,
run_velocity = 2.4,
damage = 2,
reach = 2,
reach = 3,
drops = {
{name = mobs_mc.items.arrow,
chance = 1,