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

Updated pclasses

- Moved the holographic item's name as a field in switch_params (pclasses.api.register_class)
 - Added wizard class' skeleton for later
 - Fixed a few bugs in nodes, inventory and api
 - Splitted tick function to bury items in two
 - Items from 3d_armor's armor inventory are also affected by inventory vacuuming (from tick function).
   The player's static armor inventory is first cleared, then copied to the detached one, then armor updates everything else (rendering, model, etc)
 - Fixed itemname of admin shield to reserve it properly
 - Return graveyard inventory if it already exists. Do not create it every two seconds
This commit is contained in:
LeMagnesium 2015-08-20 17:11:46 +02:00
parent 837e25bc13
commit 743507564f
11 changed files with 120 additions and 55 deletions

View File

@ -11,7 +11,8 @@ pclasses.api.register_class("admin", {
minetest.chat_send_player(pname, "Hello admin.")
end,
switch_params = {
color = {r = 255, g = 00, b = 224}
color = {r = 255, g = 00, b = 224},
holo_item = "maptools:pick_admin"
}
})
@ -19,6 +20,6 @@ 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", "shields:shield_admin")
pclasses.api.reserve_item("admin", "maptools:pick_admin")
pclasses.api.reserve_item("admin", "maptools:pick_admin_with_drops")

View File

@ -23,7 +23,8 @@ pclasses.api.register_class("hunter", {
end,
switch_params = {
color = {r = 30, g = 170, b = 00},
tile = "default_wood.png"
tile = "default_wood.png",
holo_item = "throwing:bow_minotaur_horn_improved"
}
})

View File

@ -3,3 +3,4 @@ local path = minetest.get_modpath("mff_pclasses")
dofile(path .. "/warrior.lua")
dofile(path .. "/hunter.lua")
dofile(path .. "/admin.lua")
dofile(path .. "/wizard.lua")

View File

@ -11,14 +11,15 @@ pclasses.api.register_class("warrior", {
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")
minetest.log("action", "[PClasses] Player " .. pname .. " becomes a warrior")
end,
on_unassigned = function(pname)
sprint.set_default_maxstamina(pname)
end,
switch_params = {
color = {r = 06, g = 06, b = 30},
tile = "default_steel_block.png"
tile = "default_steel_block.png",
holo_item = "default:dungeon_master_s_blood_sword"
}
})

View File

@ -0,0 +1,22 @@
------------------
-- Wizard class --
------------------
--
-- No Issue Yet
--
pclasses.api.register_class("wizard", {
on_assigned = function(pname)
-- minetest.sound_play("pclasses_full_wizard")
minetest.chat_send_player(pname, "You are now a wizard.")
-- Add specs here
minetest.log("action", "[PClasses] Player " .. pname .. " becomes a wizard")
end,
switch_params = {
color = {r = 230, g = 230, b = 0},
holo_item = "default:book"
}
})
-- Reserved items here

View File

