Skip to content

Commit

Permalink
[10384] Fixed reset time calculation for some cases.
Browse files Browse the repository at this point in the history
Most real fix suggested by Schmoozerd and  Toinan67
and some my code style part coding ;)
  • Loading branch information
VladimirMangos committed Aug 20, 2010
1 parent 65c3249 commit 5c7707e
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/game/DBCStructure.h
Expand Up @@ -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
};

Expand Down Expand Up @@ -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
};

Expand Down
21 changes: 15 additions & 6 deletions src/game/InstanceSaveMgr.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/game/InstanceSaveMgr.h
Expand Up @@ -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)
{
Expand Down
3 changes: 1 addition & 2 deletions src/game/Map.cpp
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion 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__

7 comments on commit 5c7707e

@LordJZ
Copy link
Contributor

@LordJZ LordJZ commented on 5c7707e Aug 20, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And still it's not blizzlike

@VladimirMangos
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more info?

@LordJZ
Copy link
Contributor

@LordJZ LordJZ commented on 5c7707e Aug 20, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@VladimirMangos
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uint32 instanceResetOffset;

ok, but it used only for 2 maps in map.dbc for 19 hours....

@LordJZ
Copy link
Contributor

@LordJZ LordJZ commented on 5c7707e Aug 20, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well that was just an additional feature for that patch, the main purpose was to fix reset times when the server started on the clean database

@VladimirMangos
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meaning, is i am right that you say that it not same as retial in result not using this field?
If so then i will be glad review clear patch for including this field in calculations.
In current state hard undersatnd how it connected with mapDifficulty reset times.

@LordJZ
Copy link
Contributor

@LordJZ LordJZ commented on 5c7707e Aug 21, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. At the moment of that commit in my repo mangos was choosing the time to respawn calculating offsets from current time when you launch the server after truncate instance_reset.

e.g. you launch it at 30.08 23:50, and every reset will be 30.08 23:50 + 1 day or + 7 days. Probably it was fixed for the weekday, but I haven't noticed any changes about the time of day.

Also, using the constant is more blizzlike as it is sent to client (see next commit)

P.S. Omg looks like I'm just f*cking you brain, I'll go do some tests with the latest core and then provide a full patch. :\

Please sign in to comment.