Skip to content

Commit

Permalink
fix: infinity prey time if stamina system is disabled (#1873)
Browse files Browse the repository at this point in the history
Resolves #518
  • Loading branch information
dudantas authored Nov 22, 2023
1 parent 1be3b43 commit fd0602a
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 17 deletions.
4 changes: 2 additions & 2 deletions data-canary/scripts/creaturescripts/login.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function login.onLogin(player)
end

-- Stamina
nextUseStaminaTime[player.uid] = 0
_G.NextUseStaminaTime[player.uid] = 0

-- Promotion
local vocation = player:getVocation()
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions data-canary/scripts/creaturescripts/logout.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ function playerLogin.onLogin(player)
player:initializeLoyaltySystem()

-- Stamina
nextUseStaminaTime[playerId] = 1
_G.NextUseStaminaTime[playerId] = 1

-- EXP Stamina
nextUseXpStamina[playerId] = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
19 changes: 11 additions & 8 deletions data/events/scripts/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions data/global.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fd0602a

Please sign in to comment.