void UpdateAI(const uint32 diff)
            {
                if (isFlameBreathing)
                {
                    if (!me->IsNonMeleeSpellCasted(false))
                        isFlameBreathing = false;
                    else
                        return;
                }

                if (isBombing)
                {
                    if (BombSequenceTimer <= diff)
                        HandleBombSequence();
                    else
                        BombSequenceTimer -= diff;
                    return;
                }

                if (!UpdateVictim())
                    return;

                //enrage if under 25% hp before 5 min.
                if (!enraged && HealthBelowPct(25))
                    EnrageTimer = 0;

                if (EnrageTimer <= diff)
                {
                    if (!enraged)
                    {
                        DoCast(me, SPELL_ENRAGE, true);
                        enraged = true;
                        EnrageTimer = 300000;
                    }
                    else
                    {
                        DoScriptText(SAY_BERSERK, me);
                        DoCast(me, SPELL_BERSERK, true);
                        EnrageTimer = 300000;
                    }
                } else EnrageTimer -= diff;

                if (BombTimer <= diff)
                {
                    DoScriptText(SAY_FIRE_BOMBS, me);

                    me->AttackStop();
                    me->GetMotionMaster()->Clear();
                    DoTeleportTo(JanalainPos[0][0],JanalainPos[0][1],JanalainPos[0][2]);
                    me->StopMoving();
                    DoCast(me, SPELL_FIRE_BOMB_CHANNEL, false);
                    //DoTeleportPlayer(me, JanalainPos[0][0], JanalainPos[0][1],JanalainPos[0][2], 0);
                    //DoCast(me, SPELL_TELE_TO_CENTER, true);

                    FireWall();
                    SpawnBombs();
                    isBombing = true;
                    BombSequenceTimer = 100;

                    //Teleport every Player into the middle
                    Map* pMap = me->GetMap();
                    if (!pMap->IsDungeon()) return;
                    Map::PlayerList const &PlayerList = pMap->GetPlayers();
                    for (Map::PlayerList::const_iterator i = PlayerList.begin(); i != PlayerList.end(); ++i)
                        if (Player* i_pl = i->getSource())
                            if (i_pl->isAlive())
                                DoTeleportPlayer(i_pl, JanalainPos[0][0]-5+rand()%10, JanalainPos[0][1]-5+rand()%10, JanalainPos[0][2], 0);
                    //DoCast(Temp, SPELL_SUMMON_PLAYERS, true) // core bug, spell does not work if too far
                    return;
                } else BombTimer -= diff;

                if (!noeggs)
                {
                    if (HealthBelowPct(35))
                    {
                        DoScriptText(SAY_ALL_EGGS, me);

                        me->AttackStop();
                        me->GetMotionMaster()->Clear();
                        DoTeleportTo(JanalainPos[0][0],JanalainPos[0][1],JanalainPos[0][2]);
                        me->StopMoving();
                        DoCast(me, SPELL_HATCH_ALL, false);
                        HatchAllEggs(2);
                        noeggs = true;
                    }
                    else if (HatcherTimer <= diff)
                    {
                        if (HatchAllEggs(0))
                        {
                            DoScriptText(SAY_SUMMON_HATCHER, me);
                            me->SummonCreature(MOB_AMANI_HATCHER,hatcherway[0][0][0],hatcherway[0][0][1],hatcherway[0][0][2],0,TEMPSUMMON_CORPSE_TIMED_DESPAWN,10000);
                            me->SummonCreature(MOB_AMANI_HATCHER,hatcherway[1][0][0],hatcherway[1][0][1],hatcherway[1][0][2],0,TEMPSUMMON_CORPSE_TIMED_DESPAWN,10000);
                            HatcherTimer = 90000;
                        }
                        else
                            noeggs = true;
                    } else HatcherTimer -= diff;
                }

                EnterEvadeIfOutOfCombatArea(diff);

                DoMeleeAttackIfReady();

                if (FireBreathTimer <= diff)
                {
                    if (Unit *pTarget = SelectTarget(SELECT_TARGET_RANDOM,0))
                    {
                        me->AttackStop();
                        me->GetMotionMaster()->Clear();
                        DoCast(pTarget, SPELL_FLAME_BREATH, false);
                        me->StopMoving();
                        isFlameBreathing = true;
                    }
                    FireBreathTimer = 8000;
                } else FireBreathTimer -= diff;
            }
    void UpdateAI(const uint32 diff)
    {
        if(isFlameBreathing)
        {
            if(!m_creature->IsNonMeleeSpellCasted(false))
            {
                isFlameBreathing = false;
            }else 
            {
                if(EnrageTimer > diff)
                    EnrageTimer -= diff;
                else
                    EnrageTimer = 0;
                if(HatcherTimer > diff)
                    HatcherTimer -= diff;
                else
                    HatcherTimer = 0;
                return;
            }
        }

        if(isBombing)
        {
            if(BombSequenceTimer < diff)
            {
                HandleBombSequence();
            }else 
                BombSequenceTimer -= diff;
    
            if(EnrageTimer > diff)
                EnrageTimer -= diff;
            else
                EnrageTimer = 0;
            if(HatcherTimer > diff)
                HatcherTimer -= diff;
            else
                HatcherTimer = 0;
            return;
        }

        if(!UpdateVictim())
            return;

        if (checkTimer < diff)
        {
            if (!m_creature->IsWithinDistInMap(&wLoc, 25))
                EnterEvadeMode();
            else
                DoZoneInCombat();
            checkTimer = 3000;
        }
        else
            checkTimer -= diff;

        //enrage if under 25% hp before 5 min.
        if(!enraged && m_creature->GetHealth() * 4 < m_creature->GetMaxHealth())
            EnrageTimer = 0;

        if(EnrageTimer < diff)
        {
            if(!enraged)
            {
                m_creature->CastSpell(m_creature, SPELL_ENRAGE, true);
                enraged = true;
                EnrageTimer = 300000;
            }
            else
            {
                DoScriptText(SAY_BERSERK, m_creature);
                m_creature->CastSpell(m_creature, SPELL_BERSERK, true);
                EnrageTimer = 300000;
            }
        }else EnrageTimer -= diff;

        if(BombTimer < diff)
        {
            DoScriptText(SAY_FIRE_BOMBS, m_creature);

            m_creature->AttackStop();
            m_creature->GetMotionMaster()->Clear();
            DoTeleportTo(JanalainPos[0][0],JanalainPos[0][1],JanalainPos[0][2]);
            m_creature->StopMoving();
            m_creature->CastSpell(m_creature, SPELL_FIRE_BOMB_CHANNEL, false);
            //DoTeleportPlayer(m_creature, JanalainPos[0][0], JanalainPos[0][1],JanalainPos[0][2], 0);
            //m_creature->CastSpell(m_creature, SPELL_TELE_TO_CENTER, true);

            FireWall();
            SpawnBombs();
            isBombing = true;
            BombSequenceTimer = 100;

            //Teleport every Player into the middle
            Map *map = m_creature->GetMap();
            if(!map->IsDungeon()) return;
            Map::PlayerList const &PlayerList = map->GetPlayers();
            for(Map::PlayerList::const_iterator i = PlayerList.begin(); i != PlayerList.end(); ++i)
            {
                if (Player* i_pl = i->getSource())
                    if(i_pl->isAlive())
                        DoTeleportPlayer(i_pl, JanalainPos[0][0]-5+rand()%10, JanalainPos[0][1]-5+rand()%10, JanalainPos[0][2], 0);
            }
            //m_creature->CastSpell(Temp, SPELL_SUMMON_PLAYERS, true); // core bug, spell does not work if too far
            return;
        }else BombTimer -= diff;

        if(!noeggs)
        {
            if(100 * m_creature->GetHealth() < 35 * m_creature->GetMaxHealth())
            {
                DoScriptText(SAY_ALL_EGGS, m_creature);

                m_creature->AttackStop();
                m_creature->GetMotionMaster()->Clear();
                DoTeleportTo(JanalainPos[0][0],JanalainPos[0][1],JanalainPos[0][2]);
                m_creature->StopMoving();
                m_creature->CastSpell(m_creature, SPELL_HATCH_ALL, false);
                HatchAllEggs(2);
                noeggs = true;
            }
            else if(HatcherTimer < diff)
            {
                if(HatchAllEggs(0))
                {
                    DoScriptText(SAY_SUMMON_HATCHER, m_creature);
                    m_creature->SummonCreature(MOB_AMANI_HATCHER,hatcherway[0][0][0],hatcherway[0][0][1],hatcherway[0][0][2],0,TEMPSUMMON_CORPSE_TIMED_DESPAWN,10000);
                    m_creature->SummonCreature(MOB_AMANI_HATCHER,hatcherway[1][0][0],hatcherway[1][0][1],hatcherway[1][0][2],0,TEMPSUMMON_CORPSE_TIMED_DESPAWN,10000);
                    HatcherTimer = 90000;
                }
                else
                    noeggs = true;
            }else HatcherTimer -= diff;
        }

        if(ResetTimer < diff)
        {
            float x, y, z, o;
            m_creature->GetHomePosition(x, y, z, o);
            if(m_creature->GetPositionZ() <= z-7)
            {
                EnterEvadeMode();
                return;
            }
            ResetTimer = 5000;
        }else ResetTimer -= diff;

        DoMeleeAttackIfReady();

        if(FireBreathTimer < diff)
        {
            if(Unit* target = SelectUnit(SELECT_TARGET_RANDOM,0, GetSpellMaxRange(SPELL_FLAME_BREATH), true))
            {
                me->SetSelection(target->GetGUID());
                me->SetInFront(target);
                m_creature->CastSpell(target, SPELL_FLAME_BREATH, false);
                isFlameBreathing = true;
            }
            FireBreathTimer = 8000;
        }else FireBreathTimer -= diff;
    }
    void UpdateAI(const uint32 diff)
    {
        if(isFlameBreathing)
        {
            if(!m_creature->IsNonMeleeSpellCasted(false))
            {
                isFlameBreathing = false;
            }else return;
        }

        if(isBombing)
        {
            if(BombSequenceTimer < diff)
            {
                HandleBombSequence();
            }else BombSequenceTimer -= diff;
            return;
        }

        if(!m_creature->SelectHostileTarget() && !m_creature->getVictim())
            return;

        //enrage if under 25% hp before 5 min.
        if(!enraged && m_creature->GetHealth() * 4 < m_creature->GetMaxHealth())
            EnrageTimer = 0;

        if(EnrageTimer < diff)
        {
            if(!enraged)
            {
                m_creature->CastSpell(m_creature, SPELL_ENRAGE, true);
                enraged = true;
                EnrageTimer = 300000;
            }
            else
            {
                DoScriptText(SAY_BERSERK, m_creature);

                m_creature->CastSpell(m_creature, SPELL_BERSERK, true);
                EnrageTimer = 300000;
            }
        }else EnrageTimer -= diff;

        if(BombTimer < diff)
        {
            DoScriptText(SAY_FIRE_BOMBS, m_creature);

            m_creature->AttackStop();
            m_creature->GetMotionMaster()->Clear();
            m_creature->Relocate(JanalainPos[0][0],JanalainPos[0][1],JanalainPos[0][2],0);
            m_creature->GetMotionMaster()->MovePoint(0, JanalainPos[0][0], JanalainPos[0][1], JanalainPos[0][2]);
            m_creature->StopMoving();
            m_creature->CastSpell(m_creature, SPELL_FIRE_BOMB_CHANNEL, false);
            DoTeleportPlayer(m_creature, JanalainPos[0][0], JanalainPos[0][1],JanalainPos[0][2], 0);
            m_creature->CastSpell(m_creature, SPELL_TELE_TO_CENTER, true);

            FireWall();
            SpawnBombs();
            isBombing = true;
            BombSequenceTimer = 100;

            //Teleport every Player into the middle
            Map *map = m_creature->GetMap();
            if(!map->IsDungeon()) return;
            Map::PlayerList const &PlayerList = map->GetPlayers();
            if (!PlayerList.isEmpty())
                return;
            for(Map::PlayerList::const_iterator i = PlayerList.begin(); i != PlayerList.end(); ++i)
            {
				if(i->getSource()->isAlive())
					DoTeleportPlayer(i->getSource(), JanalainPos[0][0]-5+rand()%10, JanalainPos[0][1]-5+rand()%10, JanalainPos[0][2], 0);
            }
/*Test*/    m_creature->CastSpell(JanalainPos[0][0]-5+rand()%10, JanalainPos[0][1]-5+rand()%10, JanalainPos[0][2], SPELL_SUMMON_PLAYERS, true); // core bug, spell does not work if too far
            return;
        }else BombTimer -= diff;

        if (!noeggs)
        {
            if(100 * m_creature->GetHealth() < 35 * m_creature->GetMaxHealth())
            {
                m_creature->AttackStop();
                m_creature->GetMotionMaster()->Clear();
                m_creature->Relocate(JanalainPos[0][0],JanalainPos[0][1],JanalainPos[0][2],0);
                m_creature->GetMotionMaster()->MovePoint(0, JanalainPos[0][0], JanalainPos[0][1], JanalainPos[0][2]);
                m_creature->StopMoving();
                m_creature->CastSpell(m_creature, SPELL_HATCH_ALL, false);
                HatchAllEggs(2);
                noeggs = true;
            }
            else if(HatcherTimer < diff)
            {
                if(HatchAllEggs(0))
                {
                    DoScriptText(SAY_SUMMON_HATCHER, m_creature);

                    m_creature->SummonCreature(MOB_AMANI_HATCHER,hatcherway[0][0][0],hatcherway[0][0][1],hatcherway[0][0][2],0,TEMPSUMMON_CORPSE_TIMED_DESPAWN,10000);
                    m_creature->SummonCreature(MOB_AMANI_HATCHER,hatcherway[1][0][0],hatcherway[1][0][1],hatcherway[1][0][2],0,TEMPSUMMON_CORPSE_TIMED_DESPAWN,10000);
                    HatcherTimer = 90000;
                }
                else
                    noeggs = true;
            }else HatcherTimer -= diff;
        }

        if(ResetTimer < diff)
        {
            float x, y, z;
            m_creature->GetPosition(x, y, z);
            if(x < -70 || x > 0 || y > 1176 || y < 1121 || z < 18)
                EnterEvadeMode();
            ResetTimer = 5000;
        }else ResetTimer -= diff;

        DoMeleeAttackIfReady();

        if(FireBreathTimer < diff)
        {
            if (Unit* target = m_creature->SelectAttackingTarget(ATTACKING_TARGET_RANDOM, 0))
            {
                m_creature->AttackStop();
                m_creature->GetMotionMaster()->Clear();
                m_creature->CastSpell(target, SPELL_FLAME_BREATH, false);
                m_creature->StopMoving();
                isFlameBreathing = true;
            }
            FireBreathTimer = 8000;
        }else FireBreathTimer -= diff;
    }
            void UpdateAI(const uint32 diff)
            {
                if (!UpdateVictim())
                    return;

                EnterEvadeIfOutOfCombatArea(diff);
                
                if (me->HealthBelowPct(35) && !bEnraged)
                {
                    bEnraged = true;
                    Talk(SAY_35);
                    DoCast(me, SPELL_FRENZY, true);
                    events.CancelEvent(EVENT_SUMMON_HATCHERS);
                    DoCast(me, SPELL_HATCH_ALL);
                    return;
                }

                events.Update(diff);

                while (uint32 eventId = events.ExecuteEvent())
                {
                     switch (eventId)
                     {
                        case EVENT_FLAME_BREATH:
                            me->SetReactState(REACT_PASSIVE);
                            me->AttackStop();
                            if (Unit* pTarget = SelectTarget(SELECT_TARGET_RANDOM, 0, 0.0f, true))
                                DoCast(pTarget, SPELL_FLAME_BREATH);
                            events.ScheduleEvent(EVENT_CONTINUE, 3000);
                            events.ScheduleEvent(EVENT_FLAME_BREATH, 9000);
                            break;
                        case EVENT_CONTINUE:
                            me->SetReactState(REACT_AGGRESSIVE);
                            AttackStart(me->getVictim());
                            break;
                        case EVENT_SUMMON_HATCHERS:
                            Talk(SAY_HATCHER);
                            if (!summons.HasEntry(NPC_AMANISHI_HATCHER1))
                                me->SummonCreature(NPC_AMANISHI_HATCHER1, posHatchersWay[0][0], TEMPSUMMON_CORPSE_TIMED_DESPAWN, 10000);
                            if (!summons.HasEntry(NPC_AMANISHI_HATCHER2))
                                me->SummonCreature(NPC_AMANISHI_HATCHER2, posHatchersWay[1][0], TEMPSUMMON_CORPSE_TIMED_DESPAWN, 10000);
                            events.ScheduleEvent(EVENT_SUMMON_HATCHERS, 90000);
                            break;
                        case EVENT_SPAWN_BOMBS:
                            me->SetReactState(REACT_PASSIVE);
                            me->AttackStop();
                            bombsCount = 0;
                            Talk(SAY_FIRE_BOMB);
                            SpawnBombs();
                            events.ScheduleEvent(EVENT_SUMMON_BOMBS, 1000);
                            break;
                        case EVENT_SUMMON_BOMBS:
                            if (bombsCount < 40)
                            {
                                if (Creature* pBomb = Creature::GetCreature(*me, FireBombsGUID[bombsCount]))
                                    DoCast(pBomb, SPELL_FIRE_BOMB_THROW, true);
                                bombsCount++;
                                events.ScheduleEvent(EVENT_SUMMON_BOMBS, 100);
                            }
                            else
                                events.ScheduleEvent(EVENT_DETONATE_BOMBS, 2000);
                            break;
                        case EVENT_DETONATE_BOMBS:
                            for (uint8 i = 0; i < 40; ++i)
                                if (Creature* pBomb = Creature::GetCreature(*me, FireBombsGUID[i]))
                                {
                                    pBomb->RemoveAllAuras();
                                    pBomb->CastSpell(pBomb, SPELL_FIRE_BOMB_DAMAGE, true);
                                }
                            events.ScheduleEvent(EVENT_CONTINUE, 1000);
                            break;
                        case EVENT_TELEPORT:
                            me->SetReactState(REACT_PASSIVE);
                            me->AttackStop();
                            events.RescheduleEvent(EVENT_SUMMON_HATCHERS, events.GetNextEventTime(EVENT_SUMMON_HATCHERS) + 7000);
                            events.RescheduleEvent(EVENT_FLAME_BREATH, events.GetNextEventTime(EVENT_FLAME_BREATH) + 7000);
                            Firewall();
                            DoCast(me, SPELL_TELE_TO_CENTER, true);
                            events.ScheduleEvent(EVENT_SPAWN_BOMBS, 2000);
                            break;

                     }
                }

                DoMeleeAttackIfReady();
            }