Skip to content

Commit

Permalink
[c12674] Improvements for NPC summoning code
Browse files Browse the repository at this point in the history
* Inherit faction for guardians and similar - this will prevent a bunch of pet faction related error messages
* Inherit level from responsible caster and not only caster
* Improve default position selection for summon spells for GO-casts

(based on commit [12483] - 771342e)

Signed-off-by: Dramacydal <PulLumBerMal@gmail.com>
  • Loading branch information
Schmoozerd authored and Dramacydal committed Aug 19, 2013
1 parent eb25586 commit afbe871
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 24 deletions.
30 changes: 15 additions & 15 deletions src/game/DBCEnums.h
Expand Up @@ -487,21 +487,21 @@ enum UnitNameSummonTitle
// SummonProperties.dbc, col 5
enum SummonPropFlags
{
SUMMON_PROP_FLAG_NONE = 0x0000, // 1342 spells in 3.0.3
SUMMON_PROP_FLAG_UNK1 = 0x0001, // 75 spells in 3.0.3, something unfriendly
SUMMON_PROP_FLAG_UNK2 = 0x0002, // 616 spells in 3.0.3, something friendly
SUMMON_PROP_FLAG_UNK3 = 0x0004, // 22 spells in 3.0.3, no idea...
SUMMON_PROP_FLAG_UNK4 = 0x0008, // 49 spells in 3.0.3, some mounts
SUMMON_PROP_FLAG_UNK5 = 0x0010, // 25 spells in 3.0.3, quest related?
SUMMON_PROP_FLAG_CANT_BE_DISMISSED = 0x0020, // 0 spells in 3.0.3, unused
SUMMON_PROP_FLAG_UNK7 = 0x0040, // 12 spells in 3.0.3, no idea
SUMMON_PROP_FLAG_UNK8 = 0x0080, // 4 spells in 3.0.3, no idea
SUMMON_PROP_FLAG_UNK9 = 0x0100, // 51 spells in 3.0.3, no idea, many quest related
SUMMON_PROP_FLAG_UNK10 = 0x0200, // 51 spells in 3.0.3, something defensive
SUMMON_PROP_FLAG_UNK11 = 0x0400, // 3 spells, requires something near?
SUMMON_PROP_FLAG_UNK12 = 0x0800, // 30 spells in 3.0.3, no idea
SUMMON_PROP_FLAG_UNK13 = 0x1000, // 8 spells in 3.0.3, siege vehicle
SUMMON_PROP_FLAG_UNK14 = 0x2000, // 2 spells in 3.0.3, escort?
SUMMON_PROP_FLAG_NONE = 0x0000, // 1342 spells in 3.0.3
SUMMON_PROP_FLAG_UNK1 = 0x0001, // 75 spells in 3.0.3, something unfriendly
SUMMON_PROP_FLAG_UNK2 = 0x0002, // 616 spells in 3.0.3, something friendly
SUMMON_PROP_FLAG_UNK3 = 0x0004, // 22 spells in 3.0.3, no idea...
SUMMON_PROP_FLAG_UNK4 = 0x0008, // 49 spells in 3.0.3, some mounts
SUMMON_PROP_FLAG_UNK5 = 0x0010, // 25 spells in 3.0.3, quest related?
SUMMON_PROP_FLAG_CANT_BE_DISMISSED = 0x0020, // 0 spells in 3.0.3, unused
SUMMON_PROP_FLAG_UNK7 = 0x0040, // 12 spells in 3.0.3, no idea
SUMMON_PROP_FLAG_UNK8 = 0x0080, // 4 spells in 3.0.3, no idea
SUMMON_PROP_FLAG_UNK9 = 0x0100, // 51 spells in 3.0.3, no idea, many quest related
SUMMON_PROP_FLAG_INHERIT_FACTION = 0x0200, // 51 spells in 3.0.3, something defensive (Faction inheriting is much guesswork)
SUMMON_PROP_FLAG_UNK11 = 0x0400, // 3 spells, requires something near?
SUMMON_PROP_FLAG_UNK12 = 0x0800, // 30 spells in 3.0.3, no idea
SUMMON_PROP_FLAG_UNK13 = 0x1000, // 8 spells in 3.0.3, siege vehicle
SUMMON_PROP_FLAG_UNK14 = 0x2000, // 2 spells in 3.0.3, escort?
};

// SpellEntry::Targets
Expand Down
31 changes: 23 additions & 8 deletions src/game/SpellEffects.cpp
Expand Up @@ -5029,6 +5029,18 @@ void Spell::EffectSummonType(SpellEffectEntry const* effect)
return;
}

