6 Commits

Author SHA1 Message Date
838d1df687 Version 1.2.0 2016-11-12 20:33:16 +01:00
374d9742f8 Update outdated inttlib boilerplate 2016-11-09 01:58:50 +01:00
93477205a4 Fix CC-BY 3.0 link 2016-10-29 15:29:09 +02:00
3b8097e44a Use Markdown format for README file 2016-10-29 15:27:00 +02:00
fc0efd94fb Remove redundant version number from init.lua 2016-10-29 15:23:22 +02:00
7b0ef7204b Add intllib support 2016-08-05 17:43:55 +02:00
13 changed files with 89 additions and 97 deletions

2
API.md Executable file → Normal file
View File

@ -1,4 +1,4 @@
API documentation for Mana 1.1.0
API documentation for Mana 1.2.0
================================
## Introduction

32
README.txt → README.md Executable file → Normal file
View File

@ -1,18 +1,16 @@
Mana mod [mana]
===============
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/>
# Mana [mana]
Description
===========
* Version: 1.2.0
* Note: This mod uses semantic versioning, as defined by version 2.0.0 of the SemVer standard. See: <http://semver.org/>
## Description
This mod adds basic support for mana to Minetest.
Each player will have an additional attribute: Mana. To be precise:
- Current mana reserves: How much mana the player currently has
- Maximum possible mana: How much mana the player can have at maximum
- Mana regeneration amont: How much mana will be generated each “mana tick” (default 0.2 seconds)
* Current mana reserves: How much mana the player currently has
* Maximum possible mana: How much mana the player can have at maximum
* Mana regeneration amont: How much mana will be generated each “mana tick” (default 0.2 seconds)
By default, each player spawns with 0/200 mana, and regenerates 1 mana per fifth of a second. All
these values can be configured with the server settings (`minetest.conf`) and it is highly advised to do
@ -25,15 +23,14 @@ The mod provides a simple API to set, get, add and subtract the mana (and maximu
for setting the regeneration amount. Note that this mod itself does *not* change the gameplay in a meaningful
way. You should install other mods which use the Mana mod as a dependency.
The API documentation is in the file API.md.
The API documentation is in the file `API.md`.
If the mod “HUD bars” [hudbars] is installed, a blue bar will be added to the HUD showing the player's mana reserves.
If the mod “HUD bars” [`hudbars`] is installed, a blue bar will be added to the HUD showing the player's mana reserves.
It currently only works with version 0.3.0 of this mod.
Otherwise, the mana is just shown as text.
Configuration
=============
## Configuration
This mod can be configured with minetest.conf! The following settings are accepted:
@ -43,10 +40,9 @@ This mod can be configured with minetest.conf! The following settings are accept
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.
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.
* `textures/mana_icon.png`: [CC BY 3.0](https://creativecommons.org/licenses/by/3.0/) by [Buch](http://opengameart.org/users/Buch).
* `textures/mana_bgicon.png`: CC BY 3.0, originally by Buch, modified by Wuzzy.
* `textures/mana_bar.png`: [WTFPL](http://www.wtfpl.net/txt/copying/) by Wuzzy.
* Everything else: WTFPL.

1
depends.txt Executable file → Normal file
View File

@ -1 +1,2 @@
hudbars?
intllib?

0
description.txt Executable file → Normal file
View File

147
init.lua Executable file → Normal file
View File

@ -1,5 +1,5 @@
--[[
Mana 1.0.2
Mana
This mod adds mana to players, a special attribute
License: WTFPL
@ -9,13 +9,20 @@ License: WTFPL
Initialization
]===]
local S
if (minetest.get_modpath("intllib")) then
S = intllib.Getter()
else
S = function(s,a,...)a={a,...}return s:gsub("@(%d+)",function(n)return a[tonumber(n)]end)end
end
mana = {}
mana.playerlist = {}
mana.settings = {}
mana.settings.default_max = 200
mana.settings.default_regen = 10
mana.settings.regen_timer = 10
mana.settings.default_regen = 1
mana.settings.regen_timer = 0.2
do
local default_max = tonumber(minetest.setting_get("mana_default_max"))
@ -35,13 +42,11 @@ do
end
minetest.mkdir(minetest.get_worldpath() .. "/mana/")
--[===[
API functions
]===]
function mana.set(playername, value)
function mana.set(playername, value)
if value < 0 then
minetest.log("info", "[mana] Warning: mana.set was called with negative value!")
value = 0
@ -110,7 +115,7 @@ function mana.add(playername, value)
local t = mana.playerlist[playername]
value = mana.round(value)
if(t ~= nil and ((t.mana + value) <= t.maxmana) and value >= 0) then
t.mana = t.mana + value
t.mana = t.mana + value
mana.hud_update(playername)
return true
else
@ -122,7 +127,7 @@ function mana.subtract(playername, value)
local t = mana.playerlist[playername]
value = mana.round(value)
if(t ~= nil and t.mana >= value and value >= 0) then
t.mana = t.mana -value
t.mana = t.mana -value
mana.hud_update(playername)
return true
else
@ -159,39 +164,35 @@ end
-- Load the playerlist from a previous session, if available.
function mana.load_file(playername)
local filepath = minetest.get_worldpath().."/mana/" .. playername
do
local filepath = minetest.get_worldpath().."/mana.mt"
local file = io.open(filepath, "r")
if file then
minetest.log("action", "[mana] File opened for player " .. playername .. ".")
minetest.log("action", "[mana] mana.mt opened.")
local string = file:read()
io.close(file)
if(string ~= nil) then
local savetable = minetest.deserialize(string)
if savetable and type(savetable) == "table" then
minetest.log("action", "[mana] Data successfully read.")
return savetable
end
mana.playerlist = savetable.playerlist
minetest.debug("[mana] mana.mt successfully read.")
end
end
return {}
end
mana.playerlist = {}
function mana.save_to_file(playername)
local savetable = mana.playerlist[playername]
function mana.save_to_file()
local savetable = {}
savetable.playerlist = mana.playerlist
local savestring = minetest.serialize(savetable)
local filepath = minetest.get_worldpath().."/mana/" .. playername
local filepath = minetest.get_worldpath().."/mana.mt"
local file = io.open(filepath, "w")
if file then
file:write(savestring)
io.close(file)
minetest.log("action", "[mana] Wrote mana data for "..playername..".")
minetest.log("action", "[mana] Wrote mana data into "..filepath..".")
else
minetest.log("error", "[mana] Failed to write mana data for "..playername..".")
minetest.log("error", "[mana] Failed to write mana data into "..filepath..".")
end
end
@ -208,21 +209,19 @@ minetest.register_on_leaveplayer(function(player)
if not minetest.get_modpath("hudbars") ~= nil then
mana.hud_remove(playername)
end
mana.save_to_file(playername)
mana.save_to_file()
end)
minetest.register_on_shutdown(function()
minetest.log("action", "[mana] Server shuts down. Rescuing data into mana.mt")
for _, pref in pairs(minetest.get_connected_players()) do
mana.save_to_file(pref:get_player_name())
end
minetest.log("action", "[mana] Server shuts down. Rescuing data into mana.mt")
mana.save_to_file()
end)
minetest.register_on_joinplayer(function(player)
local playername = player:get_player_name()
mana.playerlist[playername] = mana.load_file(playername)
if not mana.playerlist[playername].mana then
if mana.playerlist[playername] == nil then
mana.playerlist[playername] = {}
mana.playerlist[playername].mana = 0
mana.playerlist[playername].maxmana = mana.settings.default_max
mana.playerlist[playername].regen = mana.settings.default_regen
@ -243,38 +242,41 @@ end)
mana.regen_timer = 0
function mana_regen_step()
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
local plus = mana.playerlist[name].regen
-- 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
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
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
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
mana.regen_timer = mana.regen_timer % mana.settings.regen_timer
end
minetest.after(mana.settings.regen_timer, mana_regen_step)
end
minetest.after(0, mana_regen_step)
end)
--[===[
HUD functions
]===]
if minetest.get_modpath("hudbars") ~= nil then
hb.register_hudbar("mana", 0xFFFFFF, "Mana", { bar = "mana_bar_purple.png", icon = "mana_icon_purple.png", bgicon = "mana_bgicon.png" }, 0, mana.settings.default_max, false)
hb.register_hudbar("mana", 0xFFFFFF, S("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)
@ -288,41 +290,30 @@ if minetest.get_modpath("hudbars") ~= nil then
else
function mana.manastring(playername)
return string.format("Mana: %d/%d", mana.get(playername), mana.getmax(playername))
return S("Mana: @1/@2", mana.get(playername), mana.getmax(playername))
end
function mana.hud_add(playername)
local player = minetest.get_player_by_name(playername)
player:hud_add({
hud_elem_type = "statbar",
position = {x=0.5,y=1},
size = {x=24, y=24},
text = "mana_icon_bg_empty.png",
number = 20,
alignment = {x=-1,y=-1},
offset = {x=80, y=-186},
}
)
local id = player:hud_add({
hud_elem_type = "statbar",
position = {x=0.5,y=1},
size = {x=24, y=24},
text = "mana_icon_purple.png",
number = mana.get(playername)/10,
alignment = {x=-1,y=-1},
offset = {x=80, y=-186},
}
)
hud_elem_type = "text",
position = { x = 0.5, y=1 },
text = mana.manastring(playername),
scale = { x = 0, y = 0 },
alignment = { x = 1, y = 0},
direction = 1,
number = 0xFFFFFF,
offset = { x = -262, y = -103}
})
mana.playerlist[playername].hudid = id
return id
end
function mana.hud_update(playername)
local player = minetest.get_player_by_name(playername)
player:hud_change(mana.playerlist[playername].hudid, "number", mana.get(playername)/100)
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)

2
locale/de.txt Normal file
View File

@ -0,0 +1,2 @@
Mana = Mana
Mana: @1/@2 = Mana: @1/@2

2
locale/template.txt Normal file
View File

@ -0,0 +1,2 @@
Mana =
Mana: @1/@2 =

0
textures/mana_bar.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 80 B

After

Width:  |  Height:  |  Size: 80 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 82 B

BIN
textures/mana_bgicon.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 221 B

After

Width:  |  Height:  |  Size: 2.9 KiB

BIN
textures/mana_icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 635 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 600 B