void Update(uint32 diff)
			{
				if (RescueTimer && RescueTimer < 100*MINUTE*IN_MILLISECONDS)
				{
					RescueTimer -= std::min(RescueTimer, diff);

					if ((RescueTimer / IN_MILLISECONDS) == 25*MINUTE)
					{
						DoRemoveAurasDueToSpellOnPlayers(SPELL_KARGATHS_EXECUTIONER_1);
						DoCastSpellOnPlayers(SPELL_KARGATHS_EXECUTIONER_2);
						if (Creature* prisoner = instance->GetCreature(prisonerGUID[0]))
							Unit::Kill(prisoner, prisoner);
						if (Creature* executioner = instance->GetCreature(executionerGUID))
							executioner->RemoveLootMode(2);
					}
					else if ((RescueTimer / IN_MILLISECONDS) == 15*MINUTE)
					{
						DoRemoveAurasDueToSpellOnPlayers(SPELL_KARGATHS_EXECUTIONER_2);
						DoCastSpellOnPlayers(SPELL_KARGATHS_EXECUTIONER_3);
						if (Creature* prisoner = instance->GetCreature(prisonerGUID[1]))
							Unit::Kill(prisoner, prisoner);
					}
					else if ((RescueTimer / IN_MILLISECONDS) == 0)
					{
						DoRemoveAurasDueToSpellOnPlayers(SPELL_KARGATHS_EXECUTIONER_3);
						if (Creature* prisoner = instance->GetCreature(prisonerGUID[2]))
							Unit::Kill(prisoner, prisoner);
					}
				}
			}
 void SetData(uint32 type, uint32 data) override
 {
     if (type == DATA_EGG_EVENT)
     {
         switch (data)
         {
             case IN_PROGRESS:
                 _events.ScheduleEvent(EVENT_RAZOR_SPAWN, 45 * IN_MILLISECONDS);
                 EggEvent = data;
                 EggCount = 0;
                 break;
             case NOT_STARTED:
                 _events.CancelEvent(EVENT_RAZOR_SPAWN);
                 EggEvent = data;
                 EggCount = 0;
                 break;
             case SPECIAL:
                 if (++EggCount == 15)
                 {
                     if (Creature* razor = GetCreature(DATA_RAZORGORE_THE_UNTAMED))
                     {
                         SetData(DATA_EGG_EVENT, DONE);
                         razor->RemoveAurasDueToSpell(42013); // MindControl
                         DoRemoveAurasDueToSpellOnPlayers(42013);
                     }
                     _events.ScheduleEvent(EVENT_RAZOR_PHASE_TWO, 1 * IN_MILLISECONDS);
                     _events.CancelEvent(EVENT_RAZOR_SPAWN);
                 }
                 if (EggEvent == NOT_STARTED)
                     SetData(DATA_EGG_EVENT, IN_PROGRESS);
                 break;
         }
     }
 }
		void SetData(uint32 type, uint32 data)
		{
			switch(type)
			{
				case BOSS_SARTHARION_EVENT:
				case BOSS_TENEBRON_EVENT:
				case BOSS_SHADRON_EVENT:
				case BOSS_VESPERON_EVENT:
					Encounters[type] = data;
					break;
				case DATA_ADD_PORTAL:
					if (!m_uiPortalGUID)
					{
						if (Creature* cr = instance->GetCreature(m_uiSartharionGUID))
							if (GameObject* go = cr->SummonGameObject(GO_TWILIGHT_PORTAL, 3247.29f, 529.804f, 58.9595f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0))
							{
								cr->RemoveGameObject(go, false);
								m_uiPortalGUID = go->GetGUID();
							}

						portalCount = 0;
					}

					portalCount++;
					break;
				case DATA_CLEAR_PORTAL:
					portalCount--;
					if (!portalCount || data == 2)
					{
						if (GameObject* go = instance->GetGameObject(m_uiPortalGUID))
							go->Delete();

						DoRemoveAurasDueToSpellOnPlayers(SPELL_TWILIGHT_SHIFT);
						m_uiPortalGUID = 0;
					}
					break;
			}

			if (data == DONE)
				SaveToDB();
		}
    bool SetBossState(uint32 id, EncounterState state)
    {
        if (loading)
            return InstanceScript::SetBossState(id, state);

        if (id == DATA_FACTION_CHAMPIONS && state == DONE)
            instance->GetCreature(uiTirionGuid)->SummonGameObject(GO_CACHE,563.800964f, 140.557205f, 393.957205f, 4.700161f, 0, 0, 0, 0, 0);

        if (id == DATA_LORD_JARAXXUS && (state == DONE || state == FAIL) && !misstressOfPain.empty())
        {
            uint8 count = 0;
            for (std::vector<uint64>::const_iterator itr = misstressOfPain.begin(); itr != misstressOfPain.end(); ++itr)
            {
                Creature* c = instance->GetCreature(*itr);
                if (!c)
                    continue;

                if (c->isAlive())
                    ++count;
            }

            if (state == DONE)
                DoCompleteAchievement(instance->GetSpawnMode() == 0 || instance->GetSpawnMode() == 2 ? 3996 : 3997);

            misstressOfPain.clear();
        }

        if (id == DATA_TWIN_VALKYR && (state == DONE || state == FAIL))
        {
            DoRemoveAurasDueToSpellOnPlayers(65686);
            DoRemoveAurasDueToSpellOnPlayers(65684);
            DoRemoveAurasDueToSpellOnPlayers(67604);
        }

        if (id == DATA_BEASTS && state == DONE)
        {
            uint8 count = 0;
            if (uiSnoboldGuid_1)
            {
                if (Creature* c = instance->GetCreature(uiSnoboldGuid_1))
                    if (c->isAlive())
                        ++count;
            }
            if (uiSnoboldGuid_2)
            {
                if (Creature* c = instance->GetCreature(uiSnoboldGuid_2))
                    if (c->isAlive())
                        ++count;
            }
            if (uiSnoboldGuid_3)
            {
                if (Creature* c = instance->GetCreature(uiSnoboldGuid_3))
                    if (c->isAlive())
                        ++count;
            }
            if (uiSnoboldGuid_4)
            {
                if (Creature* c = instance->GetCreature(uiSnoboldGuid_4))
                    if (c->isAlive())
                        ++count;
            }

            if (count >= 2)
            {
                //Upper Back Pain
                uint32 achi = 0;
                if (instance->GetSpawnMode() == 0 || instance->GetSpawnMode() == 2) //10 man normal/hero
                    achi = 3797;
                else if (instance->GetSpawnMode() == 1 || instance->GetSpawnMode() == 3) //25 man normal/hero
                    achi = 3813;

                if (achi)
                    DoCompleteAchievement(achi);
            }
        }

        if (id == DATA_ANUBARAK && state == DONE)
        {
            if (instance->GetSpawnMode() == 2) //10 man
            {
                if (attempts >= 25)
                    DoCompleteAchievement(3808); //A Tribute to Skill
                if (attempts >= 45)
                    DoCompleteAchievement(3809); //A Tribute to Mad Skill
                if (attempts >= 50)
                    DoCompleteAchievement(3810); //A Tribute to Insanity
            }

            if (instance->GetSpawnMode() == 3) //25 man
            {
                if (attempts >= 25)
                    DoCompleteAchievement(3817); //A Tribute to Skill
                if (attempts >= 45)
                    DoCompleteAchievement(3818); //A Tribute to Mad Skill
                if (attempts >= 50)
                {
                    DoCompleteAchievement(3819); //A Tribute to Insanity

                    if (deathsCount == 0)
                    {
                        //A Tribute to Immortality
                        AchievementEntry const* horde = GetAchievementStore()->LookupEntry(4079);
                        AchievementEntry const* ally = GetAchievementStore()->LookupEntry(4156);
                        Map::PlayerList const &PlayerList = instance->GetPlayers();

                        if (!horde || !ally)
                        {
                            if (!horde) sLog->outError("TSCR: DoCompleteAchievement called for not existing achievement %u", horde);
                            if (!ally) sLog->outError("TSCR: DoCompleteAchievement called for not existing achievement %u", ally);
                            return InstanceScript::SetBossState(id, state);
                        }

                        if (!PlayerList.isEmpty())
                            for (Map::PlayerList::const_iterator i = PlayerList.begin(); i != PlayerList.end(); ++i)
                                if (Player *pPlayer = i->getSource())
                                    if (pPlayer->GetTeam() == HORDE)
                                        pPlayer->CompletedAchievement(horde);
                                    else if (pPlayer->GetTeam() == ALLIANCE)
                                        pPlayer->CompletedAchievement(ally);
                    }

                    //A Tribute to Dedicated Insanity
                    bool ok = true;

                    Map::PlayerList const& list = instance->GetPlayers();
                    if (!list.isEmpty())
                    {
                        for (Map::PlayerList::const_iterator itr = list.begin(); itr != list.end(); ++itr)
                        {
                            Player* plr = itr->getSource();
                            if (!plr)
                                continue;

                            for (uint8 i = EQUIPMENT_SLOT_START; i < INVENTORY_SLOT_ITEM_END; ++i)
                            {
                                if (Item *pItem = plr->GetItemByPos(INVENTORY_SLOT_BAG_0, i))
                                {
                                    if (ItemPrototype const* proto = sObjectMgr->GetItemPrototype(pItem->GetEntry()))
                                    {
                                        uint32 lvl = proto->ItemLevel;
                                        uint32 id = proto->ItemId;
                                        //ids are 272 cloacks obtained from 25-man hero Tribute Chest
                                        if (lvl>258 && id!=47545 && id!=47547 && id!=47546 && id!=47549 && id!=47554 && id!=47552 && id!=47548 && id!=47550 && id!=47553 && id!=47551)
                                        {
                                            ok = false;
                                            break;
                                        }
                                    }
                                }
                            }//end for (eq slots)
                        }//end for (players in map)
                    }//end if (not empty)
                    else
                        ok = false;

                    if (ok)
                        DoCompleteAchievement(4080);

                }//end if (50 attempts)
            }//end if (25man)


            if (instance->GetSpawnMode() == 2) //10man hero
            {
                if (attempts >= 25 && attempts < 45)
                    instance->GetCreature(uiTirionGuid)->SummonGameObject(195665, 686.117249f, 149.060455f, 142.147736f, 6.164101f, 0, 0, 0, 0, 0);
                else if (attempts >= 45 && attempts < 50)
                    instance->GetCreature(uiTirionGuid)->SummonGameObject(195666, 686.117249f, 149.060455f, 142.147736f, 6.164101f, 0, 0, 0, 0, 0);
                else if (attempts >= 50)
                    instance->GetCreature(uiTirionGuid)->SummonGameObject(195667, 686.117249f, 149.060455f, 142.147736f, 6.164101f, 0, 0, 0, 0, 0);
                else
                    instance->GetCreature(uiTirionGuid)->SummonGameObject(195668, 686.117249f, 149.060455f, 142.147736f, 6.164101f, 0, 0, 0, 0, 0);
            }

            if (instance->GetSpawnMode() == 3) //25man hero
            {
                if (attempts >= 25 && attempts < 45)
                    instance->GetCreature(uiTirionGuid)->SummonGameObject(195669, 686.117249f, 149.060455f, 142.147736f, 6.164101f, 0, 0, 0, 0, 0);
                else if (attempts >= 45 && attempts < 50)
                    instance->GetCreature(uiTirionGuid)->SummonGameObject(195670, 686.117249f, 149.060455f, 142.147736f, 6.164101f, 0, 0, 0, 0, 0);
                else if (attempts >= 50)
                    instance->GetCreature(uiTirionGuid)->SummonGameObject(195671, 686.117249f, 149.060455f, 142.147736f, 6.164101f, 0, 0, 0, 0, 0);
                else
                    instance->GetCreature(uiTirionGuid)->SummonGameObject(195672, 686.117249f, 149.060455f, 142.147736f, 6.164101f, 0, 0, 0, 0, 0);
            }

        }//end if (DONE ANUBARAK)

        return InstanceScript::SetBossState(id, state);
    }