2022-10-24 18:05:09 +03:00
|
|
|
-- mcl_raids
|
|
|
|
mcl_raids = {}
|
2022-11-07 14:04:18 +02:00
|
|
|
local S = minetest.get_translator(minetest.get_current_modname())
|
2022-10-24 18:05:09 +03:00
|
|
|
|
|
|
|
-- Define the amount of illagers to spawn each wave.
|
2022-10-24 01:10:17 +03:00
|
|
|
local waves = {
|
2022-10-24 18:05:09 +03:00
|
|
|
{
|
2022-10-24 01:10:17 +03:00
|
|
|
["mobs_mc:pillager"] = 5,
|
|
|
|
["mobs_mc:vindicator"] = 1,
|
2022-10-24 18:05:09 +03:00
|
|
|
},
|
|
|
|
{
|
2022-10-24 01:10:17 +03:00
|
|
|
["mobs_mc:pillager"] = 4,
|
|
|
|
["mobs_mc:vindicator"] = 3,
|
2022-10-24 18:05:09 +03:00
|
|
|
},
|
|
|
|
{
|
2022-10-24 01:10:17 +03:00
|
|
|
["mobs_mc:pillager"] = 4,
|
|
|
|
["mobs_mc:vindicator"] = 1,
|
|
|
|
["mobs_mc:witch"] = 1,
|
|
|
|
--["mobs_mc:ravager"] = 1,
|
2022-10-24 18:05:09 +03:00
|
|
|
},
|
|
|
|
{
|
2022-10-24 01:10:17 +03: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 18:05:09 +03:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-10-24 01:10:17 +03:00
|
|
|
local extra_wave = {
|
|
|
|
["mobs_mc:pillager"] = 5,
|
|
|
|
["mobs_mc:vindicator"] = 5,
|
|
|
|
["mobs_mc:witch"] = 1,
|
|
|
|
["mobs_mc:evoker"] = 1,
|
|
|
|
--["mobs_mc:ravager"] = 2,
|
|
|
|
}
|
|
|
|
|
2022-11-07 14:04:18 +02:00
|
|
|
local oban_layers = {
|
|
|
|
{
|
|
|
|
pattern = "rhombus",
|
|
|
|
color = "unicolor_cyan"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
color = "unicolor_grey",
|
|
|
|
pattern = "stripe_bottom"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern = "stripe_center",
|
|
|
|
color = "unicolor_darkgrey"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
color = "unicolor_black",
|
|
|
|
pattern = "stripe_middle"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern = "half_horizontal",
|
|
|
|
color = "unicolor_grey"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
color = "unicolor_grey",
|
|
|
|
pattern = "circle"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern = "border",
|
|
|
|
color = "unicolor_black"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
local oban_def = table.copy(minetest.registered_entities["mcl_banners:standing_banner"])
|
2022-11-06 13:30:16 +02:00
|
|
|
oban_def.visual_size = { x=1, y=1 }
|
2022-11-09 20:53:50 +02:00
|
|
|
local old_step = oban_def.on_step
|
|
|
|
oban_def.on_step = function(self,dtime)
|
|
|
|
if not self.object:get_attach() then return self.object:remove() end
|
|
|
|
if old_step then return old_step(self.dtime) end
|
2022-11-07 14:04:18 +02:00
|
|
|
end
|
2022-11-09 20:53:50 +02:00
|
|
|
|
2022-11-06 13:30:16 +02:00
|
|
|
minetest.register_entity(":mcl_raids:ominous_banner",oban_def)
|
|
|
|
|
2022-11-07 14:04:18 +02:00
|
|
|
function mcl_raids.drop_obanner(pos)
|
|
|
|
local it = ItemStack("mcl_banners:banner_item_white")
|
|
|
|
it:get_meta():set_string("layers",minetest.serialize(oban_layers))
|
|
|
|
it:get_meta():set_string("name",S("Ominous Banner"))
|
|
|
|
minetest.add_item(pos,it)
|
|
|
|
end
|
|
|
|
|
2022-11-08 02:59:16 +02:00
|
|
|
function mcl_raids.promote_to_raidcaptain(c) -- object
|
|
|
|
if not c or not c:get_pos() then return end
|
|
|
|
local pos = c:get_pos()
|
2022-11-07 14:04:18 +02:00
|
|
|
local l = c:get_luaentity()
|
2022-11-08 02:59:16 +02:00
|
|
|
l._banner = minetest.add_entity(pos,"mcl_raids:ominous_banner")
|
|
|
|
l._banner:set_properties({textures = {mcl_banners.make_banner_texture("unicolor_white", oban_layers)}})
|
|
|
|
l._banner:set_attach(c,"",vector.new(-1,5.5,0),vector.new(0,0,0),true)
|
2022-11-07 14:04:18 +02:00
|
|
|
l._raidcaptain = true
|
|
|
|
local old_ondie = l.on_die
|
|
|
|
l.on_die = function(self, pos, cmi_cause)
|
2022-11-08 04:17:27 +02:00
|
|
|
if l._banner then
|
2022-11-07 14:04:18 +02:00
|
|
|
l._banner:remove()
|
|
|
|
l._banner = nil
|
|
|
|
mcl_raids.drop_obanner(pos)
|
2022-11-08 04:17:27 +02:00
|
|
|
if cmi_cause.type == "punch" and cmi_cause.puncher:is_player() then
|
2022-11-09 21:30:23 +02:00
|
|
|
awards.unlock(cmi_cause.puncher:get_player_name(), "mcl:voluntary_exile")
|
2022-11-08 04:57:11 +02:00
|
|
|
local lv = mcl_potions.player_get_effect(cmi_cause.puncher, "bad_omen")
|
|
|
|
if not lv then lv = 0
|
|
|
|
else lv = lv.factor end
|
2022-11-08 04:17:27 +02:00
|
|
|
lv = math.max(5,lv + 1)
|
|
|
|
mcl_potions.bad_omen_func(cmi_cause.puncher,lv,6000)
|
|
|
|
end
|
2022-11-07 14:04:18 +02:00
|
|
|
end
|
|
|
|
if old_ondie then return old_ondie(self,pos,cmi_cause) end
|
|
|
|
end
|
2022-11-06 13:30:16 +02:00
|
|
|
end
|
|
|
|
|
2022-11-08 03:26:37 +02:00
|
|
|
function mcl_raids.is_raidcaptain_near(pos)
|
|
|
|
for k,v in pairs(minetest.get_objects_inside_radius(pos,128)) do
|
|
|
|
local l = v:get_luaentity()
|
|
|
|
if l and l._raidcaptain then return true end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function mcl_raids.register_possible_raidcaptain(mob)
|
|
|
|
local old_on_spawn = minetest.registered_entities[mob].on_spawn
|
2022-11-08 03:47:04 +02:00
|
|
|
local old_on_pick_up = minetest.registered_entities[mob].on_pick_up
|
|
|
|
if not minetest.registered_entities[mob].pick_up then minetest.registered_entities[mob].pick_up = {} end
|
|
|
|
table.insert(minetest.registered_entities[mob].pick_up,"mcl_banners:banner_item_white")
|
|
|
|
minetest.registered_entities[mob].on_pick_up = function(self,e)
|
|
|
|
local stack = ItemStack(e.itemstring)
|
|
|
|
if not self._raidcaptain and stack:get_meta():get_string("name"):find("Ominous Banner") then
|
|
|
|
stack:take_item(1)
|
|
|
|
mcl_raids.promote_to_raidcaptain(self.object)
|
|
|
|
return stack
|
|
|
|
end
|
|
|
|
if old_on_pick_up then return old_on_pick_up(self,e) end
|
|
|
|
end
|
2022-11-08 03:26:37 +02:00
|
|
|
minetest.registered_entities[mob].on_spawn = function(self)
|
|
|
|
if not mcl_raids.is_raidcaptain_near(self.object:get_pos()) then
|
|
|
|
mcl_raids.promote_to_raidcaptain(self.object)
|
|
|
|
end
|
|
|
|
if old_on_spawn then return old_on_spawn(self) end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
mcl_raids.register_possible_raidcaptain("mobs_mc:pillager")
|
|
|
|
mcl_raids.register_possible_raidcaptain("mobs_mc:vindicator")
|
|
|
|
mcl_raids.register_possible_raidcaptain("mobs_mc:evoker")
|
|
|
|
|
2022-10-24 18:17:22 +03:00
|
|
|
function mcl_raids.spawn_raid(event)
|
2022-10-24 01:10:17 +03:00
|
|
|
local pos = event.pos
|
|
|
|
local wave = event.stage
|
2022-10-22 22:56:00 +03: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-11-17 06:39:55 +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", "mcl_core:ice"})
|
2022-10-25 01:30:14 +03:00
|
|
|
mcl_bells.ring_once(pos)
|
2022-10-22 22:56:00 +03:00
|
|
|
if sn and #sn > 0 then
|
2022-10-24 01:10:17 +03:00
|
|
|
local spawn_pos = sn[math.random(#sn)]
|
2022-10-22 22:56:00 +03:00
|
|
|
if spawn_pos then
|
|
|
|
minetest.log("action", "[mcl_raids] Raid Spawn Position chosen at " .. minetest.pos_to_string(spawn_pos) .. ".")
|
2022-10-24 01:10:17 +03:00
|
|
|
event.health_max = 0
|
2022-10-25 01:30:14 +03:00
|
|
|
local w
|
|
|
|
if event.stage <= #waves then
|
|
|
|
w= waves[event.stage]
|
|
|
|
else
|
|
|
|
w = extra_wave
|
|
|
|
end
|
|
|
|
for m,c in pairs(w) do
|
2022-10-24 01:10:17 +03:00
|
|
|
for i=1,c do
|
2022-11-03 20:00:17 +02:00
|
|
|
local p = vector.offset(spawn_pos,0,1,0)
|
|
|
|
local mob = mcl_mobs.spawn(p,m)
|
2022-10-24 01:10:17 +03:00
|
|
|
local l = mob:get_luaentity()
|
|
|
|
if l then
|
|
|
|
event.health_max = event.health_max + l.health
|
|
|
|
table.insert(event.mobs,mob)
|
2022-11-03 20:00:17 +02:00
|
|
|
mcl_mobs:gopath(l,pos)
|
2022-10-24 01:10:17 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-11-08 02:59:16 +02:00
|
|
|
if event.stage == 1 then
|
|
|
|
table.shuffle(event.mobs)
|
|
|
|
mcl_raids.promote_to_raidcaptain(event.mobs[1])
|
|
|
|
end
|
2022-10-24 01:10:17 +03:00
|
|
|
minetest.log("action", "[mcl_raids] Raid Spawned. Illager Count: " .. #event.mobs .. ".")
|
2022-11-17 06:47:48 +02:00
|
|
|
return #event.mobs == 0
|
2022-10-22 22:56:00 +03: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
|
2022-11-17 06:47:48 +02:00
|
|
|
return true
|
2022-10-22 22:56:00 +03:00
|
|
|
end
|
|
|
|
|
2022-10-24 18:17:22 +03:00
|
|
|
function mcl_raids.find_villager(pos)
|
2022-10-23 01:41:53 +03: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
|
2022-11-06 12:49:39 +02:00
|
|
|
--minetest.log("action", "[mcl_raids] Villager Found.")
|
2022-10-23 01:41:53 +03:00
|
|
|
return true
|
|
|
|
else
|
2022-11-06 12:49:39 +02:00
|
|
|
--minetest.log("action", "[mcl_raids] No Villager Found.")
|
2022-10-23 01:41:53 +03:00
|
|
|
return false
|
|
|
|
end
|
2022-10-23 01:04:58 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-10-24 18:17:22 +03:00
|
|
|
function mcl_raids.find_bed(pos)
|
2022-10-24 18:37:30 +03:00
|
|
|
return minetest.find_node_near(pos,128,{"mcl_beds:bed_red_bottom"})
|
2022-10-23 01:04:58 +03:00
|
|
|
end
|
|
|
|
|
2022-10-24 18:17:22 +03:00
|
|
|
function mcl_raids.find_village(pos)
|
2022-10-23 01:04:58 +03:00
|
|
|
local bed = mcl_raids.find_bed(pos)
|
2022-10-24 18:37:30 +03:00
|
|
|
if bed and mcl_raids.find_villager(bed) then
|
|
|
|
return bed
|
2022-10-23 01:04:58 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-10-24 01:10:17 +03:00
|
|
|
mcl_events.register_event("raid",{
|
2022-11-04 22:28:51 +02:00
|
|
|
readable_name = "Raid",
|
2022-10-24 01:10:17 +03:00
|
|
|
max_stage = 5,
|
|
|
|
health = 1,
|
|
|
|
health_max = 1,
|
2022-10-25 01:30:14 +03:00
|
|
|
exclusive_to_area = 128,
|
2022-11-04 22:28:51 +02:00
|
|
|
enable_bossbar = true,
|
2022-10-24 01:10:17 +03:00
|
|
|
cond_start = function(self)
|
|
|
|
local r = {}
|
|
|
|
for _,p in pairs(minetest.get_connected_players()) do
|
2022-10-25 01:30:14 +03:00
|
|
|
if mcl_potions.player_has_effect(p,"bad_omen") then
|
2022-10-24 18:37:30 +03:00
|
|
|
local raid_pos = mcl_raids.find_village(p:get_pos())
|
|
|
|
if raid_pos then
|
2022-10-25 01:30:14 +03:00
|
|
|
table.insert(r,{ player = p:get_player_name(), pos = raid_pos })
|
2022-10-24 18:37:30 +03:00
|
|
|
end
|
2022-10-24 01:10:17 +03:00
|
|
|
end
|
2022-10-23 01:04:58 +03:00
|
|
|
end
|
2022-10-24 01:10:17 +03:00
|
|
|
if #r > 0 then return r end
|
|
|
|
end,
|
|
|
|
on_start = function(self)
|
|
|
|
self.mobs = {}
|
|
|
|
self.health_max = 1
|
|
|
|
self.health = 0
|
2022-11-03 15:10:30 +02:00
|
|
|
local lv = mcl_potions.player_get_effect(minetest.get_player_by_name(self.player), "bad_omen")
|
|
|
|
if lv and lv.factor and lv.factor > 1 then self.max_stage = 6 end
|
2022-10-24 01:10:17 +03:00
|
|
|
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)
|
2022-11-17 06:39:55 +02:00
|
|
|
local player_near = false
|
|
|
|
for _,pl in pairs(minetest.get_connected_players()) do
|
|
|
|
if self.pos and vector.distance(pl:get_pos(),self.pos) < 72 then player_near = true end
|
|
|
|
end
|
|
|
|
if not player_near then return false end
|
|
|
|
--let the event api handle cancel the event when no players are near
|
|
|
|
--without this check it would sort out the unloaded mob entities and
|
|
|
|
--think the raid is defeated.
|
2022-10-24 01:10:17 +03:00
|
|
|
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")
|
2022-10-25 02:20:09 +03:00
|
|
|
awards.unlock(self.player,"mcl:hero_of_the_village")
|
2022-11-08 04:57:11 +02:00
|
|
|
mcl_potions.player_clear_effect(minetest.get_player_by_name(self.player),"bad_omen")
|
2022-10-24 01:10:17 +03:00
|
|
|
end,
|
|
|
|
})
|
2022-11-07 14:04:18 +02:00
|
|
|
|
|
|
|
minetest.register_chatcommand("raidcap",{
|
|
|
|
privs = {debug = true},
|
|
|
|
func = function(pname,param)
|
2022-11-08 02:59:16 +02:00
|
|
|
local c = minetest.add_entity(minetest.get_player_by_name(pname):get_pos(),"mobs_mc:pillager")
|
|
|
|
mcl_raids.promote_to_raidcaptain(c)
|
2022-11-07 14:04:18 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("dump_banner_layers",{
|
|
|
|
privs = {debug = true},
|
|
|
|
func = function(pname,param)
|
|
|
|
local p = minetest.get_player_by_name(pname)
|
|
|
|
mcl_raids.drop_obanner(vector.offset(p:get_pos(),1,1,1))
|
|
|
|
for k,v in pairs(minetest.get_objects_inside_radius(p:get_pos(),5)) do
|
|
|
|
local l = v:get_luaentity()
|
|
|
|
if l and l.name == "mcl_banners:standing_banner" then
|
|
|
|
minetest.log(dump(l._base_color))
|
|
|
|
minetest.log(dump(l._layers))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|