From 5c7707e34600e4f26b8af3cd1f6cc3971a68befb Mon Sep 17 00:00:00 2001 From: VladimirMangos Date: Fri, 20 Aug 2010 14:05:09 +0400 Subject: [PATCH] [10384] Fixed reset time calculation for some cases. Most real fix suggested by Schmoozerd and Toinan67 and some my code style part coding ;) --- src/game/DBCStructure.h | 6 +++--- src/game/InstanceSaveMgr.cpp | 21 +++++++++++++++------ src/game/InstanceSaveMgr.h | 2 ++ src/game/Map.cpp | 3 +-- src/shared/revision_nr.h | 2 +- 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/game/DBCStructure.h b/src/game/DBCStructure.h index 8fdb056f288..4b845fea242 100644 --- a/src/game/DBCStructure.h +++ b/src/game/DBCStructure.h @@ -1163,8 +1163,8 @@ struct MapDifficultyEntry uint32 Difficulty; // 2 (for arenas: arena slot) //char* areaTriggerText[16]; // 3-18 text showed when transfer to map failed (missing requirements) //uint32 textFlags; // 19 - uint32 resetTime; // 20 - uint32 maxPlayers; // 21 + uint32 resetTime; // 20, in secs, 0 if no fixed reset time + uint32 maxPlayers; // 21, some heroic versions have 0 when expected same amount as in normal version //char* difficultyString; // 22 }; @@ -1860,7 +1860,7 @@ struct MapDifficulty MapDifficulty() : resetTime(0), maxPlayers(0) {} MapDifficulty(uint32 _resetTime, uint32 _maxPlayers) : resetTime(_resetTime), maxPlayers(_maxPlayers) {} - uint32 resetTime; + uint32 resetTime; // in secs, 0 if no fixed reset time uint32 maxPlayers; // some heroic dungeons have 0 when expect same value as in normal dificulty case }; diff --git a/src/game/InstanceSaveMgr.cpp b/src/game/InstanceSaveMgr.cpp index 4eacbe76458..d703fc9f12e 100644 --- a/src/game/InstanceSaveMgr.cpp +++ b/src/game/InstanceSaveMgr.cpp @@ -126,6 +126,19 @@ bool InstanceSave::UnloadIfEmpty() //== InstanceResetScheduler functions ====================== +uint32 InstanceResetScheduler::GetMaxResetTimFor(MapDifficulty const* mapDiff) +{ + if (!mapDiff || !mapDiff->resetTime) + return 0; + + uint32 delay = uint32(mapDiff->resetTime / DAY * sWorld.getConfig(CONFIG_FLOAT_RATE_INSTANCE_RESET_TIME)) * DAY; + + if (delay < DAY) // the reset_delay must be at least one day + delay = DAY; + + return delay; +} + void InstanceResetScheduler::LoadResetTimes() { time_t now = time(NULL); @@ -229,11 +242,7 @@ void InstanceResetScheduler::LoadResetTimes() if (!mapDiff->resetTime) continue; - // the reset_delay must be at least one day - uint32 period = uint32(mapDiff->resetTime / DAY * sWorld.getConfig(CONFIG_FLOAT_RATE_INSTANCE_RESET_TIME)) * DAY; - if (period < DAY) - period = DAY; - + uint32 period = GetMaxResetTimFor(mapDiff); time_t t = GetResetTimeFor(mapid,difficulty); if(!t) { @@ -637,7 +646,7 @@ void InstanceSaveManager::_ResetOrWarnAll(uint32 mapid, Difficulty difficulty, b // calculate the next reset time uint32 diff = sWorld.getConfig(CONFIG_UINT32_INSTANCE_RESET_TIME_HOUR) * HOUR; - uint32 period = mapDiff->resetTime * DAY; + uint32 period = InstanceResetScheduler::GetMaxResetTimFor(mapDiff); time_t next_reset = ((now + timeLeft + MINUTE) / DAY * DAY) + period + diff; // update it in the DB CharacterDatabase.PExecute("UPDATE instance_reset SET resettime = '"UI64FMTD"' WHERE mapid = '%d' AND difficulty = '%d'", (uint64)next_reset, mapid, difficulty); diff --git a/src/game/InstanceSaveMgr.h b/src/game/InstanceSaveMgr.h index 6b664bbf083..819535be394 100644 --- a/src/game/InstanceSaveMgr.h +++ b/src/game/InstanceSaveMgr.h @@ -161,6 +161,8 @@ class InstanceResetScheduler return itr != m_resetTimeByMapDifficulty.end() ? itr->second : 0; } + static uint32 GetMaxResetTimFor(MapDifficulty const* mapDiff); + public: // modifiers void SetResetTimeFor(uint32 mapid, Difficulty d, time_t t) { diff --git a/src/game/Map.cpp b/src/game/Map.cpp index 662fa3746ed..76cbc24a3c5 100644 --- a/src/game/Map.cpp +++ b/src/game/Map.cpp @@ -996,8 +996,7 @@ uint32 Map::GetMaxPlayers() const uint32 Map::GetMaxResetDelay() const { - MapDifficulty const* mapDiff = GetMapDifficulty(); - return mapDiff ? mapDiff->resetTime : 0; + return InstanceResetScheduler::GetMaxResetTimFor(GetMapDifficulty()); } inline GridMap *Map::GetGrid(float x, float y) diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 0bbd40ad0bc..213d79dabd5 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "10383" + #define REVISION_NR "10384" #endif // __REVISION_NR_H__