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..5adbefbf9a8 --- /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(achievement.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("20241708000535_move_achievement_to_kv") + +function migration:onExecute() + self:forEachPlayer(migrateAchievementProgress) +end + +migration:register() 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 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..382df257de8 --- /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() 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..b906afd287a 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,16 @@ 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 + local newProgress = progressNumber + 1 + if newProgress > totalProgress then + return + end - if progressNumber + 1 == totalProgress then + 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) {