Announcement

Change the announcement of the weekend bonus to be every hour instead of on player login.
This commit is contained in:
Revision
2023-06-29 19:53:33 +02:00
parent 06767e418f
commit 3adce0966b
5 changed files with 54 additions and 41 deletions

View File

@@ -1,6 +1,6 @@
#include "mod_weekendbonus.h"
WeekendBonus::WeekendBonus() : PlayerScript("WeekendBonusPlayerScript"), WorldScript("WeekendBonusWorldScript") {}
WeekendBonus::WeekendBonus() : WorldScript("WeekendBonusWorldScript") {}
void Addmod_weekendbonusScripts()
{

View File

@@ -17,14 +17,11 @@ enum Day
SATURDAY
};
class WeekendBonus : public PlayerScript, WorldScript
class WeekendBonus : public WorldScript
{
public:
WeekendBonus();
// PlayerScript
void OnLogin(Player* /*player*/) override;
// WorldScript
void OnAfterConfigLoad(bool /*reload*/) override;
void OnStartup() override;
@@ -36,6 +33,10 @@ private:
bool Triggered;
time_t LocalTime;
Milliseconds CheckFrequency;
Milliseconds CheckTime;
Milliseconds AnnouncementFrequency;
Milliseconds AnnouncementTime;
float ExperienceMultiplier;
float MoneyMultiplier;

View File

@@ -20,33 +20,6 @@ void WeekendBonus::OnAfterConfigLoad(bool reload)
}
}
void WeekendBonus::OnStartup()
{
Triggered = false;
LocalTime = time(NULL);
if ((localtime(&LocalTime)->tm_wday == Day::FRIDAY && localtime(&LocalTime)->tm_hour >= 18) || localtime(&LocalTime)->tm_wday == Day::SATURDAY || localtime(&LocalTime)->tm_wday == Day::SUNDAY)
SetRates(true);
}
void WeekendBonus::OnUpdate(uint32 /*diff*/)
{
LocalTime = time(NULL);
if ((localtime(&LocalTime)->tm_wday == Day::FRIDAY && localtime(&LocalTime)->tm_hour >= 18) && !Triggered)
{
sWorld->SendServerMessage(SERVER_MSG_STRING, "The weekend bonus is now active, granting you bonuses!");
SetRates(true);
Triggered = true;
}
else if (localtime(&LocalTime)->tm_wday == Day::MONDAY && Triggered)
{
sWorld->SendServerMessage(SERVER_MSG_STRING, "The weekend bonus is no longer active.");
SetRates(false);
Triggered = false;
}
}
void WeekendBonus::LoadDefaultValues()
{
DefaultExperienceMultiplier[0] = sWorld->getRate(RATE_XP_KILL);
@@ -66,6 +39,9 @@ void WeekendBonus::LoadDefaultValues()
DefaultReputationMultiplier = sWorld->getRate(RATE_REPUTATION_GAIN);
DefaultProficienciesMultiplier[0] = sWorld->getIntConfig(CONFIG_SKILL_GAIN_DEFENSE);
DefaultProficienciesMultiplier[1] = sWorld->getIntConfig(CONFIG_SKILL_GAIN_WEAPON);
CheckFrequency = 10s;
AnnouncementFrequency = 1h;
}
void WeekendBonus::SetRates(bool active)
@@ -110,4 +86,7 @@ void WeekendBonus::SetRates(bool active)
sWorld->setIntConfig(CONFIG_SKILL_GAIN_DEFENSE, DefaultProficienciesMultiplier[0]);
sWorld->setIntConfig(CONFIG_SKILL_GAIN_WEAPON, DefaultProficienciesMultiplier[1]);
}
Triggered = active;
AnnouncementTime = 0s;
}

View File

@@ -1,9 +0,0 @@
#include "mod_weekendbonus.h"
void WeekendBonus::OnLogin(Player* player)
{
LocalTime = time(NULL);
if ((localtime(&LocalTime)->tm_wday == Day::FRIDAY && localtime(&LocalTime)->tm_hour >= 18) || localtime(&LocalTime)->tm_wday == Day::SATURDAY || localtime(&LocalTime)->tm_wday == Day::SUNDAY)
ChatHandler(player->GetSession()).SendSysMessage("The weekend bonus is active, granting you bonuses!");
}

View File

@@ -0,0 +1,42 @@
#include "mod_weekendbonus.h"
void WeekendBonus::OnStartup()
{
Triggered = false;
LocalTime = time(NULL);
if ((localtime(&LocalTime)->tm_wday == Day::FRIDAY && localtime(&LocalTime)->tm_hour >= 18) || localtime(&LocalTime)->tm_wday == Day::SATURDAY || localtime(&LocalTime)->tm_wday == Day::SUNDAY)
SetRates(true);
}
void WeekendBonus::OnUpdate(uint32 diff)
{
CheckTime += Milliseconds(diff);
if (CheckTime > CheckFrequency)
{
LocalTime = time(NULL);
if ((localtime(&LocalTime)->tm_wday == Day::FRIDAY && localtime(&LocalTime)->tm_hour >= 18) && !Triggered)
{
sWorld->SendServerMessage(SERVER_MSG_STRING, "The weekend bonus is now active, granting you bonuses!");
SetRates(true);
}
else if (localtime(&LocalTime)->tm_wday == Day::MONDAY && Triggered)
{
sWorld->SendServerMessage(SERVER_MSG_STRING, "The weekend bonus is no longer active.");
SetRates(false);
}
CheckTime = 0s;
}
if (Triggered)
{
AnnouncementTime += Milliseconds(diff);
if (AnnouncementTime > AnnouncementFrequency)
{
sWorld->SendServerMessage(SERVER_MSG_STRING, "The weekend bonus is active, granting you bonuses!");
AnnouncementTime = 0s;
}
}
}