From 7c9b8d54fbc9d1d071347358262a00532f0b1705 Mon Sep 17 00:00:00 2001 From: Luan Luciano Date: Mon, 29 Apr 2024 12:39:56 -0300 Subject: [PATCH] fix: xp boost time granted by reward daily (#2586) --- data/events/scripts/player.lua | 36 +++++++++++-------- .../scripts/daily_reward/daily_reward.lua | 11 ++++-- data/modules/scripts/gamestore/init.lua | 8 ++--- src/creatures/players/player.cpp | 2 +- src/creatures/players/player.hpp | 26 +++++++------- src/io/functions/iologindata_load_player.cpp | 4 +-- src/io/functions/iologindata_save_player.cpp | 4 +-- .../creatures/player/player_functions.cpp | 28 +++++++-------- .../creatures/player/player_functions.hpp | 16 ++++----- src/server/network/protocol/protocolgame.cpp | 10 +++--- 10 files changed, 80 insertions(+), 65 deletions(-) diff --git a/data/events/scripts/player.lua b/data/events/scripts/player.lua index 35e0bb17e7f..ec1a92f3528 100644 --- a/data/events/scripts/player.lua +++ b/data/events/scripts/player.lua @@ -140,8 +140,8 @@ local function useStaminaXpBoost(player) return false end - local staminaMinutes = player:getExpBoostStamina() / 60 - if staminaMinutes == 0 then + local xpBoostMinutes = player:getXpBoostTime() / 60 + if xpBoostMinutes == 0 then return end @@ -156,18 +156,26 @@ local function useStaminaXpBoost(player) return end + local xpBoostLeftMinutesByDailyReward = player:kv():get("daily-reward-xp-boost") or 0 if timePassed > 60 then - if staminaMinutes > 2 then - staminaMinutes = staminaMinutes - 2 + if xpBoostMinutes > 2 then + xpBoostMinutes = xpBoostMinutes - 2 + if xpBoostLeftMinutesByDailyReward > 2 then + player:kv():set("daily-reward-xp-boost", xpBoostLeftMinutesByDailyReward - 2) + end else - staminaMinutes = 0 + xpBoostMinutes = 0 + player:kv():remove("daily-reward-xp-boost") end _G.NextUseXpStamina[playerId] = currentTime + 120 else - staminaMinutes = staminaMinutes - 1 + xpBoostMinutes = xpBoostMinutes - 1 + if xpBoostLeftMinutesByDailyReward > 0 then + player:kv():set("daily-reward-xp-boost", xpBoostLeftMinutesByDailyReward - 1) + end _G.NextUseXpStamina[playerId] = currentTime + 60 end - player:setExpBoostStamina(staminaMinutes * 60) + player:setXpBoostTime(xpBoostMinutes * 60) end local function useConcoctionTime(player) @@ -519,14 +527,14 @@ function Player:onGainExperience(target, exp, rawExp) self:addCondition(soulCondition) end - -- Store Bonus - useStaminaXpBoost(self) -- Use store boost stamina + -- XP Boost Bonus + useStaminaXpBoost(self) -- Use stamina XP boost (store or daily reward) - local Boost = self:getExpBoostStamina() - local stillHasBoost = Boost > 0 - local storeXpBoostAmount = stillHasBoost and self:getStoreXpBoost() or 0 + local xpBoostTimeLeft = self:getXpBoostTime() + local stillHasXpBoost = xpBoostTimeLeft > 0 + local xpBoostPercent = stillHasXpBoost and self:getXpBoostPercent() or 0 - self:setStoreXpBoost(storeXpBoostAmount) + self:setXpBoostPercent(xpBoostPercent) -- Stamina Bonus local staminaBonusXp = 1 @@ -564,7 +572,7 @@ function Player:onGainExperience(target, exp, rawExp) local lowLevelBonuxExp = self:getFinalLowLevelBonus() local baseRate = self:getFinalBaseRateExperience() - return (exp + (exp * (storeXpBoostAmount / 100) + (exp * (lowLevelBonuxExp / 100)))) * staminaBonusXp * baseRate + return (exp + (exp * (xpBoostPercent / 100) + (exp * (lowLevelBonuxExp / 100)))) * staminaBonusXp * baseRate end function Player:onLoseExperience(exp) diff --git a/data/modules/scripts/daily_reward/daily_reward.lua b/data/modules/scripts/daily_reward/daily_reward.lua index 1f0e805704c..09b927cedda 100644 --- a/data/modules/scripts/daily_reward/daily_reward.lua +++ b/data/modules/scripts/daily_reward/daily_reward.lua @@ -476,8 +476,15 @@ function Player.selectDailyReward(self, msg) end dailyRewardMessage = "Picked items: " .. description elseif dailyTable.type == DAILY_REWARD_TYPE_XP_BOOST then - self:setExpBoostStamina(self:getExpBoostStamina() + (rewardCount * 60)) - self:setStoreXpBoost(50) + local rewardCountReviewed = rewardCount + local xpBoostLeftMinutes = self:kv():get("daily-reward-xp-boost") or 0 + if xpBoostLeftMinutes > 0 then + rewardCountReviewed = rewardCountReviewed - xpBoostLeftMinutes + end + + self:setXpBoostTime(self:getXpBoostTime() + (rewardCountReviewed * 60)) + self:kv():set("daily-reward-xp-boost", rewardCount) + self:setXpBoostPercent(50) dailyRewardMessage = "Picked reward: XP Bonus for " .. rewardCount .. " minutes." elseif dailyTable.type == DAILY_REWARD_TYPE_PREY_REROLL then self:addPreyCards(rewardCount) diff --git a/data/modules/scripts/gamestore/init.lua b/data/modules/scripts/gamestore/init.lua index 7d9081df1fb..ba7398d9d3e 100644 --- a/data/modules/scripts/gamestore/init.lua +++ b/data/modules/scripts/gamestore/init.lua @@ -732,7 +732,7 @@ function Player.canBuyOffer(self, offer) disabled = 1 disabledReason = "You can't buy XP Boost for today." end - if self:getExpBoostStamina() > 0 then + if self:getXpBoostTime() > 0 then disabled = 1 disabledReason = "You already have an active XP boost." end @@ -1743,11 +1743,11 @@ function GameStore.processSexChangePurchase(player) end function GameStore.processExpBoostPurchase(player) - local currentExpBoostTime = player:getExpBoostStamina() + local currentXpBoostTime = player:getXpBoostTime() local expBoostCount = player:getStorageValue(GameStore.Storages.expBoostCount) - player:setStoreXpBoost(50) - player:setExpBoostStamina(currentExpBoostTime + 3600) + player:setXpBoostPercent(50) + player:setXpBoostTime(currentXpBoostTime + 3600) if expBoostCount == -1 or expBoostCount == 6 then expBoostCount = 1 diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index 1f0c9b45dce..a81981bd20c 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -1925,7 +1925,7 @@ void Player::onWalk(Direction &dir) { Creature::onWalk(dir); setNextActionTask(nullptr); - + g_callbacks().executeCallback(EventCallback_t::playerOnWalk, &EventCallback::playerOnWalk, getPlayer(), dir); } diff --git a/src/creatures/players/player.hpp b/src/creatures/players/player.hpp index 70c8c05aecd..c2a9f29831a 100644 --- a/src/creatures/players/player.hpp +++ b/src/creatures/players/player.hpp @@ -1807,11 +1807,11 @@ class Player final : public Creature, public Cylinder, public Bankable { void setGrindingXpBoost(uint16_t value) { grindingXpBoost = std::min(std::numeric_limits::max(), value); } - uint16_t getStoreXpBoost() const { - return storeXpBoost; + uint16_t getXpBoostPercent() const { + return xpBoostPercent; } - void setStoreXpBoost(uint16_t exp) { - storeXpBoost = exp; + void setXpBoostPercent(uint16_t percent) { + xpBoostPercent = percent; } uint16_t getStaminaXpBoost() const { return staminaXpBoost; @@ -1820,17 +1820,17 @@ class Player final : public Creature, public Cylinder, public Bankable { staminaXpBoost = std::min(std::numeric_limits::max(), value); } - void setExpBoostStamina(uint16_t stamina) { - // only allow stamina boosts of 12 hours or less - if (stamina > 12 * 3600) { - expBoostStamina = 12 * 3600; + void setXpBoostTime(uint16_t timeLeft) { + // only allow time boosts of 12 hours or less + if (timeLeft > 12 * 3600) { + xpBoostTime = 12 * 3600; return; } - expBoostStamina = stamina; + xpBoostTime = timeLeft; } - uint16_t getExpBoostStamina() { - return expBoostStamina; + uint16_t getXpBoostTime() { + return xpBoostTime; } int32_t getIdleTime() const { @@ -2811,7 +2811,7 @@ class Player final : public Creature, public Cylinder, public Bankable { int32_t m_deathTime = 0; uint32_t coinBalance = 0; uint32_t coinTransferableBalance = 0; - uint16_t expBoostStamina = 0; + uint16_t xpBoostTime = 0; uint8_t randomMount = 0; uint16_t lastStatsTrainingTime = 0; @@ -2821,7 +2821,7 @@ class Player final : public Creature, public Cylinder, public Bankable { uint16_t baseXpGain = 100; uint16_t voucherXpBoost = 0; uint16_t grindingXpBoost = 0; - uint16_t storeXpBoost = 0; + uint16_t xpBoostPercent = 0; uint16_t staminaXpBoost = 100; int16_t lastDepotId = -1; StashItemList stashItems; // [ItemID] = amount diff --git a/src/io/functions/iologindata_load_player.cpp b/src/io/functions/iologindata_load_player.cpp index d4a4f33774d..2c3cbf48fea 100644 --- a/src/io/functions/iologindata_load_player.cpp +++ b/src/io/functions/iologindata_load_player.cpp @@ -177,8 +177,8 @@ bool IOLoginDataLoad::loadPlayerFirst(std::shared_ptr player, DBResult_p } player->staminaMinutes = result->getNumber("stamina"); - player->setStoreXpBoost(result->getNumber("xpboost_value")); - player->setExpBoostStamina(result->getNumber("xpboost_stamina")); + player->setXpBoostPercent(result->getNumber("xpboost_value")); + player->setXpBoostTime(result->getNumber("xpboost_stamina")); player->setManaShield(result->getNumber("manashield")); player->setMaxManaShield(result->getNumber("max_manashield")); diff --git a/src/io/functions/iologindata_save_player.cpp b/src/io/functions/iologindata_save_player.cpp index 7bc1b34c864..82ba286d622 100644 --- a/src/io/functions/iologindata_save_player.cpp +++ b/src/io/functions/iologindata_save_player.cpp @@ -292,8 +292,8 @@ bool IOLoginDataSave::savePlayerFirst(std::shared_ptr player) { query << "`skill_mana_leech_amount_tries` = " << player->skills[SKILL_MANA_LEECH_AMOUNT].tries << ","; query << "`manashield` = " << player->getManaShield() << ","; query << "`max_manashield` = " << player->getMaxManaShield() << ","; - query << "`xpboost_value` = " << player->getStoreXpBoost() << ","; - query << "`xpboost_stamina` = " << player->getExpBoostStamina() << ","; + query << "`xpboost_value` = " << player->getXpBoostPercent() << ","; + query << "`xpboost_stamina` = " << player->getXpBoostTime() << ","; query << "`quickloot_fallback` = " << (player->quickLootFallbackToMainContainer ? 1 : 0) << ","; if (!player->isOffline()) { diff --git a/src/lua/functions/creatures/player/player_functions.cpp b/src/lua/functions/creatures/player/player_functions.cpp index 94da8f4ffbc..94100a1f406 100644 --- a/src/lua/functions/creatures/player/player_functions.cpp +++ b/src/lua/functions/creatures/player/player_functions.cpp @@ -3219,23 +3219,23 @@ int PlayerFunctions::luaPlayerSetGrindingXpBoost(lua_State* L) { return 1; } -int PlayerFunctions::luaPlayerGetStoreXpBoost(lua_State* L) { - // player:getStoreXpBoost() +int PlayerFunctions::luaPlayerGetXpBoostPercent(lua_State* L) { + // player:getXpBoostPercent() std::shared_ptr player = getUserdataShared(L, 1); if (player) { - lua_pushnumber(L, player->getStoreXpBoost()); + lua_pushnumber(L, player->getXpBoostPercent()); } else { lua_pushnil(L); } return 1; } -int PlayerFunctions::luaPlayerSetStoreXpBoost(lua_State* L) { - // player:setStoreXpBoost(value) +int PlayerFunctions::luaPlayerSetXpBoostPercent(lua_State* L) { + // player:setXpBoostPercent(value) std::shared_ptr player = getUserdataShared(L, 1); if (player) { - uint16_t experience = getNumber(L, 2); - player->setStoreXpBoost(experience); + uint16_t percent = getNumber(L, 2); + player->setXpBoostPercent(percent); pushBoolean(L, true); } else { lua_pushnil(L); @@ -3267,12 +3267,12 @@ int PlayerFunctions::luaPlayerSetStaminaXpBoost(lua_State* L) { return 1; } -int PlayerFunctions::luaPlayerSetExpBoostStamina(lua_State* L) { - // player:setExpBoostStamina(percent) +int PlayerFunctions::luaPlayerSetXpBoostTime(lua_State* L) { + // player:setXpBoostTime(timeLeft) std::shared_ptr player = getUserdataShared(L, 1); if (player) { - uint16_t stamina = getNumber(L, 2); - player->setExpBoostStamina(stamina); + uint16_t timeLeft = getNumber(L, 2); + player->setXpBoostTime(timeLeft); player->sendStats(); pushBoolean(L, true); } else { @@ -3281,11 +3281,11 @@ int PlayerFunctions::luaPlayerSetExpBoostStamina(lua_State* L) { return 1; } -int PlayerFunctions::luaPlayerGetExpBoostStamina(lua_State* L) { - // player:getExpBoostStamina() +int PlayerFunctions::luaPlayerGetXpBoostTime(lua_State* L) { + // player:getXpBoostTime() std::shared_ptr player = getUserdataShared(L, 1); if (player) { - lua_pushnumber(L, player->getExpBoostStamina()); + lua_pushnumber(L, player->getXpBoostTime()); } else { lua_pushnil(L); } diff --git a/src/lua/functions/creatures/player/player_functions.hpp b/src/lua/functions/creatures/player/player_functions.hpp index fafc99ff955..2be6e5076cd 100644 --- a/src/lua/functions/creatures/player/player_functions.hpp +++ b/src/lua/functions/creatures/player/player_functions.hpp @@ -273,12 +273,12 @@ class PlayerFunctions final : LuaScriptInterface { registerMethod(L, "Player", "setVoucherXpBoost", PlayerFunctions::luaPlayerSetVoucherXpBoost); registerMethod(L, "Player", "getGrindingXpBoost", PlayerFunctions::luaPlayerGetGrindingXpBoost); registerMethod(L, "Player", "setGrindingXpBoost", PlayerFunctions::luaPlayerSetGrindingXpBoost); - registerMethod(L, "Player", "getStoreXpBoost", PlayerFunctions::luaPlayerGetStoreXpBoost); - registerMethod(L, "Player", "setStoreXpBoost", PlayerFunctions::luaPlayerSetStoreXpBoost); + registerMethod(L, "Player", "getXpBoostPercent", PlayerFunctions::luaPlayerGetXpBoostPercent); + registerMethod(L, "Player", "setXpBoostPercent", PlayerFunctions::luaPlayerSetXpBoostPercent); registerMethod(L, "Player", "getStaminaXpBoost", PlayerFunctions::luaPlayerGetStaminaXpBoost); registerMethod(L, "Player", "setStaminaXpBoost", PlayerFunctions::luaPlayerSetStaminaXpBoost); - registerMethod(L, "Player", "getExpBoostStamina", PlayerFunctions::luaPlayerGetExpBoostStamina); - registerMethod(L, "Player", "setExpBoostStamina", PlayerFunctions::luaPlayerSetExpBoostStamina); + registerMethod(L, "Player", "getXpBoostTime", PlayerFunctions::luaPlayerGetXpBoostTime); + registerMethod(L, "Player", "setXpBoostTime", PlayerFunctions::luaPlayerSetXpBoostTime); registerMethod(L, "Player", "getIdleTime", PlayerFunctions::luaPlayerGetIdleTime); registerMethod(L, "Player", "getFreeBackpackSlots", PlayerFunctions::luaPlayerGetFreeBackpackSlots); @@ -627,12 +627,12 @@ class PlayerFunctions final : LuaScriptInterface { static int luaPlayerSetVoucherXpBoost(lua_State* L); static int luaPlayerGetGrindingXpBoost(lua_State* L); static int luaPlayerSetGrindingXpBoost(lua_State* L); - static int luaPlayerGetStoreXpBoost(lua_State* L); - static int luaPlayerSetStoreXpBoost(lua_State* L); + static int luaPlayerGetXpBoostPercent(lua_State* L); + static int luaPlayerSetXpBoostPercent(lua_State* L); static int luaPlayerGetStaminaXpBoost(lua_State* L); static int luaPlayerSetStaminaXpBoost(lua_State* L); - static int luaPlayerGetExpBoostStamina(lua_State* L); - static int luaPlayerSetExpBoostStamina(lua_State* L); + static int luaPlayerGetXpBoostTime(lua_State* L); + static int luaPlayerSetXpBoostTime(lua_State* L); static int luaPlayerGetIdleTime(lua_State* L); static int luaPlayerGetFreeBackpackSlots(lua_State* L); diff --git a/src/server/network/protocol/protocolgame.cpp b/src/server/network/protocol/protocolgame.cpp index 22b032f5bc4..1748699ab34 100644 --- a/src/server/network/protocol/protocolgame.cpp +++ b/src/server/network/protocol/protocolgame.cpp @@ -3390,9 +3390,9 @@ void ProtocolGame::sendCyclopediaCharacterGeneralStats() { msg.addByte(player->getLevelPercent()); msg.add(player->getBaseXpGain()); // BaseXPGainRate msg.add(player->getGrindingXpBoost()); // LowLevelBonus - msg.add(player->getStoreXpBoost()); // XPBoost + msg.add(player->getXpBoostPercent()); // XPBoost msg.add(player->getStaminaXpBoost()); // StaminaMultiplier(100=x1.0) - msg.add(player->getExpBoostStamina()); // xpBoostRemainingTime + msg.add(player->getXpBoostTime()); // xpBoostRemainingTime msg.addByte(0x01); // canBuyXpBoost msg.add(std::min(player->getHealth(), std::numeric_limits::max())); msg.add(std::min(player->getMaxHealth(), std::numeric_limits::max())); @@ -3802,7 +3802,7 @@ void ProtocolGame::sendCyclopediaCharacterStoreSummary() { msg.addByte(CYCLOPEDIA_CHARACTERINFO_STORESUMMARY); msg.addByte(0x00); // Remaining Store Xp Boost Time - msg.add(player->getExpBoostStamina()); + msg.add(player->getXpBoostTime()); // RemainingDailyRewardXpBoostTime msg.add(0); msg.addByte(0x00); @@ -7303,7 +7303,7 @@ void ProtocolGame::AddPlayerStats(NetworkMessage &msg) { } msg.add(player->getGrindingXpBoost()); // low level bonus - msg.add(player->getStoreXpBoost()); // xp boost + msg.add(player->getXpBoostPercent()); // xp boost msg.add(player->getStaminaXpBoost()); // stamina multiplier (100 = 1.0x) if (!oldProtocol) { @@ -7329,7 +7329,7 @@ void ProtocolGame::AddPlayerStats(NetworkMessage &msg) { msg.add(player->getOfflineTrainingTime() / 60 / 1000); - msg.add(player->getExpBoostStamina()); // xp boost time (seconds) + msg.add(player->getXpBoostTime()); // xp boost time (seconds) msg.addByte(1); // enables exp boost in the store if (!oldProtocol) {