diff --git a/mods/pclasses/depends.txt b/mods/pclasses/depends.txt new file mode 100644 index 00000000..00881d35 --- /dev/null +++ b/mods/pclasses/depends.txt @@ -0,0 +1,2 @@ +3d_armor +sprint diff --git a/mods/pclasses/init.lua b/mods/pclasses/init.lua index 089993b6..1ac049f9 100755 --- a/mods/pclasses/init.lua +++ b/mods/pclasses/init.lua @@ -10,6 +10,7 @@ pclasses = {} -- API pclasses.api = {} +pclasses.api.util = {} -- Configuration pclasses.conf = {} @@ -136,6 +137,17 @@ if pclasses.conf.default_class then end end +pclasses.api.util.does_wear_full_armor = function(pname, material, noshield) + local inv = minetest.get_inventory({type = "detached", name = pname .. "_armor"}) + if not inv or inv:is_empty() then + return false + end + local full_armor = true + for _, piece in pairs({"chestplate", "leggings", "boots", "helmet"}) do + full_armor = full_armor and inv:contains_item("armor", "3d_armor:" .. piece .. "_" .. material) + end + return full_armor and (inv:contains_item("armor", "shields:shield_" .. material) or noshield) +end ------------ -- Classes @@ -143,24 +155,25 @@ end pclasses.api.register_class("warrior", { determination = function(player) - local inv = minetest.get_inventory({type = "detached", name = player:get_player_name() .. "_armor"}) - local shift_class = false - if not inv or inv:is_empty("armor") then - return shift_class - end - shift_class = true - for _,piece in pairs({"chestplate", "leggings", "boots", "helmet"}) do - shift_class = shift_class and (inv:contains_item("armor", "3d_armor:" .. piece .. "_mithril") - or inv:contains_item("armor", "3d_armor:" .. piece .. "_blackmithril")) - end - return shift_class + return pclasses.api.util.does_wear_full_armor(player:get_player_name(), "harnededleather", true) + or pclasses.api.util.does_wear_full_armor(player:get_player_name(), "reinforcedleather", true) end, on_assigned = function(pname) minetest.sound_play("pclasses_full_warrior") minetest.chat_send_player(pname, "You are now a warrior") + 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 + end, + on_unassigned = function(pname) + sprint.set_default_maxstamina(pname) end, }) + pclasses.api.register_class("hunter", { determination = function(player) local inv = minetest.get_inventory({type = "detached", name = player:get_player_name() .. "_armor"}) @@ -188,17 +201,26 @@ function pclasses.api.assign_class(player) local pname = player:get_player_name() if pclasses.api.get_class_by_name("hunter").determination(player) then if pclasses.api.get_player_class(pname) ~= "hunter" then + if pclasses.api.get_class_by_name(pclasses.api.get_player_class(pname)).on_unassigned then + pclasses.api.get_class_by_name(pclasses.api.get_player_class(pname)).on_unassigned(pname) + end pclasses.api.set_player_class(pname, "hunter") pclasses.api.get_class_by_name("hunter").on_assigned(pname) end elseif pclasses.api.get_class_by_name("warrior").determination(player) then if pclasses.api.get_player_class(pname) ~= "warrior" then + if pclasses.api.get_class_by_name(pclasses.api.get_player_class(pname)).on_unassigned then + pclasses.api.get_class_by_name(pclasses.api.get_player_class(pname)).on_unassigned(pname) + end pclasses.api.set_player_class(pname, "warrior") pclasses.api.get_class_by_name("warrior").on_assigned(pname) end elseif pclasses.conf.default_class then if pclasses.api.get_player_class(pname) ~= pclasses.conf.default_class then + if pclasses.api.get_class_by_name(pclasses.api.get_player_class(pname)).on_unassigned then + pclasses.api.get_class_by_name(pclasses.api.get_player_class(pname)).on_unassigned(pname) + end pclasses.api.set_player_class(pname, pclasses.conf.default_class) pclasses.api.get_class_by_name(pclasses.conf.default_class).on_assigned(pname) end diff --git a/mods/sprint/esprint.lua b/mods/sprint/esprint.lua index bdaf0873..b1681e8b 100755 --- a/mods/sprint/esprint.lua +++ b/mods/sprint/esprint.lua @@ -10,6 +10,34 @@ distributed without any warranty. local players = {} local staminaHud = {} +-- Lil' helping functions +sprint.set_maxstamina = function(pname, mstamina) + if players[pname] and mstamine > 0 then + players[pname].maxStamina = mstamina + end +end + +sprint.get_maxstamina = function(pname) + if players[pname] then + return players[pname].maxStamina + end +end + +sprint.increase_maxstamina = function(pname, sincrease) + local stamina = sprint.get_maxstamina(pname) + if stamina then + sprint.set_maxstamina(pname, stamina + sincrease) + end +end + +sprint.dicrease_maxstamina = function(pname, sdicrease) + local stamina = sprint.get_maxstamina(pname) + if stamina then + sprint.set_maxstamina(pname, stamina - sdicrease) + end +end + + minetest.register_on_joinplayer(function(player) local playerName = player:get_player_name() @@ -18,6 +46,7 @@ minetest.register_on_joinplayer(function(player) timeOut = 0, stamina = SPRINT_STAMINA, shouldSprint = false, + maxStamina = SPRINT_STAMINA } if SPRINT_HUDBARS_USED then hb.init_hudbar(player, "sprint") @@ -115,12 +144,12 @@ minetest.register_globalstep(function(dtime) end --Increase player's stamina if he/she is not sprinting and his/her stamina is less than SPRINT_STAMINA - if playerInfo["sprinting"] == false and playerInfo["stamina"] < SPRINT_STAMINA then + if playerInfo["sprinting"] == false and playerInfo["stamina"] < playerInfo["maxStamina"] then playerInfo["stamina"] = playerInfo["stamina"] + dtime end -- Cap stamina at SPRINT_STAMINA - if playerInfo["stamina"] > SPRINT_STAMINA then - playerInfo["stamina"] = SPRINT_STAMINA + if playerInfo["stamina"] > playerInfo["stamina"] then + playerInfo["stamina"] = playerInfo["stamina"] end --Update the players's hud sprint stamina bar @@ -128,7 +157,7 @@ minetest.register_globalstep(function(dtime) if SPRINT_HUDBARS_USED then hb.change_hudbar(player, "sprint", playerInfo["stamina"]) else - local numBars = (playerInfo["stamina"]/SPRINT_STAMINA)*20 + local numBars = (playerInfo["stamina"]/playerInfo["maxStamina"])*20 player:hud_change(playerInfo["hud"], "number", numBars) end end diff --git a/mods/sprint/init.lua b/mods/sprint/init.lua index ee90f0c9..e8fc69b2 100755 --- a/mods/sprint/init.lua +++ b/mods/sprint/init.lua @@ -14,6 +14,8 @@ SPRINT_JUMP = 1.1 SPRINT_STAMINA = 10 SPRINT_TIMEOUT = 0.5 --Only used if SPRINT_METHOD = 0 +sprint = {} + if minetest.get_modpath("hudbars") ~= nil then hb.register_hudbar("sprint", 0xFFFFFF, "Stamina", { bar = "sprint_stamina_bar.png", icon = "stamina.png" },