1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2024-11-11 04:50:17 +01:00

Updated mana

- See #87
This commit is contained in:
LeMagnesium 2015-06-10 16:48:26 +02:00
parent 6ad7ddbeec
commit 4ad0939fe6
4 changed files with 39 additions and 18 deletions

View File

@ -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.

View File

@ -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: <http://semver.org/>
@ -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 <http://opengameart.org/users/Buch>.
* textures/mana_bgicon.png: CC-BY, originally by Buch <http://opengameart.org/users/Buch>, modified by Wuzzy.
* textures/mana_bar.png: WTFPL by Wuzzy.
* Everything else: WTFPL.

View File

@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB