Ejemplo n.º 1
0
    void UpdateAI(const uint32 uiDiff)
    {
        if (!m_creature->SelectHostileTarget() || !m_creature->getVictim())
            return;

        if (!m_pInstance || m_pInstance->GetData(TYPE_KELTHUZAD) != IN_PROGRESS)
            return;

        if (m_uiPhase == PHASE_INTRO)
        {
            if (m_uiIntroPackCount < 7)
            {
                if (m_uiSummonIntroTimer < uiDiff)
                {
                    if (!m_uiIntroPackCount)
                        DoScriptText(SAY_SUMMON_MINIONS, m_creature);

                    SummonIntroCreatures(m_uiIntroPackCount);
                    ++m_uiIntroPackCount;
                    m_uiSummonIntroTimer = 2000;
                }
                else
                    m_uiSummonIntroTimer -= uiDiff;
            }
            else
            {
                if (m_uiPhase1Timer < uiDiff)
                {
                    m_uiPhase = PHASE_NORMAL;
                    DespawnIntroCreatures();
                    m_creature->InterruptNonMeleeSpells(false);
                    m_creature->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE);
                    SetCombatMovement(true);
                    m_creature->GetMotionMaster()->MoveChase(m_creature->getVictim());

                    DoScriptText(EMOTE_PHASE2, m_creature);

                    switch(urand(0, 2))
                    {
                        case 0: DoScriptText(SAY_AGGRO1, m_creature); break;
                        case 1: DoScriptText(SAY_AGGRO2, m_creature); break;
                        case 2: DoScriptText(SAY_AGGRO3, m_creature); break;
                    };
                }
                else
                    m_uiPhase1Timer -= uiDiff;

                if (m_uiSoldierCount < MAX_SOLDIER_COUNT)
                {
                    if (m_uiSoldierTimer < uiDiff)
                    {
                        SummonMob(NPC_SOLDIER_FROZEN);
                        ++m_uiSoldierCount;
                        m_uiSoldierTimer = 3000;
                    }
                    else
                        m_uiSoldierTimer -= uiDiff;
                }

                if (m_uiAbominationCount < MAX_ABOMINATION_COUNT)
                {
                    if (m_uiAbominationTimer < uiDiff)
                    {
                        SummonMob(NPC_UNSTOPPABLE_ABOM);
                        ++m_uiAbominationCount;
                        m_uiAbominationTimer = 25000;
                    }
                    else
                        m_uiAbominationTimer -= uiDiff;
                }

                if (m_uiBansheeCount < MAX_BANSHEE_COUNT)
                {
                    if (m_uiBansheeTimer < uiDiff)
                    {
                        SummonMob(NPC_SOUL_WEAVER);
                        ++m_uiBansheeCount;
                        m_uiBansheeTimer = 25000;
                    }
                    else
                        m_uiBansheeTimer -= uiDiff;
                }
            }
        }
        else // normal or guardian phase
        {
            if (m_uiFrostBoltTimer < uiDiff)
            {
                if (DoCastSpellIfCan(m_creature->getVictim(), m_bIsRegularMode ? SPELL_FROST_BOLT : SPELL_FROST_BOLT_H) == CAST_OK)
                    m_uiFrostBoltTimer = urand(1000, 60000);
            }
            else
                m_uiFrostBoltTimer -= uiDiff;

            if (m_uiFrostBoltNovaTimer < uiDiff)
            {
                if (DoCastSpellIfCan(m_creature->getVictim(), m_bIsRegularMode ? SPELL_FROST_BOLT_NOVA : SPELL_FROST_BOLT_NOVA_H) == CAST_OK)
                    m_uiFrostBoltNovaTimer = 15000;
            }
            else
                m_uiFrostBoltNovaTimer -= uiDiff;

            if (m_uiManaDetonationTimer < uiDiff)
            {
                Unit* pTarget = m_creature->SelectAttackingTarget(ATTACKING_TARGET_RANDOM, 0);

                if (pTarget && pTarget->GetTypeId() == TYPEID_PLAYER && pTarget->getPowerType() == POWER_MANA)
                {
                    if (DoCastSpellIfCan(pTarget, SPELL_DETONATE_MANA) == CAST_OK)
                    {
                        if (urand(0, 1))
                            DoScriptText(SAY_SPECIAL1_MANA_DET, m_creature);

                        m_uiManaDetonationTimer = 20000;
                    }
                }
            }
            else
                m_uiManaDetonationTimer -= uiDiff;

            if (m_uiShadowFissureTimer < uiDiff)
            {
                if (Unit* pTarget = m_creature->SelectAttackingTarget(ATTACKING_TARGET_RANDOM, 0))
                {
                    if (DoCastSpellIfCan(pTarget, SPELL_SHADOW_FISSURE) == CAST_OK)
                    {
                        if (urand(0, 1))
                            DoScriptText(SAY_SPECIAL3_MANA_DET, m_creature);

                        m_uiShadowFissureTimer = 25000;
                    }
                }
            }
            else
                m_uiShadowFissureTimer -= uiDiff;

            if (m_uiFrostBlastTimer < uiDiff)
            {
                if (DoCastSpellIfCan(m_creature->getVictim(), SPELL_FROST_BLAST) == CAST_OK)
                {
                    if (urand(0, 1))
                        DoScriptText(SAY_FROST_BLAST, m_creature);

                    m_uiFrostBlastTimer = urand(30000, 60000);
                }
            }
            else
                m_uiFrostBlastTimer -= uiDiff;

            if (!m_bIsRegularMode)
            {
                if (m_uiChainsTimer < uiDiff)
                {
                    if (DoCastSpellIfCan(m_creature->getVictim(), SPELL_CHAINS_OF_KELTHUZAD) == CAST_OK)
                    {
                        DoScriptText(urand(0, 1) ? SAY_CHAIN1 : SAY_CHAIN2, m_creature);

                        m_uiChainsTimer = urand(30000, 60000);
                    }
                }
                else
                    m_uiChainsTimer -= uiDiff;
            }

            if (m_uiPhase == PHASE_NORMAL)
            {
                if (m_creature->GetHealthPercent() < 45.0f)
                {
                    m_uiPhase = PHASE_GUARDIANS;
                    DoScriptText(SAY_REQUEST_AID, m_creature);
                }
            }
            else if (m_uiPhase == PHASE_GUARDIANS && m_uiGuardiansCount < m_uiGuardiansCountMax)
            {
                if (m_uiGuardiansTimer < uiDiff)
                {
                    // Summon a Guardian of Icecrown in a random alcove
                    SummonMob(NPC_GUARDIAN);
                    m_uiGuardiansTimer = 5000;
                }
                else
                    m_uiGuardiansTimer -= uiDiff;

                if (m_uiLichKingAnswerTimer && m_pInstance)
                {
                    if (m_uiLichKingAnswerTimer <= uiDiff)
                    {
                        if (Creature* pLichKing = m_pInstance->GetSingleCreatureFromStorage(NPC_THE_LICHKING))
                            DoScriptText(SAY_ANSWER_REQUEST, pLichKing);
                        m_uiLichKingAnswerTimer = 0;
                    }
                    else
                        m_uiLichKingAnswerTimer -= uiDiff;
                }
            }

            DoMeleeAttackIfReady();
        }
    }
