Merge pull request #19 from anzz1/patch-1

Update reward_system.cpp
This commit is contained in:
Stefano Borzì
2022-01-09 14:43:34 +01:00
committed by GitHub

View File

@@ -17,20 +17,20 @@ class reward_system : public PlayerScript
public: public:
reward_system() : PlayerScript("reward_system") {} reward_system() : PlayerScript("reward_system") {}
uint32 initialTimer = (sConfigMgr->GetIntDefault("RewardTime", 1) * HOUR * IN_MILLISECONDS); uint32 initialTimer = (sConfigMgr->GetOption<uint32>("RewardTime", 1) * HOUR * IN_MILLISECONDS);
uint32 RewardTimer = initialTimer; uint32 RewardTimer = initialTimer;
int32 roll; int32 roll;
void OnLogin(Player* player) override void OnLogin(Player* player) override
{ {
if (sConfigMgr->GetBoolDefault("RewardSystem.Announce", true)) { if (sConfigMgr->GetOption<bool>("RewardSystemEnable", true) && sConfigMgr->GetOption<bool>("RewardSystem.Announce", true)) {
ChatHandler(player->GetSession()).SendSysMessage("This server is running the |cff4CFF00Reward Time Played |rmodule."); ChatHandler(player->GetSession()).SendSysMessage("This server is running the |cff4CFF00Reward Time Played |rmodule.");
} }
} }
void OnBeforeUpdate(Player* player, uint32 p_time) override void OnBeforeUpdate(Player* player, uint32 p_time) override
{ {
if (sConfigMgr->GetBoolDefault("RewardSystemEnable", true)) if (sConfigMgr->GetOption<bool>("RewardSystemEnable", true))
{ {
if (RewardTimer > 0) if (RewardTimer > 0)
{ {
@@ -40,6 +40,7 @@ public:
if (RewardTimer <= p_time) if (RewardTimer <= p_time)
{ {
roll = urand(1, Max_roll); roll = urand(1, Max_roll);
// TODO: this should use a asynchronous query with a callback instead of a synchronous, blocking query
QueryResult result = CharacterDatabase.PQuery("SELECT item, quantity FROM reward_system WHERE roll = '%u'", roll); QueryResult result = CharacterDatabase.PQuery("SELECT item, quantity FROM reward_system WHERE roll = '%u'", roll);
if (!result) if (!result)
@@ -81,7 +82,7 @@ public:
std::string receiverName; std::string receiverName;
std::string subject = "Reward System prize"; std::string subject = "Reward System prize";
std::string text = "Congratulations, you won a prize but your inventory was full. Please take your items when you will free space from your inventory"; std::string text = "Congratulations, you won a prize!";
ItemTemplate const* item_proto = sObjectMgr->GetItemTemplate(itemId); ItemTemplate const* item_proto = sObjectMgr->GetItemTemplate(itemId);
@@ -148,7 +149,7 @@ public:
void OnBeforeConfigLoad(bool reload) override void OnBeforeConfigLoad(bool reload) override
{ {
if (!reload) { if (!reload) {
Max_roll = sConfigMgr->GetIntDefault("MaxRoll", 1000); Max_roll = sConfigMgr->GetOption<uint32>("MaxRoll", 1000);
} }
} }
}; };