diff --git a/src/server/game/AI/CreatureAI.h b/src/server/game/AI/CreatureAI.h index 75a8650a23..8c26cfe132 100644 --- a/src/server/game/AI/CreatureAI.h +++ b/src/server/game/AI/CreatureAI.h @@ -127,6 +127,14 @@ class CreatureAI : public UnitAI virtual void SummonedCreatureDespawn(Creature* /*summon*/) { } virtual void SummonedCreatureDies(Creature* /*summon*/, Unit* /*killer*/) { } + // Called when the creature successfully summons a gameobject + virtual void JustSummonedGameobject(GameObject* /*gameobject*/) { } + virtual void SummonedGameobjectDespawn(GameObject* /*gameobject*/) { } + + // Called when the creature successfully registers a dynamicobject + virtual void JustRegisteredDynObject(DynamicObject* /*dynObject*/) { } + virtual void JustUnregisteredDynObject(DynamicObject* /*dynObject*/) { } + // Called when hit by a spell virtual void SpellHit(Unit* /*caster*/, SpellInfo const* /*spell*/) { } diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index 6e4577246f..7234625b65 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -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 dynamicobjects = GetDynObjects(spellId); + return dynamicobjects.empty() ? nullptr : dynamicobjects.front(); +} + +std::vector Unit::GetDynObjects(uint32 spellId) const +{ + std::vector 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 gameobjects = GetGameObjects(spellId); + return gameobjects.empty() ? nullptr : gameobjects.front(); +} + +std::vector Unit::GetGameObjects(uint32 spellId) const +{ + std::vector 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); diff --git a/src/server/game/Entities/Unit/Unit.h b/src/server/game/Entities/Unit/Unit.h index bcdc755805..e252d40b7e 100644 --- a/src/server/game/Entities/Unit/Unit.h +++ b/src/server/game/Entities/Unit/Unit.h @@ -1946,11 +1946,13 @@ class Unit : public WorldObject // DynamicObject management void _RegisterDynObject(DynamicObject* dynObj); void _UnregisterDynObject(DynamicObject* dynObj); - DynamicObject* GetDynObject(uint32 spellId); + DynamicObject* GetDynObject(uint32 spellId) const; + std::vector GetDynObjects(uint32 spellId) const; void RemoveDynObject(uint32 spellId); void RemoveAllDynObjects(); GameObject* GetGameObject(uint32 spellId) const; + std::vector GetGameObjects(uint32 spellId) const; void AddGameObject(GameObject* gameObj); void RemoveGameObject(GameObject* gameObj, bool del); void RemoveGameObject(uint32 spellid, bool del);