mirror of
https://github.com/freekode/mod-reward-played-time-improved.git
synced 2026-01-13 08:37:18 +00:00
add more items, conf send only email
This commit is contained in:
@@ -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,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;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user