2016-02-16 19:14:16 +01:00
|
|
|
mobs = {}
|
2016-06-23 20:13:01 +02:00
|
|
|
mobs.mobs = {}
|
2016-02-16 19:14:16 +01:00
|
|
|
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-07-08 15:48:42 +02:00
|
|
|
mobs.mobs[#mobs.mobs+1] = {name, def.lvl}
|
2016-06-23 20:13:01 +02:00
|
|
|
|
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-06-09 18:33:25 +02:00
|
|
|
|
|
|
|
on_punch = function(self, player)
|
|
|
|
if self.object:get_hp() <= 0 then
|
|
|
|
if player and player:is_player() then
|
|
|
|
xp.add_xp(player, def.xp or xp.get_xp(def.lvl, 10))
|
2016-06-10 17:16:00 +02:00
|
|
|
if def.drops then
|
|
|
|
minetest.spawn_item(self.object:getpos(), def.drops[math.random(1, #def.drops)])
|
|
|
|
else
|
|
|
|
minetest.spawn_item(self.object:getpos(), "money:silver_coin")
|
|
|
|
end
|
|
|
|
self.object:remove()
|
2016-06-09 18:33:25 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
|
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
|
2016-06-06 17:03:03 +02:00
|
|
|
local v = {x=math.random(-2, 2), y=(def.gravity or -9.2), z=math.random(-2, 2)}
|
|
|
|
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)
|
2016-05-19 10:56:10 +02:00
|
|
|
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-07-08 15:48:42 +02:00
|
|
|
function mobs.get_mob(lvl)
|
|
|
|
a = {}
|
|
|
|
found_mob = false
|
|
|
|
for i,n in ipairs(mobs.mobs) do
|
|
|
|
if n[2] < lvl +5 and n[2] > lvl-5 then
|
|
|
|
found_mob = true
|
|
|
|
a[#a+1] = n[1]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if found_mob then
|
|
|
|
return a[math.random(1, #a)]
|
|
|
|
end
|
|
|
|
|
|
|
|
a = {}
|
|
|
|
found_mob = false
|
|
|
|
for i,n in ipairs(mobs.mobs) do
|
|
|
|
if n[2] < lvl +5 then
|
|
|
|
found_mob = true
|
|
|
|
a[#a+1] = n[1]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if found_mob then
|
|
|
|
return a[math.random(1, #a)]
|
|
|
|
end
|
|
|
|
|
|
|
|
return mobs.mobs[math.random(1, #mobs.mobs)][1]
|
|
|
|
end
|
|
|
|
|
2016-06-23 20:13:01 +02:00
|
|
|
local timer = 0
|
|
|
|
minetest.register_globalstep(function(dtime)
|
|
|
|
timer = timer + dtime;
|
|
|
|
if timer >= 5 then
|
|
|
|
for _, player in pairs(minetest.get_connected_players()) do
|
|
|
|
local p = player:getpos()
|
|
|
|
local a = {-1, 1}
|
|
|
|
local x = math.random(20, 40)*a[math.random(1,2)] + p.x
|
|
|
|
local z = math.random(20, 40)*a[math.random(1,2)] + p.z
|
|
|
|
if minetest.get_node(vector.new(x, p.y+2, z)).name == "air" then
|
2016-07-08 15:48:42 +02:00
|
|
|
local n = mobs.get_mob(xp.player_levels[player:get_player_name()])
|
|
|
|
minetest.add_entity(vector.new(x, p.y+2, z), n)
|
2016-06-23 20:13:01 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
timer = 0
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
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 = {
|
|
|
|
},
|
2016-03-06 20:21:40 +01:00
|
|
|
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
|
|
|
|
2016-06-06 17:03:03 +02:00
|
|
|
mobs.register_mob("mobs:small_grass_monster", {
|
|
|
|
textures = {"mobs_grass_monster.png",},
|
|
|
|
lvl = 7,
|
|
|
|
hits = 3,
|
|
|
|
visual_size = {x=0.5,y=0.5},
|
|
|
|
dmg = {
|
|
|
|
full_punch_interval = 0.9,
|
|
|
|
max_drop_level = 0,
|
|
|
|
groupcaps = {
|
|
|
|
},
|
|
|
|
damage_groups = {friendly=3},
|
|
|
|
},
|
2016-06-10 17:16:00 +02:00
|
|
|
drops = {"default:grass 5"},
|
2016-06-06 17:03:03 +02:00
|
|
|
collisionbox = {-0.25, -0.25, -0.25, 0.25, 0.25, 0.25},
|
|
|
|
description = "Small Grass Monster",
|
|
|
|
range = 4,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
mobs.register_mob("mobs:grass_monster", {
|
|
|
|
textures = {"mobs_grass_monster.png",},
|
|
|
|
lvl = 22,
|
|
|
|
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-06-10 17:16:00 +02:00
|
|
|
drops = {"default:grass 10"},
|
2016-06-06 17:03:03 +02:00
|
|
|
collisionbox = {-0.6, -0.75, -0.6, 0.6, 0.6, 0.6},
|
|
|
|
description = "Grass Monster",
|
|
|
|
range = 4,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
2016-06-27 18:41:46 +02:00
|
|
|
mobs.register_mob("mobs:angry_cloud", {
|
|
|
|
textures = {"mobs_angry_cloud.png",},
|
|
|
|
lvl = 25,
|
|
|
|
hits = 4,
|
|
|
|
visual_size = {x=1.5,y=1.5},
|
|
|
|
dmg = {
|
|
|
|
full_punch_interval = 0.9,
|
|
|
|
max_drop_level = 0,
|
|
|
|
groupcaps = {
|
|
|
|
},
|
|
|
|
damage_groups = {friendly=4},
|
|
|
|
},
|
|
|
|
collisionbox = {-0.6, -0.25, -0.6, 0.6, 0.25, 0.6},
|
|
|
|
description = "Angry Cloud",
|
|
|
|
range = 5,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
mobs.register_mob("mobs:hedgehog", {
|
|
|
|
textures = {"mobs_hedgehog.png",},
|
|
|
|
lvl = 30,
|
|
|
|
hits = 7,
|
|
|
|
visual_size = {x=1,y=1},
|
|
|
|
dmg = {
|
|
|
|
full_punch_interval = 0.9,
|
|
|
|
max_drop_level = 0,
|
|
|
|
groupcaps = {
|
|
|
|
},
|
|
|
|
damage_groups = {friendly=1},
|
|
|
|
},
|
|
|
|
collisionbox = {-0.3, -0.5, -0.3, 0.3, -0.25, 0.3},
|
|
|
|
description = "Hedgehog",
|
|
|
|
range = 8,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
2016-07-01 13:52:38 +02:00
|
|
|
mobs.register_mob("mobs:book", {
|
|
|
|
textures = {"mobs_book.png",},
|
|
|
|
lvl = 35,
|
|
|
|
hits = 7,
|
|
|
|
visual_size = {x=1,y=1},
|
|
|
|
dmg = {
|
|
|
|
full_punch_interval = 0.9,
|
|
|
|
max_drop_level = 0,
|
|
|
|
groupcaps = {
|
|
|
|
},
|
|
|
|
damage_groups = {friendly=5},
|
|
|
|
},
|
|
|
|
collisionbox = {-0.3, -0.5, -0.3, 0.3, 0.4, 0.3},
|
|
|
|
description = "Book",
|
|
|
|
range = 3,
|
|
|
|
drops = {"money:coin"}
|
|
|
|
})
|
|
|
|
|
|
|
|
mobs.register_mob("mobs:coal_monster", {
|
|
|
|
textures = {"mobs_coal_monster.png",},
|
|
|
|
lvl = 40,
|
|
|
|
hits = 4,
|
|
|
|
visual_size = {x=1,y=1},
|
|
|
|
dmg = {
|
|
|
|
full_punch_interval = 0.9,
|
|
|
|
max_drop_level = 0,
|
|
|
|
groupcaps = {
|
|
|
|
},
|
|
|
|
damage_groups = {friendly=5},
|
|
|
|
},
|
|
|
|
collisionbox = {-0.3, -0.5, -0.3, 0.3, 0.3, 0.3},
|
|
|
|
description = "Coal Monster",
|
|
|
|
range = 6,
|
|
|
|
drops = {"money:coin"}
|
|
|
|
})
|
|
|
|
|
|
|
|
mobs.register_mob("mobs:lava_flower", {
|
|
|
|
textures = {"mobs_lava_flower.png",},
|
|
|
|
lvl = 37,
|
|
|
|
hits = 10,
|
|
|
|
visual_size = {x=1,y=1},
|
|
|
|
dmg = {
|
|
|
|
full_punch_interval = 0.9,
|
|
|
|
max_drop_level = 0,
|
|
|
|
groupcaps = {
|
|
|
|
},
|
|
|
|
damage_groups = {friendly=6},
|
|
|
|
},
|
|
|
|
collisionbox = {-0.3, -0.5, -0.3, 0.3, 0.3, 0.3},
|
|
|
|
description = "Lava Flower",
|
|
|
|
range = 2,
|
|
|
|
drops = {"money:coin 2"}
|
|
|
|
})
|
|
|
|
|