mirror of
https://github.com/freekode/mod-reward-played-time-improved.git
synced 2026-01-13 00:28:34 +00:00
Merge pull request #1 from freekode/pools
New rewards, send item only by mail
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
|
* 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
|
* 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**
|
**Upcoming features**
|
||||||
|
|
||||||
* Add amount for reward item
|
* Add amount for reward item
|
||||||
|
|||||||
0
apps/ci/ci-codestyle.sh
Normal file → Executable file
0
apps/ci/ci-codestyle.sh
Normal file → Executable file
@@ -7,6 +7,9 @@
|
|||||||
RewardPlayedTime.Enable = 1
|
RewardPlayedTime.Enable = 1
|
||||||
RewardPlayedTime.Announce = 1
|
RewardPlayedTime.Announce = 1
|
||||||
|
|
||||||
|
# Add item to the player bag (1) or to the mailbox (0)
|
||||||
|
RewardPlayedTime.AddToBag = 1
|
||||||
|
|
||||||
# Reward intervals in seconds
|
# Reward intervals in seconds
|
||||||
RewardPlayedTime.RewardInterval = 3600
|
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
|
||||||
|
|||||||
@@ -2,12 +2,8 @@
|
|||||||
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-AGPL3
|
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-AGPL3
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// From SC
|
|
||||||
void AddRewardPlayedTimeScripts();
|
void AddRewardPlayedTimeScripts();
|
||||||
|
|
||||||
// Add all
|
|
||||||
// cf. the naming convention https://github.com/azerothcore/azerothcore-wotlk/blob/master/doc/changelog/master.md#how-to-upgrade-4
|
|
||||||
// additionally replace all '-' in the module folder name with '_' here
|
|
||||||
void Addmod_reward_played_time_improvedScripts()
|
void Addmod_reward_played_time_improvedScripts()
|
||||||
{
|
{
|
||||||
AddRewardPlayedTimeScripts();
|
AddRewardPlayedTimeScripts();
|
||||||
|
|||||||
@@ -7,116 +7,133 @@
|
|||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "Chat.h"
|
#include "Chat.h"
|
||||||
|
|
||||||
|
bool modRptiEnabled;
|
||||||
|
bool modRptiAnnounce;
|
||||||
|
bool modRptiAddToBag;
|
||||||
|
uint32 modRptiRewardIntervalMinutes;
|
||||||
|
|
||||||
|
std::vector<uint32> modRptiItems;
|
||||||
|
std::unordered_map<ObjectGuid, uint32> modRptiTimers;
|
||||||
|
|
||||||
|
class mod_reward_time_played_conf : public WorldScript
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
mod_reward_time_played_conf() : WorldScript("mod_reward_time_played_conf", {}) { }
|
||||||
|
|
||||||
|
// Load Configuration Settings
|
||||||
|
void OnBeforeConfigLoad(bool /*reload*/) override
|
||||||
|
{
|
||||||
|
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
|
||||||
|
std::string itemList = sConfigMgr->GetOption<std::string>("RewardPlayedTime.RewardItems", "");
|
||||||
|
std::stringstream ss(itemList);
|
||||||
|
std::string token;
|
||||||
|
modRptiItems.clear();
|
||||||
|
while (std::getline(ss, token, ','))
|
||||||
|
{
|
||||||
|
modRptiItems.push_back(std::stoul(token));
|
||||||
|
}
|
||||||
|
LOG_INFO("module", "[RewardPlayedTime]: Loaded " + std::to_string(modRptiItems.size()) + " rewards.");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class RewardPlayedTime : public PlayerScript
|
class RewardPlayedTime : public PlayerScript
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RewardPlayedTime() : PlayerScript("RewardPlayedTime") { }
|
RewardPlayedTime() : PlayerScript("RewardPlayedTime") { }
|
||||||
|
|
||||||
// std::vector<std::pair<uint32, uint32>> RewardItems;
|
|
||||||
std::unordered_map<ObjectGuid, uint32> timers;
|
|
||||||
std::string mail_subject = "RewardPlayedTime";
|
std::string mail_subject = "RewardPlayedTime";
|
||||||
std::string mail_body = "Congratulations! For your hard work you got a reward, keep it up!";
|
std::string mail_body = "Congratulations! For your hard work you got a reward, keep it up!";
|
||||||
|
|
||||||
void OnPlayerLogin(Player* player) override
|
void OnPlayerLogin(Player* player) override
|
||||||
{
|
{
|
||||||
if (!sConfigMgr->GetOption<bool>("RewardPlayedTime.Enable", true))
|
if (!modRptiEnabled)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (modRptiAnnounce)
|
||||||
if (sConfigMgr->GetOption<bool>("RewardPlayedTime.Announce", true) )
|
|
||||||
{
|
{
|
||||||
ChatHandler(player->GetSession()).PSendSysMessage("This server is running the |cff4CFF00Reward Time Played Improved |rmodule.");
|
ChatHandler(player->GetSession()).PSendSysMessage("This server is running the |cff4CFF00Reward Time Played Improved |rmodule.");
|
||||||
}
|
}
|
||||||
|
|
||||||
timers[player->GetGUID()] = 0;
|
modRptiTimers[player->GetGUID()] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnPlayerBeforeUpdate(Player* player, uint32 p_time) override
|
void OnPlayerBeforeUpdate(Player* player, uint32 p_time) override
|
||||||
{
|
{
|
||||||
if (!sConfigMgr->GetOption<bool>("RewardPlayedTime.Enable", true))
|
if (!modRptiEnabled)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 rewardIntervalMinutes = sConfigMgr->GetOption<uint32>("RewardPlayedTime.RewardInterval", 3600);
|
uint32 intervalMs = modRptiRewardIntervalMinutes * SECOND * IN_MILLISECONDS;
|
||||||
uint32 intervalMs = rewardIntervalMinutes * SECOND * IN_MILLISECONDS;
|
|
||||||
|
|
||||||
ObjectGuid guid = player->GetGUID();
|
auto player_timer = modRptiTimers.find(player->GetGUID());
|
||||||
|
if (player_timer == modRptiTimers.end())
|
||||||
auto player_timer = timers.find(guid);
|
|
||||||
if (player_timer == timers.end())
|
|
||||||
{
|
{
|
||||||
return; // player not tracked
|
return; // player not tracked
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player->isAFK())
|
if (player->isAFK())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
player_timer->second += p_time;
|
player_timer->second += p_time;
|
||||||
|
|
||||||
if (player_timer->second < intervalMs)
|
if (player_timer->second < intervalMs)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (modRptiItems.empty())
|
||||||
player_timer->second = 0; // reset timer
|
|
||||||
|
|
||||||
// Get reward list
|
|
||||||
std::string itemList = sConfigMgr->GetOption<std::string>("RewardPlayedTime.RewardItems", "");
|
|
||||||
std::vector<uint32> items;
|
|
||||||
|
|
||||||
std::stringstream ss(itemList);
|
|
||||||
std::string token;
|
|
||||||
while (std::getline(ss, token, ','))
|
|
||||||
{
|
{
|
||||||
items.push_back(std::stoul(token));
|
LOG_WARN("module", "[RewardPlayedTime]: RewardItems list is empty. Check your config!");
|
||||||
}
|
|
||||||
|
|
||||||
if (items.empty())
|
|
||||||
{
|
|
||||||
LOG_WARN("module", "[RewardPlayedTime]: RewardItems list could not be parsed. Check your config!");
|
|
||||||
return; // no items configured
|
return; // no items configured
|
||||||
}
|
}
|
||||||
|
|
||||||
int32 roll = urand(0, items.size() - 1);
|
uint32 rewardItemId = RollReward();
|
||||||
uint32 rewardItemId = items[roll];
|
|
||||||
|
|
||||||
SendRewardToPlayer(player, rewardItemId, 1);
|
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)
|
void SendRewardToPlayer(Player* receiver, uint32 itemId, uint32 count)
|
||||||
{
|
{
|
||||||
ItemTemplate const* item_template = sObjectMgr->GetItemTemplate(itemId);
|
if (!ValidateItemId(itemId, count))
|
||||||
if (!item_template)
|
|
||||||
{
|
{
|
||||||
LOG_ERROR("module", "[RewardPlayedTime]: The itemId is invalid: {}", itemId);
|
|
||||||
return;
|
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!");
|
ChatHandler(receiver->GetSession()).PSendSysMessage("Congratulations! For your hard work you got a reward!");
|
||||||
|
|
||||||
if (receiver->IsInWorld() && receiver->AddItem(itemId, 1))
|
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",
|
return;
|
||||||
// item_quality_string.str(),
|
}
|
||||||
// item_template->ItemId,
|
ChatHandler(receiver->GetSession()).PSendSysMessage("Oh no! But don't worry, your item is send to your mailbox.");
|
||||||
// item_template->Name1);
|
} else {
|
||||||
return;
|
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);
|
MailDraft draft(mail_subject, mail_body);
|
||||||
CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
|
CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
|
||||||
|
|
||||||
@@ -130,17 +147,26 @@ public:
|
|||||||
CharacterDatabase.CommitTransaction(trans);
|
CharacterDatabase.CommitTransaction(trans);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnPlayerLogout(Player* player) override
|
bool ValidateItemId(uint32 itemId, uint32 count)
|
||||||
{
|
{
|
||||||
if (!sConfigMgr->GetOption<bool>("RewardPlayedTime.Enable", true)) {
|
ItemTemplate const* item_template = sObjectMgr->GetItemTemplate(itemId);
|
||||||
return;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
timers.erase(player->GetGUID());
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void AddRewardPlayedTimeScripts()
|
void AddRewardPlayedTimeScripts()
|
||||||
{
|
{
|
||||||
|
new mod_reward_time_played_conf();
|
||||||
new RewardPlayedTime();
|
new RewardPlayedTime();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user