mirror of
https://github.com/freekode/mod-reward-played-time-improved.git
synced 2026-01-13 00:28:34 +00:00
add more items, conf send only email
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
|
||||
bool modRptiEnabled;
|
||||
bool modRptiAnnounce;
|
||||
bool modRptiAddToBag;
|
||||
uint32 modRptiRewardIntervalMinutes;
|
||||
|
||||
// std::vector<std::pair<uint32, uint32>> RewardItems;
|
||||
std::vector<uint32> modRptiItems;
|
||||
std::unordered_map<ObjectGuid, uint32> modRptiTimers;
|
||||
|
||||
@@ -26,6 +26,7 @@ public:
|
||||
{
|
||||
modRptiEnabled = sConfigMgr->GetOption<bool>("RewardPlayedTime.Enable", true);
|
||||
modRptiAnnounce = sConfigMgr->GetOption<bool>("RewardPlayedTime.Announce", true);
|
||||
modRptiAddToBag = sConfigMgr->GetOption<bool>("RewardPlayedTime.AddToBag", true);
|
||||
modRptiRewardIntervalMinutes = sConfigMgr->GetOption<uint32>("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,69 +73,67 @@ 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 (modRptiAddToBag) {
|
||||
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;
|
||||
}
|
||||
|
||||
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.");
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user