Scheduled announcements

Added some scheduled announcements to tell players when the weekend bonus starts and ends.

I couldn't find a reliable way of doing this using the TaskScheduler, so I just made this for now. If I figure out a better way of doing it, I'll change it. If I find out this is plain horrible, I'll remove it.
This commit is contained in:
Revision
2021-12-10 02:38:01 +01:00
parent c611a947ea
commit 7ce010eb82

View File

@@ -37,15 +37,15 @@ class WeekendBonus : public PlayerScript
{
if (multiplierExperience > 1 && multiplierReputation > 1)
{
ChatHandler(player->GetSession()).SendSysMessage("The weekend bonus is active, increasing the experience and reputation received!");
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 received!");
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 received!");
ChatHandler(player->GetSession()).SendSysMessage("The weekend bonus is active, increasing the reputation gained!");
}
}
}
@@ -63,8 +63,68 @@ class WeekendBonusConfig : WorldScript
}
};
class WeekendBonusAnnouncement : WorldScript
{
public:
WeekendBonusAnnouncement() : WorldScript("WeekendBonusAnnouncement") {}
void OnStartup() override
{
triggered = false;
}
void OnUpdate(uint32 diff) override
{
DoAnnouncements();
}
private:
bool triggered;
time_t localTime;
void DoAnnouncements()
{
localTime = time(NULL);
if (localtime(&localTime)->tm_wday == 5 /*Friday*/ && localtime(&localTime)->tm_hour == 0 && localtime(&localTime)->tm_min == 0)
{
if (!triggered)
{
if (multiplierExperience > 1 && multiplierReputation > 1)
{
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 == 1 /*Monday*/ && localtime(&localTime)->tm_hour == 0 && localtime(&localTime)->tm_min == 0)
{
if (!triggered)
{
sWorld->SendServerMessage(SERVER_MSG_STRING, "The weekend bonus is no longer active.");
triggered = true;
}
}
else
{
if (triggered)
triggered = false;
}
}
};
void AddWeekendBonusScripts()
{
new WeekendBonus();
new WeekendBonusConfig();
new WeekendBonusAnnouncement();
}