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

[pclasses] Remove active detection, introduce class switch orbs

This commit is contained in:
Wouters Dorian 2015-07-31 21:47:55 +02:00
parent fbfc43fc63
commit 9e359f7fcd
12 changed files with 58 additions and 128 deletions

View File

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

View File

@ -1,9 +1,9 @@
-----------------------------
-- 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")
end

View File

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

View File

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

View File

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

20
mods/pclasses/nodes.lua Normal file
View File

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 292 B

View File

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