Ejemplo n.º 2
0
    void UpdateAI(const uint32 uiDiff)
    {
        if (!m_creature->SelectHostileTarget() || !m_creature->getVictim())
            return;

        if (!m_pInstance || m_pInstance->GetData(TYPE_KELTHUZAD) != IN_PROGRESS)
            return;

        if (m_uiPhase == PHASE_INTRO)
        {
            if (m_uiIntroPackCount < 7)
            {
                if (m_uiSummonIntroTimer < uiDiff)
                {
                    if (!m_uiIntroPackCount)
                        DoScriptText(SAY_SUMMON_MINIONS, m_creature);

                    SummonIntroCreatures(m_uiIntroPackCount);
                    ++m_uiIntroPackCount;
                    m_uiSummonIntroTimer = 2000;
                }
                else
                    m_uiSummonIntroTimer -= uiDiff;
            }
            else
            {
                if (m_uiPhase1Timer < uiDiff)
                {
                    m_uiPhase = PHASE_NORMAL;
                    DespawnIntroCreatures();

                    m_creature->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE);
                    SetCombatMovement(true);
                    m_creature->GetMotionMaster()->MoveChase(m_creature->getVictim());

                    DoScriptText(EMOTE_PHASE2, m_creature);

                    switch(urand(0, 2))
                    {
                        case 0: DoScriptText(SAY_AGGRO1, m_creature); break;
                        case 1: DoScriptText(SAY_AGGRO2, m_creature); break;
                        case 2: DoScriptText(SAY_AGGRO3, m_creature); break;
                    };
                }
                else
                    m_uiPhase1Timer -= uiDiff;

                if (m_uiSoldierCount < MAX_SOLDIER_COUNT)
                {
                    if (m_uiSoldierTimer < uiDiff)
                    {
                        SummonMob(NPC_SOLDIER_FROZEN);
                        ++m_uiSoldierCount;
                        m_uiSoldierTimer = 3000;
                    }
                    else
                        m_uiSoldierTimer -= uiDiff;
                }

                if (m_uiAbominationCount < MAX_ABOMINATION_COUNT)
                {
                    if (m_uiAbominationTimer < uiDiff)
                    {
                        SummonMob(NPC_UNSTOPPABLE_ABOM);
                        ++m_uiAbominationCount;
                        m_uiAbominationTimer = 25000;
                    }
                    else
                        m_uiAbominationTimer -= uiDiff;
                }

                if (m_uiBansheeCount < MAX_BANSHEE_COUNT)
                {
                    if (m_uiBansheeTimer < uiDiff)
                    {
                        SummonMob(NPC_SOUL_WEAVER);
                        ++m_uiBansheeCount;
                        m_uiBansheeTimer = 25000;
                    }
                    else
                        m_uiBansheeTimer -= uiDiff;
                }
            }
        }
        else // normal or guardian phase
        {
            if (m_uiFrostBoltTimer < uiDiff)
            {
                if (DoCastSpellIfCan(m_creature->getVictim(), m_bIsRegularMode ? SPELL_FROST_BOLT : SPELL_FROST_BOLT_H) == CAST_OK)
                    m_uiFrostBoltTimer = urand(1000, 60000);
            }
            else
                m_uiFrostBoltTimer -= uiDiff;

            if (m_uiFrostBoltNovaTimer < uiDiff)
            {
                if (DoCastSpellIfCan(m_creature->getVictim(), m_bIsRegularMode ? SPELL_FROST_BOLT_NOVA : SPELL_FROST_BOLT_NOVA_H) == CAST_OK)
                    m_uiFrostBoltNovaTimer = 15000;
            }
            else
                m_uiFrostBoltNovaTimer -= uiDiff;
               
            if (m_uiManaDetonationTimer < uiDiff)
            {
                Unit* pTarget;
                uint8 counter = 0;
                do
                {
                    counter++;
                    if (counter >= 25)
                    {
                        break;
                        pTarget = NULL;
                    }
                    else
                        pTarget = m_creature->SelectAttackingTarget(ATTACKING_TARGET_RANDOM, 0);
                }
                while(pTarget->getPowerType() != POWER_MANA);

                if (pTarget)
                {
                    if (DoCastSpellIfCan(pTarget, SPELL_MANA_DETONATION) == CAST_OK)
                    {
                        if (urand(0, 1))
                            DoScriptText(SAY_SPECIAL1_MANA_DET, m_creature);

                        m_uiManaDetonationTargetGUID = pTarget->GetGUID();
                        m_uiManaDetonationMana = m_bIsRegularMode ? urand(2500,4000) : urand(3500,5500);
                        uint32 newMana = pTarget->GetPower(POWER_MANA) - m_uiManaDetonationMana; 
                        uint32 mana = newMana < 0 ? 0 : newMana;
                        m_uiManaDetonationMana *= 1+(urand(2,m_bIsRegularMode?5:9)/10.f); // random increase damage output, not blizzlike
                        pTarget->SetPower(POWER_MANA, mana);
                        
                        m_uiManaDetonationTimer = 20000;
                        m_uiManaDetonationEndTimer = 5000;
                        m_bManaDetonationActive = true;
                    }
                }
            }
            else
                m_uiManaDetonationTimer -= uiDiff;

            if (m_bManaDetonationActive)
                if (m_uiManaDetonationEndTimer < uiDiff)
                {
                    if (Player* pTarget = m_creature->GetMap()->GetPlayer(m_uiManaDetonationTargetGUID))
                    {
                        Map *map = m_creature->GetMap();
                        Map::PlayerList const &PlayerList = map->GetPlayers();
                        if (!PlayerList.isEmpty())
                            for (Map::PlayerList::const_iterator i = PlayerList.begin(); i != PlayerList.end(); ++i)
                            {
                                if(i->getSource()->isDead() || i->getSource() == pTarget || i->getSource()->isGameMaster()) // no dmg on dead, self and GMs
                                    continue;
                                if (pTarget->GetDistance2d(i->getSource()) < 15.f)
                                    i->getSource()->DealDamage(i->getSource(), m_uiManaDetonationMana, NULL, SPELL_DIRECT_DAMAGE, SPELL_SCHOOL_MASK_ARCANE, NULL, true);
                            }
                    }
                    m_bManaDetonationActive = false;
                }
                else
                    m_uiManaDetonationEndTimer -= uiDiff;

            
            if (m_uiShadowFissureTimer < uiDiff)
            {
                if (Unit* pTarget = m_creature->SelectAttackingTarget(ATTACKING_TARGET_RANDOM, 0))
                    if(DoCastSpellIfCan(pTarget, SPELL_SHADOW_FISSURE) == CAST_OK)
                    {
                        m_fFissureX = pTarget->GetPositionX();
                        m_fFissureY = pTarget->GetPositionY();

                        if (urand(0, 1))
                            DoScriptText(SAY_SPECIAL3_MANA_DET, m_creature);

                        m_uiShadowFissureTimer = 25000;
                        m_uiShadowFissureActiveTimer = 5000;
                        m_bShadowFissureActive = true;
                    }
            }
            else
                m_uiShadowFissureTimer -= uiDiff;

            if(m_bShadowFissureActive)
                if(m_uiShadowFissureActiveTimer < uiDiff)
                {   
                    // hack for shadow fissure damage, shadow fissure spell does not give damage to players
                    Map::PlayerList const& pPlayers = m_creature->GetMap()->GetPlayers();
                    if (!pPlayers.isEmpty())
                        for (Map::PlayerList::const_iterator itr = pPlayers.begin(); itr != pPlayers.end(); ++itr)
                            if(itr->getSource() && !itr->getSource()->isGameMaster() && (itr->getSource()->GetDistance2d(m_fFissureX,m_fFissureY) < 4.0f))
                                m_creature->DealDamage(itr->getSource(),itr->getSource()->GetHealth(),NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
                    m_bShadowFissureActive = false;
                }
                else 
                    m_uiShadowFissureActiveTimer -= uiDiff;

            if (m_uiFrostBlastTimer < uiDiff)
            {
                if (DoCastSpellIfCan(m_creature->SelectAttackingTarget(ATTACKING_TARGET_RANDOM,0), SPELL_FROST_BLAST) == CAST_OK)
                {
                    if (urand(0, 1))
                        DoScriptText(SAY_FROST_BLAST, m_creature);

                    m_uiFrostBlastTimer = urand(30000, 60000);
                }
            }
            else
                m_uiFrostBlastTimer -= uiDiff;
                
            if (!m_bIsRegularMode)
            {
                if (m_uiChainsTimer < uiDiff)
                {
                    m_lChainsTargets.clear();
                    if (SpellEntry* TempSpell = (SpellEntry*)GetSpellStore()->LookupEntry(SPELL_CHAINS_OF_KELTHUZAD_TARGET))
                    {
                        TempSpell->EffectApplyAuraName[0]=SPELL_AURA_MOD_CHARM;
                        uint8 uiChainsTargetsCount = 0;
                        for (uint8 i=0; i<25; ++i)
                        {
                            if (Unit* pTarget = m_creature->SelectAttackingTarget(ATTACKING_TARGET_RANDOM, 0))
                            {
                                if (pTarget->GetTypeId() == TYPEID_PLAYER && !pTarget->HasAura(SPELL_CHAINS_OF_KELTHUZAD_TARGET, EFFECT_INDEX_0))
                                {
                                    m_creature->InterruptNonMeleeSpells(false);
                                    m_creature->CastCustomSpell(pTarget, TempSpell, NULL, NULL, NULL, true);
                                    ((Player*)pTarget)->SetClientControl(pTarget, 0);
                                    m_lChainsTargets.insert(pTarget->GetGUID());
                                    pTarget->setFaction(14);
                                    ++uiChainsTargetsCount;
                                }
                                if (uiChainsTargetsCount>=3)
                                    break;
                            }
                        }
                        m_uiChainsEndTimer = 20000;
                        m_uiChainsTargetsCastTimer = 3500;
                        DoResetThreat();
                    }
                
                    //DoCastSpellIfCan(pTarget, SPELL_CHAINS_OF_KELTHUZAD);
                    DoScriptText(urand(0, 1) ? SAY_CHAIN1 : SAY_CHAIN2, m_creature);
                    m_uiChainsTimer = urand(60000, 90000);
                }
                else
                    m_uiChainsTimer -= uiDiff;

                if (!m_lChainsTargets.empty())
                {
                    if (m_uiChainsTargetsCastTimer < uiDiff)
                    {
                        for (std::set<uint64>::iterator itr = m_lChainsTargets.begin(); itr != m_lChainsTargets.end(); ++itr)
                            if (Unit* pUnit = m_creature->GetMap()->GetUnit(*itr))
                            {
                                if (pUnit->isDead())
                                    continue;
                            
                                if (pUnit->getClass() == CLASS_PRIEST || pUnit->getClass() == CLASS_SHAMAN ||  pUnit->getClass() == CLASS_MAGE ||
                                    pUnit->getClass() == CLASS_WARLOCK) // healer classes heal kelthuzad
                                {
                                    int32 amount = urand(11000,19000);
                                    pUnit->CastCustomSpell(m_creature, 36983, &amount, NULL, NULL, false);
                                }
                                else // other classes melee players
                                    if (Unit* pVictim = m_creature->SelectAttackingTarget(ATTACKING_TARGET_RANDOM,0))
                                    {
                                        pUnit->GetMotionMaster()->MoveChase(pVictim);
                                        pUnit->Attack(pVictim,true);
                                    }
                            }
                        m_uiChainsTargetsCastTimer = 4500;
                    }
                    else
                        m_uiChainsTargetsCastTimer -= uiDiff;

                    if (m_uiChainsEndTimer < uiDiff)
                    {
                        for(std::set<uint64>::iterator itr = m_lChainsTargets.begin(); itr != m_lChainsTargets.end(); ++itr)
                            if (Player* pPlayer = m_creature->GetMap()->GetPlayer(*itr))
                            {
                                pPlayer->setFactionForRace(pPlayer->getRace());
                                pPlayer->SetClientControl(pPlayer, 1);
                            }
                        m_lChainsTargets.clear();
                    }
                    else
                        m_uiChainsEndTimer -= uiDiff;
                }
            }

            if (m_uiPhase == PHASE_NORMAL)
            {
                if (m_creature->GetHealthPercent() < 45.0f)
                {
                    m_uiPhase = PHASE_GUARDIANS;
                    DoScriptText(SAY_REQUEST_AID, m_creature);

                    // here Lich King should respond to Kel'Thuzad but I don't know which creature to make talk
                    // so for now just make Kel'Thuzad says it.
                    DoScriptText(SAY_ANSWER_REQUEST, m_creature);
                }
            }
            else if (m_uiPhase == PHASE_GUARDIANS && m_uiGuardiansCount < m_uiGuardiansCountMax)
            {
                if (m_uiGuardiansTimer < uiDiff)
                {
                    // Summon a Guardian of Icecrown in a random alcove
                    SummonMob(NPC_GUARDIAN);
                    m_uiGuardiansTimer = 5000;
                }
                else
                    m_uiGuardiansTimer -= uiDiff;
            }

            DoMeleeAttackIfReady();
        }
    }
