*Some update of aura system. Remove unnecessary variables and parameters from auraeffect. Always refer to parent aura when finding target/source/caster.

--HG--
branch : trunk
This commit is contained in:
megamage
2009-08-24 22:31:54 -05:00
parent a8f394f851
commit 87270fefc2
16 changed files with 120 additions and 139 deletions
@@ -421,7 +421,7 @@ struct TRINITY_DLL_DECL boss_veknilashAI : public boss_twinemperorsAI
continue; continue;
eff_mask|=1<<i; eff_mask|=1<<i;
} }
target->AddAura(new Aura(spell, eff_mask, NULL, target, target)); target->AddAura(new Aura(spell, eff_mask, target, target, target));
target->SetHealth(target->GetMaxHealth()); target->SetHealth(target->GetMaxHealth());
} }
@@ -506,7 +506,7 @@ struct TRINITY_DLL_DECL boss_veklorAI : public boss_twinemperorsAI
continue; continue;
eff_mask|=1<<i; eff_mask|=1<<i;
} }
target->AddAura(new Aura(spell, eff_mask, NULL, target, target)); target->AddAura(new Aura(spell, eff_mask, target, target, target));
target->SetHealth(target->GetMaxHealth()); target->SetHealth(target->GetMaxHealth());
} }
@@ -94,7 +94,7 @@ struct TRINITY_DLL_DECL mob_voidtravelerAI : public ScriptedAI
{ {
SpellEntry *spell = GET_SPELL(HeroicMode?H_SPELL_EMPOWERING_SHADOWS:SPELL_EMPOWERING_SHADOWS); SpellEntry *spell = GET_SPELL(HeroicMode?H_SPELL_EMPOWERING_SHADOWS:SPELL_EMPOWERING_SHADOWS);
if (spell) if (spell)
Vorpil->AddAura(new Aura(spell, 1, NULL, Vorpil, m_creature)); Vorpil->AddAura(new Aura(spell, 1, Vorpil, me, me));
Vorpil->SetHealth(Vorpil->GetHealth()+Vorpil->GetMaxHealth()/25); Vorpil->SetHealth(Vorpil->GetHealth()+Vorpil->GetMaxHealth()/25);
DoCast(m_creature, SPELL_SHADOW_NOVA, true); DoCast(m_creature, SPELL_SHADOW_NOVA, true);
m_creature->DealDamage(m_creature, m_creature->GetMaxHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false); m_creature->DealDamage(m_creature, m_creature->GetMaxHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
@@ -168,7 +168,7 @@ struct TRINITY_DLL_DECL boss_gurtogg_bloodboilAI : public ScriptedAI
if (eff>=TOTAL_SPELL_EFFECTS) if (eff>=TOTAL_SPELL_EFFECTS)
continue; continue;
Aura *Aur = new Aura(spellInfo, i, NULL, target); Aura *Aur = new Aura(spellInfo, i, target, target, target);
target->AddAura(Aur); target->AddAura(Aur);
} }
} }
@@ -666,7 +666,7 @@ struct TRINITY_DLL_DECL mob_enchanted_elementalAI : public ScriptedAI
continue; continue;
eff_mask|=1<<i; eff_mask|=1<<i;
} }
Vashj->AddAura(new Aura(spell, eff_mask, NULL, Vashj, Vashj)); Vashj->AddAura(new Aura(spell, eff_mask, Vashj, Vashj, Vashj));
} }
m_creature->DealDamage(m_creature, m_creature->GetMaxHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false); m_creature->DealDamage(m_creature, m_creature->GetMaxHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
} }
@@ -515,7 +515,7 @@ struct TRINITY_DLL_DECL boss_leotheras_the_blindAI : public ScriptedAI
continue; continue;
eff_mask|=1<<i; eff_mask|=1<<i;
} }
(*itr)->AddAura(new Aura(spell, eff_mask, NULL, (*itr), (*itr))); (*itr)->AddAura(new Aura(spell, eff_mask, *itr, *itr, *itr));
if (InnderDemon_Count > 4) InnderDemon_Count = 0; if (InnderDemon_Count > 4) InnderDemon_Count = 0;
//Safe storing of creatures //Safe storing of creatures
@@ -248,7 +248,7 @@ struct TRINITY_DLL_DECL boss_kelidan_the_breakerAI : public ScriptedAI
continue; continue;
eff_mask|=1<<i; eff_mask|=1<<i;
} }
m_creature->AddAura(new Aura(nova, eff_mask, NULL, m_creature, m_creature)); m_creature->AddAura(new Aura(nova, eff_mask, me, me, me));
} }
if (HeroicMode) if (HeroicMode)
+1 -1
View File
@@ -2275,7 +2275,7 @@ bool Creature::LoadCreaturesAddon(bool reload)
continue; continue;
} }
AddAuraEffect(AdditionalSpellInfo, cAura->effect_idx, this); AddAuraEffect(AdditionalSpellInfo, cAura->effect_idx, this, this);
sLog.outDebug("Spell: %u with Aura %u added to creature (GUIDLow: %u Entry: %u )", cAura->spell_id, AdditionalSpellInfo->EffectApplyAuraName[cAura->effect_idx],GetGUIDLow(),GetEntry()); sLog.outDebug("Spell: %u with Aura %u added to creature (GUIDLow: %u Entry: %u )", cAura->spell_id, AdditionalSpellInfo->EffectApplyAuraName[cAura->effect_idx],GetGUIDLow(),GetEntry());
} }
} }
+1 -1
View File
@@ -208,7 +208,7 @@ inline void Trinity::DynamicObjectUpdater::VisitHelper(Unit* target)
if (target->IsImmunedToSpell(spellInfo) || target->IsImmunedToSpellEffect(spellInfo, eff_index)) if (target->IsImmunedToSpell(spellInfo) || target->IsImmunedToSpellEffect(spellInfo, eff_index))
return; return;
// Apply PersistentAreaAura on target // Apply PersistentAreaAura on target
if(Aura *aur = target->AddAuraEffect(spellInfo, eff_index, i_dynobject.GetCaster())) if(Aura *aur = target->AddAuraEffect(spellInfo, eff_index, &i_dynobject, i_dynobject.GetCaster()))
aur->SetAuraDuration(i_dynobject.GetDuration()); aur->SetAuraDuration(i_dynobject.GetDuration());
i_dynobject.AddAffected(target); i_dynobject.AddAffected(target);
+2 -2
View File
@@ -4382,7 +4382,7 @@ bool ChatHandler::HandleAuraCommand(const char* args)
eff_mask|=1<<i; eff_mask|=1<<i;
} }
} }
Aura *Aur = new Aura(spellInfo, eff_mask, NULL, target); Aura *Aur = new Aura(spellInfo, eff_mask, target, target, target);
target->AddAura(Aur); target->AddAura(Aur);
} }
@@ -7352,7 +7352,7 @@ bool ChatHandler::HandleFreezeCommand(const char *args)
//m_session->GetPlayer()->CastSpell(player,spellID,false); //m_session->GetPlayer()->CastSpell(player,spellID,false);
SpellEntry const *spellInfo = sSpellStore.LookupEntry( 9454 ); SpellEntry const *spellInfo = sSpellStore.LookupEntry( 9454 );
Aura *Aur = new Aura(spellInfo, 1, NULL, player); Aura *Aur = new Aura(spellInfo, 1, player, player, player);
player->AddAura(Aur); player->AddAura(Aur);
//save player //save player
+1 -1
View File
@@ -1189,7 +1189,7 @@ void Pet::_LoadAuras(uint32 timediff)
else else
remaincharges = 0; remaincharges = 0;
Aura* aura = new Aura(spellproto, effmask, NULL, this, NULL, NULL); Aura* aura = new Aura(spellproto, effmask, this, this, this);
aura->SetLoadedState(caster_guid,maxduration,remaintime,remaincharges, stackcount, &damage[0]); aura->SetLoadedState(caster_guid,maxduration,remaintime,remaincharges, stackcount, &damage[0]);
if(!aura->CanBeSaved()) if(!aura->CanBeSaved())
{ {
+1 -1
View File
@@ -15379,7 +15379,7 @@ void Player::_LoadAuras(QueryResult *result, uint32 timediff)
else else
remaincharges = 0; remaincharges = 0;
Aura* aura = new Aura(spellproto, effmask, NULL, this, NULL, NULL); Aura* aura = new Aura(spellproto, effmask, this, this, this);
aura->SetLoadedState(caster_guid,maxduration,remaintime,remaincharges, stackcount, &damage[0]); aura->SetLoadedState(caster_guid,maxduration,remaintime,remaincharges, stackcount, &damage[0]);
if(!aura->CanBeSaved()) if(!aura->CanBeSaved())
{ {
+8 -5
View File
@@ -1362,22 +1362,23 @@ SpellMissInfo Spell::DoSpellHitOnUnit(Unit *unit, const uint32 effectMask, bool
} }
} }
Unit * caster = m_originalCaster ? m_originalCaster : m_caster; if(m_originalCaster)
Aura * Aur = new Aura(aurSpellInfo, aura_effmask, basePoints, unit, m_caster, caster, m_CastItem); {
Aura *Aur = new Aura(aurSpellInfo, aura_effmask, unit, m_caster, m_originalCaster, basePoints, m_CastItem);
if (!Aur->IsAreaAura()) if (!Aur->IsAreaAura())
{ {
// Now Reduce spell duration using data received at spell hit // Now Reduce spell duration using data received at spell hit
int32 duration = Aur->GetAuraMaxDuration(); int32 duration = Aur->GetAuraMaxDuration();
int32 limitduration = GetDiminishingReturnsLimitDuration(m_diminishGroup,aurSpellInfo); int32 limitduration = GetDiminishingReturnsLimitDuration(m_diminishGroup,aurSpellInfo);
unitTarget->ApplyDiminishingToDuration(m_diminishGroup, duration, caster, m_diminishLevel,limitduration); unitTarget->ApplyDiminishingToDuration(m_diminishGroup, duration, m_originalCaster, m_diminishLevel,limitduration);
Aur->setDiminishGroup(m_diminishGroup); Aur->setDiminishGroup(m_diminishGroup);
duration = caster->ModSpellDuration(aurSpellInfo, unit, duration, Aur->IsPositive()); duration = m_originalCaster->ModSpellDuration(aurSpellInfo, unit, duration, Aur->IsPositive());
//mod duration of channeled aura by spell haste //mod duration of channeled aura by spell haste
if (IsChanneledSpell(m_spellInfo)) if (IsChanneledSpell(m_spellInfo))
caster->ModSpellCastTime(aurSpellInfo, duration, this); m_originalCaster->ModSpellCastTime(aurSpellInfo, duration, this);
if(duration != Aur->GetAuraMaxDuration()) if(duration != Aur->GetAuraMaxDuration())
{ {
@@ -1395,6 +1396,8 @@ SpellMissInfo Spell::DoSpellHitOnUnit(Unit *unit, const uint32 effectMask, bool
// Set aura only when successfully applied // Set aura only when successfully applied
if (unit->AddAura(Aur, false)) if (unit->AddAura(Aur, false))
m_spellAura = Aur; m_spellAura = Aur;
}
} }
for(uint32 effectNumber = 0; effectNumber < 3; ++effectNumber) for(uint32 effectNumber = 0; effectNumber < 3; ++effectNumber)
+62 -85
View File
@@ -351,19 +351,19 @@ pAuraHandler AuraHandler[TOTAL_AURAS]=
}; };
#undef Aura #undef Aura
Aura::Aura(SpellEntry const* spellproto, uint32 effMask, int32 *currentBasePoints, Unit *target, WorldObject *source, Unit *caster, Item* castItem) : Aura::Aura(SpellEntry const* spellproto, uint32 effMask, Unit *target, WorldObject *source, Unit *caster, int32 *currentBasePoints, Item* castItem) :
m_caster_guid(0), m_castItemGuid(castItem?castItem->GetGUID():0), m_target(target), m_spellProto(spellproto),
m_timeCla(0), m_removeMode(AURA_REMOVE_BY_DEFAULT), m_AuraDRGroup(DIMINISHING_NONE), m_target(target), m_source(source), m_caster_guid(caster->GetGUID()), m_castItemGuid(castItem ? castItem->GetGUID() : 0),
m_auraSlot(MAX_AURAS), m_auraLevel(1), m_procCharges(0), m_stackAmount(1), m_isRemoved(false) m_applyTime(time(NULL)),
m_timeCla(0), m_removeMode(AURA_REMOVE_BY_DEFAULT), m_AuraDRGroup(DIMINISHING_NONE),
m_auraSlot(MAX_AURAS), m_auraLevel(1), m_procCharges(0), m_stackAmount(1), m_isRemoved(false)
{ {
assert(target); assert(target);
assert(source);
assert(spellproto && spellproto == sSpellStore.LookupEntry( spellproto->Id ) && "`info` must be pointer to sSpellStore element"); assert(spellproto && spellproto == sSpellStore.LookupEntry( spellproto->Id ) && "`info` must be pointer to sSpellStore element");
m_auraFlags = effMask; m_auraFlags = effMask;
m_spellProto = spellproto;
if(m_spellProto->manaPerSecond || m_spellProto->manaPerSecondPerLevel) if(m_spellProto->manaPerSecond || m_spellProto->manaPerSecondPerLevel)
m_timeCla = 1000; m_timeCla = 1000;
@@ -371,28 +371,15 @@ m_auraSlot(MAX_AURAS), m_auraLevel(1), m_procCharges(0), m_stackAmount(1), m_isR
m_isSingleTargetAura = IsSingleTargetSpell(m_spellProto); m_isSingleTargetAura = IsSingleTargetSpell(m_spellProto);
m_applyTime = time(NULL);
if(!caster)
{
m_caster_guid = target->GetGUID();
//damage = m_currentBasePoints+1; // stored value-1
m_maxduration = target->CalcSpellDuration(m_spellProto);
}
else
{
m_caster_guid = caster->GetGUID();
//damage = caster->CalculateSpellDamage(m_spellProto,m_effIndex,m_currentBasePoints,target); //damage = caster->CalculateSpellDamage(m_spellProto,m_effIndex,m_currentBasePoints,target);
m_maxduration = caster->CalcSpellDuration(m_spellProto); m_maxduration = caster->CalcSpellDuration(m_spellProto);
}
if(m_maxduration == -1 || m_isPassive && m_spellProto->DurationIndex == 0) if(m_maxduration == -1 || m_isPassive && m_spellProto->DurationIndex == 0)
m_permanent = true; m_permanent = true;
else else
m_permanent = false; m_permanent = false;
Player* modOwner = caster ? caster->GetSpellModOwner() : NULL; Player* modOwner = caster->GetSpellModOwner();
if(!m_permanent && modOwner) if(!m_permanent && modOwner)
{ {
@@ -410,7 +397,7 @@ m_auraSlot(MAX_AURAS), m_auraLevel(1), m_procCharges(0), m_stackAmount(1), m_isR
if(modOwner) if(modOwner)
modOwner->ApplySpellMod(GetId(), SPELLMOD_CHARGES, m_procCharges); modOwner->ApplySpellMod(GetId(), SPELLMOD_CHARGES, m_procCharges);
m_isRemovedOnShapeLost = (m_caster_guid==m_target->GetGUID() && m_isRemovedOnShapeLost = (caster == target &&
m_spellProto->Stances && m_spellProto->Stances &&
!(m_spellProto->AttributesEx2 & SPELL_ATTR_EX2_NOT_NEED_SHAPESHIFT) && !(m_spellProto->AttributesEx2 & SPELL_ATTR_EX2_NOT_NEED_SHAPESHIFT) &&
!(m_spellProto->Attributes & SPELL_ATTR_NOT_SHAPESHIFT)); !(m_spellProto->Attributes & SPELL_ATTR_NOT_SHAPESHIFT));
@@ -419,39 +406,33 @@ m_auraSlot(MAX_AURAS), m_auraLevel(1), m_procCharges(0), m_stackAmount(1), m_isR
{ {
if (m_auraFlags & (uint8(1) << i)) if (m_auraFlags & (uint8(1) << i))
{ {
if (currentBasePoints) if(!(m_partAuras[i] = CreateAuraEffect(this, i, currentBasePoints ? currentBasePoints + i : NULL)))
m_partAuras[i] = CreateAuraEffect(this, i, currentBasePoints + i, caster, NULL, source); m_auraFlags &= uint8(~(1<< i)); // correct flags if aura couldn't be created
else
m_partAuras[i] = CreateAuraEffect(this, i, NULL, caster, NULL, source);
// correct flags if aura couldn't be created
if (!m_partAuras[i])
m_auraFlags &= uint8(~(1<< i));
} }
else else
{ {
m_partAuras[i]=NULL; m_partAuras[i] = NULL;
} }
} }
// Aura is positive when it is casted by friend and at least one aura is positive // Aura is positive when it is casted by friend and at least one aura is positive
// or when it is casted by enemy and at least one aura is negative // or when it is casted by enemy and at least one aura is negative
bool swap=false; bool swap = false;
if (!caster || caster==target) // caster == target - 1 negative effect is enough for aura to be negative if (caster == target) // caster == target - 1 negative effect is enough for aura to be negative
m_positive = false; m_positive = false;
else else
m_positive = !caster->IsHostileTo(m_target); m_positive = !caster->IsHostileTo(m_target);
for (uint8 i=0;i<MAX_SPELL_EFFECTS;++i)
for(uint8 i = 0; i < MAX_SPELL_EFFECTS; ++i)
{ {
if (!(1<<i & GetEffectMask())) if((1<<i & GetEffectMask()) && m_positive == IsPositiveEffect(GetId(), i))
continue;
if (m_positive == IsPositiveEffect(GetId(), i))
{ {
swap = true; swap = true;
break; break;
} }
} }
if (!swap) if (!swap)
m_positive=!m_positive; m_positive = !m_positive;
} }
Aura::~Aura() Aura::~Aura()
@@ -462,7 +443,7 @@ Aura::~Aura()
delete m_partAuras[i]; delete m_partAuras[i];
} }
AuraEffect::AuraEffect(Aura * parentAura, uint8 effIndex, int32 * currentBasePoints , Unit *caster, Item* castItem, WorldObject *source) : AuraEffect::AuraEffect(Aura *parentAura, uint8 effIndex, int32 *currentBasePoints) :
m_parentAura(parentAura), m_spellmod(NULL), m_periodicTimer(0), m_isPeriodic(false), m_isAreaAura(false), m_isPersistent(false), m_parentAura(parentAura), m_spellmod(NULL), m_periodicTimer(0), m_isPeriodic(false), m_isAreaAura(false), m_isPersistent(false),
m_target(parentAura->GetTarget()), m_tickNumber(0) m_target(parentAura->GetTarget()), m_tickNumber(0)
, m_spellProto(parentAura->GetSpellProto()), m_effIndex(effIndex), m_auraName(AuraType(m_spellProto->EffectApplyAuraName[m_effIndex])) , m_spellProto(parentAura->GetSpellProto()), m_effIndex(effIndex), m_auraName(AuraType(m_spellProto->EffectApplyAuraName[m_effIndex]))
@@ -474,6 +455,7 @@ m_target(parentAura->GetTarget()), m_tickNumber(0)
else else
m_currentBasePoints = m_spellProto->EffectBasePoints[m_effIndex]; m_currentBasePoints = m_spellProto->EffectBasePoints[m_effIndex];
Unit *caster = GetParentAura()->GetCaster();
if(caster) if(caster)
m_amount = caster->CalculateSpellDamage(m_spellProto, m_effIndex, m_currentBasePoints, m_target); m_amount = caster->CalculateSpellDamage(m_spellProto, m_effIndex, m_currentBasePoints, m_target);
else else
@@ -482,7 +464,11 @@ m_target(parentAura->GetTarget()), m_tickNumber(0)
if (int32 amount = CalculateCrowdControlAuraAmount(caster)) if (int32 amount = CalculateCrowdControlAuraAmount(caster))
m_amount = amount; m_amount = amount;
if (!m_amount && castItem && castItem->GetItemSuffixFactor()) if(!m_amount && caster)
if(uint64 itemGUID = GetParentAura()->GetCastItemGUID())
if(Player *playerCaster = dynamic_cast<Player*>(caster))
if(Item *castItem = playerCaster->GetItemByGuid(itemGUID))
if (castItem->GetItemSuffixFactor())
{ {
ItemRandomSuffixEntry const *item_rand_suffix = sItemRandomSuffixStore.LookupEntry(abs(castItem->GetItemRandomPropertyId())); ItemRandomSuffixEntry const *item_rand_suffix = sItemRandomSuffixStore.LookupEntry(abs(castItem->GetItemRandomPropertyId()));
if(item_rand_suffix) if(item_rand_suffix)
@@ -507,7 +493,6 @@ m_target(parentAura->GetTarget()), m_tickNumber(0)
} }
Player* modOwner = caster ? caster->GetSpellModOwner() : NULL; Player* modOwner = caster ? caster->GetSpellModOwner() : NULL;
m_sourceGUID = source ? source->GetGUID() : (caster ? caster->GetGUID() : 0);
m_amplitude = m_spellProto->EffectAmplitude[m_effIndex]; m_amplitude = m_spellProto->EffectAmplitude[m_effIndex];
//apply casting time mods for channeled spells //apply casting time mods for channeled spells
@@ -525,20 +510,20 @@ m_target(parentAura->GetTarget()), m_tickNumber(0)
m_isApplied = false; m_isApplied = false;
} }
AreaAuraEffect::AreaAuraEffect(Aura * parentAura, uint32 effIndex, int32 * currentBasePoints, Unit * caster, Item * castItem, Unit * source) AreaAuraEffect::AreaAuraEffect(Aura * parentAura, uint32 effIndex, int32 *currentBasePoints)
: AuraEffect(parentAura, effIndex, currentBasePoints, caster, castItem, source) : AuraEffect(parentAura, effIndex, currentBasePoints)
{ {
m_removeTime = FRIENDLY_AA_REMOVE_TIME; m_removeTime = FRIENDLY_AA_REMOVE_TIME;
m_isAreaAura = true; m_isAreaAura = true;
Unit* caster_ptr = caster ? caster : source ? source : m_target;
if (m_spellProto->Effect[effIndex] == SPELL_EFFECT_APPLY_AREA_AURA_ENEMY) if (m_spellProto->Effect[effIndex] == SPELL_EFFECT_APPLY_AREA_AURA_ENEMY)
m_radius = GetSpellRadiusForHostile(sSpellRadiusStore.LookupEntry(GetSpellProto()->EffectRadiusIndex[m_effIndex])); m_radius = GetSpellRadiusForHostile(sSpellRadiusStore.LookupEntry(GetSpellProto()->EffectRadiusIndex[m_effIndex]));
else else
m_radius = GetSpellRadiusForFriend(sSpellRadiusStore.LookupEntry(GetSpellProto()->EffectRadiusIndex[m_effIndex])); m_radius = GetSpellRadiusForFriend(sSpellRadiusStore.LookupEntry(GetSpellProto()->EffectRadiusIndex[m_effIndex]));
if(Player* modOwner = caster_ptr->GetSpellModOwner()) Unit *source = GetSource();
assert(source);
if(Player* modOwner = source->GetSpellModOwner()) // source or caster? should be the same
modOwner->ApplySpellMod(GetId(), SPELLMOD_RADIUS, m_radius); modOwner->ApplySpellMod(GetId(), SPELLMOD_RADIUS, m_radius);
switch(m_spellProto->Effect[effIndex]) switch(m_spellProto->Effect[effIndex])
@@ -558,7 +543,7 @@ AreaAuraEffect::AreaAuraEffect(Aura * parentAura, uint32 effIndex, int32 * curre
break; break;
case SPELL_EFFECT_APPLY_AREA_AURA_ENEMY: case SPELL_EFFECT_APPLY_AREA_AURA_ENEMY:
m_areaAuraType = AREA_AURA_ENEMY; m_areaAuraType = AREA_AURA_ENEMY;
if(m_target == caster_ptr) if(m_target == source)
*const_cast<AuraType*>(&m_auraName) = SPELL_AURA_NONE; // Do not do any effect on self *const_cast<AuraType*>(&m_auraName) = SPELL_AURA_NONE; // Do not do any effect on self
break; break;
case SPELL_EFFECT_APPLY_AREA_AURA_PET: case SPELL_EFFECT_APPLY_AREA_AURA_PET:
@@ -566,7 +551,7 @@ AreaAuraEffect::AreaAuraEffect(Aura * parentAura, uint32 effIndex, int32 * curre
break; break;
case SPELL_EFFECT_APPLY_AREA_AURA_OWNER: case SPELL_EFFECT_APPLY_AREA_AURA_OWNER:
m_areaAuraType = AREA_AURA_OWNER; m_areaAuraType = AREA_AURA_OWNER;
if(m_target == caster_ptr) if(m_target == source)
*const_cast<AuraType*>(&m_auraName) = SPELL_AURA_NONE; *const_cast<AuraType*>(&m_auraName) = SPELL_AURA_NONE;
break; break;
default: default:
@@ -576,36 +561,34 @@ AreaAuraEffect::AreaAuraEffect(Aura * parentAura, uint32 effIndex, int32 * curre
} }
} }
AreaAuraEffect::~AreaAuraEffect() Unit *AreaAuraEffect::GetSource() const { return dynamic_cast<Unit*>(GetParentAura()->GetSource()); }
{
}
PersistentAreaAuraEffect::PersistentAreaAuraEffect(Aura * parentAura, uint32 effIndex, int32 * currentBasePoints, Unit * caster,Item * castItem, DynamicObject *source) PersistentAreaAuraEffect::PersistentAreaAuraEffect(Aura * parentAura, uint32 effIndex, int32 *currentBasePoints)
: AuraEffect(parentAura, effIndex, currentBasePoints, caster, castItem, source) : AuraEffect(parentAura, effIndex, currentBasePoints)
{ {
m_isPersistent = true; m_isPersistent = true;
} }
PersistentAreaAuraEffect::~PersistentAreaAuraEffect() DynamicObject *PersistentAreaAuraEffect::GetSource() const { return dynamic_cast<DynamicObject*>(GetParentAura()->GetSource()); }
{
}
AuraEffect* CreateAuraEffect(Aura * parentAura, uint32 effIndex, int32 *currentBasePoints, Unit * caster, Item * castItem, WorldObject* source) AuraEffect* CreateAuraEffect(Aura * parentAura, uint32 effIndex, int32 *currentBasePoints)
{ {
// TODO: source should belong to aura, but not areaeffect. multiple areaaura/persistent aura should use one source // TODO: source should belong to aura, but not areaeffect. multiple areaaura/persistent aura should use one source
assert(parentAura); assert(parentAura);
WorldObject *source = parentAura->GetSource();
assert(source);
if (IsAreaAuraEffect(parentAura->GetSpellProto()->Effect[effIndex])) if (IsAreaAuraEffect(parentAura->GetSpellProto()->Effect[effIndex]))
{ {
if(!source) assert(source->isType(TYPEMASK_UNIT));
source = caster; return new AreaAuraEffect(parentAura, effIndex, currentBasePoints);
//TODO: determine source here
if(source && source->isType(TYPEMASK_UNIT))
return new AreaAuraEffect(parentAura, effIndex, currentBasePoints, caster, castItem, (Unit*)source);
} }
else if (parentAura->GetSpellProto()->Effect[effIndex] == SPELL_EFFECT_APPLY_AURA) else if (parentAura->GetSpellProto()->Effect[effIndex] == SPELL_EFFECT_APPLY_AURA)
return new AuraEffect(parentAura, effIndex, currentBasePoints, caster, castItem, source); return new AuraEffect(parentAura, effIndex, currentBasePoints);
else if (parentAura->GetSpellProto()->Effect[effIndex] == SPELL_EFFECT_PERSISTENT_AREA_AURA) else if (parentAura->GetSpellProto()->Effect[effIndex] == SPELL_EFFECT_PERSISTENT_AREA_AURA)
return new PersistentAreaAuraEffect(parentAura, effIndex, currentBasePoints, caster, castItem); {
assert(source->isType(TYPEMASK_DYNAMICOBJECT));
return new PersistentAreaAuraEffect(parentAura, effIndex, currentBasePoints);
}
return NULL; return NULL;
} }
@@ -620,18 +603,6 @@ Unit* Aura::GetCaster() const
return unit && unit->IsInWorld() ? unit : NULL; return unit && unit->IsInWorld() ? unit : NULL;
} }
Unit* AuraEffect::GetSource() const
{
if(m_sourceGUID == m_target->GetGUID())
return m_target;
//return ObjectAccessor::GetUnit(*m_target,m_caster_guid);
//must return caster even if it's in another grid/map
Unit *unit = ObjectAccessor::GetObjectInWorld(m_sourceGUID, (Unit*)NULL);
//only player can be not in world while in objectaccessor
return unit && unit->IsInWorld() ? unit : NULL;
}
void Aura::Update(uint32 diff) void Aura::Update(uint32 diff)
{ {
// TODO: store pointer to caster in aura class for update/mod handling code // TODO: store pointer to caster in aura class for update/mod handling code
@@ -721,10 +692,16 @@ void AuraEffect::Update(uint32 diff)
void AreaAuraEffect::Update(uint32 diff) void AreaAuraEffect::Update(uint32 diff)
{ {
// update for the caster of the aura Unit *source = GetSource();
if(m_sourceGUID == m_target->GetGUID()) if(!source) // this should never happen
{
m_target->RemoveAura(GetParentAura());
return;
}
// update for the source of the aura
if(source == m_target)
{ {
Unit *source = m_target;
Unit *caster = GetCaster(); Unit *caster = GetCaster();
if (!caster) if (!caster)
{ {
@@ -797,7 +774,7 @@ void AreaAuraEffect::Update(uint32 diff)
// Check if basepoints can be safely reduced // Check if basepoints can be safely reduced
if (newBp == m_spellProto->EffectBasePoints[m_effIndex]) if (newBp == m_spellProto->EffectBasePoints[m_effIndex])
newBp = actualSpellInfo->EffectBasePoints[m_effIndex]; newBp = actualSpellInfo->EffectBasePoints[m_effIndex];
(*tIter)->AddAuraEffect(actualSpellInfo, GetEffIndex(), caster, &newBp, source); (*tIter)->AddAuraEffect(actualSpellInfo, GetEffIndex(), source, caster, &newBp);
if(m_areaAuraType == AREA_AURA_ENEMY) if(m_areaAuraType == AREA_AURA_ENEMY)
caster->CombatStart(*tIter); caster->CombatStart(*tIter);
@@ -1497,8 +1474,8 @@ bool Aura::IsVisible() const
{ {
if(m_partAuras[i]->IsAreaAura()) if(m_partAuras[i]->IsAreaAura())
{ {
if(WorldObject *source = m_partAuras[i]->GetSource()) if(Unit *source = ((AreaAuraEffect*)m_partAuras[i])->GetSource())
if(source->GetTypeId() == TYPEID_UNIT && ((Creature*)source)->isTotem()) if(source->isTotem())
return true; return true;
if(m_partAuras[i]->GetAuraName() != SPELL_AURA_NONE) if(m_partAuras[i]->GetAuraName() != SPELL_AURA_NONE)
@@ -1842,13 +1819,13 @@ bool Aura::IsAuraType(AuraType type) const
void Aura::SetLoadedState(uint64 caster_guid,int32 maxduration,int32 duration,int32 charges, uint8 stackamount, int32 * amount) void Aura::SetLoadedState(uint64 caster_guid,int32 maxduration,int32 duration,int32 charges, uint8 stackamount, int32 * amount)
{ {
m_caster_guid = caster_guid; *const_cast<uint64*>(&m_caster_guid) = caster_guid;
m_maxduration = maxduration; m_maxduration = maxduration;
m_duration = duration; m_duration = duration;
m_procCharges = charges; m_procCharges = charges;
m_stackAmount = stackamount; m_stackAmount = stackamount;
for (uint8 i=0; i<MAX_SPELL_EFFECTS;++i) for(uint8 i = 0; i < MAX_SPELL_EFFECTS; ++i)
if (m_partAuras[i]) if(m_partAuras[i])
m_partAuras[i]->SetAmount(amount[i]); m_partAuras[i]->SetAmount(amount[i]);
} }
@@ -6622,7 +6599,7 @@ void AuraEffect::HandleAuraControlVehicle(bool apply, bool Real, bool /*changeAm
if(!m_target->IsVehicle()) if(!m_target->IsVehicle())
return; return;
Unit *caster = GetSource(); Unit *caster = dynamic_cast<Unit*>(GetParentAura()->GetSource());
if(!caster || caster == m_target) if(!caster || caster == m_target)
return; return;
+18 -15
View File
@@ -54,7 +54,7 @@ class TRINITY_DLL_SPEC Aura
friend void Player::SendAurasForTarget(Unit *target); friend void Player::SendAurasForTarget(Unit *target);
public: public:
virtual ~Aura(); virtual ~Aura();
explicit Aura(SpellEntry const* spellproto, uint32 effMask, int32 *currentBasePoints, Unit *target, WorldObject *source = NULL, Unit *caster = NULL, Item *castItem = NULL); explicit Aura(SpellEntry const* spellproto, uint32 effMask, Unit *target, WorldObject *source, Unit *caster, int32 *currentBasePoints = NULL, Item *castItem = NULL);
SpellEntry const* GetSpellProto() const { return m_spellProto; } SpellEntry const* GetSpellProto() const { return m_spellProto; }
uint32 GetId() const{ return m_spellProto->Id; } uint32 GetId() const{ return m_spellProto->Id; }
@@ -63,6 +63,7 @@ class TRINITY_DLL_SPEC Aura
uint64 const& GetCasterGUID() const { return m_caster_guid; } uint64 const& GetCasterGUID() const { return m_caster_guid; }
Unit* GetCaster() const; Unit* GetCaster() const;
Unit* GetTarget() const { return m_target; } Unit* GetTarget() const { return m_target; }
WorldObject *GetSource() const { return m_source; }
time_t GetAuraApplyTime() const { return m_applyTime; } time_t GetAuraApplyTime() const { return m_applyTime; }
int32 GetAuraMaxDuration() const { return m_maxduration; } int32 GetAuraMaxDuration() const { return m_maxduration; }
@@ -133,11 +134,12 @@ class TRINITY_DLL_SPEC Aura
void SetIsSingleTarget(bool val) { m_isSingleTargetAura = val;} void SetIsSingleTarget(bool val) { m_isSingleTargetAura = val;}
private: private:
SpellEntry const *m_spellProto; const SpellEntry * const m_spellProto;
Unit * const m_target; Unit * const m_target;
uint64 m_caster_guid; WorldObject * const m_source;
uint64 m_castItemGuid; // it is NOT safe to keep a pointer to the item because it may get deleted const uint64 m_caster_guid;
time_t m_applyTime; const uint64 m_castItemGuid; // it is NOT safe to keep a pointer to the item because it may get deleted
const time_t m_applyTime;
int32 m_maxduration; // Max aura duration int32 m_maxduration; // Max aura duration
int32 m_duration; // Current time int32 m_duration; // Current time
@@ -169,7 +171,7 @@ class TRINITY_DLL_SPEC Aura
class TRINITY_DLL_SPEC AuraEffect class TRINITY_DLL_SPEC AuraEffect
{ {
public: public:
friend AuraEffect* CreateAuraEffect(Aura * parentAura, uint32 effIndex, int32 *currentBasePoints, Unit * caster, Item * castItem, WorldObject *source); friend AuraEffect* CreateAuraEffect(Aura * parentAura, uint32 effIndex, int32 *currentBasePoints);
friend void Aura::SetStackAmount(uint8 stackAmount, bool applied); friend void Aura::SetStackAmount(uint8 stackAmount, bool applied);
//aura handlers //aura handlers
void HandleNULL(bool, bool, bool) void HandleNULL(bool, bool, bool)
@@ -338,7 +340,6 @@ class TRINITY_DLL_SPEC AuraEffect
Unit * GetCaster() const { return m_parentAura->GetCaster(); } Unit * GetCaster() const { return m_parentAura->GetCaster(); }
uint64 GetCasterGUID() const{ return m_parentAura->GetCasterGUID(); } uint64 GetCasterGUID() const{ return m_parentAura->GetCasterGUID(); }
Unit* GetSource() const; // { return m_parentAura->GetSource(); }
Aura * GetParentAura() const { return m_parentAura; } Aura * GetParentAura() const { return m_parentAura; }
SpellEntry const* GetSpellProto() const { return m_spellProto; } SpellEntry const* GetSpellProto() const { return m_spellProto; }
@@ -378,10 +379,9 @@ class TRINITY_DLL_SPEC AuraEffect
void CleanupTriggeredSpells(); void CleanupTriggeredSpells();
protected: protected:
explicit AuraEffect(Aura * parentAura, uint8 effIndex, int32 *currentBasePoints , Unit *caster, Item *castItem, WorldObject *source); explicit AuraEffect(Aura * parentAura, uint8 effIndex, int32 *currentBasePoints = NULL);
Aura * const m_parentAura; Aura * const m_parentAura;
Unit * const m_target; Unit * const m_target;
uint64 m_sourceGUID; // Spell::m_caster/trap? for normal aura, totem/paladin for areaaura, dynobj for persistent aura
uint32 m_tickNumber; uint32 m_tickNumber;
@@ -405,10 +405,11 @@ class TRINITY_DLL_SPEC AuraEffect
class TRINITY_DLL_SPEC AreaAuraEffect : public AuraEffect class TRINITY_DLL_SPEC AreaAuraEffect : public AuraEffect
{ {
public: public:
AreaAuraEffect(Aura * parentAura, uint32 effIndex, int32 * currentBasePoints, Unit * caster=NULL, Item * castItem=NULL, Unit * source = NULL); friend AuraEffect* CreateAuraEffect(Aura * parentAura, uint32 effIndex, int32 *currentBasePoints);
~AreaAuraEffect();
void Update(uint32 diff); void Update(uint32 diff);
private: Unit *GetSource() const;
protected:
explicit AreaAuraEffect(Aura * parentAura, uint32 effIndex, int32 *currentBasePoints = NULL);
float m_radius; float m_radius;
int32 m_removeTime; int32 m_removeTime;
AreaAuraType m_areaAuraType; AreaAuraType m_areaAuraType;
@@ -417,11 +418,13 @@ class TRINITY_DLL_SPEC AreaAuraEffect : public AuraEffect
class TRINITY_DLL_SPEC PersistentAreaAuraEffect : public AuraEffect class TRINITY_DLL_SPEC PersistentAreaAuraEffect : public AuraEffect
{ {
public: public:
PersistentAreaAuraEffect(Aura * parentAura, uint32 eff, int32 *currentBasePoints, Unit *caster = NULL, Item* castItem = NULL, DynamicObject * source = NULL); friend AuraEffect* CreateAuraEffect(Aura * parentAura, uint32 effIndex, int32 *currentBasePoints);
~PersistentAreaAuraEffect();
void Update(uint32 diff); void Update(uint32 diff);
DynamicObject *GetSource() const;
protected:
explicit PersistentAreaAuraEffect(Aura * parentAura, uint32 eff, int32 *currentBasePoints = NULL);
}; };
AuraEffect* CreateAuraEffect(Aura * parentAura, uint32 effIndex, int32 *currentBasePoints, Unit *caster, Item *castItem = NULL, WorldObject *source = NULL); AuraEffect* CreateAuraEffect(Aura * parentAura, uint32 effIndex, int32 *currentBasePoints = NULL);
#endif #endif
+12 -14
View File
@@ -4023,7 +4023,7 @@ void Unit::RemoveAurasDueToSpellBySteal(uint32 spellId, uint64 casterGUID, Unit
damage[i]=NULL; damage[i]=NULL;
} }
int32 dur = 2*MINUTE*IN_MILISECONDS < aur->GetAuraDuration() ? 2*MINUTE*IN_MILISECONDS : aur->GetAuraDuration(); int32 dur = 2*MINUTE*IN_MILISECONDS < aur->GetAuraDuration() ? 2*MINUTE*IN_MILISECONDS : aur->GetAuraDuration();
Aura * new_aur = new Aura(aur->GetSpellProto(),aur->GetEffectMask(), NULL, stealer, stealer, NULL); Aura * new_aur = new Aura(aur->GetSpellProto(),aur->GetEffectMask(), stealer, stealer, stealer);
new_aur->SetLoadedState(aur->GetCasterGUID(), dur, dur, aur->GetAuraCharges(), aur->GetStackAmount(), &damage[0]); new_aur->SetLoadedState(aur->GetCasterGUID(), dur, dur, aur->GetAuraCharges(), aur->GetStackAmount(), &damage[0]);
// Unregister _before_ adding to stealer // Unregister _before_ adding to stealer
@@ -6214,7 +6214,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger
// Light's Beacon - Beacon of Light // Light's Beacon - Beacon of Light
if ( dummySpell->Id == 53651 ) if ( dummySpell->Id == 53651 )
{ {
if (Unit * source = triggeredByAura->GetSource()) if (Unit *source = dynamic_cast<Unit*>(triggeredByAura->GetParentAura()->GetSource()))
{ {
// do not proc when target of beacon of light is healed // do not proc when target of beacon of light is healed
if (source == this) if (source == this)
@@ -8877,18 +8877,16 @@ Unit* Unit::SelectMagnetTarget(Unit *victim, SpellEntry const *spellInfo)
Unit::AuraEffectList const& magnetAuras = victim->GetAurasByType(SPELL_AURA_SPELL_MAGNET); Unit::AuraEffectList const& magnetAuras = victim->GetAurasByType(SPELL_AURA_SPELL_MAGNET);
for(Unit::AuraEffectList::const_iterator itr = magnetAuras.begin(); itr != magnetAuras.end(); ++itr) for(Unit::AuraEffectList::const_iterator itr = magnetAuras.begin(); itr != magnetAuras.end(); ++itr)
if(Unit* magnet = (*itr)->IsAreaAura() ? ((AreaAuraEffect*)(*itr))->GetSource():(*itr)->GetCaster() ) if(Unit* magnet = dynamic_cast<Unit*>((*itr)->GetParentAura()->GetSource()))
if(magnet->isAlive()) if(magnet->isAlive())
{
return magnet; return magnet;
} }
}
// Melee && ranged case // Melee && ranged case
else else
{ {
AuraEffectList const& hitTriggerAuras = victim->GetAurasByType(SPELL_AURA_ADD_CASTER_HIT_TRIGGER); AuraEffectList const& hitTriggerAuras = victim->GetAurasByType(SPELL_AURA_ADD_CASTER_HIT_TRIGGER);
for(AuraEffectList::const_iterator i = hitTriggerAuras.begin(); i != hitTriggerAuras.end(); ++i) for(AuraEffectList::const_iterator i = hitTriggerAuras.begin(); i != hitTriggerAuras.end(); ++i)
if(Unit* magnet = (*i)->IsAreaAura() ? ((AreaAuraEffect*)(*i))->GetSource():(*i)->GetCaster() ) if(Unit* magnet = dynamic_cast<Unit*>((*i)->GetParentAura()->GetSource()))
if(magnet->isAlive() && magnet->IsWithinLOSInMap(this)) if(magnet->isAlive() && magnet->IsWithinLOSInMap(this))
if(roll_chance_i((*i)->GetAmount())) if(roll_chance_i((*i)->GetAmount()))
{ {
@@ -14506,7 +14504,7 @@ void Unit::HandleAuraEffect(AuraEffect * aureff, bool apply)
} }
} }
void Unit::AddAura(uint32 spellId, Unit* target) void Unit::AddAura(uint32 spellId, Unit *target)
{ {
if(!target || !target->isAlive()) if(!target || !target->isAlive())
return; return;
@@ -14533,8 +14531,8 @@ void Unit::AddAura(uint32 spellId, Unit* target)
if (!eff_mask) if (!eff_mask)
return; return;
//TODO: we use target as source for now, but that may not be true // Because source is not give, use caster as source
Aura *Aur = new Aura(spellInfo, eff_mask, NULL, target, target, this, NULL); Aura *Aur = new Aura(spellInfo, eff_mask, target, this, this);
target->AddAura(Aur); target->AddAura(Aur);
} }
@@ -14550,7 +14548,7 @@ void Unit::SetAuraStack(uint32 spellId, Unit *target, uint32 stack)
aur->SetStackAmount(stack); aur->SetStackAmount(stack);
} }
Aura * Unit::AddAuraEffect(const SpellEntry * spellInfo, uint8 effIndex, Unit* caster, int32 * basePoints, Unit * source) Aura * Unit::AddAuraEffect(const SpellEntry * spellInfo, uint8 effIndex, WorldObject *source, Unit* caster, int32 * basePoints)
{ {
// can't do that for passive auras - they stack from same caster so there is no way to get exact aura which should get effect // can't do that for passive auras - they stack from same caster so there is no way to get exact aura which should get effect
//assert (!IsPassiveSpell(spellInfo)); //assert (!IsPassiveSpell(spellInfo));
@@ -14561,8 +14559,8 @@ Aura * Unit::AddAuraEffect(const SpellEntry * spellInfo, uint8 effIndex, Unit* c
if (aur) if (aur)
{ {
AuraEffect *aurEffect = CreateAuraEffect(aur, effIndex, basePoints, caster,NULL, source); if(AuraEffect *aurEffect = CreateAuraEffect(aur, effIndex, basePoints))
if (aurEffect && !aur->SetPartAura(aurEffect, effIndex)) if(!aur->SetPartAura(aurEffect, effIndex))
delete aurEffect; delete aurEffect;
} }
else else
@@ -14571,10 +14569,10 @@ Aura * Unit::AddAuraEffect(const SpellEntry * spellInfo, uint8 effIndex, Unit* c
{ {
int32 amount[MAX_SPELL_EFFECTS]; int32 amount[MAX_SPELL_EFFECTS];
amount[effIndex] = *basePoints; amount[effIndex] = *basePoints;
aur = new Aura(spellInfo, 1<<effIndex, amount, this, source, caster, NULL); aur = new Aura(spellInfo, 1<<effIndex, this, source, caster, amount, NULL);
} }
else else
aur = new Aura(spellInfo, 1<<effIndex, NULL, this, source ,caster, NULL); aur = new Aura(spellInfo, 1<<effIndex, this, source, caster, NULL, NULL);
if(!AddAura(aur)) if(!AddAura(aur))
return NULL; return NULL;
+1 -1
View File
@@ -1363,7 +1363,7 @@ class TRINITY_DLL_SPEC Unit : public WorldObject
void AddAura(uint32 spellId, Unit *target); void AddAura(uint32 spellId, Unit *target);
void SetAuraStack(uint32 spellId, Unit *target, uint32 stack); void SetAuraStack(uint32 spellId, Unit *target, uint32 stack);
void HandleAuraEffect(AuraEffect * aureff, bool apply); void HandleAuraEffect(AuraEffect * aureff, bool apply);
Aura *AddAuraEffect(const SpellEntry * spellInfo, uint8 effIndex, Unit* caster, int32 * basePoints=NULL, Unit * source=NULL); Aura *AddAuraEffect(const SpellEntry *spellInfo, uint8 effIndex, WorldObject *source, Unit *caster, int32 *basePoints = NULL);
bool IsDamageToThreatSpell(SpellEntry const * spellInfo) const; bool IsDamageToThreatSpell(SpellEntry const * spellInfo) const;