mirror of
https://github.com/noisiver/mod-weekendbonus.git
synced 2026-01-13 00:58:36 +00:00
Rewrite
Rewrote a huge chunk of the module. It will now use sWorld->setRate to handle bonuses instead of a what feels like a hacky way of doing it. It also supports giving a bonus to money looted and gained from quests.
This commit is contained in:
@@ -3,5 +3,8 @@
|
|||||||
# Multiplier for experience gains on weekends
|
# Multiplier for experience gains on weekends
|
||||||
WeekendBonus.Multiplier.Experience = 2
|
WeekendBonus.Multiplier.Experience = 2
|
||||||
|
|
||||||
|
# Multiplier for money looted and rewarded from quests on weekends
|
||||||
|
WeekendBonus.Multiplier.Money = 2
|
||||||
|
|
||||||
# Multiplier for reputation gains on weekends
|
# Multiplier for reputation gains on weekends
|
||||||
WeekendBonus.Multiplier.Reputation = 2
|
WeekendBonus.Multiplier.Reputation = 2
|
||||||
|
|||||||
@@ -3,8 +3,9 @@
|
|||||||
#include "Player.h"
|
#include "Player.h"
|
||||||
#include "ScriptMgr.h"
|
#include "ScriptMgr.h"
|
||||||
|
|
||||||
uint32 multiplierExperience;
|
float multiplierExperience;
|
||||||
uint32 multiplierReputation;
|
float multiplierMoney;
|
||||||
|
float multiplierReputation;
|
||||||
|
|
||||||
enum Day
|
enum Day
|
||||||
{
|
{
|
||||||
@@ -22,42 +23,13 @@ class WeekendBonusPlayer : public PlayerScript
|
|||||||
public:
|
public:
|
||||||
WeekendBonusPlayer() : PlayerScript("WeekendBonusPlayer") {}
|
WeekendBonusPlayer() : PlayerScript("WeekendBonusPlayer") {}
|
||||||
|
|
||||||
void OnGiveXP(Player* player, uint32& amount, Unit* /*victim*/) override
|
|
||||||
{
|
|
||||||
time_t t = time(NULL);
|
|
||||||
|
|
||||||
if (localtime(&t)->tm_wday == Day::FRIDAY || localtime(&t)->tm_wday == Day::SATURDAY || localtime(&t)->tm_wday == Day::SUNDAY)
|
|
||||||
if (multiplierExperience > 1)
|
|
||||||
amount *= multiplierExperience;
|
|
||||||
}
|
|
||||||
|
|
||||||
void OnReputationChange(Player* player, uint32 /*factionId*/, int32& standing, bool /*incremental*/) override
|
|
||||||
{
|
|
||||||
time_t t = time(NULL);
|
|
||||||
|
|
||||||
if (localtime(&t)->tm_wday == Day::FRIDAY || localtime(&t)->tm_wday == Day::SATURDAY || localtime(&t)->tm_wday == Day::SUNDAY)
|
|
||||||
if (multiplierReputation > 1)
|
|
||||||
standing *= multiplierReputation;
|
|
||||||
}
|
|
||||||
|
|
||||||
void OnLogin(Player* player) override
|
void OnLogin(Player* player) override
|
||||||
{
|
{
|
||||||
time_t t = time(NULL);
|
time_t t = time(NULL);
|
||||||
|
|
||||||
if (localtime(&t)->tm_wday == Day::FRIDAY || localtime(&t)->tm_wday == Day::SATURDAY || localtime(&t)->tm_wday == Day::SUNDAY)
|
if (localtime(&t)->tm_wday == Day::FRIDAY || localtime(&t)->tm_wday == Day::SATURDAY || localtime(&t)->tm_wday == Day::SUNDAY)
|
||||||
{
|
{
|
||||||
if (multiplierExperience > 1 && multiplierReputation > 1)
|
ChatHandler(player->GetSession()).SendSysMessage("The weekend bonus is active, granting you bonuses to experience, reputation and money!");
|
||||||
{
|
|
||||||
ChatHandler(player->GetSession()).SendSysMessage("The weekend bonus is active, increasing the experience and reputation gained!");
|
|
||||||
}
|
|
||||||
else if (multiplierExperience > 1)
|
|
||||||
{
|
|
||||||
ChatHandler(player->GetSession()).SendSysMessage("The weekend bonus is active, increasing the experience gained!");
|
|
||||||
}
|
|
||||||
else if (multiplierReputation > 1)
|
|
||||||
{
|
|
||||||
ChatHandler(player->GetSession()).SendSysMessage("The weekend bonus is active, increasing the reputation gained!");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -69,25 +41,30 @@ class WeekendBonusWorld : WorldScript
|
|||||||
|
|
||||||
void OnAfterConfigLoad(bool /*reload*/) override
|
void OnAfterConfigLoad(bool /*reload*/) override
|
||||||
{
|
{
|
||||||
multiplierExperience = sConfigMgr->GetOption<int32>("WeekendBonus.Multiplier.Experience", 1);
|
multiplierExperience = sConfigMgr->GetOption<float>("WeekendBonus.Multiplier.Experience", 2.0f);
|
||||||
multiplierReputation = sConfigMgr->GetOption<int32>("WeekendBonus.Multiplier.Reputation", 1);
|
multiplierMoney = sConfigMgr->GetOption<float>("WeekendBonus.Multiplier.Money", 2.0f);
|
||||||
|
multiplierReputation = sConfigMgr->GetOption<float>("WeekendBonus.Multiplier.Reputation", 2.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnStartup() override
|
void OnStartup() override
|
||||||
{
|
{
|
||||||
triggered = false;
|
triggered = false;
|
||||||
|
localTime = time(NULL);
|
||||||
|
|
||||||
|
if (localtime(&localTime)->tm_wday == Day::FRIDAY || localtime(&localTime)->tm_wday == Day::SATURDAY || localtime(&localTime)->tm_wday == Day::SUNDAY)
|
||||||
|
SetWorldRates();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnUpdate(uint32 diff) override
|
void OnUpdate(uint32 diff) override
|
||||||
{
|
{
|
||||||
DoAnnouncements();
|
HandleWeekendBonuses();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool triggered;
|
bool triggered;
|
||||||
time_t localTime;
|
time_t localTime;
|
||||||
|
|
||||||
void DoAnnouncements()
|
void HandleWeekendBonuses()
|
||||||
{
|
{
|
||||||
localTime = time(NULL);
|
localTime = time(NULL);
|
||||||
|
|
||||||
@@ -95,34 +72,45 @@ class WeekendBonusWorld : WorldScript
|
|||||||
{
|
{
|
||||||
if (!triggered)
|
if (!triggered)
|
||||||
{
|
{
|
||||||
if (multiplierExperience > 1 && multiplierReputation > 1)
|
sWorld->SendServerMessage(SERVER_MSG_STRING, "The weekend bonus is now active, granting you bonuses to experience, reputation and money!");
|
||||||
{
|
SetWorldRates();
|
||||||
sWorld->SendServerMessage(SERVER_MSG_STRING, "The weekend bonus is now active, increasing the experience and reputation gained!");
|
|
||||||
}
|
|
||||||
else if (multiplierExperience > 1)
|
|
||||||
{
|
|
||||||
sWorld->SendServerMessage(SERVER_MSG_STRING, "The weekend bonus is now active, increasing the experience gained!");
|
|
||||||
}
|
|
||||||
else if (multiplierReputation > 1)
|
|
||||||
{
|
|
||||||
sWorld->SendServerMessage(SERVER_MSG_STRING, "The weekend bonus is now active, increasing the reputation gained!");
|
|
||||||
}
|
|
||||||
|
|
||||||
triggered = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (localtime(&localTime)->tm_wday == Day::MONDAY && localtime(&localTime)->tm_hour == 0 && localtime(&localTime)->tm_min == 0)
|
else if (localtime(&localTime)->tm_wday == Day::MONDAY && localtime(&localTime)->tm_hour == 0 && localtime(&localTime)->tm_min == 0)
|
||||||
{
|
{
|
||||||
if (!triggered)
|
if (triggered)
|
||||||
{
|
{
|
||||||
sWorld->SendServerMessage(SERVER_MSG_STRING, "The weekend bonus is no longer active.");
|
sWorld->SendServerMessage(SERVER_MSG_STRING, "The weekend bonus is no longer active.");
|
||||||
triggered = true;
|
SetWorldRates();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetWorldRates()
|
||||||
|
{
|
||||||
|
if (!triggered)
|
||||||
|
{
|
||||||
|
sWorld->setRate(RATE_XP_KILL, sWorld->getRate(RATE_XP_KILL) * multiplierExperience);
|
||||||
|
sWorld->setRate(RATE_XP_BG_KILL, sWorld->getRate(RATE_XP_BG_KILL) * multiplierExperience);
|
||||||
|
sWorld->setRate(RATE_XP_QUEST, sWorld->getRate(RATE_XP_QUEST) * multiplierExperience);
|
||||||
|
sWorld->setRate(RATE_XP_QUEST_DF, sWorld->getRate(RATE_XP_QUEST_DF) * multiplierExperience);
|
||||||
|
sWorld->setRate(RATE_XP_EXPLORE, sWorld->getRate(RATE_XP_EXPLORE) * multiplierExperience);
|
||||||
|
sWorld->setRate(RATE_XP_PET, sWorld->getRate(RATE_XP_PET) * multiplierExperience);
|
||||||
|
sWorld->setRate(RATE_DROP_MONEY, sWorld->getRate(RATE_DROP_MONEY) * multiplierMoney);
|
||||||
|
sWorld->setRate(RATE_REPUTATION_GAIN, sWorld->getRate(RATE_REPUTATION_GAIN) * multiplierReputation);
|
||||||
|
triggered = true;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (triggered)
|
sWorld->setRate(RATE_XP_KILL, sWorld->getRate(RATE_XP_KILL) / multiplierExperience);
|
||||||
triggered = false;
|
sWorld->setRate(RATE_XP_BG_KILL, sWorld->getRate(RATE_XP_BG_KILL) / multiplierExperience);
|
||||||
|
sWorld->setRate(RATE_XP_QUEST, sWorld->getRate(RATE_XP_QUEST) / multiplierExperience);
|
||||||
|
sWorld->setRate(RATE_XP_QUEST_DF, sWorld->getRate(RATE_XP_QUEST_DF) / multiplierExperience);
|
||||||
|
sWorld->setRate(RATE_XP_EXPLORE, sWorld->getRate(RATE_XP_EXPLORE) / multiplierExperience);
|
||||||
|
sWorld->setRate(RATE_XP_PET, sWorld->getRate(RATE_XP_PET) / multiplierExperience);
|
||||||
|
sWorld->setRate(RATE_DROP_MONEY, sWorld->getRate(RATE_DROP_MONEY) / multiplierMoney);
|
||||||
|
sWorld->setRate(RATE_REPUTATION_GAIN, sWorld->getRate(RATE_REPUTATION_GAIN) / multiplierReputation);
|
||||||
|
triggered = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user