[10534] Fixed second and later resets schedule for raid/heroic after server restart.

Signed-off-by: VladimirMangos <vladimir@getmangos.com>
This commit is contained in:
Funkybit 2010-09-25 14:07:25 +04:00 committed by VladimirMangos
parent 3b35153b7d
commit b531bcfee1
3 changed files with 31 additions and 9 deletions

View file

@ -138,6 +138,13 @@ uint32 InstanceResetScheduler::GetMaxResetTimeFor(MapDifficulty const* mapDiff)
return delay; return delay;
} }
time_t InstanceResetScheduler::CalculateNextResetTime(MapDifficulty const* mapDiff, time_t prevResetTime)
{
uint32 diff = sWorld.getConfig(CONFIG_UINT32_INSTANCE_RESET_TIME_HOUR) * HOUR;
uint32 period = GetMaxResetTimeFor(mapDiff);
return ((prevResetTime + MINUTE) / DAY * DAY) + period + diff;
}
void InstanceResetScheduler::LoadResetTimes() void InstanceResetScheduler::LoadResetTimes()
{ {
time_t now = time(NULL); time_t now = time(NULL);
@ -313,25 +320,42 @@ void InstanceResetScheduler::Update()
while(!m_resetTimeQueue.empty() && (t = m_resetTimeQueue.begin()->first) < now) while(!m_resetTimeQueue.empty() && (t = m_resetTimeQueue.begin()->first) < now)
{ {
InstanceResetEvent &event = m_resetTimeQueue.begin()->second; InstanceResetEvent &event = m_resetTimeQueue.begin()->second;
if(event.type == RESET_EVENT_DUNGEON) if (event.type == RESET_EVENT_DUNGEON)
{ {
// for individual normal instances, max creature respawn + X hours // for individual normal instances, max creature respawn + X hours
m_InstanceSaves._ResetInstance(event.mapid, event.instanceId); m_InstanceSaves._ResetInstance(event.mapid, event.instanceId);
m_resetTimeQueue.erase(m_resetTimeQueue.begin());
} }
else else
{ {
// global reset/warning for a certain map // global reset/warning for a certain map
time_t resetTime = GetResetTimeFor(event.mapid,event.difficulty); time_t resetTime = GetResetTimeFor(event.mapid,event.difficulty);
m_InstanceSaves._ResetOrWarnAll(event.mapid, event.difficulty, event.type != RESET_EVENT_INFORM_LAST, uint32(resetTime - now)); m_InstanceSaves._ResetOrWarnAll(event.mapid, event.difficulty, event.type != RESET_EVENT_INFORM_LAST, uint32(resetTime - now));
if(event.type != RESET_EVENT_INFORM_LAST) if (event.type != RESET_EVENT_INFORM_LAST)
{ {
// schedule the next warning/reset // schedule the next warning/reset
event.type = ResetEventType(event.type+1); event.type = ResetEventType(event.type+1);
ScheduleReset(true, resetTime - resetEventTypeDelay[event.type], event); ScheduleReset(true, resetTime - resetEventTypeDelay[event.type], event);
} }
m_resetTimeQueue.erase(m_resetTimeQueue.begin()); else
{
// re-schedule the next/new global reset/warning
// calculate the next reset time
MapDifficulty const* mapDiff = GetMapDifficultyData(event.mapid,event.difficulty);
MANGOS_ASSERT(mapDiff);
time_t next_reset = InstanceResetScheduler::CalculateNextResetTime(mapDiff, resetTime);
ResetEventType type = RESET_EVENT_INFORM_1;
for (; type < RESET_EVENT_INFORM_LAST; type = ResetEventType(type+1))
if (next_reset - resetEventTypeDelay[type] > now)
break;
// add new scheduler event to the queue
event.type = type;
ScheduleReset(true, next_reset - resetEventTypeDelay[event.type], event);
}
} }
m_resetTimeQueue.erase(m_resetTimeQueue.begin());
} }
} }
@ -605,9 +629,7 @@ void InstanceSaveManager::_ResetOrWarnAll(uint32 mapid, Difficulty difficulty, b
CharacterDatabase.CommitTransaction(); CharacterDatabase.CommitTransaction();
// calculate the next reset time // calculate the next reset time
uint32 diff = sWorld.getConfig(CONFIG_UINT32_INSTANCE_RESET_TIME_HOUR) * HOUR; time_t next_reset = InstanceResetScheduler::CalculateNextResetTime(mapDiff, now + timeLeft);
uint32 period = InstanceResetScheduler::GetMaxResetTimeFor(mapDiff);
time_t next_reset = ((now + timeLeft + MINUTE) / DAY * DAY) + period + diff;
// update it in the DB // update it in the DB
CharacterDatabase.PExecute("UPDATE instance_reset SET resettime = '"UI64FMTD"' WHERE mapid = '%d' AND difficulty = '%d'", (uint64)next_reset, mapid, difficulty); CharacterDatabase.PExecute("UPDATE instance_reset SET resettime = '"UI64FMTD"' WHERE mapid = '%d' AND difficulty = '%d'", (uint64)next_reset, mapid, difficulty);
} }

View file

@ -164,7 +164,7 @@ class InstanceResetScheduler
} }
static uint32 GetMaxResetTimeFor(MapDifficulty const* mapDiff); static uint32 GetMaxResetTimeFor(MapDifficulty const* mapDiff);
static time_t CalculateNextResetTime(MapDifficulty const* mapDiff, time_t prevResetTime);
public: // modifiers public: // modifiers
void SetResetTimeFor(uint32 mapid, Difficulty d, time_t t) void SetResetTimeFor(uint32 mapid, Difficulty d, time_t t)
{ {

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__ #ifndef __REVISION_NR_H__
#define __REVISION_NR_H__ #define __REVISION_NR_H__
#define REVISION_NR "10533" #define REVISION_NR "10534"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__