Skip to content

Commit

Permalink
improve: migrate part of daily reward to KV (#2006)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
luan and elsongabriel authored Dec 29, 2023
1 parent a5dcb65 commit b3a85ee
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 18 deletions.
4 changes: 2 additions & 2 deletions data/libs/daily_reward/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion data/modules/scripts/daily_reward/daily_reward.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions src/creatures/combat/condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1165,16 +1165,16 @@ bool ConditionRegeneration::executeCondition(std::shared_ptr<Creature> 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<int32_t>(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);
Expand Down Expand Up @@ -1205,10 +1205,10 @@ bool ConditionRegeneration::executeCondition(std::shared_ptr<Creature> 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);
Expand Down
16 changes: 8 additions & 8 deletions src/server/network/protocol/protocolgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int32_t>(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 << ".";
Expand Down
1 change: 0 additions & 1 deletion src/utils/const.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b3a85ee

Please sign in to comment.