mirror of
https://github.com/mangosfour/server.git
synced 2025-12-16 22:37:02 +00:00
[11323] Avoid explicit use HIGHGUID_UNIT as creature high guid in guids or creature creating.
This helper change for allow have in future static spawned vehicles as `creature` table data. Added CreatureInfo::GetHighGuid() high guid selector, and wrapper CreatureData::GetHighGuid() for most real cases of usage. Also easy get expected guid form by CreatureData::GetObjectGuid(lowguid). Also fixed some memory lost cases at creature spawn fail.
This commit is contained in:
parent
0dfcbf8051
commit
ba77d85a30
16 changed files with 156 additions and 81 deletions
|
|
@ -49,6 +49,13 @@
|
|||
// apply implementation of the singletons
|
||||
#include "Policies/SingletonImp.h"
|
||||
|
||||
|
||||
HighGuid CreatureData::GetHighGuid() const
|
||||
{
|
||||
// info existence checked at loading
|
||||
return ObjectMgr::GetCreatureTemplate(id)->GetHighGuid();
|
||||
}
|
||||
|
||||
TrainerSpell const* TrainerSpellData::Find(uint32 spell_id) const
|
||||
{
|
||||
TrainerSpellMap::const_iterator itr = spellList.find(spell_id);
|
||||
|
|
@ -728,12 +735,12 @@ bool Creature::AIM_Initialize()
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Creature::Create(uint32 guidlow, CreatureCreatePos& cPos, uint32 Entry, Team team /*= TEAM_NONE*/, const CreatureData *data /*= NULL*/, GameEventCreatureData const* eventData /*= NULL*/)
|
||||
bool Creature::Create(uint32 guidlow, CreatureCreatePos& cPos, CreatureInfo const* cinfo, Team team /*= TEAM_NONE*/, const CreatureData *data /*= NULL*/, GameEventCreatureData const* eventData /*= NULL*/)
|
||||
{
|
||||
SetMap(cPos.GetMap());
|
||||
SetPhaseMask(cPos.GetPhaseMask(), false);
|
||||
|
||||
if (!CreateFromProto(guidlow, Entry, team, data, eventData))
|
||||
if (!CreateFromProto(guidlow, cinfo, team, data, eventData))
|
||||
return false;
|
||||
|
||||
cPos.SelectFinalPoint(this);
|
||||
|
|
@ -1234,19 +1241,13 @@ float Creature::GetSpellDamageMod(int32 Rank)
|
|||
}
|
||||
}
|
||||
|
||||
bool Creature::CreateFromProto(uint32 guidlow, uint32 Entry, Team team, const CreatureData *data /*=NULL*/, GameEventCreatureData const* eventData /*=NULL*/)
|
||||
bool Creature::CreateFromProto(uint32 guidlow, CreatureInfo const* cinfo, Team team, const CreatureData *data /*=NULL*/, GameEventCreatureData const* eventData /*=NULL*/)
|
||||
{
|
||||
CreatureInfo const *cinfo = ObjectMgr::GetCreatureTemplate(Entry);
|
||||
if(!cinfo)
|
||||
{
|
||||
sLog.outErrorDb("Creature entry %u does not exist.", Entry);
|
||||
return false;
|
||||
}
|
||||
m_originalEntry = Entry;
|
||||
m_originalEntry = cinfo->Entry;
|
||||
|
||||
Object::_Create(guidlow, Entry, HIGHGUID_UNIT);
|
||||
Object::_Create(guidlow, cinfo->Entry, cinfo->GetHighGuid());
|
||||
|
||||
if (!UpdateEntry(Entry, team, data, eventData, false))
|
||||
if (!UpdateEntry(cinfo->Entry, team, data, eventData, false))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
@ -1262,15 +1263,22 @@ bool Creature::LoadFromDB(uint32 guidlow, Map *map)
|
|||
return false;
|
||||
}
|
||||
|
||||
CreatureInfo const *cinfo = ObjectMgr::GetCreatureTemplate(data->id);
|
||||
if(!cinfo)
|
||||
{
|
||||
sLog.outErrorDb("Creature (Entry: %u) not found in table `creature_template`, can't load. ", data->id);
|
||||
return false;
|
||||
}
|
||||
|
||||
GameEventCreatureData const* eventData = sGameEventMgr.GetCreatureUpdateDataForActiveEvent(guidlow);
|
||||
|
||||
// Creature can be loaded already in map if grid has been unloaded while creature walk to another grid
|
||||
if (map->GetCreature(ObjectGuid(HIGHGUID_UNIT, data->id, guidlow)))
|
||||
if (map->GetCreature(data->GetObjectGuid(guidlow)))
|
||||
return false;
|
||||
|
||||
CreatureCreatePos pos(map, data->posX, data->posY, data->posZ, data->orientation, data->phaseMask);
|
||||
|
||||
if (!Create(guidlow, pos, data->id, TEAM_NONE, data, eventData))
|
||||
if (!Create(guidlow, pos, cinfo, TEAM_NONE, data, eventData))
|
||||
return false;
|
||||
|
||||
m_respawnradius = data->spawndist;
|
||||
|
|
@ -2427,7 +2435,7 @@ struct AddCreatureToRemoveListInMapsWorker
|
|||
|
||||
void Creature::AddToRemoveListInMaps(uint32 db_guid, CreatureData const* data)
|
||||
{
|
||||
AddCreatureToRemoveListInMapsWorker worker(ObjectGuid(HIGHGUID_UNIT, data->id, db_guid));
|
||||
AddCreatureToRemoveListInMapsWorker worker(data->GetObjectGuid(db_guid));
|
||||
sMapMgr.DoForAllMapsWithMapId(data->mapid, worker);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue