From 7ce010eb820302b29047c604b8b892d2fce2fc00 Mon Sep 17 00:00:00 2001 From: Revision Date: Fri, 10 Dec 2021 02:38:01 +0100 Subject: [PATCH] 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. --- src/WeekendBonus.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 3 deletions(-) diff --git a/src/WeekendBonus.cpp b/src/WeekendBonus.cpp index 14bb4c2..423722f 100644 --- a/src/WeekendBonus.cpp +++ b/src/WeekendBonus.cpp @@ -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(); }