Regen can now be a float and negative

This commit is contained in:
Wuzzy 2015-05-25 22:43:41 +02:00
parent 6f1b549931
commit 336b6dac87
1 changed files with 14 additions and 6 deletions

View File

@ -70,11 +70,6 @@ function mana.setmax(playername, value)
end
function mana.setregen(playername, value)
if value < 0 then
value = 0
minetest.log("info", "[mana] Warning: mana.setregen was called with negative value!")
end
value = mana.round(value)
mana.playerlist[playername].regen = value
end
@ -223,6 +218,7 @@ minetest.register_on_joinplayer(function(player)
mana.playerlist[playername].mana = 0
mana.playerlist[playername].maxmana = mana.settings.default_max
mana.playerlist[playername].regen = mana.settings.default_regen
mana.playerlist[playername].remainder = 0
end
if minetest.get_modpath("hudbars") ~= nil then
@ -248,7 +244,19 @@ minetest.register_globalstep(function(dtime)
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 * factor)
local plus = mana.playerlist[name].regen * factor
-- Compability check for version <= 1.0.2 which did not have the remainder field
if mana.playerlist[name].remainder ~= nil then
plus = plus + mana.playerlist[name].remainder
end
local plus_now = math.floor(plus)
local floor = plus - plus_now
if plus_now > 0 then
mana.add_up_to(name, plus_now)
else
mana.subtract_up_to(name, math.abs(plus_now))
end
mana.playerlist[name].remainder = floor
end
end
end