182 lines
4.1 KiB
Lua
Raw Normal View History

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,
2016-06-01 16:55:21 +02:00
visual = "upright_sprite",
visual_size = def.visual_size or {x=1, y=1},
2016-02-16 19:14:16 +01:00
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-06-01 16:55:21 +02:00
--mobs
mobs.register_mob("mobs:slime", {
textures = {"mobs_slime.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 = {
},
damage_groups = {friendly=3},
2016-02-16 19:14:16 +01:00
},
2016-06-01 16:55:21 +02:00
collisionbox = {-0.4, -0.5, -0.4, 0.4, 0.5, 0.4},
description = "Slime",
2016-02-16 19:14:16 +01:00
range = 3,
2015-12-31 11:01:14 +01:00
})
2016-03-24 16:41:44 +01:00
2016-06-01 16:55:21 +02:00
mobs.register_mob("mobs:big_slime", {
textures = {"mobs_slime.png",},
lvl = 7,
2016-03-24 16:41:44 +01:00
hits = 6,
2016-06-01 16:55:21 +02:00
visual_size = {x=2,y=2},
2016-03-24 16:41:44 +01:00
dmg = {
full_punch_interval = 0.9,
max_drop_level = 0,
groupcaps = {
},
2016-06-01 16:55:21 +02:00
damage_groups = {friendly=3},
2016-03-24 16:41:44 +01:00
},
2016-06-01 16:55:21 +02:00
collisionbox = {-0.9, -1, -0.9, 0.9, 1, 0.9},
description = "Big Slime",
range = 3,
2016-03-24 16:41:44 +01:00
})
2016-06-01 16:55:21 +02:00
mobs.register_mob("mobs:dungeon_guardian", {
textures = {"mobs_dungeon_guardian.png",},
lvl = 15,
2016-03-24 16:41:44 +01:00
hits = 6,
2016-06-01 16:55:21 +02:00
visual_size = {x=2,y=2},
2016-03-24 16:41:44 +01:00
dmg = {
full_punch_interval = 0.9,
max_drop_level = 0,
groupcaps = {
},
2016-06-01 16:55:21 +02:00
damage_groups = {friendly=3},
2016-03-24 16:41:44 +01:00
},
2016-06-01 16:55:21 +02:00
collisionbox = {-0.8, -1, -0.8, 0.8, 1, 0.8},
description = "Dungeon Guardian",
range = 4,
})
mobs.register_mob("mobs:blue_cube", {
textures = {"mobs_blue_cube.png",},
lvl = 20,
hits = 6,
visual_size = {x=1.5,y=1.5},
dmg = {
full_punch_interval = 0.9,
max_drop_level = 0,
groupcaps = {
},
damage_groups = {friendly=3},
2016-03-24 16:41:44 +01:00
},
2016-06-01 16:55:21 +02:00
collisionbox = {-0.6, -0.75, -0.6, 0.6, 0.75, 0.6},
description = "Blue Cube",
range = 4,
2016-03-24 16:41:44 +01:00
})
2016-06-01 16:55:21 +02:00