From 9811c6e5b884832ebc7e6e958e3c3dac528eabde Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Sun, 18 Feb 2024 17:27:59 -0300 Subject: [PATCH] fix: progress --- .../20241708000535_move_achievement_to_kv.lua | 2 +- data/scripts/lib/register_achievements.lua | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/data-otservbr-global/scripts/game_migrations/20241708000535_move_achievement_to_kv.lua b/data-otservbr-global/scripts/game_migrations/20241708000535_move_achievement_to_kv.lua index 236284e19cc..83a53762f74 100644 --- a/data-otservbr-global/scripts/game_migrations/20241708000535_move_achievement_to_kv.lua +++ b/data-otservbr-global/scripts/game_migrations/20241708000535_move_achievement_to_kv.lua @@ -6,7 +6,7 @@ local function migrateAchievementProgress(player) local oldStorageKey = achievementProgressStorage + id local progressNumber = player:getStorageValue(oldStorageKey) if progressNumber > 0 then - local achievScopeName = tostring(foundAchievement.name .. "-progress") + local achievScopeName = tostring(achievement.name .. "-progress") player:kv():scoped(achievScopeName, progressNumber) player:setStorageValue(oldStorageKey, -1) end diff --git a/data/scripts/lib/register_achievements.lua b/data/scripts/lib/register_achievements.lua index a1a8ae02d6d..b906afd287a 100644 --- a/data/scripts/lib/register_achievements.lua +++ b/data/scripts/lib/register_achievements.lua @@ -646,11 +646,13 @@ function Player.addAchievementProgress(self, achievement, totalProgress) local achievScopeName = tostring(foundAchievement.name .. "-progress") local progressNumber = achievScope:get(achievScopeName) or 0 local newProgress = progressNumber + 1 + if newProgress > totalProgress then + return + end + if newProgress == totalProgress then self:addAchievement(foundAchievement.id) logger.debug("[Player.addAchievementProgress] - Achievement '{}' completed", foundAchievement.name) - achievScope:remove(achievScopeName) - return end logger.debug("[Player.addAchievementProgress] - Achievement '{}' progress updated to '{}', total progress '{}'", foundAchievement.name, newProgress, totalProgress)