Skip to content

Commit

Permalink
fix: hazard level up (opentibiabr#1883)
Browse files Browse the repository at this point in the history
Fixes a typo in level up function as well as simplified levelUp
function.
Also set maxLevel base as 1 to handle nil values in getPlayerMaxLevel
  • Loading branch information
sebbesiren authored Nov 23, 2023
1 parent 0fe949c commit b9cf8e1
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions data/libs/hazard_lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -88,30 +88,22 @@ function Hazard:getPlayerMaxLevel(player)
local fromStorage = player:getStorageValue(self.storageMax)
return fromStorage <= 0 and 1 or fromStorage
end
local fromKV = player:kv():scoped(self.name):get("maxLevel")
local fromKV = player:kv():scoped(self.name):get("maxLevel") or 1

return fromKV <= 0 and 1 or fromKV
end

function Hazard:levelUp(player)
if self.storageMax and self.storageCurrent then
local current = self:getPlayerCurrentLevel(player)
local max = self:getPlayerMaxLevel(player)
if current == max then
self:setPlayerMaxLevel(player, max + 1)
end
return
end

local current = player:kv(self.name):get("currentLevel")
local max = player:kv(self.name):get("maxLevel")
local current = self:getPlayerCurrentLevel(player)
local max = self:getPlayerMaxLevel(player)
if current == max then
player:kv(self.name):set("maxLevel", max + 1)
self:setPlayerMaxLevel(player, max + 1)
end
end

function Hazard:setPlayerMaxLevel(player, level)
if level > self.maxLevelLevel then
level = self.maxLevelLevel
if level > self.maxLevel then
level = self.maxLevel
end

if self.storageMax then
Expand Down

0 comments on commit b9cf8e1

Please sign in to comment.