From dc017864fd8c8b6944a0b8f22b9406eb2231d096 Mon Sep 17 00:00:00 2001 From: cora Date: Tue, 25 Oct 2022 00:30:14 +0200 Subject: [PATCH] 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