mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2024-11-16 07:20:31 +01:00
Added sprint increase and dicrease with warrior class
- WIP - Solves part of #113 and #114
This commit is contained in:
parent
c80f4e5276
commit
4146c070d0
2
mods/pclasses/depends.txt
Normal file
2
mods/pclasses/depends.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
3d_armor
|
||||
sprint
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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" },
|
||||
|
|
Loading…
Reference in New Issue
Block a user