[11133] Implement template functions for call functor for all Map/MapPersistentState with some map id.

This commit is contained in:
VladimirMangos 2011-02-11 04:02:19 +03:00
parent f4a2a582d9
commit da1b616312
5 changed files with 76 additions and 7 deletions

View file

@ -618,11 +618,28 @@ bool GameObject::LoadFromDB(uint32 guid, Map *map)
return true;
}
struct GameObjectRespawnDeleteWorker
{
explicit GameObjectRespawnDeleteWorker(uint32 guid) : i_guid(guid) {}
void operator() (MapPersistentState* state)
{
state->SaveGORespawnTime(i_guid, 0);
}
uint32 i_guid;
};
void GameObject::DeleteFromDB()
{
// FIXME: this can be not safe in case multiply loaded instance copies
if (MapPersistentState* save = sMapPersistentStateMgr.GetPersistentState(GetMapId(), GetInstanceId()))
save->SaveGORespawnTime(m_DBTableGuid, 0);
if (!m_DBTableGuid)
{
DEBUG_LOG("Trying to delete not saved gameobject!");
return;
}
sMapPersistentStateMgr.DoForAllStatesWithMapId(GetMapId(), GameObjectRespawnDeleteWorker(m_DBTableGuid));
sObjectMgr.DeleteGOData(m_DBTableGuid);
WorldDatabase.PExecuteLog("DELETE FROM gameobject WHERE guid = '%u'", m_DBTableGuid);