2022-10-24 17:05:09 +02:00
|
|
|
-- mcl_raids
|
|
|
|
|
|
|
|
mcl_raids = {}
|
|
|
|
|
|
|
|
-- Define the amount of illagers to spawn each wave.
|
2022-10-24 00:10:17 +02:00
|
|
|
local waves = {
|
2022-10-24 17:05:09 +02:00
|
|
|
{
|
2022-10-24 00:10:17 +02:00
|
|
|
["mobs_mc:pillager"] = 5,
|
|
|
|
["mobs_mc:vindicator"] = 1,
|
2022-10-24 17:05:09 +02:00
|
|
|
},
|
|
|
|
{
|
2022-10-24 00:10:17 +02:00
|
|
|
["mobs_mc:pillager"] = 4,
|
|
|
|
["mobs_mc:vindicator"] = 3,
|
2022-10-24 17:05:09 +02:00
|
|
|
},
|
|
|
|
{
|
2022-10-24 00:10:17 +02:00
|
|
|
["mobs_mc:pillager"] = 4,
|
|
|
|
["mobs_mc:vindicator"] = 1,
|
|
|
|
["mobs_mc:witch"] = 1,
|
|
|
|
--["mobs_mc:ravager"] = 1,
|
2022-10-24 17:05:09 +02:00
|
|
|
},
|
|
|
|
{
|
2022-10-24 00:10:17 +02:00
|
|
|
["mobs_mc:pillager"] = 5,
|
|
|
|
["mobs_mc:vindicator"] = 2,
|
|
|
|
["mobs_mc:witch"] = 3,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
["mobs_mc:pillager"] = 5,
|
|
|
|
["mobs_mc:vindicator"] = 5,
|
|
|
|
["mobs_mc:witch"] = 1,
|
|
|
|
["mobs_mc:evoker"] = 1,
|
2022-10-24 17:05:09 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-10-24 00:10:17 +02:00
|
|
|
local extra_wave = {
|
|
|
|
["mobs_mc:pillager"] = 5,
|
|
|
|
["mobs_mc:vindicator"] = 5,
|
|
|
|
["mobs_mc:witch"] = 1,
|
|
|
|
["mobs_mc:evoker"] = 1,
|
|
|
|
--["mobs_mc:ravager"] = 2,
|
|
|
|
}
|
|
|
|
|
|
|
|
mcl_raids.spawn_raid = function(event)
|
|
|
|
local pos = event.pos
|
|
|
|
local wave = event.stage
|
2022-10-22 21:56:00 +02:00
|
|
|
local illager_count = 0
|
|
|
|
local spawnable = false
|
|
|
|
local r = 32
|
|
|
|
local n = 12
|
|
|
|
local i = math.random(1, n)
|
|
|
|
local raid_pos = vector.offset(pos,r * math.cos(((i-1)/n) * (2*math.pi)),0, r * math.sin(((i-1)/n) * (2*math.pi)))
|
2022-10-24 00:10:17 +02:00
|
|
|
local sn = minetest.find_nodes_in_area_under_air(vector.offset(raid_pos,-5,-50,-5), vector.offset(raid_pos,5,50,5), {"group:grass_block", "group:grass_block_snow", "group:snow_cover", "group:sand"})
|
2022-10-22 21:56:00 +02:00
|
|
|
if sn and #sn > 0 then
|
2022-10-24 00:10:17 +02:00
|
|
|
local spawn_pos = sn[math.random(#sn)]
|
2022-10-22 21:56:00 +02:00
|
|
|
if spawn_pos then
|
|
|
|
minetest.log("action", "[mcl_raids] Raid Spawn Position chosen at " .. minetest.pos_to_string(spawn_pos) .. ".")
|
2022-10-24 00:10:17 +02:00
|
|
|
event.health_max = 0
|
|
|
|
for m,c in pairs(waves[event.stage]) do
|
|
|
|
for i=1,c do
|
|
|
|
local mob = mcl_mobs.spawn(spawn_pos,m)
|
|
|
|
local l = mob:get_luaentity()
|
|
|
|
if l then
|
|
|
|
event.health_max = event.health_max + l.health
|
|
|
|
table.insert(event.mobs,mob)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
minetest.log("action", "[mcl_raids] Raid Spawned. Illager Count: " .. #event.mobs .. ".")
|
2022-10-22 21:56:00 +02:00
|
|
|
else
|
|
|
|
minetest.log("action", "[mcl_raids] Raid Spawn Postion not chosen.")
|
|
|
|
end
|
|
|
|
elseif not sn then
|
|
|
|
minetest.log("action", "[mcl_raids] Raid Spawn Position error, no appropriate site found.")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-10-23 00:04:58 +02:00
|
|
|
mcl_raids.find_villager = function(pos)
|
2022-10-23 00:41:53 +02:00
|
|
|
local obj = minetest.get_objects_inside_radius(pos, 8)
|
|
|
|
for _, objects in ipairs(obj) do
|
|
|
|
local object = objects:get_luaentity()
|
|
|
|
if object then
|
|
|
|
if object.name ~= "mobs_mc:villager" then
|
|
|
|
return
|
|
|
|
elseif object.name == "mobs_mc:villager" then
|
|
|
|
minetest.log("action", "[mcl_raids] Villager Found.")
|
|
|
|
return true
|
|
|
|
else
|
|
|
|
minetest.log("action", "[mcl_raids] No Villager Found.")
|
|
|
|
return false
|
|
|
|
end
|
2022-10-23 00:04:58 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
mcl_raids.find_bed = function(pos)
|
|
|
|
local beds = minetest.find_nodes_in_area(vector.offset(pos, -8, -8, -8), vector.offset(pos, 8, 8, 8), "mcl_beds:bed_red_bottom")
|
2022-10-23 00:41:53 +02:00
|
|
|
if beds[1] then
|
2022-10-23 00:04:58 +02:00
|
|
|
minetest.log("action", "[mcl_raids] Bed Found.")
|
|
|
|
return true
|
|
|
|
else
|
|
|
|
minetest.log("action", "[mcl_raids] No Bed Found.")
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
mcl_raids.find_village = function(pos)
|
|
|
|
local bed = mcl_raids.find_bed(pos)
|
|
|
|
local villager = mcl_raids.find_villager(pos)
|
|
|
|
local raid_started = false
|
2022-10-24 00:10:17 +02:00
|
|
|
|
2022-10-23 00:04:58 +02:00
|
|
|
if (bed and villager) and raid_started == false then
|
2022-10-23 00:41:53 +02:00
|
|
|
local raid = mcl_raids.spawn_raid(pos, 1)
|
|
|
|
if raid then
|
|
|
|
minetest.log("action", "[mcl_raids] Village found, starting raid.")
|
|
|
|
raid_started = true
|
|
|
|
else
|
|
|
|
minetest.log("action", "[mcl_raids] Village found.")
|
|
|
|
end
|
2022-10-23 00:04:58 +02:00
|
|
|
return true
|
2022-10-23 00:41:53 +02:00
|
|
|
elseif raid_started == true then
|
|
|
|
minetest.log("action", "[mcl_raids] Raid already started.")
|
|
|
|
return
|
2022-10-23 00:04:58 +02:00
|
|
|
else
|
|
|
|
minetest.log("action", "[mcl_raids] Village not found, raid is not starting.")
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-10-24 17:05:09 +02:00
|
|
|
minetest.register_chatcommand("spawn_raid", {
|
|
|
|
privs = {
|
2022-10-24 00:10:17 +02:00
|
|
|
debug = true,
|
2022-10-24 17:05:09 +02:00
|
|
|
},
|
|
|
|
func = function(name)
|
2022-10-24 00:10:17 +02:00
|
|
|
local m = minetest.get_player_by_name(name):get_meta()
|
|
|
|
m:set_string("_has_bad_omen","yes")
|
2022-10-24 17:05:09 +02:00
|
|
|
end
|
|
|
|
})
|
2022-10-23 00:04:58 +02:00
|
|
|
|
2022-10-24 00:10:17 +02:00
|
|
|
mcl_events.register_event("raid",{
|
|
|
|
max_stage = 5,
|
|
|
|
health = 1,
|
|
|
|
health_max = 1,
|
|
|
|
cond_start = function(self)
|
|
|
|
local r = {}
|
|
|
|
for _,p in pairs(minetest.get_connected_players()) do
|
|
|
|
local m=p:get_meta()
|
|
|
|
if m:get_string("_has_bad_omen") == "yes" then
|
|
|
|
m:set_string("_has_bad_omen","")
|
|
|
|
table.insert(r,p:get_pos())
|
|
|
|
end
|
2022-10-23 00:04:58 +02:00
|
|
|
end
|
2022-10-24 00:10:17 +02:00
|
|
|
if #r > 0 then return r end
|
|
|
|
end,
|
|
|
|
on_start = function(self)
|
|
|
|
self.mobs = {}
|
|
|
|
self.health_max = 1
|
|
|
|
self.health = 0
|
|
|
|
end,
|
|
|
|
cond_progress = function(self)
|
|
|
|
local m = {}
|
|
|
|
local h = 0
|
|
|
|
for k,o in pairs(self.mobs) do
|
|
|
|
if o and o:get_pos() then
|
|
|
|
local l = o:get_luaentity()
|
|
|
|
h = h + l.health
|
|
|
|
table.insert(m,o)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
self.mobs = m
|
|
|
|
self.health = h
|
|
|
|
self.percent = math.max(0,(self.health / self.health_max ) * 100)
|
|
|
|
if #m < 1 then
|
|
|
|
return true end
|
|
|
|
end,
|
|
|
|
on_stage_begin = mcl_raids.spawn_raid,
|
|
|
|
cond_complete = function(self)
|
|
|
|
local m = {}
|
|
|
|
for k,o in pairs(self.mobs) do
|
|
|
|
if o and o:get_pos() then
|
|
|
|
local l = o:get_luaentity()
|
|
|
|
table.insert(m,o)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return self.stage >= self.max_stage and #m < 1
|
|
|
|
end,
|
|
|
|
on_complete = function(self)
|
|
|
|
--minetest.log("RAID complete")
|
|
|
|
end,
|
|
|
|
})
|