mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-15 23:20:36 +01:00
Core/Events: Replace remaining packed time calculations with WowTime class
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
#include "StringConvert.h"
|
||||
#include "World.h"
|
||||
#include "WorldStateMgr.h"
|
||||
#include "WowTime.h"
|
||||
|
||||
GameEventMgr* GameEventMgr::instance()
|
||||
{
|
||||
@@ -1679,9 +1680,9 @@ void GameEventMgr::SetHolidayEventTime(GameEventData& event)
|
||||
uint8 stageIndex = event.holidayStage - 1;
|
||||
event.length = holiday->Duration[stageIndex] * HOUR / MINUTE;
|
||||
|
||||
time_t stageOffset = 0;
|
||||
Hours stageOffset = 0h;
|
||||
for (uint8 i = 0; i < stageIndex; ++i)
|
||||
stageOffset += holiday->Duration[i] * HOUR;
|
||||
stageOffset += Hours(holiday->Duration[i]);
|
||||
|
||||
switch (holiday->CalendarFilterType)
|
||||
{
|
||||
@@ -1704,47 +1705,25 @@ void GameEventMgr::SetHolidayEventTime(GameEventData& event)
|
||||
event.occurence += holiday->Duration[i] * HOUR / MINUTE;
|
||||
}
|
||||
|
||||
bool singleDate = ((holiday->Date[0] >> 24) & 0x1F) == 31; // Events with fixed date within year have - 1
|
||||
|
||||
time_t curTime = GameTime::GetGameTime();
|
||||
WowTime const& curTime = *GameTime::GetWowTime();
|
||||
for (uint8 i = 0; i < MAX_HOLIDAY_DATES && holiday->Date[i]; ++i)
|
||||
{
|
||||
uint32 date = holiday->Date[i];
|
||||
|
||||
tm timeInfo;
|
||||
WowTime date;
|
||||
date.SetPackedTime(holiday->Date[i]);
|
||||
bool singleDate = date.GetYear() == -1;
|
||||
if (singleDate)
|
||||
{
|
||||
localtime_r(&curTime, &timeInfo);
|
||||
timeInfo.tm_year -= 1; // First try last year (event active through New Year)
|
||||
}
|
||||
else
|
||||
timeInfo.tm_year = ((date >> 24) & 0x1F) + 100;
|
||||
|
||||
timeInfo.tm_mon = (date >> 20) & 0xF;
|
||||
timeInfo.tm_mday = ((date >> 14) & 0x3F) + 1;
|
||||
timeInfo.tm_hour = (date >> 6) & 0x1F;
|
||||
timeInfo.tm_min = date & 0x3F;
|
||||
timeInfo.tm_sec = 0;
|
||||
timeInfo.tm_wday = 0;
|
||||
timeInfo.tm_yday = 0;
|
||||
timeInfo.tm_isdst = -1;
|
||||
date.SetYear(GameTime::GetWowTime()->GetYear() - 1); // First try last year (event active through New Year)
|
||||
|
||||
// try to get next start time (skip past dates)
|
||||
time_t startTime = mktime(&timeInfo);
|
||||
if (curTime < startTime + event.length * MINUTE)
|
||||
if (curTime < date + Minutes(event.length))
|
||||
{
|
||||
event.start = startTime + stageOffset;
|
||||
event.start = (date + stageOffset).GetUnixTimeFromUtcTime();
|
||||
break;
|
||||
}
|
||||
else if (singleDate)
|
||||
{
|
||||
tm tmCopy;
|
||||
localtime_r(&curTime, &tmCopy);
|
||||
int year = tmCopy.tm_year; // This year
|
||||
tmCopy = timeInfo;
|
||||
tmCopy.tm_year = year;
|
||||
|
||||
event.start = mktime(&tmCopy) + stageOffset;
|
||||
date.SetYear(date.GetYear() + 1); // This year
|
||||
event.start = (date + stageOffset).GetUnixTimeFromUtcTime();
|
||||
break;
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user