@ -15,39 +15,42 @@ Yet another class mod for Minetest.
### pclasses.api
- All functions used to declare, get, set classes
### pclasses.api.util
- Some utility functions
### pclasses.conf
- Some configuration values
### pclasses.classes
- All classes and their specs
### pclasses.datas
- Miscellaneous datas
### pclasses.data
- Miscellaneous data
#### pclasses.datas.players
#### pclasses.data.players
- List of all players' class. Index is player's name and value is the class's name
#### pclasses.datas.hud_ids
#### pclasses.data.hud_ids
- Surely useful in the future with a hypothetical hud to show current class
# Functions
### pclasses.api.create_class_id
- Arguments : None
- Indicates the next free id/index in the classes' table
### pclasses.api.register_class
- Arguments : cname, def
- Registers a class and its specifications
- Def is a definition table that can contain many functions/values :
- `on_assigned` which is a function, receiving as argument the player name
- `on_unassigned` which is a function, receiving as argument the player name
- `switch_params`, which is a table, containing parameters for the switch pedestal :
- `holo_item` is mandatory. It's the itemstring of the item to be put over the pedestal
- `color` is optional. Default is white. It's a RGB table.
- `tile` is optional. Default is none. It's a string of the texture to be applied over the pedestal
### pclasses.api.id_for_class
- Arguments : cname (class' name)
- Returns the id/index corresponding the class in the classes' table
- Returns 0 if not found, nil if no name given
### pclasses.api.register_class(cname)
- Argument : cname
- Registers a class in the classes' table
- Pretty useless at the moment
- Returns class' id or nil if any error
### pclasses.api.get_class_by_id
- Argument : id
- Return the class' specs (table) corresponding an id or nil when not found
### pclasses.register_class_switch
- Arguments : cname, params
- Used internally to create switch pedestals
- `params` is the `def` table given to `pclasses.api.register_class`, documented above
### pclasses.api.get_class_by_name
- Argument : cname
@ -64,4 +67,27 @@ Yet another class mod for Minetest.
### pclasses.api.set_player_class
- Arguments : pname, cname
- Assign a player the cname class
- Returns true if achieved, false if not
### pclasses.api.util.does_wear_full_armor
- Arguments : pname, material, noshield
- Returns true if player `pname` is wearing the full armor made out of `material`
- `noshield` must be true when the full armor has no shield
### pclasses.api.util.can_have_item
- Arguments : pname, itemname
- Returns true if player `pname` can have items `itemstring` in his main inventory, according to his class
### pclasses.api.reserve_item
- Arguments : cname, itemstring
- Adds an entry in the reserved items' table. Players will need to belong to class `cname` in order to have items `itemstring` in their main inventory
- Note : You can reserve the same item for two classes, any player of either of both can then have the item
### pclasses.api.create_graveyard_inventory
- Argument : player
- Creates a detached inventory dedicated to 'dead' items (confiscated reserved items)
- Used internally, should not be used outside of pclasses
### pclasses.api.vacuum_graveyard
- Argument : player
- Check all of `player`'s graveyard inventory to get them back items they obtained to right to have

View File

@ -6,6 +6,7 @@ pclasses.api.register_class("adventurer", {
switch_params = {
color = { r = 142, g = 64, b = 00},
tile = "wool_white.png",
holo_item = "unified_inventory:bag_large"
},
on_assigned = function(pname)
minetest.chat_send_player(pname, "You are now an adventurer")

View File

@ -116,27 +116,41 @@ end
-- Determination and reserved items tick --
-------------------------------------------
local function tick()
for id, ref in ipairs(minetest.get_connected_players()) do
local name = ref:get_player_name()
local inv = minetest.get_inventory({type="player", name = name})
for i = 1, inv:get_size("main") do
local stack = inv:get_stack("main", i)
if pclasses.data.reserved_items[stack:get_name()] then
if not pclasses.api.util.can_have_item(name, stack:get_name()) then
inv:set_stack("main", i, "")
local grave_inv = pclasses.api.create_graveyard_inventory(ref)
if grave_inv and grave_inv:room_for_item("graveyard", stack) then
grave_inv:add_item("graveyard", stack)
inv:add_item("graveyard", stack)
-- ^ Because add_item doesn't trigger on_put, nonsense
else
minetest.add_item(ref:getpos(), stack)
end
local function vacuum_inventory(name, inv, invname)
local ref = minetest.get_player_by_name(name)
for i = 1, inv:get_size(invname) do
local stack = inv:get_stack(invname, i)
if pclasses.data.reserved_items[stack:get_name()] then
if not pclasses.api.util.can_have_item(name, stack:get_name()) then
inv:set_stack(invname, i, "")
local grave_inv = pclasses.api.create_graveyard_inventory(ref)
if grave_inv and grave_inv:room_for_item("graveyard", stack) then
grave_inv:add_item("graveyard", stack)
inv:add_item("graveyard", stack)
-- ^ Because add_item doesn't trigger on_put, nonsense
else
minetest.add_item(ref:getpos(), stack)
end
end
end
end
end
local function tick()
for id, ref in ipairs(minetest.get_connected_players()) do
local name = ref:get_player_name()
local armor_inv = minetest.get_inventory({type = "detached", name = name .. "_armor"})
local inv = ref:get_inventory()
vacuum_inventory(name, inv, "main")
vacuum_inventory(name, inv, "armor")
-- Hack the hack
for i = 1, armor_inv:get_size("armor") do
armor_inv:set_stack("armor", i, inv:get_stack("armor", i))
end
armor:set_player_armor(ref)
armor:update_inventory(ref)
end
minetest.after(2, tick)
end

View File

@ -18,6 +18,7 @@ pclasses.conf.default_class = "adventurer"
pclasses.conf.save_interval = 3 * 60
pclasses.conf.datafile = minetest.get_worldpath() .. "/pclasses"
pclasses.conf.gravefile = minetest.get_worldpath() .. "/graveyards"
-- Classes
pclasses.classes = {}

View File

@ -5,8 +5,12 @@
-- Inventory for 'dead' items
pclasses.api.create_graveyard_inventory = function(player)
local pname = player:get_player_name()
local grave_inv = minetest.get_inventory({type = "detached", name = pname .. "_graveyard"})
if grave_inv then
return grave_inv
end
local player_inv = minetest.get_inventory({type = "player", name = pname})
local grave_inv = minetest.create_detached_inventory(pname .. "_graveyard", {
grave_inv = minetest.create_detached_inventory(pname .. "_graveyard", {
on_take = function(inv, listname, index, stack, player)
player_inv:set_stack(listname, index, nil)
end,
@ -64,7 +68,7 @@ function pclasses.api.vacuum_graveyard(player)
if player_inv:room_for_item("main", stack) then
player_inv:add_item("main", stack)
else
minetest.add_item(pos, stack)
minetest.add_item(player:getpos(), stack)
end
end
end

View File

@ -61,18 +61,11 @@ minetest.register_entity("pclasses:item", {
end,
})
local classes_items = {
["hunter"] = "throwing:bow_minotaur_horn_improved",
["warrior"] = "default:dungeon_master_s_blood_sword",
["admin"] = "maptools:pick_admin",
["adventurer"] = "unified_inventory:bag_large",
["wizard"] = "default:book"
}
function pclasses.register_class_switch(cname, params)
local color = params.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"
local holo_item = params.holo_item or "default:diamond"
minetest.register_node(":pclasses:class_switch_" .. cname, {
description = "Class switch orb (" .. cname .. ")",
tiles = {(params.tile or overlay) .. "^[colorize:" .. txtcolor .. ":200"},
@ -101,7 +94,7 @@ function pclasses.register_class_switch(cname, params)
local obj = minetest.add_entity(pos, "pclasses:item")
if obj then
obj:get_luaentity():set_item(classes_items[cname])
obj:get_luaentity():set_item(holo_item)
obj:get_luaentity():set_class(cname)
end
pos.y = pos.y - 1
@ -119,7 +112,7 @@ function pclasses.register_class_switch(cname, params)
local obj = minetest.add_entity(pos, "pclasses:item")
if obj then
obj:get_luaentity():set_item(classes_items[cname])
obj:get_luaentity():set_item(holo_item)
obj:get_luaentity():set_class(cname)
end
return true