void OnApply(constAuraEffectPtr aurEff, AuraEffectHandleModes /*mode*/)
 {
     AuraPtr aura = aurEff->GetBase();
     uint32 duration = urand(3000, 45000);
     aura->SetDuration(duration);
     aura->SetMaxDuration(duration);
 }
		void UpdateAI(uint32 const diff)
		{
			events.Update(diff);

			if (!UpdateVictim())
				return;

			if (phase1_timer)
			{
				if (phase1 <= diff)
				{
					phase1_timer = false;
					phase2_timer = true;
					deadvanced = true;

					me->CastSpell(me, ADVANCE);

					if (me->HasAura(ADVANCE))
					{
						AuraPtr Advance = me->GetAura(ADVANCE);

						if (Advance)
						{
							Advance->SetDuration(10000000);
						}
					}

					me->MonsterSay("Power.. I must have more power.. Guards, Protect your empress!", LANG_UNIVERSAL, me->GetGUID());
					DoPlaySoundToSet(me, 29270);

					events.ScheduleEvent(EVENT_SUMMON_MOBS, 500);
					events.ScheduleEvent(EVENT_ADVANCE, 500);
				}
				else
					phase1 -= diff;
			}
			if (phase2_timer)
			{
				if (phase2 <= diff)
				{
					phase2_timer = false;

					if (deadvanced)
					{
						deadvanced = false;

						me->RemoveAura(ADVANCE);
						events.ScheduleEvent(EVENT_DEADVANCE, 500);
					}
				}
				else
					phase2 -= diff;
			}

			if (thirdphase)
			{
				if (Unit* victim = me->getVictim())
				{
					if (!me->IsWithinDistInMap(victim, 2.0f))
					{
						events.ScheduleEvent(EVENT_MOVE_FIX, 1000);
					}
				}
			}

			if (SayCharmed)
			{
				SayCharmed = false;

				me->MonsterYell("You are mine now!", LANG_UNIVERSAL, me->GetGUID());
				DoPlaySoundToSet(me, 29282);
			}
			// Introduction RP	

			while (uint32 eventId = events.ExecuteEvent())
			{
				switch (eventId)
				{
				case EVENT_SUMMON_MOBS:
					// side a
					me->SummonCreature(MOB_REAVER, -2453.20f, 989.60f, 569.630f, 3.498173f, TEMPSUMMON_MANUAL_DESPAWN);
					me->SummonCreature(MOB_WIND, -2448.70f, 992.45f, 569.630f, 3.407852f, TEMPSUMMON_MANUAL_DESPAWN);
					me->SummonCreature(MOB_WIND, -2445.68f, 989.26f, 569.630f, 3.407852f, TEMPSUMMON_MANUAL_DESPAWN);
					// side b
					me->SummonCreature(MOB_REAVER, -2504.68f, 987.24f, 569.630f, 0.295318f, TEMPSUMMON_MANUAL_DESPAWN);
					me->SummonCreature(MOB_WIND, -2508.52f, 981.49f, 569.630f, 0.295318f, TEMPSUMMON_MANUAL_DESPAWN);
					me->SummonCreature(MOB_WIND, -2510.62f, 992.30f, 569.630f, 0.295318f, TEMPSUMMON_MANUAL_DESPAWN);
					break;
				case EVENT_ADVANCE:
					me->SetDisplayId(11686); // invis

					if (MotionMaster* motion = me->GetMotionMaster())
						motion->MovePoint(1, -2476.62f, 1035.45f, 572.818f);

					me->SetReactState(REACT_PASSIVE);
					me->AddUnitState(UNIT_STATE_CANNOT_AUTOATTACK);

					me->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_PC);
					me->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_NPC);

					events.CancelEvent(EVENT_DEAD_SCREECH);
					events.CancelEvent(EVENT_CRY_TERROR);
					events.CancelEvent(EVENT_EYE_OF_THE_EMPRESS);
					events.CancelEvent(EVENT_DISSONANCE_SHIELD);

					me->DespawnCreaturesInArea(DISSONANCE_SHIELD_TRIGGER);
					me->SetSpeed(MOVE_RUN, 0.0f);
					break;
				case EVENT_DEADVANCE:
					me->SetDisplayId(42730); // originial dis

                    events.ScheduleEvent(EVENT_CRY_TERROR, 7500);
                    events.ScheduleEvent(EVENT_DEAD_SCREECH, 10000);
                    events.ScheduleEvent(EVENT_EYE_OF_THE_EMPRESS, 8000);
                    events.ScheduleEvent(EVENT_DISSONANCE_SHIELD, 30000);

					me->Attack(me->getVictim(), true);

					me->SetReactState(REACT_AGGRESSIVE);
					me->ClearUnitState(UNIT_STATE_CANNOT_AUTOATTACK);
					me->SetSpeed(MOVE_RUN, 1.13f);
					me->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_PC);
					me->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_NPC);
					break;
				case EVENT_CRY_TERROR:
					if (Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 0, 50, true))
					{
						me->AddAura(123788, target);
					}
					events.ScheduleEvent(EVENT_CRY_TERROR, 7500);
					break;
				case EVENT_DEAD_SCREECH:
					for (int i = 0; i <= 1; i++)
					{
						if (Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 0, 50, true))
						{
							me->CastSpell(target, DEAD_SCREECH_DMG);
						}
					}
					events.ScheduleEvent(EVENT_DEAD_SCREECH, 10000);
					break;
				case EVENT_EYE_OF_THE_EMPRESS:
					if (!me->getVictim()->HasAura(EYE_OF_THE_EMPRESS))
					{
						me->getVictim()->CastSpell(me->getVictim(), EYE_OF_THE_EMPRESS);
					}
					else
					{
						AuraPtr aura_B = me->getVictim()->GetAura(EYE_OF_THE_EMPRESS);

						if (aura_B && aura_B->GetStackAmount() <= 5)
						{
							aura_B->SetStackAmount(aura_B->GetStackAmount() + 1);
						}
					}
					events.ScheduleEvent(EVENT_EYE_OF_THE_EMPRESS, 6000);
					break;
				case EVENT_DISSONANCE_SHIELD:

					if (!me->FindNearestCreature(DISSONANCE_SHIELD_TRIGGER, 100.0f, true))
					{
						me->SummonCreature(DISSONANCE_SHIELD_TRIGGER, dis_1, TEMPSUMMON_MANUAL_DESPAWN, 0);
						me->SummonCreature(DISSONANCE_SHIELD_TRIGGER, dis_2, TEMPSUMMON_MANUAL_DESPAWN, 0);
					}

					events.ScheduleEvent(EVENT_DISSONANCE_SHIELD, 65000);
					break;
					// phase 3
				case EVENT_SHA_ENERGY:

					int count;

					if (Is25ManRaid())
						count = 4;
					else
						count = 1;

					for (int i = 0; i <= count; i++)
					{
						if (Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 0, 50, true))
						{
							me->CastSpell(target, SHA_ENERGY);
						}
					}
					events.ScheduleEvent(EVENT_SHA_ENERGY, 10000);
					break;
				case EVENT_AMASSING_DARKNESS:
					if (Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 0, 50, true))
					{
						if (!target->HasAura(AMASSING_DARKNESS_AURA))
						{
							me->CastSpell(target, AMASSING_DARKNESS);
							me->AddAura(AMASSING_DARKNESS_AURA, target);
						}

						UnitList targets;
						JadeCore::AnyUnitHavingBuffInObjectRangeCheck u_check(target, target, 100, AMASSING_DARKNESS_AURA, true);
						JadeCore::UnitListSearcher<JadeCore::AnyUnitHavingBuffInObjectRangeCheck> searcher(target, targets, u_check);
						target->VisitNearbyObject(100, searcher);

						for (UnitList::const_iterator it = targets.begin(); it != targets.end(); ++it)
						{
							if (!(*it))
								return;

							if ((*it)->GetGUID() != target->GetGUID())
							me->CastSpell((*it), AMASSING_DARKNESS);
						}

						if (Is25ManRaid())
							events.ScheduleEvent(EVENT_AMASSING_DARKNESS, 2500);
						else
							events.ScheduleEvent(EVENT_AMASSING_DARKNESS, 6500);
					}
					break;
				case EVENT_CONSUMING_TERROR:
					if (Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 0, 50, true))
					{
						// cancel first phase abilities
						events.CancelEvent(EVENT_SHA_ENERGY);
						events.CancelEvent(EVENT_AMASSING_DARKNESS);;
						events.CancelEvent(EVENT_VISIONS_OF_DEMISE);
						events.CancelEvent(EVENT_CALAMITY);

						// scehdule new abilities third phase
						events.ScheduleEvent(EVENT_SHA_ENERGY, 10000);
						events.ScheduleEvent(EVENT_AMASSING_DARKNESS, 10000);
						events.ScheduleEvent(EVENT_CONSUMING_TERROR, 40000);
						events.ScheduleEvent(EVENT_VISIONS_OF_DEMISE, urand(29000, 35000));
						events.ScheduleEvent(EVENT_CALAMITY, urand(15000, 20000));

						me->CastSpell(target, CONSUMING_TERROR);
						events.ScheduleEvent(EVENT_CONSUMING_TERROR, 40000);
					}
					break;
				case EVENT_CALAMITY:
					DoCastAOE(CALAMITY);
					events.ScheduleEvent(EVENT_CALAMITY, 20000);
					break;
				case EVENT_VISIONS_OF_DEMISE:
					for (int i = 0; i <= 1; i++)
					{
						if (Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 0, 50, true))
						{
							me->AddAura(124862, target);
						}
					}
					events.ScheduleEvent(EVENT_VISIONS_OF_DEMISE, urand(29000, 35000));
					break;
				case EVENT_MOVE_FIX:
					if (Unit* victim = me->getVictim())
					{
						if (!me->IsWithinDistInMap(victim, 2.0f))
						{
							if (MotionMaster* motion = me->GetMotionMaster())
							{
								motion->MovePoint(1, victim->GetPositionX(), victim->GetPositionY(), victim->GetPositionZ());
							}
							events.ScheduleEvent(EVENT_MOVE_FIX, 2000);
						}
					}
					break;
				}
			}
			DoMeleeAttackIfReady();
		}