Integrate raids with mcl_events

This commit is contained in:
cora 2022-10-24 00:10:17 +02:00
parent 052e76bfcc
commit 390aec5d7a
3 changed files with 101 additions and 72 deletions

View File

@ -138,7 +138,7 @@ mcl_events.register_event("infestation",{
return true end return true end
end, end,
on_stage_begin = function(self) on_stage_begin = function(self)
self.health_max = 1 self.health_max = 0
for i=1,15 * self.stage do for i=1,15 * self.stage do
local m = mcl_mobs.spawn(vector.add(self.pos,vector.new(math.random(20)-10,0,math.random(20)-10)),"mobs_mc:silverfish") local m = mcl_mobs.spawn(vector.add(self.pos,vector.new(math.random(20)-10,0,math.random(20)-10)),"mobs_mc:silverfish")
local l = m:get_luaentity() local l = m:get_luaentity()

View File

@ -3,83 +3,74 @@
mcl_raids = {} mcl_raids = {}
-- Define the amount of illagers to spawn each wave. -- Define the amount of illagers to spawn each wave.
mcl_raids.wave_definitions = { local waves = {
-- Pillager
{ {
illager_name = "mobs_mc:pillager", ["mobs_mc:pillager"] = 5,
wave_1 = 5, ["mobs_mc:vindicator"] = 1,
wave_2 = 4,
wave_3 = 4,
wave_4 = 5,
wave_5 = 5,
extra_wave = 5,
}, },
-- Vindicator aka Angry Axeman
{ {
illager_name = "mobs_mc:vindicator", ["mobs_mc:pillager"] = 4,
wave_1 = 1, ["mobs_mc:vindicator"] = 3,
wave_2 = 3,
wave_3 = 1,
wave_4 = 2,
wave_5 = 5,
extra_wave = 5,
}, },
--{"mobs_mc:ravager", 0, 0, 1, 0, 0, 2},
-- Witch
{ {
illager_name = "mobs_mc:witch", ["mobs_mc:pillager"] = 4,
wave_1 = 0, ["mobs_mc:vindicator"] = 1,
wave_2 = 0, ["mobs_mc:witch"] = 1,
wave_3 = 1, --["mobs_mc:ravager"] = 1,
wave_4 = 3,
wave_5 = 1,
extra_wave = 1,
}, },
-- Evoker
{ {
illager_name = "mobs_mc:evoker", ["mobs_mc:pillager"] = 5,
wave_1 = 0, ["mobs_mc:vindicator"] = 2,
wave_2 = 0, ["mobs_mc:witch"] = 3,
wave_3 = 0, },
wave_4 = 0, {
wave_5 = 1, ["mobs_mc:pillager"] = 5,
extra_wave = 1, ["mobs_mc:vindicator"] = 5,
["mobs_mc:witch"] = 1,
["mobs_mc:evoker"] = 1,
}, },
} }
mcl_raids.spawn_raid = function(pos, wave) 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
local illager_count = 0 local illager_count = 0
local spawnable = false local spawnable = false
local r = 32 local r = 32
local n = 12 local n = 12
local i = math.random(1, n) 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))) 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)))
local sn = minetest.find_nodes_in_area_under_air(vector.offset(raid_pos,0,100,0), vector.offset(raid_pos,0,-100,0), {"group:grass_block", "group:grass_block_snow", "group:snow_cover", "group:sand"}) 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"})
if sn and #sn > 0 then if sn and #sn > 0 then
local spawn_pos = sn[1] local spawn_pos = sn[math.random(#sn)]
if spawn_pos then if spawn_pos then
minetest.log("action", "[mcl_raids] Raid Spawn Position chosen at " .. minetest.pos_to_string(spawn_pos) .. ".") minetest.log("action", "[mcl_raids] Raid Spawn Position chosen at " .. minetest.pos_to_string(spawn_pos) .. ".")
spawnable = true 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 .. ".")
else else
minetest.log("action", "[mcl_raids] Raid Spawn Postion not chosen.") minetest.log("action", "[mcl_raids] Raid Spawn Postion not chosen.")
end end
elseif not sn then elseif not sn then
minetest.log("action", "[mcl_raids] Raid Spawn Position error, no appropriate site found.") minetest.log("action", "[mcl_raids] Raid Spawn Position error, no appropriate site found.")
end end
if spawnable and spawn_pos then
for _, raiddefs in pairs(mcl_raids.wave_definitions) do
local wave_count = raiddefs.wave_1
for i = 0, wave_count do
local entity = minetest.add_entity(spawn_pos, raiddefs.illager_name)
if entity then
local l = entity:get_luaentity()
l.raidmember = true
illager_count = illager_count + 1
end
end
end
minetest.log("action", "[mcl_raids] Raid Spawned. Illager Count: " .. illager_count .. ".")
end
end end
mcl_raids.find_villager = function(pos) mcl_raids.find_villager = function(pos)
@ -136,26 +127,62 @@ end
minetest.register_chatcommand("spawn_raid", { minetest.register_chatcommand("spawn_raid", {
privs = { privs = {
server = true, debug = true,
}, },
func = function(name) func = function(name)
local wave = 1 local m = minetest.get_player_by_name(name):get_meta()
local player = minetest.get_player_by_name(name) m:set_string("_has_bad_omen","yes")
local pos = player:get_pos()
mcl_raids.spawn_raid(pos, wave)
end end
}) })
local etime = 0 mcl_events.register_event("raid",{
minetest.register_globalstep(function(dtime) max_stage = 5,
etime = dtime + etime health = 1,
if etime < 10 then return end health_max = 1,
etime = 0 cond_start = function(self)
for _,pl in pairs(minetest.get_connected_players()) do local r = {}
if pl:get_meta():get_string("_has_bad_omen") then for _,p in pairs(minetest.get_connected_players()) do
mcl_raids.find_village(pl:get_pos()) local m=p:get_meta()
else if m:get_string("_has_bad_omen") == "yes" then
return m:set_string("_has_bad_omen","")
table.insert(r,p:get_pos())
end end
end end
end) 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,
})

View File

@ -1 +1,3 @@
name = mcl_raids name = mcl_raids
author = PrairieWind
depends = mcl_events, mcl_mobs