diff --git a/data-otservbr-global/scripts/game_migrations/20241715984279_move_wheel_scrolls_from_storagename_to_kv.lua b/data-otservbr-global/scripts/game_migrations/20241715984279_move_wheel_scrolls_from_storagename_to_kv.lua new file mode 100644 index 00000000000..a5cc9a123f4 --- /dev/null +++ b/data-otservbr-global/scripts/game_migrations/20241715984279_move_wheel_scrolls_from_storagename_to_kv.lua @@ -0,0 +1,24 @@ +local promotionScrolls = { + { oldScroll = "wheel.scroll.abridged", newScroll = "abridged" }, + { oldScroll = "wheel.scroll.basic", newScroll = "basic" }, + { oldScroll = "wheel.scroll.revised", newScroll = "revised" }, + { oldScroll = "wheel.scroll.extended", newScroll = "extended" }, + { oldScroll = "wheel.scroll.advanced", newScroll = "advanced" }, +} + +local function migrate(player) + for _, scrollTable in ipairs(promotionScrolls) do + local oldStorage = player:getStorageValueByName(scrollTable.oldScroll) + if oldStorage > 0 then + player:kv():scoped("wheel-of-destiny"):scoped("scrolls"):set(scrollTable.newScroll, true) + end + end +end + +local migration = Migration("20241715984279_move_wheel_scrolls_from_storagename_to_kv") + +function migration:onExecute() + self:forEachPlayer(migrate) +end + +migration:register() diff --git a/data/scripts/actions/items/wheel_scrolls.lua b/data/scripts/actions/items/wheel_scrolls.lua index b42339a706e..61aaa6fe40a 100644 --- a/data/scripts/actions/items/wheel_scrolls.lua +++ b/data/scripts/actions/items/wheel_scrolls.lua @@ -1,9 +1,9 @@ local promotionScrolls = { - [43946] = { storageName = "wheel.scroll.abridged", points = 3, name = "abridged promotion scroll" }, - [43947] = { storageName = "wheel.scroll.basic", points = 5, name = "basic promotion scroll" }, - [43948] = { storageName = "wheel.scroll.revised", points = 9, name = "revised promotion scroll" }, - [43949] = { storageName = "wheel.scroll.extended", points = 13, name = "extended promotion scroll" }, - [43950] = { storageName = "wheel.scroll.advanced", points = 20, name = "advanced promotion scroll" }, + [43946] = { name = "abridged", points = 3, itemName = "abridged promotion scroll" }, + [43947] = { name = "basic", points = 5, itemName = "basic promotion scroll" }, + [43948] = { name = "revised", points = 9, itemName = "revised promotion scroll" }, + [43949] = { name = "extended", points = 13, itemName = "extended promotion scroll" }, + [43950] = { name = "advanced", points = 20, itemName = "advanced promotion scroll" }, } local scroll = Action() @@ -15,13 +15,14 @@ function scroll.onUse(player, item, fromPosition, target, toPosition, isHotkey) end local scrollData = promotionScrolls[item:getId()] - if player:getStorageValueByName(scrollData.storageName) == 1 then + local scrollKV = player:kv():scoped("wheel-of-destiny"):scoped("scrolls") + if scrollKV:get(scrollData.name) then player:sendTextMessage(MESSAGE_LOOK, "You have already deciphered this scroll.") return true end - player:setStorageValueByName(scrollData.storageName, 1) - player:sendTextMessage(MESSAGE_LOOK, "You have gained " .. scrollData.points .. " promotion points for the Wheel of Destiny by deciphering the " .. scrollData.name .. ".") + scrollKV:set(scrollData.name, true) + player:sendTextMessage(MESSAGE_LOOK, "You have gained " .. scrollData.points .. " promotion points for the Wheel of Destiny by deciphering the " .. scrollData.itemName .. ".") item:remove(1) return true end diff --git a/data/scripts/lib/register_migrations.lua b/data/scripts/lib/register_migrations.lua index 5a2734dfc51..26b9a7b1a94 100644 --- a/data/scripts/lib/register_migrations.lua +++ b/data/scripts/lib/register_migrations.lua @@ -45,7 +45,7 @@ function Migration:register() return end if not self:_validateName() then - error("Invalid migration name: " .. self.name .. ". Migration names must be in the format: _. Example: 20231128213149_add_new_monsters") + logger.error("Invalid migration name: " .. self.name .. ". Migration names must be in the format: _. Example: 20231128213149_add_new_monsters") end table.insert(Migration.registry, self) diff --git a/src/creatures/players/wheel/player_wheel.cpp b/src/creatures/players/wheel/player_wheel.cpp index c4fdbf5e169..4c7a3dc52e0 100644 --- a/src/creatures/players/wheel/player_wheel.cpp +++ b/src/creatures/players/wheel/player_wheel.cpp @@ -130,16 +130,16 @@ namespace { struct PromotionScroll { uint16_t itemId; - std::string storageKey; + std::string name; uint8_t extraPoints; }; std::vector WheelOfDestinyPromotionScrolls = { - { 43946, "wheel.scroll.abridged", 3 }, - { 43947, "wheel.scroll.basic", 5 }, - { 43948, "wheel.scroll.revised", 9 }, - { 43949, "wheel.scroll.extended", 13 }, - { 43950, "wheel.scroll.advanced", 20 }, + { 43946, "abridged", 3 }, + { 43947, "basic", 5 }, + { 43948, "revised", 9 }, + { 43949, "extended", 13 }, + { 43950, "advanced", 20 }, }; } // namespace @@ -744,18 +744,21 @@ int PlayerWheel::getSpellAdditionalDuration(const std::string &spellName) const } void PlayerWheel::addPromotionScrolls(NetworkMessage &msg) const { - uint16_t count = 0; std::vector unlockedScrolls; for (const auto &scroll : WheelOfDestinyPromotionScrolls) { - auto storageValue = m_player.getStorageValueByName(scroll.storageKey); - if (storageValue > 0) { - count++; + const auto &scrollKv = m_player.kv()->scoped("wheel-of-destiny")->scoped("scrolls"); + if (!scrollKv) { + continue; + } + + auto scrollOpt = scrollKv->get(scroll.name); + if (scrollOpt && scrollOpt->get()) { unlockedScrolls.push_back(scroll.itemId); } } - msg.add(count); + msg.add(unlockedScrolls.size()); for (const auto &itemId : unlockedScrolls) { msg.add(itemId); } @@ -1239,8 +1242,13 @@ uint16_t PlayerWheel::getExtraPoints() const { uint16_t totalBonus = 0; for (const auto &scroll : WheelOfDestinyPromotionScrolls) { - auto storageValue = m_player.getStorageValueByName(scroll.storageKey); - if (storageValue > 0) { + const auto &scrollKv = m_player.kv()->scoped("wheel-of-destiny")->scoped("scrolls"); + if (!scrollKv) { + continue; + } + + auto scrollKV = scrollKv->get(scroll.name); + if (scrollKV && scrollKV->get()) { totalBonus += scroll.extraPoints; } } diff --git a/src/lua/functions/creatures/player/player_functions.cpp b/src/lua/functions/creatures/player/player_functions.cpp index 50774e35e2a..413f1bd3f47 100644 --- a/src/lua/functions/creatures/player/player_functions.cpp +++ b/src/lua/functions/creatures/player/player_functions.cpp @@ -1767,6 +1767,7 @@ int PlayerFunctions::luaPlayerGetStorageValueByName(lua_State* L) { return 0; } + g_logger().warn("The function 'player:getStorageValueByName' is deprecated and will be removed in future versions, please use KV system"); auto name = getString(L, 2); lua_pushnumber(L, player->getStorageValueByName(name)); return 1; @@ -1781,6 +1782,7 @@ int PlayerFunctions::luaPlayerSetStorageValueByName(lua_State* L) { return 0; } + g_logger().warn("The function 'player:setStorageValueByName' is deprecated and will be removed in future versions, please use KV system"); auto storageName = getString(L, 2); int32_t value = getNumber(L, 3);