Skip to content

Commit

Permalink
refactor achievement-related functions in Player class
Browse files Browse the repository at this point in the history
  • Loading branch information
omarcopires committed Dec 12, 2023
1 parent e3327fd commit 505555f
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions data/lib/core/achievements.lua
Original file line number Diff line number Diff line change
Expand Up @@ -683,18 +683,19 @@ function isAchievementSecret(ach)
end

function Player.hasAchievement(self, ach)
local achievement
if tonumber(ach) then
achievement = getAchievementInfoById(ach)
else
achievement = getAchievementInfoByName(ach)
end
local achievement = tonumber(ach) and getAchievementInfoById(ach) or getAchievementInfoByName(ach)
if not achievement then
print("[!] -> Invalid achievement \"" .. ach .. "\".")
print("[Warning - Player.hasAchievement] Attempt to check for an invalid achievement (ID or Name): " .. tostring(ach))
return false
end

local achievementId = achievement.id
if not achievementId then
print("[Error - Player.hasAchievement] Missing achievement ID for \"" .. tostring(ach) .. "\". This may indicate a problem in the achievements configuration.")
return false
end

return self:getStorageValue(PlayerStorageKeys.achievementsBase + achievement.id) > 0
return self:getStorageValue(PlayerStorageKeys.achievementsBase + achievementId) and true or false
end

function Player.getAchievements(self)
Expand Down

0 comments on commit 505555f

Please sign in to comment.