This commit is contained in:
Evgeny
2025-09-01 19:52:09 +02:00
parent e95fc49e68
commit 09bba47c89

View File

@@ -7,13 +7,13 @@
#include "Config.h" #include "Config.h"
#include "Chat.h" #include "Chat.h"
bool modEnabled; bool modRptiEnabled;
bool modAnnounce; bool modRptiAnnounce;
uint32 rewardIntervalMinutes; uint32 modRptiRewardIntervalMinutes;
// std::vector<std::pair<uint32, uint32>> RewardItems; // std::vector<std::pair<uint32, uint32>> RewardItems;
std::vector<uint32> items; std::vector<uint32> modRptiItems;
std::unordered_map<ObjectGuid, uint32> timers; std::unordered_map<ObjectGuid, uint32> modRptiTimers;
class mod_reward_time_played_conf : public WorldScript class mod_reward_time_played_conf : public WorldScript
@@ -24,18 +24,18 @@ public:
// Load Configuration Settings // Load Configuration Settings
void OnBeforeConfigLoad(bool /*reload*/) override void OnBeforeConfigLoad(bool /*reload*/) override
{ {
modEnabled = sConfigMgr->GetOption<bool>("RewardPlayedTime.Enable", true); modRptiEnabled = sConfigMgr->GetOption<bool>("RewardPlayedTime.Enable", true);
modAnnounce = sConfigMgr->GetOption<bool>("RewardPlayedTime.Announce", true); modRptiAnnounce = sConfigMgr->GetOption<bool>("RewardPlayedTime.Announce", true);
rewardIntervalMinutes = sConfigMgr->GetOption<uint32>("RewardPlayedTime.RewardInterval", 3600); modRptiRewardIntervalMinutes = sConfigMgr->GetOption<uint32>("RewardPlayedTime.RewardInterval", 3600);
// Get reward list // Get reward list
std::string itemList = sConfigMgr->GetOption<std::string>("RewardPlayedTime.RewardItems", ""); std::string itemList = sConfigMgr->GetOption<std::string>("RewardPlayedTime.RewardItems", "");
std::stringstream ss(itemList); std::stringstream ss(itemList);
std::string token; std::string token;
items.clear(); modRptiItems.clear();
while (std::getline(ss, token, ',')) while (std::getline(ss, token, ','))
{ {
items.push_back(std::stoul(token)); modRptiItems.push_back(std::stoul(token));
} }
} }
}; };
@@ -50,31 +50,31 @@ public:
void OnPlayerLogin(Player* player) override void OnPlayerLogin(Player* player) override
{ {
if (!modEnabled) if (!modRptiEnabled)
{ {
return; return;
} }
if (modAnnounce) if (modRptiAnnounce)
{ {
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 (!modEnabled) if (!modRptiEnabled)
{ {
return; return;
} }
uint32 intervalMs = rewardIntervalMinutes * SECOND * IN_MILLISECONDS; uint32 intervalMs = modRptiRewardIntervalMinutes * SECOND * IN_MILLISECONDS;
ObjectGuid guid = player->GetGUID(); ObjectGuid guid = player->GetGUID();
auto player_timer = timers.find(guid); auto player_timer = modRptiTimers.find(guid);
if (player_timer == timers.end()) if (player_timer == modRptiTimers.end())
{ {
return; // player not tracked return; // player not tracked
} }
@@ -92,14 +92,14 @@ public:
player_timer->second = 0; // reset timer player_timer->second = 0; // reset timer
if (items.empty()) if (modRptiItems.empty())
{ {
LOG_WARN("module", "[RewardPlayedTime]: RewardItems list could not be parsed. Check your config!"); 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); int32 roll = urand(0, modRptiItems.size() - 1);
uint32 rewardItemId = items[roll]; uint32 rewardItemId = modRptiItems[roll];
SendRewardToPlayer(player, rewardItemId, 1); SendRewardToPlayer(player, rewardItemId, 1);
} }
@@ -150,11 +150,11 @@ public:
void OnPlayerLogout(Player* player) override void OnPlayerLogout(Player* player) override
{ {
if (!modEnabled) { if (!modRptiEnabled) {
return; return;
} }
timers.erase(player->GetGUID()); modRptiTimers.erase(player->GetGUID());
} }
}; };