mirror of
git://repo.or.cz/minetest_mana.git
synced 2024-11-15 23:00:20 +01:00
Regen can now be a float and negative
This commit is contained in:
parent
6f1b549931
commit
336b6dac87
20
init.lua
20
init.lua
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user