Show
Ignore:
Timestamp:
11/19/08 13:48:11 (17 years ago)
Author:
yumileroy
Message:

[svn] Some update on channeled spells.

Original author: megamage
Date: 2008-11-14 14:19:23-06:00

Files:
1 modified

Legend:

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

    r217 r226  
    182182    m_Visibility = VISIBILITY_ON; 
    183183 
     184    m_interruptMask = 0; 
    184185    m_detectInvisibilityMask = 0; 
    185186    m_invisibilityMask = 0; 
     
    466467void Unit::RemoveAurasWithInterruptFlags(uint32 flag) 
    467468{ 
     469    if(!(m_interruptMask & flag)) 
     470        return; 
     471 
     472    // interrupt auras 
    468473    AuraList::iterator iter, next; 
    469474    for (iter = m_interruptableAuras.begin(); iter != m_interruptableAuras.end(); iter = next) 
     
    479484                next = m_interruptableAuras.begin(); 
    480485            else 
    481                 return; 
    482         } 
    483     } 
     486                break; 
     487        } 
     488    } 
     489 
     490    // interrupt channeled spell 
     491    if(Spell* spell = m_currentSpells[CURRENT_CHANNELED_SPELL]) 
     492        if(spell->getState() == SPELL_STATE_CASTING && (spell->m_spellInfo->AuraInterruptFlags & flag)) 
     493            InterruptNonMeleeSpells(false); 
     494} 
     495 
     496void Unit::UpdateInterruptMask() 
     497{ 
     498    m_interruptMask = 0; 
     499    for(AuraList::iterator i = m_interruptableAuras.begin(); i != m_interruptableAuras.end(); ++i) 
     500    { 
     501        if(*i) 
     502            m_interruptMask |= (*i)->GetSpellProto()->AuraInterruptFlags; 
     503    } 
     504    if(Spell* spell = m_currentSpells[CURRENT_CHANNELED_SPELL]) 
     505        if(spell->getState() == SPELL_STATE_CASTING) 
     506            m_interruptMask |= spell->m_spellInfo->AuraInterruptFlags; 
    484507} 
    485508 
     
    527550    } 
    528551 
    529     // remove affects from victim (including from 0 damage and DoTs) 
    530     //if(pVictim != this) 
    531     //    pVictim->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH); 
    532  
    533     // remove affects from attacker at any non-DoT damage (including 0 damage) 
    534     if( damagetype != DOT) 
    535     { 
    536         if(pVictim->GetTypeId() == TYPEID_PLAYER && !pVictim->IsStandState() && !pVictim->hasUnitState(UNIT_STAT_STUNNED)) 
    537             pVictim->SetStandState(PLAYER_STATE_NONE); 
    538     } 
    539  
    540552    //Script Event damage taken 
    541553    if( pVictim->GetTypeId()== TYPEID_UNIT && ((Creature *)pVictim)->AI() ) 
    542554        ((Creature *)pVictim)->AI()->DamageTaken(this, damage); 
    543555 
    544     if(!damage) 
     556    if(!damage) //when will zero damage? need interrupt aura? 
    545557    { 
    546558        // Rage from physical damage received . 
     
    869881        } 
    870882 
    871         // polymorphed and other negative transformed cases 
    872         if(pVictim->getTransForm() && pVictim->hasUnitState(UNIT_STAT_CONFUSED)) 
    873             pVictim->RemoveAurasDueToSpell(pVictim->getTransForm()); 
    874  
    875883        if(damagetype == DIRECT_DAMAGE|| damagetype == SPELL_DIRECT_DAMAGE) 
    876884            pVictim->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_DIRECT_DAMAGE); 
     
    910918        } 
    911919 
    912         // TODO: Store auras by interrupt flag to speed this up. 
    913         /*AuraMap& vAuras = pVictim->GetAuras(); 
    914         for (AuraMap::iterator i = vAuras.begin(), next; i != vAuras.end(); i = next) 
    915         { 
    916             const SpellEntry *se = i->second->GetSpellProto(); 
    917             next = i; ++next; 
    918             if( se->AuraInterruptFlags & AURA_INTERRUPT_FLAG_DAMAGE ) 
    919             { 
    920                 bool remove = true; 
    921                 if (se->procFlags & (1<<3)) 
    922                 { 
    923                     if (!roll_chance_i(se->procChance)) 
    924                         remove = false; 
    925                 } 
    926                 if (remove) 
    927                 { 
    928                     pVictim->RemoveAurasDueToSpell(i->second->GetId()); 
    929                     // FIXME: this may cause the auras with proc chance to be rerolled several times 
    930                     next = vAuras.begin(); 
    931                 } 
    932             } 
    933             else */ 
    934         pVictim->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_DAMAGE); 
    935         pVictim->RemoveSpellbyDamageTaken(damage, spellProto ? spellProto->Id : 0); 
    936  
    937         if (damagetype != NODAMAGE && damage && pVictim->GetTypeId() == TYPEID_PLAYER) 
    938         { 
    939             if( damagetype != DOT ) 
    940             { 
    941                 for (uint32 i = CURRENT_FIRST_NON_MELEE_SPELL; i < CURRENT_MAX_SPELL; i++) 
    942                 { 
    943                     // skip channeled spell (processed differently below) 
    944                     if (i == CURRENT_CHANNELED_SPELL) 
    945                         continue; 
    946  
    947                     if(Spell* spell = pVictim->m_currentSpells[i]) 
     920        if (damagetype != NODAMAGE && damage)// && pVictim->GetTypeId() == TYPEID_PLAYER) 
     921        { 
     922            //if (se->procFlags & (1<<3)) 
     923            pVictim->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_DAMAGE); 
     924            pVictim->RemoveSpellbyDamageTaken(damage, spellProto ? spellProto->Id : 0); 
     925 
     926            if(pVictim != this && pVictim->GetTypeId() == TYPEID_PLAYER) // does not support creature push_back 
     927            { 
     928                if(damagetype != DOT) 
     929                { 
     930                    if(Spell* spell = pVictim->m_currentSpells[CURRENT_GENERIC_SPELL]) 
     931                    { 
    948932                        if(spell->getState() == SPELL_STATE_PREPARING) 
    949                             spell->Delayed(); 
    950                 } 
    951             } 
    952  
    953             if(Spell* spell = pVictim->m_currentSpells[CURRENT_CHANNELED_SPELL]) 
    954             { 
    955                 if (spell->getState() == SPELL_STATE_CASTING) 
    956                 { 
    957                     uint32 channelInterruptFlags = spell->m_spellInfo->ChannelInterruptFlags; 
    958                     if( channelInterruptFlags & CHANNEL_FLAG_DELAY ) 
     933                        { 
     934                            uint32 interruptFlags = spell->m_spellInfo->InterruptFlags; 
     935                            if(interruptFlags & SPELL_INTERRUPT_FLAG_DAMAGE) 
     936                                pVictim->InterruptNonMeleeSpells(false); 
     937                            else if(interruptFlags & SPELL_INTERRUPT_FLAG_PUSH_BACK) 
     938                                spell->Delayed(); 
     939                        } 
     940                    } 
     941                } 
     942 
     943                if(Spell* spell = pVictim->m_currentSpells[CURRENT_CHANNELED_SPELL]) 
     944                { 
     945                    if(spell->getState() == SPELL_STATE_CASTING) 
    959946                    { 
    960                         if(pVictim!=this)                   //don't shorten the duration of channeling if you damage yourself 
     947                        uint32 channelInterruptFlags = spell->m_spellInfo->ChannelInterruptFlags; 
     948                        if( channelInterruptFlags & CHANNEL_FLAG_DELAY ) 
    961949                            spell->DelayedChannel(); 
    962950                    } 
    963                     else if( (channelInterruptFlags & (CHANNEL_FLAG_DAMAGE | CHANNEL_FLAG_DAMAGE2)) ) 
    964                     { 
    965                         sLog.outDetail("Spell %u canceled at damage!",spell->m_spellInfo->Id); 
    966                         pVictim->InterruptSpell(CURRENT_CHANNELED_SPELL); 
    967                     } 
    968                 } 
    969                 else if (spell->getState() == SPELL_STATE_DELAYED) 
    970                     // break channeled spell in delayed state on damage 
    971                 { 
    972                     sLog.outDetail("Spell %u canceled at damage!",spell->m_spellInfo->Id); 
    973                     pVictim->InterruptSpell(CURRENT_CHANNELED_SPELL); 
    974951                } 
    975952            } 
     
    37963773        m_modAuras[Aur->GetModifier()->m_auraname].push_back(Aur); 
    37973774        if(Aur->GetSpellProto()->AuraInterruptFlags) 
     3775        { 
    37983776            m_interruptableAuras.push_back(Aur); 
     3777            AddInterruptMask(Aur->GetSpellProto()->AuraInterruptFlags); 
     3778        } 
    37993779        if(Aur->GetSpellProto()->Attributes & SPELL_ATTR_BREAKABLE_BY_DAMAGE) 
    38003780        { 
     
    41644144        m_modAuras[(*i).second->GetModifier()->m_auraname].remove((*i).second); 
    41654145        if((*i).second->GetSpellProto()->AuraInterruptFlags) 
     4146        { 
    41664147            m_interruptableAuras.remove((*i).second); 
     4148            UpdateInterruptMask(); 
     4149        } 
    41674150        if((*i).second->GetSpellProto()->Attributes & SPELL_ATTR_BREAKABLE_BY_DAMAGE) 
    41684151            m_ccAuras.remove((*i).second); 
     
    84858468void Unit::CombatStart(Unit* target) 
    84868469{ 
     8470    if(!target->IsStandState() && !target->hasUnitState(UNIT_STAT_STUNNED)) 
     8471        target->SetStandState(PLAYER_STATE_NONE); 
     8472 
    84878473    if(!target->isInCombat() && target->GetTypeId() != TYPEID_PLAYER && ((Creature*)target)->AI()) 
    84888474        ((Creature*)target)->AI()->AttackStart(this);