From 8b6409b7f11db60fef517ef7196dfbd89c8e9e0c Mon Sep 17 00:00:00 2001 From: PrairieAstronomer Date: Mon, 24 Oct 2022 17:05:09 +0200 Subject: [PATCH 01/49] Add mcl_raids --- mods/ENVIRONMENT/mcl_raids/init.lua | 91 +++++++++++++++++++++++++++++ mods/ENVIRONMENT/mcl_raids/mod.conf | 1 + 2 files changed, 92 insertions(+) create mode 100644 mods/ENVIRONMENT/mcl_raids/init.lua create mode 100644 mods/ENVIRONMENT/mcl_raids/mod.conf diff --git a/mods/ENVIRONMENT/mcl_raids/init.lua b/mods/ENVIRONMENT/mcl_raids/init.lua new file mode 100644 index 000000000..073628a6c --- /dev/null +++ b/mods/ENVIRONMENT/mcl_raids/init.lua @@ -0,0 +1,91 @@ +-- mcl_raids + +mcl_raids = {} + +-- Define the amount of illagers to spawn each wave. +mcl_raids.wave_definitions = { + -- Pillager + { + illager_name = "mobs_mc:pillager", + wave_1 = 5, + wave_2 = 4, + wave_3 = 4, + wave_4 = 5, + wave_5 = 5, + extra_wave = 5, + }, + -- Vindicator aka Angry Axeman + { + illager_name = "mobs_mc:vindicator", + wave_1 = 1, + 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", + wave_1 = 0, + wave_2 = 0, + wave_3 = 1, + wave_4 = 3, + wave_5 = 1, + extra_wave = 1, + }, + -- Evoker + { + illager_name = "mobs_mc:evoker", + wave_1 = 0, + wave_2 = 0, + wave_3 = 0, + wave_4 = 0, + wave_5 = 1, + extra_wave = 1, + }, +} + +minetest.register_chatcommand("spawn_raid", { + privs = { + server = true, + }, + func = function(name) + local wave = 1 + local illager_count = 0 + local player = minetest.get_player_by_name(name) + local pos = player:get_pos() + 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))) + 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"}) + if sn and #sn > 0 then + spawn_pos = sn[1] + if spawn_pos then + minetest.log("action", "[mcl_raids] Raid Spawn Position chosen at " .. minetest.pos_to_string(spawn_pos) .. ".") + spawnable = true + 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 + 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 +}) diff --git a/mods/ENVIRONMENT/mcl_raids/mod.conf b/mods/ENVIRONMENT/mcl_raids/mod.conf new file mode 100644 index 000000000..f04ef142a --- /dev/null +++ b/mods/ENVIRONMENT/mcl_raids/mod.conf @@ -0,0 +1 @@ +name = mcl_raids \ No newline at end of file From 96ac31bec3ff6c184ecff9825fb4f79f11db34cb Mon Sep 17 00:00:00 2001 From: PrairieWind Date: Sat, 22 Oct 2022 13:56:00 -0600 Subject: [PATCH 02/49] Add Bad Omen Effect --- mods/ENVIRONMENT/mcl_raids/init.lua | 68 +++++++++--------- mods/ITEMS/mcl_potions/commands.lua | 1 + mods/ITEMS/mcl_potions/functions.lua | 48 +++++++++++++ mods/ITEMS/mcl_potions/mod.conf | 2 +- .../textures/mcl_potions_effect_bad_omen.png | Bin 0 -> 4566 bytes 5 files changed, 86 insertions(+), 33 deletions(-) create mode 100644 mods/ITEMS/mcl_potions/textures/mcl_potions_effect_bad_omen.png diff --git a/mods/ENVIRONMENT/mcl_raids/init.lua b/mods/ENVIRONMENT/mcl_raids/init.lua index 073628a6c..8194e686a 100644 --- a/mods/ENVIRONMENT/mcl_raids/init.lua +++ b/mods/ENVIRONMENT/mcl_raids/init.lua @@ -47,45 +47,49 @@ mcl_raids.wave_definitions = { }, } +mcl_raids.spawn_raid = function(pos, wave) + 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))) + 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"}) + if sn and #sn > 0 then + spawn_pos = sn[1] + if spawn_pos then + minetest.log("action", "[mcl_raids] Raid Spawn Position chosen at " .. minetest.pos_to_string(spawn_pos) .. ".") + spawnable = true + 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 + 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 + minetest.register_chatcommand("spawn_raid", { privs = { server = true, }, func = function(name) local wave = 1 - local illager_count = 0 local player = minetest.get_player_by_name(name) local pos = player:get_pos() - 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))) - 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"}) - if sn and #sn > 0 then - spawn_pos = sn[1] - if spawn_pos then - minetest.log("action", "[mcl_raids] Raid Spawn Position chosen at " .. minetest.pos_to_string(spawn_pos) .. ".") - spawnable = true - 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 - 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 + mcl_raids.spawn_raid(pos, wave) end }) diff --git a/mods/ITEMS/mcl_potions/commands.lua b/mods/ITEMS/mcl_potions/commands.lua index 1fbf591d9..76ac71e72 100644 --- a/mods/ITEMS/mcl_potions/commands.lua +++ b/mods/ITEMS/mcl_potions/commands.lua @@ -19,6 +19,7 @@ get_chat_function["water_breathing"] = mcl_potions.water_breathing_func get_chat_function["leaping"] = mcl_potions.leaping_func get_chat_function["swiftness"] = mcl_potions.swiftness_func get_chat_function["heal"] = mcl_potions.healing_func +get_chat_function["bad_omen"] = mcl_potions.bad_omen_func minetest.register_chatcommand("effect",{ params = S(" []"), diff --git a/mods/ITEMS/mcl_potions/functions.lua b/mods/ITEMS/mcl_potions/functions.lua index 15be8a90c..446191c0a 100644 --- a/mods/ITEMS/mcl_potions/functions.lua +++ b/mods/ITEMS/mcl_potions/functions.lua @@ -9,6 +9,7 @@ EF.leaping = {} EF.swift = {} -- for swiftness AND slowness EF.night_vision = {} EF.fire_proof = {} +EF.bad_omen = {} local EFFECT_TYPES = 0 for _,_ in pairs(EF) do @@ -350,6 +351,28 @@ minetest.register_globalstep(function(dtime) end + -- Check for Bad Omen + for player, vals in pairs(EF.bad_omen) do + + is_player = player:is_player() + entity = player:get_luaentity() + + EF.bad_omen[player].timer = EF.bad_omen[player].timer + dtime + + if player:get_pos() then mcl_potions._add_spawner(player, "#0b6138") end + + if EF.bad_omen[player] and EF.bad_omen[player].timer >= EF.bad_omen[player].dur then + EF.bad_omen[player] = nil + mcl_raids.spawn_raid(player:get_pos(), 1) + if is_player then + meta = player:get_meta() + meta:set_string("_had_bad_omen", minetest.serialize(EF.bad_omen[player])) + potions_set_hud(player) + end + end + + end + end) -- Prevent damage to player with Fire Resistance enabled @@ -386,6 +409,7 @@ function mcl_potions._clear_cached_player_data(player) EF.swift[player] = nil EF.night_vision[player] = nil EF.fire_proof[player] = nil + EF.bad_omen[player] = nil meta = player:get_meta() meta:set_int("night_vision", 0) @@ -429,6 +453,7 @@ function mcl_potions._save_player_effects(player) meta:set_string("_is_swift", minetest.serialize(EF.swift[player])) meta:set_string("_is_cat", minetest.serialize(EF.night_vision[player])) meta:set_string("_is_fire_proof", minetest.serialize(EF.fire_proof[player])) + meta:set_string("_has_bad_omen", minetest.serialize(EF.bad_omen[player])) end @@ -480,6 +505,10 @@ function mcl_potions._load_player_effects(player) EF.fire_proof[player] = minetest.deserialize(meta:get_string("_is_fire_proof")) end + if minetest.deserialize(meta:get_string("_had_bad_omen")) then + EF.bad_omen[player] = minetest.deserialize(meta:get_string("_has_bad_omen")) + end + end -- Returns true if player has given effect @@ -966,3 +995,22 @@ function mcl_potions._extinguish_nearby_fire(pos, radius) end return exting end + +function mcl_potions.bad_omen_func(player, null, duration) + + if not EF.bad_omen[player] then + + EF.bad_omen[player] = {dur = duration, timer = 0} + + else + + local victim = EF.bad_omen[player] + victim.dur = math.max(duration, victim.dur - victim.timer) + victim.timer = 0 + end + + if player:is_player() then + potions_set_icons(player) + end + +end diff --git a/mods/ITEMS/mcl_potions/mod.conf b/mods/ITEMS/mcl_potions/mod.conf index bcb6d8ad3..c3e56fe5a 100644 --- a/mods/ITEMS/mcl_potions/mod.conf +++ b/mods/ITEMS/mcl_potions/mod.conf @@ -1,2 +1,2 @@ name = mcl_potions -depends = mcl_core, mcl_farming, mcl_mobitems, mcl_fishing, mcl_bows, mcl_end, mcl_weather, playerphysics, mcl_wip +depends = mcl_core, mcl_farming, mcl_mobitems, mcl_fishing, mcl_bows, mcl_end, mcl_weather, playerphysics, mcl_wip, mcl_raids diff --git a/mods/ITEMS/mcl_potions/textures/mcl_potions_effect_bad_omen.png b/mods/ITEMS/mcl_potions/textures/mcl_potions_effect_bad_omen.png new file mode 100644 index 0000000000000000000000000000000000000000..dfe8f0332605f4d3995be6ec3de58f5f00e6054c GIT binary patch literal 4566 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 AhyVZp literal 0 HcmV?d00001 From 1b6d778dd12894d9f1e3e22d67f8b53f271f3ed9 Mon Sep 17 00:00:00 2001 From: PrairieWind Date: Sat, 22 Oct 2022 16:04:58 -0600 Subject: [PATCH 03/49] Add Village Checks --- mods/ENVIRONMENT/mcl_raids/init.lua | 55 ++++++++++++++++++++++++++++ mods/ITEMS/mcl_potions/functions.lua | 6 +-- 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/mods/ENVIRONMENT/mcl_raids/init.lua b/mods/ENVIRONMENT/mcl_raids/init.lua index 8194e686a..5aa082398 100644 --- a/mods/ENVIRONMENT/mcl_raids/init.lua +++ b/mods/ENVIRONMENT/mcl_raids/init.lua @@ -82,6 +82,47 @@ mcl_raids.spawn_raid = function(pos, wave) end end +mcl_raids.find_villager = function(pos) + local obj = minetest.get_objects_inside_radius(pos, 16) + for _, objects in pairs(obj) do + object = objects:get_luaentity() + if object and 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 + 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") + if beds then + 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 + + if (bed and villager) and raid_started == false then + mcl_raids.spawn_raid(pos, 1) + raid_started = true + minetest.log("action", "[mcl_raids] Village found, starting raid.") + return true + else + minetest.log("action", "[mcl_raids] Village not found, raid is not starting.") + return false + end +end + minetest.register_chatcommand("spawn_raid", { privs = { server = true, @@ -93,3 +134,17 @@ minetest.register_chatcommand("spawn_raid", { mcl_raids.spawn_raid(pos, wave) end }) + +local etime = 0 +minetest.register_globalstep(function(dtime) + etime = dtime + etime + if etime < 10 then return end + etime = 0 + for _,pl in pairs(minetest.get_connected_players()) do + if pl:get_meta():get_string("_has_bad_omen") then + mcl_raids.find_village(pl:get_pos()) + else + return + end + end +end) diff --git a/mods/ITEMS/mcl_potions/functions.lua b/mods/ITEMS/mcl_potions/functions.lua index 446191c0a..d4478c33f 100644 --- a/mods/ITEMS/mcl_potions/functions.lua +++ b/mods/ITEMS/mcl_potions/functions.lua @@ -355,7 +355,6 @@ minetest.register_globalstep(function(dtime) for player, vals in pairs(EF.bad_omen) do is_player = player:is_player() - entity = player:get_luaentity() EF.bad_omen[player].timer = EF.bad_omen[player].timer + dtime @@ -363,10 +362,9 @@ minetest.register_globalstep(function(dtime) if EF.bad_omen[player] and EF.bad_omen[player].timer >= EF.bad_omen[player].dur then EF.bad_omen[player] = nil - mcl_raids.spawn_raid(player:get_pos(), 1) if is_player then meta = player:get_meta() - meta:set_string("_had_bad_omen", minetest.serialize(EF.bad_omen[player])) + meta:set_string("_has_bad_omen", minetest.serialize(EF.bad_omen[player])) potions_set_hud(player) end end @@ -505,7 +503,7 @@ function mcl_potions._load_player_effects(player) EF.fire_proof[player] = minetest.deserialize(meta:get_string("_is_fire_proof")) end - if minetest.deserialize(meta:get_string("_had_bad_omen")) then + if minetest.deserialize(meta:get_string("_has_bad_omen")) then EF.bad_omen[player] = minetest.deserialize(meta:get_string("_has_bad_omen")) end From 5dc1a3d456089d60d005d391fc088d625b839f6d Mon Sep 17 00:00:00 2001 From: PrairieWind Date: Sat, 22 Oct 2022 16:41:53 -0600 Subject: [PATCH 04/49] Village Finder Tweaks --- mods/ENVIRONMENT/mcl_raids/init.lua | 39 ++++++++++++++++++----------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/mods/ENVIRONMENT/mcl_raids/init.lua b/mods/ENVIRONMENT/mcl_raids/init.lua index 5aa082398..2c4adf003 100644 --- a/mods/ENVIRONMENT/mcl_raids/init.lua +++ b/mods/ENVIRONMENT/mcl_raids/init.lua @@ -56,7 +56,7 @@ mcl_raids.spawn_raid = function(pos, wave) 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"}) if sn and #sn > 0 then - spawn_pos = sn[1] + local spawn_pos = sn[1] if spawn_pos then minetest.log("action", "[mcl_raids] Raid Spawn Position chosen at " .. minetest.pos_to_string(spawn_pos) .. ".") spawnable = true @@ -83,22 +83,26 @@ mcl_raids.spawn_raid = function(pos, wave) end mcl_raids.find_villager = function(pos) - local obj = minetest.get_objects_inside_radius(pos, 16) - for _, objects in pairs(obj) do - object = objects:get_luaentity() - if object and 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 + 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 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") - if beds then + if beds[1] then minetest.log("action", "[mcl_raids] Bed Found.") return true else @@ -113,10 +117,17 @@ mcl_raids.find_village = function(pos) local raid_started = false if (bed and villager) and raid_started == false then - mcl_raids.spawn_raid(pos, 1) - raid_started = true - minetest.log("action", "[mcl_raids] Village found, starting raid.") + 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 return true + elseif raid_started == true then + minetest.log("action", "[mcl_raids] Raid already started.") + return else minetest.log("action", "[mcl_raids] Village not found, raid is not starting.") return false From f06d5a1ee324f3416f83c8ca24d044b56e944415 Mon Sep 17 00:00:00 2001 From: cora Date: Sat, 22 Oct 2022 23:36:23 +0200 Subject: [PATCH 05/49] Add event api prototype state, test with chatcommand /infest (debug priv) --- mods/CORE/mcl_events/init.lua | 127 ++++++++++++++++++++++++++++++++++ mods/CORE/mcl_events/mod.conf | 3 + 2 files changed, 130 insertions(+) create mode 100644 mods/CORE/mcl_events/init.lua create mode 100644 mods/CORE/mcl_events/mod.conf diff --git a/mods/CORE/mcl_events/init.lua b/mods/CORE/mcl_events/init.lua new file mode 100644 index 000000000..164dfdaa1 --- /dev/null +++ b/mods/CORE/mcl_events/init.lua @@ -0,0 +1,127 @@ +mcl_events = {} +mcl_events.registered_events = {} +local active_events = {} + +local tpl_eventdef = { + stage = 1, + max_stage = 1, + --pos = vector.zero(), + --time_start = 0, + completed = false, + cond_start = function(event) end, --return table of positions + on_step = function(event) end, + on_start = function(event) end, + on_stage_begin = function(event) end, + cond_progress = function(event) end, --return next stage + cond_complete = function(event) end, --return success +} + +function mcl_events.register_event(name,def) + mcl_events.registered_events[name] = {} + --setmetatable(mcl_events.registered_events[name],tpl_eventdef) + mcl_events.registered_events[name] = def + mcl_events.registered_events[name].name = name +end + +local function start_event(p,e) + minetest.log("event started: "..e.name.." at "..minetest.pos_to_string(p)) + local idx = #active_events + 1 + active_events[idx] = table.copy(e) + setmetatable(active_events[idx],e) + active_events[idx].pos = vector.copy(p) + active_events[idx].stage = 1 + active_events[idx].time_start = os.time() + active_events[idx]:on_start(p) +end + +local function finish_event(self,idx) + minetest.log("event finished: "..self.name.." at "..minetest.pos_to_string(self.pos)) + if self.on_complete then self:on_complete() end + table.remove(active_events,idx) +end + +local etime = 0 +function check_events(dtime) + for idx,ae in pairs(active_events) do + if ae.cond_complete and ae:cond_complete() then + finish_event(ae,idx) + elseif ae.max_stage and ae.max_stage < ae.stage then + finish_event(ae,idx) + elseif ae.cond_progress then + local p = ae:cond_progress() + if p == true then + ae.stage = ae.stage + 1 + minetest.log("event progressed to stage "..ae.stage) + ae:on_stage_begin() + elseif tonumber(p) then + ae.stage = tonumber(p) or ae.stage + 1 + minetest.log("event progressed to stage "..ae.stage) + ae:on_stage_begin() + end + + elseif ae.on_step then + ae:on_step() + end + end + etime = etime - dtime + if etime > 0 then return end + etime = 10 + for _,e in pairs(mcl_events.registered_events) do + local pp = e.cond_start() + if pp then + for _,p in pairs(pp) do + start_event(p,e) + end + end + end +end + +minetest.register_globalstep(check_events) + +mcl_events.register_event("infestation",{ + max_stage = 5, + cond_start = function(self) + local r = {} + for _,p in pairs(minetest.get_connected_players()) do + if p:get_meta():get_string("infestation-omen") == "yes" then + p:get_meta():set_string("infestation-omen","") + table.insert(r,p:get_pos()) + end + end + if #r > 0 then return r end + end, + on_start = function(self) + self.mobs = {} + minetest.log("inf") + end, + cond_progress = function(self) + local m = {} + for k,o in pairs(self.mobs) do + if o and o:get_pos() then table.insert(m,o) end + end + if #m < 1 then + minetest.log("INFESTATION stage "..self.stage.." completed") + return true end + self.mobs = m + end, + on_stage_begin = function(self) + minetest.log("event "..self.name.." stage "..self.stage.." begin...") + for i=1,5 * 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") + if m then + table.insert(self.mobs,m) + end + end + end, + on_complete = function(self) + minetest.log("INFESTATION complete") + end, +}) + +minetest.register_chatcommand("infest",{ + privs = {debug = true}, + func = function(n,param) + local p = minetest.get_player_by_name(n) + p:get_meta():set_string("infestation-omen","yes") + end, +}) diff --git a/mods/CORE/mcl_events/mod.conf b/mods/CORE/mcl_events/mod.conf new file mode 100644 index 000000000..a69f0a303 --- /dev/null +++ b/mods/CORE/mcl_events/mod.conf @@ -0,0 +1,3 @@ +name = mcl_events +author = cora +depends = mcl_mobs From 627ce0dc3bc72ebea2d31e4d348e0194107e017a Mon Sep 17 00:00:00 2001 From: cora Date: Sun, 23 Oct 2022 00:13:28 +0200 Subject: [PATCH 06/49] Finish at max_stage not max_stage + 1 --- mods/CORE/mcl_events/init.lua | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/mods/CORE/mcl_events/init.lua b/mods/CORE/mcl_events/init.lua index 164dfdaa1..8c440e22c 100644 --- a/mods/CORE/mcl_events/init.lua +++ b/mods/CORE/mcl_events/init.lua @@ -44,10 +44,12 @@ local etime = 0 function check_events(dtime) for idx,ae in pairs(active_events) do if ae.cond_complete and ae:cond_complete() then + ae.finished = true finish_event(ae,idx) - elseif ae.max_stage and ae.max_stage < ae.stage then + elseif not ae.cond_complete and ae.max_stage and ae.max_stage <= ae.stage then + ae.finished = true finish_event(ae,idx) - elseif ae.cond_progress then + elseif not ae.finished and ae.cond_progress then local p = ae:cond_progress() if p == true then ae.stage = ae.stage + 1 @@ -58,8 +60,7 @@ function check_events(dtime) minetest.log("event progressed to stage "..ae.stage) ae:on_stage_begin() end - - elseif ae.on_step then + elseif not ae.finished and ae.on_step then ae:on_step() end end @@ -92,7 +93,6 @@ mcl_events.register_event("infestation",{ end, on_start = function(self) self.mobs = {} - minetest.log("inf") end, cond_progress = function(self) local m = {} @@ -113,6 +113,9 @@ mcl_events.register_event("infestation",{ end end end, + cond_complete = function(self) + return self.stage >= self.max_stage + end, on_complete = function(self) minetest.log("INFESTATION complete") end, From f17a9220bbb5e446967a196b4efed47d33106700 Mon Sep 17 00:00:00 2001 From: cora Date: Sun, 23 Oct 2022 03:44:15 +0200 Subject: [PATCH 07/49] Add bossbar support --- mods/CORE/mcl_events/init.lua | 56 ++++++++++++++++++++++++++++++----- mods/CORE/mcl_events/mod.conf | 2 +- 2 files changed, 50 insertions(+), 8 deletions(-) diff --git a/mods/CORE/mcl_events/init.lua b/mods/CORE/mcl_events/init.lua index 8c440e22c..46c847169 100644 --- a/mods/CORE/mcl_events/init.lua +++ b/mods/CORE/mcl_events/init.lua @@ -5,6 +5,8 @@ local active_events = {} local tpl_eventdef = { stage = 1, max_stage = 1, + percent = 100, + bossbars = {}, --pos = vector.zero(), --time_start = 0, completed = false, @@ -23,6 +25,21 @@ function mcl_events.register_event(name,def) mcl_events.registered_events[name].name = name end +local function addbars(self) + for _,player in pairs(minetest.get_connected_players()) do + if vector.distance(self.pos,player:get_pos()) < 75 then + local bar = mcl_bossbars.add_bar(player, {color = "red", text = self.name .. " stage "..self.stage.." / "..self.max_stage, percentage = self.percent }, true,1) + table.insert(self.bars,bar) + end + end +end + +local function update_bars(self) + for _,b in pairs(self.bars) do + mcl_bossbars.update_bar(b,{text = self.name .. " stage "..self.stage,percentage=self.percent}) + end +end + local function start_event(p,e) minetest.log("event started: "..e.name.." at "..minetest.pos_to_string(p)) local idx = #active_events + 1 @@ -32,11 +49,17 @@ local function start_event(p,e) active_events[idx].stage = 1 active_events[idx].time_start = os.time() active_events[idx]:on_start(p) + active_events[idx].bars = {} + active_events[idx].percent = 0 + addbars(active_events[idx]) end local function finish_event(self,idx) minetest.log("event finished: "..self.name.." at "..minetest.pos_to_string(self.pos)) if self.on_complete then self:on_complete() end + for _,b in pairs(self.bars) do + mcl_bossbars.remove_bar(b) + end table.remove(active_events,idx) end @@ -53,16 +76,16 @@ function check_events(dtime) local p = ae:cond_progress() if p == true then ae.stage = ae.stage + 1 - minetest.log("event progressed to stage "..ae.stage) ae:on_stage_begin() elseif tonumber(p) then ae.stage = tonumber(p) or ae.stage + 1 - minetest.log("event progressed to stage "..ae.stage) ae:on_stage_begin() end elseif not ae.finished and ae.on_step then ae:on_step() end + addbars(ae) + --update_bars(ae) end etime = etime - dtime if etime > 0 then return end @@ -81,6 +104,8 @@ minetest.register_globalstep(check_events) mcl_events.register_event("infestation",{ max_stage = 5, + health = 1, + health_max = 1, cond_start = function(self) local r = {} for _,p in pairs(minetest.get_connected_players()) do @@ -93,28 +118,45 @@ mcl_events.register_event("infestation",{ 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 table.insert(m,o) end + if o and o:get_pos() then + local l = o:get_luaentity() + h = h + l.health + table.insert(m,o) + end end + self.health = h + self.percent = math.max(0,(self.health / self.health_max ) * 100) if #m < 1 then - minetest.log("INFESTATION stage "..self.stage.." completed") return true end self.mobs = m end, on_stage_begin = function(self) - minetest.log("event "..self.name.." stage "..self.stage.." begin...") + self.health_max = 1 for i=1,5 * 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") - if m then + local l = m:get_luaentity() + if l then + self.health_max = self.health_max + l.health table.insert(self.mobs,m) end end end, cond_complete = function(self) - return self.stage >= self.max_stage + 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("INFESTATION complete") diff --git a/mods/CORE/mcl_events/mod.conf b/mods/CORE/mcl_events/mod.conf index a69f0a303..44d11a1cc 100644 --- a/mods/CORE/mcl_events/mod.conf +++ b/mods/CORE/mcl_events/mod.conf @@ -1,3 +1,3 @@ name = mcl_events author = cora -depends = mcl_mobs +depends = mcl_mobs,mcl_bossbars From 052e76bfcca40ada88fa2a08326286cc279ceac4 Mon Sep 17 00:00:00 2001 From: cora Date: Sun, 23 Oct 2022 04:03:05 +0200 Subject: [PATCH 08/49] start at effective stage 1 --- mods/CORE/mcl_events/init.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/mods/CORE/mcl_events/init.lua b/mods/CORE/mcl_events/init.lua index 46c847169..62ddd0363 100644 --- a/mods/CORE/mcl_events/init.lua +++ b/mods/CORE/mcl_events/init.lua @@ -3,10 +3,10 @@ mcl_events.registered_events = {} local active_events = {} local tpl_eventdef = { - stage = 1, + stage = 0, max_stage = 1, percent = 100, - bossbars = {}, + bars = {}, --pos = vector.zero(), --time_start = 0, completed = false, @@ -45,12 +45,12 @@ local function start_event(p,e) local idx = #active_events + 1 active_events[idx] = table.copy(e) setmetatable(active_events[idx],e) + active_events[idx].stage = 0 + active_events[idx].percent = 100 + active_events[idx].bars = {} active_events[idx].pos = vector.copy(p) - active_events[idx].stage = 1 active_events[idx].time_start = os.time() active_events[idx]:on_start(p) - active_events[idx].bars = {} - active_events[idx].percent = 0 addbars(active_events[idx]) end @@ -131,15 +131,15 @@ mcl_events.register_event("infestation",{ 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 - self.mobs = m end, on_stage_begin = function(self) self.health_max = 1 - for i=1,5 * 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 l = m:get_luaentity() if l then From 390aec5d7a388e867a732b65be3e383ade8e9df5 Mon Sep 17 00:00:00 2001 From: cora Date: Mon, 24 Oct 2022 00:10:17 +0200 Subject: [PATCH 09/49] Integrate raids with mcl_events --- mods/CORE/mcl_events/init.lua | 2 +- mods/ENVIRONMENT/mcl_raids/init.lua | 167 ++++++++++++++++------------ mods/ENVIRONMENT/mcl_raids/mod.conf | 4 +- 3 files changed, 101 insertions(+), 72 deletions(-) diff --git a/mods/CORE/mcl_events/init.lua b/mods/CORE/mcl_events/init.lua index 62ddd0363..4718dd8df 100644 --- a/mods/CORE/mcl_events/init.lua +++ b/mods/CORE/mcl_events/init.lua @@ -138,7 +138,7 @@ mcl_events.register_event("infestation",{ return true end end, on_stage_begin = function(self) - self.health_max = 1 + self.health_max = 0 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 l = m:get_luaentity() diff --git a/mods/ENVIRONMENT/mcl_raids/init.lua b/mods/ENVIRONMENT/mcl_raids/init.lua index 2c4adf003..f76c26151 100644 --- a/mods/ENVIRONMENT/mcl_raids/init.lua +++ b/mods/ENVIRONMENT/mcl_raids/init.lua @@ -3,83 +3,74 @@ mcl_raids = {} -- Define the amount of illagers to spawn each wave. -mcl_raids.wave_definitions = { - -- Pillager +local waves = { { - illager_name = "mobs_mc:pillager", - wave_1 = 5, - wave_2 = 4, - wave_3 = 4, - wave_4 = 5, - wave_5 = 5, - extra_wave = 5, + ["mobs_mc:pillager"] = 5, + ["mobs_mc:vindicator"] = 1, }, - -- Vindicator aka Angry Axeman { - illager_name = "mobs_mc:vindicator", - wave_1 = 1, - wave_2 = 3, - wave_3 = 1, - wave_4 = 2, - wave_5 = 5, - extra_wave = 5, + ["mobs_mc:pillager"] = 4, + ["mobs_mc:vindicator"] = 3, }, - --{"mobs_mc:ravager", 0, 0, 1, 0, 0, 2}, - -- Witch { - illager_name = "mobs_mc:witch", - wave_1 = 0, - wave_2 = 0, - wave_3 = 1, - wave_4 = 3, - wave_5 = 1, - extra_wave = 1, + ["mobs_mc:pillager"] = 4, + ["mobs_mc:vindicator"] = 1, + ["mobs_mc:witch"] = 1, + --["mobs_mc:ravager"] = 1, }, - -- Evoker { - illager_name = "mobs_mc:evoker", - wave_1 = 0, - wave_2 = 0, - wave_3 = 0, - wave_4 = 0, - wave_5 = 1, - extra_wave = 1, + ["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, }, } -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 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))) - 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 - local spawn_pos = sn[1] + local spawn_pos = sn[math.random(#sn)] if spawn_pos then 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 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 - 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 mcl_raids.find_villager = function(pos) @@ -115,7 +106,7 @@ mcl_raids.find_village = function(pos) local bed = mcl_raids.find_bed(pos) local villager = mcl_raids.find_villager(pos) local raid_started = false - + if (bed and villager) and raid_started == false then local raid = mcl_raids.spawn_raid(pos, 1) if raid then @@ -136,26 +127,62 @@ end minetest.register_chatcommand("spawn_raid", { privs = { - server = true, + debug = true, }, func = function(name) - local wave = 1 - local player = minetest.get_player_by_name(name) - local pos = player:get_pos() - mcl_raids.spawn_raid(pos, wave) + local m = minetest.get_player_by_name(name):get_meta() + m:set_string("_has_bad_omen","yes") end }) -local etime = 0 -minetest.register_globalstep(function(dtime) - etime = dtime + etime - if etime < 10 then return end - etime = 0 - for _,pl in pairs(minetest.get_connected_players()) do - if pl:get_meta():get_string("_has_bad_omen") then - mcl_raids.find_village(pl:get_pos()) - else - return +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 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, +}) diff --git a/mods/ENVIRONMENT/mcl_raids/mod.conf b/mods/ENVIRONMENT/mcl_raids/mod.conf index f04ef142a..694520114 100644 --- a/mods/ENVIRONMENT/mcl_raids/mod.conf +++ b/mods/ENVIRONMENT/mcl_raids/mod.conf @@ -1 +1,3 @@ -name = mcl_raids \ No newline at end of file +name = mcl_raids +author = PrairieWind +depends = mcl_events, mcl_mobs From 99fce095efb505857e0a152adf8685dba6593113 Mon Sep 17 00:00:00 2001 From: cora Date: Mon, 24 Oct 2022 17:17:22 +0200 Subject: [PATCH 10/49] fix closure style function declarations its BANNED in CONTRIB.md --- mods/ENVIRONMENT/mcl_raids/init.lua | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/mods/ENVIRONMENT/mcl_raids/init.lua b/mods/ENVIRONMENT/mcl_raids/init.lua index f76c26151..fa42339f4 100644 --- a/mods/ENVIRONMENT/mcl_raids/init.lua +++ b/mods/ENVIRONMENT/mcl_raids/init.lua @@ -1,5 +1,4 @@ -- mcl_raids - mcl_raids = {} -- Define the amount of illagers to spawn each wave. @@ -39,7 +38,7 @@ local extra_wave = { --["mobs_mc:ravager"] = 2, } -mcl_raids.spawn_raid = function(event) +function mcl_raids.spawn_raid(event) local pos = event.pos local wave = event.stage local illager_count = 0 @@ -73,7 +72,7 @@ mcl_raids.spawn_raid = function(event) end end -mcl_raids.find_villager = function(pos) +function mcl_raids.find_villager(pos) local obj = minetest.get_objects_inside_radius(pos, 8) for _, objects in ipairs(obj) do local object = objects:get_luaentity() @@ -91,7 +90,7 @@ mcl_raids.find_villager = function(pos) end end -mcl_raids.find_bed = function(pos) +function mcl_raids.find_bed(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") if beds[1] then minetest.log("action", "[mcl_raids] Bed Found.") @@ -102,7 +101,7 @@ mcl_raids.find_bed = function(pos) end end -mcl_raids.find_village = function(pos) +function mcl_raids.find_village(pos) local bed = mcl_raids.find_bed(pos) local villager = mcl_raids.find_villager(pos) local raid_started = false From 7ab2c5fecd20c1e52a5966b35b994270183a15a1 Mon Sep 17 00:00:00 2001 From: cora Date: Mon, 24 Oct 2022 17:37:11 +0200 Subject: [PATCH 11/49] Make debug output an opt-in setting --- mods/CORE/mcl_events/init.lua | 14 +++++++++++--- settingtypes.txt | 5 ++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/mods/CORE/mcl_events/init.lua b/mods/CORE/mcl_events/init.lua index 4718dd8df..478b80896 100644 --- a/mods/CORE/mcl_events/init.lua +++ b/mods/CORE/mcl_events/init.lua @@ -1,5 +1,6 @@ mcl_events = {} mcl_events.registered_events = {} +local DBG = minetest.settings:get_bool("mcl_logging_event_api",false) local active_events = {} local tpl_eventdef = { @@ -18,6 +19,13 @@ local tpl_eventdef = { cond_complete = function(event) end, --return success } +local function mcl_log(m,l) + if DBG then + if not l then l = "action" end + minetest.log(l,"[mcl_events] "..m) + end +end + function mcl_events.register_event(name,def) mcl_events.registered_events[name] = {} --setmetatable(mcl_events.registered_events[name],tpl_eventdef) @@ -41,7 +49,7 @@ local function update_bars(self) end local function start_event(p,e) - minetest.log("event started: "..e.name.." at "..minetest.pos_to_string(p)) + mcl_log("event started: "..e.name.." at "..minetest.pos_to_string(vector.round(p))) local idx = #active_events + 1 active_events[idx] = table.copy(e) setmetatable(active_events[idx],e) @@ -55,7 +63,7 @@ local function start_event(p,e) end local function finish_event(self,idx) - minetest.log("event finished: "..self.name.." at "..minetest.pos_to_string(self.pos)) + mcl_log("Finished: "..self.name.." at "..minetest.pos_to_string(vector.round(self.pos))) if self.on_complete then self:on_complete() end for _,b in pairs(self.bars) do mcl_bossbars.remove_bar(b) @@ -159,7 +167,7 @@ mcl_events.register_event("infestation",{ return self.stage >= self.max_stage and #m < 1 end, on_complete = function(self) - minetest.log("INFESTATION complete") + mcl_log("INFESTATION complete") end, }) diff --git a/settingtypes.txt b/settingtypes.txt index 39dbc2e90..1b21316b7 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -233,4 +233,7 @@ mcl_logging_mapgen (Chunk generation logging) bool false mcl_logging_structures (Structure generation logging) bool true #Complete debug logging for mcl_signs events. Use this if you have issues with signs. -mcl_logging_mcl_signs (Complete debug logging for mcl_signs) bool true +mcl_logging_mcl_signs (Complete debug logging for mcl_signs) bool false + +#Debug logging for mcl_events. +mcl_logging_event_api (Debug logging for mcl_events) bool false From 37144f8787eef4d0774f4eed391a684b924a98d3 Mon Sep 17 00:00:00 2001 From: cora Date: Mon, 24 Oct 2022 17:37:30 +0200 Subject: [PATCH 12/49] Check for actual raid conditions and positions --- mods/ENVIRONMENT/mcl_raids/init.lua | 36 +++++++---------------------- 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/mods/ENVIRONMENT/mcl_raids/init.lua b/mods/ENVIRONMENT/mcl_raids/init.lua index fa42339f4..c267bdf9e 100644 --- a/mods/ENVIRONMENT/mcl_raids/init.lua +++ b/mods/ENVIRONMENT/mcl_raids/init.lua @@ -91,36 +91,13 @@ function mcl_raids.find_villager(pos) end function mcl_raids.find_bed(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") - if beds[1] then - minetest.log("action", "[mcl_raids] Bed Found.") - return true - else - minetest.log("action", "[mcl_raids] No Bed Found.") - return false - end + return minetest.find_node_near(pos,128,{"mcl_beds:bed_red_bottom"}) end function mcl_raids.find_village(pos) local bed = mcl_raids.find_bed(pos) - local villager = mcl_raids.find_villager(pos) - local raid_started = false - - if (bed and villager) and raid_started == false then - 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 - return true - elseif raid_started == true then - minetest.log("action", "[mcl_raids] Raid already started.") - return - else - minetest.log("action", "[mcl_raids] Village not found, raid is not starting.") - return false + if bed and mcl_raids.find_villager(bed) then + return bed end end @@ -143,8 +120,11 @@ mcl_events.register_event("raid",{ 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()) + local raid_pos = mcl_raids.find_village(p:get_pos()) + if raid_pos then + m:set_string("_has_bad_omen","") + table.insert(r,raid_pos) + end end end if #r > 0 then return r end From 2159edba05eb5e37ee9721f037d02c1365816e28 Mon Sep 17 00:00:00 2001 From: cora Date: Mon, 24 Oct 2022 23:23:08 +0200 Subject: [PATCH 13/49] Remove dependency on mcl_potions --- mods/ITEMS/mcl_potions/mod.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_potions/mod.conf b/mods/ITEMS/mcl_potions/mod.conf index c3e56fe5a..bcb6d8ad3 100644 --- a/mods/ITEMS/mcl_potions/mod.conf +++ b/mods/ITEMS/mcl_potions/mod.conf @@ -1,2 +1,2 @@ name = mcl_potions -depends = mcl_core, mcl_farming, mcl_mobitems, mcl_fishing, mcl_bows, mcl_end, mcl_weather, playerphysics, mcl_wip, mcl_raids +depends = mcl_core, mcl_farming, mcl_mobitems, mcl_fishing, mcl_bows, mcl_end, mcl_weather, playerphysics, mcl_wip From dc017864fd8c8b6944a0b8f22b9406eb2231d096 Mon Sep 17 00:00:00 2001 From: cora Date: Tue, 25 Oct 2022 00:30:14 +0200 Subject: [PATCH 14/49] raids: properly integrate potions api supports "level" now, bad omen > 1 means extra wave additionally the playername is saved in the event object now for later access and events can be made exclusive to a certain radius now. --- mods/CORE/mcl_events/init.lua | 18 +++++++++++++---- mods/ENVIRONMENT/mcl_raids/init.lua | 29 ++++++++++++++-------------- mods/ENVIRONMENT/mcl_raids/mod.conf | 2 +- mods/ITEMS/mcl_potions/functions.lua | 23 ++++++++++++---------- 4 files changed, 42 insertions(+), 30 deletions(-) diff --git a/mods/CORE/mcl_events/init.lua b/mods/CORE/mcl_events/init.lua index 478b80896..3819488ff 100644 --- a/mods/CORE/mcl_events/init.lua +++ b/mods/CORE/mcl_events/init.lua @@ -49,16 +49,16 @@ local function update_bars(self) end local function start_event(p,e) - mcl_log("event started: "..e.name.." at "..minetest.pos_to_string(vector.round(p))) + mcl_log("event started: "..e.name.." at "..minetest.pos_to_string(vector.round(p.pos))) local idx = #active_events + 1 active_events[idx] = table.copy(e) setmetatable(active_events[idx],e) + for k,v in pairs(p) do active_events[idx][k] = v end active_events[idx].stage = 0 active_events[idx].percent = 100 active_events[idx].bars = {} - active_events[idx].pos = vector.copy(p) active_events[idx].time_start = os.time() - active_events[idx]:on_start(p) + active_events[idx]:on_start(p.pos) addbars(active_events[idx]) end @@ -102,7 +102,17 @@ function check_events(dtime) local pp = e.cond_start() if pp then for _,p in pairs(pp) do - start_event(p,e) + local start = true + if e.exclusive_to_area then + for _,ae in pairs(active_events) do + if e.name == ae.name and vector.distance(p.pos,ae.pos) < e.exclusive_to_area then start = false end + end + end + if start then + start_event(p,e) + elseif DBG then + mcl_log("event "..e.name.." already active at "..minetest.pos_to_string(vector.round(p.pos))) + end end end end diff --git a/mods/ENVIRONMENT/mcl_raids/init.lua b/mods/ENVIRONMENT/mcl_raids/init.lua index c267bdf9e..6307933cf 100644 --- a/mods/ENVIRONMENT/mcl_raids/init.lua +++ b/mods/ENVIRONMENT/mcl_raids/init.lua @@ -48,12 +48,19 @@ function mcl_raids.spawn_raid(event) 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 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_bells.ring_once(pos) if sn and #sn > 0 then local spawn_pos = sn[math.random(#sn)] if spawn_pos then minetest.log("action", "[mcl_raids] Raid Spawn Position chosen at " .. minetest.pos_to_string(spawn_pos) .. ".") event.health_max = 0 - for m,c in pairs(waves[event.stage]) do + local w + if event.stage <= #waves then + w= waves[event.stage] + else + w = extra_wave + end + for m,c in pairs(w) do for i=1,c do local mob = mcl_mobs.spawn(spawn_pos,m) local l = mob:get_luaentity() @@ -101,29 +108,18 @@ function mcl_raids.find_village(pos) end end -minetest.register_chatcommand("spawn_raid", { - privs = { - debug = true, - }, - func = function(name) - local m = minetest.get_player_by_name(name):get_meta() - m:set_string("_has_bad_omen","yes") - end -}) - mcl_events.register_event("raid",{ max_stage = 5, health = 1, health_max = 1, + exclusive_to_area = 128, 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 + if mcl_potions.player_has_effect(p,"bad_omen") then local raid_pos = mcl_raids.find_village(p:get_pos()) if raid_pos then - m:set_string("_has_bad_omen","") - table.insert(r,raid_pos) + table.insert(r,{ player = p:get_player_name(), pos = raid_pos }) end end end @@ -133,6 +129,8 @@ mcl_events.register_event("raid",{ self.mobs = {} self.health_max = 1 self.health = 0 + local lv = mcl_potions.player_get_effect(minetest.get_player_by_name(self.player), "bad_omen").factor + if lv and lv > 1 then self.max_stage = 6 end end, cond_progress = function(self) local m = {} @@ -163,5 +161,6 @@ mcl_events.register_event("raid",{ end, on_complete = function(self) --minetest.log("RAID complete") + --TODO: Award hero of the village end, }) diff --git a/mods/ENVIRONMENT/mcl_raids/mod.conf b/mods/ENVIRONMENT/mcl_raids/mod.conf index 694520114..b81864cca 100644 --- a/mods/ENVIRONMENT/mcl_raids/mod.conf +++ b/mods/ENVIRONMENT/mcl_raids/mod.conf @@ -1,3 +1,3 @@ name = mcl_raids author = PrairieWind -depends = mcl_events, mcl_mobs +depends = mcl_events, mcl_mobs, mcl_potions, mcl_bells diff --git a/mods/ITEMS/mcl_potions/functions.lua b/mods/ITEMS/mcl_potions/functions.lua index d4478c33f..7213ddc4b 100644 --- a/mods/ITEMS/mcl_potions/functions.lua +++ b/mods/ITEMS/mcl_potions/functions.lua @@ -408,7 +408,7 @@ function mcl_potions._clear_cached_player_data(player) EF.night_vision[player] = nil EF.fire_proof[player] = nil EF.bad_omen[player] = nil - + meta = player:get_meta() meta:set_int("night_vision", 0) end @@ -422,9 +422,9 @@ function mcl_potions._reset_player_effects(player, set_hud) mcl_potions.make_invisible(player, false) playerphysics.remove_physics_factor(player, "jump", "mcl_potions:leaping") - + playerphysics.remove_physics_factor(player, "speed", "mcl_potions:swiftness") - + mcl_weather.skycolor.update_sky_color({player}) mcl_potions._clear_cached_player_data(player) @@ -517,6 +517,13 @@ function mcl_potions.player_has_effect(player, effect_name) return EF[effect_name][player] ~= nil end +function mcl_potions.player_get_effect(player, effect_name) + if not EF[effect_name] or not EF[effect_name][player] then + return false + end + return EF[effect_name][player] +end + minetest.register_on_leaveplayer( function(player) mcl_potions._save_player_effects(player) mcl_potions._clear_cached_player_data(player) -- clearout the buffer to prevent looking for a player not there @@ -994,21 +1001,17 @@ function mcl_potions._extinguish_nearby_fire(pos, radius) return exting end -function mcl_potions.bad_omen_func(player, null, duration) - +function mcl_potions.bad_omen_func(player, factor, duration) if not EF.bad_omen[player] then - - EF.bad_omen[player] = {dur = duration, timer = 0} - + EF.bad_omen[player] = {dur = duration, timer = 0, factor = factor} else - local victim = EF.bad_omen[player] victim.dur = math.max(duration, victim.dur - victim.timer) victim.timer = 0 + victim.factor = factor end if player:is_player() then potions_set_icons(player) end - end From 232f57c24744b32c431f94c276268afdfb6b1a38 Mon Sep 17 00:00:00 2001 From: cora Date: Tue, 25 Oct 2022 01:20:09 +0200 Subject: [PATCH 15/49] Add hero of the village achievement --- mods/ENVIRONMENT/mcl_raids/init.lua | 2 +- mods/ENVIRONMENT/mcl_raids/mod.conf | 2 +- .../mcl_raids_hero_of_the_village_icon.png | Bin 0 -> 4639 bytes mods/HUD/mcl_achievements/init.lua | 8 ++++++++ 4 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 mods/ENVIRONMENT/mcl_raids/textures/mcl_raids_hero_of_the_village_icon.png diff --git a/mods/ENVIRONMENT/mcl_raids/init.lua b/mods/ENVIRONMENT/mcl_raids/init.lua index 6307933cf..a497d1c34 100644 --- a/mods/ENVIRONMENT/mcl_raids/init.lua +++ b/mods/ENVIRONMENT/mcl_raids/init.lua @@ -161,6 +161,6 @@ mcl_events.register_event("raid",{ end, on_complete = function(self) --minetest.log("RAID complete") - --TODO: Award hero of the village + awards.unlock(self.player,"mcl:hero_of_the_village") end, }) diff --git a/mods/ENVIRONMENT/mcl_raids/mod.conf b/mods/ENVIRONMENT/mcl_raids/mod.conf index b81864cca..39f752ed7 100644 --- a/mods/ENVIRONMENT/mcl_raids/mod.conf +++ b/mods/ENVIRONMENT/mcl_raids/mod.conf @@ -1,3 +1,3 @@ name = mcl_raids author = PrairieWind -depends = mcl_events, mcl_mobs, mcl_potions, mcl_bells +depends = mcl_events, mcl_mobs, mcl_potions, mcl_bells, mcl_achievements diff --git a/mods/ENVIRONMENT/mcl_raids/textures/mcl_raids_hero_of_the_village_icon.png b/mods/ENVIRONMENT/mcl_raids/textures/mcl_raids_hero_of_the_village_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..0db5d9613407d59957d52558dbcb9317ad8f53bb GIT binary patch literal 4639 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 VC@B6o6UqPp002ovPDHLkV1nYc Date: Thu, 3 Nov 2022 14:10:30 +0100 Subject: [PATCH 16/49] Add debug chatcommand to start events --- mods/CORE/mcl_events/init.lua | 73 ++++------------------------- mods/ENVIRONMENT/mcl_raids/init.lua | 4 +- 2 files changed, 10 insertions(+), 67 deletions(-) diff --git a/mods/CORE/mcl_events/init.lua b/mods/CORE/mcl_events/init.lua index 3819488ff..aa8a14b0a 100644 --- a/mods/CORE/mcl_events/init.lua +++ b/mods/CORE/mcl_events/init.lua @@ -73,6 +73,7 @@ end local etime = 0 function check_events(dtime) + --process active events for idx,ae in pairs(active_events) do if ae.cond_complete and ae:cond_complete() then ae.finished = true @@ -95,6 +96,7 @@ function check_events(dtime) addbars(ae) --update_bars(ae) end + -- check if a new event should be started etime = etime - dtime if etime > 0 then return end etime = 10 @@ -120,71 +122,12 @@ end minetest.register_globalstep(check_events) -mcl_events.register_event("infestation",{ - max_stage = 5, - health = 1, - health_max = 1, - cond_start = function(self) - local r = {} - for _,p in pairs(minetest.get_connected_players()) do - if p:get_meta():get_string("infestation-omen") == "yes" then - p:get_meta():set_string("infestation-omen","") - table.insert(r,p:get_pos()) - 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 = function(self) - self.health_max = 0 - 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 l = m:get_luaentity() - if l then - self.health_max = self.health_max + l.health - table.insert(self.mobs,m) - end - end - end, - 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) - mcl_log("INFESTATION complete") - end, -}) - -minetest.register_chatcommand("infest",{ +minetest.register_chatcommand("event_start",{ privs = {debug = true}, - func = function(n,param) - local p = minetest.get_player_by_name(n) - p:get_meta():set_string("infestation-omen","yes") + func = function(pname,param) + local p = minetest.get_player_by_name(pname) + local evdef = mcl_events.registered_events[param] + if not evdef then return end + start_event({pos=p:get_pos(),player=pname,factor=1},evdef) end, }) diff --git a/mods/ENVIRONMENT/mcl_raids/init.lua b/mods/ENVIRONMENT/mcl_raids/init.lua index a497d1c34..23f3d34d1 100644 --- a/mods/ENVIRONMENT/mcl_raids/init.lua +++ b/mods/ENVIRONMENT/mcl_raids/init.lua @@ -129,8 +129,8 @@ mcl_events.register_event("raid",{ self.mobs = {} self.health_max = 1 self.health = 0 - local lv = mcl_potions.player_get_effect(minetest.get_player_by_name(self.player), "bad_omen").factor - if lv and lv > 1 then self.max_stage = 6 end + 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 end, cond_progress = function(self) local m = {} From ae90cbe3efbdb675e296cb5a9a9f4527b65142ff Mon Sep 17 00:00:00 2001 From: cora Date: Thu, 3 Nov 2022 19:00:17 +0100 Subject: [PATCH 17/49] Set raiders on path to village after spawn --- mods/ENVIRONMENT/mcl_raids/init.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mods/ENVIRONMENT/mcl_raids/init.lua b/mods/ENVIRONMENT/mcl_raids/init.lua index 23f3d34d1..1d57034c9 100644 --- a/mods/ENVIRONMENT/mcl_raids/init.lua +++ b/mods/ENVIRONMENT/mcl_raids/init.lua @@ -62,11 +62,13 @@ function mcl_raids.spawn_raid(event) end for m,c in pairs(w) do for i=1,c do - local mob = mcl_mobs.spawn(spawn_pos,m) + local p = vector.offset(spawn_pos,0,1,0) + local mob = mcl_mobs.spawn(p,m) local l = mob:get_luaentity() if l then event.health_max = event.health_max + l.health table.insert(event.mobs,mob) + mcl_mobs:gopath(l,pos) end end end From 160d7ca6fa7780298888df56653f6f7399d03139 Mon Sep 17 00:00:00 2001 From: PrairieWind Date: Fri, 4 Nov 2022 13:55:56 -0600 Subject: [PATCH 18/49] Add Voluntary Exile Advancement --- mods/HUD/mcl_achievements/init.lua | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/mods/HUD/mcl_achievements/init.lua b/mods/HUD/mcl_achievements/init.lua index 4e4dbb728..ced758948 100644 --- a/mods/HUD/mcl_achievements/init.lua +++ b/mods/HUD/mcl_achievements/init.lua @@ -531,9 +531,19 @@ awards.register_achievement("mcl:obsidian", { }) awards.register_achievement("mcl:hero_of_the_village", { - title = S("Hero of the village"), + title = S("Hero of the Village"), description = S("Successfully defend a village from a raid"), icon = "mcl_raids_hero_of_the_village_icon.png", type = "Advancement", - group = "Overworld", + group = "Adventure", + secret = true, +}) + +awards.register_achievement("mcl:voluntary_exile", { + title = S("Voluntary Exile"), + description = S("Kill a raid captain. Maybe consider staying away from the local villages for the time being..."), + icon = "mcl_potions_effect_bad_omen.png", + type = "Advancement", + group = "Adventure", + secret = true, }) From 48a85110527c0cff66817092f6f12552a254f2ad Mon Sep 17 00:00:00 2001 From: PrairieWind Date: Fri, 4 Nov 2022 14:28:51 -0600 Subject: [PATCH 19/49] Make bossbars enablable/disablable per event type. Update some capitalization. --- mods/CORE/mcl_events/init.lua | 12 +++++++----- mods/ENVIRONMENT/mcl_raids/init.lua | 2 ++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/mods/CORE/mcl_events/init.lua b/mods/CORE/mcl_events/init.lua index aa8a14b0a..7754ea2b9 100644 --- a/mods/CORE/mcl_events/init.lua +++ b/mods/CORE/mcl_events/init.lua @@ -34,22 +34,24 @@ function mcl_events.register_event(name,def) end local function addbars(self) + if not self.enable_bossbar then return end for _,player in pairs(minetest.get_connected_players()) do if vector.distance(self.pos,player:get_pos()) < 75 then - local bar = mcl_bossbars.add_bar(player, {color = "red", text = self.name .. " stage "..self.stage.." / "..self.max_stage, percentage = self.percent }, true,1) + local bar = mcl_bossbars.add_bar(player, {color = "red", text = self.readable_name .. ": Wave "..self.stage.." / "..self.max_stage, percentage = self.percent }, true,1) table.insert(self.bars,bar) end end end local function update_bars(self) + if not self.enable_bossbar then return end for _,b in pairs(self.bars) do - mcl_bossbars.update_bar(b,{text = self.name .. " stage "..self.stage,percentage=self.percent}) + mcl_bossbars.update_bar(b,{text = self.readable_name .. ": Wave "..self.stage,percentage=self.percent}) end end local function start_event(p,e) - mcl_log("event started: "..e.name.." at "..minetest.pos_to_string(vector.round(p.pos))) + mcl_log("[mcl_events] Event started: "..e.readable_name.." at "..minetest.pos_to_string(vector.round(p.pos))) local idx = #active_events + 1 active_events[idx] = table.copy(e) setmetatable(active_events[idx],e) @@ -63,7 +65,7 @@ local function start_event(p,e) end local function finish_event(self,idx) - mcl_log("Finished: "..self.name.." at "..minetest.pos_to_string(vector.round(self.pos))) + mcl_log("[mcl_events] Finished: "..self.readable_name.." at "..minetest.pos_to_string(vector.round(self.pos))) if self.on_complete then self:on_complete() end for _,b in pairs(self.bars) do mcl_bossbars.remove_bar(b) @@ -113,7 +115,7 @@ function check_events(dtime) if start then start_event(p,e) elseif DBG then - mcl_log("event "..e.name.." already active at "..minetest.pos_to_string(vector.round(p.pos))) + mcl_log("[mcl_events] Event "..e.readable_name.." already active at "..minetest.pos_to_string(vector.round(p.pos))) end end end diff --git a/mods/ENVIRONMENT/mcl_raids/init.lua b/mods/ENVIRONMENT/mcl_raids/init.lua index 1d57034c9..4b8d81fe9 100644 --- a/mods/ENVIRONMENT/mcl_raids/init.lua +++ b/mods/ENVIRONMENT/mcl_raids/init.lua @@ -111,10 +111,12 @@ function mcl_raids.find_village(pos) end mcl_events.register_event("raid",{ + readable_name = "Raid", max_stage = 5, health = 1, health_max = 1, exclusive_to_area = 128, + enable_bossbar = true, cond_start = function(self) local r = {} for _,p in pairs(minetest.get_connected_players()) do From b82912f30dfdfab85e48be2935b78b024d82fd7f Mon Sep 17 00:00:00 2001 From: cora Date: Sat, 5 Nov 2022 12:26:46 +0100 Subject: [PATCH 20/49] Add zombie sieges --- mods/ENVIRONMENT/mcl_zombie_sieges/init.lua | 75 +++++++++++++++++++++ mods/ENVIRONMENT/mcl_zombie_sieges/mod.conf | 3 + 2 files changed, 78 insertions(+) create mode 100644 mods/ENVIRONMENT/mcl_zombie_sieges/init.lua create mode 100644 mods/ENVIRONMENT/mcl_zombie_sieges/mod.conf diff --git a/mods/ENVIRONMENT/mcl_zombie_sieges/init.lua b/mods/ENVIRONMENT/mcl_zombie_sieges/init.lua new file mode 100644 index 000000000..18561f3ad --- /dev/null +++ b/mods/ENVIRONMENT/mcl_zombie_sieges/init.lua @@ -0,0 +1,75 @@ + +local function check_spawn_pos(pos) + return minetest.get_natural_light(pos) < 7 +end + +local function spawn_zombies(self) + local nn = minetest.find_nodes_in_area_under_air(vector.offset(self.pos,-32,-32,-32),vector.offset(self.pos,32,32,32),{"group:solid"}) + table.shuffle(nn) + for i=1,20 do + local p = vector.offset(nn[i%#nn],0,1,0) + if check_spawn_pos(p) then + local m = mcl_mobs.spawn(p,"mobs_mc:zombie") + local l = m:get_luaentity() + mcl_mobs:gopath(m:get_luaentity(),self.pos) + table.insert(self.mobs,m) + self.health_max = self.health_max + l.health + end + end +end + +mcl_events.register_event("zombie_siege",{ + readable_name = "Zombie Siege", + max_stage = 1, + health = 1, + health_max = 1, + exclusive_to_area = 128, + enable_bossbar = false, + cond_start = function(self) + local t = minetest.get_timeofday() + local r = {} + for _,p in pairs(minetest.get_connected_players()) do + local village = mcl_raids.find_village(p:get_pos()) + if t < 0.1 and village then + table.insert(r,{ player = p:get_player_name(), pos = village}) + 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 = spawn_zombies, + 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("SIEGE complete") + --awards.unlock(self.player,"mcl:hero_of_the_village") + end, +}) diff --git a/mods/ENVIRONMENT/mcl_zombie_sieges/mod.conf b/mods/ENVIRONMENT/mcl_zombie_sieges/mod.conf new file mode 100644 index 000000000..0263d367a --- /dev/null +++ b/mods/ENVIRONMENT/mcl_zombie_sieges/mod.conf @@ -0,0 +1,3 @@ +name = mcl_zombie_sieges +author = cora +depends = mcl_events, mcl_raids From 1d18482103af4219a5ec158d29c6bb8865e25e62 Mon Sep 17 00:00:00 2001 From: cora Date: Sun, 6 Nov 2022 11:49:39 +0100 Subject: [PATCH 21/49] Comment out excessive logging --- mods/ENVIRONMENT/mcl_raids/init.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mods/ENVIRONMENT/mcl_raids/init.lua b/mods/ENVIRONMENT/mcl_raids/init.lua index 4b8d81fe9..288df6e39 100644 --- a/mods/ENVIRONMENT/mcl_raids/init.lua +++ b/mods/ENVIRONMENT/mcl_raids/init.lua @@ -89,10 +89,10 @@ function mcl_raids.find_villager(pos) if object.name ~= "mobs_mc:villager" then return elseif object.name == "mobs_mc:villager" then - minetest.log("action", "[mcl_raids] Villager Found.") + --minetest.log("action", "[mcl_raids] Villager Found.") return true else - minetest.log("action", "[mcl_raids] No Villager Found.") + --minetest.log("action", "[mcl_raids] No Villager Found.") return false end end From 59d384020eebe218f8c72dc9dbebd2b87e8be006 Mon Sep 17 00:00:00 2001 From: cora Date: Sun, 6 Nov 2022 11:49:57 +0100 Subject: [PATCH 22/49] Finx spawn positions in 16-radius --- mods/ENVIRONMENT/mcl_zombie_sieges/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ENVIRONMENT/mcl_zombie_sieges/init.lua b/mods/ENVIRONMENT/mcl_zombie_sieges/init.lua index 18561f3ad..116732280 100644 --- a/mods/ENVIRONMENT/mcl_zombie_sieges/init.lua +++ b/mods/ENVIRONMENT/mcl_zombie_sieges/init.lua @@ -4,7 +4,7 @@ local function check_spawn_pos(pos) end local function spawn_zombies(self) - local nn = minetest.find_nodes_in_area_under_air(vector.offset(self.pos,-32,-32,-32),vector.offset(self.pos,32,32,32),{"group:solid"}) + local nn = minetest.find_nodes_in_area_under_air(vector.offset(self.pos,-16,-16,-16),vector.offset(self.pos,16,16,16),{"group:solid"}) table.shuffle(nn) for i=1,20 do local p = vector.offset(nn[i%#nn],0,1,0) From 097ee8b4d4c345691e6904d3dbf992d7184e9084 Mon Sep 17 00:00:00 2001 From: cora Date: Sun, 6 Nov 2022 11:50:13 +0100 Subject: [PATCH 23/49] Z sieges happen in 10% of the nights --- mods/ENVIRONMENT/mcl_zombie_sieges/init.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mods/ENVIRONMENT/mcl_zombie_sieges/init.lua b/mods/ENVIRONMENT/mcl_zombie_sieges/init.lua index 116732280..8a43b0e7e 100644 --- a/mods/ENVIRONMENT/mcl_zombie_sieges/init.lua +++ b/mods/ENVIRONMENT/mcl_zombie_sieges/init.lua @@ -26,11 +26,13 @@ mcl_events.register_event("zombie_siege",{ exclusive_to_area = 128, enable_bossbar = false, cond_start = function(self) + local pr = PseudoRandom(minetest.get_day_count()) + local rnd = pr:next(1,10) local t = minetest.get_timeofday() local r = {} for _,p in pairs(minetest.get_connected_players()) do local village = mcl_raids.find_village(p:get_pos()) - if t < 0.1 and village then + if t < 0.04 and village and rnd == 1 then table.insert(r,{ player = p:get_player_name(), pos = village}) end end From c7cc9ccb3e9e1af913491cc59c7c13d9f0cf7ff3 Mon Sep 17 00:00:00 2001 From: cora Date: Sun, 6 Nov 2022 12:30:16 +0100 Subject: [PATCH 24/49] Add raid captain spawn func with banner attach --- mods/ENVIRONMENT/mcl_raids/init.lua | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/mods/ENVIRONMENT/mcl_raids/init.lua b/mods/ENVIRONMENT/mcl_raids/init.lua index 288df6e39..b5bf4ba79 100644 --- a/mods/ENVIRONMENT/mcl_raids/init.lua +++ b/mods/ENVIRONMENT/mcl_raids/init.lua @@ -38,6 +38,27 @@ local extra_wave = { --["mobs_mc:ravager"] = 2, } +local oban_def = minetest.registered_entities["mcl_banners:standing_banner"] +oban_def.visual_size = { x=1, y=1 } +minetest.register_entity(":mcl_raids:ominous_banner",oban_def) + +function mcl_raids.spawn_raidcaptain(pos) + local c = minetest.add_entity(pos,"mobs_mc:pillager") + local b = minetest.add_entity(pos,"mcl_raids:ominous_banner") + --TODO: add actual banner pattern + --b:set_properties({textures = {mcl_banners.make_banner_texture(self._base_color, self._layers)}}) + b:get_luaentity() + b:set_attach(c,"",vector.new(-1.75,5.5,-0.5),vector.new(0,0,0),true) +end + +minetest.register_chatcommand("raidcap",{ + privs = {debug = true}, + func = function(pname,param) + mcl_raids.spawn_raidcaptain(minetest.get_player_by_name(pname):get_pos()) + end, +}) + + function mcl_raids.spawn_raid(event) local pos = event.pos local wave = event.stage From d1788b56436f29abd964adf0ecb97bfdb9d52239 Mon Sep 17 00:00:00 2001 From: cora Date: Mon, 7 Nov 2022 13:04:18 +0100 Subject: [PATCH 25/49] Add actual banner pattern, drop banner on death --- mods/ENVIRONMENT/mcl_raids/init.lua | 94 +++++++++++++++++++++++++---- 1 file changed, 81 insertions(+), 13 deletions(-) diff --git a/mods/ENVIRONMENT/mcl_raids/init.lua b/mods/ENVIRONMENT/mcl_raids/init.lua index b5bf4ba79..f607d707b 100644 --- a/mods/ENVIRONMENT/mcl_raids/init.lua +++ b/mods/ENVIRONMENT/mcl_raids/init.lua @@ -1,5 +1,6 @@ -- mcl_raids mcl_raids = {} +local S = minetest.get_translator(minetest.get_current_modname()) -- Define the amount of illagers to spawn each wave. local waves = { @@ -38,27 +39,72 @@ local extra_wave = { --["mobs_mc:ravager"] = 2, } -local oban_def = minetest.registered_entities["mcl_banners:standing_banner"] +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"]) oban_def.visual_size = { x=1, y=1 } +oban_def.on_rightclick = function(self) + minetest.log(dump(self._base_color)) + minetest.log(dump(self._layers)) +end minetest.register_entity(":mcl_raids:ominous_banner",oban_def) +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 + function mcl_raids.spawn_raidcaptain(pos) local c = minetest.add_entity(pos,"mobs_mc:pillager") + local l = c:get_luaentity() local b = minetest.add_entity(pos,"mcl_raids:ominous_banner") - --TODO: add actual banner pattern - --b:set_properties({textures = {mcl_banners.make_banner_texture(self._base_color, self._layers)}}) - b:get_luaentity() - b:set_attach(c,"",vector.new(-1.75,5.5,-0.5),vector.new(0,0,0),true) + b:set_properties({textures = {mcl_banners.make_banner_texture("unicolor_white", oban_layers)}}) + b:set_attach(c,"",vector.new(-1,5,-0.8),vector.new(0,0,0),true) + l._raidcaptain = true + l._banner = b + local old_ondie = l.on_die + l.on_die = function(self, pos, cmi_cause) + if l._banner and l._banner:get_pos() then + l._banner:remove() + l._banner = nil + mcl_raids.drop_obanner(pos) + end + if old_ondie then return old_ondie(self,pos,cmi_cause) end + end end -minetest.register_chatcommand("raidcap",{ - privs = {debug = true}, - func = function(pname,param) - mcl_raids.spawn_raidcaptain(minetest.get_player_by_name(pname):get_pos()) - end, -}) - - function mcl_raids.spawn_raid(event) local pos = event.pos local wave = event.stage @@ -189,3 +235,25 @@ mcl_events.register_event("raid",{ awards.unlock(self.player,"mcl:hero_of_the_village") end, }) + +minetest.register_chatcommand("raidcap",{ + privs = {debug = true}, + func = function(pname,param) + mcl_raids.spawn_raidcaptain(minetest.get_player_by_name(pname):get_pos()) + 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 +}) From 3600bc80668b05d2f92225312e3f0fea669478d4 Mon Sep 17 00:00:00 2001 From: cora Date: Tue, 8 Nov 2022 01:59:16 +0100 Subject: [PATCH 26/49] Spawn raidcaptain in raids --- mods/ENVIRONMENT/mcl_raids/init.lua | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/mods/ENVIRONMENT/mcl_raids/init.lua b/mods/ENVIRONMENT/mcl_raids/init.lua index f607d707b..32e372eeb 100644 --- a/mods/ENVIRONMENT/mcl_raids/init.lua +++ b/mods/ENVIRONMENT/mcl_raids/init.lua @@ -86,14 +86,14 @@ function mcl_raids.drop_obanner(pos) minetest.add_item(pos,it) end -function mcl_raids.spawn_raidcaptain(pos) - local c = minetest.add_entity(pos,"mobs_mc:pillager") +function mcl_raids.promote_to_raidcaptain(c) -- object + if not c or not c:get_pos() then return end + local pos = c:get_pos() local l = c:get_luaentity() - local b = minetest.add_entity(pos,"mcl_raids:ominous_banner") - b:set_properties({textures = {mcl_banners.make_banner_texture("unicolor_white", oban_layers)}}) - b:set_attach(c,"",vector.new(-1,5,-0.8),vector.new(0,0,0),true) + 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) l._raidcaptain = true - l._banner = b local old_ondie = l.on_die l.on_die = function(self, pos, cmi_cause) if l._banner and l._banner:get_pos() then @@ -139,6 +139,10 @@ function mcl_raids.spawn_raid(event) end end end + if event.stage == 1 then + table.shuffle(event.mobs) + mcl_raids.promote_to_raidcaptain(event.mobs[1]) + end minetest.log("action", "[mcl_raids] Raid Spawned. Illager Count: " .. #event.mobs .. ".") else minetest.log("action", "[mcl_raids] Raid Spawn Postion not chosen.") @@ -239,7 +243,8 @@ mcl_events.register_event("raid",{ minetest.register_chatcommand("raidcap",{ privs = {debug = true}, func = function(pname,param) - mcl_raids.spawn_raidcaptain(minetest.get_player_by_name(pname):get_pos()) + local c = minetest.add_entity(minetest.get_player_by_name(pname):get_pos(),"mobs_mc:pillager") + mcl_raids.promote_to_raidcaptain(c) end, }) From af0c718538b12889bec7c939fbbba8fef528bb20 Mon Sep 17 00:00:00 2001 From: cora Date: Tue, 8 Nov 2022 02:26:37 +0100 Subject: [PATCH 27/49] Add natural raidcaptain spawning --- mods/ENVIRONMENT/mcl_raids/init.lua | 21 +++++++++++++++++++++ mods/ENVIRONMENT/mcl_raids/mod.conf | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/mods/ENVIRONMENT/mcl_raids/init.lua b/mods/ENVIRONMENT/mcl_raids/init.lua index 32e372eeb..2b5e2874f 100644 --- a/mods/ENVIRONMENT/mcl_raids/init.lua +++ b/mods/ENVIRONMENT/mcl_raids/init.lua @@ -105,6 +105,27 @@ function mcl_raids.promote_to_raidcaptain(c) -- object end end +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 + 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") + function mcl_raids.spawn_raid(event) local pos = event.pos local wave = event.stage diff --git a/mods/ENVIRONMENT/mcl_raids/mod.conf b/mods/ENVIRONMENT/mcl_raids/mod.conf index 39f752ed7..b4616e56b 100644 --- a/mods/ENVIRONMENT/mcl_raids/mod.conf +++ b/mods/ENVIRONMENT/mcl_raids/mod.conf @@ -1,3 +1,3 @@ name = mcl_raids author = PrairieWind -depends = mcl_events, mcl_mobs, mcl_potions, mcl_bells, mcl_achievements +depends = mcl_events, mobs_mc, mcl_potions, mcl_bells, mcl_achievements From 62fe08de595256fa2468526525e274ef9146c5a5 Mon Sep 17 00:00:00 2001 From: cora Date: Tue, 8 Nov 2022 02:47:04 +0100 Subject: [PATCH 28/49] Make illagers pick up ominous banners and promote themselves to captain --- mods/ENVIRONMENT/mcl_raids/init.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/mods/ENVIRONMENT/mcl_raids/init.lua b/mods/ENVIRONMENT/mcl_raids/init.lua index 2b5e2874f..488445731 100644 --- a/mods/ENVIRONMENT/mcl_raids/init.lua +++ b/mods/ENVIRONMENT/mcl_raids/init.lua @@ -114,6 +114,18 @@ end function mcl_raids.register_possible_raidcaptain(mob) local old_on_spawn = minetest.registered_entities[mob].on_spawn + 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 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) From 6251c623dd23cbbb1139c2154fab013ccb5418fd Mon Sep 17 00:00:00 2001 From: cora Date: Tue, 8 Nov 2022 03:17:27 +0100 Subject: [PATCH 29/49] Give player bad omen effect when killing captain --- mods/ENVIRONMENT/mcl_raids/init.lua | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/mods/ENVIRONMENT/mcl_raids/init.lua b/mods/ENVIRONMENT/mcl_raids/init.lua index 488445731..e77c0717f 100644 --- a/mods/ENVIRONMENT/mcl_raids/init.lua +++ b/mods/ENVIRONMENT/mcl_raids/init.lua @@ -93,13 +93,24 @@ function mcl_raids.promote_to_raidcaptain(c) -- object 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) + local bl = l._banner:get_luaentity() + bl.parent = c + bl.on_step = function(self,dtime) + if not self.parent or not self.parent:get_pos() then return self.object:remove() end + end l._raidcaptain = true local old_ondie = l.on_die l.on_die = function(self, pos, cmi_cause) - if l._banner and l._banner:get_pos() then + if l._banner then l._banner:remove() l._banner = nil mcl_raids.drop_obanner(pos) + if cmi_cause.type == "punch" and cmi_cause.puncher:is_player() then + local lv = mcl_potions.player_get_effect(cmi_cause.puncher, "bad_omen").factor + if not lv then lv = 0 end + lv = math.max(5,lv + 1) + mcl_potions.bad_omen_func(cmi_cause.puncher,lv,6000) + end end if old_ondie then return old_ondie(self,pos,cmi_cause) end end From c3455de6045a273a69a6e3b5513e7aa4940ef923 Mon Sep 17 00:00:00 2001 From: cora Date: Tue, 8 Nov 2022 03:57:11 +0100 Subject: [PATCH 30/49] Clear bad omen when raid complete --- mods/ENVIRONMENT/mcl_raids/init.lua | 6 ++++-- mods/ITEMS/mcl_potions/functions.lua | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/mods/ENVIRONMENT/mcl_raids/init.lua b/mods/ENVIRONMENT/mcl_raids/init.lua index e77c0717f..ec6527b49 100644 --- a/mods/ENVIRONMENT/mcl_raids/init.lua +++ b/mods/ENVIRONMENT/mcl_raids/init.lua @@ -106,8 +106,9 @@ function mcl_raids.promote_to_raidcaptain(c) -- object l._banner = nil mcl_raids.drop_obanner(pos) if cmi_cause.type == "punch" and cmi_cause.puncher:is_player() then - local lv = mcl_potions.player_get_effect(cmi_cause.puncher, "bad_omen").factor - if not lv then lv = 0 end + local lv = mcl_potions.player_get_effect(cmi_cause.puncher, "bad_omen") + if not lv then lv = 0 + else lv = lv.factor end lv = math.max(5,lv + 1) mcl_potions.bad_omen_func(cmi_cause.puncher,lv,6000) end @@ -281,6 +282,7 @@ mcl_events.register_event("raid",{ on_complete = function(self) --minetest.log("RAID complete") awards.unlock(self.player,"mcl:hero_of_the_village") + mcl_potions.player_clear_effect(minetest.get_player_by_name(self.player),"bad_omen") end, }) diff --git a/mods/ITEMS/mcl_potions/functions.lua b/mods/ITEMS/mcl_potions/functions.lua index 7213ddc4b..de3f6df10 100644 --- a/mods/ITEMS/mcl_potions/functions.lua +++ b/mods/ITEMS/mcl_potions/functions.lua @@ -524,6 +524,11 @@ function mcl_potions.player_get_effect(player, effect_name) return EF[effect_name][player] end +function mcl_potions.player_clear_effect(player,effect) + EF[effect][player] = nil + potions_set_icons(player) +end + minetest.register_on_leaveplayer( function(player) mcl_potions._save_player_effects(player) mcl_potions._clear_cached_player_data(player) -- clearout the buffer to prevent looking for a player not there From 608da950e46d28cc76cf1faa7766868b80c58538 Mon Sep 17 00:00:00 2001 From: cora Date: Wed, 9 Nov 2022 00:56:42 +0100 Subject: [PATCH 31/49] Abort events when no player is near --- mods/CORE/mcl_events/init.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/mods/CORE/mcl_events/init.lua b/mods/CORE/mcl_events/init.lua index 7754ea2b9..a0b764163 100644 --- a/mods/CORE/mcl_events/init.lua +++ b/mods/CORE/mcl_events/init.lua @@ -120,6 +120,18 @@ function check_events(dtime) end end end + for idx,ae in pairs(active_events) do + local player_near = false + for _,pl in pairs(minetest.get_connected_players()) do + if ae.pos and vector.distance(pl:get_pos(),ae.pos) < 256 then player_near = true end + end + if ae.pos and not player_near then + if ae.fail and ae:fail() ~= true then + mcl_log("[mcl_events] Event "..e.readable_name.." at "..minetest.pos_to_string(vector.round(p.pos)).." aborted - no players near." ) + active_events[idx] = nil + end + end + end end minetest.register_globalstep(check_events) From 358250012f477810a2ff072b8e70467c89464935 Mon Sep 17 00:00:00 2001 From: cora Date: Wed, 9 Nov 2022 19:53:50 +0100 Subject: [PATCH 32/49] Remove banner when not attached --- mods/ENVIRONMENT/mcl_raids/init.lua | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/mods/ENVIRONMENT/mcl_raids/init.lua b/mods/ENVIRONMENT/mcl_raids/init.lua index ec6527b49..1a9005bf8 100644 --- a/mods/ENVIRONMENT/mcl_raids/init.lua +++ b/mods/ENVIRONMENT/mcl_raids/init.lua @@ -73,10 +73,12 @@ local oban_layers = { local oban_def = table.copy(minetest.registered_entities["mcl_banners:standing_banner"]) oban_def.visual_size = { x=1, y=1 } -oban_def.on_rightclick = function(self) - minetest.log(dump(self._base_color)) - minetest.log(dump(self._layers)) +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 end + minetest.register_entity(":mcl_raids:ominous_banner",oban_def) function mcl_raids.drop_obanner(pos) @@ -93,11 +95,6 @@ function mcl_raids.promote_to_raidcaptain(c) -- object 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) - local bl = l._banner:get_luaentity() - bl.parent = c - bl.on_step = function(self,dtime) - if not self.parent or not self.parent:get_pos() then return self.object:remove() end - end l._raidcaptain = true local old_ondie = l.on_die l.on_die = function(self, pos, cmi_cause) From a1e21b44c8948cce9b6f60d708126f4b1c9c49d5 Mon Sep 17 00:00:00 2001 From: PrairieWind Date: Wed, 9 Nov 2022 12:30:23 -0700 Subject: [PATCH 33/49] Add code to unlock Voluntary Exile advancement --- mods/ENVIRONMENT/mcl_raids/init.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/mods/ENVIRONMENT/mcl_raids/init.lua b/mods/ENVIRONMENT/mcl_raids/init.lua index 1a9005bf8..4a4120c9d 100644 --- a/mods/ENVIRONMENT/mcl_raids/init.lua +++ b/mods/ENVIRONMENT/mcl_raids/init.lua @@ -103,6 +103,7 @@ function mcl_raids.promote_to_raidcaptain(c) -- object l._banner = nil mcl_raids.drop_obanner(pos) if cmi_cause.type == "punch" and cmi_cause.puncher:is_player() then + awards.unlock(cmi_cause.puncher:get_player_name(), "mcl:voluntary_exile") local lv = mcl_potions.player_get_effect(cmi_cause.puncher, "bad_omen") if not lv then lv = 0 else lv = lv.factor end From 2147790b44bc2b2e912642dd71c4512faa497fe5 Mon Sep 17 00:00:00 2001 From: cora Date: Thu, 10 Nov 2022 00:14:35 +0100 Subject: [PATCH 34/49] Add setting to disable events --- mods/CORE/mcl_events/init.lua | 4 ++++ settingtypes.txt | 3 +++ 2 files changed, 7 insertions(+) diff --git a/mods/CORE/mcl_events/init.lua b/mods/CORE/mcl_events/init.lua index a0b764163..9221f33ec 100644 --- a/mods/CORE/mcl_events/init.lua +++ b/mods/CORE/mcl_events/init.lua @@ -1,5 +1,8 @@ mcl_events = {} mcl_events.registered_events = {} +local disabled_events = minetest.settings:get("mcl_disabled_events") +if disabled_events then disabled_events = disabled_events:split(",") +else disabled_events = {} end local DBG = minetest.settings:get_bool("mcl_logging_event_api",false) local active_events = {} @@ -27,6 +30,7 @@ local function mcl_log(m,l) end function mcl_events.register_event(name,def) + if table.indexof(disabled_events,name) ~= -1 then return end mcl_events.registered_events[name] = {} --setmetatable(mcl_events.registered_events[name],tpl_eventdef) mcl_events.registered_events[name] = def diff --git a/settingtypes.txt b/settingtypes.txt index 1b21316b7..78aa9d44b 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -42,6 +42,9 @@ mcl_tnt_griefing (TNT destroys blocks) bool true # Comma separated list of disabled structure names mcl_disabled_structures (Disabled structures) string +# Comma separated list of disabled event names +mcl_disabled_events (Disabled events) string + [Players] # If enabled, players respawn at the bed they last lay on instead of normal # spawn. From 22fa5096c94d2ab5634cc61884ef9f667415e893 Mon Sep 17 00:00:00 2001 From: cora Date: Wed, 16 Nov 2022 00:56:05 +0100 Subject: [PATCH 35/49] Add debug command status feedback --- mods/CORE/mcl_events/init.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mods/CORE/mcl_events/init.lua b/mods/CORE/mcl_events/init.lua index 9221f33ec..22a2bcdf6 100644 --- a/mods/CORE/mcl_events/init.lua +++ b/mods/CORE/mcl_events/init.lua @@ -142,10 +142,12 @@ minetest.register_globalstep(check_events) minetest.register_chatcommand("event_start",{ privs = {debug = true}, + description = "Debug command to start events", func = function(pname,param) local p = minetest.get_player_by_name(pname) local evdef = mcl_events.registered_events[param] - if not evdef then return end + if not evdef then return false,"Event "..param.." doesn't exist.'" end start_event({pos=p:get_pos(),player=pname,factor=1},evdef) + return true,"Started event "..param end, }) From 057a78ed307e9509a5208f44741d94413decb287 Mon Sep 17 00:00:00 2001 From: cora Date: Thu, 17 Nov 2022 05:39:55 +0100 Subject: [PATCH 36/49] Fix raid registering as completed when unloading the area --- mods/CORE/mcl_events/init.lua | 8 +++----- mods/ENVIRONMENT/mcl_raids/init.lua | 10 +++++++++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/mods/CORE/mcl_events/init.lua b/mods/CORE/mcl_events/init.lua index 22a2bcdf6..1e278d80f 100644 --- a/mods/CORE/mcl_events/init.lua +++ b/mods/CORE/mcl_events/init.lua @@ -127,13 +127,11 @@ function check_events(dtime) for idx,ae in pairs(active_events) do local player_near = false for _,pl in pairs(minetest.get_connected_players()) do - if ae.pos and vector.distance(pl:get_pos(),ae.pos) < 256 then player_near = true end + if ae.pos and vector.distance(pl:get_pos(),ae.pos) < 150 then player_near = true end end if ae.pos and not player_near then - if ae.fail and ae:fail() ~= true then - mcl_log("[mcl_events] Event "..e.readable_name.." at "..minetest.pos_to_string(vector.round(p.pos)).." aborted - no players near." ) - active_events[idx] = nil - end + mcl_log("[mcl_events] Event "..ae.readable_name.." at "..minetest.pos_to_string(vector.round(ae.pos)).." aborted - no players near." ) + active_events[idx] = nil end end end diff --git a/mods/ENVIRONMENT/mcl_raids/init.lua b/mods/ENVIRONMENT/mcl_raids/init.lua index 4a4120c9d..4918b6059 100644 --- a/mods/ENVIRONMENT/mcl_raids/init.lua +++ b/mods/ENVIRONMENT/mcl_raids/init.lua @@ -157,7 +157,7 @@ function mcl_raids.spawn_raid(event) 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))) - 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"}) + 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"}) mcl_bells.ring_once(pos) if sn and #sn > 0 then local spawn_pos = sn[math.random(#sn)] @@ -268,6 +268,14 @@ mcl_events.register_event("raid",{ end, on_stage_begin = mcl_raids.spawn_raid, cond_complete = function(self) + 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. local m = {} for k,o in pairs(self.mobs) do if o and o:get_pos() then From db4f9ec5a3558d4071488a08b6e95227a7d1a2f8 Mon Sep 17 00:00:00 2001 From: cora Date: Thu, 17 Nov 2022 05:47:48 +0100 Subject: [PATCH 37/49] Fix raid instawin when no spawnable blocks found --- mods/CORE/mcl_events/init.lua | 5 ++++- mods/ENVIRONMENT/mcl_raids/init.lua | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/mods/CORE/mcl_events/init.lua b/mods/CORE/mcl_events/init.lua index 1e278d80f..1d2fcfb35 100644 --- a/mods/CORE/mcl_events/init.lua +++ b/mods/CORE/mcl_events/init.lua @@ -91,7 +91,10 @@ function check_events(dtime) local p = ae:cond_progress() if p == true then ae.stage = ae.stage + 1 - ae:on_stage_begin() + if ae:on_stage_begin() == true then + mcl_log("[mcl_events] Event "..ae.readable_name.." at "..minetest.pos_to_string(vector.round(ae.pos)).." failed at stage_begin of stage "..ae.stage ) + active_events[idx] = nil + end elseif tonumber(p) then ae.stage = tonumber(p) or ae.stage + 1 ae:on_stage_begin() diff --git a/mods/ENVIRONMENT/mcl_raids/init.lua b/mods/ENVIRONMENT/mcl_raids/init.lua index 4918b6059..4986ef082 100644 --- a/mods/ENVIRONMENT/mcl_raids/init.lua +++ b/mods/ENVIRONMENT/mcl_raids/init.lua @@ -187,12 +187,14 @@ function mcl_raids.spawn_raid(event) mcl_raids.promote_to_raidcaptain(event.mobs[1]) end minetest.log("action", "[mcl_raids] Raid Spawned. Illager Count: " .. #event.mobs .. ".") + return #event.mobs == 0 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 + return true end function mcl_raids.find_villager(pos) From 94057aa7e560b3b15ee0acc4625d93409e0dbd52 Mon Sep 17 00:00:00 2001 From: cora Date: Thu, 17 Nov 2022 05:48:15 +0100 Subject: [PATCH 38/49] Code cleanup --- mods/CORE/mcl_events/init.lua | 10 ---------- mods/ENVIRONMENT/mcl_raids/init.lua | 1 - 2 files changed, 11 deletions(-) diff --git a/mods/CORE/mcl_events/init.lua b/mods/CORE/mcl_events/init.lua index 1d2fcfb35..9c908846f 100644 --- a/mods/CORE/mcl_events/init.lua +++ b/mods/CORE/mcl_events/init.lua @@ -31,8 +31,6 @@ end function mcl_events.register_event(name,def) if table.indexof(disabled_events,name) ~= -1 then return end - mcl_events.registered_events[name] = {} - --setmetatable(mcl_events.registered_events[name],tpl_eventdef) mcl_events.registered_events[name] = def mcl_events.registered_events[name].name = name end @@ -47,13 +45,6 @@ local function addbars(self) end end -local function update_bars(self) - if not self.enable_bossbar then return end - for _,b in pairs(self.bars) do - mcl_bossbars.update_bar(b,{text = self.readable_name .. ": Wave "..self.stage,percentage=self.percent}) - end -end - local function start_event(p,e) mcl_log("[mcl_events] Event started: "..e.readable_name.." at "..minetest.pos_to_string(vector.round(p.pos))) local idx = #active_events + 1 @@ -103,7 +94,6 @@ function check_events(dtime) ae:on_step() end addbars(ae) - --update_bars(ae) end -- check if a new event should be started etime = etime - dtime diff --git a/mods/ENVIRONMENT/mcl_raids/init.lua b/mods/ENVIRONMENT/mcl_raids/init.lua index 4986ef082..fc751a32c 100644 --- a/mods/ENVIRONMENT/mcl_raids/init.lua +++ b/mods/ENVIRONMENT/mcl_raids/init.lua @@ -288,7 +288,6 @@ mcl_events.register_event("raid",{ return self.stage >= self.max_stage and #m < 1 end, on_complete = function(self) - --minetest.log("RAID complete") awards.unlock(self.player,"mcl:hero_of_the_village") mcl_potions.player_clear_effect(minetest.get_player_by_name(self.player),"bad_omen") end, From e5515ed119f3cca83eee26860af05e5a1d0bc6ed Mon Sep 17 00:00:00 2001 From: cora Date: Thu, 17 Nov 2022 20:06:00 +0100 Subject: [PATCH 39/49] Add debug field: active event counter to verify it doesn't memleak --- mods/CORE/mcl_events/init.lua | 7 +++++++ mods/CORE/mcl_events/mod.conf | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/mods/CORE/mcl_events/init.lua b/mods/CORE/mcl_events/init.lua index 9c908846f..4b0dcd81e 100644 --- a/mods/CORE/mcl_events/init.lua +++ b/mods/CORE/mcl_events/init.lua @@ -131,6 +131,13 @@ end minetest.register_globalstep(check_events) +mcl_info.register_debug_field("Active Events",{ + level = 4, + func = function(pl,pos) + return tostring(#active_events) + end +}) + minetest.register_chatcommand("event_start",{ privs = {debug = true}, description = "Debug command to start events", diff --git a/mods/CORE/mcl_events/mod.conf b/mods/CORE/mcl_events/mod.conf index 44d11a1cc..29a45628a 100644 --- a/mods/CORE/mcl_events/mod.conf +++ b/mods/CORE/mcl_events/mod.conf @@ -1,3 +1,3 @@ name = mcl_events author = cora -depends = mcl_mobs,mcl_bossbars +depends = mcl_mobs,mcl_bossbars, mcl_info From 8564a12398c640113d684aa88371b87b84a2a5c8 Mon Sep 17 00:00:00 2001 From: cora Date: Fri, 18 Nov 2022 02:54:16 +0100 Subject: [PATCH 40/49] Nerf vex summoning so evoker doesnt spawn infinite vexes --- mods/ENTITIES/mobs_mc/villager_evoker.lua | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/mods/ENTITIES/mobs_mc/villager_evoker.lua b/mods/ENTITIES/mobs_mc/villager_evoker.lua index b85001985..242fa802a 100644 --- a/mods/ENTITIES/mobs_mc/villager_evoker.lua +++ b/mods/ENTITIES/mobs_mc/villager_evoker.lua @@ -11,6 +11,8 @@ local S = minetest.get_translator("mobs_mc") local pr = PseudoRandom(os.time()*666) +local spawned_vexes = {} --this is stored locally so the mobs engine doesn't try to store it in staticdata + mcl_mobs:register_mob("mobs_mc:evoker", { description = S("Evoker"), type = "monster", @@ -42,16 +44,24 @@ mcl_mobs:register_mob("mobs_mc:evoker", { attack_type = "dogfight", -- Summon vexes custom_attack = function(self, to_attack) - local r = pr:next(2,4) + if not spawned_vexes[self] then spawned_vexes[self] = {} end + if #spawned_vexes[self] >= 7 then return end + for k,v in pairs(spawned_vexes[self]) do + if not v or v.health <= 0 then table.remove(spawned_vexes[self],k) end + end + local r = pr:next(1,4) local basepos = self.object:get_pos() basepos.y = basepos.y + 1 for i=1, r do local spawnpos = vector.add(basepos, minetest.yaw_to_dir(pr:next(0,360))) local vex = minetest.add_entity(spawnpos, "mobs_mc:vex") local ent = vex:get_luaentity() + -- Mark vexes as summoned and start their life clock (they take damage it reaches 0) ent._summoned = true ent._lifetimer = pr:next(33, 108) + + table.insert(spawned_vexes[self],ent) end end, shoot_interval = 15, From 93e50343174cb17cd0c7b2677a8bd97b2a0fd8c4 Mon Sep 17 00:00:00 2001 From: cora Date: Fri, 18 Nov 2022 07:02:00 +0100 Subject: [PATCH 41/49] Add fireworks when raid complete --- mods/CORE/mcl_events/init.lua | 6 ++- mods/ENVIRONMENT/mcl_raids/init.lua | 58 +++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/mods/CORE/mcl_events/init.lua b/mods/CORE/mcl_events/init.lua index 4b0dcd81e..a4157f4ac 100644 --- a/mods/CORE/mcl_events/init.lua +++ b/mods/CORE/mcl_events/init.lua @@ -55,7 +55,9 @@ local function start_event(p,e) active_events[idx].percent = 100 active_events[idx].bars = {} active_events[idx].time_start = os.time() - active_events[idx]:on_start(p.pos) + if active_events[idx].on_start then + active_events[idx]:on_start(p.pos) + end addbars(active_events[idx]) end @@ -91,7 +93,7 @@ function check_events(dtime) ae:on_stage_begin() end elseif not ae.finished and ae.on_step then - ae:on_step() + ae:on_step(dtime) end addbars(ae) end diff --git a/mods/ENVIRONMENT/mcl_raids/init.lua b/mods/ENVIRONMENT/mcl_raids/init.lua index fc751a32c..b900418f6 100644 --- a/mods/ENVIRONMENT/mcl_raids/init.lua +++ b/mods/ENVIRONMENT/mcl_raids/init.lua @@ -226,6 +226,27 @@ function mcl_raids.find_village(pos) end end +local function get_point_on_circle(pos,r,n) + local rt = {} + for i=1, n do + table.insert(rt,vector.offset(pos,r * math.cos(((i-1)/n) * (2*math.pi)),0, r* math.sin(((i-1)/n) * (2*math.pi)) )) + end + table.shuffle(rt) + return rt[1] +end + +local function start_firework_rocket(pos) + local pp = get_point_on_circle(pos,math.random(32,64),32) + local o = minetest.add_entity(pp,"mcl_bows:rocket_entity") + o:set_acceleration(vector.new(math.random(0,2),math.random(30,50),math.random(0,2))) +end + +local function make_firework(pos) + for i=1,math.random(25) do + minetest.after(math.random(i),start_firework_rocket,pos) + end +end + mcl_events.register_event("raid",{ readable_name = "Raid", max_stage = 5, @@ -290,6 +311,7 @@ mcl_events.register_event("raid",{ on_complete = function(self) awards.unlock(self.player,"mcl:hero_of_the_village") mcl_potions.player_clear_effect(minetest.get_player_by_name(self.player),"bad_omen") + make_firework(self.pos) end, }) @@ -315,3 +337,39 @@ minetest.register_chatcommand("dump_banner_layers",{ end end }) + +local function is_new_years() + local d = os.date("*t") + return d.month == 1 and d.day == 1 and d.hour < 1 +end + +mcl_events.register_event("new_years",{ + stage = 0, + max_stage = 1, + readable_name = "New Years", + pos = vector.new(0,0,0), + exclusive_to_area = 256, + cond_start = function(event) + if not is_new_years() then return false end + local r = {} + for _,p in pairs(minetest.get_connected_players()) do + table.insert(r,{ player = p:get_player_name(), pos = p:get_pos()}) + end + return r + end, + on_start = function(self) + minetest.chat_send_player(self.player," Happy new year <3") + end, + on_step = function(self,dtime) + if not self.timer or self.timer < 0 then + self.timer = math.random(1,5) + for i=1,math.random(8) do + minetest.after(math.random(i),start_firework_rocket,minetest.get_player_by_name(self.player):get_pos()) + end + end + self.timer = self.timer - dtime + end, + cond_complete = function(event) + return not is_new_years() + end, --return success +}) From c6fc3885972f6ad55eb173b79c1e1c33c0ca8603 Mon Sep 17 00:00:00 2001 From: cora Date: Fri, 18 Nov 2022 07:26:44 +0100 Subject: [PATCH 42/49] Add _harmless option for rocket arrows so event fireworks dont grief things --- mods/ENVIRONMENT/mcl_raids/init.lua | 8 ++++++-- mods/ITEMS/mcl_bows/rocket.lua | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/mods/ENVIRONMENT/mcl_raids/init.lua b/mods/ENVIRONMENT/mcl_raids/init.lua index b900418f6..fead074ae 100644 --- a/mods/ENVIRONMENT/mcl_raids/init.lua +++ b/mods/ENVIRONMENT/mcl_raids/init.lua @@ -236,8 +236,12 @@ local function get_point_on_circle(pos,r,n) end local function start_firework_rocket(pos) - local pp = get_point_on_circle(pos,math.random(32,64),32) - local o = minetest.add_entity(pp,"mcl_bows:rocket_entity") + local p = get_point_on_circle(pos,math.random(32,64),32) + local n = minetest.get_node(p) + local l = minetest.get_natural_light(pos,0.5) + if n.name ~= "air" or l <= minetest.LIGHT_MAX then return end + local o = minetest.add_entity(p,"mcl_bows:rocket_entity") + o:get_luaentity()._harmless = true o:set_acceleration(vector.new(math.random(0,2),math.random(30,50),math.random(0,2))) end diff --git a/mods/ITEMS/mcl_bows/rocket.lua b/mods/ITEMS/mcl_bows/rocket.lua index 6180472c1..e71c0c122 100644 --- a/mods/ITEMS/mcl_bows/rocket.lua +++ b/mods/ITEMS/mcl_bows/rocket.lua @@ -19,6 +19,7 @@ local function dir_to_pitch(dir) end local function damage_explosion(self, damagemulitplier) + if self._harmless then return end local p = self.object:get_pos() if not p then return end mcl_explosions.explode(p, 3, {}) From 87d5cdc439a7af6a93388319121999a311627fdf Mon Sep 17 00:00:00 2001 From: cora Date: Fri, 18 Nov 2022 15:15:58 +0100 Subject: [PATCH 43/49] Make raid end firework last a bit longer --- mods/ENVIRONMENT/mcl_raids/init.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mods/ENVIRONMENT/mcl_raids/init.lua b/mods/ENVIRONMENT/mcl_raids/init.lua index fead074ae..087cbf666 100644 --- a/mods/ENVIRONMENT/mcl_raids/init.lua +++ b/mods/ENVIRONMENT/mcl_raids/init.lua @@ -245,10 +245,12 @@ local function start_firework_rocket(pos) o:set_acceleration(vector.new(math.random(0,2),math.random(30,50),math.random(0,2))) end -local function make_firework(pos) +local function make_firework(pos,stime) + if os.time() - stime > 60 then return end for i=1,math.random(25) do minetest.after(math.random(i),start_firework_rocket,pos) end + minetest.after(10,make_firework,pos,stime) end mcl_events.register_event("raid",{ @@ -315,7 +317,7 @@ mcl_events.register_event("raid",{ on_complete = function(self) awards.unlock(self.player,"mcl:hero_of_the_village") mcl_potions.player_clear_effect(minetest.get_player_by_name(self.player),"bad_omen") - make_firework(self.pos) + make_firework(self.pos,os.time()) end, }) From d0ea7c405911e429aa887cceb93cb43fb4c5d71d Mon Sep 17 00:00:00 2001 From: cora Date: Wed, 23 Nov 2022 23:09:10 +0100 Subject: [PATCH 44/49] Set events metatable correctly --- mods/CORE/mcl_events/init.lua | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/mods/CORE/mcl_events/init.lua b/mods/CORE/mcl_events/init.lua index a4157f4ac..f657250e2 100644 --- a/mods/CORE/mcl_events/init.lua +++ b/mods/CORE/mcl_events/init.lua @@ -6,13 +6,11 @@ else disabled_events = {} end local DBG = minetest.settings:get_bool("mcl_logging_event_api",false) local active_events = {} -local tpl_eventdef = { +local event_tpl = { stage = 0, max_stage = 1, percent = 100, bars = {}, - --pos = vector.zero(), - --time_start = 0, completed = false, cond_start = function(event) end, --return table of positions on_step = function(event) end, @@ -49,7 +47,7 @@ local function start_event(p,e) mcl_log("[mcl_events] Event started: "..e.readable_name.." at "..minetest.pos_to_string(vector.round(p.pos))) local idx = #active_events + 1 active_events[idx] = table.copy(e) - setmetatable(active_events[idx],e) + setmetatable(active_events[idx],{__index = event_tpl}) for k,v in pairs(p) do active_events[idx][k] = v end active_events[idx].stage = 0 active_events[idx].percent = 100 From dabc09adb24e2f0e92c711a330c4f190aaf76ca8 Mon Sep 17 00:00:00 2001 From: cora Date: Fri, 25 Nov 2022 00:25:45 +0100 Subject: [PATCH 45/49] Lower and unify distance check --- mods/CORE/mcl_events/init.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mods/CORE/mcl_events/init.lua b/mods/CORE/mcl_events/init.lua index f657250e2..5ec2577a9 100644 --- a/mods/CORE/mcl_events/init.lua +++ b/mods/CORE/mcl_events/init.lua @@ -36,7 +36,7 @@ end local function addbars(self) if not self.enable_bossbar then return end for _,player in pairs(minetest.get_connected_players()) do - if vector.distance(self.pos,player:get_pos()) < 75 then + if vector.distance(self.pos,player:get_pos()) < 64 then local bar = mcl_bossbars.add_bar(player, {color = "red", text = self.readable_name .. ": Wave "..self.stage.." / "..self.max_stage, percentage = self.percent }, true,1) table.insert(self.bars,bar) end @@ -120,7 +120,7 @@ function check_events(dtime) for idx,ae in pairs(active_events) do local player_near = false for _,pl in pairs(minetest.get_connected_players()) do - if ae.pos and vector.distance(pl:get_pos(),ae.pos) < 150 then player_near = true end + if ae.pos and vector.distance(pl:get_pos(),ae.pos) < 64 then player_near = true end end if ae.pos and not player_near then mcl_log("[mcl_events] Event "..ae.readable_name.." at "..minetest.pos_to_string(vector.round(ae.pos)).." aborted - no players near." ) From 624092ddd303a22798ac5268a60a380cf117a9bd Mon Sep 17 00:00:00 2001 From: cora Date: Fri, 25 Nov 2022 00:26:18 +0100 Subject: [PATCH 46/49] Search the area before giving up when no mobs in table left otherwise it will advance stages prematurely --- mods/ENVIRONMENT/mcl_raids/init.lua | 62 +++++++++++++++++------------ 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/mods/ENVIRONMENT/mcl_raids/init.lua b/mods/ENVIRONMENT/mcl_raids/init.lua index 087cbf666..a5b47f5dd 100644 --- a/mods/ENVIRONMENT/mcl_raids/init.lua +++ b/mods/ENVIRONMENT/mcl_raids/init.lua @@ -116,7 +116,7 @@ function mcl_raids.promote_to_raidcaptain(c) -- object end function mcl_raids.is_raidcaptain_near(pos) - for k,v in pairs(minetest.get_objects_inside_radius(pos,128)) do + for k,v in pairs(minetest.get_objects_inside_radius(pos,32)) do local l = v:get_luaentity() if l and l._raidcaptain then return true end end @@ -176,6 +176,7 @@ function mcl_raids.spawn_raid(event) local mob = mcl_mobs.spawn(p,m) local l = mob:get_luaentity() if l then + l.raidmob = true event.health_max = event.health_max + l.health table.insert(event.mobs,mob) mcl_mobs:gopath(l,pos) @@ -253,6 +254,36 @@ local function make_firework(pos,stime) minetest.after(10,make_firework,pos,stime) end +local function is_player_near(self) + for _,pl in pairs(minetest.get_connected_players()) do + if self.pos and vector.distance(pl:get_pos(),self.pos) < 64 then return true end + end +end + +local function check_mobs(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 + if #m == 0 then --if no valid mobs in table search if there are any (reloaded ones) in the area + for k,o in pairs(minetest.get_objects_inside_radius(self.pos,64)) do + local l = o:get_luaentity() + if l and l.raidmob then + local l = o:get_luaentity() + h = h + l.health + table.insert(m,o) + end + end + end + self.mobs = m + return h +end + mcl_events.register_event("raid",{ readable_name = "Raid", max_stage = 5, @@ -280,38 +311,19 @@ mcl_events.register_event("raid",{ if lv and lv.factor and lv.factor > 1 then self.max_stage = 6 end 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 + if not is_player_near(self) then return false end + self.health = check_mobs(self) self.percent = math.max(0,(self.health / self.health_max ) * 100) - if #m < 1 then + if #self.mobs < 1 then return true end end, on_stage_begin = mcl_raids.spawn_raid, cond_complete = function(self) - 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 + if not is_player_near(self) 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. - 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 + check_mobs(self) return self.stage >= self.max_stage and #m < 1 end, on_complete = function(self) From 3b368fdd5a14949fc2a4b408561d5e54a8d203c0 Mon Sep 17 00:00:00 2001 From: cora Date: Fri, 25 Nov 2022 04:36:10 +0100 Subject: [PATCH 47/49] Fix wrong var name for mob table --- mods/ENVIRONMENT/mcl_raids/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ENVIRONMENT/mcl_raids/init.lua b/mods/ENVIRONMENT/mcl_raids/init.lua index a5b47f5dd..053543c9d 100644 --- a/mods/ENVIRONMENT/mcl_raids/init.lua +++ b/mods/ENVIRONMENT/mcl_raids/init.lua @@ -324,7 +324,7 @@ mcl_events.register_event("raid",{ --without this check it would sort out the unloaded mob entities and --think the raid is defeated. check_mobs(self) - return self.stage >= self.max_stage and #m < 1 + return self.stage >= self.max_stage and #self.mobs < 1 end, on_complete = function(self) awards.unlock(self.player,"mcl:hero_of_the_village") From ac7038e7a556d1597ca282b98efd101bba1ee9f5 Mon Sep 17 00:00:00 2001 From: cora Date: Fri, 25 Nov 2022 16:11:12 +0100 Subject: [PATCH 48/49] Raids/raidcaptain: Nil check cmi_cause apparently is nil sometimes --- mods/ENVIRONMENT/mcl_raids/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ENVIRONMENT/mcl_raids/init.lua b/mods/ENVIRONMENT/mcl_raids/init.lua index 053543c9d..5a4575670 100644 --- a/mods/ENVIRONMENT/mcl_raids/init.lua +++ b/mods/ENVIRONMENT/mcl_raids/init.lua @@ -102,7 +102,7 @@ function mcl_raids.promote_to_raidcaptain(c) -- object l._banner:remove() l._banner = nil mcl_raids.drop_obanner(pos) - if cmi_cause.type == "punch" and cmi_cause.puncher:is_player() then + if cmi_cause and cmi_cause.type == "punch" and cmi_cause.puncher:is_player() then awards.unlock(cmi_cause.puncher:get_player_name(), "mcl:voluntary_exile") local lv = mcl_potions.player_get_effect(cmi_cause.puncher, "bad_omen") if not lv then lv = 0 From 69f5bad0bb95b81c0ebc83f1b6d7eddd4ad9bcce Mon Sep 17 00:00:00 2001 From: cora Date: Fri, 25 Nov 2022 22:11:19 +0100 Subject: [PATCH 49/49] Document mcl_events --- mods/CORE/mcl_events/API.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 mods/CORE/mcl_events/API.md diff --git a/mods/CORE/mcl_events/API.md b/mods/CORE/mcl_events/API.md new file mode 100644 index 000000000..c94328e50 --- /dev/null +++ b/mods/CORE/mcl_events/API.md @@ -0,0 +1,27 @@ +## mcl_events +### Registering Events + `mlc_events.register_event("name",def)` + +#### Event Definition + { + stage = 0, + max_stage = 1, + percent = 100, + bars = {}, + completed = false, + cond_start = function() end, + --return table of paramtables e.g. { { player = playername, pos = position, ... } }, custom parameters will be passed to the event object/table + on_step = function(event) end, + --this function is run every game step when the event is active + on_start = function(event) end, + -- this function is run when the event starts + on_stage_begin = function(event) end, + -- this function runs when a new stage of the event starts + cond_progress = function(event) end, --return false or next stage id + --this function checks if the event should progress to the next (or any other) stage + cond_complete = function(event) end, + --return true if event finished successfully +} + +### Debugging + * /event_start -- starts the given event at the current player coordinates