From b3a85eee3622fc9eceafed96c1f45ce77e1fe403 Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Thu, 28 Dec 2023 22:38:38 -0800 Subject: [PATCH] improve: migrate part of daily reward to KV (#2006) Started moving daily reward to KV since it's easier to share that between lua/cpp and it's the direction the project is going. Co-authored-by: Elson Costa --- data/libs/daily_reward/player.lua | 4 ++-- .../scripts/daily_reward/daily_reward.lua | 1 - src/creatures/combat/condition.cpp | 12 ++++++------ src/server/network/protocol/protocolgame.cpp | 16 ++++++++-------- src/utils/const.hpp | 1 - 5 files changed, 16 insertions(+), 18 deletions(-) diff --git a/data/libs/daily_reward/player.lua b/data/libs/daily_reward/player.lua index 671f4d118ff..2635e7d377b 100644 --- a/data/libs/daily_reward/player.lua +++ b/data/libs/daily_reward/player.lua @@ -23,11 +23,11 @@ function Player.setDayStreak(self, value) end function Player.getStreakLevel(self) - return math.max(self:getStorageValue(DailyReward.storages.currentStreakLevel), 0) + return self:kv():scoped("daily-reward"):get("streak") or 7 end function Player.setStreakLevel(self, value) - self:setStorageValue(DailyReward.storages.currentStreakLevel, value) + self:kv():scoped("daily-reward"):set("streak", value) end function Player.setNextRewardTime(self, value) diff --git a/data/modules/scripts/daily_reward/daily_reward.lua b/data/modules/scripts/daily_reward/daily_reward.lua index 270aa3189da..177b23cc90b 100644 --- a/data/modules/scripts/daily_reward/daily_reward.lua +++ b/data/modules/scripts/daily_reward/daily_reward.lua @@ -80,7 +80,6 @@ DailyReward = { storages = { -- Player currentDayStreak = 14897, - currentStreakLevel = 14898, -- Cpp uses the same storage value on const.h (STORAGEVALUE_DAILYREWARD) nextRewardTime = 14899, collectionTokens = 14901, staminaBonus = 14902, diff --git a/src/creatures/combat/condition.cpp b/src/creatures/combat/condition.cpp index 2320ad99ee3..8b8ddff7ca4 100644 --- a/src/creatures/combat/condition.cpp +++ b/src/creatures/combat/condition.cpp @@ -1165,16 +1165,16 @@ bool ConditionRegeneration::executeCondition(std::shared_ptr creature, internalHealthTicks += interval; internalManaTicks += interval; auto player = creature->getPlayer(); - int32_t PlayerdailyStreak = 0; + int32_t dailyStreak = 0; if (player) { - PlayerdailyStreak = player->getStorageValue(STORAGEVALUE_DAILYREWARD); + dailyStreak = static_cast(player->kv()->scoped("daily-reward")->get("streak")->getNumber()); } - if (creature->getZoneType() != ZONE_PROTECTION || PlayerdailyStreak >= DAILY_REWARD_HP_REGENERATION) { + if (creature->getZoneType() != ZONE_PROTECTION || dailyStreak >= DAILY_REWARD_HP_REGENERATION) { if (internalHealthTicks >= getHealthTicks(creature)) { internalHealthTicks = 0; int32_t realHealthGain = creature->getHealth(); - if (creature->getZoneType() == ZONE_PROTECTION && PlayerdailyStreak >= DAILY_REWARD_DOUBLE_HP_REGENERATION) { + if (creature->getZoneType() == ZONE_PROTECTION && dailyStreak >= DAILY_REWARD_DOUBLE_HP_REGENERATION) { creature->changeHealth(healthGain * 2); // Double regen from daily reward } else { creature->changeHealth(healthGain); @@ -1205,10 +1205,10 @@ bool ConditionRegeneration::executeCondition(std::shared_ptr creature, } } - if (creature->getZoneType() != ZONE_PROTECTION || PlayerdailyStreak >= DAILY_REWARD_MP_REGENERATION) { + if (creature->getZoneType() != ZONE_PROTECTION || dailyStreak >= DAILY_REWARD_MP_REGENERATION) { if (internalManaTicks >= getManaTicks(creature)) { internalManaTicks = 0; - if (creature->getZoneType() == ZONE_PROTECTION && PlayerdailyStreak >= DAILY_REWARD_DOUBLE_MP_REGENERATION) { + if (creature->getZoneType() == ZONE_PROTECTION && dailyStreak >= DAILY_REWARD_DOUBLE_MP_REGENERATION) { creature->changeMana(manaGain * 2); // Double regen from daily reward } else { creature->changeMana(manaGain); diff --git a/src/server/network/protocol/protocolgame.cpp b/src/server/network/protocol/protocolgame.cpp index 1b55e3e94fa..313bec0d9a4 100644 --- a/src/server/network/protocol/protocolgame.cpp +++ b/src/server/network/protocol/protocolgame.cpp @@ -5735,29 +5735,29 @@ void ProtocolGame::sendRestingStatus(uint8_t protection) { NetworkMessage msg; msg.addByte(0xA9); msg.addByte(protection); // 1 / 0 - int32_t PlayerdailyStreak = player->getStorageValue(STORAGEVALUE_DAILYREWARD); - msg.addByte(PlayerdailyStreak < 2 ? 0 : 1); - if (PlayerdailyStreak < 2) { + int32_t dailyStreak = static_cast(player->kv()->scoped("daily-reward")->get("streak")->getNumber()); + msg.addByte(dailyStreak < 2 ? 0 : 1); + if (dailyStreak < 2) { msg.addString("Resting Area (no active bonus)", "ProtocolGame::sendRestingStatus - Resting Area (no active bonus)"); } else { std::ostringstream ss; ss << "Active Resting Area Bonuses: "; - if (PlayerdailyStreak < DAILY_REWARD_DOUBLE_HP_REGENERATION) { + if (dailyStreak < DAILY_REWARD_DOUBLE_HP_REGENERATION) { ss << "\nHit Points Regeneration"; } else { ss << "\nDouble Hit Points Regeneration"; } - if (PlayerdailyStreak >= DAILY_REWARD_MP_REGENERATION) { - if (PlayerdailyStreak < DAILY_REWARD_DOUBLE_MP_REGENERATION) { + if (dailyStreak >= DAILY_REWARD_MP_REGENERATION) { + if (dailyStreak < DAILY_REWARD_DOUBLE_MP_REGENERATION) { ss << ",\nMana Points Regeneration"; } else { ss << ",\nDouble Mana Points Regeneration"; } } - if (PlayerdailyStreak >= DAILY_REWARD_STAMINA_REGENERATION) { + if (dailyStreak >= DAILY_REWARD_STAMINA_REGENERATION) { ss << ",\nStamina Points Regeneration"; } - if (PlayerdailyStreak >= DAILY_REWARD_SOUL_REGENERATION) { + if (dailyStreak >= DAILY_REWARD_SOUL_REGENERATION) { ss << ",\nSoul Points Regeneration"; } ss << "."; diff --git a/src/utils/const.hpp b/src/utils/const.hpp index b9020a177f7..f86ec7aec7b 100644 --- a/src/utils/const.hpp +++ b/src/utils/const.hpp @@ -28,7 +28,6 @@ static constexpr uint8_t IMBUEMENT_MAX_TIER = 3; static constexpr int32_t STORAGEVALUE_EMOTE = 30008; static constexpr int32_t STORAGEVALUE_PODIUM = 30020; static constexpr int32_t STORAGEVALUE_AUTO_LOOT = 30063; -static constexpr int32_t STORAGEVALUE_DAILYREWARD = 14898; static constexpr int32_t STORAGEVALUE_BESTIARYKILLCOUNT = 61305000; // Can get up to 2000 storages! // Hazard system storage