diff options
author | megamage <none@none> | 2009-08-24 22:31:54 -0500 |
---|---|---|
committer | megamage <none@none> | 2009-08-24 22:31:54 -0500 |
commit | 87270fefc235d45c2d9116b4a26f0dc32f1a5d7e (patch) | |
tree | dfe9897672fc1e33fa8ee1b5fa4f9c299afa2aec /src/game | |
parent | a8f394f8510797e60e93a22ed409d860579ad76b (diff) |
*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
Diffstat (limited to 'src/game')
-rw-r--r-- | src/game/Creature.cpp | 2 | ||||
-rw-r--r-- | src/game/GridNotifiersImpl.h | 2 | ||||
-rw-r--r-- | src/game/Level3.cpp | 4 | ||||
-rw-r--r-- | src/game/Pet.cpp | 2 | ||||
-rw-r--r-- | src/game/Player.cpp | 2 | ||||
-rw-r--r-- | src/game/Spell.cpp | 13 | ||||
-rw-r--r-- | src/game/SpellAuras.cpp | 153 | ||||
-rw-r--r-- | src/game/SpellAuras.h | 33 | ||||
-rw-r--r-- | src/game/Unit.cpp | 32 | ||||
-rw-r--r-- | src/game/Unit.h | 2 |
10 files changed, 113 insertions, 132 deletions
diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp index 9aa6eb78c74..a1cb9e5649f 100644 --- a/src/game/Creature.cpp +++ b/src/game/Creature.cpp @@ -2275,7 +2275,7 @@ bool Creature::LoadCreaturesAddon(bool reload) 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()); } } diff --git a/src/game/GridNotifiersImpl.h b/src/game/GridNotifiersImpl.h index f2970805eab..7deeb2ec5fd 100644 --- a/src/game/GridNotifiersImpl.h +++ b/src/game/GridNotifiersImpl.h @@ -208,7 +208,7 @@ inline void Trinity::DynamicObjectUpdater::VisitHelper(Unit* target) if (target->IsImmunedToSpell(spellInfo) || target->IsImmunedToSpellEffect(spellInfo, eff_index)) return; // 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()); i_dynobject.AddAffected(target); diff --git a/src/game/Level3.cpp b/src/game/Level3.cpp index d51db1d5a7a..6826d2bb53b 100644 --- a/src/game/Level3.cpp +++ b/src/game/Level3.cpp @@ -4382,7 +4382,7 @@ bool ChatHandler::HandleAuraCommand(const char* args) 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); } @@ -7352,7 +7352,7 @@ bool ChatHandler::HandleFreezeCommand(const char *args) //m_session->GetPlayer()->CastSpell(player,spellID,false); 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); //save player diff --git a/src/game/Pet.cpp b/src/game/Pet.cpp index 3d7f56e5d9f..7ebd7531daf 100644 --- a/src/game/Pet.cpp +++ b/src/game/Pet.cpp @@ -1189,7 +1189,7 @@ void Pet::_LoadAuras(uint32 timediff) else 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]); if(!aura->CanBeSaved()) { diff --git a/src/game/Player.cpp b/src/game/Player.cpp index 326e04e27c2..c793ff927bd 100644 --- a/src/game/Player.cpp +++ b/src/game/Player.cpp @@ -15379,7 +15379,7 @@ void Player::_LoadAuras(QueryResult *result, uint32 timediff) else 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]); if(!aura->CanBeSaved()) { diff --git a/src/game/Spell.cpp b/src/game/Spell.cpp index 5d7e57d2c34..7d4099500d9 100644 --- a/src/game/Spell.cpp +++ b/src/game/Spell.cpp @@ -1362,22 +1362,23 @@ SpellMissInfo Spell::DoSpellHitOnUnit(Unit *unit, const uint32 effectMask, bool } } - Unit * caster = m_originalCaster ? m_originalCaster : m_caster; - Aura * Aur = new Aura(aurSpellInfo, aura_effmask, basePoints, unit, m_caster, caster, m_CastItem); + if(m_originalCaster) + { + Aura *Aur = new Aura(aurSpellInfo, aura_effmask, unit, m_caster, m_originalCaster, basePoints, m_CastItem); if (!Aur->IsAreaAura()) { // Now Reduce spell duration using data received at spell hit int32 duration = Aur->GetAuraMaxDuration(); 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); - 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 if (IsChanneledSpell(m_spellInfo)) - caster->ModSpellCastTime(aurSpellInfo, duration, this); + m_originalCaster->ModSpellCastTime(aurSpellInfo, duration, this); if(duration != Aur->GetAuraMaxDuration()) { @@ -1395,6 +1396,8 @@ SpellMissInfo Spell::DoSpellHitOnUnit(Unit *unit, const uint32 effectMask, bool // Set aura only when successfully applied if (unit->AddAura(Aur, false)) m_spellAura = Aur; + + } } for(uint32 effectNumber = 0; effectNumber < 3; ++effectNumber) diff --git a/src/game/SpellAuras.cpp b/src/game/SpellAuras.cpp index 54464b521f7..5f75ce3192a 100644 --- a/src/game/SpellAuras.cpp +++ b/src/game/SpellAuras.cpp @@ -351,19 +351,19 @@ pAuraHandler AuraHandler[TOTAL_AURAS]= }; #undef Aura -Aura::Aura(SpellEntry const* spellproto, uint32 effMask, int32 *currentBasePoints, Unit *target, WorldObject *source, Unit *caster, Item* castItem) : -m_caster_guid(0), m_castItemGuid(castItem?castItem->GetGUID():0), m_target(target), -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) +Aura::Aura(SpellEntry const* spellproto, uint32 effMask, Unit *target, WorldObject *source, Unit *caster, int32 *currentBasePoints, Item* castItem) : + m_spellProto(spellproto), + m_target(target), m_source(source), m_caster_guid(caster->GetGUID()), m_castItemGuid(castItem ? castItem->GetGUID() : 0), + 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(source); assert(spellproto && spellproto == sSpellStore.LookupEntry( spellproto->Id ) && "`info` must be pointer to sSpellStore element"); m_auraFlags = effMask; - m_spellProto = spellproto; - if(m_spellProto->manaPerSecond || m_spellProto->manaPerSecondPerLevel) 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_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); - m_maxduration = caster->CalcSpellDuration(m_spellProto); - } + //damage = caster->CalculateSpellDamage(m_spellProto,m_effIndex,m_currentBasePoints,target); + m_maxduration = caster->CalcSpellDuration(m_spellProto); if(m_maxduration == -1 || m_isPassive && m_spellProto->DurationIndex == 0) m_permanent = true; else m_permanent = false; - Player* modOwner = caster ? caster->GetSpellModOwner() : NULL; + Player* modOwner = caster->GetSpellModOwner(); 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) modOwner->ApplySpellMod(GetId(), SPELLMOD_CHARGES, m_procCharges); - m_isRemovedOnShapeLost = (m_caster_guid==m_target->GetGUID() && + m_isRemovedOnShapeLost = (caster == target && m_spellProto->Stances && !(m_spellProto->AttributesEx2 & SPELL_ATTR_EX2_NOT_NEED_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 (currentBasePoints) - m_partAuras[i] = CreateAuraEffect(this, i, currentBasePoints + i, caster, NULL, source); - 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)); + if(!(m_partAuras[i] = CreateAuraEffect(this, i, currentBasePoints ? currentBasePoints + i : NULL))) + m_auraFlags &= uint8(~(1<< i)); // correct flags if aura couldn't be created } 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 - // or when it is casted by enemy and at least one aura is negative - bool swap=false; - if (!caster || caster==target) // caster == target - 1 negative effect is enough for aura to be negative + // or when it is casted by enemy and at least one aura is negative + bool swap = false; + if (caster == target) // caster == target - 1 negative effect is enough for aura to be negative m_positive = false; else 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())) - continue; - if (m_positive == IsPositiveEffect(GetId(), i)) + if((1<<i & GetEffectMask()) && m_positive == IsPositiveEffect(GetId(), i)) { swap = true; break; } } if (!swap) - m_positive=!m_positive; + m_positive = !m_positive; } Aura::~Aura() @@ -462,7 +443,7 @@ Aura::~Aura() 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_target(parentAura->GetTarget()), m_tickNumber(0) , 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 m_currentBasePoints = m_spellProto->EffectBasePoints[m_effIndex]; + Unit *caster = GetParentAura()->GetCaster(); if(caster) m_amount = caster->CalculateSpellDamage(m_spellProto, m_effIndex, m_currentBasePoints, m_target); else @@ -482,7 +464,11 @@ m_target(parentAura->GetTarget()), m_tickNumber(0) if (int32 amount = CalculateCrowdControlAuraAmount(caster)) 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())); if(item_rand_suffix) @@ -507,7 +493,6 @@ m_target(parentAura->GetTarget()), m_tickNumber(0) } Player* modOwner = caster ? caster->GetSpellModOwner() : NULL; - m_sourceGUID = source ? source->GetGUID() : (caster ? caster->GetGUID() : 0); m_amplitude = m_spellProto->EffectAmplitude[m_effIndex]; //apply casting time mods for channeled spells @@ -525,20 +510,20 @@ m_target(parentAura->GetTarget()), m_tickNumber(0) m_isApplied = false; } -AreaAuraEffect::AreaAuraEffect(Aura * parentAura, uint32 effIndex, int32 * currentBasePoints, Unit * caster, Item * castItem, Unit * source) -: AuraEffect(parentAura, effIndex, currentBasePoints, caster, castItem, source) +AreaAuraEffect::AreaAuraEffect(Aura * parentAura, uint32 effIndex, int32 *currentBasePoints) +: AuraEffect(parentAura, effIndex, currentBasePoints) { m_removeTime = FRIENDLY_AA_REMOVE_TIME; m_isAreaAura = true; - Unit* caster_ptr = caster ? caster : source ? source : m_target; - if (m_spellProto->Effect[effIndex] == SPELL_EFFECT_APPLY_AREA_AURA_ENEMY) m_radius = GetSpellRadiusForHostile(sSpellRadiusStore.LookupEntry(GetSpellProto()->EffectRadiusIndex[m_effIndex])); else 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); switch(m_spellProto->Effect[effIndex]) @@ -558,7 +543,7 @@ AreaAuraEffect::AreaAuraEffect(Aura * parentAura, uint32 effIndex, int32 * curre break; case SPELL_EFFECT_APPLY_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 break; case SPELL_EFFECT_APPLY_AREA_AURA_PET: @@ -566,7 +551,7 @@ AreaAuraEffect::AreaAuraEffect(Aura * parentAura, uint32 effIndex, int32 * curre break; case SPELL_EFFECT_APPLY_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; break; 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) -: AuraEffect(parentAura, effIndex, currentBasePoints, caster, castItem, source) +PersistentAreaAuraEffect::PersistentAreaAuraEffect(Aura * parentAura, uint32 effIndex, int32 *currentBasePoints) +: AuraEffect(parentAura, effIndex, currentBasePoints) { 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 assert(parentAura); + WorldObject *source = parentAura->GetSource(); + assert(source); if (IsAreaAuraEffect(parentAura->GetSpellProto()->Effect[effIndex])) { - if(!source) - source = caster; - //TODO: determine source here - if(source && source->isType(TYPEMASK_UNIT)) - return new AreaAuraEffect(parentAura, effIndex, currentBasePoints, caster, castItem, (Unit*)source); + assert(source->isType(TYPEMASK_UNIT)); + return new AreaAuraEffect(parentAura, effIndex, currentBasePoints); } 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) - return new PersistentAreaAuraEffect(parentAura, effIndex, currentBasePoints, caster, castItem); + { + assert(source->isType(TYPEMASK_DYNAMICOBJECT)); + return new PersistentAreaAuraEffect(parentAura, effIndex, currentBasePoints); + } return NULL; } @@ -620,18 +603,6 @@ Unit* Aura::GetCaster() const 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) { // 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) { - // update for the caster of the aura - if(m_sourceGUID == m_target->GetGUID()) + Unit *source = GetSource(); + 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(); if (!caster) { @@ -797,7 +774,7 @@ void AreaAuraEffect::Update(uint32 diff) // Check if basepoints can be safely reduced if (newBp == m_spellProto->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) caster->CombatStart(*tIter); @@ -1497,8 +1474,8 @@ bool Aura::IsVisible() const { if(m_partAuras[i]->IsAreaAura()) { - if(WorldObject *source = m_partAuras[i]->GetSource()) - if(source->GetTypeId() == TYPEID_UNIT && ((Creature*)source)->isTotem()) + if(Unit *source = ((AreaAuraEffect*)m_partAuras[i])->GetSource()) + if(source->isTotem()) return true; 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) { - m_caster_guid = caster_guid; + *const_cast<uint64*>(&m_caster_guid) = caster_guid; m_maxduration = maxduration; m_duration = duration; m_procCharges = charges; m_stackAmount = stackamount; - for (uint8 i=0; i<MAX_SPELL_EFFECTS;++i) - if (m_partAuras[i]) + for(uint8 i = 0; i < MAX_SPELL_EFFECTS; ++i) + if(m_partAuras[i]) m_partAuras[i]->SetAmount(amount[i]); } @@ -6622,7 +6599,7 @@ void AuraEffect::HandleAuraControlVehicle(bool apply, bool Real, bool /*changeAm if(!m_target->IsVehicle()) return; - Unit *caster = GetSource(); + Unit *caster = dynamic_cast<Unit*>(GetParentAura()->GetSource()); if(!caster || caster == m_target) return; diff --git a/src/game/SpellAuras.h b/src/game/SpellAuras.h index 262795077c6..6701939f622 100644 --- a/src/game/SpellAuras.h +++ b/src/game/SpellAuras.h @@ -54,7 +54,7 @@ class TRINITY_DLL_SPEC Aura friend void Player::SendAurasForTarget(Unit *target); public: 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; } uint32 GetId() const{ return m_spellProto->Id; } @@ -63,6 +63,7 @@ class TRINITY_DLL_SPEC Aura uint64 const& GetCasterGUID() const { return m_caster_guid; } Unit* GetCaster() const; Unit* GetTarget() const { return m_target; } + WorldObject *GetSource() const { return m_source; } time_t GetAuraApplyTime() const { return m_applyTime; } int32 GetAuraMaxDuration() const { return m_maxduration; } @@ -133,11 +134,12 @@ class TRINITY_DLL_SPEC Aura void SetIsSingleTarget(bool val) { m_isSingleTargetAura = val;} private: - SpellEntry const *m_spellProto; + const SpellEntry * const m_spellProto; Unit * const m_target; - uint64 m_caster_guid; - uint64 m_castItemGuid; // it is NOT safe to keep a pointer to the item because it may get deleted - time_t m_applyTime; + WorldObject * const m_source; + const uint64 m_caster_guid; + 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_duration; // Current time @@ -169,7 +171,7 @@ class TRINITY_DLL_SPEC Aura class TRINITY_DLL_SPEC AuraEffect { 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); //aura handlers void HandleNULL(bool, bool, bool) @@ -338,7 +340,6 @@ class TRINITY_DLL_SPEC AuraEffect Unit * GetCaster() const { return m_parentAura->GetCaster(); } uint64 GetCasterGUID() const{ return m_parentAura->GetCasterGUID(); } - Unit* GetSource() const; // { return m_parentAura->GetSource(); } Aura * GetParentAura() const { return m_parentAura; } SpellEntry const* GetSpellProto() const { return m_spellProto; } @@ -378,10 +379,9 @@ class TRINITY_DLL_SPEC AuraEffect void CleanupTriggeredSpells(); 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; 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; @@ -405,10 +405,11 @@ class TRINITY_DLL_SPEC AuraEffect class TRINITY_DLL_SPEC AreaAuraEffect : public AuraEffect { public: - AreaAuraEffect(Aura * parentAura, uint32 effIndex, int32 * currentBasePoints, Unit * caster=NULL, Item * castItem=NULL, Unit * source = NULL); - ~AreaAuraEffect(); + friend AuraEffect* CreateAuraEffect(Aura * parentAura, uint32 effIndex, int32 *currentBasePoints); void Update(uint32 diff); - private: + Unit *GetSource() const; + protected: + explicit AreaAuraEffect(Aura * parentAura, uint32 effIndex, int32 *currentBasePoints = NULL); float m_radius; int32 m_removeTime; AreaAuraType m_areaAuraType; @@ -417,11 +418,13 @@ class TRINITY_DLL_SPEC AreaAuraEffect : public AuraEffect class TRINITY_DLL_SPEC PersistentAreaAuraEffect : public AuraEffect { public: - PersistentAreaAuraEffect(Aura * parentAura, uint32 eff, int32 *currentBasePoints, Unit *caster = NULL, Item* castItem = NULL, DynamicObject * source = NULL); - ~PersistentAreaAuraEffect(); + friend AuraEffect* CreateAuraEffect(Aura * parentAura, uint32 effIndex, int32 *currentBasePoints); 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 diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index 7ad3dc983dd..12aa858e861 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -4023,7 +4023,7 @@ void Unit::RemoveAurasDueToSpellBySteal(uint32 spellId, uint64 casterGUID, Unit damage[i]=NULL; } 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]); // Unregister _before_ adding to stealer @@ -6214,7 +6214,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger // Light's Beacon - Beacon of Light 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 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); for(Unit::AuraEffectList::const_iterator itr = magnetAuras.begin(); itr != magnetAuras.end(); ++itr) - if(Unit* magnet = (*itr)->IsAreaAura() ? ((AreaAuraEffect*)(*itr))->GetSource():(*itr)->GetCaster() ) - if(magnet->isAlive()) - { - return magnet; - } + if(Unit* magnet = dynamic_cast<Unit*>((*itr)->GetParentAura()->GetSource())) + if(magnet->isAlive()) + return magnet; } // Melee && ranged case else { AuraEffectList const& hitTriggerAuras = victim->GetAurasByType(SPELL_AURA_ADD_CASTER_HIT_TRIGGER); 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(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()) return; @@ -14533,8 +14531,8 @@ void Unit::AddAura(uint32 spellId, Unit* target) if (!eff_mask) return; - //TODO: we use target as source for now, but that may not be true - Aura *Aur = new Aura(spellInfo, eff_mask, NULL, target, target, this, NULL); + // Because source is not give, use caster as source + Aura *Aur = new Aura(spellInfo, eff_mask, target, this, this); target->AddAura(Aur); } @@ -14550,7 +14548,7 @@ void Unit::SetAuraStack(uint32 spellId, Unit *target, uint32 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 //assert (!IsPassiveSpell(spellInfo)); @@ -14561,9 +14559,9 @@ Aura * Unit::AddAuraEffect(const SpellEntry * spellInfo, uint8 effIndex, Unit* c if (aur) { - AuraEffect *aurEffect = CreateAuraEffect(aur, effIndex, basePoints, caster,NULL, source); - if (aurEffect && !aur->SetPartAura(aurEffect, effIndex)) - delete aurEffect; + if(AuraEffect *aurEffect = CreateAuraEffect(aur, effIndex, basePoints)) + if(!aur->SetPartAura(aurEffect, effIndex)) + delete aurEffect; } else { @@ -14571,10 +14569,10 @@ Aura * Unit::AddAuraEffect(const SpellEntry * spellInfo, uint8 effIndex, Unit* c { int32 amount[MAX_SPELL_EFFECTS]; 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 - 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)) return NULL; diff --git a/src/game/Unit.h b/src/game/Unit.h index cf38b1527e7..17979c94e0b 100644 --- a/src/game/Unit.h +++ b/src/game/Unit.h @@ -1363,7 +1363,7 @@ class TRINITY_DLL_SPEC Unit : public WorldObject void AddAura(uint32 spellId, Unit *target); void SetAuraStack(uint32 spellId, Unit *target, uint32 stack); 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; |