From 34c7316fafd12ddc5929585e5f544237d633600f Mon Sep 17 00:00:00 2001 From: talamortis Date: Sun, 11 Feb 2018 15:42:41 +0000 Subject: [PATCH 1/4] Added more options to reward system. Players now can change the min and max time the roll will take place. --- conf/reward_system.conf.dist | 16 +++++++++++- src/reward_system.cpp | 50 +++++++++++++++++++++--------------- 2 files changed, 45 insertions(+), 21 deletions(-) diff --git a/conf/reward_system.conf.dist b/conf/reward_system.conf.dist index 2672644..83f331e 100644 --- a/conf/reward_system.conf.dist +++ b/conf/reward_system.conf.dist @@ -12,4 +12,18 @@ RewardSystemEnable = 1 # Description: Can alter the max roll for players # Default: 1000 - (Enabled) # -MaxRoll = 1000 \ No newline at end of file +MaxRoll = 1000 + +# +# MinTime +# Description: Min Time in Hours before the random roll will take place +# Default: 2 +# +MinTime = 2 + +# +# MaxTime +# Description: Max Time in Hours before the random roll will take place +# Default: 4 +# +MaxTime = 4 \ No newline at end of file diff --git a/src/reward_system.cpp b/src/reward_system.cpp index a053976..498d383 100644 --- a/src/reward_system.cpp +++ b/src/reward_system.cpp @@ -10,49 +10,57 @@ int32 roll; bool RewardSystem_Enable; uint32 Max_roll; +uint32 min_time; +uint32 max_time; class reward_system : public PlayerScript { public: reward_system() : PlayerScript("rewardsystem") {} - uint32 rewardtimer = urand(2 * HOUR*IN_MILLISECONDS, 4 * HOUR*IN_MILLISECONDS); + uint32 rewardtimer = urand(min_time * HOUR*IN_MILLISECONDS, max_time * HOUR*IN_MILLISECONDS); - void OnBeforePlayerUpdate(Player* player, uint32 p_time) + void OnBeforeUpdate(Player* player, uint32 p_time) { - - if (!RewardSystem_Enable) - return; + if (RewardSystem_Enable) { - if (rewardtimer <= p_time) + if (rewardtimer > 0) { - roll = urand(1, Max_roll); //Lets make a random number from 1 - - QueryResult result = CharacterDatabase.PQuery("SELECT item, quantity FROM reward_system WHERE roll = '%u'", roll); - rewardtimer = urand(2 * HOUR*IN_MILLISECONDS, 4 * HOUR*IN_MILLISECONDS); - - if (!result || player->isAFK()) - { + if (player->isAFK()) return; - } - else + + if (rewardtimer <= p_time) { + roll = urand(1, Max_roll); + + QueryResult result = CharacterDatabase.PQuery("SELECT item, quantity FROM reward_system WHERE roll = '%u'", roll); + + if (!result) + { + ChatHandler(player->GetSession()).PSendSysMessage("better luck next time your roll was %u", roll); + rewardtimer = urand(min_time * HOUR*IN_MILLISECONDS, max_time * HOUR*IN_MILLISECONDS); + return; + } + + //Lets now get the item + do { - //Lets now get the item Field* fields = result->Fetch(); uint32 pItem = fields[0].GetInt32(); uint32 quantity = fields[1].GetInt32(); // now lets add the item player->AddItem(pItem, quantity); - - ChatHandler(player->GetSession()).PSendSysMessage("You have rolled %u which gave you item %u", roll, pItem); - + ChatHandler(player->GetSession()).PSendSysMessage("Congratulations you have won with a roll of %u", roll); } while (result->NextRow()); + + + rewardtimer = urand(min_time * HOUR*IN_MILLISECONDS, max_time * HOUR*IN_MILLISECONDS); } + else rewardtimer -= p_time; } - else - rewardtimer -= p_time; + } } }; @@ -74,6 +82,8 @@ public: RewardSystem_Enable = sConfigMgr->GetBoolDefault("RewardSystemEnable", true); Max_roll = sConfigMgr->GetIntDefault("MaxRoll", 1000); + min_time = sConfigMgr->GetIntDefault("MinTime", 2); + max_time = sConfigMgr->GetIntDefault("MaxTime", 4); } } }; From c9d66f03ff736606d9cd0fc8c6cebadf62156f15 Mon Sep 17 00:00:00 2001 From: talamortis Date: Sun, 11 Feb 2018 17:48:55 +0000 Subject: [PATCH 2/4] added config path for linux builds --- src/reward_system.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/reward_system.cpp b/src/reward_system.cpp index 498d383..54747b2 100644 --- a/src/reward_system.cpp +++ b/src/reward_system.cpp @@ -73,7 +73,13 @@ public: void OnBeforeConfigLoad(bool reload) override { if (!reload) { - std::string cfg_file = "reward_system.conf"; + std::string conf_path = _CONF_DIR; + std::string cfg_file = conf_path + "/reward_system.conf"; + +#ifdef WIN32 + cfg_file = "reward_system.conf"; +#endif // WIN32 + std::string cfg_def_file = cfg_file + ".dist"; sConfigMgr->LoadMore(cfg_def_file.c_str()); From 9b4be84789fa4d31a05e0c801c2af6cff3c6de86 Mon Sep 17 00:00:00 2001 From: talamortis Date: Tue, 13 Feb 2018 02:01:51 +0000 Subject: [PATCH 3/4] Update module --- conf/reward_system.conf.dist | 22 ++++------------------ src/reward_system.cpp | 34 +++++++++++++++++----------------- 2 files changed, 21 insertions(+), 35 deletions(-) diff --git a/conf/reward_system.conf.dist b/conf/reward_system.conf.dist index 83f331e..e310e11 100644 --- a/conf/reward_system.conf.dist +++ b/conf/reward_system.conf.dist @@ -8,22 +8,8 @@ RewardSystemEnable = 1 # -# MaxRoll -# Description: Can alter the max roll for players -# Default: 1000 - (Enabled) +# RewardTime +# Description: Time in hours to reward the player +# Default: 1 - (Enabled) # -MaxRoll = 1000 - -# -# MinTime -# Description: Min Time in Hours before the random roll will take place -# Default: 2 -# -MinTime = 2 - -# -# MaxTime -# Description: Max Time in Hours before the random roll will take place -# Default: 4 -# -MaxTime = 4 \ No newline at end of file +RewardTime = 1 \ No newline at end of file diff --git a/src/reward_system.cpp b/src/reward_system.cpp index 54747b2..7c0db66 100644 --- a/src/reward_system.cpp +++ b/src/reward_system.cpp @@ -7,38 +7,44 @@ #include "Define.h" #include "GossipDef.h" -int32 roll; bool RewardSystem_Enable; -uint32 Max_roll; -uint32 min_time; -uint32 max_time; class reward_system : public PlayerScript { public: reward_system() : PlayerScript("rewardsystem") {} - uint32 rewardtimer = urand(min_time * HOUR*IN_MILLISECONDS, max_time * HOUR*IN_MILLISECONDS); + uint32 RewardTimer; + int32 roll; + uint32 Max_roll; + + void OnLogin(Player* p) + { + if (RewardSystem_Enable) + { + ChatHandler(p->GetSession()).SendSysMessage("This server is running the |cff4CFF00Player Reward System |rmodule."); + RewardTimer = (sConfigMgr->GetIntDefault("RewardTime", 1)*HOUR*IN_MILLISECONDS); + } + } void OnBeforeUpdate(Player* player, uint32 p_time) { if (RewardSystem_Enable) { - if (rewardtimer > 0) + if (RewardTimer > 0) { if (player->isAFK()) return; - if (rewardtimer <= p_time) + if (RewardTimer <= p_time) { roll = urand(1, Max_roll); - QueryResult result = CharacterDatabase.PQuery("SELECT item, quantity FROM reward_system WHERE roll = '%u'", roll); if (!result) { ChatHandler(player->GetSession()).PSendSysMessage("better luck next time your roll was %u", roll); - rewardtimer = urand(min_time * HOUR*IN_MILLISECONDS, max_time * HOUR*IN_MILLISECONDS); + RewardTimer = (sConfigMgr->GetIntDefault("RewardTime", 1)*HOUR*IN_MILLISECONDS); return; } @@ -56,9 +62,9 @@ public: } while (result->NextRow()); - rewardtimer = urand(min_time * HOUR*IN_MILLISECONDS, max_time * HOUR*IN_MILLISECONDS); + RewardTimer = (sConfigMgr->GetIntDefault("RewardTime", 1)*HOUR*IN_MILLISECONDS); } - else rewardtimer -= p_time; + else RewardTimer -= p_time; } } @@ -81,15 +87,9 @@ public: #endif // WIN32 std::string cfg_def_file = cfg_file + ".dist"; - sConfigMgr->LoadMore(cfg_def_file.c_str()); - sConfigMgr->LoadMore(cfg_file.c_str()); - RewardSystem_Enable = sConfigMgr->GetBoolDefault("RewardSystemEnable", true); - Max_roll = sConfigMgr->GetIntDefault("MaxRoll", 1000); - min_time = sConfigMgr->GetIntDefault("MinTime", 2); - max_time = sConfigMgr->GetIntDefault("MaxTime", 4); } } }; From 2c2e8e1c29c7b85939c71fb1fb4b087261c545a7 Mon Sep 17 00:00:00 2001 From: talamortis Date: Tue, 13 Feb 2018 11:25:24 +0000 Subject: [PATCH 4/4] Fixed crash on linux build. --- conf/reward_system.conf.dist | 9 ++++++++- src/reward_system.cpp | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/conf/reward_system.conf.dist b/conf/reward_system.conf.dist index e310e11..a929549 100644 --- a/conf/reward_system.conf.dist +++ b/conf/reward_system.conf.dist @@ -12,4 +12,11 @@ RewardSystemEnable = 1 # Description: Time in hours to reward the player # Default: 1 - (Enabled) # -RewardTime = 1 \ No newline at end of file +RewardTime = 1 + +# +# MaxRoll +# Description: Max roll the player will do +# Default: 1000 - (Enabled) +# +MaxRoll = 1000 \ No newline at end of file diff --git a/src/reward_system.cpp b/src/reward_system.cpp index 7c0db66..996a983 100644 --- a/src/reward_system.cpp +++ b/src/reward_system.cpp @@ -8,6 +8,7 @@ #include "GossipDef.h" bool RewardSystem_Enable; +uint32 Max_roll; class reward_system : public PlayerScript { @@ -16,7 +17,6 @@ public: uint32 RewardTimer; int32 roll; - uint32 Max_roll; void OnLogin(Player* p) { @@ -49,7 +49,6 @@ public: } //Lets now get the item - do { Field* fields = result->Fetch(); @@ -90,6 +89,7 @@ public: sConfigMgr->LoadMore(cfg_def_file.c_str()); sConfigMgr->LoadMore(cfg_file.c_str()); RewardSystem_Enable = sConfigMgr->GetBoolDefault("RewardSystemEnable", true); + Max_roll = sConfigMgr->GetIntDefault("MaxRoll", 1000); } } };