Delete obj if it is not successfully added to grid. More to fix.
This commit is contained in:
@@ -1454,7 +1454,11 @@ bool Battleground::AddObject(uint32 type, uint32 entry, float x, float y, float
|
|||||||
data.go_state = 1;
|
data.go_state = 1;
|
||||||
*/
|
*/
|
||||||
// Add to world, so it can be later looked up from HashMapHolder
|
// Add to world, so it can be later looked up from HashMapHolder
|
||||||
map->AddToMap(go);
|
if (!map->AddToMap(go))
|
||||||
|
{
|
||||||
|
delete go;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
m_BgObjects[type] = go->GetGUID();
|
m_BgObjects[type] = go->GetGUID();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1557,7 +1561,12 @@ Creature* Battleground::AddCreature(uint32 entry, uint32 type, uint32 teamval, f
|
|||||||
creature->SetSpeed(MOVE_WALK, cinfo->speed_walk);
|
creature->SetSpeed(MOVE_WALK, cinfo->speed_walk);
|
||||||
creature->SetSpeed(MOVE_RUN, cinfo->speed_run);
|
creature->SetSpeed(MOVE_RUN, cinfo->speed_run);
|
||||||
|
|
||||||
map->AddToMap(creature);
|
if (!map->AddToMap(creature))
|
||||||
|
{
|
||||||
|
delete creature;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
m_BgCreatures[type] = creature->GetGUID();
|
m_BgCreatures[type] = creature->GetGUID();
|
||||||
|
|
||||||
if (respawntime)
|
if (respawntime)
|
||||||
|
|||||||
@@ -1241,7 +1241,7 @@ bool Creature::CreateFromProto(uint32 guidlow, uint32 Entry, uint32 vehId, uint3
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Creature::LoadFromDB(uint32 guid, Map* map)
|
bool Creature::LoadCreatureFromDB(uint32 guid, Map* map, bool addToMap)
|
||||||
{
|
{
|
||||||
CreatureData const* data = sObjectMgr->GetCreatureData(guid);
|
CreatureData const* data = sObjectMgr->GetCreatureData(guid);
|
||||||
|
|
||||||
@@ -1310,6 +1310,8 @@ bool Creature::LoadFromDB(uint32 guid, Map* map)
|
|||||||
|
|
||||||
m_creatureData = data;
|
m_creatureData = data;
|
||||||
|
|
||||||
|
if (addToMap && !GetMap()->AddToMap(this))
|
||||||
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -575,7 +575,8 @@ class Creature : public Unit, public GridObject<Creature>, public MapCreature
|
|||||||
void setDeathState(DeathState s); // override virtual Unit::setDeathState
|
void setDeathState(DeathState s); // override virtual Unit::setDeathState
|
||||||
bool FallGround();
|
bool FallGround();
|
||||||
|
|
||||||
bool LoadFromDB(uint32 guid, Map* map);
|
bool LoadFromDB(uint32 guid, Map* map) { return LoadCreatureFromDB(guid, map, false); }
|
||||||
|
bool LoadCreatureFromDB(uint32 guid, Map* map, bool addToMap = true);
|
||||||
void SaveToDB();
|
void SaveToDB();
|
||||||
// overriden in Pet
|
// overriden in Pet
|
||||||
virtual void SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask);
|
virtual void SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask);
|
||||||
|
|||||||
@@ -695,7 +695,7 @@ void GameObject::SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask)
|
|||||||
WorldDatabase.CommitTransaction(trans);
|
WorldDatabase.CommitTransaction(trans);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GameObject::LoadFromDB(uint32 guid, Map* map)
|
bool GameObject::LoadGameObjectFromDB(uint32 guid, Map* map, bool addToMap)
|
||||||
{
|
{
|
||||||
GameObjectData const* data = sObjectMgr->GetGOData(guid);
|
GameObjectData const* data = sObjectMgr->GetGOData(guid);
|
||||||
|
|
||||||
@@ -760,6 +760,9 @@ bool GameObject::LoadFromDB(uint32 guid, Map* map)
|
|||||||
|
|
||||||
m_goData = data;
|
m_goData = data;
|
||||||
|
|
||||||
|
if (addToMap && !GetMap()->AddToMap(this))
|
||||||
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -648,7 +648,8 @@ class GameObject : public WorldObject, public GridObject<GameObject>
|
|||||||
|
|
||||||
void SaveToDB();
|
void SaveToDB();
|
||||||
void SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask);
|
void SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask);
|
||||||
bool LoadFromDB(uint32 guid, Map* map);
|
bool LoadFromDB(uint32 guid, Map* map) { return LoadGameObjectFromDB(guid, map, false); }
|
||||||
|
bool LoadGameObjectFromDB(uint32 guid, Map* map, bool addToMap = true);
|
||||||
void DeleteFromDB();
|
void DeleteFromDB();
|
||||||
|
|
||||||
void SetOwnerGUID(uint64 owner)
|
void SetOwnerGUID(uint64 owner)
|
||||||
|
|||||||
@@ -1176,10 +1176,8 @@ void GameEventMgr::GameEventSpawn(int16 event_id)
|
|||||||
{
|
{
|
||||||
Creature* creature = new Creature;
|
Creature* creature = new Creature;
|
||||||
//sLog->outDebug("Spawning creature %u", *itr);
|
//sLog->outDebug("Spawning creature %u", *itr);
|
||||||
if (!creature->LoadFromDB(*itr, map))
|
if (!creature->LoadCreatureFromDB(*itr, map))
|
||||||
delete creature;
|
delete creature;
|
||||||
else
|
|
||||||
map->AddToMap(creature);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1205,7 +1203,8 @@ void GameEventMgr::GameEventSpawn(int16 event_id)
|
|||||||
{
|
{
|
||||||
GameObject* pGameobject = new GameObject;
|
GameObject* pGameobject = new GameObject;
|
||||||
//sLog->outDebug("Spawning gameobject %u", *itr);
|
//sLog->outDebug("Spawning gameobject %u", *itr);
|
||||||
if (!pGameobject->LoadFromDB(*itr, map))
|
//TODO: find out when it is add to map
|
||||||
|
if (!pGameobject->LoadGameObjectFromDB(*itr, map, false))
|
||||||
delete pGameobject;
|
delete pGameobject;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1630,13 +1630,12 @@ uint32 ObjectMgr::AddGOData(uint32 entry, uint32 mapId, float x, float y, float
|
|||||||
if (!map->Instanceable() && map->IsGridLoaded(x, y))
|
if (!map->Instanceable() && map->IsGridLoaded(x, y))
|
||||||
{
|
{
|
||||||
GameObject* go = new GameObject;
|
GameObject* go = new GameObject;
|
||||||
if (!go->LoadFromDB(guid, map))
|
if (!go->LoadGameObjectFromDB(guid, map))
|
||||||
{
|
{
|
||||||
sLog->outError("AddGOData: cannot add gameobject entry %u to map", entry);
|
sLog->outError("AddGOData: cannot add gameobject entry %u to map", entry);
|
||||||
delete go;
|
delete go;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
map->AddToMap(go);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sLog->outDebug(LOG_FILTER_MAPS, "AddGOData: dbguid %u entry %u map %u x %f y %f z %f o %f", guid, entry, mapId, x, y, z, o);
|
sLog->outDebug(LOG_FILTER_MAPS, "AddGOData: dbguid %u entry %u map %u x %f y %f z %f o %f", guid, entry, mapId, x, y, z, o);
|
||||||
@@ -1666,13 +1665,12 @@ bool ObjectMgr::MoveCreData(uint32 guid, uint32 mapId, Position pos)
|
|||||||
if (!map->Instanceable() && map->IsGridLoaded(data.posX, data.posY))
|
if (!map->Instanceable() && map->IsGridLoaded(data.posX, data.posY))
|
||||||
{
|
{
|
||||||
Creature* creature = new Creature;
|
Creature* creature = new Creature;
|
||||||
if (!creature->LoadFromDB(guid, map))
|
if (!creature->LoadCreatureFromDB(guid, map))
|
||||||
{
|
{
|
||||||
sLog->outError("AddCreature: cannot add creature entry %u to map", guid);
|
sLog->outError("AddCreature: cannot add creature entry %u to map", guid);
|
||||||
delete creature;
|
delete creature;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
map->AddToMap(creature);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -1719,13 +1717,12 @@ uint32 ObjectMgr::AddCreData(uint32 entry, uint32 /*team*/, uint32 mapId, float
|
|||||||
if (!map->Instanceable() && !map->IsRemovalGrid(x, y))
|
if (!map->Instanceable() && !map->IsRemovalGrid(x, y))
|
||||||
{
|
{
|
||||||
Creature* creature = new Creature;
|
Creature* creature = new Creature;
|
||||||
if (!creature->LoadFromDB(guid, map))
|
if (!creature->LoadCreatureFromDB(guid, map))
|
||||||
{
|
{
|
||||||
sLog->outError("AddCreature: cannot add creature entry %u to map", entry);
|
sLog->outError("AddCreature: cannot add creature entry %u to map", entry);
|
||||||
delete creature;
|
delete creature;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
map->AddToMap(creature);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -365,13 +365,11 @@ void PoolGroup<Creature>::Spawn1Object(PoolObject* obj)
|
|||||||
{
|
{
|
||||||
Creature* creature = new Creature;
|
Creature* creature = new Creature;
|
||||||
//sLog->outDebug(LOG_FILTER_POOLSYS, "Spawning creature %u", guid);
|
//sLog->outDebug(LOG_FILTER_POOLSYS, "Spawning creature %u", guid);
|
||||||
if (!creature->LoadFromDB(obj->guid, map))
|
if (!creature->LoadCreatureFromDB(obj->guid, map))
|
||||||
{
|
{
|
||||||
delete creature;
|
delete creature;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
map->AddToMap(creature);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -391,7 +389,7 @@ void PoolGroup<GameObject>::Spawn1Object(PoolObject* obj)
|
|||||||
{
|
{
|
||||||
GameObject* pGameobject = new GameObject;
|
GameObject* pGameobject = new GameObject;
|
||||||
//sLog->outDebug(LOG_FILTER_POOLSYS, "Spawning gameobject %u", guid);
|
//sLog->outDebug(LOG_FILTER_POOLSYS, "Spawning gameobject %u", guid);
|
||||||
if (!pGameobject->LoadFromDB(obj->guid, map))
|
if (!pGameobject->LoadGameObjectFromDB(obj->guid, map, false))
|
||||||
{
|
{
|
||||||
delete pGameobject;
|
delete pGameobject;
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -165,14 +165,12 @@ public:
|
|||||||
object->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), player->GetPhaseMaskForSpawn());
|
object->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), player->GetPhaseMaskForSpawn());
|
||||||
|
|
||||||
// this will generate a new guid if the object is in an instance
|
// this will generate a new guid if the object is in an instance
|
||||||
if (!object->LoadFromDB(guidLow, map))
|
if (!object->LoadGameObjectFromDB(guidLow, map))
|
||||||
{
|
{
|
||||||
delete object;
|
delete object;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
map->AddToMap(object);
|
|
||||||
|
|
||||||
// TODO: is it really necessary to add both the real and DB table guid here ?
|
// TODO: is it really necessary to add both the real and DB table guid here ?
|
||||||
sObjectMgr->AddGameobjectToGrid(guidLow, sObjectMgr->GetGOData(guidLow));
|
sObjectMgr->AddGameobjectToGrid(guidLow, sObjectMgr->GetGOData(guidLow));
|
||||||
|
|
||||||
|
|||||||
@@ -147,9 +147,12 @@ public:
|
|||||||
uint32 db_guid = creature->GetDBTableGUIDLow();
|
uint32 db_guid = creature->GetDBTableGUIDLow();
|
||||||
|
|
||||||
// To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells();
|
// To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells();
|
||||||
creature->LoadFromDB(db_guid, map);
|
if (!creature->LoadCreatureFromDB(db_guid, map))
|
||||||
|
{
|
||||||
|
delete creature;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
map->AddToMap(creature);
|
|
||||||
sObjectMgr->AddCreatureToGrid(db_guid, sObjectMgr->GetCreatureData(db_guid));
|
sObjectMgr->AddCreatureToGrid(db_guid, sObjectMgr->GetCreatureData(db_guid));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -578,8 +578,13 @@ public:
|
|||||||
|
|
||||||
wpCreature2->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMaskForSpawn());
|
wpCreature2->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMaskForSpawn());
|
||||||
// To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells();
|
// To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells();
|
||||||
wpCreature2->LoadFromDB(wpCreature2->GetDBTableGUIDLow(), map);
|
//TODO: Should we first use "Create" then use "LoadFromDB"?
|
||||||
map->AddToMap(wpCreature2);
|
if (!wpCreature2->LoadCreatureFromDB(wpCreature2->GetDBTableGUIDLow(), map))
|
||||||
|
{
|
||||||
|
handler->PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, VISUAL_WAYPOINT);
|
||||||
|
delete wpCreature2;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
//sMapMgr->GetMap(npcCreature->GetMapId())->Add(wpCreature2);
|
//sMapMgr->GetMap(npcCreature->GetMapId())->Add(wpCreature2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -777,8 +782,12 @@ public:
|
|||||||
|
|
||||||
wpCreature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMaskForSpawn());
|
wpCreature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMaskForSpawn());
|
||||||
// To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells();
|
// To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells();
|
||||||
wpCreature->LoadFromDB(wpCreature->GetDBTableGUIDLow(), map);
|
if (!wpCreature->LoadCreatureFromDB(wpCreature->GetDBTableGUIDLow(), map))
|
||||||
map->AddToMap(wpCreature);
|
{
|
||||||
|
handler->PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, id);
|
||||||
|
delete wpCreature;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (target)
|
if (target)
|
||||||
{
|
{
|
||||||
@@ -824,8 +833,12 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
creature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMaskForSpawn());
|
creature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMaskForSpawn());
|
||||||
creature->LoadFromDB(creature->GetDBTableGUIDLow(), map);
|
if (!creature->LoadCreatureFromDB(creature->GetDBTableGUIDLow(), map))
|
||||||
map->AddToMap(creature);
|
{
|
||||||
|
handler->PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, id);
|
||||||
|
delete creature;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (target)
|
if (target)
|
||||||
{
|
{
|
||||||
@@ -872,8 +885,12 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
creature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMaskForSpawn());
|
creature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMaskForSpawn());
|
||||||
creature->LoadFromDB(creature->GetDBTableGUIDLow(), map);
|
if (!creature->LoadCreatureFromDB(creature->GetDBTableGUIDLow(), map))
|
||||||
map->AddToMap(creature);
|
{
|
||||||
|
handler->PSendSysMessage(LANG_WAYPOINT_NOTCREATED, id);
|
||||||
|
delete creature;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (target)
|
if (target)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -166,11 +166,15 @@ bool OutdoorPvPSI::HandleDropFlag(Player* player, uint32 spellId)
|
|||||||
if (!go->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_GAMEOBJECT), SI_SILITHYST_MOUND, map, player->GetPhaseMask(), player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), player->GetOrientation(), 0, 0, 0, 0, 100, GO_STATE_READY))
|
if (!go->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_GAMEOBJECT), SI_SILITHYST_MOUND, map, player->GetPhaseMask(), player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), player->GetOrientation(), 0, 0, 0, 0, 100, GO_STATE_READY))
|
||||||
{
|
{
|
||||||
delete go;
|
delete go;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
go->SetRespawnTime(0);
|
||||||
|
|
||||||
|
if (!map->AddToMap(go))
|
||||||
{
|
{
|
||||||
go->SetRespawnTime(0);
|
delete go;
|
||||||
map->AddToMap(go);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -189,17 +193,22 @@ bool OutdoorPvPSI::HandleDropFlag(Player* player, uint32 spellId)
|
|||||||
Map* map = player->GetMap();
|
Map* map = player->GetMap();
|
||||||
if (!map)
|
if (!map)
|
||||||
{
|
{
|
||||||
delete go;
|
delete go;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!go->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_GAMEOBJECT), SI_SILITHYST_MOUND, map, player->GetPhaseMask(), player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), player->GetOrientation(), 0, 0, 0, 0, 100, GO_STATE_READY))
|
if (!go->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_GAMEOBJECT), SI_SILITHYST_MOUND, map, player->GetPhaseMask(), player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), player->GetOrientation(), 0, 0, 0, 0, 100, GO_STATE_READY))
|
||||||
{
|
{
|
||||||
delete go;
|
delete go;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
go->SetRespawnTime(0);
|
||||||
|
|
||||||
|
if (!map->AddToMap(go))
|
||||||
{
|
{
|
||||||
go->SetRespawnTime(0);
|
delete go;
|
||||||
map->AddToMap(go);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user