diff --git a/README.md b/README.md index ad67178..750929a 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,8 @@ This module grants players a random reward item every some time of session playt * Rewards are chosen from a configurable list * Items are added directly to the player’s bags. If bags are full, the item is sent via in-game mail +List of Items: https://docs.google.com/spreadsheets/d/1ELCKMdPya1XaBS-YImPtIuEjEPXj2yf1AuVOHhf-QHs/edit?usp=sharing + **Upcoming features** * Add amount for reward item diff --git a/conf/mod-reward-played-time-improved.conf.dist b/conf/mod-reward-played-time-improved.conf.dist index 7986a75..9aec6da 100644 --- a/conf/mod-reward-played-time-improved.conf.dist +++ b/conf/mod-reward-played-time-improved.conf.dist @@ -7,6 +7,9 @@ RewardPlayedTime.Enable = 1 RewardPlayedTime.Announce = 1 +# Add item to the player bag (1) or to the mailbox (0) +RewardPlayedTime.AddToBag = 1 + # Reward intervals in seconds RewardPlayedTime.RewardInterval = 3600 -RewardPlayedTime.RewardItems = 117, 159, 2589, 4306, 4338, 43015, 33447, 33448, 38260, 44817, 22250, 51809, 37705, 37702, 22445, 22573, 22574 +RewardPlayedTime.RewardItems = 1401, 1412, 1416, 117, 159, 414, 436, 118, 1205, 4536, 4540, 4541, 4542, 4544, 3770, 3771, 4599, 4601, 4602, 4604, 4605, 4606, 4607, 4608, 8952, 8953, 2589, 2592, 4306, 4338, 14047, 2835, 2836, 2838, 2770, 2771, 2772, 3355, 3356, 3357, 3358, 2447, 765, 2449, 1210, 2450, 13463, 13464, 13465, 22445, 22573, 22574, 37702, 37705, 22572, 22575, 37701, 37704, 22785, 22786, 22787, 23424, 23425, 43015, 33447, 33448, 38260, 44817, 22250, 36932, 35624, 36918, 51809, 47257, 44326, 47213 diff --git a/src/RewardPlayedTime.cpp b/src/RewardPlayedTime.cpp index bb96512..ee37f90 100644 --- a/src/RewardPlayedTime.cpp +++ b/src/RewardPlayedTime.cpp @@ -9,9 +9,9 @@ bool modRptiEnabled; bool modRptiAnnounce; +bool modRptiAddToBag; uint32 modRptiRewardIntervalMinutes; -// std::vector> RewardItems; std::vector modRptiItems; std::unordered_map modRptiTimers; @@ -26,6 +26,7 @@ public: { modRptiEnabled = sConfigMgr->GetOption("RewardPlayedTime.Enable", true); modRptiAnnounce = sConfigMgr->GetOption("RewardPlayedTime.Announce", true); + modRptiAddToBag = sConfigMgr->GetOption("RewardPlayedTime.AddToBag", true); modRptiRewardIntervalMinutes = sConfigMgr->GetOption("RewardPlayedTime.RewardInterval", 3600); // Get reward list @@ -37,6 +38,7 @@ public: { modRptiItems.push_back(std::stoul(token)); } + LOG_INFO("module", "[RewardPlayedTime]: Loaded " + std::to_string(modRptiItems.size()) + " rewards."); } }; @@ -71,70 +73,68 @@ public: uint32 intervalMs = modRptiRewardIntervalMinutes * SECOND * IN_MILLISECONDS; - ObjectGuid guid = player->GetGUID(); - - auto player_timer = modRptiTimers.find(guid); + auto player_timer = modRptiTimers.find(player->GetGUID()); if (player_timer == modRptiTimers.end()) { return; // player not tracked } - if (player->isAFK()) { return; } player_timer->second += p_time; + if (player_timer->second < intervalMs) { return; } - - player_timer->second = 0; // reset timer - if (modRptiItems.empty()) { - LOG_WARN("module", "[RewardPlayedTime]: RewardItems list could not be parsed. Check your config!"); + LOG_WARN("module", "[RewardPlayedTime]: RewardItems list is empty. Check your config!"); return; // no items configured } - int32 roll = urand(0, modRptiItems.size() - 1); - uint32 rewardItemId = modRptiItems[roll]; - + uint32 rewardItemId = RollReward(); SendRewardToPlayer(player, rewardItemId, 1); + + player_timer->second = 0; // reset timer + } + + void OnPlayerLogout(Player* player) override + { + if (!modRptiEnabled) { + return; + } + + modRptiTimers.erase(player->GetGUID()); + } + + uint32 RollReward() + { + int32 roll = urand(0, modRptiItems.size() - 1); + return modRptiItems[roll]; } void SendRewardToPlayer(Player* receiver, uint32 itemId, uint32 count) { - ItemTemplate const* item_template = sObjectMgr->GetItemTemplate(itemId); - if (!item_template) + if (!ValidateItemId(itemId, count)) { - LOG_ERROR("module", "[RewardPlayedTime]: The itemId is invalid: {}", itemId); return; } - if (count < 1 || (item_template->MaxCount > 0 && count > uint32(item_template->MaxCount))) - { - LOG_ERROR("module", "[RewardPlayedTime]: The item count is invalid: {} : {}", itemId, count); - return; - } - - std::ostringstream item_quality_string; - item_quality_string << std::hex << ItemQualityColors[item_template->Quality]; ChatHandler(receiver->GetSession()).PSendSysMessage("Congratulations! For your hard work you got a reward!"); - if (receiver->IsInWorld() && receiver->AddItem(itemId, 1)) - { - // // Show item link in chat - // ChatHandler(receiver->GetSession()).PSendSysMessage("You got - |c{}|Hitem:{}:0:0:0:0:0:0:0:0:0|h[{}]|h|r", - // item_quality_string.str(), - // item_template->ItemId, - // item_template->Name1); - return; + if (modRptiAddToBag) { + if (receiver->IsInWorld() && receiver->AddItem(itemId, 1)) + { + return; + } + ChatHandler(receiver->GetSession()).PSendSysMessage("Oh no! But don't worry, your item is send to your mailbox."); + } else { + ChatHandler(receiver->GetSession()).PSendSysMessage("Your item is send to your mailbox."); } - ChatHandler(receiver->GetSession()).PSendSysMessage("Oh no! But don't worry, your item is send to your mailbox."); - MailDraft draft(mail_subject, mail_body); CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction(); @@ -148,13 +148,21 @@ public: CharacterDatabase.CommitTransaction(trans); } - void OnPlayerLogout(Player* player) override + bool ValidateItemId(uint32 itemId, uint32 count) { - if (!modRptiEnabled) { - return; + ItemTemplate const* item_template = sObjectMgr->GetItemTemplate(itemId); + if (!item_template) + { + LOG_ERROR("module", "[RewardPlayedTime]: The itemId is invalid: {}", itemId); + return false; + } + if (count < 1 || (item_template->MaxCount > 0 && count > uint32(item_template->MaxCount))) + { + LOG_ERROR("module", "[RewardPlayedTime]: The item count is invalid: {} : {}", itemId, count); + return false; } - modRptiTimers.erase(player->GetGUID()); + return true; } };