Core/AI: Add better support for tracking DynObjs
By Krudor
This commit is contained in:
1 parent
7290943406
commit
14d3e15c1f
3 files changed
+43
-13
No files matched your search
@@ -4703,24 +4703,31 @@ void Unit::ApplyStatPercentBuffMod(Stats stat, float val, bool apply)
|
||||
void Unit::_RegisterDynObject(DynamicObject* dynObj)
|
||||
{
|
||||
m_dynObj.push_back(dynObj);
|
||||
if (GetTypeId() == TYPEID_UNIT && IsAIEnabled)
|
||||
ToCreature()->AI()->JustRegisteredDynObject(dynObj);
|
||||
}
|
||||
|
||||
void Unit::_UnregisterDynObject(DynamicObject* dynObj)
|
||||
{
|
||||
m_dynObj.remove(dynObj);
|
||||
if (GetTypeId() == TYPEID_UNIT && IsAIEnabled)
|
||||
ToCreature()->AI()->JustUnregisteredDynObject(dynObj);
|
||||
}
|
||||
|
||||
DynamicObject* Unit::GetDynObject(uint32 spellId)
|
||||
DynamicObject* Unit::GetDynObject(uint32 spellId) const
|
||||
{
|
||||
if (m_dynObj.empty())
|
||||
return NULL;
|
||||
for (DynObjectList::const_iterator i = m_dynObj.begin(); i != m_dynObj.end();++i)
|
||||
{
|
||||
DynamicObject* dynObj = *i;
|
||||
if (dynObj->GetSpellId() == spellId)
|
||||
return dynObj;
|
||||
}
|
||||
return NULL;
|
||||
std::vector<DynamicObject*> dynamicobjects = GetDynObjects(spellId);
|
||||
return dynamicobjects.empty() ? nullptr : dynamicobjects.front();
|
||||
}
|
||||
|
||||
std::vector<DynamicObject*> Unit::GetDynObjects(uint32 spellId) const
|
||||
{
|
||||
std::vector<DynamicObject*> dynamicobjects;
|
||||
for (DynObjectList::const_iterator i = m_dynObj.begin(); i != m_dynObj.end(); ++i)
|
||||
if ((*i)->GetSpellId() == spellId)
|
||||
dynamicobjects.push_back(*i);
|
||||
|
||||
return dynamicobjects;
|
||||
}
|
||||
|
||||
void Unit::RemoveDynObject(uint32 spellId)
|
||||
@@ -4748,11 +4755,18 @@ void Unit::RemoveAllDynObjects()
|
||||
|
||||
GameObject* Unit::GetGameObject(uint32 spellId) const
|
||||
{
|
||||
std::vector<GameObject*> gameobjects = GetGameObjects(spellId);
|
||||
return gameobjects.empty() ? nullptr : gameobjects.front();
|
||||
}
|
||||
|
||||
std::vector<GameObject*> Unit::GetGameObjects(uint32 spellId) const
|
||||
{
|
||||
std::vector<GameObject*> gameobjects;
|
||||
for (GameObjectList::const_iterator i = m_gameObj.begin(); i != m_gameObj.end(); ++i)
|
||||
if ((*i)->GetSpellId() == spellId)
|
||||
return *i;
|
||||
gameobjects.push_back(*i);
|
||||
|
||||
return NULL;
|
||||
return gameobjects;
|
||||
}
|
||||
|
||||
void Unit::AddGameObject(GameObject* gameObj)
|
||||
@@ -4771,6 +4785,9 @@ void Unit::AddGameObject(GameObject* gameObj)
|
||||
// note: item based cooldowns and cooldown spell mods with charges ignored (unknown existing cases)
|
||||
GetSpellHistory()->StartCooldown(createBySpell, 0, nullptr, true);
|
||||
}
|
||||
|
||||
if (GetTypeId() == TYPEID_UNIT && ToCreature()->IsAIEnabled)
|
||||
ToCreature()->AI()->JustSummonedGameobject(gameObj);
|
||||
}
|
||||
|
||||
void Unit::RemoveGameObject(GameObject* gameObj, bool del)
|
||||
@@ -4803,6 +4820,9 @@ void Unit::RemoveGameObject(GameObject* gameObj, bool del)
|
||||
|
||||
m_gameObj.remove(gameObj);
|
||||
|
||||
if (GetTypeId() == TYPEID_UNIT && ToCreature()->IsAIEnabled)
|
||||
ToCreature()->AI()->SummonedGameobjectDespawn(gameObj);
|
||||
|
||||
if (del)
|
||||
{
|
||||
gameObj->SetRespawnTime(0);
|
||||
|
||||
Reference in new issue
Block a user