[8686] Fixed logic of triggering spells from SPELL_AURA_PERIODIC_TRIGGER_SPELL and SPELL_AURA_PERIODIC_TRIGGER_SPELL_WITH_VALUE.

This patch should correct target selection for triggered spells
with target type TARGET_SELF.

Signed-off-by: ApoC <apoc@nymfe.net>
This commit is contained in:
ApoC 2009-10-20 19:39:23 +02:00
parent cd43a0a192
commit 5bae4fccf8
2 changed files with 46 additions and 36 deletions

View file

@ -572,7 +572,7 @@ Aura* CreateAura(SpellEntry const* spellproto, uint32 eff, int32 *currentBasePoi
Unit* Aura::GetCaster() const Unit* Aura::GetCaster() const
{ {
if(m_caster_guid==m_target->GetGUID()) if(m_caster_guid == m_target->GetGUID())
return m_target; return m_target;
//return ObjectAccessor::GetUnit(*m_target,m_caster_guid); //return ObjectAccessor::GetUnit(*m_target,m_caster_guid);
@ -1450,10 +1450,10 @@ void Aura::HandleAddTargetTrigger(bool apply, bool /*Real*/)
void Aura::TriggerSpell() void Aura::TriggerSpell()
{ {
Unit* caster = GetCaster(); const uint64& casterGUID = GetCasterGUID();
Unit* target = GetTriggerTarget(); Unit* target = GetTriggerTarget();
if(!caster || !target) if(!casterGUID || !target)
return; return;
// generic casting code with custom spells and target/caster customs // generic casting code with custom spells and target/caster customs
@ -1479,9 +1479,9 @@ void Aura::TriggerSpell()
case 17949: case 17949:
case 27252: case 27252:
{ {
if (caster->GetTypeId()!=TYPEID_PLAYER) if (target->GetTypeId() != TYPEID_PLAYER)
return; return;
Item* item = ((Player*)caster)->GetWeaponForAttack(BASE_ATTACK); Item* item = ((Player*)target)->GetWeaponForAttack(BASE_ATTACK);
if (!item) if (!item)
return; return;
uint32 enchant_id = 0; uint32 enchant_id = 0;
@ -1496,10 +1496,10 @@ void Aura::TriggerSpell()
return; return;
} }
// remove old enchanting before applying new // remove old enchanting before applying new
((Player*)caster)->ApplyEnchantment(item,TEMP_ENCHANTMENT_SLOT,false); ((Player*)target)->ApplyEnchantment(item,TEMP_ENCHANTMENT_SLOT,false);
item->SetEnchantment(TEMP_ENCHANTMENT_SLOT, enchant_id, m_modifier.periodictime+1000, 0); item->SetEnchantment(TEMP_ENCHANTMENT_SLOT, enchant_id, m_modifier.periodictime+1000, 0);
// add new enchanting // add new enchanting
((Player*)caster)->ApplyEnchantment(item,TEMP_ENCHANTMENT_SLOT,true); ((Player*)target)->ApplyEnchantment(item,TEMP_ENCHANTMENT_SLOT,true);
return; return;
} }
// // Periodic Mana Burn // // Periodic Mana Burn
@ -1542,14 +1542,13 @@ void Aura::TriggerSpell()
// Restoration // Restoration
case 23493: case 23493:
{ {
int32 heal = caster->GetMaxHealth() / 10; int32 heal = target->GetMaxHealth() / 10;
caster->DealHeal(caster, heal, auraSpellInfo); target->DealHeal(target, heal, auraSpellInfo);
int32 mana = caster->GetMaxPower(POWER_MANA); if (int32 mana = target->GetMaxPower(POWER_MANA))
if (mana)
{ {
mana /= 10; mana /= 10;
caster->EnergizeBySpell(caster, 23493, mana, POWER_MANA); target->EnergizeBySpell(target, 23493, mana, POWER_MANA);
} }
return; return;
} }
@ -1579,7 +1578,7 @@ void Aura::TriggerSpell()
case 25371: case 25371:
{ {
int32 bpDamage = target->GetMaxHealth()*10/100; int32 bpDamage = target->GetMaxHealth()*10/100;
caster->CastCustomSpell(target, 25373, &bpDamage, NULL, NULL, true, NULL, this); target->CastCustomSpell(target, 25373, &bpDamage, NULL, NULL, true, NULL, this, casterGUID);
return; return;
} }
// // Pain Spike // // Pain Spike
@ -1606,7 +1605,7 @@ void Aura::TriggerSpell()
case 27808: case 27808:
{ {
int32 bpDamage = target->GetMaxHealth()*26/100; int32 bpDamage = target->GetMaxHealth()*26/100;
caster->CastCustomSpell(target, 29879, &bpDamage, NULL, NULL, true, NULL, this); target->CastCustomSpell(target, 29879, &bpDamage, NULL, NULL, true, NULL, this, casterGUID);
return; return;
} }
// // Detonate Mana // // Detonate Mana
@ -1657,10 +1656,13 @@ void Aura::TriggerSpell()
// Extract Gas // Extract Gas
case 30427: case 30427:
{ {
Unit* caster = GetCaster();
if (!caster)
return;
// move loot to player inventory and despawn target // move loot to player inventory and despawn target
if(caster->GetTypeId() ==TYPEID_PLAYER && if(caster->GetTypeId() ==TYPEID_PLAYER &&
target->GetTypeId() == TYPEID_UNIT && target->GetTypeId() == TYPEID_UNIT &&
((Creature*)target)->GetCreatureInfo()->type == CREATURE_TYPE_GAS_CLOUD) ((Creature*)target)->GetCreatureInfo()->type == CREATURE_TYPE_GAS_CLOUD)
{ {
Player* player = (Player*)caster; Player* player = (Player*)caster;
Creature* creature = (Creature*)target; Creature* creature = (Creature*)target;
@ -1700,7 +1702,7 @@ void Aura::TriggerSpell()
case 31373: case 31373:
{ {
// Summon Elemental after create item // Summon Elemental after create item
caster->SummonCreature(17870, 0, 0, 0, caster->GetOrientation(), TEMPSUMMON_DEAD_DESPAWN, 0); target->SummonCreature(17870, 0, 0, 0, target->GetOrientation(), TEMPSUMMON_DEAD_DESPAWN, 0);
return; return;
} }
// // Bloodmyst Tesla // // Bloodmyst Tesla
@ -1722,9 +1724,9 @@ void Aura::TriggerSpell()
{ {
// cast 24 spells 34269-34289, 34314-34316 // cast 24 spells 34269-34289, 34314-34316
for(uint32 spell_id = 34269; spell_id != 34290; ++spell_id) for(uint32 spell_id = 34269; spell_id != 34290; ++spell_id)
caster->CastSpell(m_target, spell_id, true); target->CastSpell(target, spell_id, true, NULL, this, casterGUID);
for(uint32 spell_id = 34314; spell_id != 34317; ++spell_id) for(uint32 spell_id = 34314; spell_id != 34317; ++spell_id)
caster->CastSpell(m_target, spell_id, true); target->CastSpell(target, spell_id, true, NULL, this, casterGUID);
return; return;
} }
// // Gravity Lapse // // Gravity Lapse
@ -1815,7 +1817,10 @@ void Aura::TriggerSpell()
if(m_target->GetTypeId() != TYPEID_UNIT) if(m_target->GetTypeId() != TYPEID_UNIT)
return; return;
caster->CastSpell(caster, 38495, true); if (Unit* caster = GetCaster())
caster->CastSpell(caster, 38495, true, NULL, this);
else
return;
Creature* creatureTarget = (Creature*)m_target; Creature* creatureTarget = (Creature*)m_target;
@ -2073,7 +2078,7 @@ void Aura::TriggerSpell()
bool all = true; bool all = true;
for(int i = 0; i < MAX_TOTEM; ++i) for(int i = 0; i < MAX_TOTEM; ++i)
{ {
if(!caster->m_TotemSlot[i]) if(!target->m_TotemSlot[i])
{ {
all = false; all = false;
break; break;
@ -2081,9 +2086,9 @@ void Aura::TriggerSpell()
} }
if(all) if(all)
caster->CastSpell(caster, 38437, true); target->CastSpell(target, 38437, true, NULL, this);
else else
caster->RemoveAurasDueToSpell(38437); target->RemoveAurasDueToSpell(38437);
return; return;
} }
default: default:
@ -2113,14 +2118,14 @@ void Aura::TriggerSpell()
// 2) maybe aura must be replace by new with accumulative stat mods instead stacking // 2) maybe aura must be replace by new with accumulative stat mods instead stacking
// prevent cast by triggered auras // prevent cast by triggered auras
if(m_caster_guid == m_target->GetGUID()) if(casterGUID == target->GetGUID())
return; return;
// stop triggering after each affected stats lost > 90 // stop triggering after each affected stats lost > 90
int32 intelectLoss = 0; int32 intelectLoss = 0;
int32 spiritLoss = 0; int32 spiritLoss = 0;
Unit::AuraList const& mModStat = m_target->GetAurasByType(SPELL_AURA_MOD_STAT); Unit::AuraList const& mModStat = target->GetAurasByType(SPELL_AURA_MOD_STAT);
for(Unit::AuraList::const_iterator i = mModStat.begin(); i != mModStat.end(); ++i) for(Unit::AuraList::const_iterator i = mModStat.begin(); i != mModStat.end(); ++i)
{ {
if ((*i)->GetId() == 1010) if ((*i)->GetId() == 1010)
@ -2137,47 +2142,52 @@ void Aura::TriggerSpell()
if(intelectLoss <= -90 && spiritLoss <= -90) if(intelectLoss <= -90 && spiritLoss <= -90)
return; return;
caster = target;
break; break;
} }
// Mana Tide // Mana Tide
case 16191: case 16191:
{ {
caster->CastCustomSpell(target, trigger_spell_id, &m_modifier.m_amount, NULL, NULL, true, NULL, this); target->CastCustomSpell(target, trigger_spell_id, &m_modifier.m_amount, NULL, NULL, true, NULL, this);
return; return;
} }
// Ground Slam // Ground Slam
case 33525: case 33525:
target->CastSpell(target, trigger_spell_id, true); target->CastSpell(target, trigger_spell_id, true, NULL, this, casterGUID);
return; return;
// Beacon of Light // Beacon of Light
case 53563: case 53563:
// original caster must be target (beacon) // original caster must be target (beacon)
m_target->CastSpell(m_target,trigger_spell_id,true,NULL,this,m_target->GetGUID()); target->CastSpell(target, trigger_spell_id, true, NULL, this, target->GetGUID());
return; return;
} }
} }
// All ok cast by default case // All ok cast by default case
if(triggeredSpellInfo) if(triggeredSpellInfo)
caster->CastSpell(target, triggeredSpellInfo, true, 0, this); target->CastSpell(target, triggeredSpellInfo, true, NULL, this, casterGUID);
else if(target->GetTypeId()!=TYPEID_UNIT || !Script->EffectDummyCreature(caster, GetId(), GetEffIndex(), (Creature*)target)) else
sLog.outError("Aura::TriggerSpell: Spell %u have 0 in EffectTriggered[%d], not handled custom case?",GetId(),GetEffIndex()); {
if (Unit* caster = GetCaster())
{
if(target->GetTypeId() != TYPEID_UNIT || !Script->EffectDummyCreature(caster, GetId(), GetEffIndex(), (Creature*)target))
sLog.outError("Aura::TriggerSpell: Spell %u have 0 in EffectTriggered[%d], not handled custom case?",GetId(),GetEffIndex());
}
}
} }
void Aura::TriggerSpellWithValue() void Aura::TriggerSpellWithValue()
{ {
Unit* caster = GetCaster(); const uint64& casterGUID = GetCasterGUID();
Unit* target = GetTriggerTarget(); Unit* target = GetTriggerTarget();
if(!caster || !target) if(!casterGUID || !target)
return; return;
// generic casting code with custom spells and target/caster customs // generic casting code with custom spells and target/caster customs
uint32 trigger_spell_id = GetSpellProto()->EffectTriggerSpell[m_effIndex]; uint32 trigger_spell_id = GetSpellProto()->EffectTriggerSpell[m_effIndex];
int32 basepoints0 = this->GetModifier()->m_amount; int32 basepoints0 = this->GetModifier()->m_amount;
caster->CastCustomSpell(target, trigger_spell_id, &basepoints0, NULL, NULL, true, NULL, this); target->CastCustomSpell(target, trigger_spell_id, &basepoints0, NULL, NULL, true, NULL, this, casterGUID);
} }
/*********************************************************/ /*********************************************************/

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__ #ifndef __REVISION_NR_H__
#define __REVISION_NR_H__ #define __REVISION_NR_H__
#define REVISION_NR "8685" #define REVISION_NR "8686"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__