spawners/spawners_env/spawners_env.lua

264 lines
7.3 KiB
Lua
Raw Permalink Normal View History

2018-11-22 15:13:38 -08:00
--
2016-10-12 14:49:57 -07:00
-- * CREATE ALL SPAWNERS NODES *
2018-11-22 15:13:38 -08:00
--
2016-10-12 14:49:57 -07:00
2016-12-15 15:09:41 -08:00
function spawners_env.create(mob_name, mod_prefix, size, offset, mesh, texture, night_only, sound_custom, env, boss)
2018-11-22 15:13:38 -08:00
--
2016-10-12 14:49:57 -07:00
-- DUMMY INSIDE THE SPAWNER
2018-11-22 15:13:38 -08:00
--
2016-10-12 14:49:57 -07:00
local dummy_definition = {
hp_max = 1,
physical = true,
collisionbox = {0,0,0,0,0,0},
visual = "mesh",
visual_size = size,
mesh = mesh,
textures = texture,
makes_footstep_sound = false,
timer = 0,
automatic_rotate = math.pi * -3,
m_name = "dummy"
}
dummy_definition.on_activate = function(self)
self.object:setvelocity({x=0, y=0, z=0})
self.object:setacceleration({x=0, y=0, z=0})
self.object:set_armor_groups({immortal=1})
end
-- remove dummy after dug up the spawner
dummy_definition.on_step = function(self, dtime)
self.timer = self.timer + dtime
local n = minetest.get_node_or_nil(self.object:getpos())
if self.timer > 2 then
if n and n.name and n.name ~= "spawners_env:"..mod_prefix.."_"..mob_name.."_spawner_active" then
self.object:remove()
end
end
end
minetest.register_entity("spawners_env:dummy_"..mod_prefix.."_"..mob_name, dummy_definition)
2018-11-22 15:13:38 -08:00
--
2016-10-12 14:49:57 -07:00
-- ACTIVE SPAWNER ENV
2018-11-22 15:13:38 -08:00
--
2016-10-12 14:49:57 -07:00
minetest.register_node("spawners_env:"..mod_prefix.."_"..mob_name.."_spawner_active", {
description = mod_prefix.."_"..mob_name.." spawner active env",
paramtype = "light",
light_source = 4,
2017-07-27 12:05:41 -07:00
paramtype2 = "glasslikeliquidlevel",
drawtype = "glasslike_framed_optional",
2016-10-12 14:49:57 -07:00
walkable = true,
2016-11-13 07:53:40 -08:00
sounds = default.node_sound_metal_defaults(),
2016-10-12 14:49:57 -07:00
damage_per_second = 4,
sunlight_propagates = true,
tiles = {
{
2016-12-07 12:37:36 -08:00
name = "spawners_env_spawner_animated_16.png",
2016-10-12 14:49:57 -07:00
animation = {
type = "vertical_frames",
2016-12-07 12:37:36 -08:00
aspect_w = 16,
aspect_h = 16,
2016-10-12 14:49:57 -07:00
length = 2.0
},
}
},
is_ground_content = true,
groups = {cracky=1,level=2,igniter=1,not_in_creative_inventory=1},
2016-12-07 12:37:36 -08:00
on_timer = function(pos, elapsed)
2016-12-15 15:09:41 -08:00
spawners_env.check_for_spawning_timer(pos, mob_name, night_only, mod_prefix, sound_custom, env, boss)
2016-12-07 12:37:36 -08:00
return false
end,
2016-10-12 14:49:57 -07:00
drop = {
max_items = 1,
items = {
2016-12-07 12:37:36 -08:00
{items = {"spawners_mobs:"..mod_prefix.."_"..mob_name.."_spawner"}, rarity = 20}
2016-10-12 14:49:57 -07:00
}
},
on_construct = function(pos)
pos.y = pos.y + offset
minetest.add_entity(pos,"spawners_env:dummy_"..mod_prefix.."_"..mob_name)
end,
})
2018-11-22 15:13:38 -08:00
--
2016-10-12 14:49:57 -07:00
-- WAITING SPAWNER ENV
2018-11-22 15:13:38 -08:00
--
2016-10-12 14:49:57 -07:00
-- waiting for light - everything is ok but too much light or not enough light
minetest.register_node("spawners_env:"..mod_prefix.."_"..mob_name.."_spawner_waiting", {
description = mod_prefix.."_"..mob_name.." spawner waiting env",
paramtype = "light",
light_source = 2,
2017-07-27 12:05:41 -07:00
paramtype2 = "glasslikeliquidlevel",
drawtype = "glasslike_framed_optional",
2016-10-12 14:49:57 -07:00
walkable = true,
2016-11-13 07:53:40 -08:00
sounds = default.node_sound_metal_defaults(),
2016-10-12 14:49:57 -07:00
sunlight_propagates = true,
tiles = {
{
2016-12-07 12:37:36 -08:00
name = "spawners_env_spawner_waiting_animated_16.png",
2016-10-12 14:49:57 -07:00
animation = {
type = "vertical_frames",
2016-12-07 12:37:36 -08:00
aspect_w = 16,
aspect_h = 16,
2016-10-12 14:49:57 -07:00
length = 2.0
},
}
},
is_ground_content = true,
groups = {cracky=1,level=2,not_in_creative_inventory=1},
2016-12-07 12:37:36 -08:00
on_timer = function(pos, elapsed)
2016-12-15 15:09:41 -08:00
spawners_env.check_for_spawning_timer(pos, mob_name, night_only, mod_prefix, sound_custom, env, boss)
2016-12-07 12:37:36 -08:00
return false
end,
2016-10-12 14:49:57 -07:00
drop = {
max_items = 1,
items = {
2016-12-07 12:37:36 -08:00
{items = {"spawners_mobs:"..mod_prefix.."_"..mob_name.."_spawner"}, rarity = 20}
2016-10-12 14:49:57 -07:00
}
},
})
2018-11-22 15:13:38 -08:00
--
2016-10-12 14:49:57 -07:00
-- INACTIVE SPAWNER (DEFAULT) ENV
2018-11-22 15:13:38 -08:00
--
2016-10-12 14:49:57 -07:00
minetest.register_node("spawners_env:"..mod_prefix.."_"..mob_name.."_spawner", {
description = mod_prefix.."_"..mob_name.." spawner env",
paramtype = "light",
2017-07-27 12:05:41 -07:00
paramtype2 = "glasslikeliquidlevel",
drawtype = "glasslike_framed_optional",
2016-10-12 14:49:57 -07:00
walkable = true,
2016-11-13 07:53:40 -08:00
sounds = default.node_sound_metal_defaults(),
2016-10-12 14:49:57 -07:00
sunlight_propagates = true,
2016-12-07 12:37:36 -08:00
tiles = {"spawners_env_spawner_16.png"},
2016-10-12 14:49:57 -07:00
is_ground_content = true,
2016-12-15 15:19:00 -08:00
groups = {cracky=1,level=2,not_in_creative_inventory=0},
2016-10-12 14:49:57 -07:00
stack_max = 1,
drop = {
max_items = 1,
items = {
2016-12-07 12:37:36 -08:00
{items = {"spawners_mobs:"..mod_prefix.."_"..mob_name.."_spawner"}, rarity = 20}
2016-10-12 14:49:57 -07:00
}
},
on_construct = function(pos)
2016-12-15 15:09:41 -08:00
spawners_env.check_for_spawning_timer(pos, mob_name, night_only, mod_prefix, sound_custom, env, boss)
2016-10-12 14:49:57 -07:00
end,
})
2018-11-22 15:13:38 -08:00
--
2016-12-07 12:37:36 -08:00
-- * LBM *
2018-11-22 15:13:38 -08:00
--
2016-10-12 14:49:57 -07:00
2016-12-07 12:37:36 -08:00
minetest.register_lbm({
name = "spawners_env:check_for_spawning_timer",
2016-10-12 14:49:57 -07:00
nodenames = {
"spawners_env:"..mod_prefix.."_"..mob_name.."_spawner",
"spawners_env:"..mod_prefix.."_"..mob_name.."_spawner_active",
"spawners_env:"..mod_prefix.."_"..mob_name.."_spawner_waiting"
},
2016-12-07 12:37:36 -08:00
action = function(pos)
2016-12-15 15:09:41 -08:00
spawners_env.check_for_spawning_timer(pos, mob_name, night_only, mod_prefix, sound_custom, env, boss)
2016-12-07 12:37:36 -08:00
end
})
end
2016-10-12 14:49:57 -07:00
2018-11-22 15:13:38 -08:00
--
2016-12-07 12:37:36 -08:00
-- * check for spawning *
2018-11-22 15:13:38 -08:00
--
2016-12-15 15:09:41 -08:00
function spawners_env.check_for_spawning_timer(pos, mob_name, night_only, mod_prefix, sound_custom, env, boss)
2016-10-12 14:49:57 -07:00
2016-12-15 15:09:41 -08:00
local random_pos, waiting = spawners_env.check_node_status(pos, mob_name, night_only, boss)
2016-10-12 14:49:57 -07:00
2016-12-07 12:37:36 -08:00
local node = minetest.get_node_or_nil(pos)
2016-10-12 14:49:57 -07:00
2016-12-07 12:37:36 -08:00
-- minetest.log("action", "[Mod][Spawners] checking for: "..mob_name.." at "..minetest.pos_to_string(pos))
2016-10-12 14:49:57 -07:00
2016-12-07 12:37:36 -08:00
if random_pos then
-- print('try to spawn another mob at: '..minetest.pos_to_string(random_pos))
2016-10-12 14:49:57 -07:00
2016-12-07 12:37:36 -08:00
local mobs_counter_table = {}
2016-12-15 15:09:41 -08:00
local mobs_check_radius
local mobs_max
2016-12-07 12:37:36 -08:00
mobs_counter_table[mob_name] = 0
2018-11-22 15:13:38 -08:00
2016-12-15 15:09:41 -08:00
if boss then
mobs_max = 1
mobs_check_radius = 35
else
mobs_max = 3
mobs_check_radius = 10
end
2016-10-12 14:49:57 -07:00
2016-12-07 12:37:36 -08:00
-- collect all spawned mobs around area
2016-12-15 15:09:41 -08:00
for _,obj in ipairs(minetest.get_objects_inside_radius(pos, mobs_check_radius)) do
2018-11-22 15:13:38 -08:00
2016-12-07 12:37:36 -08:00
if obj:get_luaentity() ~= nil then
2016-10-12 14:49:57 -07:00
2018-11-22 15:13:38 -08:00
-- get entity name
2016-12-07 12:37:36 -08:00
local name_split = string.split(obj:get_luaentity().name, ":")
2016-10-12 14:49:57 -07:00
2016-12-07 12:37:36 -08:00
if name_split[2] == mob_name then
mobs_counter_table[mob_name]=mobs_counter_table[mob_name]+1
2016-10-12 14:49:57 -07:00
end
2016-12-07 12:37:36 -08:00
2016-10-12 14:49:57 -07:00
end
end
2016-12-07 12:37:36 -08:00
-- print(mob_name.." : "..mobs_counter_table[mob_name])
2016-12-15 15:09:41 -08:00
2016-12-07 12:37:36 -08:00
-- enough place to spawn more mobs
2016-12-15 15:09:41 -08:00
if mobs_counter_table[mob_name] < mobs_max then
2016-12-07 12:37:36 -08:00
-- make sure the right node status is shown
if node.name ~= "spawners_env:"..mod_prefix.."_"..mob_name.."_spawner_active" then
minetest.set_node(pos, {name="spawners_env:"..mod_prefix.."_"..mob_name.."_spawner_active"})
end
2016-12-15 15:09:41 -08:00
if boss then
2018-11-22 15:13:38 -08:00
-- color: deep orange
minetest.chat_send_all(minetest.colorize("#FF5722", "Balrog has spawned to this World!"))
2016-12-15 15:09:41 -08:00
end
2016-12-07 12:37:36 -08:00
spawners_env.start_spawning(random_pos, 1, "spawners_env:"..mob_name, mod_prefix, sound_custom)
else
-- print("too many mobs: waiting")
-- waiting status
if node.name ~= "spawners_env:"..mod_prefix.."_"..mob_name.."_spawner_waiting" then
minetest.set_node(pos, {name="spawners_env:"..mod_prefix.."_"..mob_name.."_spawner_waiting"})
end
end
else
-- print("no random_pos found: waiting")
-- waiting status
if node.name ~= "spawners_env:"..mod_prefix.."_"..mob_name.."_spawner_waiting" then
minetest.set_node(pos, {name="spawners_env:"..mod_prefix.."_"..mob_name.."_spawner_waiting"})
end
end
2016-12-15 15:09:41 -08:00
-- 6 hours = 21600 seconds
-- 4 hours = 14400 seconds
-- 1 hour = 3600 seconds
if boss then
minetest.get_node_timer(pos):start(3600)
else
minetest.get_node_timer(pos):start(math.random(5, 15))
end
2016-10-12 14:49:57 -07:00
end
2018-11-22 15:13:38 -08:00
--
2016-10-12 14:49:57 -07:00
-- CALL 'CREATE' FOR ALL SPAWNERS
2018-11-22 15:13:38 -08:00
--
2016-10-12 14:49:57 -07:00
for i, mob_table in ipairs(spawners_env.mob_tables) do
if mob_table then
2016-12-15 15:09:41 -08:00
spawners_env.create(mob_table.name, mob_table.mod_prefix, mob_table.dummy_size, mob_table.dummy_offset, mob_table.dummy_mesh, mob_table.dummy_texture, mob_table.night_only, mob_table.sound_custom, mob_table.env, mob_table.boss)
2016-10-12 14:49:57 -07:00
end
end