2015-07-15 17:08:22 +02:00
|
|
|
-------------------
|
|
|
|
-- Player Classes
|
|
|
|
--
|
|
|
|
|
|
|
|
-- NOTE: This is a very simple interface for classes, more features will be
|
|
|
|
-- added depending on the various mechanisms we will need
|
|
|
|
|
|
|
|
-- Global namespace
|
|
|
|
pclasses = {}
|
|
|
|
|
|
|
|
-- API
|
|
|
|
pclasses.api = {}
|
2015-07-26 01:05:10 +02:00
|
|
|
pclasses.api.util = {}
|
2015-07-15 17:08:22 +02:00
|
|
|
|
2015-07-17 13:44:11 +02:00
|
|
|
-- Configuration
|
|
|
|
pclasses.conf = {}
|
|
|
|
pclasses.conf.default_class = "adventurer"
|
|
|
|
pclasses.conf.save_interval = 3 * 60
|
|
|
|
pclasses.conf.datafile = minetest.get_worldpath() .. "/pclasses"
|
|
|
|
|
2015-07-15 17:08:22 +02:00
|
|
|
-- Classes
|
|
|
|
pclasses.classes = {}
|
|
|
|
|
|
|
|
-- Data
|
|
|
|
pclasses.datas = {}
|
|
|
|
pclasses.datas.players = {}
|
2015-07-19 23:20:01 +02:00
|
|
|
pclasses.datas.reserved_items = {}
|
2015-07-15 17:08:22 +02:00
|
|
|
pclasses.datas.hud_ids = {} -- HUD maybe?
|
|
|
|
|
2015-07-27 19:13:30 +02:00
|
|
|
dofile(minetest.get_modpath("pclasses") .. "/api.lua")
|
2015-07-15 17:08:22 +02:00
|
|
|
|
|
|
|
|
2015-07-17 13:44:11 +02:00
|
|
|
|
|
|
|
---------------------------
|
|
|
|
-- Backup and load system
|
|
|
|
--
|
|
|
|
|
|
|
|
-- Startup
|
|
|
|
local pfile = io.open(pclasses.conf.datafile, "r")
|
|
|
|
if pfile then
|
|
|
|
local line = pfile:read()
|
|
|
|
if line then
|
|
|
|
pclasses.datas.players = minetest.deserialize(line)
|
|
|
|
end
|
2015-07-27 22:50:48 +02:00
|
|
|
pfile:close()
|
2015-07-17 13:44:11 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Frequent backup
|
|
|
|
local function save_datas()
|
|
|
|
local pfile = io.open(pclasses.conf.datafile, "w")
|
|
|
|
pfile:write(minetest.serialize(pclasses.datas.players))
|
2015-07-27 23:43:31 +02:00
|
|
|
pfile:close()
|
2015-07-17 13:44:11 +02:00
|
|
|
minetest.log("action", "[PClasses] Datas saved")
|
|
|
|
end
|
|
|
|
|
|
|
|
local save_timer = 0
|
|
|
|
minetest.register_globalstep(function(dtime)
|
|
|
|
save_timer = save_timer + dtime
|
|
|
|
if save_timer >= pclasses.conf.save_interval then
|
|
|
|
save_datas()
|
|
|
|
save_timer = 0
|
|
|
|
end
|
|
|
|
end)
|
2015-07-18 18:31:24 +02:00
|
|
|
minetest.register_on_shutdown(save_datas)
|
2015-07-17 13:44:11 +02:00
|
|
|
|
2015-07-27 19:13:30 +02:00
|
|
|
|
|
|
|
|
|
|
|
------------------
|
|
|
|
-- Default class
|
2015-07-17 13:44:11 +02:00
|
|
|
--
|
2015-07-27 19:13:30 +02:00
|
|
|
|
2015-07-17 13:44:11 +02:00
|
|
|
if pclasses.conf.default_class then
|
2015-07-27 19:13:30 +02:00
|
|
|
dofile(minetest.get_modpath("pclasses") .. "/" .. pclasses.conf.default_class .. ".lua")
|
|
|
|
if pclasses.api.get_class_by_name(pclasses.conf.default_class) then
|
2015-07-17 13:44:11 +02:00
|
|
|
minetest.register_on_joinplayer(function(player)
|
|
|
|
if not pclasses.api.get_player_class(player:get_player_name()) then
|
|
|
|
pclasses.api.set_player_class(player:get_player_name(),
|
|
|
|
pclasses.conf.default_class)
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
end
|
2015-07-18 18:31:24 +02:00
|
|
|
|
2015-07-27 19:13:30 +02:00
|
|
|
|
2015-07-18 18:31:24 +02:00
|
|
|
|
|
|
|
------------
|
|
|
|
-- Classes
|
|
|
|
--
|
|
|
|
|
2015-07-27 19:13:30 +02:00
|
|
|
dofile(minetest.get_modpath("pclasses") .. "/warrior.lua")
|
|
|
|
dofile(minetest.get_modpath("pclasses") .. "/hunter.lua")
|
2015-07-28 16:14:51 +02:00
|
|
|
dofile(minetest.get_modpath("pclasses") .. "/admin.lua")
|
2015-07-19 23:20:01 +02:00
|
|
|
|