mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-31 09:33:47 +00:00
feat(Core/GameObject): Expand IsSummonedBy() to GameObjects (#14789)
Co-authored-by: jackpoz <giacomopoz@gmail.com>
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
#include "QuestDef.h"
|
||||
#include <list>
|
||||
|
||||
class Creature;
|
||||
class GameObject;
|
||||
class Unit;
|
||||
class SpellInfo;
|
||||
@@ -66,6 +67,10 @@ public:
|
||||
virtual void SpellHit(Unit* /*unit*/, SpellInfo const* /*spellInfo*/) {}
|
||||
virtual bool CanBeSeen(Player const* /*seer*/) { return true; }
|
||||
|
||||
// Called when the gameobject summon successfully other creature
|
||||
virtual void JustSummoned(Creature* /*summon*/) { }
|
||||
virtual void SummonedCreatureDespawn(Creature* /*summon*/) { }
|
||||
|
||||
virtual void SummonedCreatureDies(Creature* /*summon*/, Unit* /*killer*/) { }
|
||||
};
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ int32 CritterAI::Permissible(Creature const* creature)
|
||||
return PERMIT_BASE_NO;
|
||||
}
|
||||
|
||||
void TriggerAI::IsSummonedBy(Unit* summoner)
|
||||
void TriggerAI::IsSummonedBy(WorldObject* summoner)
|
||||
{
|
||||
if (me->m_spells[0])
|
||||
me->CastSpell(me, me->m_spells[0], false, 0, 0, summoner ? summoner->GetGUID() : ObjectGuid::Empty);
|
||||
|
||||
@@ -80,7 +80,7 @@ class TriggerAI : public NullCreatureAI
|
||||
{
|
||||
public:
|
||||
explicit TriggerAI(Creature* c) : NullCreatureAI(c) {}
|
||||
void IsSummonedBy(Unit* summoner) override;
|
||||
void IsSummonedBy(WorldObject* summoner) override;
|
||||
|
||||
static int32 Permissible(Creature const* creature);
|
||||
};
|
||||
|
||||
@@ -126,7 +126,7 @@ public:
|
||||
|
||||
// Called when the creature summon successfully other creature
|
||||
virtual void JustSummoned(Creature* /*summon*/) {}
|
||||
virtual void IsSummonedBy(Unit* /*summoner*/) {}
|
||||
virtual void IsSummonedBy(WorldObject* /*summoner*/) {}
|
||||
|
||||
virtual void SummonedCreatureDespawn(Creature* /*summon*/) {}
|
||||
virtual void SummonedCreatureDies(Creature* /*summon*/, Unit* /*killer*/) {}
|
||||
|
||||
@@ -878,9 +878,9 @@ void SmartAI::ReceiveEmote(Player* player, uint32 textEmote)
|
||||
GetScript()->ProcessEventsFor(SMART_EVENT_RECEIVE_EMOTE, player, textEmote);
|
||||
}
|
||||
|
||||
void SmartAI::IsSummonedBy(Unit* summoner)
|
||||
void SmartAI::IsSummonedBy(WorldObject* summoner)
|
||||
{
|
||||
GetScript()->ProcessEventsFor(SMART_EVENT_JUST_SUMMONED, summoner);
|
||||
GetScript()->ProcessEventsFor(SMART_EVENT_JUST_SUMMONED, summoner->ToUnit(), 0, 0, false, nullptr, summoner->ToGameObject());
|
||||
}
|
||||
|
||||
void SmartAI::DamageDealt(Unit* doneTo, uint32& damage, DamageEffectType /*damagetype*/)
|
||||
|
||||
@@ -125,7 +125,7 @@ public:
|
||||
void MovementInform(uint32 MovementType, uint32 Data) override;
|
||||
|
||||
// Called when creature is summoned by another unit
|
||||
void IsSummonedBy(Unit* summoner) override;
|
||||
void IsSummonedBy(WorldObject* summoner) override;
|
||||
|
||||
// Called at any Damage to any victim (before damage apply)
|
||||
void DamageDealt(Unit* doneTo, uint32& damage, DamageEffectType damagetyp) override;
|
||||
|
||||
@@ -3207,13 +3207,23 @@ void SmartScript::GetTargets(ObjectVector& targets, SmartScriptHolder const& e,
|
||||
// xinef: Get owner of owner
|
||||
if (e.target.owner.useCharmerOrOwner && !targets.empty())
|
||||
{
|
||||
if (Unit* owner = targets.front()->ToUnit())
|
||||
if (WorldObject* owner = targets.front())
|
||||
{
|
||||
targets.clear();
|
||||
|
||||
if (Unit* base = ObjectAccessor::GetUnit(*owner, owner->GetCharmerOrOwnerGUID()))
|
||||
if (owner->ToCreature())
|
||||
{
|
||||
targets.push_back(base);
|
||||
if (Unit* base = ObjectAccessor::GetUnit(*owner, owner->ToCreature()->GetCharmerOrOwnerGUID()))
|
||||
{
|
||||
targets.push_back(base);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Unit* base = ObjectAccessor::GetUnit(*owner, owner->ToGameObject()->GetOwnerGUID()))
|
||||
{
|
||||
targets.push_back(base);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
|
||||
#include "TemporarySummon.h"
|
||||
#include "CreatureAI.h"
|
||||
#include "GameObject.h"
|
||||
#include "GameObjectAI.h"
|
||||
#include "Log.h"
|
||||
#include "ObjectAccessor.h"
|
||||
#include "Pet.h"
|
||||
@@ -250,11 +252,23 @@ void TempSummon::InitStats(uint32 duration)
|
||||
|
||||
void TempSummon::InitSummon()
|
||||
{
|
||||
Unit* owner = GetSummonerUnit();
|
||||
WorldObject* owner = GetSummoner();
|
||||
if (owner)
|
||||
{
|
||||
if (owner->GetTypeId() == TYPEID_UNIT && owner->ToCreature()->IsAIEnabled)
|
||||
owner->ToCreature()->AI()->JustSummoned(this);
|
||||
if (owner->GetTypeId() == TYPEID_UNIT)
|
||||
{
|
||||
if (owner->ToCreature()->IsAIEnabled)
|
||||
{
|
||||
owner->ToCreature()->AI()->JustSummoned(this);
|
||||
}
|
||||
}
|
||||
else if (owner->GetTypeId() == TYPEID_GAMEOBJECT)
|
||||
{
|
||||
if (owner->ToGameObject()->AI())
|
||||
{
|
||||
owner->ToGameObject()->AI()->JustSummoned(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Xinef: Allow to call this hook when npc is summoned by gameobject, in this case pass this as summoner to avoid possible null checks
|
||||
@@ -290,9 +304,17 @@ void TempSummon::UnSummon(uint32 msTime)
|
||||
return;
|
||||
}
|
||||
|
||||
Unit* owner = GetSummonerUnit();
|
||||
if (owner && owner->GetTypeId() == TYPEID_UNIT && owner->ToCreature()->IsAIEnabled)
|
||||
owner->ToCreature()->AI()->SummonedCreatureDespawn(this);
|
||||
if (WorldObject* owner = GetSummoner())
|
||||
{
|
||||
if (owner->GetTypeId() == TYPEID_UNIT && owner->ToCreature()->IsAIEnabled)
|
||||
{
|
||||
owner->ToCreature()->AI()->SummonedCreatureDespawn(this);
|
||||
}
|
||||
else if (owner->GetTypeId() == TYPEID_GAMEOBJECT && owner->ToGameObject()->AI())
|
||||
{
|
||||
owner->ToGameObject()->AI()->SummonedCreatureDespawn(this);
|
||||
}
|
||||
}
|
||||
|
||||
AddObjectToRemoveList();
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "DisableMgr.h"
|
||||
#include "DynamicVisibility.h"
|
||||
#include "Formulas.h"
|
||||
#include "GameObjectAI.h"
|
||||
#include "GameTime.h"
|
||||
#include "GridNotifiersImpl.h"
|
||||
#include "Group.h"
|
||||
@@ -18081,9 +18082,19 @@ void Unit::Kill(Unit* killer, Unit* victim, bool durabilityLoss, WeaponAttackTyp
|
||||
}
|
||||
|
||||
if (TempSummon* summon = creature->ToTempSummon())
|
||||
if (Unit* summoner = summon->GetSummonerUnit())
|
||||
if (summoner->ToCreature() && summoner->IsAIEnabled)
|
||||
{
|
||||
if (WorldObject* summoner = summon->GetSummoner())
|
||||
{
|
||||
if (summoner->ToCreature() && summoner->ToCreature()->IsAIEnabled)
|
||||
{
|
||||
summoner->ToCreature()->AI()->SummonedCreatureDies(creature, killer);
|
||||
}
|
||||
else if (summoner->ToGameObject() && summoner->ToGameObject()->AI())
|
||||
{
|
||||
summoner->ToGameObject()->AI()->SummonedCreatureDies(creature, killer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Dungeon specific stuff, only applies to players killing creatures
|
||||
if (creature->GetInstanceId())
|
||||
|
||||
Reference in New Issue
Block a user