Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: hazard level up #1883

Merged
merged 5 commits into from
Nov 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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