Update module

This commit is contained in:
talamortis
2018-02-13 02:01:51 +00:00
parent c9d66f03ff
commit 9b4be84789
2 changed files with 21 additions and 35 deletions

View File

@@ -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
RewardTime = 1

View File

@@ -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);
}
}
};