Optimize mana regeneration for slow servers

Slow servers are servers which call globalstep in a lower frequency than specified by the mana tick.
This commit is contained in:
Wuzzy 2015-02-22 09:07:59 +01:00
parent 8b02324870
commit 1a4adfb71b

View File

@ -240,16 +240,17 @@ mana.regen_timer = 0
minetest.register_globalstep(function(dtime)
mana.regen_timer = mana.regen_timer + dtime
if mana.regen_timer >= mana.settings.regen_timer then
local factor = math.floor(mana.regen_timer / mana.settings.regen_timer)
local players = minetest.get_connected_players()
for i=1, #players do
local name = players[i]:get_player_name()
if mana.playerlist[name] ~= nil then
if players[i]:get_hp() > 0 then
mana.add_up_to(name, mana.playerlist[name].regen)
mana.add_up_to(name, mana.playerlist[name].regen * factor)
end
end
end
mana.regen_timer = 0
mana.regen_timer = mana.regen_timer % mana.settings.regen_timer
end
end)