Core/Spells: Implemented personal summons (#19231)

* By default determined by summon property flag SUMMON_PROP_FLAG_PERSONAL_SPAWN

Closes #18254
This commit is contained in:
Traesh
2018-04-08 20:35:33 +02:00
committed by Shauren
parent 66c559f15b
commit b7bb5e6a98
9 changed files with 51 additions and 17 deletions

View File

@@ -25,6 +25,7 @@
#include "UnitEvents.h"
#include "SpellAuras.h"
#include "SpellMgr.h"
#include "TemporarySummon.h"
//==============================================================
//================= ThreatCalcHelper ===========================
@@ -415,11 +416,28 @@ void ThreatManager::addThreat(Unit* victim, float threat, SpellSchoolMask school
void ThreatManager::doAddThreat(Unit* victim, float threat)
{
uint32 redirectThreadPct = victim->GetRedirectThreatPercent();
Unit* redirectTarget = victim->GetRedirectThreatTarget();
// If victim is personnal spawn, redirect all aggro to summoner
if (TempSummon* tempSummonVictim = victim->ToTempSummon())
{
if (tempSummonVictim->IsVisibleBySummonerOnly())
{
// Personnal Spawns from same summoner can aggro each other
if (!GetOwner()->ToTempSummon() ||
!GetOwner()->ToTempSummon()->IsVisibleBySummonerOnly() ||
tempSummonVictim->GetSummonerGUID() != GetOwner()->ToTempSummon()->GetSummonerGUID())
{
redirectThreadPct = 100;
redirectTarget = tempSummonVictim->GetSummoner();
}
}
}
// must check > 0.0f, otherwise dead loop
if (threat > 0.0f && redirectThreadPct)
{
if (Unit* redirectTarget = victim->GetRedirectThreatTarget())
if (redirectTarget)
{
float redirectThreat = CalculatePct(threat, redirectThreadPct);
threat -= redirectThreat;

View File

@@ -957,7 +957,7 @@ enum SummonPropFlags
SUMMON_PROP_FLAG_UNK2 = 0x00000002, // 616 spells in 3.0.3, something friendly
SUMMON_PROP_FLAG_UNK3 = 0x00000004, // 22 spells in 3.0.3, no idea...
SUMMON_PROP_FLAG_UNK4 = 0x00000008, // 49 spells in 3.0.3, some mounts
SUMMON_PROP_FLAG_UNK5 = 0x00000010, // 25 spells in 3.0.3, quest related?
SUMMON_PROP_FLAG_PERSONAL_SPAWN = 0x00000010, // Personal Spawn (creature visible only by summoner)
SUMMON_PROP_FLAG_UNK6 = 0x00000020, // 0 spells in 3.3.5, unused
SUMMON_PROP_FLAG_UNK7 = 0x00000040, // 12 spells in 3.0.3, no idea
SUMMON_PROP_FLAG_UNK8 = 0x00000080, // 4 spells in 3.0.3, no idea

View File

@@ -27,7 +27,7 @@
TempSummon::TempSummon(SummonPropertiesEntry const* properties, Unit* owner, bool isWorldObject) :
Creature(isWorldObject), m_Properties(properties), m_type(TEMPSUMMON_MANUAL_DESPAWN),
m_timer(0), m_lifetime(0)
m_timer(0), m_lifetime(0), m_visibleBySummonerOnly(false)
{
if (owner)
m_summonerGUID = owner->GetGUID();

View File

@@ -60,12 +60,16 @@ class TC_GAME_API TempSummon : public Creature
TempSummonType const& GetSummonType() { return m_type; }
uint32 GetTimer() const { return m_timer; }
void SetVisibleBySummonerOnly(bool visibleBySummonerOnly) { m_visibleBySummonerOnly = visibleBySummonerOnly; }
bool IsVisibleBySummonerOnly() const { return m_visibleBySummonerOnly; }
const SummonPropertiesEntry* const m_Properties;
private:
TempSummonType m_type;
uint32 m_timer;
uint32 m_lifetime;
ObjectGuid m_summonerGUID;
bool m_visibleBySummonerOnly;
};
class TC_GAME_API Minion : public TempSummon

View File

@@ -2645,7 +2645,7 @@ void GameObject::SetAnimKitId(uint16 animKitId, bool oneshot)
class GameObjectModelOwnerImpl : public GameObjectModelOwnerBase
{
public:
explicit GameObjectModelOwnerImpl(GameObject const* owner) : _owner(owner) { }
explicit GameObjectModelOwnerImpl(GameObject* owner) : _owner(owner) { }
virtual ~GameObjectModelOwnerImpl() = default;
bool IsSpawned() const override { return _owner->isSpawned(); }
@@ -2658,7 +2658,7 @@ public:
void DebugVisualizeCorner(G3D::Vector3 const& corner) const override { _owner->SummonCreature(1, corner.x, corner.y, corner.z, 0, TEMPSUMMON_MANUAL_DESPAWN); }
private:
GameObject const* _owner;
GameObject* _owner;
};
GameObjectModel* GameObject::CreateModel()

View File

@@ -2112,8 +2112,15 @@ bool WorldObject::CanSeeOrDetect(WorldObject const* obj, bool ignoreStealth, boo
WorldObject const* viewpoint = this;
if (Player const* player = this->ToPlayer())
{
viewpoint = player->GetViewpoint();
if (Creature const* creature = obj->ToCreature())
if (TempSummon const* tempSummon = creature->ToTempSummon())
if (tempSummon->IsVisibleBySummonerOnly() && GetGUID() != tempSummon->GetSummonerGUID())
return false;
}
if (!viewpoint)
viewpoint = this;
@@ -2346,7 +2353,7 @@ void WorldObject::AddObjectToRemoveList()
map->AddObjectToRemoveList(this);
}
TempSummon* Map::SummonCreature(uint32 entry, Position const& pos, SummonPropertiesEntry const* properties /*= NULL*/, uint32 duration /*= 0*/, Unit* summoner /*= NULL*/, uint32 spellId /*= 0*/, uint32 vehId /*= 0*/)
TempSummon* Map::SummonCreature(uint32 entry, Position const& pos, SummonPropertiesEntry const* properties /*= NULL*/, uint32 duration /*= 0*/, Unit* summoner /*= NULL*/, uint32 spellId /*= 0*/, uint32 vehId /*= 0*/, bool visibleBySummonerOnly /*= false*/)
{
uint32 mask = UNIT_MASK_SUMMON;
if (properties)
@@ -2431,6 +2438,9 @@ TempSummon* Map::SummonCreature(uint32 entry, Position const& pos, SummonPropert
summon->SetHomePosition(pos);
summon->InitStats(duration);
summon->SetVisibleBySummonerOnly(visibleBySummonerOnly);
AddToMap(summon->ToCreature());
summon->InitSummon();
@@ -2485,11 +2495,11 @@ Scenario* WorldObject::GetScenario() const
return nullptr;
}
TempSummon* WorldObject::SummonCreature(uint32 entry, Position const& pos, TempSummonType spwtype /*= TEMPSUMMON_MANUAL_DESPAWN*/, uint32 duration /*= 0*/, uint32 /*vehId = 0*/) const
TempSummon* WorldObject::SummonCreature(uint32 entry, Position const& pos, TempSummonType spwtype /*= TEMPSUMMON_MANUAL_DESPAWN*/, uint32 duration /*= 0*/, uint32 vehId /*= 0*/, bool visibleBySummonerOnly /*= false*/)
{
if (Map* map = FindMap())
{
if (TempSummon* summon = map->SummonCreature(entry, pos, NULL, duration, isType(TYPEMASK_UNIT) ? (Unit*)this : NULL))
if (TempSummon* summon = map->SummonCreature(entry, pos, nullptr, duration, ToUnit(), 0, vehId, visibleBySummonerOnly))
{
summon->SetTempSummonType(spwtype);
return summon;
@@ -2499,7 +2509,7 @@ TempSummon* WorldObject::SummonCreature(uint32 entry, Position const& pos, TempS
return nullptr;
}
TempSummon* WorldObject::SummonCreature(uint32 id, float x, float y, float z, float ang /*= 0*/, TempSummonType spwtype /*= TEMPSUMMON_MANUAL_DESPAWN*/, uint32 despwtime /*= 0*/) const
TempSummon* WorldObject::SummonCreature(uint32 id, float x, float y, float z, float ang /*= 0*/, TempSummonType spwtype /*= TEMPSUMMON_MANUAL_DESPAWN*/, uint32 despwtime /*= 0*/, bool visibleBySummonerOnly /*= false*/)
{
if (!x && !y && !z)
{
@@ -2509,7 +2519,7 @@ TempSummon* WorldObject::SummonCreature(uint32 id, float x, float y, float z, fl
Position pos;
pos.Relocate(x, y, z, ang);
return SummonCreature(id, pos, spwtype, despwtime, 0);
return SummonCreature(id, pos, spwtype, despwtime, 0, visibleBySummonerOnly);
}
GameObject* WorldObject::SummonGameObject(uint32 entry, Position const& pos, QuaternionData const& rot, uint32 respawnTime)

View File

@@ -502,8 +502,8 @@ class TC_GAME_API WorldObject : public Object, public WorldLocation
Scenario* GetScenario() const;
TempSummon* SummonCreature(uint32 id, Position const& pos, TempSummonType spwtype = TEMPSUMMON_MANUAL_DESPAWN, uint32 despwtime = 0, uint32 vehId = 0) const;
TempSummon* SummonCreature(uint32 id, float x, float y, float z, float ang = 0, TempSummonType spwtype = TEMPSUMMON_MANUAL_DESPAWN, uint32 despwtime = 0) const;
TempSummon* SummonCreature(uint32 id, Position const& pos, TempSummonType spwtype = TEMPSUMMON_MANUAL_DESPAWN, uint32 despwtime = 0, uint32 vehId = 0, bool visibleBySummonerOnly = false);
TempSummon* SummonCreature(uint32 id, float x, float y, float z, float ang = 0, TempSummonType spwtype = TEMPSUMMON_MANUAL_DESPAWN, uint32 despwtime = 0, bool visibleBySummonerOnly = false);
GameObject* SummonGameObject(uint32 entry, Position const& pos, QuaternionData const& rot, uint32 respawnTime /* s */);
GameObject* SummonGameObject(uint32 entry, float x, float y, float z, float ang, QuaternionData const& rot, uint32 respawnTime /* s */);
Creature* SummonTrigger(float x, float y, float z, float ang, uint32 dur, CreatureAI* (*GetAI)(Creature*) = NULL);

View File

@@ -447,7 +447,7 @@ class TC_GAME_API Map : public GridRefManager<NGridType>
void UpdateIteratorBack(Player* player);
TempSummon* SummonCreature(uint32 entry, Position const& pos, SummonPropertiesEntry const* properties = NULL, uint32 duration = 0, Unit* summoner = NULL, uint32 spellId = 0, uint32 vehId = 0);
TempSummon* SummonCreature(uint32 entry, Position const& pos, SummonPropertiesEntry const* properties = NULL, uint32 duration = 0, Unit* summoner = NULL, uint32 spellId = 0, uint32 vehId = 0, bool visibleOnlyBySummoner = false);
void SummonCreatureGroup(uint8 group, std::list<TempSummon*>* list = NULL);
AreaTrigger* GetAreaTrigger(ObjectGuid const& guid);
Conversation* GetConversation(ObjectGuid const& guid);

View File

@@ -1974,6 +1974,8 @@ void Spell::EffectSummonType(SpellEffIndex effIndex)
if (!m_originalCaster)
return;
bool personalSpawn = (properties->Flags & SUMMON_PROP_FLAG_PERSONAL_SPAWN) != 0;
int32 duration = m_spellInfo->CalcDuration(m_originalCaster);
TempSummon* summon = NULL;
@@ -2035,7 +2037,7 @@ void Spell::EffectSummonType(SpellEffIndex effIndex)
case SUMMON_TYPE_LIGHTWELL:
case SUMMON_TYPE_TOTEM:
{
summon = m_caster->GetMap()->SummonCreature(entry, *destTarget, properties, duration, m_originalCaster, m_spellInfo->Id);
summon = m_caster->GetMap()->SummonCreature(entry, *destTarget, properties, duration, m_originalCaster, m_spellInfo->Id, 0, personalSpawn);
if (!summon || !summon->IsTotem())
return;
@@ -2048,7 +2050,7 @@ void Spell::EffectSummonType(SpellEffIndex effIndex)
}
case SUMMON_TYPE_MINIPET:
{
summon = m_caster->GetMap()->SummonCreature(entry, *destTarget, properties, duration, m_originalCaster, m_spellInfo->Id);
summon = m_caster->GetMap()->SummonCreature(entry, *destTarget, properties, duration, m_originalCaster, m_spellInfo->Id, 0, personalSpawn);
if (!summon || !summon->HasUnitTypeMask(UNIT_MASK_MINION))
return;
@@ -2075,7 +2077,7 @@ void Spell::EffectSummonType(SpellEffIndex effIndex)
// randomize position for multiple summons
pos = m_caster->GetRandomPoint(*destTarget, radius);
summon = m_originalCaster->SummonCreature(entry, pos, summonType, duration);
summon = m_originalCaster->SummonCreature(entry, pos, summonType, duration, 0, personalSpawn);
if (!summon)
continue;
@@ -2096,7 +2098,7 @@ void Spell::EffectSummonType(SpellEffIndex effIndex)
SummonGuardian(effIndex, entry, properties, numSummons);
break;
case SUMMON_CATEGORY_PUPPET:
summon = m_caster->GetMap()->SummonCreature(entry, *destTarget, properties, duration, m_originalCaster, m_spellInfo->Id);
summon = m_caster->GetMap()->SummonCreature(entry, *destTarget, properties, duration, m_originalCaster, m_spellInfo->Id, 0, personalSpawn);
break;
case SUMMON_CATEGORY_VEHICLE:
// Summoning spells (usually triggered by npc_spellclick) that spawn a vehicle and that cause the clicker