mirror of
https://github.com/freekode/mod-reward-played-time-improved.git
synced 2026-01-13 00:28:34 +00:00
refactor
This commit is contained in:
@@ -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,24 +7,54 @@
|
|||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "Chat.h"
|
#include "Chat.h"
|
||||||
|
|
||||||
|
bool modEnabled;
|
||||||
|
bool modAnnounce;
|
||||||
|
uint32 rewardIntervalMinutes;
|
||||||
|
|
||||||
|
// std::vector<std::pair<uint32, uint32>> RewardItems;
|
||||||
|
std::vector<uint32> items;
|
||||||
|
std::unordered_map<ObjectGuid, uint32> 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<bool>("RewardPlayedTime.Enable", true);
|
||||||
|
modAnnounce = sConfigMgr->GetOption<bool>("RewardPlayedTime.Announce", true);
|
||||||
|
rewardIntervalMinutes = 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;
|
||||||
|
items.clear();
|
||||||
|
while (std::getline(ss, token, ','))
|
||||||
|
{
|
||||||
|
items.push_back(std::stoul(token));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
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 (!modEnabled)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (modAnnounce)
|
||||||
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.");
|
||||||
}
|
}
|
||||||
@@ -34,12 +64,11 @@ public:
|
|||||||
|
|
||||||
void OnPlayerBeforeUpdate(Player* player, uint32 p_time) override
|
void OnPlayerBeforeUpdate(Player* player, uint32 p_time) override
|
||||||
{
|
{
|
||||||
if (!sConfigMgr->GetOption<bool>("RewardPlayedTime.Enable", true))
|
if (!modEnabled)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 rewardIntervalMinutes = sConfigMgr->GetOption<uint32>("RewardPlayedTime.RewardInterval", 3600);
|
|
||||||
uint32 intervalMs = rewardIntervalMinutes * SECOND * IN_MILLISECONDS;
|
uint32 intervalMs = rewardIntervalMinutes * SECOND * IN_MILLISECONDS;
|
||||||
|
|
||||||
ObjectGuid guid = player->GetGUID();
|
ObjectGuid guid = player->GetGUID();
|
||||||
@@ -63,17 +92,6 @@ public:
|
|||||||
|
|
||||||
player_timer->second = 0; // reset timer
|
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (items.empty())
|
if (items.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!");
|
||||||
@@ -132,7 +150,7 @@ public:
|
|||||||
|
|
||||||
void OnPlayerLogout(Player* player) override
|
void OnPlayerLogout(Player* player) override
|
||||||
{
|
{
|
||||||
if (!sConfigMgr->GetOption<bool>("RewardPlayedTime.Enable", true)) {
|
if (!modEnabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,5 +160,6 @@ public:
|
|||||||
|
|
||||||
void AddRewardPlayedTimeScripts()
|
void AddRewardPlayedTimeScripts()
|
||||||
{
|
{
|
||||||
|
new mod_reward_time_played_conf();
|
||||||
new RewardPlayedTime();
|
new RewardPlayedTime();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user