Ejemplo n.º 3
0
    void UpdateAI(const uint32 uiDiff)
    {
        if (!m_creature->SelectHostileTarget() || !m_creature->getVictim())
            return;

        if (!m_pInstance || m_pInstance->GetData(TYPE_KELTHUZAD) != IN_PROGRESS)
            return;

        if (m_uiPhase == PHASE_INTRO)
        {
            if (m_uiIntroPackCount < 7)
            {
                if (m_uiSummonIntroTimer < uiDiff)
                {
                    if (!m_uiIntroPackCount)
                        DoScriptText(SAY_SUMMON_MINIONS, m_creature);

                    SummonIntroCreatures(m_uiIntroPackCount);
                    ++m_uiIntroPackCount;
                    m_uiSummonIntroTimer = 2000;
                }
                else
                    m_uiSummonIntroTimer -= uiDiff;
            }
            else
            {
                if (m_uiPhase1Timer < uiDiff)
                {
                    m_uiPhase = PHASE_NORMAL;
                    DespawnIntroCreatures();

                    m_creature->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE);
                    SetCombatMovement(true);
                    m_creature->GetMotionMaster()->MoveChase(m_creature->getVictim());

                    DoScriptText(EMOTE_PHASE2, m_creature);

                    switch(urand(0, 2))
                    {
                        case 0: DoScriptText(SAY_AGGRO1, m_creature); break;
                        case 1: DoScriptText(SAY_AGGRO2, m_creature); break;
                        case 2: DoScriptText(SAY_AGGRO3, m_creature); break;
                    };
                }
                else
                    m_uiPhase1Timer -= uiDiff;

                if (m_uiSoldierCount < MAX_SOLDIER_COUNT)
                {
                    if (m_uiSoldierTimer < uiDiff)
                    {
                        SummonMob(NPC_SOLDIER_FROZEN);
                        ++m_uiSoldierCount;
                        m_uiSoldierTimer = 3000;
                    }
                    else
                        m_uiSoldierTimer -= uiDiff;
                }

                if (m_uiAbominationCount < MAX_ABOMINATION_COUNT)
                {
                    if (m_uiAbominationTimer < uiDiff)
                    {
                        SummonMob(NPC_UNSTOPPABLE_ABOM);
                        ++m_uiAbominationCount;
                        m_uiAbominationTimer = 25000;
                    }
                    else
                        m_uiAbominationTimer -= uiDiff;
                }

                if (m_uiBansheeCount < MAX_BANSHEE_COUNT)
                {
                    if (m_uiBansheeTimer < uiDiff)
                    {
                        SummonMob(NPC_SOUL_WEAVER);
                        ++m_uiBansheeCount;
                        m_uiBansheeTimer = 25000;
                    }
                    else
                        m_uiBansheeTimer -= uiDiff;
                }
            }
        }
        else // normal or guardian phase
        {
            if (m_uiFrostBoltTimer < uiDiff)
            {
                if (DoCastSpellIfCan(m_creature->getVictim(), m_bIsRegularMode ? SPELL_FROST_BOLT : SPELL_FROST_BOLT_H) == CAST_OK)
                    m_uiFrostBoltTimer = urand(1000, 60000);
            }
            else
                m_uiFrostBoltTimer -= uiDiff;

            if (m_uiFrostBoltNovaTimer < uiDiff)
            {
                if (DoCastSpellIfCan(m_creature->getVictim(), m_bIsRegularMode ? SPELL_FROST_BOLT_NOVA : SPELL_FROST_BOLT_NOVA_H) == CAST_OK)
                    m_uiFrostBoltNovaTimer = 15000;
            }
            else
                m_uiFrostBoltNovaTimer -= uiDiff;

            if (m_uiManaDetonationTimer < uiDiff)
            {
                if (Unit* pTarget = SelectTargetWithMana())
                {
                    if (DoCastSpellIfCan(pTarget, SPELL_MANA_DETONATION) == CAST_OK)
                    {
                        if (urand(0, 1))
                            DoScriptText(SAY_SPECIAL1_MANA_DET, m_creature);

                        m_uiManaDetonationTimer = 20000;
                    }
                }
            }
            else
                m_uiManaDetonationTimer -= uiDiff;

            if (m_uiShadowFissureTimer < uiDiff)
            {
                if (Unit* pTarget = m_creature->SelectAttackingTarget(ATTACKING_TARGET_RANDOM, 0))
                {
                    Player *pPlayerTarget = pTarget->GetCharmerOrOwnerPlayerOrPlayerItself();
                    if (DoCastSpellIfCan(pPlayerTarget ? pPlayerTarget : pTarget, SPELL_SHADOW_FISSURE) == CAST_OK)
                    {
                        if (urand(0, 1))
                            DoScriptText(SAY_SPECIAL3_MANA_DET, m_creature);

                        m_uiShadowFissureTimer = 25000;
                    }
                }
            }
            else
                m_uiShadowFissureTimer -= uiDiff;

            if (m_uiFrostBlastTimer < uiDiff)
            {
                if (Unit* pTarget = m_creature->SelectAttackingTarget(ATTACKING_TARGET_RANDOM, (m_bIsRegularMode ? 1 : 0)))
                {
                    Player *pPlayerTarget = pTarget->GetCharmerOrOwnerPlayerOrPlayerItself();
                    if (pPlayerTarget && (m_bIsRegularMode || pPlayerTarget != m_creature->getVictim()))
                    {
                        if (DoCastSpellIfCan(pPlayerTarget, SPELL_FROST_BLAST) == CAST_OK)
                        {
                            if (urand(0, 1))
                                DoScriptText(SAY_FROST_BLAST, m_creature);

                            m_uiFrostBlastTimer = urand(30000, 60000);
                        }
                    }
                }
            }
            else
                m_uiFrostBlastTimer -= uiDiff;

            if (!m_bIsRegularMode)
            {
                if (m_uiChainsTimer < uiDiff)
                {
                    if (DoCastSpellIfCan(m_creature->getVictim(), SPELL_CHAINS_OF_KELTHUZAD) == CAST_OK)
                    {
                        DoScriptText(urand(0, 1) ? SAY_CHAIN1 : SAY_CHAIN2, m_creature);

                        m_uiChainsTimer = urand(30000, 60000);
                    }
                }
                else
                    m_uiChainsTimer -= uiDiff;
            }

            if (m_uiPhase == PHASE_NORMAL)
            {
                if (m_creature->GetHealthPercent() < 45.0f)
                {
                    m_uiPhase = PHASE_GUARDIANS;
                    DoScriptText(SAY_REQUEST_AID, m_creature);

                    // here Lich King should respond to Kel'Thuzad but I don't know which creature to make talk
                    // so for now just make Kel'Thuzad says it.
                    DoScriptText(SAY_ANSWER_REQUEST, m_creature);
                }
            }
            else if (m_uiPhase == PHASE_GUARDIANS && m_uiGuardiansCount < m_uiGuardiansCountMax)
            {
                if (m_uiGuardiansTimer < uiDiff)
                {
                    // Summon a Guardian of Icecrown in a random alcove
                    SummonMob(NPC_GUARDIAN);
                    m_uiGuardiansTimer = 5000;
                }
                else
                    m_uiGuardiansTimer -= uiDiff;
            }

            DoMeleeAttackIfReady();
        }
    }
