Over 100 camangos Cata commits applied (to c12950)

Over 100 camangos Cata commits applied. up to and inclusing c12950.
This commit is contained in:
Charles A Edwards 2016-08-20 17:10:24 +01:00 committed by Antz
parent b4ec0440aa
commit eef77eadb9
117 changed files with 4314 additions and 3547 deletions

View file

@ -44,7 +44,10 @@
INSTANTIATE_SINGLETON_1(MapPersistentStateManager);
static uint32 resetEventTypeDelay[MAX_RESET_EVENT_TYPE] = { 0, 3600, 900, 300, 60 };
static uint32 resetEventTypeDelay[MAX_RESET_EVENT_TYPE] = { 0, // not used
3600, 900, 300, 60, // (seconds) normal and official timer delay to inform player about instance reset
60, 30, 10, 5 // (seconds) fast reset by gm command inform timer
};
//== MapPersistentState functions ==========================
MapPersistentState::MapPersistentState(uint16 MapId, uint32 InstanceId, Difficulty difficulty)
@ -220,6 +223,11 @@ DungeonPersistentState::DungeonPersistentState(uint16 MapId, uint32 InstanceId,
DungeonPersistentState::~DungeonPersistentState()
{
DEBUG_LOG("Unloading DungeonPersistantState of map %u instance %u", GetMapId(), GetInstanceId());
UnbindThisState();
}
void DungeonPersistentState::UnbindThisState()
{
while (!m_playerList.empty())
{
Player* player = *(m_playerList.begin());
@ -537,7 +545,7 @@ void DungeonResetScheduler::ScheduleReset(bool add, time_t time, DungeonResetEve
void DungeonResetScheduler::Update()
{
time_t now = time(NULL), t;
time_t now = time(nullptr), t;
while (!m_resetTimeQueue.empty() && (t = m_resetTimeQueue.begin()->first) < now)
{
DungeonResetEvent& event = m_resetTimeQueue.begin()->second;
@ -550,8 +558,10 @@ void DungeonResetScheduler::Update()
{
// global reset/warning for a certain map
time_t resetTime = GetResetTimeFor(event.mapid, event.difficulty);
m_InstanceSaves._ResetOrWarnAll(event.mapid, event.difficulty, event.type != RESET_EVENT_INFORM_LAST, uint32(resetTime - now));
if (event.type != RESET_EVENT_INFORM_LAST)
uint32 timeLeft = uint32(std::max(int32(resetTime - now), 0));
bool warn = event.type != RESET_EVENT_INFORM_LAST && event.type != RESET_EVENT_FORCED_INFORM_LAST;
m_InstanceSaves._ResetOrWarnAll(event.mapid, event.difficulty, warn, timeLeft);
if (event.type != RESET_EVENT_INFORM_LAST && event.type != RESET_EVENT_FORCED_INFORM_LAST)
{
// schedule the next warning/reset
event.type = ResetEventType(event.type + 1);
@ -584,6 +594,32 @@ void DungeonResetScheduler::Update()
}
}
void DungeonResetScheduler::ResetAllRaid()
{
time_t now = time(nullptr);
ResetTimeQueue rTQ;
rTQ.clear();
time_t timeleft = resetEventTypeDelay[RESET_EVENT_FORCED_INFORM_1];
for (ResetTimeQueue::iterator itr = m_resetTimeQueue.begin(); itr != m_resetTimeQueue.end(); ++itr)
{
DungeonResetEvent& event = itr->second;
// we only reset raid dungeon
if (event.type == RESET_EVENT_NORMAL_DUNGEON)
{
rTQ.insert(std::pair<time_t, DungeonResetEvent>(itr->first, event));
continue;
}
event.type = RESET_EVENT_FORCED_INFORM_1;
time_t next_reset = now + timeleft;
SetResetTimeFor(event.mapid, event.difficulty, next_reset);
rTQ.insert(std::pair<time_t, DungeonResetEvent>(now, event));
}
m_resetTimeQueue = rTQ;
}
//== MapPersistentStateManager functions =========================
MapPersistentStateManager::MapPersistentStateManager() : lock_instLists(false), m_Scheduler(*this)
@ -855,14 +891,37 @@ void MapPersistentStateManager::_ResetInstance(uint32 mapid, uint32 instanceId)
DeleteInstanceFromDB(instanceId); // even if state not loaded
}
struct MapPersistantStateResetWorker
{
MapPersistantStateResetWorker() {};
void operator()(Map* map)
{
((DungeonMap*)map)->TeleportAllPlayersTo(TELEPORT_LOCATION_HOMEBIND);
((DungeonMap*)map)->Reset(INSTANCE_RESET_GLOBAL);
}
};
struct MapPersistantStateWarnWorker
{
MapPersistantStateWarnWorker(time_t _timeLeft) : timeLeft(_timeLeft)
{};
void operator()(Map* map)
{
((DungeonMap*)map)->SendResetWarnings(timeLeft);
}
time_t timeLeft;
};
void MapPersistentStateManager::_ResetOrWarnAll(uint32 mapid, Difficulty difficulty, bool warn, uint32 timeLeft)
{
// global reset for all instances of the given map
MapEntry const* mapEntry = sMapStore.LookupEntry(mapid);
if (!mapEntry->Instanceable())
if (!mapEntry->IsDungeon())
return;
time_t now = time(NULL);
time_t now = time(nullptr);
if (!warn)
{
@ -873,14 +932,21 @@ void MapPersistentStateManager::_ResetOrWarnAll(uint32 mapid, Difficulty difficu
return;
}
// remove all binds to instances of the given map
for (PersistentStateMap::iterator itr = m_instanceSaveByInstanceId.begin(); itr != m_instanceSaveByInstanceId.end();)
{
// remove all binds for online player
std::list<DungeonPersistentState *> unbindList;
// note that we must build a list of states to unbind and then unbind them in two steps. this is because the unbinding may
// trigger the modification of the collection, which would invalidate the iterator and cause a crash.
for (PersistentStateMap::iterator itr = m_instanceSaveByInstanceId.begin(); itr != m_instanceSaveByInstanceId.end(); ++itr)
if (itr->second->GetMapId() == mapid && itr->second->GetDifficulty() == difficulty)
_ResetSave(m_instanceSaveByInstanceId, itr);
else
++itr;
}
unbindList.push_back((DungeonPersistentState *)itr->second);
for (auto i : unbindList)
i->UnbindThisState();
// reset maps, teleport player automaticaly to their homebinds and unload maps
MapPersistantStateResetWorker worker;
sMapMgr.DoForAllMapsWithMapId(mapid, worker);
// delete them from the DB, even if not loaded
CharacterDatabase.BeginTransaction();
@ -893,23 +959,12 @@ void MapPersistentStateManager::_ResetOrWarnAll(uint32 mapid, Difficulty difficu
time_t next_reset = DungeonResetScheduler::CalculateNextResetTime(mapDiff, now + timeLeft);
// update it in the DB
CharacterDatabase.PExecute("UPDATE instance_reset SET resettime = '" UI64FMTD "' WHERE mapid = '%u' AND difficulty = '%u'", (uint64)next_reset, mapid, difficulty);
return;
}
// note: this isn't fast but it's meant to be executed very rarely
const MapManager::MapMapType& maps = sMapMgr.Maps();
MapManager::MapMapType::const_iterator iter_last = maps.lower_bound(MapID(mapid + 1));
for (MapManager::MapMapType::const_iterator mitr = maps.lower_bound(MapID(mapid)); mitr != iter_last; ++mitr)
{
Map* map2 = mitr->second;
if (map2->GetId() != mapid)
break;
if (warn)
((DungeonMap*)map2)->SendResetWarnings(timeLeft);
else
((DungeonMap*)map2)->Reset(INSTANCE_RESET_GLOBAL);
}
MapPersistantStateWarnWorker worker(timeLeft);
sMapMgr.DoForAllMapsWithMapId(mapid, worker);
}
void MapPersistentStateManager::GetStatistics(uint32& numStates, uint32& numBoundPlayers, uint32& numBoundGroups)