Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions conf/mod-cta-switch.conf.dist
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ ModCTASwitch.SwitchAV = 18
ModCTASwitch.SwitchEots = 19
ModCTASwitch.SwitchSota = 20
ModCTASwitch.SwitchIoc = 18
ModCTASwitch.DailyCTA = 1
54 changes: 40 additions & 14 deletions src/mod_cta_switch_script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ enum EventIds
EVENT_CTA_EYE_OF_THE_STORM = 21,
EVENT_CTA_STRAND_OF_THE_ANCIENTS = 53,
EVENT_CTA_ISLE_OF_CONQUEST = 54,
EVENT_HOURLY_BELLS = 73,
};

class cta_switch_event_script : public GameEventScript
Expand Down Expand Up @@ -110,6 +111,28 @@ class cta_switch_event_script : public GameEventScript

sGameEventMgr->StopEvent(eventId, true);
sGameEventMgr->StartEvent(sConfigMgr->GetOption<int>("ModCTASwitch.SwitchIoc", EVENT_CTA_ALTERAC_VALLEY), true);
break;
case EVENT_HOURLY_BELLS:
if (!sConfigMgr->GetOption<bool>("ModCTASwitch.DailyCTA", false))
return;

time_t t = time(nullptr);
tm* now = localtime(&t);

// Exclude Friday (5), Saturday (6), Sunday (0), and Monday (1)
if (now->tm_wday == 5 || now->tm_wday == 6 || now->tm_wday == 0 || now->tm_wday == 1)
return;

if (!sGameEventMgr->IsActiveEvent(EVENT_CTA_ALTERAC_VALLEY) &&
!sGameEventMgr->IsActiveEvent(EVENT_CTA_ARATHI_BASIN) &&
!sGameEventMgr->IsActiveEvent(EVENT_CTA_WARSONG_GULCH) &&
!sGameEventMgr->IsActiveEvent(EVENT_CTA_EYE_OF_THE_STORM) &&
!sGameEventMgr->IsActiveEvent(EVENT_CTA_ISLE_OF_CONQUEST) &&
!sGameEventMgr->IsActiveEvent(EVENT_CTA_STRAND_OF_THE_ANCIENTS))
{
sGameEventMgr->StartEvent(urand(EVENT_CTA_WARSONG_GULCH, EVENT_CTA_EYE_OF_THE_STORM), true);
}

break;
}
}
Expand All @@ -119,31 +142,34 @@ class cta_switch_event_script : public GameEventScript
if (!sConfigMgr->GetOption<int>("ModCTASwitch.Enable", 0))
return;

if (sConfigMgr->GetOption<bool>("ModCTASwitch.DailyCTA", false))
return;

time_t t = time(nullptr);
tm* now = localtime(&t);

if (now->tm_wday != 2 /* Tuesday */)
return;

std::vector<uint16> eventIds = { EVENT_CTA_ALTERAC_VALLEY, EVENT_CTA_ARATHI_BASIN, EVENT_CTA_WARSONG_GULCH,
EVENT_CTA_EYE_OF_THE_STORM, EVENT_CTA_ISLE_OF_CONQUEST, EVENT_CTA_STRAND_OF_THE_ANCIENTS };

for (uint16 const& activeEvent : eventIds)
{
if (sGameEventMgr->IsActiveEvent(activeEvent))
{
time_t t = time(nullptr);
tm* now = localtime(&t);
GameEventMgr::GameEventDataMap const& events = sGameEventMgr->GetEventMap();

if (now->tm_wday == 2 /* Tuesday */)
if (std::size_t(activeEvent) >= events.size())
{
GameEventMgr::GameEventDataMap const& events = sGameEventMgr->GetEventMap();

if (std::size_t(activeEvent) >= events.size())
{
LOG_ERROR("module", "[CTA-Switch]: Error, tried to stop unexisting event. ID: {}", activeEvent);
return;
}
LOG_ERROR("module", "[CTA-Switch]: Error, tried to stop unexisting event. ID: {}", activeEvent);
return;
}

GameEventData const& eventData = events[activeEvent];
GameEventData const& eventData = events[activeEvent];

sGameEventMgr->StopEvent(activeEvent, true);
LOG_INFO("module", "[CTA-Switch]: Stopping {} ({})", eventData.Description, activeEvent);
}
sGameEventMgr->StopEvent(activeEvent, true);
LOG_INFO("module", "[CTA-Switch]: Stopping {} ({})", eventData.Description, activeEvent);
}
}
}
Expand Down