aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Entities
diff options
context:
space:
mode:
authorGiacomo Pozzoni <giacomopoz@gmail.com>2019-05-23 21:08:29 +0200
committerGitHub <noreply@github.com>2019-05-23 21:08:29 +0200
commit797fba98e95da1236465a15061ec4122d7ec33fe (patch)
tree2ebd1df31f8bd2573cdb65683e0966b4e3c97a43 /src/server/game/Entities
parent457fc224733cc78cedc5e956442a9f5d7bd2f049 (diff)
3.3.5 gameobject summoner (#23289)
* Scripts/Misc: Change IsSummonedBy(Unit*) to IsSummonedBy(WorldObject*) * Scripts/Misc: Fix build * Core/TempSummons: Rename GetSummoner() to GetSummonerUnit() * Core/TempSummons: Add support to TempSummons::GetSummoner() to return GameObject too * Fix build * Core/TempSummons: Allow GameObject to be owner of TempSummon * Core/TempSummons: Add support to SAI for GameObject owner of TempSummon * Scripts/Misc: Fix no-pch build * Core/TempSummons: Implement PR comments
Diffstat (limited to 'src/server/game/Entities')
-rw-r--r--src/server/game/Entities/Creature/TemporarySummon.cpp50
-rw-r--r--src/server/game/Entities/Creature/TemporarySummon.h6
-rw-r--r--src/server/game/Entities/Object/Object.cpp14
-rw-r--r--src/server/game/Entities/Unit/Unit.cpp15
4 files changed, 62 insertions, 23 deletions
diff --git a/src/server/game/Entities/Creature/TemporarySummon.cpp b/src/server/game/Entities/Creature/TemporarySummon.cpp
index b68bf43b4a5..6d6e72f9117 100644
--- a/src/server/game/Entities/Creature/TemporarySummon.cpp
+++ b/src/server/game/Entities/Creature/TemporarySummon.cpp
@@ -19,13 +19,15 @@
#include "TemporarySummon.h"
#include "CreatureAI.h"
#include "DBCStructure.h"
+#include "GameObject.h"
+#include "GameObjectAI.h"
#include "Log.h"
#include "Map.h"
#include "ObjectAccessor.h"
#include "Pet.h"
#include "Player.h"
-TempSummon::TempSummon(SummonPropertiesEntry const* properties, Unit* owner, bool isWorldObject) :
+TempSummon::TempSummon(SummonPropertiesEntry const* properties, WorldObject* owner, bool isWorldObject) :
Creature(isWorldObject), m_Properties(properties), m_type(TEMPSUMMON_MANUAL_DESPAWN),
m_timer(0), m_lifetime(0)
{
@@ -35,9 +37,16 @@ m_timer(0), m_lifetime(0)
m_unitTypeMask |= UNIT_MASK_SUMMON;
}
-Unit* TempSummon::GetSummoner() const
+WorldObject* TempSummon::GetSummoner() const
{
- return m_summonerGUID ? ObjectAccessor::GetUnit(*this, m_summonerGUID) : nullptr;
+ return m_summonerGUID ? ObjectAccessor::GetWorldObject(*this, m_summonerGUID) : nullptr;
+}
+
+Unit* TempSummon::GetSummonerUnit() const
+{
+ if (WorldObject* summoner = GetSummoner())
+ return summoner->ToUnit();
+ return nullptr;
}
Creature* TempSummon::GetSummonerCreatureBase() const
@@ -45,6 +54,13 @@ Creature* TempSummon::GetSummonerCreatureBase() const
return m_summonerGUID ? ObjectAccessor::GetCreature(*this, m_summonerGUID) : nullptr;
}
+GameObject* TempSummon::GetSummonerGameObject() const
+{
+ if (WorldObject* summoner = GetSummoner())
+ return summoner->ToGameObject();
+ return nullptr;
+}
+
void TempSummon::Update(uint32 diff)
{
Creature::Update(diff);
@@ -168,7 +184,7 @@ void TempSummon::InitStats(uint32 duration)
if (m_type == TEMPSUMMON_MANUAL_DESPAWN)
m_type = (duration == 0) ? TEMPSUMMON_DEAD_DESPAWN : TEMPSUMMON_TIMED_DESPAWN;
- Unit* owner = GetSummoner();
+ Unit* owner = GetSummonerUnit();
if (owner && IsTrigger() && m_spells[0])
{
@@ -203,11 +219,19 @@ void TempSummon::InitStats(uint32 duration)
void TempSummon::InitSummon()
{
- Unit* owner = GetSummoner();
+ 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);
+ }
if (IsAIEnabled())
AI()->IsSummonedBy(owner);
}
@@ -241,9 +265,13 @@ void TempSummon::UnSummon(uint32 msTime)
return;
}
- Unit* owner = GetSummoner();
- 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();
}
@@ -261,7 +289,7 @@ void TempSummon::RemoveFromWorld()
if (m_Properties)
if (uint32 slot = m_Properties->Slot)
- if (Unit* owner = GetSummoner())
+ if (Unit* owner = GetSummonerUnit())
if (owner->m_SummonSlot[slot] == GetGUID())
owner->m_SummonSlot[slot].Clear();
diff --git a/src/server/game/Entities/Creature/TemporarySummon.h b/src/server/game/Entities/Creature/TemporarySummon.h
index d0ef8cb38e4..de44bda118e 100644
--- a/src/server/game/Entities/Creature/TemporarySummon.h
+++ b/src/server/game/Entities/Creature/TemporarySummon.h
@@ -36,7 +36,7 @@ struct SummonPropertiesEntry;
class TC_GAME_API TempSummon : public Creature
{
public:
- explicit TempSummon(SummonPropertiesEntry const* properties, Unit* owner, bool isWorldObject);
+ explicit TempSummon(SummonPropertiesEntry const* properties, WorldObject* owner, bool isWorldObject);
virtual ~TempSummon() { }
void Update(uint32 time) override;
virtual void InitStats(uint32 lifetime);
@@ -46,8 +46,10 @@ class TC_GAME_API TempSummon : public Creature
void RemoveFromWorld() override;
void SetTempSummonType(TempSummonType type);
void SaveToDB(uint32 /*mapid*/, uint8 /*spawnMask*/, uint32 /*phaseMask*/) override { }
- Unit* GetSummoner() const;
+ WorldObject* GetSummoner() const;
+ Unit* GetSummonerUnit() const;
Creature* GetSummonerCreatureBase() const;
+ GameObject* GetSummonerGameObject() const;
ObjectGuid GetSummonerGUID() const { return m_summonerGUID; }
TempSummonType GetSummonType() const { return m_type; }
uint32 GetTimer() const { return m_timer; }
diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp
index afdd4dcdd25..3820e3e8523 100644
--- a/src/server/game/Entities/Object/Object.cpp
+++ b/src/server/game/Entities/Object/Object.cpp
@@ -1830,7 +1830,7 @@ void WorldObject::AddObjectToRemoveList()
map->AddObjectToRemoveList(this);
}
-TempSummon* Map::SummonCreature(uint32 entry, Position const& pos, SummonPropertiesEntry const* properties /*= nullptr*/, uint32 duration /*= 0*/, Unit* summoner /*= nullptr*/, uint32 spellId /*= 0*/, uint32 vehId /*= 0*/)
+TempSummon* Map::SummonCreature(uint32 entry, Position const& pos, SummonPropertiesEntry const* properties /*= nullptr*/, uint32 duration /*= 0*/, WorldObject* summoner /*= nullptr*/, uint32 spellId /*= 0*/, uint32 vehId /*= 0*/)
{
uint32 mask = UNIT_MASK_SUMMON;
if (properties)
@@ -1884,6 +1884,8 @@ TempSummon* Map::SummonCreature(uint32 entry, Position const& pos, SummonPropert
if (summoner)
phase = summoner->GetPhaseMask();
+ Unit* summonerUnit = summoner ? summoner->ToUnit() : nullptr;
+
TempSummon* summon = nullptr;
switch (mask)
{
@@ -1891,16 +1893,16 @@ TempSummon* Map::SummonCreature(uint32 entry, Position const& pos, SummonPropert
summon = new TempSummon(properties, summoner, false);
break;
case UNIT_MASK_GUARDIAN:
- summon = new Guardian(properties, summoner, false);
+ summon = new Guardian(properties, summonerUnit, false);
break;
case UNIT_MASK_PUPPET:
- summon = new Puppet(properties, summoner);
+ summon = new Puppet(properties, summonerUnit);
break;
case UNIT_MASK_TOTEM:
- summon = new Totem(properties, summoner);
+ summon = new Totem(properties, summonerUnit);
break;
case UNIT_MASK_MINION:
- summon = new Minion(properties, summoner, false);
+ summon = new Minion(properties, summonerUnit, false);
break;
}
@@ -1969,7 +1971,7 @@ TempSummon* WorldObject::SummonCreature(uint32 entry, Position const& pos, TempS
{
if (Map* map = FindMap())
{
- if (TempSummon* summon = map->SummonCreature(entry, pos, nullptr, despawnTime, ToUnit(), spellId))
+ if (TempSummon* summon = map->SummonCreature(entry, pos, nullptr, despawnTime, this, spellId))
{
summon->SetTempSummonType(despawnType);
return summon;
diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp
index 5b2cdfd0b7e..fbd2f89d611 100644
--- a/src/server/game/Entities/Unit/Unit.cpp
+++ b/src/server/game/Entities/Unit/Unit.cpp
@@ -31,6 +31,7 @@
#include "CreatureAI.h"
#include "CreatureAIImpl.h"
#include "Formulas.h"
+#include "GameObjectAI.h"
#include "GameTime.h"
#include "GridNotifiersImpl.h"
#include "Group.h"
@@ -806,7 +807,7 @@ bool Unit::HasBreakableByDamageCrowdControlAura(Unit* excludeCasterChannel) cons
if (!victim->ToCreature()->hasLootRecipient())
victim->ToCreature()->SetLootRecipient(attacker);
- if (!attacker || attacker->IsControlledByPlayer() || (attacker->ToTempSummon() && attacker->ToTempSummon()->GetSummoner() && attacker->ToTempSummon()->GetSummoner()->GetTypeId() == TYPEID_PLAYER))
+ if (!attacker || attacker->IsControlledByPlayer() || (attacker->ToTempSummon() && attacker->ToTempSummon()->GetSummonerUnit() && attacker->ToTempSummon()->GetSummonerUnit()->GetTypeId() == TYPEID_PLAYER))
victim->ToCreature()->LowerPlayerDamageReq(health < damage ? health : damage);
}
@@ -10955,10 +10956,16 @@ bool Unit::InitTamedPet(Pet* pet, uint8 level, uint32 spell_id)
if (CreatureAI* ai = creature->AI())
ai->JustDied(attacker);
- if (TempSummon* summon = creature->ToTempSummon())
- if (Unit* summoner = summon->GetSummoner())
- if (summoner->ToCreature() && summoner->IsAIEnabled())
+ if (TempSummon * summon = creature->ToTempSummon())
+ {
+ if (WorldObject * summoner = summon->GetSummoner())
+ {
+ if (summoner->ToCreature() && summoner->ToCreature()->IsAIEnabled())
summoner->ToCreature()->AI()->SummonedCreatureDies(creature, attacker);
+ else if (summoner->ToGameObject() && summoner->ToGameObject()->AI())
+ summoner->ToGameObject()->AI()->SummonedCreatureDies(creature, attacker);
+ }
+ }
// Dungeon specific stuff, only applies to players killing creatures
if (creature->GetInstanceId())