From 15de4282422f41d5f25d510bc7e97aff4b03902e Mon Sep 17 00:00:00 2001 From: VladimirMangos Date: Sun, 20 Dec 2009 19:23:54 +0300 Subject: [PATCH] [9037] Cleanups in spellmode apply code. * Add constructores for spellmode creating instead explcit fields init * Use uint32 for family mask 2 instead unneded uint64 Also drop one from manual applies for uno-existed now spell. --- src/game/DBCStructure.h | 4 ++ src/game/Player.cpp | 34 ++++++++++++-- src/game/Player.h | 13 +++++- src/game/Spell.cpp | 5 +- src/game/SpellAuras.cpp | 99 ++++++---------------------------------- src/game/SpellAuras.h | 2 +- src/game/SpellMgr.cpp | 19 -------- src/game/SpellMgr.h | 2 - src/game/Unit.cpp | 17 ++----- src/shared/revision_nr.h | 2 +- 10 files changed, 70 insertions(+), 127 deletions(-) diff --git a/src/game/DBCStructure.h b/src/game/DBCStructure.h index d5b294f21..45e353f4e 100644 --- a/src/game/DBCStructure.h +++ b/src/game/DBCStructure.h @@ -1426,6 +1426,10 @@ struct SpellEntry // helpers int32 CalculateSimpleValue(uint8 eff) const { return EffectBasePoints[eff]+int32(EffectBaseDice[eff]); } + uint32 const* GetEffectSpellClassMask(uint8 effect) const + { + return EffectSpellClassMaskA + effect * 3; + } private: // prevent creating custom entries (copy data from original in fact) diff --git a/src/game/Player.cpp b/src/game/Player.cpp index 2d09f4f3b..968299f28 100644 --- a/src/game/Player.cpp +++ b/src/game/Player.cpp @@ -274,6 +274,33 @@ std::ostringstream& operator<< (std::ostringstream& ss, PlayerTaxi const& taxi) return ss; } +SpellModifier::SpellModifier( SpellModOp _op, SpellModType _type, int32 _value, SpellEntry const* spellEntry, uint8 eff, int16 _charges /*= 0*/ ) : op(_op), type(_type), charges(_charges), value(_value), spellId(spellEntry->Id), lastAffected(NULL) +{ + uint32 const* ptr = spellEntry->GetEffectSpellClassMask(eff); + mask = uint64(ptr[0]) | (uint64(ptr[1]) << 32); + mask2= ptr[2]; +} + +SpellModifier::SpellModifier( SpellModOp _op, SpellModType _type, int32 _value, Aura const* aura, int16 _charges /*= 0*/ ) : op(_op), type(_type), charges(_charges), value(_value), spellId(aura->GetId()), lastAffected(NULL) +{ + uint32 const* ptr = aura->getAuraSpellClassMask(); + mask = uint64(ptr[0]) | (uint64(ptr[1]) << 32); + mask2= ptr[2]; +} + +bool SpellModifier::isAffectedOnSpell( SpellEntry const *spell ) const +{ + SpellEntry const *affect_spell = sSpellStore.LookupEntry(spellId); + // False if affect_spell == NULL or spellFamily not equal + if (!affect_spell || affect_spell->SpellFamilyName != spell->SpellFamilyName) + return false; + if (mask & spell->SpellFamilyFlags) + return true; + if (mask2 & spell->SpellFamilyFlags2) + return true; + return false; +} + //== Player ==================================================== UpdateMask Player::updateVisualBits; @@ -17173,7 +17200,7 @@ bool Player::IsAffectedBySpellmod(SpellEntry const *spellInfo, SpellModifier *mo return false; } - return sSpellMgr.IsAffectedByMod(spellInfo, mod); + return mod->isAffectedOnSpell(spellInfo); } void Player::AddSpellMod(SpellModifier* mod, bool apply) @@ -17183,9 +17210,9 @@ void Player::AddSpellMod(SpellModifier* mod, bool apply) for(int eff=0;eff<96;++eff) { uint64 _mask = 0; - uint64 _mask2= 0; + uint32 _mask2= 0; if (eff<64) _mask = uint64(1) << (eff- 0); - else _mask2= uint64(1) << (eff-64); + else _mask2= uint32(1) << (eff-64); if ( mod->mask & _mask || mod->mask2 & _mask2) { int32 val = 0; @@ -21288,3 +21315,4 @@ void Player::SetHomebindToCurrentPos() CharacterDatabase.PExecute("UPDATE character_homebind SET map = '%u', zone = '%u', position_x = '%f', position_y = '%f', position_z = '%f' WHERE guid = '%u'", m_homebindMapId, m_homebindZoneId, m_homebindX, m_homebindY, m_homebindZ, GetGUIDLow()); } + diff --git a/src/game/Player.h b/src/game/Player.h index 75e8e3163..97412964d 100644 --- a/src/game/Player.h +++ b/src/game/Player.h @@ -97,12 +97,23 @@ struct PlayerSpell struct SpellModifier { SpellModifier() : charges(0), lastAffected(NULL) {} + + SpellModifier(SpellModOp _op, SpellModType _type, int32 _value, uint32 _spellId, uint64 _mask, uint32 _mask2 = 0, int16 _charges = 0) + : op(_op), type(_type), charges(_charges), value(_value), mask(_mask), mask2(_mask2), spellId(_spellId), lastAffected(NULL) + {} + + SpellModifier(SpellModOp _op, SpellModType _type, int32 _value, SpellEntry const* spellEntry, uint8 eff, int16 _charges = 0); + + SpellModifier(SpellModOp _op, SpellModType _type, int32 _value, Aura const* aura, int16 _charges = 0); + + bool isAffectedOnSpell(SpellEntry const *spell) const; + SpellModOp op : 8; SpellModType type : 8; int16 charges : 16; int32 value; uint64 mask; - uint64 mask2; + uint32 mask2; uint32 spellId; Spell const* lastAffected; }; diff --git a/src/game/Spell.cpp b/src/game/Spell.cpp index ce6814fc7..9f141df99 100644 --- a/src/game/Spell.cpp +++ b/src/game/Spell.cpp @@ -5772,7 +5772,10 @@ void Spell::UpdatePointers() bool Spell::IsAffectedByAura(Aura *aura) const { - return sSpellMgr.IsAffectedByMod(m_spellInfo, aura->getAuraSpellMod()); + if(SpellModifier* mod = aura->getAuraSpellMod()) + return mod->isAffectedOnSpell(m_spellInfo); + else + return false; } bool Spell::CheckTargetCreatureType(Unit* target) const diff --git a/src/game/SpellAuras.cpp b/src/game/SpellAuras.cpp index 337340650..77ade4ca6 100644 --- a/src/game/SpellAuras.cpp +++ b/src/game/SpellAuras.cpp @@ -1395,30 +1395,14 @@ void Aura::HandleAddModifier(bool apply, bool Real) break; } - SpellModifier *mod = new SpellModifier; - mod->op = SpellModOp(m_modifier.m_miscvalue); - mod->value = m_modifier.m_amount; - mod->type = SpellModType(m_modifier.m_auraname); // SpellModType value == spell aura types - mod->spellId = GetId(); - - uint32 const *ptr; - switch (m_effIndex) - { - case 0: ptr = &m_spellProto->EffectSpellClassMaskA[0]; break; - case 1: ptr = &m_spellProto->EffectSpellClassMaskB[0]; break; - case 2: ptr = &m_spellProto->EffectSpellClassMaskC[0]; break; - default: - return; - } - - mod->mask = (uint64)ptr[0] | (uint64)ptr[1]<<32; - mod->mask2= (uint64)ptr[2]; - - // prevent expire spell mods with (charges > 0 && m_stackAmount > 1) - // all this spell expected expire not at use but at spell proc event check - mod->charges = m_spellProto->StackAmount > 1 ? 0 : m_procCharges; - - m_spellmod = mod; + m_spellmod = new SpellModifier( + SpellModOp(m_modifier.m_miscvalue), + SpellModType(m_modifier.m_auraname), // SpellModType value == spell aura types + m_modifier.m_amount, + this, + // prevent expire spell mods with (charges > 0 && m_stackAmount > 1) + // all this spell expected expire not at use but at spell proc event check + m_spellProto->StackAmount > 1 ? 0 : m_procCharges); } ((Player*)m_target)->AddSpellMod(m_spellmod, apply); @@ -1454,18 +1438,10 @@ void Aura::HandleAddTargetTrigger(bool apply, bool /*Real*/) SpellModifier *mod = new SpellModifier; mod->spellId = GetId(); - uint32 const *ptr; - switch (m_effIndex) - { - case 0: ptr = &m_spellProto->EffectSpellClassMaskA[0]; break; - case 1: ptr = &m_spellProto->EffectSpellClassMaskB[0]; break; - case 2: ptr = &m_spellProto->EffectSpellClassMaskC[0]; break; - default: - return; - } + uint32 const *ptr = m_spellProto->GetEffectSpellClassMask(m_effIndex); mod->mask = (uint64)ptr[0] | (uint64)ptr[1]<<32; - mod->mask2= (uint64)ptr[2]; + mod->mask2= ptr[2]; m_spellmod = mod; } else @@ -2611,14 +2587,8 @@ void Aura::HandleAuraDummy(bool apply, bool Real) if(apply) { // Reduce backfire damage (dot damage) from Shadow Word: Death - SpellModifier *mod = new SpellModifier; - mod->op = SPELLMOD_DOT; - mod->value = m_modifier.m_amount; - mod->type = SPELLMOD_PCT; - mod->spellId = GetId(); - mod->mask = UI64LIT(0x0000200000000000); - mod->mask2= UI64LIT(0x0); - m_spellmod = mod; + // aura have wrong effectclassmask, so use hardcoded value + m_spellmod = new SpellModifier(SPELLMOD_DOT,SPELLMOD_PCT,m_modifier.m_amount,GetId(),0x0000200000000000); } ((Player*)m_target)->AddSpellMod(m_spellmod, apply); return; @@ -2636,17 +2606,8 @@ void Aura::HandleAuraDummy(bool apply, bool Real) return; if(apply) - { - SpellModifier *mod = new SpellModifier; - mod->op = SPELLMOD_DOT; - mod->value = m_modifier.m_amount/7; - mod->type = SPELLMOD_FLAT; - mod->spellId = GetId(); - mod->mask = UI64LIT(0x001000000000); - mod->mask2= UI64LIT(0x0); - - m_spellmod = mod; - } + // dummy not have proper effectclassmask + m_spellmod = new SpellModifier(SPELLMOD_DOT,SPELLMOD_FLAT,m_modifier.m_amount/7,GetId(),UI64LIT(0x001000000000)); ((Player*)m_target)->AddSpellMod(m_spellmod, apply); return; @@ -2770,39 +2731,7 @@ void Aura::HandleAuraDummy(bool apply, bool Real) } break; case SPELLFAMILY_SHAMAN: - { - // Improved Weapon Totems - if( GetSpellProto()->SpellIconID == 57 && m_target->GetTypeId()==TYPEID_PLAYER ) - { - if(apply) - { - SpellModifier *mod = new SpellModifier; - mod->op = SPELLMOD_EFFECT1; - mod->value = m_modifier.m_amount; - mod->type = SPELLMOD_PCT; - mod->spellId = GetId(); - switch (m_effIndex) - { - case 0: - // Windfury Totem - mod->mask = UI64LIT(0x00200000000); - mod->mask2= UI64LIT(0x0); - break; - case 1: - // Flametongue Totem - mod->mask = UI64LIT(0x00400000000); - mod->mask2= UI64LIT(0x0); - break; - } - - m_spellmod = mod; - } - - ((Player*)m_target)->AddSpellMod(m_spellmod, apply); - return; - } break; - } } // pet auras diff --git a/src/game/SpellAuras.h b/src/game/SpellAuras.h index 489976a5d..bae2f36d9 100644 --- a/src/game/SpellAuras.h +++ b/src/game/SpellAuras.h @@ -339,7 +339,7 @@ class MANGOS_DLL_SPEC Aura void TriggerSpell(); void TriggerSpellWithValue(); - uint32 const *getAuraSpellClassMask() const { return m_spellProto->EffectSpellClassMaskA + m_effIndex * 3; } + uint32 const *getAuraSpellClassMask() const { return m_spellProto->GetEffectSpellClassMask(m_effIndex); } bool isAffectedOnSpell(SpellEntry const *spell) const; protected: Aura(SpellEntry const* spellproto, uint32 eff, int32 *currentBasePoints, Unit *target, Unit *caster = NULL, Item* castItem = NULL); diff --git a/src/game/SpellMgr.cpp b/src/game/SpellMgr.cpp index 2f6621ee7..e018eaf36 100644 --- a/src/game/SpellMgr.cpp +++ b/src/game/SpellMgr.cpp @@ -862,25 +862,6 @@ void SpellMgr::LoadSpellTargetPositions() sLog.outString( ">> Loaded %u spell teleport coordinates", count ); } -bool SpellMgr::IsAffectedByMod(SpellEntry const *spellInfo, SpellModifier *mod) const -{ - // false for spellInfo == NULL - if (!spellInfo || !mod) - return false; - - SpellEntry const *affect_spell = sSpellStore.LookupEntry(mod->spellId); - // False if affect_spell == NULL or spellFamily not equal - if (!affect_spell || affect_spell->SpellFamilyName != spellInfo->SpellFamilyName) - return false; - - // true - if (mod->mask & spellInfo->SpellFamilyFlags || - mod->mask2 & spellInfo->SpellFamilyFlags2) - return true; - - return false; -} - struct DoSpellProcEvent { DoSpellProcEvent(SpellProcEventEntry const& _spe) : spe(_spe) {} diff --git a/src/game/SpellMgr.h b/src/game/SpellMgr.h index 0583f62ba..8d8e3d8a4 100644 --- a/src/game/SpellMgr.h +++ b/src/game/SpellMgr.h @@ -732,8 +732,6 @@ class SpellMgr // Accessors (const or static functions) public: - bool IsAffectedByMod(SpellEntry const *spellInfo, SpellModifier *mod) const; - SpellElixirMap const& GetSpellElixirMap() const { return mSpellElixirs; } uint32 GetSpellElixirMask(uint32 spellid) const diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index 50c3ce29e..42d434dfa 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -6548,13 +6548,8 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, Aura* triggeredByAu } // No thread generated mod // TODO: exist special flag in spell attributes for this, need found and use! - SpellModifier *mod = new SpellModifier; - mod->op = SPELLMOD_THREAT; - mod->value = -100; - mod->type = SPELLMOD_PCT; - mod->spellId = dummySpell->Id; - mod->mask = UI64LIT(0x0000000000000003); - mod->mask2= UI64LIT(0x0); + SpellModifier *mod = new SpellModifier(SPELLMOD_THREAT,SPELLMOD_PCT,-100,triggeredByAura); + ((Player*)this)->AddSpellMod(mod, true); // Remove cooldown (Chain Lightning - have Category Recovery time) @@ -12809,13 +12804,7 @@ bool Unit::HandleMendingAuraProc( Aura* triggeredByAura ) if(Player* target = ((Player*)this)->GetNextRandomRaidMember(radius)) { // aura will applied from caster, but spell casted from current aura holder - SpellModifier *mod = new SpellModifier; - mod->op = SPELLMOD_CHARGES; - mod->value = jumps-5; // negative - mod->type = SPELLMOD_FLAT; - mod->spellId = spellProto->Id; - mod->mask = spellProto->SpellFamilyFlags; - mod->mask2 = spellProto->SpellFamilyFlags2; + SpellModifier *mod = new SpellModifier(SPELLMOD_CHARGES,SPELLMOD_FLAT,jumps-5,spellProto->Id,spellProto->SpellFamilyFlags,spellProto->SpellFamilyFlags2); // remove before apply next (locked against deleted) triggeredByAura->SetInUse(true); diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index f286a4c0c..d9eccda5b 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "9036" + #define REVISION_NR "9037" #endif // __REVISION_NR_H__