feat(Core/GameObject): Expand IsSummonedBy() to GameObjects (#14789)

Co-authored-by: jackpoz <giacomopoz@gmail.com>
This commit is contained in:
Skjalf
2023-01-29 09:44:33 -03:00
committed by GitHub
parent 4ecf96c379
commit bf30c66ba4
44 changed files with 191 additions and 95 deletions

View File

@@ -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();
}

View File

@@ -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())