1
0
Fork 0

Make bossbars enablable/disablable per event type. Update some capitalization.

This commit is contained in:
PrairieWind 2022-11-04 14:28:51 -06:00 committed by cora
parent 160d7ca6fa
commit 48a8511052
2 changed files with 9 additions and 5 deletions

View File

@ -34,22 +34,24 @@ function mcl_events.register_event(name,def)
end end
local function addbars(self) local function addbars(self)
if not self.enable_bossbar then return end
for _,player in pairs(minetest.get_connected_players()) do 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()) < 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) table.insert(self.bars,bar)
end end
end end
end end
local function update_bars(self) local function update_bars(self)
if not self.enable_bossbar then return end
for _,b in pairs(self.bars) do 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
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.pos))) mcl_log("[mcl_events] Event started: "..e.readable_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)
@ -63,7 +65,7 @@ local function start_event(p,e)
end end
local function finish_event(self,idx) 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 if self.on_complete then self:on_complete() end
for _,b in pairs(self.bars) do for _,b in pairs(self.bars) do
mcl_bossbars.remove_bar(b) mcl_bossbars.remove_bar(b)
@ -113,7 +115,7 @@ function check_events(dtime)
if start then if start then
start_event(p,e) start_event(p,e)
elseif DBG then 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 end
end end

View File

@ -111,10 +111,12 @@ function mcl_raids.find_village(pos)
end end
mcl_events.register_event("raid",{ mcl_events.register_event("raid",{
readable_name = "Raid",
max_stage = 5, max_stage = 5,
health = 1, health = 1,
health_max = 1, health_max = 1,
exclusive_to_area = 128, exclusive_to_area = 128,
enable_bossbar = true,
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