Skip to content

Commit

Permalink
[12483] 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
  • Loading branch information
Schmoozerd committed May 10, 2013
1 parent 953ac1b commit 771342e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/game/DBCEnums.h
Expand Up @@ -398,7 +398,7 @@ enum SummonPropFlags
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_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
Expand Down
31 changes: 23 additions & 8 deletions src/game/SpellEffects.cpp
Expand Up @@ -4988,6 +4988,18 @@ void Spell::EffectSummonType(SpellEffectIndex eff_idx)
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 @@ -4996,7 +5008,7 @@ void Spell::EffectSummonType(SpellEffectIndex eff_idx)
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 @@ -5017,7 +5029,7 @@ void Spell::EffectSummonType(SpellEffectIndex eff_idx)
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)", m_spellInfo->Effect[eff_idx], m_spellInfo->Id, eff_idx);
Expand All @@ -5030,15 +5042,15 @@ void Spell::EffectSummonType(SpellEffectIndex eff_idx)
{
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 @@ -5164,6 +5176,9 @@ void Spell::EffectSummonType(SpellEffectIndex eff_idx)

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 "12482"
#define REVISION_NR "12483"
#endif // __REVISION_NR_H__

4 comments on commit 771342e

@cala
Copy link
Contributor

@cala cala commented on 771342e May 10, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this means we will no longer see some "Minion of insert_name_here" as hostile while insert_name_here is friendly?

@Schmoozerd
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should happen, yes :)

@cala
Copy link
Contributor

@cala cala commented on 771342e May 10, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is sweet. Thank you.

@Rog360
Copy link

@Rog360 Rog360 commented on 771342e May 10, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice Work... ;)

Please sign in to comment.