feat(Core/Events): update holiday code and remove misleading log (event date is the one from game_event) (#3365)
Cherry-picked https://github.com/TrinityCore/TrinityCore/commit/5b4287e6832da32539a49e68f6a5ab0ee55854b3 Co-authored-by: ariel- <ariel-@users.noreply.github.com> Co-authored-by: Kitzunu <24550914+Kitzunu@users.noreply.github.com>
This commit is contained in:
@@ -24,7 +24,6 @@
|
||||
#include "World.h"
|
||||
#include "Transport.h"
|
||||
#include "AccountMgr.h"
|
||||
|
||||
#ifdef ELUNA
|
||||
#include "LuaEngine.h"
|
||||
#endif
|
||||
@@ -1191,6 +1190,7 @@ GameObject* GameObject::LookupFishingHoleAround(float range)
|
||||
{
|
||||
GameObject* ok = nullptr;
|
||||
|
||||
|
||||
CellCoord p(acore::ComputeCellCoord(GetPositionX(), GetPositionY()));
|
||||
Cell cell(p);
|
||||
acore::NearestGameObjectFishingHole u_check(*this, range);
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "LuaEngine.h"
|
||||
#endif
|
||||
#include <time.h>
|
||||
#include "Util.h"
|
||||
|
||||
GameEventMgr* GameEventMgr::instance()
|
||||
{
|
||||
@@ -1015,7 +1016,12 @@ void GameEventMgr::LoadHolidayDates()
|
||||
if (uint32 duration = fields[3].GetUInt32())
|
||||
entry->Duration[0] = duration;
|
||||
|
||||
modifiedHolidays.insert(entry->Id);
|
||||
auto itr = std::lower_bound(modifiedHolidays.begin(), modifiedHolidays.end(), entry->Id);
|
||||
if (itr == modifiedHolidays.end() || *itr != entry->Id)
|
||||
{
|
||||
modifiedHolidays.insert(itr, entry->Id);
|
||||
}
|
||||
|
||||
++count;
|
||||
|
||||
} while (result->NextRow());
|
||||
@@ -1753,8 +1759,10 @@ void GameEventMgr::SetHolidayEventTime(GameEventData& event)
|
||||
event.length = holiday->Duration[stageIndex] * HOUR / MINUTE;
|
||||
|
||||
time_t stageOffset = 0;
|
||||
for (int i = 0; i < stageIndex; ++i)
|
||||
for (uint8 i = 0; i < stageIndex; ++i)
|
||||
{
|
||||
stageOffset += holiday->Duration[i] * HOUR;
|
||||
}
|
||||
|
||||
switch (holiday->CalendarFilterType)
|
||||
{
|
||||
@@ -1773,44 +1781,62 @@ void GameEventMgr::SetHolidayEventTime(GameEventData& event)
|
||||
if (holiday->Looping)
|
||||
{
|
||||
event.occurence = 0;
|
||||
for (int i = 0; i < MAX_HOLIDAY_DURATIONS && holiday->Duration[i]; ++i)
|
||||
for (uint8 i = 0; i < MAX_HOLIDAY_DURATIONS && holiday->Duration[i]; ++i)
|
||||
{
|
||||
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 = time(nullptr);
|
||||
for (int i = 0; i < MAX_HOLIDAY_DATES && holiday->Date[i]; ++i)
|
||||
for (uint8 i = 0; i < MAX_HOLIDAY_DATES && holiday->Date[i]; ++i)
|
||||
|
||||
{
|
||||
uint32 date = holiday->Date[i];
|
||||
|
||||
tm timeInfo;
|
||||
if (singleDate)
|
||||
timeInfo.tm_year = localtime(&curTime)->tm_year - 1; // First try last year (event active through New Year)
|
||||
{
|
||||
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_isdst = -1;
|
||||
tm tmCopy = timeInfo;
|
||||
|
||||
// try to get next start time (skip past dates)
|
||||
time_t startTime = mktime(&timeInfo);
|
||||
if (curTime < startTime + event.length * MINUTE)
|
||||
{
|
||||
event.start = startTime + stageOffset;
|
||||
return;
|
||||
break;
|
||||
}
|
||||
else if (singleDate)
|
||||
{
|
||||
tmCopy.tm_year = localtime(&curTime)->tm_year; // This year
|
||||
tm tmCopy;
|
||||
localtime_r(&curTime, &tmCopy);
|
||||
int year = tmCopy.tm_year; // This year
|
||||
tmCopy = timeInfo;
|
||||
tmCopy.tm_year = year;
|
||||
event.start = mktime(&tmCopy) + stageOffset;
|
||||
return;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
// date is due and not a singleDate event, try with next DBC date (modified by holiday_dates)
|
||||
// if none is found we don't modify start date and use the one in game_event
|
||||
}
|
||||
|
||||
}
|
||||
sLog->outString("No suitable start date found for holiday %u.", event.holiday_id);
|
||||
}
|
||||
|
||||
bool IsHolidayActive(HolidayIds id)
|
||||
|
||||
@@ -105,9 +105,7 @@ class GameEventMgr
|
||||
bool StartEvent(uint16 event_id, bool overwrite = false);
|
||||
void StopEvent(uint16 event_id, bool overwrite = false);
|
||||
void HandleQuestComplete(uint32 quest_id); // called on world event type quest completions
|
||||
void HandleWorldEventGossip(Player* player, Creature* c);
|
||||
uint32 GetNPCFlag(Creature* cr);
|
||||
uint32 GetNpcTextId(uint32 guid);
|
||||
private:
|
||||
void SendWorldStateUpdate(Player* player, uint16 event_id);
|
||||
void AddActiveEvent(uint16 event_id) { m_ActiveEvents.insert(event_id); }
|
||||
@@ -164,7 +162,7 @@ class GameEventMgr
|
||||
public:
|
||||
GameEventGuidMap mGameEventCreatureGuids;
|
||||
GameEventGuidMap mGameEventGameobjectGuids;
|
||||
std::set<uint32> modifiedHolidays;
|
||||
std::vector<uint32> modifiedHolidays;
|
||||
};
|
||||
|
||||
#define sGameEventMgr GameEventMgr::instance()
|
||||
|
||||
@@ -2129,4 +2129,3 @@ typedef std::vector<TaxiPathNodeList> TaxiPathNodesByPath;
|
||||
#define TaxiMaskSize 14
|
||||
typedef uint32 TaxiMask[TaxiMaskSize];
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user