diff --git a/src/RPT_loader.cpp b/src/RPT_loader.cpp index 367cd1d..ac06373 100644 --- a/src/RPT_loader.cpp +++ b/src/RPT_loader.cpp @@ -2,12 +2,8 @@ * Copyright (C) 2016+ AzerothCore , released under GNU AGPL v3 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-AGPL3 */ -// From SC 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() { AddRewardPlayedTimeScripts(); diff --git a/src/RewardPlayedTime.cpp b/src/RewardPlayedTime.cpp index f0c6245..b652dc1 100644 --- a/src/RewardPlayedTime.cpp +++ b/src/RewardPlayedTime.cpp @@ -7,24 +7,54 @@ #include "Config.h" #include "Chat.h" +bool modEnabled; +bool modAnnounce; +uint32 rewardIntervalMinutes; + +// std::vector> RewardItems; +std::vector items; +std::unordered_map timers; + + +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 + { + modEnabled = sConfigMgr->GetOption("RewardPlayedTime.Enable", true); + modAnnounce = sConfigMgr->GetOption("RewardPlayedTime.Announce", true); + rewardIntervalMinutes = sConfigMgr->GetOption("RewardPlayedTime.RewardInterval", 3600); + + // Get reward list + std::string itemList = sConfigMgr->GetOption("RewardPlayedTime.RewardItems", ""); + std::stringstream ss(itemList); + std::string token; + items.clear(); + while (std::getline(ss, token, ',')) + { + items.push_back(std::stoul(token)); + } + } +}; + class RewardPlayedTime : public PlayerScript { public: RewardPlayedTime() : PlayerScript("RewardPlayedTime") { } - // std::vector> RewardItems; - std::unordered_map timers; std::string mail_subject = "RewardPlayedTime"; std::string mail_body = "Congratulations! For your hard work you got a reward, keep it up!"; void OnPlayerLogin(Player* player) override { - if (!sConfigMgr->GetOption("RewardPlayedTime.Enable", true)) + if (!modEnabled) { return; } - - if (sConfigMgr->GetOption("RewardPlayedTime.Announce", true) ) + if (modAnnounce) { ChatHandler(player->GetSession()).PSendSysMessage("This server is running the |cff4CFF00Reward Time Played Improved |rmodule."); } @@ -34,12 +64,11 @@ public: void OnPlayerBeforeUpdate(Player* player, uint32 p_time) override { - if (!sConfigMgr->GetOption("RewardPlayedTime.Enable", true)) + if (!modEnabled) { return; } - uint32 rewardIntervalMinutes = sConfigMgr->GetOption("RewardPlayedTime.RewardInterval", 3600); uint32 intervalMs = rewardIntervalMinutes * SECOND * IN_MILLISECONDS; ObjectGuid guid = player->GetGUID(); @@ -63,17 +92,6 @@ public: player_timer->second = 0; // reset timer - // Get reward list - std::string itemList = sConfigMgr->GetOption("RewardPlayedTime.RewardItems", ""); - std::vector items; - - std::stringstream ss(itemList); - std::string token; - while (std::getline(ss, token, ',')) - { - items.push_back(std::stoul(token)); - } - if (items.empty()) { LOG_WARN("module", "[RewardPlayedTime]: RewardItems list could not be parsed. Check your config!"); @@ -132,7 +150,7 @@ public: void OnPlayerLogout(Player* player) override { - if (!sConfigMgr->GetOption("RewardPlayedTime.Enable", true)) { + if (!modEnabled) { return; } @@ -142,5 +160,6 @@ public: void AddRewardPlayedTimeScripts() { + new mod_reward_time_played_conf(); new RewardPlayedTime(); }