1
0
Fork 0

Fix raid registering as completed when unloading the area

This commit is contained in:
cora 2022-11-17 05:39:55 +01:00
parent 22fa5096c9
commit 057a78ed30
2 changed files with 12 additions and 6 deletions

View File

@ -127,16 +127,14 @@ function check_events(dtime)
for idx,ae in pairs(active_events) do for idx,ae in pairs(active_events) do
local player_near = false local player_near = false
for _,pl in pairs(minetest.get_connected_players()) do 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 end
if ae.pos and not player_near then if ae.pos and not player_near then
if ae.fail and ae:fail() ~= true then mcl_log("[mcl_events] Event "..ae.readable_name.." at "..minetest.pos_to_string(vector.round(ae.pos)).." aborted - no players near." )
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 active_events[idx] = nil
end end
end end
end end
end
minetest.register_globalstep(check_events) minetest.register_globalstep(check_events)

View File

@ -157,7 +157,7 @@ function mcl_raids.spawn_raid(event)
local n = 12 local n = 12
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_core:ice"})
mcl_bells.ring_once(pos) 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)]
@ -268,6 +268,14 @@ mcl_events.register_event("raid",{
end, end,
on_stage_begin = mcl_raids.spawn_raid, on_stage_begin = mcl_raids.spawn_raid,
cond_complete = function(self) 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 = {} local m = {}
for k,o in pairs(self.mobs) do for k,o in pairs(self.mobs) do
if o and o:get_pos() then if o and o:get_pos() then