Skip to content

Commit

Permalink
fix: xp boost time granted by reward daily (opentibiabr#2586)
Browse files Browse the repository at this point in the history
  • Loading branch information
luanluciano93 authored Apr 29, 2024
1 parent 8b89817 commit 7c9b8d5
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 65 deletions.
36 changes: 22 additions & 14 deletions data/events/scripts/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 9 additions & 2 deletions data/modules/scripts/daily_reward/daily_reward.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions data/modules/scripts/gamestore/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1925,7 +1925,7 @@ void Player::onWalk(Direction &dir) {

Creature::onWalk(dir);
setNextActionTask(nullptr);

g_callbacks().executeCallback(EventCallback_t::playerOnWalk, &EventCallback::playerOnWalk, getPlayer(), dir);
}

Expand Down
26 changes: 13 additions & 13 deletions src/creatures/players/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1807,11 +1807,11 @@ class Player final : public Creature, public Cylinder, public Bankable {
void setGrindingXpBoost(uint16_t value) {
grindingXpBoost = std::min<uint16_t>(std::numeric_limits<uint16_t>::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;
Expand All @@ -1820,17 +1820,17 @@ class Player final : public Creature, public Cylinder, public Bankable {
staminaXpBoost = std::min<uint16_t>(std::numeric_limits<uint16_t>::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 {
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/io/functions/iologindata_load_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ bool IOLoginDataLoad::loadPlayerFirst(std::shared_ptr<Player> player, DBResult_p
}

player->staminaMinutes = result->getNumber<uint16_t>("stamina");
player->setStoreXpBoost(result->getNumber<uint16_t>("xpboost_value"));
player->setExpBoostStamina(result->getNumber<uint16_t>("xpboost_stamina"));
player->setXpBoostPercent(result->getNumber<uint16_t>("xpboost_value"));
player->setXpBoostTime(result->getNumber<uint16_t>("xpboost_stamina"));

player->setManaShield(result->getNumber<uint16_t>("manashield"));
player->setMaxManaShield(result->getNumber<uint16_t>("max_manashield"));
Expand Down
4 changes: 2 additions & 2 deletions src/io/functions/iologindata_save_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ bool IOLoginDataSave::savePlayerFirst(std::shared_ptr<Player> 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()) {
Expand Down
28 changes: 14 additions & 14 deletions src/lua/functions/creatures/player/player_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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> player = getUserdataShared<Player>(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> player = getUserdataShared<Player>(L, 1);
if (player) {
uint16_t experience = getNumber<uint16_t>(L, 2);
player->setStoreXpBoost(experience);
uint16_t percent = getNumber<uint16_t>(L, 2);
player->setXpBoostPercent(percent);
pushBoolean(L, true);
} else {
lua_pushnil(L);
Expand Down Expand Up @@ -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> player = getUserdataShared<Player>(L, 1);
if (player) {
uint16_t stamina = getNumber<uint16_t>(L, 2);
player->setExpBoostStamina(stamina);
uint16_t timeLeft = getNumber<uint16_t>(L, 2);
player->setXpBoostTime(timeLeft);
player->sendStats();
pushBoolean(L, true);
} else {
Expand All @@ -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> player = getUserdataShared<Player>(L, 1);
if (player) {
lua_pushnumber(L, player->getExpBoostStamina());
lua_pushnumber(L, player->getXpBoostTime());
} else {
lua_pushnil(L);
}
Expand Down
16 changes: 8 additions & 8 deletions src/lua/functions/creatures/player/player_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions src/server/network/protocol/protocolgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3390,9 +3390,9 @@ void ProtocolGame::sendCyclopediaCharacterGeneralStats() {
msg.addByte(player->getLevelPercent());
msg.add<uint16_t>(player->getBaseXpGain()); // BaseXPGainRate
msg.add<uint16_t>(player->getGrindingXpBoost()); // LowLevelBonus
msg.add<uint16_t>(player->getStoreXpBoost()); // XPBoost
msg.add<uint16_t>(player->getXpBoostPercent()); // XPBoost
msg.add<uint16_t>(player->getStaminaXpBoost()); // StaminaMultiplier(100=x1.0)
msg.add<uint16_t>(player->getExpBoostStamina()); // xpBoostRemainingTime
msg.add<uint16_t>(player->getXpBoostTime()); // xpBoostRemainingTime
msg.addByte(0x01); // canBuyXpBoost
msg.add<uint32_t>(std::min<int32_t>(player->getHealth(), std::numeric_limits<uint16_t>::max()));
msg.add<uint32_t>(std::min<int32_t>(player->getMaxHealth(), std::numeric_limits<uint16_t>::max()));
Expand Down Expand Up @@ -3802,7 +3802,7 @@ void ProtocolGame::sendCyclopediaCharacterStoreSummary() {
msg.addByte(CYCLOPEDIA_CHARACTERINFO_STORESUMMARY);
msg.addByte(0x00);
// Remaining Store Xp Boost Time
msg.add<uint32_t>(player->getExpBoostStamina());
msg.add<uint32_t>(player->getXpBoostTime());
// RemainingDailyRewardXpBoostTime
msg.add<uint32_t>(0);
msg.addByte(0x00);
Expand Down Expand Up @@ -7303,7 +7303,7 @@ void ProtocolGame::AddPlayerStats(NetworkMessage &msg) {
}

msg.add<uint16_t>(player->getGrindingXpBoost()); // low level bonus
msg.add<uint16_t>(player->getStoreXpBoost()); // xp boost
msg.add<uint16_t>(player->getXpBoostPercent()); // xp boost
msg.add<uint16_t>(player->getStaminaXpBoost()); // stamina multiplier (100 = 1.0x)

if (!oldProtocol) {
Expand All @@ -7329,7 +7329,7 @@ void ProtocolGame::AddPlayerStats(NetworkMessage &msg) {

msg.add<uint16_t>(player->getOfflineTrainingTime() / 60 / 1000);

msg.add<uint16_t>(player->getExpBoostStamina()); // xp boost time (seconds)
msg.add<uint16_t>(player->getXpBoostTime()); // xp boost time (seconds)
msg.addByte(1); // enables exp boost in the store

if (!oldProtocol) {
Expand Down

0 comments on commit 7c9b8d5

Please sign in to comment.