Ejemplo n.º 4
0
    void UpdateAI(const uint32 uiDiff)
    {
        if (!m_creature->SelectHostileTarget() || !m_creature->getVictim())
            return;

        if (!m_pInstance || m_pInstance->GetData(TYPE_KELTHUZAD) != IN_PROGRESS)
            return;

        if (m_uiPhase == PHASE_INTRO)
        {
            if (m_uiIntroPackCount < 7)
            {
                if (m_uiSummonIntroTimer < uiDiff)
                {
                    if (!m_uiIntroPackCount)
                        DoScriptText(SAY_SUMMON_MINIONS, m_creature);

                    SummonIntroCreatures(m_uiIntroPackCount);
                    ++m_uiIntroPackCount;
                    m_uiSummonIntroTimer = 2000;
                }
                else
                    m_uiSummonIntroTimer -= uiDiff;
            }
            else
            {
                if (m_uiPhase1Timer < uiDiff)
                {
                    m_uiPhase = PHASE_NORMAL;
                    DespawnIntroCreatures();

                    m_creature->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE);
                    SetCombatMovement(true);
                    m_creature->GetMotionMaster()->MoveChase(m_creature->getVictim());

                    DoScriptText(EMOTE_PHASE2, m_creature);

                    switch(urand(0, 2))
                    {
                        case 0: DoScriptText(SAY_AGGRO1, m_creature); break;
                        case 1: DoScriptText(SAY_AGGRO2, m_creature); break;
                        case 2: DoScriptText(SAY_AGGRO3, m_creature); break;
                    };
                }
                else
                    m_uiPhase1Timer -= uiDiff;

                if (m_uiSoldierCount < MAX_SOLDIER_COUNT)
                {
                    if (m_uiSoldierTimer < uiDiff)
                    {
                        SummonMob(NPC_SOLDIER_FROZEN);
                        ++m_uiSoldierCount;
                        m_uiSoldierTimer = 3000;
                    }
                    else
                        m_uiSoldierTimer -= uiDiff;
                }

                if (m_uiAbominationCount < MAX_ABOMINATION_COUNT)
                {
                    if (m_uiAbominationTimer < uiDiff)
                    {
                        SummonMob(NPC_UNSTOPPABLE_ABOM);
                        ++m_uiAbominationCount;
                        m_uiAbominationTimer = 25000;
                    }
                    else
                        m_uiAbominationTimer -= uiDiff;
                }

                if (m_uiBansheeCount < MAX_BANSHEE_COUNT)
                {
                    if (m_uiBansheeTimer < uiDiff)
                    {
                        SummonMob(NPC_SOUL_WEAVER);
                        ++m_uiBansheeCount;
                        m_uiBansheeTimer = 25000;
                    }
                    else
                        m_uiBansheeTimer -= uiDiff;
                }
            }
        }
        else // normal or guardian phase
        {
            if (m_uiFrostBoltTimer < uiDiff)
            {
                if (DoCastSpellIfCan(m_creature->getVictim(), m_bIsRegularMode ? SPELL_FROST_BOLT : SPELL_FROST_BOLT_H) == CAST_OK)
                    m_uiFrostBoltTimer = urand(1000, 60000);
            }
            else
                m_uiFrostBoltTimer -= uiDiff;

            if (m_uiFrostBoltNovaTimer < uiDiff)
            {
                if (DoCastSpellIfCan(m_creature->getVictim(), m_bIsRegularMode ? SPELL_FROST_BOLT_NOVA : SPELL_FROST_BOLT_NOVA_H) == CAST_OK)
                    m_uiFrostBoltNovaTimer = 15000;
            }
            else
                m_uiFrostBoltNovaTimer -= uiDiff;

                        //Check for Mana Detonation
            if (m_uiManaDetonationTimer < uiDiff)
            {
                if (Unit* pTarget = m_creature->SelectAttackingTarget(ATTACKING_TARGET_RANDOM,1))
                    if (pTarget->getPowerType() == POWER_MANA)
                    {
                        int32 curPower = pTarget->GetPower(POWER_MANA);
                        if (curPower < (m_bIsRegularMode ? 4000 : 5500))
                            return;

                        m_creature->CastSpell(pTarget,SPELL_MANA_DETONATION, true);
                        int32 manareduction = m_bIsRegularMode ? urand(2500,4000) : urand(3500,5500);
                        int32 mana = curPower - manareduction;
                        pTarget->SetPower(POWER_MANA, mana);

                        Map *map = m_creature->GetMap();
                        if (map->IsDungeon())
                        {
                            Map::PlayerList const &PlayerList = map->GetPlayers();

                            if (!PlayerList.isEmpty())

                                for (Map::PlayerList::const_iterator i = PlayerList.begin(); i != PlayerList.end(); ++i)
                                {
                                    if (i->getSource()->isAlive() && pTarget->GetDistance2d(i->getSource()->GetPositionX(), i->getSource()->GetPositionY()) < 15)
                                        i->getSource()->DealDamage(i->getSource(), manareduction, NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, true);
                                }
                        }
                    }

                if (rand()%2)
                    DoScriptText(SAY_SPECIAL1_MANA_DET, m_creature);

                m_uiManaDetonationTimer = 15000;
            }else m_uiManaDetonationTimer -= uiDiff;

            if (m_uiShadowFissureTimer < uiDiff)
            {
                if (Unit* pTarget = m_creature->SelectAttackingTarget(ATTACKING_TARGET_RANDOM, 0))
                {
                        m_creature->CastSpell(pTarget,SPELL_SHADOW_FISSURE,true);
                        m_uiShadowFissureActiveTimer = 3000;
                        if (urand(0, 1))
                            DoScriptText(SAY_SPECIAL3_MANA_DET, m_creature);
                }
                m_uiShadowFissureTimer = 25000;
            }
            else
                m_uiShadowFissureTimer -= uiDiff;

            if(m_uiShadowFissureActiveTimer)
                if(m_uiShadowFissureActiveTimer < uiDiff)
                {
                    // hack for shadow fissure
                    // TODO: find energy beam visual spell
                    m_uiShadowFissureActiveTimer = 0;

                    Creature* pFissure = GetClosestCreatureWithEntry(m_creature, NPC_SHADOW_FISSURE, 100.0f);

                    if(!pFissure)
                        return;

                    Map::PlayerList const& pPlayers = m_creature->GetMap()->GetPlayers();
                    for (Map::PlayerList::const_iterator itr = pPlayers.begin(); itr != pPlayers.end(); ++itr)
                        if(itr->getSource()->GetDistance2d(pFissure) < 2.0f)
                            pFissure->DealDamage(itr->getSource(),itr->getSource()->GetHealth(),NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
                }
                else 
                    m_uiShadowFissureActiveTimer -= uiDiff;

            if (m_uiFrostBlastTimer < uiDiff)
            {
                if (DoCastSpellIfCan(m_creature->getVictim(), SPELL_FROST_BLAST) == CAST_OK)
                {
                    if (urand(0, 1))
                        DoScriptText(SAY_FROST_BLAST, m_creature);

                    m_uiFrostBlastTimer = urand(30000, 60000);
                }
            }
            else
                m_uiFrostBlastTimer -= uiDiff;

            // not sure if this is right
            //if (!m_bIsRegularMode)
            //{
                if (m_uiChainsTimer < uiDiff)
                {
                    if (DoCastSpellIfCan(m_creature->getVictim(), SPELL_CHAINS_OF_KELTHUZAD) == CAST_OK)
                    {
                        DoScriptText(urand(0, 1) ? SAY_CHAIN1 : SAY_CHAIN2, m_creature);

                        m_uiChainsTimer = urand(30000, 60000);
                    }
                }
                else
                    m_uiChainsTimer -= uiDiff;
            //}

            if (m_uiPhase == PHASE_NORMAL)
            {
                if (m_creature->GetHealthPercent() < 45.0f)
                {
                    m_uiPhase = PHASE_GUARDIANS;
                    DoScriptText(SAY_REQUEST_AID, m_creature);

                    // here Lich King should respond to Kel'Thuzad but I don't know which creature to make talk
                    // so for now just make Kel'Thuzad says it.
                    DoScriptText(SAY_ANSWER_REQUEST, m_creature);
                }
            }
            else if (m_uiPhase == PHASE_GUARDIANS && m_uiGuardiansCount < m_uiGuardiansCountMax)
            {
                if (m_uiGuardiansTimer < uiDiff)
                {
                    // Summon a Guardian of Icecrown in a random alcove
                    SummonMob(NPC_GUARDIAN);
                    m_uiGuardiansTimer = 5000;
                }
                else
                    m_uiGuardiansTimer -= uiDiff;
            }

            DoMeleeAttackIfReady();
        }
    }