From fd0602a45daeb26f5e9e0976b309c54d156b679d Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Tue, 21 Nov 2023 23:41:19 -0300 Subject: [PATCH] fix: infinity prey time if stamina system is disabled (#1873) Resolves #518 --- data-canary/scripts/creaturescripts/login.lua | 4 ++-- .../scripts/creaturescripts/logout.lua | 4 ++-- .../scripts/creaturescripts/others/login.lua | 2 +- .../scripts/creaturescripts/others/logout.lua | 4 ++-- data/events/scripts/player.lua | 19 +++++++++++-------- data/global.lua | 4 ++-- 6 files changed, 20 insertions(+), 17 deletions(-) diff --git a/data-canary/scripts/creaturescripts/login.lua b/data-canary/scripts/creaturescripts/login.lua index edcb45ac327..5455b801d8c 100644 --- a/data-canary/scripts/creaturescripts/login.lua +++ b/data-canary/scripts/creaturescripts/login.lua @@ -14,7 +14,7 @@ function login.onLogin(player) end -- Stamina - nextUseStaminaTime[player.uid] = 0 + _G.NextUseStaminaTime[player.uid] = 0 -- Promotion local vocation = player:getVocation() @@ -98,7 +98,7 @@ function login.onLogin(player) local playerId = player:getId() -- Stamina - nextUseStaminaTime[playerId] = 1 + _G.NextUseStaminaTime[playerId] = 1 -- EXP Stamina nextUseXpStamina[playerId] = 1 diff --git a/data-canary/scripts/creaturescripts/logout.lua b/data-canary/scripts/creaturescripts/logout.lua index df1ff64b8ce..22612d2a7e4 100644 --- a/data-canary/scripts/creaturescripts/logout.lua +++ b/data-canary/scripts/creaturescripts/logout.lua @@ -2,8 +2,8 @@ local logout = CreatureEvent("PlayerLogout") function logout.onLogout(player) local playerId = player:getId() - if nextUseStaminaTime[playerId] then - nextUseStaminaTime[playerId] = nil + if _G.NextUseStaminaTime[playerId] then + _G.NextUseStaminaTime[playerId] = nil end if onExerciseTraining[playerId] then diff --git a/data-otservbr-global/scripts/creaturescripts/others/login.lua b/data-otservbr-global/scripts/creaturescripts/others/login.lua index 45e2cabc7fc..180a4e68d7d 100644 --- a/data-otservbr-global/scripts/creaturescripts/others/login.lua +++ b/data-otservbr-global/scripts/creaturescripts/others/login.lua @@ -208,7 +208,7 @@ function playerLogin.onLogin(player) player:initializeLoyaltySystem() -- Stamina - nextUseStaminaTime[playerId] = 1 + _G.NextUseStaminaTime[playerId] = 1 -- EXP Stamina nextUseXpStamina[playerId] = 1 diff --git a/data-otservbr-global/scripts/creaturescripts/others/logout.lua b/data-otservbr-global/scripts/creaturescripts/others/logout.lua index 314246a981a..eb68a47cf3f 100644 --- a/data-otservbr-global/scripts/creaturescripts/others/logout.lua +++ b/data-otservbr-global/scripts/creaturescripts/others/logout.lua @@ -2,8 +2,8 @@ local playerLogout = CreatureEvent("PlayerLogout") function playerLogout.onLogout(player) local playerId = player:getId() - if nextUseStaminaTime[playerId] ~= nil then - nextUseStaminaTime[playerId] = nil + if _G.NextUseStaminaTime[playerId] ~= nil then + _G.NextUseStaminaTime[playerId] = nil end player:saveSpecialStorage() diff --git a/data/events/scripts/player.lua b/data/events/scripts/player.lua index 333d506919d..a8649d5b08e 100644 --- a/data/events/scripts/player.lua +++ b/data/events/scripts/player.lua @@ -96,7 +96,7 @@ local soulCondition = Condition(CONDITION_SOUL, CONDITIONID_DEFAULT) soulCondition:setTicks(4 * 60 * 1000) soulCondition:setParameter(CONDITION_PARAM_SOULGAIN, 1) -local function useStamina(player) +local function useStamina(player, isStaminaEnabled) if not player then return false end @@ -107,12 +107,12 @@ local function useStamina(player) end local playerId = player:getId() - if not playerId or not nextUseStaminaTime[playerId] then + if not playerId or not _G.NextUseStaminaTime[playerId] then return false end local currentTime = os.time() - local timePassed = currentTime - nextUseStaminaTime[playerId] + local timePassed = currentTime - _G.NextUseStaminaTime[playerId] if timePassed <= 0 then return end @@ -123,14 +123,16 @@ local function useStamina(player) else staminaMinutes = 0 end - nextUseStaminaTime[playerId] = currentTime + 120 + _G.NextUseStaminaTime[playerId] = currentTime + 120 player:removePreyStamina(120) else staminaMinutes = staminaMinutes - 1 - nextUseStaminaTime[playerId] = currentTime + 60 + _G.NextUseStaminaTime[playerId] = currentTime + 60 player:removePreyStamina(60) end - player:setStamina(staminaMinutes) + if isStaminaEnabled then + player:setStamina(staminaMinutes) + end end local function useStaminaXpBoost(player) @@ -514,8 +516,9 @@ function Player:onGainExperience(target, exp, rawExp) -- Stamina Bonus local staminaBonusXp = 1 - if configManager.getBoolean(configKeys.STAMINA_SYSTEM) then - useStamina(self) + local isStaminaEnabled = configManager.getBoolean(configKeys.STAMINA_SYSTEM) + useStamina(self, isStaminaEnabled) + if isStaminaEnabled then staminaBonusXp = self:getFinalBonusStamina() self:setStaminaXpBoost(staminaBonusXp * 100) end diff --git a/data/global.lua b/data/global.lua index 9fad23e8787..7a26302b345 100644 --- a/data/global.lua +++ b/data/global.lua @@ -105,8 +105,8 @@ if onExerciseTraining == nil then end -- Stamina -if nextUseStaminaTime == nil then - nextUseStaminaTime = {} +if not _G.NextUseStaminaTime then + _G.NextUseStaminaTime = {} end if nextUseXpStamina == nil then