// Get casting object
WorldObject* realCaster = GetCastingObject();
if (!realCaster)
{
sLog.outError("EffectSummonType: No Casting Object found for spell %u, (caster = %s)", m_spellInfo->Id, m_caster->GetGuidStr().c_str());
return;
}

Unit* responsibleCaster = m_originalCaster;
if (realCaster->GetTypeId() == TYPEID_GAMEOBJECT)
responsibleCaster = ((GameObject*)realCaster)->GetOwner();

// Expected Amount: TODO - there are quite some exceptions (like totems, engineering dragonlings..)
uint32 amount = damage > 0 ? damage : 1;

Expand All @@ -5037,7 +5049,7 @@ void Spell::EffectSummonType(SpellEffectEntry const* effect)
amount = 1;

// Expected Level (Totem, Pet and Critter may not use this)
uint32 level = m_caster->getLevel();
uint32 level = responsibleCaster ? responsibleCaster->getLevel() : m_caster->getLevel();
// level of creature summoned using engineering item based at engineering skill level
if (m_caster->GetTypeId() == TYPEID_PLAYER && m_CastItem)
{
Expand All @@ -5058,7 +5070,7 @@ void Spell::EffectSummonType(SpellEffectEntry const* effect)
m_targets.getDestination(summonPositions[0].x, summonPositions[0].y, summonPositions[0].z);
else
{
m_caster->GetPosition(summonPositions[0].x, summonPositions[0].y, summonPositions[0].z);
realCaster->GetPosition(summonPositions[0].x, summonPositions[0].y, summonPositions[0].z);

// TODO - Is this really an error?
sLog.outDebug("Spell Effect EFFECT_SUMMON (%u) - summon without destination (spell id %u, effIndex %u)", effect->Effect, m_spellInfo->Id, SpellEffectIndex(effect->EffectIndex));
Expand All @@ -5071,15 +5083,15 @@ void Spell::EffectSummonType(SpellEffectEntry const* effect)
{
if (m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION || radius > 1.0f)
{
m_caster->GetRandomPoint(summonPositions[0].x, summonPositions[0].y, summonPositions[0].z, radius, itr->x, itr->y, itr->z);
if (m_caster->GetMap()->GetHitPosition(summonPositions[0].x, summonPositions[0].y, summonPositions[0].z, itr->x, itr->y, itr->z, m_caster->GetPhaseMask(), -0.5f))
m_caster->UpdateAllowedPositionZ(itr->x, itr->y, itr->z);
realCaster->GetRandomPoint(summonPositions[0].x, summonPositions[0].y, summonPositions[0].z, radius, itr->x, itr->y, itr->z);
if (realCaster->GetMap()->GetHitPosition(summonPositions[0].x, summonPositions[0].y, summonPositions[0].z, itr->x, itr->y, itr->z, m_caster->GetPhaseMask(), -0.5f))
realCaster->UpdateAllowedPositionZ(itr->x, itr->y, itr->z);
}
else // Get a point near the caster
{
m_caster->GetClosePoint(itr->x, itr->y, itr->z, 0.0f, radius, frand(0.0f, 2 * M_PI_F));
if (m_caster->GetMap()->GetHitPosition(summonPositions[0].x, summonPositions[0].y, summonPositions[0].z, itr->x, itr->y, itr->z, m_caster->GetPhaseMask(), -0.5f))
m_caster->UpdateAllowedPositionZ(itr->x, itr->y, itr->z);
realCaster->GetClosePoint(itr->x, itr->y, itr->z, 0.0f, radius, frand(0.0f, 2 * M_PI_F));
if (realCaster->GetMap()->GetHitPosition(summonPositions[0].x, summonPositions[0].y, summonPositions[0].z, itr->x, itr->y, itr->z, m_caster->GetPhaseMask(), -0.5f))
realCaster->UpdateAllowedPositionZ(itr->x, itr->y, itr->z);
}
}

Expand Down Expand Up @@ -5205,6 +5217,9 @@ void Spell::EffectSummonType(SpellEffectEntry const* effect)

if (summon_prop->FactionId)
itr->creature->setFaction(summon_prop->FactionId);
// Else set faction to summoner's faction for pet-like summoned
else if ((summon_prop->Flags & SUMMON_PROP_FLAG_INHERIT_FACTION) || !itr->creature->IsTemporarySummon())
itr->creature->setFaction(responsibleCaster ? responsibleCaster->getFaction() : m_caster->getFaction());

if (!itr->creature->IsTemporarySummon())
{
Expand Down
2 changes: 1 addition & 1 deletion src/shared/revision_nr.h
@@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "12673"
#define REVISION_NR "12674"
#endif // __REVISION_NR_H__

0 comments on commit afbe871

Please sign in to comment.