2016-02-16 19:14:16 +01:00
|
|
|
mobs = {}
|
|
|
|
function mobs.get_velocity(v, yaw, y)
|
2015-12-31 11:01:14 +01:00
|
|
|
local x = -math.sin(yaw) * v
|
|
|
|
local z = math.cos(yaw) * v
|
|
|
|
return {x = x, y = y, z = z}
|
|
|
|
end
|
|
|
|
|
2016-02-16 19:14:16 +01:00
|
|
|
function mobs.register_mob(name, def)
|
2016-03-07 17:32:13 +01:00
|
|
|
if not def.hp then
|
|
|
|
if def.lvl and def.hits then
|
|
|
|
def.hp = classes.get_dmg(def.lvl)*def.hits
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-16 19:14:16 +01:00
|
|
|
minetest.register_entity(name, {
|
|
|
|
hp_max = def.hp,
|
|
|
|
physical = true,
|
|
|
|
collisionbox = def.collisionbox,
|
|
|
|
visual = "mesh",
|
|
|
|
mesh = def.mesh,
|
|
|
|
visual_size = {x=1, y=1},
|
|
|
|
textures = def.textures,
|
|
|
|
spritediv = {x=1, y=1},
|
|
|
|
initial_sprite_basepos = {x=0, y=0},
|
|
|
|
is_visible = true,
|
|
|
|
makes_footstep_sound = false,
|
|
|
|
automatic_rotate = true,
|
|
|
|
speed = 0,
|
2016-03-24 16:41:44 +01:00
|
|
|
anim = "",
|
2016-05-19 10:56:10 +02:00
|
|
|
t = 0.0,
|
2016-02-16 19:14:16 +01:00
|
|
|
on_step = function(self, dtime)
|
2016-05-19 10:56:10 +02:00
|
|
|
self.t = self.t + dtime
|
|
|
|
if self.t > 1 then
|
2016-02-16 19:14:16 +01:00
|
|
|
local all_objects = minetest.get_objects_inside_radius(self.object:getpos(), def.range)
|
2016-05-19 10:56:10 +02:00
|
|
|
local found = false
|
2016-02-16 19:14:16 +01:00
|
|
|
local _,obj
|
|
|
|
for _,obj in ipairs(all_objects) do
|
|
|
|
if obj:is_player() then
|
2016-05-19 10:56:10 +02:00
|
|
|
print("[mob] punch player")
|
|
|
|
local v = vector.direction(self.object:getpos(), obj:getpos())
|
|
|
|
v.y = (def.gravity or -9.2)
|
|
|
|
self.object:setvelocity(v)
|
|
|
|
self.object:setyaw(math.atan(v.x, v.z))
|
|
|
|
|
|
|
|
local yaw = math.atan(v.z/v.x)+math.pi/2
|
|
|
|
--yaw = yaw+(math.pi/2)
|
|
|
|
if v.x + self.object:getpos().x > self.object:getpos().x then
|
|
|
|
yaw = yaw+math.pi
|
|
|
|
end
|
|
|
|
self.object:setyaw(yaw)
|
|
|
|
|
|
|
|
found = true
|
2016-02-16 19:14:16 +01:00
|
|
|
obj:punch(self.object, 10, def.dmg, nil)
|
2016-05-19 10:56:10 +02:00
|
|
|
break
|
2016-02-16 19:14:16 +01:00
|
|
|
end
|
2015-12-31 11:01:14 +01:00
|
|
|
end
|
2016-05-19 10:56:10 +02:00
|
|
|
|
|
|
|
if not found then
|
|
|
|
all_objects = minetest.get_objects_inside_radius(self.object:getpos(), 10)
|
|
|
|
for _,obj in ipairs(all_objects) do
|
|
|
|
if obj:is_player() then
|
|
|
|
local obj_p = obj:getpos()
|
|
|
|
local p = self.object:getpos()
|
|
|
|
local v = vector.multiply(vector.direction(p, obj_p), 4)
|
|
|
|
local d = obj_p.y - p.y
|
|
|
|
if d > 0 and d < 2 then
|
|
|
|
v.y = 2
|
|
|
|
else
|
|
|
|
v.y = (def.gravity or -9.2)
|
|
|
|
end
|
|
|
|
self.object:setvelocity(v)
|
|
|
|
|
|
|
|
local yaw = math.atan(v.z/v.x)+math.pi/2
|
|
|
|
--yaw = yaw+(math.pi/2)
|
|
|
|
if v.x + self.object:getpos().x > self.object:getpos().x then
|
|
|
|
yaw = yaw+math.pi
|
|
|
|
end
|
|
|
|
|
|
|
|
self.object:setyaw(yaw)
|
|
|
|
found = true
|
|
|
|
break
|
|
|
|
end
|
2016-03-24 16:41:44 +01:00
|
|
|
end
|
|
|
|
end
|
2016-05-19 10:56:10 +02:00
|
|
|
|
|
|
|
if not found then
|
|
|
|
self.object:setvelocity({x=math.random(-2, 2), y=(def.gravity or -9.2), z=math.random(-2, 2)})
|
|
|
|
end
|
|
|
|
self.t = 0
|
2015-12-31 11:01:14 +01:00
|
|
|
end
|
2016-02-16 19:14:16 +01:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craftitem(name, {
|
|
|
|
description = def.description,
|
|
|
|
inventory_image = "mobs_spawn.png",
|
2015-12-31 11:01:14 +01:00
|
|
|
|
2016-02-16 19:14:16 +01:00
|
|
|
on_place = function(itemstack, placer, pointed_thing)
|
|
|
|
if pointed_thing.type ~= "node" then
|
|
|
|
return
|
|
|
|
end
|
2016-03-24 16:41:44 +01:00
|
|
|
local p = {x=pointed_thing.above.x, y=pointed_thing.above.y+2, z=pointed_thing.above.z}
|
|
|
|
minetest.add_entity(p, name)
|
2016-02-16 19:14:16 +01:00
|
|
|
if not minetest.setting_getbool("creative_mode") then
|
|
|
|
itemstack:take_item()
|
|
|
|
end
|
|
|
|
return itemstack
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
end
|
2015-12-31 11:01:14 +01:00
|
|
|
|
2016-02-16 19:14:16 +01:00
|
|
|
mobs.register_mob("mobs:angry_player", {
|
|
|
|
mesh = "character.x",
|
|
|
|
textures = {"character.png",},
|
2016-03-07 17:32:13 +01:00
|
|
|
lvl = 3,
|
|
|
|
hits = 6,
|
2016-02-16 19:14:16 +01:00
|
|
|
dmg = {
|
|
|
|
full_punch_interval = 0.9,
|
|
|
|
max_drop_level = 0,
|
|
|
|
groupcaps = {
|
|
|
|
},
|
2016-03-06 20:21:40 +01:00
|
|
|
damage_groups = {friendly=3},
|
2016-02-16 19:14:16 +01:00
|
|
|
},
|
|
|
|
collisionbox = {-0.3, -1, -0.3, 0.3, 0.5, 0.3},
|
|
|
|
description = "Angry Player",
|
|
|
|
range = 3,
|
2015-12-31 11:01:14 +01:00
|
|
|
})
|
2016-03-24 16:41:44 +01:00
|
|
|
|
|
|
|
mobs.register_mob("mobs:fire_cube", {
|
|
|
|
mesh = "mobs_fire_cube.x",
|
|
|
|
textures = {"mobs_fire_cube.png",},
|
|
|
|
lvl = 5,
|
|
|
|
hits = 6,
|
|
|
|
dmg = {
|
|
|
|
full_punch_interval = 0.9,
|
|
|
|
max_drop_level = 0,
|
|
|
|
groupcaps = {
|
|
|
|
},
|
|
|
|
damage_groups = {friendly=4},
|
|
|
|
},
|
|
|
|
collisionbox = {-1, -1, -1, 1, 1, 1},
|
|
|
|
description = "Fire Cube",
|
|
|
|
range = 5,
|
|
|
|
animations = {
|
|
|
|
walk = {x=0, y=30},
|
|
|
|
punch = {x=35, y = 60}
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
mobs.register_mob("mobs:water_cube", {
|
|
|
|
mesh = "mobs_fire_cube.x",
|
|
|
|
textures = {"mobs_water_cube.png",},
|
|
|
|
lvl = 10,
|
|
|
|
hits = 6,
|
|
|
|
dmg = {
|
|
|
|
full_punch_interval = 0.9,
|
|
|
|
max_drop_level = 0,
|
|
|
|
groupcaps = {
|
|
|
|
},
|
|
|
|
damage_groups = {friendly=5},
|
|
|
|
},
|
|
|
|
collisionbox = {-1, -1, -1, 1, 1, 1},
|
|
|
|
description = "Water Cube",
|
|
|
|
range = 5,
|
|
|
|
animations = {
|
|
|
|
walk = {x=0, y=30},
|
|
|
|
punch = {x=35, y = 60}
|
|
|
|
},
|
|
|
|
})
|