65 lines
1.6 KiB
Lua
Executable File

magic = { }
local magic_file = minetest.get_worldpath().."/magic"
local magicpath = minetest.get_modpath("magic")
magic.player_magic = default.deserialize_from_file(magic_file)
hud.register("magic", {
hud_elem_type = "statbar",
position = {x = 0.5, y = 1},
offset = {x=-262,y=-113},
size = HUD_SB_SIZE,
text = "hud_magic_fg.png",
number = 20,
alignment = {x=-1,y=-1},
background = "hud_magic_bg.png",
autohide_bg = true,
max = 20,
})
dofile(magicpath.."/api.lua")
dofile(magicpath.."/loop.lua")
function magic.update_magic(player,name)
if minetest.check_player_privs(name, {immortal=true}) then
magic.player_magic[name] = 20
hud.change_item(player,"magic", {number = magic.player_magic[name]})
return
end
local s = skills.get_skill(name,SKILL_MAGIC)
local baseAdj = 2
if magic.player_magic[name] ~= nil then
if default.player_get_animation(player) == "lay" then
baseAdj = baseAdj + 3
end
if default.player_get_animation(player) == "sit" then
baseAdj = baseAdj + 1
end
local adj = baseAdj * ( s.level / 10 )
magic.player_magic[name] = magic.player_magic[name] + adj
if magic.player_magic[name] > 20 then
magic.player_magic[name] = 20
end
if magic.player_magic[name] < 0 then
magic.player_magic[name] = 0
end
else
magic.player_magic[name] = 20
end
hud.change_item(player,"magic", {number = magic.player_magic[name]})
end
minetest.register_on_shutdown(function()
default.serialize_to_file(magic_file,magic.player_magic)
end)
-- load magic spells
dofile(magicpath.."/thunder.lua")
dofile(magicpath.."/magicmissle.lua")
dofile(magicpath.."/heal.lua")