1
0
Fork 0

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.
This commit is contained in:
cora 2022-10-25 00:30:14 +02:00
parent 2159edba05
commit dc017864fd
4 changed files with 42 additions and 30 deletions

View File

@ -49,16 +49,16 @@ local function update_bars(self)
end end
local function start_event(p,e) 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 local idx = #active_events + 1
active_events[idx] = table.copy(e) active_events[idx] = table.copy(e)
setmetatable(active_events[idx],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].stage = 0
active_events[idx].percent = 100 active_events[idx].percent = 100
active_events[idx].bars = {} active_events[idx].bars = {}
active_events[idx].pos = vector.copy(p)
active_events[idx].time_start = os.time() active_events[idx].time_start = os.time()
active_events[idx]:on_start(p) active_events[idx]:on_start(p.pos)
addbars(active_events[idx]) addbars(active_events[idx])
end end
@ -102,7 +102,17 @@ function check_events(dtime)
local pp = e.cond_start() local pp = e.cond_start()
if pp then if pp then
for _,p in pairs(pp) do 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 end
end end

View File

@ -48,12 +48,19 @@ function mcl_raids.spawn_raid(event)
local i = math.random(1, n) local i = math.random(1, n)
local raid_pos = vector.offset(pos,r * math.cos(((i-1)/n) * (2*math.pi)),0, r * math.sin(((i-1)/n) * (2*math.pi))) local raid_pos = vector.offset(pos,r * math.cos(((i-1)/n) * (2*math.pi)),0, r * math.sin(((i-1)/n) * (2*math.pi)))
local sn = minetest.find_nodes_in_area_under_air(vector.offset(raid_pos,-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_bells.ring_once(pos)
if sn and #sn > 0 then if sn and #sn > 0 then
local spawn_pos = sn[math.random(#sn)] local spawn_pos = sn[math.random(#sn)]
if spawn_pos then if spawn_pos then
minetest.log("action", "[mcl_raids] Raid Spawn Position chosen at " .. minetest.pos_to_string(spawn_pos) .. ".") minetest.log("action", "[mcl_raids] Raid Spawn Position chosen at " .. minetest.pos_to_string(spawn_pos) .. ".")
event.health_max = 0 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 for i=1,c do
local mob = mcl_mobs.spawn(spawn_pos,m) local mob = mcl_mobs.spawn(spawn_pos,m)
local l = mob:get_luaentity() local l = mob:get_luaentity()
@ -101,29 +108,18 @@ function mcl_raids.find_village(pos)
end end
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",{ mcl_events.register_event("raid",{
max_stage = 5, max_stage = 5,
health = 1, health = 1,
health_max = 1, health_max = 1,
exclusive_to_area = 128,
cond_start = function(self) cond_start = function(self)
local r = {} local r = {}
for _,p in pairs(minetest.get_connected_players()) do for _,p in pairs(minetest.get_connected_players()) do
local m=p:get_meta() if mcl_potions.player_has_effect(p,"bad_omen") then
if m:get_string("_has_bad_omen") == "yes" then
local raid_pos = mcl_raids.find_village(p:get_pos()) local raid_pos = mcl_raids.find_village(p:get_pos())
if raid_pos then if raid_pos then
m:set_string("_has_bad_omen","") table.insert(r,{ player = p:get_player_name(), pos = raid_pos })
table.insert(r,raid_pos)
end end
end end
end end
@ -133,6 +129,8 @@ mcl_events.register_event("raid",{
self.mobs = {} self.mobs = {}
self.health_max = 1 self.health_max = 1
self.health = 0 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, end,
cond_progress = function(self) cond_progress = function(self)
local m = {} local m = {}
@ -163,5 +161,6 @@ mcl_events.register_event("raid",{
end, end,
on_complete = function(self) on_complete = function(self)
--minetest.log("RAID complete") --minetest.log("RAID complete")
--TODO: Award hero of the village
end, end,
}) })

View File

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

View File

@ -517,6 +517,13 @@ function mcl_potions.player_has_effect(player, effect_name)
return EF[effect_name][player] ~= nil return EF[effect_name][player] ~= nil
end 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) minetest.register_on_leaveplayer( function(player)
mcl_potions._save_player_effects(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 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 return exting
end 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 if not EF.bad_omen[player] then
EF.bad_omen[player] = {dur = duration, timer = 0, factor = factor}
EF.bad_omen[player] = {dur = duration, timer = 0}
else else
local victim = EF.bad_omen[player] local victim = EF.bad_omen[player]
victim.dur = math.max(duration, victim.dur - victim.timer) victim.dur = math.max(duration, victim.dur - victim.timer)
victim.timer = 0 victim.timer = 0
victim.factor = factor
end end
if player:is_player() then if player:is_player() then
potions_set_icons(player) potions_set_icons(player)
end end
end end