From 372bc536fd1ac3d14d1acc7d1f3aeff3b3faccbe Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Sun, 18 Feb 2024 15:51:39 -0300 Subject: [PATCH 1/5] fix: achievement migration --- ...0231128213358_move_hireling_data_to_kv.lua | 0 .../20241708000535_move_achievement_to_kv.lua | 39 +++++++++++++++++++ .../20241708000535_move_achievement_to_kv.lua | 20 ---------- data/scripts/lib/register_achievements.lua | 9 +++-- src/game/game.cpp | 4 +- .../creatures/player/player_functions.cpp | 4 +- src/server/network/protocol/protocolgame.cpp | 2 + 7 files changed, 50 insertions(+), 28 deletions(-) rename data-otservbr-global/scripts/{globalevents => }/game_migrations/20231128213358_move_hireling_data_to_kv.lua (100%) create mode 100644 data-otservbr-global/scripts/game_migrations/20241708000535_move_achievement_to_kv.lua delete mode 100644 data-otservbr-global/scripts/globalevents/game_migrations/20241708000535_move_achievement_to_kv.lua diff --git a/data-otservbr-global/scripts/globalevents/game_migrations/20231128213358_move_hireling_data_to_kv.lua b/data-otservbr-global/scripts/game_migrations/20231128213358_move_hireling_data_to_kv.lua similarity index 100% rename from data-otservbr-global/scripts/globalevents/game_migrations/20231128213358_move_hireling_data_to_kv.lua rename to data-otservbr-global/scripts/game_migrations/20231128213358_move_hireling_data_to_kv.lua 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 new file mode 100644 index 00000000000..236284e19cc --- /dev/null +++ b/data-otservbr-global/scripts/game_migrations/20241708000535_move_achievement_to_kv.lua @@ -0,0 +1,39 @@ +local achievementProgressStorage = 20000 +local achievementStorage = 30000 + +local function migrateAchievementProgress(player) + for id, achievement in pairs(ACHIEVEMENTS) do + local oldStorageKey = achievementProgressStorage + id + local progressNumber = player:getStorageValue(oldStorageKey) + if progressNumber > 0 then + local achievScopeName = tostring(foundAchievement.name .. "-progress") + player:kv():scoped(achievScopeName, progressNumber) + player:setStorageValue(oldStorageKey, -1) + end + local oldAchievement = player:getStorageValue(achievementStorage + id) + if oldAchievement > 0 then + player:addAchievement(achievement.name) + player:setStorageValue(achievementStorage + id, -1) + end + end + local points = 0 + local list = player:getAchievements() + if #list > 0 then + for i = 1, #list do + local a = Game.getAchievementInfoById(list[i]) + if a.points > 0 then + points = points + a.points + end + end + end + + player:addAchievementPoints(points) +end + +local migration = Migration("20241708275600_move_achievement_to_kv") + +function migration:onExecute() + self:forEachPlayer(migrateAchievementProgress) +end + +migration:register() diff --git a/data-otservbr-global/scripts/globalevents/game_migrations/20241708000535_move_achievement_to_kv.lua b/data-otservbr-global/scripts/globalevents/game_migrations/20241708000535_move_achievement_to_kv.lua deleted file mode 100644 index 1efd61e3e10..00000000000 --- a/data-otservbr-global/scripts/globalevents/game_migrations/20241708000535_move_achievement_to_kv.lua +++ /dev/null @@ -1,20 +0,0 @@ -local achievementStorage = 20000 - -local function migrateAchievementProgress(player) - for id, achievement in pairs(ACHIEVEMENTS) do - local oldStorageKey = achievementStorage + id - local progressNumber = player:getStorageValue(oldStorageKey) - if progressNumber > 0 then - player:kv():scoped("achievements"):set("progress", progressNumber) - player:setStorageValue(oldStorageKey, -1) - end - end -end - -local migration = Migration("20241708000535_move_achievement_to_kv") - -function migration:onExecute() - self:forEachPlayer(migrateAchievementProgress) -end - -migration:register() diff --git a/data/scripts/lib/register_achievements.lua b/data/scripts/lib/register_achievements.lua index 4d644590bba..a1a8ae02d6d 100644 --- a/data/scripts/lib/register_achievements.lua +++ b/data/scripts/lib/register_achievements.lua @@ -483,6 +483,7 @@ ACHIEVEMENTS = { [482] = { name = "Dream Catcher", grade = 1, points = 3, description = "You are the slayer of the ancient nightmare beast and prevented the nightmare to spread its madness." }, [483] = { name = "Champion of Summer", grade = 1, points = 2, secret = true, description = "You have vanquished numerous arena champions in the name of the Summer Court." }, [484] = { name = "Champion of Winter", grade = 1, points = 2, secret = true, description = "You have vanquished numerous arena champions in the name of the Winter Court." }, + [485] = { name = "Allow Cookies?", grade = 2, points = 6, description = "With a perfectly harmless smile, you tricked all the funny guys into eating your exploding cookies. Next time you pull this prank, consider wearing a Boy Scout outfit to make it even better." }, [486] = { name = "Bewitcher", grade = 2, points = 5, secret = true, description = "You literally put everything in that cauldron except lilac and gooseberries." }, [487] = { name = "Gryphon Rider", grade = 1, points = 3, description = "Unmasking spies, killing demons, discovering omens, solving puzzles and fighting ogres, manticores and feral sphinxes. - Nobody said it was easy to become a gryphon rider." }, [488] = { name = "Sculptor Apprentice", grade = 1, points = 2, secret = true, description = "Granted, you didn't carve those lifelike animal figurines yourself. But helping a medusa to find proper objects and even watching her using her petrifying gaze is almost as rewarding." }, @@ -644,14 +645,14 @@ function Player.addAchievementProgress(self, achievement, totalProgress) local achievScope = self:kv():scoped("achievements") local achievScopeName = tostring(foundAchievement.name .. "-progress") local progressNumber = achievScope:get(achievScopeName) or 0 - - if progressNumber + 1 == totalProgress then + local newProgress = progressNumber + 1 + 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, progressNumber + 1, totalProgress) - achievScope:set(achievScopeName, progressNumber + 1) + logger.debug("[Player.addAchievementProgress] - Achievement '{}' progress updated to '{}', total progress '{}'", foundAchievement.name, newProgress, totalProgress) + achievScope:set(achievScopeName, newProgress) end diff --git a/src/game/game.cpp b/src/game/game.cpp index 03e19e50075..ce8358fe7f2 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -207,7 +207,7 @@ Game::Game() { // Create instance of IOWheel to Game class m_IOWheel = std::make_unique(); - std::unordered_map m_highscoreCategoriesNames = { + m_highscoreCategoriesNames = { { static_cast(HighscoreCategories_t::ACHIEVEMENTS), "Achievement Points" }, { static_cast(HighscoreCategories_t::AXE_FIGHTING), "Axe Fighting" }, { static_cast(HighscoreCategories_t::CHARMS), "Charm Points" }, @@ -224,7 +224,7 @@ Game::Game() { { static_cast(HighscoreCategories_t::SWORD_FIGHTING), "Sword Fighting" }, }; - std::vector m_highscoreCategories = { + m_highscoreCategories = { HighscoreCategory("Experience Points", static_cast(HighscoreCategories_t::EXPERIENCE)), HighscoreCategory("Fist Fighting", static_cast(HighscoreCategories_t::FIST_FIGHTING)), HighscoreCategory("Club Fighting", static_cast(HighscoreCategories_t::CLUB_FIGHTING)), diff --git a/src/lua/functions/creatures/player/player_functions.cpp b/src/lua/functions/creatures/player/player_functions.cpp index 17a550bad9d..90e9e721618 100644 --- a/src/lua/functions/creatures/player/player_functions.cpp +++ b/src/lua/functions/creatures/player/player_functions.cpp @@ -4237,7 +4237,7 @@ int PlayerFunctions::luaPlayerRemoveAchievement(lua_State* L) { } int PlayerFunctions::luaPlayerGetAchievementPoints(lua_State* L) { - // player:getAchievementsPoints() + // player:getAchievementPoints() const auto &player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); @@ -4249,7 +4249,7 @@ int PlayerFunctions::luaPlayerGetAchievementPoints(lua_State* L) { } int PlayerFunctions::luaPlayerAddAchievementPoints(lua_State* L) { - // player:addAchievementsPoints(amount) + // player:addAchievementPoints(amount) const auto &player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); diff --git a/src/server/network/protocol/protocolgame.cpp b/src/server/network/protocol/protocolgame.cpp index 18b5a14c228..15ed659a0d9 100644 --- a/src/server/network/protocol/protocolgame.cpp +++ b/src/server/network/protocol/protocolgame.cpp @@ -2161,7 +2161,9 @@ void ProtocolGame::sendHighscores(const std::vector &charact uint8_t selectedCategory = 0; const auto &highscoreCategories = g_game().getHighscoreCategories(); msg.addByte(highscoreCategories.size()); // Category Count + g_logger().debug("[ProtocolGame::sendHighscores] - Category Count: {}", highscoreCategories.size()); for (const HighscoreCategory &category : highscoreCategories) { + g_logger().debug("[ProtocolGame::sendHighscores] - Category: {} - Name: {}", category.m_id, category.m_name); msg.addByte(category.m_id); // Category Id msg.addString(category.m_name, "ProtocolGame::sendHighscores - category.name"); // Category Name if (category.m_id == categoryId) { From 9811c6e5b884832ebc7e6e958e3c3dac528eabde Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Sun, 18 Feb 2024 17:27:59 -0300 Subject: [PATCH 2/5] 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) From e3078dbdab239b2d3e0e9655787650e111c0de88 Mon Sep 17 00:00:00 2001 From: Elson Costa Date: Tue, 20 Feb 2024 12:22:15 -0300 Subject: [PATCH 3/5] Fixed migration filename and moved '20241708362079_move_vip_system_to_kv.lua' into new folder. --- .../game_migrations/20241708000535_move_achievement_to_kv.lua | 2 +- .../game_migrations/20241708362079_move_vip_system_to_kv.lua | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename data-otservbr-global/scripts/{globalevents => }/game_migrations/20241708362079_move_vip_system_to_kv.lua (100%) 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 83a53762f74..5adbefbf9a8 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 @@ -30,7 +30,7 @@ local function migrateAchievementProgress(player) player:addAchievementPoints(points) end -local migration = Migration("20241708275600_move_achievement_to_kv") +local migration = Migration("20241708000535_move_achievement_to_kv") function migration:onExecute() self:forEachPlayer(migrateAchievementProgress) diff --git a/data-otservbr-global/scripts/globalevents/game_migrations/20241708362079_move_vip_system_to_kv.lua b/data-otservbr-global/scripts/game_migrations/20241708362079_move_vip_system_to_kv.lua similarity index 100% rename from data-otservbr-global/scripts/globalevents/game_migrations/20241708362079_move_vip_system_to_kv.lua rename to data-otservbr-global/scripts/game_migrations/20241708362079_move_vip_system_to_kv.lua From 76e4866650bc0bee44296fc9c7f6474384cba6ce Mon Sep 17 00:00:00 2001 From: Elson Costa Date: Wed, 21 Feb 2024 00:49:12 -0300 Subject: [PATCH 4/5] Created new migration '20241708485868_move_some_storages_to_kv.lua'. --- ...0241708485868_move_some_storages_to_kv.lua | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 data-otservbr-global/scripts/game_migrations/20241708485868_move_some_storages_to_kv.lua diff --git a/data-otservbr-global/scripts/game_migrations/20241708485868_move_some_storages_to_kv.lua b/data-otservbr-global/scripts/game_migrations/20241708485868_move_some_storages_to_kv.lua new file mode 100644 index 00000000000..41c6c8056b4 --- /dev/null +++ b/data-otservbr-global/scripts/game_migrations/20241708485868_move_some_storages_to_kv.lua @@ -0,0 +1,24 @@ +local oldAutolootStorage = 30063 +local flasksStorage = 'talkaction.potions.flask' + +local function migrate(player) + local isAutoLoot = player:getStorageValue(oldAutolootStorage) + if isAutoLoot > 0 then + player:setFeature(Features.AutoLoot, 1) + player:setStorageValue(oldAutolootStorage, -1) + end + + local getOldFlasksStorage = player:getStorageValueByName(flasksStorage) + if getOldFlasksStorage > 0 then + player:kv():set("talkaction.potions.flask", true) + player:setStorageValueByName(flasksStorage, -1) + end +end + +local migration = Migration("20241708485868_move_some_storages_to_kv") + +function migration:onExecute() + self:forEachPlayer(migrate) +end + +migration:register() From 7945ac8e022be97ac10a37c6efb264feb0ba34b6 Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Wed, 21 Feb 2024 03:49:52 +0000 Subject: [PATCH 5/5] Lua code format - (Stylua) --- .../game_migrations/20241708485868_move_some_storages_to_kv.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data-otservbr-global/scripts/game_migrations/20241708485868_move_some_storages_to_kv.lua b/data-otservbr-global/scripts/game_migrations/20241708485868_move_some_storages_to_kv.lua index 41c6c8056b4..382df257de8 100644 --- a/data-otservbr-global/scripts/game_migrations/20241708485868_move_some_storages_to_kv.lua +++ b/data-otservbr-global/scripts/game_migrations/20241708485868_move_some_storages_to_kv.lua @@ -1,5 +1,5 @@ local oldAutolootStorage = 30063 -local flasksStorage = 'talkaction.potions.flask' +local flasksStorage = "talkaction.potions.flask" local function migrate(player) local isAutoLoot = player:getStorageValue(oldAutolootStorage)