mirror of
https://github.com/noisiver/mod-weekendbonus.git
synced 2026-01-13 00:58:36 +00:00
Announcement
Change the announcement of the weekend bonus to be every hour instead of on player login.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
#include "mod_weekendbonus.h"
|
#include "mod_weekendbonus.h"
|
||||||
|
|
||||||
WeekendBonus::WeekendBonus() : PlayerScript("WeekendBonusPlayerScript"), WorldScript("WeekendBonusWorldScript") {}
|
WeekendBonus::WeekendBonus() : WorldScript("WeekendBonusWorldScript") {}
|
||||||
|
|
||||||
void Addmod_weekendbonusScripts()
|
void Addmod_weekendbonusScripts()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -17,14 +17,11 @@ enum Day
|
|||||||
SATURDAY
|
SATURDAY
|
||||||
};
|
};
|
||||||
|
|
||||||
class WeekendBonus : public PlayerScript, WorldScript
|
class WeekendBonus : public WorldScript
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WeekendBonus();
|
WeekendBonus();
|
||||||
|
|
||||||
// PlayerScript
|
|
||||||
void OnLogin(Player* /*player*/) override;
|
|
||||||
|
|
||||||
// WorldScript
|
// WorldScript
|
||||||
void OnAfterConfigLoad(bool /*reload*/) override;
|
void OnAfterConfigLoad(bool /*reload*/) override;
|
||||||
void OnStartup() override;
|
void OnStartup() override;
|
||||||
@@ -36,6 +33,10 @@ private:
|
|||||||
|
|
||||||
bool Triggered;
|
bool Triggered;
|
||||||
time_t LocalTime;
|
time_t LocalTime;
|
||||||
|
Milliseconds CheckFrequency;
|
||||||
|
Milliseconds CheckTime;
|
||||||
|
Milliseconds AnnouncementFrequency;
|
||||||
|
Milliseconds AnnouncementTime;
|
||||||
|
|
||||||
float ExperienceMultiplier;
|
float ExperienceMultiplier;
|
||||||
float MoneyMultiplier;
|
float MoneyMultiplier;
|
||||||
|
|||||||
@@ -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()
|
void WeekendBonus::LoadDefaultValues()
|
||||||
{
|
{
|
||||||
DefaultExperienceMultiplier[0] = sWorld->getRate(RATE_XP_KILL);
|
DefaultExperienceMultiplier[0] = sWorld->getRate(RATE_XP_KILL);
|
||||||
@@ -66,6 +39,9 @@ void WeekendBonus::LoadDefaultValues()
|
|||||||
DefaultReputationMultiplier = sWorld->getRate(RATE_REPUTATION_GAIN);
|
DefaultReputationMultiplier = sWorld->getRate(RATE_REPUTATION_GAIN);
|
||||||
DefaultProficienciesMultiplier[0] = sWorld->getIntConfig(CONFIG_SKILL_GAIN_DEFENSE);
|
DefaultProficienciesMultiplier[0] = sWorld->getIntConfig(CONFIG_SKILL_GAIN_DEFENSE);
|
||||||
DefaultProficienciesMultiplier[1] = sWorld->getIntConfig(CONFIG_SKILL_GAIN_WEAPON);
|
DefaultProficienciesMultiplier[1] = sWorld->getIntConfig(CONFIG_SKILL_GAIN_WEAPON);
|
||||||
|
|
||||||
|
CheckFrequency = 10s;
|
||||||
|
AnnouncementFrequency = 1h;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WeekendBonus::SetRates(bool active)
|
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_DEFENSE, DefaultProficienciesMultiplier[0]);
|
||||||
sWorld->setIntConfig(CONFIG_SKILL_GAIN_WEAPON, DefaultProficienciesMultiplier[1]);
|
sWorld->setIntConfig(CONFIG_SKILL_GAIN_WEAPON, DefaultProficienciesMultiplier[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Triggered = active;
|
||||||
|
AnnouncementTime = 0s;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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!");
|
|
||||||
}
|
|
||||||
42
src/mod_weekendbonus_world.cpp
Normal file
42
src/mod_weekendbonus_world.cpp
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user