diff --git a/mods/pclasses/admin.lua b/mods/pclasses/admin.lua deleted file mode 100755 index 44795e7b..00000000 --- a/mods/pclasses/admin.lua +++ /dev/null @@ -1,24 +0,0 @@ ------------------ --- Admin class -- ------------------ - --- --- https://github.com/MinetestForFun/minetest-minetestforfun-server/issues/139 --- - -pclasses.api.register_class("admin", { - determination = function(player) - return minetest.get_player_privs(player:get_player_name()).server - end, - on_assigned = function(pname) - minetest.chat_send_player(pname, "Hello admin.") - end -}) - -pclasses.api.reserve_item("admin", "3d_armor:helmet_admin") -pclasses.api.reserve_item("admin", "3d_armor:chestplate_admin") -pclasses.api.reserve_item("admin", "3d_armor:leggings_admin") -pclasses.api.reserve_item("admin", "3d_armor:boots_admin") -pclasses.api.reserve_item("admin", "shields:shields_admin") -pclasses.api.reserve_item("admin", "maptools:pick_admin") -pclasses.api.reserve_item("admin", "maptools:pick_admin_with_drops") diff --git a/mods/pclasses/adventurer.lua b/mods/pclasses/adventurer.lua index e31eefb4..2086f975 100755 --- a/mods/pclasses/adventurer.lua +++ b/mods/pclasses/adventurer.lua @@ -1,11 +1,11 @@ ----------------------------- --- Default class assignment +-- Boilerplate class -- pclasses.api.register_class("adventurer", { - determination = function() return true end, + orb_color = { r = 255, g = 200, b = 200 }, on_assigned = function(pname) - minetest.chat_send_player(pname, "You are now an adventurer") + minetest.chat_send_player(pname, "You are now an adventurer") end }) diff --git a/mods/pclasses/api.lua b/mods/pclasses/api.lua index 6a0d5d81..5456cd00 100755 --- a/mods/pclasses/api.lua +++ b/mods/pclasses/api.lua @@ -13,11 +13,8 @@ function pclasses.api.register_class(cname, def) minetest.log("error", "[PClasses] Error registering class " .. cname .. ". Reason : no definition table.") return - elseif not def.determination then - minetest.log("error", "[PClasses] Error registreing class " .. - cname .. ". Reason : no determination function.") - return end + pclasses.register_class_switch_orb(cname, def.orb_color) pclasses.classes[cname] = def return true @@ -79,36 +76,12 @@ pclasses.api.util.does_wear_full_armor = function(pname, material, noshield) return full_armor and (inv:contains_item("armor", "shields:shield_" .. material) or noshield) end ----------------------------- --- Determination callback -- ----------------------------- - -function pclasses.api.assign_class(player) - -- Look for every sign needed to deduct a player's class - -- Starting from the most important class to the less one - - local pname = player:get_player_name() - - if pclasses.classes["admin"].determination(player) then - pclasses.api.set_player_class(pname, "admin") - - elseif pclasses.classes["hunter"].determination(player) then - pclasses.api.set_player_class(pname, "hunter") - - elseif pclasses.api.get_class_by_name("warrior").determination(player) then - pclasses.api.set_player_class(pname, "warrior") - - elseif pclasses.conf.default_class then - pclasses.api.set_player_class(pname, pclasses.conf.default_class) - end -end - ------------------- -- Reserved items -- function pclasses.api.reserve_item(cname, itemstring) pclasses.data.reserved_items[itemstring] = pclasses.data.reserved_items[itemstring] or {} - table.insert(pclasses.data.reserved_items[itemstring], 1, cname) + table.insert(pclasses.data.reserved_items[itemstring], cname) end ------------------------------------------- -- Determination and reserved items tick -- @@ -116,8 +89,6 @@ end local function tick() for id, ref in ipairs(minetest.get_connected_players()) do - pclasses.api.assign_class(ref) - local name = ref:get_player_name() local inv = minetest.get_inventory({type="player", name = name}) for i = 1, inv:get_size("main") do diff --git a/mods/pclasses/hunter.lua b/mods/pclasses/hunter.lua deleted file mode 100755 index 3e28a790..00000000 --- a/mods/pclasses/hunter.lua +++ /dev/null @@ -1,33 +0,0 @@ ------------------- --- Hunter class -- ------------------- - --- --- See https://github.com/Ombridride/minetest-minetestforfun-server/issues/114 --- - -pclasses.api.register_class("hunter", { - determination = function(player) - return pclasses.api.util.does_wear_full_armor(player:get_player_name(), "reinforcedleather", true) - or pclasses.api.util.does_wear_full_armor(player:get_player_name(), "hardenedleather", true) - end, - on_assigned = function(pname) - minetest.chat_send_player(pname, "You are now a hunter") - minetest.sound_play("pclasses_full_hunter") - local reinforced = pclasses.api.util.does_wear_full_armor(pname, "reinforcedleather", true) - if reinforced then - sprint.increase_maxstamina(pname, 20) - else - sprint.increase_maxstamina(pname, 10) - end - minetest.log("action", "[PClasses] Player " .. pname .. " become a hunter") - end, - on_unassigned = function(pname) - sprint.set_default_maxstamina(pname) - end, -}) - - -pclasses.api.reserve_item("hunter", "throwing:bow_minotaur_horn") -pclasses.api.reserve_item("hunter", "throwing:bow_minotaur_horn_improved") -pclasses.api.reserve_item("hunter", "throwing:arrow_mithril") diff --git a/mods/pclasses/init.lua b/mods/pclasses/init.lua index b9e4afc8..387a07d2 100755 --- a/mods/pclasses/init.lua +++ b/mods/pclasses/init.lua @@ -28,8 +28,37 @@ pclasses.data.reserved_items = {} pclasses.data.hud_ids = {} -- HUD maybe? dofile(minetest.get_modpath("pclasses") .. "/api.lua") +dofile(minetest.get_modpath("pclasses") .. "/nodes.lua") +function pclasses.data.load() + local file = io.open(minetest.get_worldpath().."/quests", "r") + if file then + local loaded = minetest.deserialize(file:read("*all")) + file:close() + pclasses.data.players = loaded.players or pclasses.data.players + minetest.log("action", "[PClasses] Loaded data") + end +end +function pclasses.data.save() + local file, err = io.open(pclasses.conf.datafile, "w") + if file then + file:write(minetest.serialize({ + players = pclasses.data.players, + })) + file:close() + minetest.log("action", "[PClasses] Saved data") + else + minetest.log("error", "[PClasses] Data save failed: open failed: " .. err) + end +end + +local function data_save_loop() + minetest.after(save_interval, data_save_loop) + pclasses.data.save() +end + +pclasses.data.load() ------------------ -- Default class @@ -39,18 +68,10 @@ if pclasses.conf.default_class then dofile(minetest.get_modpath("pclasses") .. "/" .. pclasses.conf.default_class .. ".lua") if pclasses.api.get_class_by_name(pclasses.conf.default_class) then minetest.register_on_joinplayer(function(player) - pclasses.api.assign_class(player) + local pname = player:get_player_name() + if pclasses.api.get_player_class(pname) == nil then + pclasses.api.set_player_class(pname, pclasses.conf.default_class) + end end) end end - - - ------------- --- Classes --- - -dofile(minetest.get_modpath("pclasses") .. "/warrior.lua") -dofile(minetest.get_modpath("pclasses") .. "/hunter.lua") -dofile(minetest.get_modpath("pclasses") .. "/admin.lua") - diff --git a/mods/pclasses/nodes.lua b/mods/pclasses/nodes.lua new file mode 100644 index 00000000..c9d58f54 --- /dev/null +++ b/mods/pclasses/nodes.lua @@ -0,0 +1,20 @@ +function pclasses.register_class_switch_orb(cname, color) + color = color or { r = 255, g = 255, b = 255 } + local txtcolor = string.format("#%02x%02x%02x", color.r, color.g, color.b) + local overlay = "pclasses_class_switch_orb_overlay.png" + minetest.register_node(":pclasses:class_switch_orb_" .. cname, { + description = "Class switch orb (" .. cname .. ")", + tiles = {overlay .. "^[colorize:" .. txtcolor .. "^" .. overlay}, + drop = "", + can_dig = function() return false end, + diggable = false, + sunlight_propagates = true, + light_source = 10, + sounds = default.node_sound_glass_defaults(), + groups = {not_in_creative_inventory=1}, + on_rightclick = function(pos, node, player, itemstack, pointed_thing) + -- TODO implement timeout logic + pclasses.api.set_player_class(player:get_player_name(), cname) + end + }) +end diff --git a/mods/pclasses/sounds/3d_armor_full_warrior.ogg-old b/mods/pclasses/sounds/3d_armor_full_warrior.ogg-old deleted file mode 100755 index e6882043..00000000 Binary files a/mods/pclasses/sounds/3d_armor_full_warrior.ogg-old and /dev/null differ diff --git a/mods/pclasses/sounds/pclasses_full_hunter.ogg b/mods/pclasses/sounds/pclasses_full_hunter.ogg deleted file mode 100755 index 21ecf0d7..00000000 Binary files a/mods/pclasses/sounds/pclasses_full_hunter.ogg and /dev/null differ diff --git a/mods/pclasses/sounds/pclasses_full_warrior.ogg b/mods/pclasses/sounds/pclasses_full_warrior.ogg deleted file mode 100755 index fd262bc2..00000000 Binary files a/mods/pclasses/sounds/pclasses_full_warrior.ogg and /dev/null differ diff --git a/mods/pclasses/sounds/pclasses_full_wizard.ogg b/mods/pclasses/sounds/pclasses_full_wizard.ogg deleted file mode 100755 index 28bdcb62..00000000 Binary files a/mods/pclasses/sounds/pclasses_full_wizard.ogg and /dev/null differ diff --git a/mods/pclasses/textures/pclasses_class_switch_orb_overlay.png b/mods/pclasses/textures/pclasses_class_switch_orb_overlay.png new file mode 100644 index 00000000..aee7e0f4 Binary files /dev/null and b/mods/pclasses/textures/pclasses_class_switch_orb_overlay.png differ diff --git a/mods/pclasses/warrior.lua b/mods/pclasses/warrior.lua deleted file mode 100755 index 66edb1d8..00000000 --- a/mods/pclasses/warrior.lua +++ /dev/null @@ -1,25 +0,0 @@ -------------------- --- Warrior class -- -------------------- - --- --- See https://github.com/Ombridride/minetest-minetestforfun-server/issues/113 --- - -pclasses.api.register_class("warrior", { - determination = function(player) - return pclasses.api.util.does_wear_full_armor(player:get_player_name(), "blackmithril", false) - end, - on_assigned = function(pname) - minetest.sound_play("pclasses_full_warrior") - minetest.chat_send_player(pname, "You are now a warrior") - sprint.set_maxstamina(pname, 20) - minetest.log("action", "[PClasses] Player " .. pname .. " become a warrior") - end, - on_unassigned = function(pname) - sprint.set_default_maxstamina(pname) - end, -}) - -pclasses.api.reserve_item("warrior", "moreores:sword_mithril") -pclasses.api.reserve_item("warrior", "default:dungeon_master_s_blood_sword")