From 4ad0939fe6dd6c65dc9a7ed0b54aa8bbbc40d5b5 Mon Sep 17 00:00:00 2001 From: LeMagnesium Date: Wed, 10 Jun 2015 16:48:26 +0200 Subject: [PATCH] Updated mana - See #87 --- mods/mana/API.md | 9 ++++-- mods/mana/README.txt | 5 ++-- mods/mana/init.lua | 43 +++++++++++++++++++---------- mods/mana/textures/mana_bgicon.png | Bin 0 -> 2950 bytes 4 files changed, 39 insertions(+), 18 deletions(-) create mode 100644 mods/mana/textures/mana_bgicon.png diff --git a/mods/mana/API.md b/mods/mana/API.md index c82eda1d..dce2daf6 100755 --- a/mods/mana/API.md +++ b/mods/mana/API.md @@ -1,4 +1,4 @@ -API documentation for Mana 1.0.1 +API documentation for Mana 1.1.0 ================================ ## Introduction @@ -41,7 +41,12 @@ the new maximum. ### `mana.setregen(playername, value)` Sets the mana regeneration per mana tick of the player to `value`. -Negative values are not permitted. +Floating-point numbers are also permitted, in which the generation +of 1 mana takes longer than 1 mana tick. I.e. `0.5`. means +that 1 mana is generated every 2 mana ticks. A negative value means the +player loses mana. + + The length of one “mana tick” is specified as the server-wide setting `mana_default_regen` in seconds. diff --git a/mods/mana/README.txt b/mods/mana/README.txt index 8f9ba0ce..8a54d407 100755 --- a/mods/mana/README.txt +++ b/mods/mana/README.txt @@ -1,6 +1,6 @@ Mana mod [mana] =============== -Version: 1.0.1 +Version: 1.1.0 Note: This mod uses semantic versioning, as defined by version 2.0.0 of the SemVer standard. See: @@ -38,7 +38,7 @@ Configuration This mod can be configured with minetest.conf! The following settings are accepted: * `mana_default_max`: Initial max. mana given to new players. Default: `200`. This value must be non-negative. -* `mana_default_regen`: Initial regenerated mana per “mana tick”. Default: `1`. This value must be non-negative. +* `mana_default_regen`: Initial regenerated mana per “mana tick”. Default: `1`. This value can be a floating value. I.e. if the value is `0.5`, 1 mana is generated every two mana ticks (note that the player's mana amount is still a whole number). This value can be negative, in which case the player will lose mana. * `mana_regen_timer`: The length of a “mana tick” in seconds. Each player will get his/her mana increased by the current regen value per mana tick. Default: `0.2`. This value must be positive, also try to avoid very small values as those could probably stress your machine a lot. @@ -47,5 +47,6 @@ This mod can be configured with minetest.conf! The following settings are accept License information =================== * textures/mana_icon.png: CC-BY by Buch . +* textures/mana_bgicon.png: CC-BY, originally by Buch , modified by Wuzzy. * textures/mana_bar.png: WTFPL by Wuzzy. * Everything else: WTFPL. diff --git a/mods/mana/init.lua b/mods/mana/init.lua index 3dfb5953..14632cd1 100755 --- a/mods/mana/init.lua +++ b/mods/mana/init.lua @@ -1,5 +1,5 @@ --[[ -Mana 1.0.1 +Mana 1.0.2 This mod adds mana to players, a special attribute License: WTFPL @@ -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 @@ -172,7 +167,6 @@ do if(string ~= nil) then local savetable = minetest.deserialize(string) mana.playerlist = savetable.playerlist - if mana.playerlist == nil then mana.playerlist = {} end minetest.log("action", "[mana] mana.mt successfully read.") end end @@ -205,10 +199,10 @@ end) minetest.register_on_leaveplayer(function(player) local playername = player:get_player_name() - if minetest.get_modpath("hudbars") == nil then - player:hud_remove(mana.playerlist[playername].hudid) + if not minetest.get_modpath("hudbars") ~= nil then + mana.hud_remove(playername) end - --mana.playerlist[playername] = nil --uncomment to reset mana at deco/reco + mana.save_to_file() end) minetest.register_on_shutdown(function() @@ -224,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 @@ -249,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 @@ -262,7 +269,7 @@ end) ]===] if minetest.get_modpath("hudbars") ~= nil then - hb.register_hudbar("mana", 0xFFFFFF, "Mana", { bar = "mana_bar.png", icon = "mana_icon.png" }, 0, mana.settings.default_max, false) + hb.register_hudbar("mana", 0xFFFFFF, "Mana", { bar = "mana_bar.png", icon = "mana_icon.png", bgicon = "mana_bgicon.png" }, 0, mana.settings.default_max, false) function mana.hud_update(playername) local player = minetest.get_player_by_name(playername) @@ -271,6 +278,9 @@ if minetest.get_modpath("hudbars") ~= nil then end end + function mana.hud_remove(playername) + end + else function mana.manastring(playername) return string.format("Mana: %d/%d", mana.get(playername), mana.getmax(playername)) @@ -278,7 +288,7 @@ else function mana.hud_add(playername) local player = minetest.get_player_by_name(playername) - player:hud_add({ + id = player:hud_add({ hud_elem_type = "statbar", position = {x=0.5,y=1}, size = {x=24, y=24}, @@ -305,7 +315,12 @@ else function mana.hud_update(playername) local player = minetest.get_player_by_name(playername) - player:hud_change(mana.playerlist[playername].hudid, "number", mana.get(playername)/10) + player:hud_change(mana.playerlist[playername].hudid, "text", mana.manastring(playername)) + end + + function mana.hud_remove(playername) + local player = minetest.get_player_by_name(playername) + player:hud_remove(mana.playerlist[playername].hudid) end end diff --git a/mods/mana/textures/mana_bgicon.png b/mods/mana/textures/mana_bgicon.png new file mode 100644 index 0000000000000000000000000000000000000000..ea35a9cab89cb74351bb30082d26ccc9d78f5d4d GIT binary patch literal 2950 zcmV;13wiX3P)EX>4Tx07!|QmUmQC*A|D*y?1({%`g-xL+`x}AiX!K z(nMjH8DJ;_4l^{dA)*2iMMMM@L4qO%jD{kyB8r88V8I@cAfUux6j4!mGqP56<>kGX zm){>}eQ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