From ee58c4930fa75f0bbaeb8a8b3374855bba9fd625 Mon Sep 17 00:00:00 2001 From: crabman77 Date: Sat, 8 Apr 2017 18:23:57 +0200 Subject: [PATCH] improve pclasses to fix class stats don't change on equip/unequip/destroy armor --- mods/3d_armor/3d_armor/armor.lua | 1 + mods/mff/mff_pclasses/admin.lua | 3 +++ mods/mff/mff_pclasses/hunter.lua | 19 +++++++++++++------ mods/mff/mff_pclasses/warrior.lua | 8 +++++++- mods/mff/mff_pclasses/wizard.lua | 8 +++++++- mods/pclasses/README.md | 5 +++++ mods/pclasses/adventurer.lua | 7 +++++++ mods/pclasses/api.lua | 7 +++++++ 8 files changed, 50 insertions(+), 8 deletions(-) diff --git a/mods/3d_armor/3d_armor/armor.lua b/mods/3d_armor/3d_armor/armor.lua index 493be794..6f561db2 100755 --- a/mods/3d_armor/3d_armor/armor.lua +++ b/mods/3d_armor/3d_armor/armor.lua @@ -249,6 +249,7 @@ armor.set_player_armor = function(self, player) player:set_armor_groups(armor_groups) --player:set_physics_override(physics_o) player_physics.set_stats(player, "3d_armor", {speed=physics_o.speed-1, jump=physics_o.jump-1, gravity=physics_o.gravity-1}) + pclasses.api.util.on_update(name) self.textures[name].armor = armor_texture self.textures[name].preview = preview self.def[name].state = state diff --git a/mods/mff/mff_pclasses/admin.lua b/mods/mff/mff_pclasses/admin.lua index 822fa268..73a91dcc 100755 --- a/mods/mff/mff_pclasses/admin.lua +++ b/mods/mff/mff_pclasses/admin.lua @@ -11,9 +11,12 @@ pclasses.api.register_class("admin", { if inform then minetest.chat_send_player(pname, "Hello admin.") end + pclasses.api.util.on_update(pname) end, on_unassigned = function(pname) end, + on_update = function(pname) + end, switch_params = { color = {r = 255, g = 00, b = 224}, holo_item = "maptools:pick_admin" diff --git a/mods/mff/mff_pclasses/hunter.lua b/mods/mff/mff_pclasses/hunter.lua index 2e36d931..03d3a8a9 100755 --- a/mods/mff/mff_pclasses/hunter.lua +++ b/mods/mff/mff_pclasses/hunter.lua @@ -12,17 +12,24 @@ pclasses.api.register_class("hunter", { minetest.chat_send_player(pname, "You are now a hunter") minetest.sound_play("pclasses_full_hunter", {to_player=pname, gain=1}) end - local reinforced = pclasses.api.util.does_wear_full_armor(pname, "reinforcedleather", true) - if reinforced then - sprint.increase_maxstamina(pname, 40) - else - sprint.increase_maxstamina(pname, 30) - end + pclasses.api.util.on_update(pname) minetest.log("action", "[PClasses] Player " .. pname .. " become a hunter") end, on_unassigned = function(pname) sprint.set_default_maxstamina(pname) end, + on_update = function(pname) + local staminavalue = 30 + local manavalue = 100 + local reinforced = pclasses.api.util.does_wear_full_armor(pname, "reinforcedleather", true) + if reinforced then + staminavalue = staminavalue + 20 + else + staminavalue = staminavalue + 10 + end + sprint.set_maxstamina(pname, staminavalue) + mana.setmax(pname, manavalue) + end, switch_params = { color = {r = 30, g = 170, b = 00}, tile = "default_wood.png", diff --git a/mods/mff/mff_pclasses/warrior.lua b/mods/mff/mff_pclasses/warrior.lua index 703fdc75..15e314f7 100755 --- a/mods/mff/mff_pclasses/warrior.lua +++ b/mods/mff/mff_pclasses/warrior.lua @@ -12,12 +12,18 @@ pclasses.api.register_class("warrior", { minetest.sound_play("pclasses_full_warrior", {to_player=pname, gain=1}) minetest.chat_send_player(pname, "You are now a warrior") end - sprint.set_maxstamina(pname, 20) + pclasses.api.util.on_update(pname) minetest.log("action", "[PClasses] Player " .. pname .. " becomes a warrior") end, on_unassigned = function(pname) sprint.set_default_maxstamina(pname) end, + on_update = function(pname) + local staminavalue = 20 + local manavalue = 100 + sprint.set_maxstamina(pname, staminavalue) + mana.setmax(pname, manavalue) + end, switch_params = { color = {r = 06, g = 06, b = 30}, tile = "default_steel_block.png", diff --git a/mods/mff/mff_pclasses/wizard.lua b/mods/mff/mff_pclasses/wizard.lua index 039c741a..aa40754d 100755 --- a/mods/mff/mff_pclasses/wizard.lua +++ b/mods/mff/mff_pclasses/wizard.lua @@ -13,12 +13,18 @@ pclasses.api.register_class("wizard", { minetest.chat_send_player(pname, "You are now a wizard.") end -- Add specs here - mana.setmax(pname, mana.getmax(pname)+100) + pclasses.api.util.on_update(pname) minetest.log("action", "[PClasses] Player " .. pname .. " becomes a wizard") end, on_unassigned = function(pname) mana.setmax(pname, mana.getmax(pname)-100) end, + on_update = function(pname) + local staminavalue = 30 + local manavalue = 200 + sprint.set_maxstamina(pname, staminavalue) + mana.setmax(pname, manavalue) + end, switch_params = { color = {r = 230, g = 230, b = 0}, holo_item = "default:book" diff --git a/mods/pclasses/README.md b/mods/pclasses/README.md index d972c4ac..5e5d8e61 100755 --- a/mods/pclasses/README.md +++ b/mods/pclasses/README.md @@ -42,6 +42,7 @@ Yet another class mod for Minetest. - 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 + - `on_update` 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. @@ -78,6 +79,10 @@ Yet another class mod for Minetest. - Arguments : pname, itemname - Returns true if player `pname` can have items `itemstring` in his main inventory, according to his class +### pclasses.api.util.on_update + - Arguments : pname + - Update player's stats + ### 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 diff --git a/mods/pclasses/adventurer.lua b/mods/pclasses/adventurer.lua index 93e854a7..0a4c2676 100755 --- a/mods/pclasses/adventurer.lua +++ b/mods/pclasses/adventurer.lua @@ -12,9 +12,16 @@ pclasses.api.register_class("adventurer", { if inform then minetest.chat_send_player(pname, "You are now an adventurer") end + pclasses.api.util.on_update(pname) end, on_unassigned = function(pname) end, + on_update = function(pname) + local staminavalue = 10 + local manavalue = 100 + sprint.set_maxstamina(pname, staminavalue) + mana.setmax(pname, manavalue) + end, informations = pclasses.api.textify("Adventurer, the casual players, or hardcore players. Whatever end of the spectrum\n" .. "you're in, adventurer will bring you what you want : no advantages, no help. Maybe you\n" .. "don't want that if you just began playing. If that's the case.. just pick another tab and\n" .. diff --git a/mods/pclasses/api.lua b/mods/pclasses/api.lua index ff9caac9..d6857aa3 100755 --- a/mods/pclasses/api.lua +++ b/mods/pclasses/api.lua @@ -100,6 +100,13 @@ function pclasses.api.util.can_have_item(pname, itemname) return false end +function pclasses.api.util.on_update(pname) + local cname = pclasses.api.get_player_class(pname) + if cname ~= nil and pclasses.api.get_class_by_name(cname) and pclasses.api.get_class_by_name(cname).on_update then + pclasses.api.get_class_by_name(cname).on_update(pname) + end +end + -- TEMPORARY CLASS SHIFT SYSTEM -- Used to test on local servers --