1
0
Fork 0

Raids performance optimisation. Check for village less and over less distance.

This commit is contained in:
ancientmarinerdev 2022-12-09 22:59:58 +00:00
parent e408dd45e5
commit f7f0a2be8b
3 changed files with 22 additions and 7 deletions

View File

@ -102,6 +102,7 @@ function check_events(dtime)
for _,e in pairs(mcl_events.registered_events) do for _,e in pairs(mcl_events.registered_events) do
local pp = e.cond_start() local pp = e.cond_start()
if pp then if pp then
--minetest.log("It's gonna start the raid maybe")
for _,p in pairs(pp) do for _,p in pairs(pp) do
local start = true local start = true
if e.exclusive_to_area then if e.exclusive_to_area then
@ -110,11 +111,14 @@ function check_events(dtime)
end end
end end
if start then if start then
--minetest.log("It's gonna start the raid definitely")
start_event(p,e) start_event(p,e)
elseif DBG then elseif DBG then
mcl_log("[mcl_events] Event "..e.readable_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
else
--minetest.log("Do not start this raid")
end end
end end
for idx,ae in pairs(active_events) do for idx,ae in pairs(active_events) do

View File

@ -217,7 +217,7 @@ function mcl_raids.find_villager(pos)
end end
function mcl_raids.find_bed(pos) function mcl_raids.find_bed(pos)
return minetest.find_node_near(pos,128,{"mcl_beds:bed_red_bottom"}) return minetest.find_node_near(pos,32,{"mcl_beds:bed_red_bottom"})
end end
function mcl_raids.find_village(pos) function mcl_raids.find_village(pos)
@ -292,11 +292,13 @@ mcl_events.register_event("raid",{
exclusive_to_area = 128, exclusive_to_area = 128,
enable_bossbar = true, enable_bossbar = true,
cond_start = function(self) cond_start = function(self)
--minetest.log("Cond start raid")
local r = {} local r = {}
for _,p in pairs(minetest.get_connected_players()) do for _,p in pairs(minetest.get_connected_players()) do
if mcl_potions.player_has_effect(p,"bad_omen") then if mcl_potions.player_has_effect(p,"bad_omen") 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
--minetest.log("We have a raid position. Start raid")
table.insert(r,{ player = p:get_player_name(), pos = raid_pos }) table.insert(r,{ player = p:get_player_name(), pos = raid_pos })
end end
end end

View File

@ -26,15 +26,24 @@ mcl_events.register_event("zombie_siege",{
exclusive_to_area = 128, exclusive_to_area = 128,
enable_bossbar = false, enable_bossbar = false,
cond_start = function(self) cond_start = function(self)
--minetest.log("Cond start zs")
local r = {}
local t = minetest.get_timeofday()
local pr = PseudoRandom(minetest.get_day_count()) local pr = PseudoRandom(minetest.get_day_count())
local rnd = pr:next(1,10) local rnd = pr:next(1,10)
local t = minetest.get_timeofday()
local r = {} if t < 0.04 and rnd == 1 then
for _,p in pairs(minetest.get_connected_players()) do --minetest.log("Well, it's siege time")
local village = mcl_raids.find_village(p:get_pos()) for _,p in pairs(minetest.get_connected_players()) do
if t < 0.04 and village and rnd == 1 then local village = mcl_raids.find_village(p:get_pos())
table.insert(r,{ player = p:get_player_name(), pos = village}) if village then
--minetest.log("Found village")
table.insert(r,{ player = p:get_player_name(), pos = village})
end
end end
else
--minetest.log("Not night for a siege, or not success")
end end
if #r > 0 then return r end if #r > 0 then return r end
end, end,