From a5dcb65881225dca721310d70371ff9be8e15c71 Mon Sep 17 00:00:00 2001 From: Luan Luciano Date: Fri, 29 Dec 2023 03:02:34 -0300 Subject: [PATCH 1/3] improve: upgrade from storage to kv in data/ (#1979) - upgrade from storage to kv --------- Co-authored-by: Luan Santos --- .../actions/other/exercise_training.lua | 5 ++- .../creaturescripts/familiar/on_death.lua | 2 +- .../creaturescripts/familiar/on_login.lua | 26 +++---------- data-otservbr-global/lib/core/storages.lua | 6 --- .../actions/other/exercise_training.lua | 5 ++- .../creaturescripts/familiar/on_death.lua | 2 +- .../creaturescripts/familiar/on_login.lua | 7 ++-- .../scripts/creaturescripts/others/login.lua | 13 ++++--- data/chatchannels/scripts/help.lua | 11 +++--- data/events/scripts/creature.lua | 14 +++---- data/events/scripts/player.lua | 3 +- data/libs/core/global_storage.lua | 5 --- data/libs/functions/player.lua | 7 ++-- data/npclib/npc_system/modules.lua | 39 ++++++++++--------- .../scripts/eventcallbacks/player/on_look.lua | 3 +- 15 files changed, 66 insertions(+), 82 deletions(-) diff --git a/data-canary/scripts/actions/other/exercise_training.lua b/data-canary/scripts/actions/other/exercise_training.lua index ecf414a8029..82d13962100 100644 --- a/data-canary/scripts/actions/other/exercise_training.lua +++ b/data-canary/scripts/actions/other/exercise_training.lua @@ -38,7 +38,8 @@ function exerciseTraining.onUse(player, item, fromPosition, target, toPosition, end end - if player:getStorageValue(Storage.IsTraining) > os.time() then + local hasExhaustion = player:kv():get("training-exhaustion") or 0 + if hasExhaustion > os.time() then player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "This exercise dummy can only be used after a 30 second cooldown.") return true end @@ -48,7 +49,7 @@ function exerciseTraining.onUse(player, item, fromPosition, target, toPosition, _G.OnExerciseTraining[playerId].event = addEvent(ExerciseEvent, 0, playerId, targetPos, item.itemid, targetId) _G.OnExerciseTraining[playerId].dummyPos = targetPos player:setTraining(true) - player:setStorageValue(Storage.IsTraining, os.time() + 30) + player:kv():set("training-exhaustion", os.time() + 30) end return true end diff --git a/data-canary/scripts/creaturescripts/familiar/on_death.lua b/data-canary/scripts/creaturescripts/familiar/on_death.lua index 02187ef20d9..47d3ba81839 100644 --- a/data-canary/scripts/creaturescripts/familiar/on_death.lua +++ b/data-canary/scripts/creaturescripts/familiar/on_death.lua @@ -9,7 +9,7 @@ function familiarOnDeath.onDeath(creature, corpse, lasthitkiller, mostdamagekill local vocation = FAMILIAR_ID[player:getVocation():getBaseId()] if table.contains(vocation, creature:getName()) then - player:setStorageValue(Global.Storage.FamiliarSummon, os.time()) + player:kv():set("familiar-summon-time", os.time()) for sendMessage = 1, #FAMILIAR_TIMER do stopEvent(player:getStorageValue(FAMILIAR_TIMER[sendMessage].storage)) player:setStorageValue(FAMILIAR_TIMER[sendMessage].storage, -1) diff --git a/data-canary/scripts/creaturescripts/familiar/on_login.lua b/data-canary/scripts/creaturescripts/familiar/on_login.lua index ca0371be77c..e264040dbf9 100644 --- a/data-canary/scripts/creaturescripts/familiar/on_login.lua +++ b/data-canary/scripts/creaturescripts/familiar/on_login.lua @@ -8,7 +8,8 @@ function familiarOnLogin.onLogin(player) local vocation = FAMILIAR_ID[player:getVocation():getBaseId()] local familiarName - local familiarTimeLeft = player:getStorageValue(Global.Storage.FamiliarSummon) - player:getLastLogout() + local familiarSummonTime = player:kv():get("familiar-summon-time") or 0 + local familiarTimeLeft = familiarSummonTime - player:getLastLogout() if vocation then if (not player:isPremium() and player:hasFamiliar(vocation.id)) or player:getLevel() < 200 then @@ -26,27 +27,10 @@ function familiarOnLogin.onLogin(player) end end - if familiarName then - local position = player:getPosition() - local familiarMonster = Game.createMonster(familiarName, position, true, false, player) - if familiarMonster then - familiarMonster:setOutfit({ lookType = player:getFamiliarLooktype() }) - familiarMonster:registerEvent("FamiliarDeath") - position:sendMagicEffect(CONST_ME_MAGIC_BLUE) - - local deltaSpeed = math.max(player:getSpeed() - familiarMonster:getSpeed(), 0) - familiarMonster:changeSpeed(deltaSpeed) - - player:setStorageValue(Global.Storage.FamiliarSummon, os.time() + familiarTimeLeft) - addEvent(RemoveFamiliar, familiarTimeLeft * 1000, familiarMonster:getId(), player:getId()) - - for sendMessage = 1, #FAMILIAR_TIMER do - if player:getStorageValue(FAMILIAR_TIMER[sendMessage].storage) == -1 and familiarTimeLeft >= FAMILIAR_TIMER[sendMessage].countdown then - player:setStorageValue(FAMILIAR_TIMER[sendMessage].storage, addEvent(SendMessageFunction, (familiarTimeLeft - FAMILIAR_TIMER[sendMessage].countdown) * 1000, player:getId(), FAMILIAR_TIMER[sendMessage].message)) - end - end - end + if not familiarName then + return true end + player:createFamiliar(familiarName, familiarTimeLeft) return true end diff --git a/data-otservbr-global/lib/core/storages.lua b/data-otservbr-global/lib/core/storages.lua index 12a7cdd33d1..10e5e305f63 100644 --- a/data-otservbr-global/lib/core/storages.lua +++ b/data-otservbr-global/lib/core/storages.lua @@ -79,8 +79,6 @@ Reserved player action storage key ranges (const.h) Storage = { -- General storages - IsTraining = 30000, - -- Reserved in Global.Storage.NpcExhaust = 30001 Dragonfetish = 30003, EdronRopeQuest = 30004, GhostShipQuest = 30005, @@ -102,10 +100,7 @@ Storage = { RookgaardDestiny = 30020, EruaranGreeting = 30021, MaryzaCookbook = 30022, - -- Reserved in Global.Storage.CombatProtectionStorage = 30023 Factions = 30024, - -- Reserved in Global.Storage.BlockMovementStorage = 30025 - -- Reserved in Global.Storage.FamiliarSummon = 30026 -- unused TrainerRoom = 30027, -- unused NpcSpawn = 30028, ExerciseDummyExhaust = 30029, @@ -130,7 +125,6 @@ Storage = { Navigator = 30048, DwarvenLegs = 30049, PrinceDrazzakTime = 30050, - -- Reserved in Global.Storage.StoreExaust = 30051 LemonCupcake = 30052, BlueberryCupcake = 30053, -- Reserved in Global.Storage.FamiliarSummonEvent10 = 30054 diff --git a/data-otservbr-global/scripts/actions/other/exercise_training.lua b/data-otservbr-global/scripts/actions/other/exercise_training.lua index e7f67c854be..616467aff56 100644 --- a/data-otservbr-global/scripts/actions/other/exercise_training.lua +++ b/data-otservbr-global/scripts/actions/other/exercise_training.lua @@ -54,7 +54,8 @@ function exerciseTraining.onUse(player, item, fromPosition, target, toPosition, end end - if player:getStorageValue(Storage.IsTraining) > os.time() then + local hasExhaustion = player:kv():get("training-exhaustion") or 0 + if hasExhaustion > os.time() then player:sendTextMessage(MESSAGE_FAILURE, "You are already training!") return true end @@ -64,7 +65,7 @@ function exerciseTraining.onUse(player, item, fromPosition, target, toPosition, _G.OnExerciseTraining[playerId].event = addEvent(ExerciseEvent, 0, playerId, targetPos, item.itemid, targetId) _G.OnExerciseTraining[playerId].dummyPos = targetPos player:setTraining(true) - player:setStorageValue(Storage.IsTraining, os.time() + cooldown) + player:kv():set("training-exhaustion", os.time() + cooldown) player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have started training on an exercise dummy.") end return true diff --git a/data-otservbr-global/scripts/creaturescripts/familiar/on_death.lua b/data-otservbr-global/scripts/creaturescripts/familiar/on_death.lua index 02187ef20d9..47d3ba81839 100644 --- a/data-otservbr-global/scripts/creaturescripts/familiar/on_death.lua +++ b/data-otservbr-global/scripts/creaturescripts/familiar/on_death.lua @@ -9,7 +9,7 @@ function familiarOnDeath.onDeath(creature, corpse, lasthitkiller, mostdamagekill local vocation = FAMILIAR_ID[player:getVocation():getBaseId()] if table.contains(vocation, creature:getName()) then - player:setStorageValue(Global.Storage.FamiliarSummon, os.time()) + player:kv():set("familiar-summon-time", os.time()) for sendMessage = 1, #FAMILIAR_TIMER do stopEvent(player:getStorageValue(FAMILIAR_TIMER[sendMessage].storage)) player:setStorageValue(FAMILIAR_TIMER[sendMessage].storage, -1) diff --git a/data-otservbr-global/scripts/creaturescripts/familiar/on_login.lua b/data-otservbr-global/scripts/creaturescripts/familiar/on_login.lua index 8e9c7fdbf81..e264040dbf9 100644 --- a/data-otservbr-global/scripts/creaturescripts/familiar/on_login.lua +++ b/data-otservbr-global/scripts/creaturescripts/familiar/on_login.lua @@ -8,12 +8,13 @@ function familiarOnLogin.onLogin(player) local vocation = FAMILIAR_ID[player:getVocation():getBaseId()] local familiarName - local familiarTimeLeft = player:getStorageValue(Global.Storage.FamiliarSummon) - player:getLastLogout() + local familiarSummonTime = player:kv():get("familiar-summon-time") or 0 + local familiarTimeLeft = familiarSummonTime - player:getLastLogout() if vocation then - if (not isPremium(player) and player:hasFamiliar(vocation.id)) or player:getLevel() < 200 then + if (not player:isPremium() and player:hasFamiliar(vocation.id)) or player:getLevel() < 200 then player:removeFamiliar(vocation.id) - elseif isPremium(player) and player:getLevel() >= 200 then + elseif player:isPremium() and player:getLevel() >= 200 then if familiarTimeLeft > 0 then familiarName = vocation.name end diff --git a/data-otservbr-global/scripts/creaturescripts/others/login.lua b/data-otservbr-global/scripts/creaturescripts/others/login.lua index 27bfddd5ddc..852e53c2a63 100644 --- a/data-otservbr-global/scripts/creaturescripts/others/login.lua +++ b/data-otservbr-global/scripts/creaturescripts/others/login.lua @@ -1,16 +1,16 @@ -local function onMovementRemoveProtection(cid, oldPos, time) - local player = Player(cid) +local function onMovementRemoveProtection(playerId, oldPos, time) + local player = Player(playerId) if not player then return true end local playerPos = player:getPosition() if (playerPos.x ~= oldPos.x or playerPos.y ~= oldPos.y or playerPos.z ~= oldPos.z) or player:getTarget() then - player:setStorageValue(Global.Storage.CombatProtectionStorage, 0) + player:kv():remove("combat-protection") return true end - addEvent(onMovementRemoveProtection, 1000, cid, oldPos, time - 1) + addEvent(onMovementRemoveProtection, 1000, playerId, oldPos, time - 1) end local function protectionZoneCheck(playerName) @@ -250,8 +250,9 @@ function playerLogin.onLogin(player) stats.playerId = player:getId() end - if player:getStorageValue(Global.Storage.CombatProtectionStorage) < 1 then - player:setStorageValue(Global.Storage.CombatProtectionStorage, 1) + local isProtected = player:kv():get("combat-protection") or 0 + if isProtected < 1 then + player:kv():set("combat-protection", 1) onMovementRemoveProtection(playerId, player:getPosition(), 10) end diff --git a/data/chatchannels/scripts/help.lua b/data/chatchannels/scripts/help.lua index a5d9e9fe53d..de51a575168 100644 --- a/data/chatchannels/scripts/help.lua +++ b/data/chatchannels/scripts/help.lua @@ -1,5 +1,4 @@ local CHANNEL_HELP = 7 -local storage = 456112 local muted = Condition(CONDITION_CHANNELMUTEDTICKS, CONDITIONID_DEFAULT) muted:setParameter(CONDITION_PARAM_SUBID, CHANNEL_HELP) @@ -12,7 +11,8 @@ function onSpeak(player, type, message) return false end - if player:getStorageValue(storage) > os.time() then + local hasExhaustion = player:kv():get("channel-help-exhaustion") or 0 + if hasExhaustion > os.time() then player:sendCancelMessage("You are muted from the Help channel for using it inappropriately.") return false end @@ -25,7 +25,7 @@ function onSpeak(player, type, message) if playerGroupType > target:getAccountType() then if not target:getCondition(CONDITION_CHANNELMUTEDTICKS, CONDITIONID_DEFAULT, CHANNEL_HELP) then target:addCondition(muted) - target:setStorageValue(storage, os.time() + 180) + target:kv():set("channel-help-exhaustion", os.time() + 180) -- 3 minutes sendChannelMessage(CHANNEL_HELP, TALKTYPE_CHANNEL_R1, target:getName() .. " has been muted by " .. player:getName() .. " for using Help Channel inappropriately.") else player:sendCancelMessage("That player is already muted.") @@ -42,10 +42,11 @@ function onSpeak(player, type, message) local target = Player(targetName) if target then if playerGroupType > target:getAccountType() then - if target:getStorageValue(storage) > os.time() then + local hasExhaustionTarget = target:kv():get("channel-help-exhaustion") or 0 + if hasExhaustionTarget > os.time() then target:removeCondition(CONDITION_CHANNELMUTEDTICKS, CONDITIONID_DEFAULT, CHANNEL_HELP) sendChannelMessage(CHANNEL_HELP, TALKTYPE_CHANNEL_R1, target:getName() .. " has been unmuted.") - target:setStorageValue(storage, -1) + target:kv():remove("channel-help-exhaustion") else player:sendCancelMessage("That player is not muted.") end diff --git a/data/events/scripts/creature.lua b/data/events/scripts/creature.lua index 4da8217988d..e7a74a33191 100644 --- a/data/events/scripts/creature.lua +++ b/data/events/scripts/creature.lua @@ -13,14 +13,14 @@ local function removeCombatProtection(playerUid) time = 30 end - player:setStorageValue(Global.Storage.CombatProtectionStorage, 2) + player:kv():set("combat-protection", 2) addEvent(function(playerFuncUid) local playerEvent = Player(playerFuncUid) if not playerEvent then return end - playerEvent:setStorageValue(Global.Storage.CombatProtectionStorage, 0) + playerEvent:kv():remove("combat-protection") playerEvent:remove() end, time * 1000, playerUid) end @@ -32,16 +32,16 @@ function Creature:onTargetCombat(target) if target:isPlayer() then if self:isMonster() then - local protectionStorage = target:getStorageValue(Global.Storage.CombatProtectionStorage) + local isProtected = target:kv():get("combat-protection") or 0 if target:getIp() == 0 then -- If player is disconnected, monster shall ignore to attack the player if target:isPzLocked() then return true end - if protectionStorage <= 0 then + if isProtected <= 0 then addEvent(removeCombatProtection, 30 * 1000, target.uid) - target:setStorageValue(Global.Storage.CombatProtectionStorage, 1) - elseif protectionStorage == 1 then + target:kv():set("combat-protection", 1) + elseif isProtected == 1 then self:searchTarget() return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER end @@ -49,7 +49,7 @@ function Creature:onTargetCombat(target) return true end - if protectionStorage >= os.time() then + if isProtected >= os.time() then return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER end end diff --git a/data/events/scripts/player.lua b/data/events/scripts/player.lua index cf78eeb2bc7..0a719401ed0 100644 --- a/data/events/scripts/player.lua +++ b/data/events/scripts/player.lua @@ -206,8 +206,9 @@ function Player:onLookInBattleList(creature, distance) local master = creature:getMaster() local summons = { "sorcerer familiar", "knight familiar", "druid familiar", "paladin familiar" } if master and table.contains(summons, creature:getName():lower()) then + local familiarSummonTime = master:kv():get("familiar-summon-time") or 0 description = description .. " (Master: " .. master:getName() .. "). \z - It will disappear in " .. getTimeInWords(master:getStorageValue(Global.Storage.FamiliarSummon) - os.time()) + It will disappear in " .. getTimeInWords(familiarSummonTime - os.time()) end end if self:getGroup():getAccess() then diff --git a/data/libs/core/global_storage.lua b/data/libs/core/global_storage.lua index 8576adc54a7..4119be5ebb6 100644 --- a/data/libs/core/global_storage.lua +++ b/data/libs/core/global_storage.lua @@ -23,11 +23,6 @@ Reserved player action storage key ranges (const.hpp) Global = { Storage = { - NpcExhaust = 30001, - CombatProtectionStorage = 30023, - BlockMovementStorage = 30025, - FamiliarSummon = 30026, - StoreExaust = 30051, FamiliarSummonEvent10 = 30054, FamiliarSummonEvent60 = 30055, }, diff --git a/data/libs/functions/player.lua b/data/libs/functions/player.lua index ce9c8177d9d..d494f35edd3 100644 --- a/data/libs/functions/player.lua +++ b/data/libs/functions/player.lua @@ -121,11 +121,12 @@ function Player.getCookiesDelivered(self) end function Player.allowMovement(self, allow) - return self:setStorageValue(Global.Storage.BlockMovementStorage, allow and -1 or 1) + return allow and self:kv():remove("block-movement") or self:kv():set("block-movement", 1) end function Player.hasAllowMovement(self) - return self:getStorageValue(Global.Storage.BlockMovementStorage) ~= 1 + local blockMovement = self:kv():get("block-movement") or 0 + return blockMovement ~= 1 end function Player.checkGnomeRank(self) @@ -431,7 +432,7 @@ function Player:createFamiliar(familiarName, timeLeft) playerPosition:sendMagicEffect(CONST_ME_MAGIC_BLUE) myFamiliar:getPosition():sendMagicEffect(CONST_ME_TELEPORT) -- Divide by 2 to get half the time (the default total time is 30 / 2 = 15) - self:setStorageValue(Global.Storage.FamiliarSummon, os.time() + timeLeft) + self:kv():set("familiar-summon-time", os.time() + timeLeft) addEvent(RemoveFamiliar, timeLeft * 1000, myFamiliar:getId(), self:getId()) for sendMessage = 1, #FAMILIAR_TIMER do self:setStorageValue( diff --git a/data/npclib/npc_system/modules.lua b/data/npclib/npc_system/modules.lua index 68fff0c39df..5e7db715080 100644 --- a/data/npclib/npc_system/modules.lua +++ b/data/npclib/npc_system/modules.lua @@ -223,27 +223,30 @@ if Modules == nil then npcHandler:say("First get rid of those blood stains! You are not going to ruin my vehicle!", npc, player) elseif not player:removeMoneyBank(cost) then npcHandler:say("You don't have enough money.", npc, player) - elseif os.time() < player:getStorageValue(Global.Storage.NpcExhaust) then - npcHandler:say("Sorry, but you need to wait three seconds before travel again.", player) - playerPosition:sendMagicEffect(CONST_ME_POFF) else - npcHandler:removeInteraction(npc, player) - npcHandler:say(parameters.text or "Set the sails!", npc, player) - - local destination = parameters.destination - if type(destination) == "function" then - destination = destination(player) - end + local hasExhaustion = player:kv():get("npc-exhaustion") or 0 + if hasExhaustion > os.time() then + npcHandler:say("Sorry, but you need to wait three seconds before travel again.", player) + playerPosition:sendMagicEffect(CONST_ME_POFF) + else + npcHandler:removeInteraction(npc, player) + npcHandler:say(parameters.text or "Set the sails!", npc, player) - player:setStorageValue(Global.Storage.NpcExhaust, 3 + os.time()) - player:teleportTo(destination) - playerPosition:sendMagicEffect(CONST_ME_TELEPORT) + local destination = parameters.destination + if type(destination) == "function" then + destination = destination(player) + end - -- What a foolish Quest - Mission 3 - if Storage.WhatAFoolish.PieBoxTimer ~= nil then - if player:getStorageValue(Storage.WhatAFoolish.PieBoxTimer) > os.time() then - if destination ~= Position(32660, 31957, 15) then -- kazordoon steamboat - player:setStorageValue(Storage.WhatAFoolish.PieBoxTimer, 1) + player:kv():set("npc-exhaustion", os.time() + 3) -- 3 seconds + player:teleportTo(destination) + playerPosition:sendMagicEffect(CONST_ME_TELEPORT) + + -- What a foolish Quest - Mission 3 + if Storage.WhatAFoolish.PieBoxTimer ~= nil then + if player:getStorageValue(Storage.WhatAFoolish.PieBoxTimer) > os.time() then + if destination ~= Position(32660, 31957, 15) then -- kazordoon steamboat + player:setStorageValue(Storage.WhatAFoolish.PieBoxTimer, 1) + end end end end diff --git a/data/scripts/eventcallbacks/player/on_look.lua b/data/scripts/eventcallbacks/player/on_look.lua index 985bbfcd3a3..f1a35d14565 100644 --- a/data/scripts/eventcallbacks/player/on_look.lua +++ b/data/scripts/eventcallbacks/player/on_look.lua @@ -25,7 +25,8 @@ function callback.playerOnLook(player, thing, position, distance) if thing:isMonster() then local master = thing:getMaster() if master and table.contains({ "sorcerer familiar", "knight familiar", "druid familiar", "paladin familiar" }, thing:getName():lower()) then - description = string.format("%s (Master: %s). \z It will disappear in %s", description, master:getName(), getTimeInWords(master:getStorageValue(Global.Storage.FamiliarSummon) - os.time())) + local familiarSummonTime = master:kv():get("familiar-summon-time") or 0 + description = string.format("%s (Master: %s). \z It will disappear in %s", description, master:getName(), getTimeInWords(familiarSummonTime - os.time())) end end end From b3a85eee3622fc9eceafed96c1f45ce77e1fe403 Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Thu, 28 Dec 2023 22:38:38 -0800 Subject: [PATCH 2/3] 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 From df811d7669e8929e7a733f36f938f900f09ee06f Mon Sep 17 00:00:00 2001 From: roberto furtado Date: Fri, 29 Dec 2023 03:52:42 -0300 Subject: [PATCH 3/3] fix: cyclopedia description (#1923) * double protection information was removed * fixing speed information that showed in half --------- Co-authored-by: Eduardo Dantas Co-authored-by: Luan Santos Co-authored-by: GitHub Actions --- src/items/item.cpp | 51 ++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/src/items/item.cpp b/src/items/item.cpp index a3f0b3f1a4b..87a3abd7d63 100644 --- a/src/items/item.cpp +++ b/src/items/item.cpp @@ -1291,7 +1291,7 @@ Item::getDescriptions(const ItemType &it, std::shared_ptr item /*= nullptr if (it.abilities->speed) { ss.str(""); - ss << std::showpos << (it.abilities->speed >> 1) << std::noshowpos; + ss << std::showpos << it.abilities->speed << std::noshowpos; descriptions.emplace_back("Speed", ss.str()); } @@ -1606,7 +1606,7 @@ Item::getDescriptions(const ItemType &it, std::shared_ptr item /*= nullptr ss.str(""); bool skillBoost = false; if (it.abilities->speed) { - ss << std::showpos << "speed " << (it.abilities->speed >> 1) << std::noshowpos; + ss << std::showpos << "speed " << it.abilities->speed << std::noshowpos; skillBoost = true; } @@ -1653,14 +1653,11 @@ Item::getDescriptions(const ItemType &it, std::shared_ptr item /*= nullptr ss << it.abilities->skills[i]; } ss << '%' << std::noshowpos; - skillBoost = true; } - if (it.abilities->stats[STAT_MAGICPOINTS]) { - ss.str(""); - ss << std::showpos << it.abilities->stats[STAT_MAGICPOINTS] << std::noshowpos; - descriptions.emplace_back("Magic Level", ss.str()); + if (skillBoost) { + descriptions.emplace_back("Skill Boost", ss.str()); } for (uint8_t i = 1; i <= 11; i++) { @@ -1692,12 +1689,6 @@ Item::getDescriptions(const ItemType &it, std::shared_ptr item /*= nullptr descriptions.emplace_back("Damage Reflection", ss.str()); } - if (it.abilities->speed) { - ss.str(""); - ss << std::showpos << (it.abilities->speed >> 1) << std::noshowpos; - descriptions.emplace_back("Speed", ss.str()); - } - if (it.abilities->cleavePercent) { ss.str(""); ss << std::showpos << (it.abilities->cleavePercent) << std::noshowpos << "%"; @@ -1728,17 +1719,6 @@ Item::getDescriptions(const ItemType &it, std::shared_ptr item /*= nullptr descriptions.emplace_back("Effect", ss.str()); } - for (size_t i = 0; i < COMBAT_COUNT; ++i) { - if (it.abilities->absorbPercent[i] == 0) { - continue; - } - - ss.str(""); - ss << getCombatName(indexToCombatType(i)) << ' ' - << std::showpos << it.abilities->absorbPercent[i] << std::noshowpos << '%'; - descriptions.emplace_back("Protection", ss.str()); - } - for (size_t i = 0; i < COMBAT_COUNT; ++i) { if (it.abilities->fieldAbsorbPercent[i] == 0) { continue; @@ -2587,6 +2567,7 @@ std::string Item::getDescription(const ItemType &it, int32_t lookDistance, std:: if (!begin) { s << ')'; } + // This block refers to the look of the weapons. } else if (it.weaponType != WEAPON_AMMO) { bool begin = true; @@ -2601,6 +2582,28 @@ std::string Item::getDescription(const ItemType &it, int32_t lookDistance, std:: extraDefense = it.extraDefense; } + if (it.isContainer() || (item && item->getContainer())) { + uint32_t volume = 0; + + if (!item || !item->hasAttribute(ItemAttribute_t::UNIQUEID)) { + if (it.isContainer()) { + volume = it.maxItems; + } else if (item) { + volume = item->getContainer()->capacity(); + } + } + + if (volume != 0) { + if (begin) { + begin = false; + s << " ("; + } else { + s << ", "; + } + + s << "Vol:" << volume; + } + } if (attack != 0) { begin = false; s << " (Atk:" << attack;