Show
Ignore:
Timestamp:
11/22/08 00:36:22 (17 years ago)
Author:
yumileroy
Message:

Merged commit 269 (5f0e38da128a).

Original author: gvcoman
Date: 2008-11-21 14:34:05-05:00

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/game/Unit.cpp

    r277 r279  
    11501150            if ( GetSpellSchoolMask(spellInfo) & SPELL_SCHOOL_MASK_NORMAL ) 
    11511151            { 
    1152                 uint32 modDamage=*damage; 
    1153  
    11541152                // apply spellmod to Done damage 
    11551153                if(Player* modOwner = GetSpellModOwner()) 
     
    14361434    if(!this || !pVictim) 
    14371435        return 0; 
    1438     if(!this->isAlive() || !pVictim->isAlive()) 
     1436    if(!isAlive() || !pVictim->isAlive()) 
    14391437        return 0; 
    14401438 
     
    37993797        { 
    38003798            m_ccAuras.push_back(Aur); 
    3801             RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_CC); 
    38023799        } 
    38033800    } 
     
    39153912        if(!is_triggered_by_spell) 
    39163913        { 
    3917             SpellSpecific i_spellId_spec = GetSpellSpecific(i_spellId); 
    3918  
    3919             bool is_sspc = IsSingleFromSpellSpecificPerCaster(spellId_spec,i_spellId_spec); 
    3920  
    3921             if( is_sspc && Aur->GetCasterGUID() == (*i).second->GetCasterGUID() ) 
    3922             { 
    3923                 // cannot remove higher rank 
    3924                 if (spellmgr.IsRankSpellDueToSpell(spellProto, i_spellId)) 
    3925                     if(CompareAuraRanks(spellId, effIndex, i_spellId, i_effIndex) < 0) 
    3926                         return false; 
     3914            bool sameCaster = Aur->GetCasterGUID() == (*i).second->GetCasterGUID(); 
     3915            if( spellmgr.IsNoStackSpellDueToSpell(spellId, i_spellId, sameCaster) ) 
     3916            { 
     3917                //some spells should be not removed by lower rank of them 
     3918                // what is this spell? 
     3919                if (!sameCaster 
     3920                    &&(spellProto->Effect[effIndex]==SPELL_EFFECT_APPLY_AREA_AURA_PARTY) 
     3921                    &&(spellProto->DurationIndex==21) 
     3922                    &&(spellmgr.IsRankSpellDueToSpell(spellProto, i_spellId)) 
     3923                    &&(CompareAuraRanks(spellId, effIndex, i_spellId, i_effIndex) < 0)) 
     3924                    return false; 
    39273925 
    39283926                // Its a parent aura (create this aura in ApplyModifier) 
     
    39383936                else 
    39393937                    next =  m_Auras.begin(); 
    3940             } 
    3941             else if( !is_sspc && spellmgr.IsNoStackSpellDueToSpell(spellId, i_spellId) ) 
    3942             { 
    3943                 // Its a parent aura (create this aura in ApplyModifier) 
    3944                 if ((*i).second->IsInUse()) 
    3945                 { 
    3946                     sLog.outError("Aura (Spell %u Effect %u) is in process but attempt removed at aura (Spell %u Effect %u) adding, need add stack rule for Unit::RemoveNoStackAurasDueToAura", i->second->GetId(), i->second->GetEffIndex(),Aur->GetId(), Aur->GetEffIndex()); 
    3947                     continue; 
    3948                 } 
    3949                 RemoveAurasDueToSpell(i_spellId); 
    3950  
    3951                 if( m_Auras.empty() ) 
    3952                     break; 
    3953                 else 
    3954                     next =  m_Auras.begin(); 
    3955             } 
    3956             // Potions stack aura by aura (elixirs/flask already checked) 
    3957             else if( spellProto->SpellFamilyName == SPELLFAMILY_POTION && i_spellProto->SpellFamilyName == SPELLFAMILY_POTION ) 
    3958             { 
    3959                 if (IsNoStackAuraDueToAura(spellId, effIndex, i_spellId, i_effIndex)) 
    3960                 { 
    3961                     if(CompareAuraRanks(spellId, effIndex, i_spellId, i_effIndex) < 0) 
    3962                         return false;                       // cannot remove higher rank 
    3963  
    3964                     // Its a parent aura (create this aura in ApplyModifier) 
    3965                     if ((*i).second->IsInUse()) 
    3966                     { 
    3967                         sLog.outError("Aura (Spell %u Effect %u) is in process but attempt removed at aura (Spell %u Effect %u) adding, need add stack rule for Unit::RemoveNoStackAurasDueToAura", i->second->GetId(), i->second->GetEffIndex(),Aur->GetId(), Aur->GetEffIndex()); 
    3968                         continue; 
    3969                     } 
    3970                     RemoveAura(i); 
    3971                     next = i; 
    3972                 } 
    39733938            } 
    39743939        } 
     
    41454110void Unit::RemoveAura(AuraMap::iterator &i, AuraRemoveMode mode) 
    41464111{ 
    4147     if (IsSingleTargetSpell((*i).second->GetSpellProto())) 
    4148     { 
    4149         if(Unit* caster = (*i).second->GetCaster()) 
     4112    Aura* Aur = i->second; 
     4113    SpellEntry const* AurSpellInfo = Aur->GetSpellProto(); 
     4114 
     4115    Unit* caster = NULL; 
     4116    if (IsSingleTargetSpell(AurSpellInfo)) 
     4117    { 
     4118        caster = Aur->GetCaster(); 
     4119        if(caster) 
    41504120        { 
    41514121            AuraList& scAuras = caster->GetSingleCastAuras(); 
    4152             scAuras.remove((*i).second); 
     4122            scAuras.remove(Aur); 
    41534123        } 
    41544124        else 
     
    41594129    } 
    41604130 
    4161     if ((*i).second->GetModifier()->m_auraname < TOTAL_AURAS) 
     4131    // remove from list before mods removing (prevent cyclic calls, mods added before including to aura list - use reverse order) 
     4132    if (Aur->GetModifier()->m_auraname < TOTAL_AURAS) 
    41624133    { 
    41634134        m_modAuras[(*i).second->GetModifier()->m_auraname].remove((*i).second); 
     
    41714142    } 
    41724143 
    4173     // remove from list before mods removing (prevent cyclic calls, mods added before including to aura list - use reverse order) 
    4174     Aura* Aur = i->second; 
    41754144    // Set remove mode 
    41764145    Aur->SetRemoveMode(mode); 
     
    41804149    ++m_removedAuras;                                       // internal count used by unit update 
    41814150 
    4182     // Status unsummoned at aura remove 
     4151    // Statue unsummoned at aura remove 
    41834152    Totem* statue = NULL; 
    4184     if(IsChanneledSpell(Aur->GetSpellProto())) 
    4185         if(Unit* caster = Aur->GetCaster()) 
     4153    bool caster_channeled = false; 
     4154    if(IsChanneledSpell(AurSpellInfo)) 
     4155    { 
     4156        if(!caster)                                         // can be already located for IsSingleTargetSpell case 
     4157            caster = Aur->GetCaster(); 
     4158 
     4159        if(caster) 
     4160        { 
    41864161            if(caster->GetTypeId()==TYPEID_UNIT && ((Creature*)caster)->isTotem() && ((Totem*)caster)->GetTotemType()==TOTEM_STATUE) 
    41874162                statue = ((Totem*)caster); 
    4188  
     4163            else 
     4164                caster_channeled = caster==this; 
     4165        } 
     4166    } 
    41894167 
    41904168    if(const std::vector<int32> *spell_triggered = spellmgr.GetSpellLinked(-(int32)Aur->GetSpellProto()->Id)) 
     
    42034181    Aur->_RemoveAura(); 
    42044182    delete Aur; 
     4183 
     4184    if(caster_channeled) 
     4185        RemoveAurasAtChanneledTarget (AurSpellInfo); 
    42054186 
    42064187    if(statue) 
     
    46294610} 
    46304611 
    4631 bool Unit::HandleHasteAuraProc(Unit *pVictim, SpellEntry const *hasteSpell, uint32 /*effIndex*/, uint32 damage, Aura* triggeredByAura, SpellEntry const * procSpell, uint32 /*procFlag*/, uint32 cooldown) 
    4632 { 
     4612bool Unit::HandleHasteAuraProc(Unit *pVictim, uint32 damage, Aura* triggeredByAura, SpellEntry const * /*procSpell*/, uint32 /*procFlag*/, uint32 cooldown) 
     4613{ 
     4614    SpellEntry const *hasteSpell = triggeredByAura->GetSpellProto(); 
     4615 
    46334616    Item* castItem = triggeredByAura->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER 
    46344617        ? ((Player*)this)->GetItemByGuid(triggeredByAura->GetCastItemGUID()) : NULL; 
     
    46904673} 
    46914674 
    4692 bool Unit::HandleDummyAuraProc(Unit *pVictim, SpellEntry const *dummySpell, uint32 effIndex, uint32 damage, Aura* triggeredByAura, SpellEntry const * procSpell, uint32 procFlag, uint32 cooldown) 
    4693 { 
     4675bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, Aura* triggeredByAura, SpellEntry const * procSpell, uint32 procFlag, uint32 cooldown) 
     4676{ 
     4677    SpellEntry const *dummySpell = triggeredByAura->GetSpellProto (); 
     4678    uint32 effIndex = triggeredByAura->GetEffIndex (); 
     4679 
    46944680    Item* castItem = triggeredByAura->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER 
    46954681        ? ((Player*)this)->GetItemByGuid(triggeredByAura->GetCastItemGUID()) : NULL; 
     
    62796265                            return false; 
    62806266 
    6281                         uint32 spell = 0; 
    62826267                        switch(triggeredByAura->GetSpellProto()->Id) 
    62836268                        { 
     
    63096294 
    63106295                        // overwrite non existing triggered spell call in spell.dbc 
    6311                         uint32 spell = 0; 
    63126296                        switch(triggeredByAura->GetSpellProto()->Id) 
    63136297                        { 
     
    65096493} 
    65106494 
    6511 bool Unit::HandleOverrideClassScriptAuraProc(Unit *pVictim, int32 scriptId, uint32 damage, Aura *triggeredByAura, SpellEntry const *procSpell, uint32 cooldown) 
    6512 { 
     6495bool Unit::HandleOverrideClassScriptAuraProc(Unit *pVictim, Aura *triggeredByAura, SpellEntry const *procSpell, uint32 cooldown) 
     6496{ 
     6497    int32 scriptId = triggeredByAura->GetModifier()->m_miscvalue; 
     6498 
    65136499    if(!pVictim || !pVictim->isAlive()) 
    65146500        return false; 
     
    72767262} 
    72777263 
    7278 void Unit::SendEnergizeSpellLog(Unit *pVictim, uint32 SpellID, uint32 Damage, Powers powertype, bool critical) 
     7264void Unit::SendEnergizeSpellLog(Unit *pVictim, uint32 SpellID, uint32 Damage, Powers powertype) 
    72797265{ 
    72807266    WorldPacket data(SMSG_SPELLENERGIZELOG, (8+8+4+4+4+1)); 
     
    73767362    AuraList const& mModDamagePercentTaken = pVictim->GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN); 
    73777363    for(AuraList::const_iterator i = mModDamagePercentTaken.begin(); i != mModDamagePercentTaken.end(); ++i) 
    7378         if((*i)->GetModifier()->m_miscvalue & GetSpellSchoolMask(spellProto)) 
     7364        if( (*i)->GetModifier()->m_miscvalue & GetSpellSchoolMask(spellProto) ) 
    73797365            TakenTotalMod *= ((*i)->GetModifier()->m_amount+100.0f)/100.0f; 
    73807366 
     
    82248210 
    82258211    // ..done (for creature type by mask) in taken 
    8226     AuraList const& mDamageDoneCreature = this->GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_CREATURE); 
     8212    AuraList const& mDamageDoneCreature = GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_CREATURE); 
    82278213    for(AuraList::const_iterator i = mDamageDoneCreature.begin();i != mDamageDoneCreature.end(); ++i) 
    82288214        if(creatureTypeMask & uint32((*i)->GetModifier()->m_miscvalue)) 
     
    82928278    // SPELL_AURA_MOD_OFFHAND_DAMAGE_PCT  included in weapon damage 
    82938279 
    8294     AuraList const& mDamageDoneVersus = this->GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_VERSUS); 
     8280    AuraList const& mDamageDoneVersus = GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_VERSUS); 
    82958281    for(AuraList::const_iterator i = mDamageDoneVersus.begin();i != mDamageDoneVersus.end(); ++i) 
    82968282        if(creatureTypeMask & uint32((*i)->GetModifier()->m_miscvalue)) 
     
    85228508        target->SetStandState(PLAYER_STATE_NONE); 
    85238509 
    8524     if(!target->isInCombat() && target->GetTypeId() != TYPEID_PLAYER && ((Creature*)target)->AI()) 
     8510    if(!target->isInCombat() && target->GetTypeId() != TYPEID_PLAYER 
     8511        && ((Creature*)target)->isAggressive() && ((Creature*)target)->AI()) 
    85258512        ((Creature*)target)->AI()->AttackStart(this); 
    85268513 
     
    85718558{ 
    85728559    assert(target); 
     8560 
     8561    if(!IsHostileTo(target)) 
     8562        return false; 
    85738563 
    85748564    if(!target->isAttackableByAOE() || target->hasUnitState(UNIT_STAT_DIED)) 
     
    87478737    if(IsInWorld()) 
    87488738    { 
    8749         Map *m = MapManager::Instance().GetMap(GetMapId(), this); 
     8739        Map *m = GetMap(); 
    87508740 
    87518741        if(GetTypeId()==TYPEID_PLAYER) 
     
    91569146    } 
    91579147 
     9148    // search nearby enemy before enter evade mode 
     9149    if(Unit *target = ((Creature*)this)->SelectNearestTarget()) 
     9150    { 
     9151        ((Creature*)this)->AI()->AttackStart(target); 
     9152        return true; 
     9153    } 
     9154 
    91589155    // enter in evade mode in other case 
    91599156    ((Creature*)this)->AI()->EnterEvadeMode(); 
     
    98099806} 
    98109807 
    9811  
    9812  
    98139808CharmInfo* Unit::InitCharmInfo(Unit *charm) 
    98149809{ 
     
    99859980struct ProcTriggeredData 
    99869981{ 
    9987     ProcTriggeredData(SpellEntry const * _spellInfo, uint32 _spellParam, Aura* _triggeredByAura, uint32 _cooldown) 
    9988         : spellInfo(_spellInfo), spellParam(_spellParam), triggeredByAura(_triggeredByAura), 
     9982    ProcTriggeredData(Aura* _triggeredByAura, uint32 _cooldown) 
     9983        : triggeredByAura(_triggeredByAura), 
    99899984        triggeredByAura_SpellPair(Unit::spellEffectPair(triggeredByAura->GetId(),triggeredByAura->GetEffIndex())), 
    99909985        cooldown(_cooldown) 
    9991         {} 
    9992  
    9993     SpellEntry const * spellInfo; 
    9994     uint32 spellParam; 
    9995     Aura* triggeredByAura; 
    9996     Unit::spellEffectPair triggeredByAura_SpellPair; 
    9997     uint32 cooldown; 
     9986    {} 
     9987 
     9988    Aura* triggeredByAura;                                  // triggred aura, can be invalidate at triggered aura proccessing 
     9989    Unit::spellEffectPair triggeredByAura_SpellPair;        // spell pair, used for re-find aura (by pointer comparison in range) 
     9990    uint32 cooldown;                                        // possible hidden cooldown 
    99989991}; 
    99999992 
     
    1001210005            next = i; ++next; 
    1001310006 
    10014             SpellEntry const *spellProto = (*i)->GetSpellProto(); 
    10015             if(!spellProto) 
     10007            Aura* i_aura = *i; 
     10008 
     10009            uint32 cooldown;                                // returned at next line 
     10010            if(!IsTriggeredAtSpellProcEvent(i_aura->GetSpellProto(), procSpell, procFlag,attType,isVictim,cooldown)) 
    1001610011                continue; 
    1001710012 
    10018             SpellProcEventEntry const *spellProcEvent = spellmgr.GetSpellProcEvent(spellProto->Id); 
    10019             if(!spellProcEvent) 
    10020             { 
    10021                 // used to prevent spam in log about same non-handled spells 
    10022                 static std::set<uint32> nonHandledSpellProcSet; 
    10023  
    10024                 if(spellProto->procFlags != 0 && nonHandledSpellProcSet.find(spellProto->Id)==nonHandledSpellProcSet.end()) 
    10025                 { 
    10026                     sLog.outError("ProcDamageAndSpell: spell %u (%s aura source) not have record in `spell_proc_event`)",spellProto->Id,(isVictim?"a victim's":"an attacker's")); 
    10027                     nonHandledSpellProcSet.insert(spellProto->Id); 
    10028                 } 
    10029  
    10030                 // spell.dbc use totally different flags, that only can create problems if used. 
    10031                 continue; 
    10032             } 
    10033  
    10034             // Check spellProcEvent data requirements 
    10035             if(!SpellMgr::IsSpellProcEventCanTriggeredBy(spellProcEvent, procSpell,procFlag)) 
    10036                 continue; 
    10037  
    10038             // Check if current equipment allows aura to proc 
    10039             if(!isVictim && GetTypeId() == TYPEID_PLAYER ) 
    10040             { 
    10041                 if(spellProto->EquippedItemClass == ITEM_CLASS_WEAPON) 
    10042                 { 
    10043                     Item *item = ((Player*)this)->GetWeaponForAttack(attType,true); 
    10044  
    10045                     if(!item || !((1<<item->GetProto()->SubClass) & spellProto->EquippedItemSubClassMask)) 
    10046                         continue; 
    10047                 } 
    10048                 else if(spellProto->EquippedItemClass == ITEM_CLASS_ARMOR) 
    10049                 { 
    10050                     // Check if player is wearing shield 
    10051                     Item *item = ((Player*)this)->GetShield(true); 
    10052                     if(!item || !((1<<item->GetProto()->SubClass) & spellProto->EquippedItemSubClassMask)) 
    10053                         continue; 
    10054                 } 
    10055             } 
    10056  
    10057             float chance = (float)spellProto->procChance; 
    10058  
    10059             if(Player* modOwner = GetSpellModOwner()) 
    10060                 modOwner->ApplySpellMod(spellProto->Id,SPELLMOD_CHANCE_OF_SUCCESS,chance); 
    10061  
    10062             if(!isVictim && spellProcEvent->ppmRate != 0) 
    10063             { 
    10064                 uint32 WeaponSpeed = GetAttackTime(attType); 
    10065                 chance = GetPPMProcChance(WeaponSpeed, spellProcEvent->ppmRate); 
    10066             } 
    10067  
    10068             if(roll_chance_f(chance)) 
    10069             { 
    10070                 uint32 cooldown = spellProcEvent->cooldown; 
    10071  
    10072                 uint32 i_spell_eff = (*i)->GetEffIndex(); 
    10073  
    10074                 int32 i_spell_param; 
    10075                 switch(*aur) 
    10076                 { 
    10077                     case SPELL_AURA_PROC_TRIGGER_SPELL: 
    10078                         i_spell_param = procFlag; 
    10079                         break; 
    10080                     case SPELL_AURA_DUMMY: 
    10081                     case SPELL_AURA_PRAYER_OF_MENDING: 
    10082                     case SPELL_AURA_MOD_HASTE: 
    10083                         i_spell_param = i_spell_eff; 
    10084                         break; 
    10085                     case SPELL_AURA_OVERRIDE_CLASS_SCRIPTS: 
    10086                         i_spell_param = (*i)->GetModifier()->m_miscvalue; 
    10087                         break; 
    10088                     default: 
    10089                         i_spell_param = (*i)->GetModifier()->m_amount; 
    10090                         break; 
    10091                 } 
    10092  
    10093                 procTriggered.push_back( ProcTriggeredData(spellProto,i_spell_param,*i, cooldown) ); 
    10094             } 
     10013            procTriggered.push_back( ProcTriggeredData(i_aura, cooldown) ); 
    1009510014        } 
    1009610015 
     
    1012510044            } 
    1012610045 
    10127             // save charges existence before processing to prevent crash at access to deleted triggered aura after 
    10128             bool triggeredByAuraWithCharges =  i->triggeredByAura->m_procCharges > 0; 
    10129  
     10046            /// this is aura triggering code call 
     10047            Aura* triggeredByAura = i->triggeredByAura; 
     10048 
     10049            /// save charges existence before processing to prevent crash at access to deleted triggered aura after 
     10050            /// used in speedup code check before check aura existance. 
     10051            bool triggeredByAuraWithCharges =  triggeredByAura->m_procCharges > 0; 
     10052 
     10053            /// success in event proccesing 
     10054            /// used in speedup code check before check aura existance. 
    1013010055            bool casted = false; 
     10056 
     10057            /// process triggered code 
    1013110058            switch(*aur) 
    1013210059            { 
    1013310060                case SPELL_AURA_PROC_TRIGGER_SPELL: 
    1013410061                { 
    10135                     sLog.outDebug("ProcDamageAndSpell: casting spell %u (triggered by %s aura of spell %u)", i->spellInfo->Id,(isVictim?"a victim's":"an attacker's"),i->triggeredByAura->GetId()); 
    10136                     casted = HandleProcTriggerSpell(pTarget, damage, i->triggeredByAura, procSpell,i->spellParam,attType,i->cooldown); 
     10062                    sLog.outDebug("ProcDamageAndSpell: casting spell (triggered by %s proc aura of spell %u)", 
     10063                        (isVictim?"a victim's":"an attacker's"),triggeredByAura->GetId()); 
     10064                    casted = HandleProcTriggerSpell(pTarget, damage, triggeredByAura, procSpell, procFlag, attType, i->cooldown); 
    1013710065                    break; 
    1013810066                } 
    1013910067                case SPELL_AURA_PROC_TRIGGER_DAMAGE: 
    1014010068                { 
    10141                     sLog.outDebug("ProcDamageAndSpell: doing %u damage from spell id %u (triggered by %s aura of spell %u)", i->spellParam, i->spellInfo->Id,(isVictim?"a victim's":"an attacker's"),i->triggeredByAura->GetId()); 
    10142                     uint32 damage = i->spellParam; 
    10143                     SpellNonMeleeDamageLog(pTarget, i->spellInfo->Id, damage, true, true); 
     10069                    uint32 triggered_damage = triggeredByAura->GetModifier()->m_amount; 
     10070                    sLog.outDebug("ProcDamageAndSpell: doing %u damage (triggered by %s aura of spell %u)", 
     10071                        triggered_damage, (isVictim?"a victim's":"an attacker's"),triggeredByAura->GetId()); 
     10072                    SpellNonMeleeDamageLog(pTarget, triggeredByAura->GetId(), triggered_damage, true, true); 
    1014410073                    casted = true; 
    1014510074                    break; 
     
    1014710076                case SPELL_AURA_DUMMY: 
    1014810077                { 
    10149                     sLog.outDebug("ProcDamageAndSpell: casting spell id %u (triggered by %s dummy aura of spell %u)", i->spellInfo->Id,(isVictim?"a victim's":"an attacker's"),i->triggeredByAura->GetId()); 
    10150                     casted = HandleDummyAuraProc(pTarget, i->spellInfo, i->spellParam, damage, i->triggeredByAura, procSpell, procFlag,i->cooldown); 
     10078                    uint32 effect = triggeredByAura->GetEffIndex(); 
     10079                    sLog.outDebug("ProcDamageAndSpell: casting spell (triggered by %s dummy aura of spell %u)", 
     10080                        (isVictim?"a victim's":"an attacker's"),triggeredByAura->GetId()); 
     10081                    casted = HandleDummyAuraProc(pTarget, damage, triggeredByAura, procSpell, procFlag,i->cooldown); 
    1015110082                    break; 
    1015210083                } 
    1015310084                case SPELL_AURA_PRAYER_OF_MENDING: 
    1015410085                { 
    10155                     sLog.outDebug("ProcDamageAndSpell(mending): casting spell id %u (triggered by %s dummy aura of spell %u)", i->spellInfo->Id,(isVictim?"a victim's":"an attacker's"),i->triggeredByAura->GetId()); 
    10156  
    10157                     // aura can be deleted at casts 
    10158                     int32 heal = i->triggeredByAura->GetModifier()->m_amount; 
    10159                     uint64 caster_guid = i->triggeredByAura->GetCasterGUID(); 
    10160  
    10161                     // jumps 
    10162                     int32 jumps = i->triggeredByAura->m_procCharges-1; 
    10163  
    10164                     // current aura expire 
    10165                     i->triggeredByAura->m_procCharges = 1;  // will removed at next charges decrease 
    10166  
    10167                     // next target selection 
    10168                     if(jumps > 0 && GetTypeId()==TYPEID_PLAYER && IS_PLAYER_GUID(caster_guid)) 
    10169                     { 
    10170                         Aura* aura = i->triggeredByAura; 
    10171  
    10172                         SpellEntry const* spellProto = aura->GetSpellProto(); 
    10173                         uint32 effIdx = aura->GetEffIndex(); 
    10174  
    10175                         float radius; 
    10176                         if (spellProto->EffectRadiusIndex[effIdx]) 
    10177                             radius = GetSpellRadius(sSpellRadiusStore.LookupEntry(spellProto->EffectRadiusIndex[effIdx])); 
    10178                         else 
    10179                             radius = GetSpellMaxRange(sSpellRangeStore.LookupEntry(spellProto->rangeIndex)); 
    10180  
    10181                         if(Player* caster = ((Player*)aura->GetCaster())) 
    10182                         { 
    10183                             caster->ApplySpellMod(spellProto->Id, SPELLMOD_RADIUS, radius,NULL); 
    10184  
    10185                             if(Player* target = ((Player*)this)->GetNextRandomRaidMember(radius)) 
    10186                             { 
    10187                                 // aura will applied from caster, but spell casted from current aura holder 
    10188                                 SpellModifier *mod = new SpellModifier; 
    10189                                 mod->op = SPELLMOD_CHARGES; 
    10190                                 mod->value = jumps-5;               // negative 
    10191                                 mod->type = SPELLMOD_FLAT; 
    10192                                 mod->spellId = spellProto->Id; 
    10193                                 mod->effectId = effIdx; 
    10194                                 mod->lastAffected = NULL; 
    10195                                 mod->mask = spellProto->SpellFamilyFlags; 
    10196                                 mod->charges = 0; 
    10197  
    10198                                 caster->AddSpellMod(mod, true); 
    10199                                 CastCustomSpell(target,spellProto->Id,&heal,NULL,NULL,true,NULL,aura,caster->GetGUID()); 
    10200                                 caster->AddSpellMod(mod, false); 
    10201                             } 
    10202                         } 
    10203                     } 
    10204  
    10205                     // heal 
    10206                     CastCustomSpell(this,33110,&heal,NULL,NULL,true,NULL,NULL,caster_guid); 
    10207                     casted = true; 
     10086                    sLog.outDebug("ProcDamageAndSpell: casting mending (triggered by %s dummy aura of spell %u)", 
     10087                        (isVictim?"a victim's":"an attacker's"),triggeredByAura->GetId()); 
     10088 
     10089                    casted = HandleMeandingAuraProc(triggeredByAura); 
    1020810090                    break; 
    1020910091                } 
    1021010092                case SPELL_AURA_MOD_HASTE: 
    1021110093                { 
    10212                     sLog.outDebug("ProcDamageAndSpell: casting spell id %u (triggered by %s haste aura of spell %u)", i->spellInfo->Id,(isVictim?"a victim's":"an attacker's"),i->triggeredByAura->GetId()); 
    10213                     casted = HandleHasteAuraProc(pTarget, i->spellInfo, i->spellParam, damage, i->triggeredByAura, procSpell, procFlag,i->cooldown); 
     10094                    sLog.outDebug("ProcDamageAndSpell: casting spell (triggered by %s haste aura of spell %u)", 
     10095                        (isVictim?"a victim's":"an attacker's"),triggeredByAura->GetId()); 
     10096                    casted = HandleHasteAuraProc(pTarget, damage, triggeredByAura, procSpell, procFlag,i->cooldown); 
    1021410097                    break; 
    1021510098                } 
     
    1021810101                    // nothing do, just charges counter 
    1021910102                    // but count only in case appropriate school damage 
    10220                     casted = i->triggeredByAura->GetModifier()->m_miscvalue & damageSchoolMask; 
     10103                    casted = triggeredByAura->GetModifier()->m_miscvalue & damageSchoolMask; 
    1022110104                    break; 
    1022210105                } 
    1022310106                case SPELL_AURA_OVERRIDE_CLASS_SCRIPTS: 
    1022410107                { 
    10225                     sLog.outDebug("ProcDamageAndSpell: casting spell id %u (triggered by %s aura of spell %u)", i->spellInfo->Id,(isVictim?"a victim's":"an attacker's"),i->triggeredByAura->GetId()); 
    10226                     casted = HandleOverrideClassScriptAuraProc(pTarget, i->spellParam, damage, i->triggeredByAura, procSpell,i->cooldown); 
     10108                    sLog.outDebug("ProcDamageAndSpell: casting spell (triggered by %s class script aura of spell %u)", 
     10109                        (isVictim?"a victim's":"an attacker's"),triggeredByAura->GetId()); 
     10110                    casted = HandleOverrideClassScriptAuraProc(pTarget, triggeredByAura, procSpell,i->cooldown); 
    1022710111                    break; 
    1022810112                } 
     
    1023510119            } 
    1023610120 
    10237             // Update charge (aura can be removed by triggers) 
     10121            /// Update charge (aura can be removed by triggers) 
    1023810122            if(casted && triggeredByAuraWithCharges) 
    1023910123            { 
    10240                 // need found aura (can be dropped by triggers) 
     10124                /// need re-found aura (can be dropped by triggers) 
    1024110125                AuraMap::const_iterator lower = GetAuras().lower_bound(i->triggeredByAura_SpellPair); 
    1024210126                AuraMap::const_iterator upper = GetAuras().upper_bound(i->triggeredByAura_SpellPair); 
    1024310127                for(AuraMap::const_iterator itr = lower; itr!= upper; ++itr) 
    1024410128                { 
    10245                     if(itr->second == i->triggeredByAura) 
     10129                    if(itr->second == triggeredByAura)      // pointer still valid 
    1024610130                    { 
    10247                         if(i->triggeredByAura->m_procCharges > 0) 
    10248                             i->triggeredByAura->m_procCharges -= 1; 
    10249  
    10250                         i->triggeredByAura->UpdateAuraCharges(); 
     10131                        if(triggeredByAura->m_procCharges > 0) 
     10132                            triggeredByAura->m_procCharges -= 1; 
     10133 
     10134                        triggeredByAura->UpdateAuraCharges(); 
    1025110135                        break; 
    1025210136                    } 
     
    1025510139        } 
    1025610140 
    10257         // Safely remove auras with zero charges 
     10141        /// Safely remove auras with zero charges 
    1025810142        for(AuraList::const_iterator i = auras.begin(), next; i != auras.end(); i = next) 
    1025910143        { 
     
    1036810252    // send explicit stop packet 
    1036910253    // rely on vmaps here because for example stormwind is in air 
    10370     float z = MapManager::Instance().GetBaseMap(GetMapId())->GetHeight(GetPositionX(), GetPositionY(), GetPositionZ(), true); 
     10254    //float z = MapManager::Instance().GetBaseMap(GetMapId())->GetHeight(GetPositionX(), GetPositionY(), GetPositionZ(), true); 
    1037110255    //if (fabs(GetPositionZ() - z) < 2.0f) 
    1037210256    //    Relocate(GetPositionX(), GetPositionY(), z); 
     
    1057810462} 
    1057910463 
    10580 Unit* Unit::SelectNearbyTarget() const 
     10464Unit* Unit::SelectNearbyTarget(float dist) const 
    1058110465{ 
    1058210466    CellPair p(Trinity::ComputeCellPair(GetPositionX(), GetPositionY())); 
     
    1058810472 
    1058910473    { 
    10590         Trinity::AnyUnfriendlyUnitInObjectRangeCheck u_check(this, this, ATTACK_DISTANCE); 
     10474        Trinity::AnyUnfriendlyUnitInObjectRangeCheck u_check(this, this, dist); 
    1059110475        Trinity::UnitListSearcher<Trinity::AnyUnfriendlyUnitInObjectRangeCheck> searcher(targets, u_check); 
    1059210476 
     
    1085210736    } 
    1085310737 
    10854     pet->SetUInt64Value(UNIT_FIELD_SUMMONEDBY, this->GetGUID()); 
    10855     pet->SetUInt64Value(UNIT_FIELD_CREATEDBY, this->GetGUID()); 
    10856     pet->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE,this->getFaction()); 
     10738    pet->SetUInt64Value(UNIT_FIELD_SUMMONEDBY, GetGUID()); 
     10739    pet->SetUInt64Value(UNIT_FIELD_CREATEDBY, GetGUID()); 
     10740    pet->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE,getFaction()); 
    1085710741    pet->SetUInt32Value(UNIT_CREATED_BY_SPELL, spell_id); 
    1085810742 
     
    1087210756    return pet; 
    1087310757} 
     10758 
     10759bool Unit::IsTriggeredAtSpellProcEvent(SpellEntry const* spellProto, SpellEntry const* procSpell, uint32 procFlag, WeaponAttackType attType, bool isVictim, uint32& cooldown ) 
     10760{ 
     10761    SpellProcEventEntry const * spellProcEvent = spellmgr.GetSpellProcEvent(spellProto->Id); 
     10762 
     10763    if(!spellProcEvent) 
     10764    { 
     10765        // used to prevent spam in log about same non-handled spells 
     10766        static std::set<uint32> nonHandledSpellProcSet; 
     10767 
     10768        if(spellProto->procFlags != 0 && nonHandledSpellProcSet.find(spellProto->Id)==nonHandledSpellProcSet.end()) 
     10769        { 
     10770            sLog.outError("ProcDamageAndSpell: spell %u (%s aura source) not have record in `spell_proc_event`)",spellProto->Id,(isVictim?"a victim's":"an attacker's")); 
     10771            nonHandledSpellProcSet.insert(spellProto->Id); 
     10772        } 
     10773 
     10774        // spell.dbc use totally different flags, that only can create problems if used. 
     10775        return false; 
     10776    } 
     10777 
     10778    // Check spellProcEvent data requirements 
     10779    if(!SpellMgr::IsSpellProcEventCanTriggeredBy(spellProcEvent, procSpell,procFlag)) 
     10780        return false; 
     10781 
     10782    // Check if current equipment allows aura to proc 
     10783    if(!isVictim && GetTypeId() == TYPEID_PLAYER ) 
     10784    { 
     10785        if(spellProto->EquippedItemClass == ITEM_CLASS_WEAPON) 
     10786        { 
     10787            Item *item = ((Player*)this)->GetWeaponForAttack(attType,true); 
     10788 
     10789            if(!item || !((1<<item->GetProto()->SubClass) & spellProto->EquippedItemSubClassMask)) 
     10790                return false; 
     10791        } 
     10792        else if(spellProto->EquippedItemClass == ITEM_CLASS_ARMOR) 
     10793        { 
     10794            // Check if player is wearing shield 
     10795            Item *item = ((Player*)this)->GetShield(true); 
     10796            if(!item || !((1<<item->GetProto()->SubClass) & spellProto->EquippedItemSubClassMask)) 
     10797                return false; 
     10798        } 
     10799    } 
     10800 
     10801    float chance = (float)spellProto->procChance; 
     10802 
     10803    if(Player* modOwner = GetSpellModOwner()) 
     10804        modOwner->ApplySpellMod(spellProto->Id,SPELLMOD_CHANCE_OF_SUCCESS,chance); 
     10805 
     10806    if(!isVictim && spellProcEvent && spellProcEvent->ppmRate != 0) 
     10807    { 
     10808        uint32 WeaponSpeed = GetAttackTime(attType); 
     10809        chance = GetPPMProcChance(WeaponSpeed, spellProcEvent->ppmRate); 
     10810    } 
     10811 
     10812    cooldown = spellProcEvent ? spellProcEvent->cooldown : 0; 
     10813    return roll_chance_f(chance); 
     10814} 
     10815 
     10816bool Unit::HandleMeandingAuraProc( Aura* triggeredByAura ) 
     10817{ 
     10818    // aura can be deleted at casts 
     10819    SpellEntry const* spellProto = triggeredByAura->GetSpellProto(); 
     10820    uint32 effIdx = triggeredByAura->GetEffIndex(); 
     10821    int32 heal = triggeredByAura->GetModifier()->m_amount; 
     10822    uint64 caster_guid = triggeredByAura->GetCasterGUID(); 
     10823 
     10824    // jumps 
     10825    int32 jumps = triggeredByAura->m_procCharges-1; 
     10826 
     10827    // current aura expire 
     10828    triggeredByAura->m_procCharges = 1;             // will removed at next charges decrease 
     10829 
     10830    // next target selection 
     10831    if(jumps > 0 && GetTypeId()==TYPEID_PLAYER && IS_PLAYER_GUID(caster_guid)) 
     10832    { 
     10833        float radius; 
     10834        if (spellProto->EffectRadiusIndex[effIdx]) 
     10835            radius = GetSpellRadius(sSpellRadiusStore.LookupEntry(spellProto->EffectRadiusIndex[effIdx])); 
     10836        else 
     10837            radius = GetSpellMaxRange(sSpellRangeStore.LookupEntry(spellProto->rangeIndex)); 
     10838 
     10839        if(Player* caster = ((Player*)triggeredByAura->GetCaster())) 
     10840        { 
     10841            caster->ApplySpellMod(spellProto->Id, SPELLMOD_RADIUS, radius,NULL); 
     10842 
     10843            if(Player* target = ((Player*)this)->GetNextRandomRaidMember(radius)) 
     10844            { 
     10845                // aura will applied from caster, but spell casted from current aura holder 
     10846                SpellModifier *mod = new SpellModifier; 
     10847                mod->op = SPELLMOD_CHARGES; 
     10848                mod->value = jumps-5;               // negative 
     10849                mod->type = SPELLMOD_FLAT; 
     10850                mod->spellId = spellProto->Id; 
     10851                mod->effectId = effIdx; 
     10852                mod->lastAffected = NULL; 
     10853                mod->mask = spellProto->SpellFamilyFlags; 
     10854                mod->charges = 0; 
     10855 
     10856                caster->AddSpellMod(mod, true); 
     10857                CastCustomSpell(target,spellProto->Id,&heal,NULL,NULL,true,NULL,triggeredByAura,caster->GetGUID()); 
     10858                caster->AddSpellMod(mod, false); 
     10859            } 
     10860        } 
     10861    } 
     10862 
     10863    // heal 
     10864    CastCustomSpell(this,33110,&heal,NULL,NULL,true,NULL,NULL,caster_guid); 
     10865    return true; 
     10866} 
     10867 
     10868void Unit::RemoveAurasAtChanneledTarget(SpellEntry const* spellInfo) 
     10869{ 
     10870    uint64 target_guid = GetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT); 
     10871 
     10872    if(!IS_UNIT_GUID(target_guid)) 
     10873        return; 
     10874 
     10875    Unit* target = ObjectAccessor::GetUnit(*this, target_guid); 
     10876    if(!target) 
     10877        return; 
     10878 
     10879    for (AuraMap::iterator iter = target->GetAuras().begin(); iter != target->GetAuras().end(); ) 
     10880    { 
     10881        if (iter->second->GetId() == spellInfo->Id && iter->second->GetCasterGUID()==GetGUID()) 
     10882            target->RemoveAura(iter); 
     10883        else 
     10884            ++iter; 
     10885    } 
     10886}