IF
        Global("RU_STAGE_OVER","GLOBAL",1)
THEN
	RESPONSE #100
                ReallyForceSpellRES("ru_disap",Myself)
                Wait(2)
                DestroySelf()
END

IF
	Heard([ANYONE],201)
	InMyGroup([ANYONE])
        !GlobalTimerNotExpired("SongTimer","LOCALS")
THEN
	RESPONSE #10
                SetGlobalTimer("SongTimer","LOCALS",30)
                DisplayStringHead(Myself,@171)
                Shout(201)
                ReallyForceSpellRES("RU_MUMSH",Myself)
                ScreenShake([5.5],3)
	RESPONSE #10
                SetGlobalTimer("SongTimer","LOCALS",30)
                DisplayStringHead(Myself,@293)
                Shout(201)
                ReallyForceSpellRES("RU_MUMSH",Myself)
                ScreenShake([5.5],3)
	RESPONSE #10
                SetGlobalTimer("SongTimer","LOCALS",30)
                DisplayStringHead(Myself,@294)
                Shout(201)
                ReallyForceSpellRES("RU_MUMSH",Myself)
                ScreenShake([5.5],3)
	RESPONSE #70
                SetGlobalTimer("SongTimer","LOCALS",30)
                Shout(201)
                ReallyForceSpellRES("RU_MUMSH",Myself)
                ScreenShake([5.5],3)
END

IF
        See(NearestEnemyOf(Myself))
        Global("Prep1","LOCALS",0)
THEN
	RESPONSE #100
                SetGlobal("Prep1","LOCALS",1)
                DisplayString(Myself,@275)
                ApplySpell(Myself,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
                ApplySpell(Myself,WIZARD_PROTECTION_FROM_THE_ELEMENTS)
                ApplySpell(Myself,WIZARD_PROTECTION_FROM_ENERGY)
END

IF
        See(NearestEnemyOf(Myself))
        Global("Prep1","LOCALS",0)
THEN
	RESPONSE #100
                SetGlobal("Prep1","LOCALS",1)
                DisplayString(Myself,@278)
                ApplySpell(Myself,CLERIC_ARMOR_OF_FAITH)
                ApplySpell(Myself,CLERIC_ARMOR_OF_FAITH)
                ApplySpell(Myself,CLERIC_ARMOR_OF_FAITH)
END

IF
        See(NearestEnemyOf(Myself))
        HPPercentLT(Myself,50)
THEN
	RESPONSE #100
                SetGlobal("Prep1","LOCALS",1)
                DisplayString(Myself,@274)
                ApplySpell(Myself,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
END

IF
        GlobalLT("IMMUN","LOCALS",6)
        See(NearestEnemyOf(Myself))
        CheckStat(Myself,0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
        !GlobalTimerNotExpired("CastingDelay","LOCALS")
THEN
	RESPONSE #100
                SetGlobalTimer("CastingDelay","LOCALS",6)
                IncrementGlobal("IMMUN","LOCALS",1)
                ForceSpell(Myself,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
END

IF
        GlobalLT("IMMUN","LOCALS",6)
        See(NearestEnemyOf(Myself))
        CheckStat(Myself, 0, STONESKINS)
        !GlobalTimerNotExpired("CastingDelay","LOCALS")
THEN
	RESPONSE #100
                SetGlobalTimer("CastingDelay","LOCALS",6)
                IncrementGlobal("IMMUN","LOCALS",1)
                ForceSpell(Myself,WIZARD_STONE_SKIN)
END

IF
        GlobalLT("IMMUN","LOCALS",6)
        See(NearestEnemyOf(Myself))
        !GlobalTimerNotExpired("FIRESHIELD","LOCALS")
        !GlobalTimerNotExpired("CastingDelay","LOCALS")
THEN
	RESPONSE #100
                SetGlobalTimer("CastingDelay","LOCALS",6)
                IncrementGlobal("IMMUN","LOCALS",1)
                SetGlobalTimer("FIRESHIELD","LOCALS",120)
                ForceSpellRES("SPPR730",Myself)
                Continue()
END

IF
        See(NearestEnemyOf(Myself))
        GlobalLT("IMMUN","LOCALS",6)
        !StateCheck(Myself,STATE_BLESS)
        !GlobalTimerNotExpired("CastingDelay","LOCALS")
THEN
	RESPONSE #100
                SetGlobalTimer("CastingDelay","LOCALS",6)
                IncrementGlobal("IMMUN","LOCALS",1)
                ForceSpell(Myself,CLERIC_BLESS)
                Continue()
END

IF
        See(NearestEnemyOf(Myself))
        !StateCheck(Myself,STATE_CHANT)
        GlobalLT("IMMUN","LOCALS",6)
        !GlobalTimerNotExpired("CastingDelay","LOCALS")
THEN
	RESPONSE #100
                SetGlobalTimer("CastingDelay","LOCALS",6)
                IncrementGlobal("IMMUN","LOCALS",1)
                ForceSpell(Myself,CLERIC_CHANT)
                Continue()
END

IF
        See(NearestEnemyOf(Myself))
        !GlobalTimerNotExpired("DHarmony","LOCALS")
        !GlobalTimerNotExpired("CastingDelay","LOCALS")
THEN
	RESPONSE #100
                SetGlobalTimer("CastingDelay","LOCALS",6)
                IncrementGlobal("IMMUN","LOCALS",1)
                SetGlobalTimer("DHarmony","LOCALS",120)
                ForceSpell(Myself,CLERIC_DEFENSIVE_HARMONY)
                Continue()
END

IF
        See(NearestEnemyOf(Myself))
        !CheckStatGT(Myself,0,WIZARD_SPELL_SHIELD)
        GlobalLT("IMMUN","LOCALS",6)
        !GlobalTimerNotExpired("CastingDelay","LOCALS")
THEN
	RESPONSE #100
                SetGlobalTimer("CastingDelay","LOCALS",6)
                IncrementGlobal("IMMUN","LOCALS",1)
                ForceSpell(Myself,WIZARD_SPELL_SHIELD)
END

IF
	See(NearestEnemyOf(Myself))
THEN
	RESPONSE #100
		Continue()
END

IF
	NumCreatureGT([ENEMY],1)
	See(SecondNearestEnemyOf(Myself))
        RandomNum(2,1)
THEN
	RESPONSE #100
		Continue()
END

IF
	NumCreatureGT([ENEMY],2)
	See(ThirdNearestEnemyOf(Myself))
        RandomNum(2,1)
THEN
	RESPONSE #100
		Continue()
END

IF
	NumCreatureGT([ENEMY],3)
	See(FourthNearestEnemyOf(Myself))
        RandomNum(2,1)
THEN
	RESPONSE #100
		Continue()
END

IF
	NumCreatureGT([ENEMY],4)
	See(FifthNearestEnemyOf(Myself))
        RandomNum(2,1)
THEN
	RESPONSE #100
		Continue()
END

IF
	NumCreatureGT([ENEMY],5)
	See(SixthNearestEnemyOf(Myself))
        RandomNum(2,1)
THEN
	RESPONSE #100
		Continue()
END

IF
        GlobalLT("PIERC","LOCALS",4)
        OR(11)
          StateCheck(LastSeenBy(Myself), STATE_INVISIBLE)
          StateCheck(LastSeenBy(Myself), STATE_IMPROVEDINVISIBILITY)
          StateCheck(LastSeenBy(Myself), STATE_MIRRORIMAGE)
          StateCheck(LastSeenBy(Myself), STATE_HASTED)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_MAGIC_ENERGY)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_MISLEAD)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_TENSERS_TRANSFORMATION)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_ENERGY)
          CheckStatGT(LastSeenBy(Myself),0,STONESKINS)
          CheckStatGT(LastSeenBy(Myself),0,IMPROVEDHASTE)
        !GlobalTimerNotExpired("CastingDelay","LOCALS")
THEN
	RESPONSE #25
                IncrementGlobal("PIERC","LOCALS",1)
                SetGlobalTimer("CastingDelay","LOCALS",6)
                ForceSpell(LastSeenBy(Myself),WIZARD_WARDING_WHIP)
                Continue()
	RESPONSE #25
                IncrementGlobal("PIERC","LOCALS",1)
                SetGlobalTimer("CastingDelay","LOCALS",6)
                ForceSpell(LastSeenBy(Myself),WIZARD_BREACH)
                Continue()
	RESPONSE #25
                IncrementGlobal("PIERC","LOCALS",1)
                SetGlobalTimer("CastingDelay","LOCALS",6)
                ForceSpell(LastSeenBy(Myself),WIZARD_SECRET_WORD)
                Continue()
	RESPONSE #25
                IncrementGlobal("PIERC","LOCALS",1)
                SetGlobalTimer("CastingDelay","LOCALS",6)
                ForceSpell(LastSeenBy(Myself),WIZARD_DISPEL_MAGIC)
                Continue()
END

IF
        OR(2)
          StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
          StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
        Global("TrueSight","LOCALS",0)
        !GlobalTimerNotExpired("CastingDelay","LOCALS")
THEN
	RESPONSE #100
                SetGlobalTimer("CastingDelay","LOCALS",6)
                SetGlobal("TrueSight","LOCALS",1)
                ForceSpell(Myself,WIZARD_TRUE_SIGHT)
END

IF
        GlobalLT("PIERC","LOCALS",4)
        CheckStatGT(LastSeenBy(Myself), 30, RESISTMAGIC)
        !GlobalTimerNotExpired("CastingDelay","LOCALS")
        RandomNum(2,1)
THEN
	RESPONSE #100
                SetGlobalTimer("CastingDelay","LOCALS",6)
                IncrementGlobal("PIERC","LOCALS",1)
                ForceSpell(LastSeenBy(Myself),WIZARD_LOWER_RESISTANCE)
END

IF
        GlobalLT("PIERC","LOCALS",4)
        CheckStatLT(LastSeenBy(Myself), 10, SAVEVSDEATH)
        !GlobalTimerNotExpired("CastingDelay","LOCALS")
        RandomNum(2,2)
THEN
	RESPONSE #100
                SetGlobalTimer("CastingDelay","LOCALS",6)
                IncrementGlobal("PIERC","LOCALS",1)
                ForceSpell(LastSeenBy(Myself),WIZARD_GREATER_MALISON)
END

IF
        Range(NearestEnemyOf(Myself),3)
        Global("IMPRISONMENT","LOCALS",0)
        !GlobalTimerNotExpired("CastingDelay","LOCALS")
THEN
	RESPONSE #100
                SetGlobalTimer("CastingDelay","LOCALS",6)
                SetGlobal("IMPRISONMENT","LOCALS",1)
                ForceSpell(NearestEnemyOf(Myself),WIZARD_IMPRISONMENT)
END

IF
        GlobalLT("ATTACK","LOCALS",10)
        HPLT(LastSeenBy(Myself), 90)
        CheckStatLT(LastSeenBy(Myself), 50, RESISTMAGIC)
	!StateCheck(LastSeenBy(Myself),STATE_STUNNED)
        !GlobalTimerNotExpired("CastingDelay","LOCALS")
        !InMyGroup(LastSeenBy(Myself))
THEN
	RESPONSE #100
                IncrementGlobal("ATTACK","LOCALS",1)
                SetGlobalTimer("CastingDelay","LOCALS",6)
                ForceSpell(LastSeenBy(Myself),WIZARD_POWER_WORD_STUN)
END

IF
        GlobalLT("ATTACK","LOCALS",10)
        RandomNum(10,1)
        CheckStatLT(LastSeenBy(Myself), 100, MAGICDAMAGERESISTANCE)
        CheckStatLT(LastSeenBy(Myself), 100, RESISTMAGIC)
        !GlobalTimerNotExpired("CastingDelay","LOCALS")
        !InMyGroup(LastSeenBy(Myself))
THEN
	RESPONSE #100
                IncrementGlobal("ATTACK","LOCALS",1)
                SetGlobalTimer("CastingDelay","LOCALS",6)
                ForceSpell(LastSeenBy(Myself),WIZARD_ABI_DALZIMS_HORRID_WILTING)
END
IF
        GlobalLT("ATTACK","LOCALS",10)
        RandomNum(10,2)
        OR(2)
         CheckStatLT(LastSeenBy(Myself), 100, RESISTFIRE)
         CheckStatLT(LastSeenBy(Myself), 100, RESISTCOLD)
        CheckStatLT(LastSeenBy(Myself), 100, RESISTMAGIC)
        !GlobalTimerNotExpired("CastingDelay","LOCALS")
        !InMyGroup(LastSeenBy(Myself))
THEN
	RESPONSE #100
                IncrementGlobal("ATTACK","LOCALS",1)
                SetGlobalTimer("CastingDelay","LOCALS",6)
                ForceSpell(LastSeenBy(Myself),CLERIC_STORM_OF_VENGEANCE)
END

IF
        GlobalLT("ATTACK","LOCALS",10)
        RandomNum(10,3)
        CheckStatLT(LastSeenBy(Myself), 100, RESISTMAGIC)
        !GlobalTimerNotExpired("CastingDelay","LOCALS")
        !InMyGroup(LastSeenBy(Myself))
THEN
	RESPONSE #100
                IncrementGlobal("ATTACK","LOCALS",1)
                SetGlobalTimer("CastingDelay","LOCALS",6)
                ForceSpell(LastSeenBy(Myself),CLERIC_EARTHQUAKE)
END
IF
        GlobalLT("ATTACK","LOCALS",10)
        RandomNum(10,4)
        CheckStatLT(LastSeenBy(Myself), 100, RESISTMAGIC)
        !GlobalTimerNotExpired("CastingDelay","LOCALS")
        !InMyGroup(LastSeenBy(Myself))
THEN
	RESPONSE #100
                IncrementGlobal("ATTACK","LOCALS",1)
                SetGlobalTimer("CastingDelay","LOCALS",6)
                ForceSpell(LastSeenBy(Myself),CLERIC_FINGER_OF_DEATH)
END

IF
        GlobalLT("ATTACK","LOCALS",10)
        RandomNum(10,5)
        CheckStatLT(LastSeenBy(Myself), 100, RESISTPIERCING)
        !GlobalTimerNotExpired("CastingDelay","LOCALS")
        !InMyGroup(LastSeenBy(Myself))
THEN
	RESPONSE #100
                IncrementGlobal("ATTACK","LOCALS",1)
                SetGlobalTimer("CastingDelay","LOCALS",6)
                ForceSpell(LastSeenBy(Myself),CLERIC_INSECT_PLAGUE)
END

IF
        GlobalLT("ATTACK","LOCALS",10)
        RandomNum(10,6)
        CheckStatLT(LastSeenBy(Myself), 100, RESISTMAGIC)
        CheckStatLT(LastSeenBy(Myself), 100, RESISTELECTRICITY)
        !GlobalTimerNotExpired("CastingDelay","LOCALS")
        !InMyGroup(LastSeenBy(Myself))
THEN
	RESPONSE #100
                IncrementGlobal("ATTACK","LOCALS",1)
                SetGlobalTimer("CastingDelay","LOCALS",6)
                ForceSpell(LastSeenBy(Myself),CLERIC_BOLT_OF_GLORY)
END
IF
        GlobalLT("ATTACK","LOCALS",10)
        RandomNum(10,7)
        CheckStatLT(LastSeenBy(Myself), 100, RESISTMAGIC)
        CheckStatLT(LastSeenBy(Myself), 100, RESISTELECTRICITY)
        !GlobalTimerNotExpired("CastingDelay","LOCALS")
        !InMyGroup(LastSeenBy(Myself))
THEN
	RESPONSE #100
                IncrementGlobal("ATTACK","LOCALS",1)
                SetGlobalTimer("CastingDelay","LOCALS",6)
                ForceSpell(LastSeenBy(Myself),WIZARD_CHAIN_LIGHTNING)
END

IF
        GlobalLT("ATTACK","LOCALS",10)
        RandomNum(10,8)
        CheckStatLT(LastSeenBy(Myself), 100, RESISTMAGIC)
        CheckStatLT(LastSeenBy(Myself), 100, RESISTCOLD)
        !GlobalTimerNotExpired("CastingDelay","LOCALS")
        !InMyGroup(LastSeenBy(Myself))
THEN
	RESPONSE #100
                IncrementGlobal("ATTACK","LOCALS",1)
                SetGlobalTimer("CastingDelay","LOCALS",6)
                ForceSpell(LastSeenBy(Myself),WIZARD_ICE_STORM)
END

IF
        GlobalLT("ATTACK","LOCALS",10)
        RandomNum(10,9)
        CheckStatLT(LastSeenBy(Myself), 100, RESISTMAGIC)
        CheckStatLT(LastSeenBy(Myself), 100, MAGICDAMAGERESISTANCE)
        !GlobalTimerNotExpired("CastingDelay","LOCALS")
        !InMyGroup(LastSeenBy(Myself))
THEN
	RESPONSE #100
                IncrementGlobal("ATTACK","LOCALS",1)
                SetGlobalTimer("CastingDelay","LOCALS",6)
                ForceSpell(LastSeenBy(Myself),WIZARD_SKULL_TRAP)
END

IF
        GlobalLT("ATTACK","LOCALS",10)
        RandomNum(10,10)
        OR(2)
         CheckStatLT(LastSeenBy(Myself), 100, RESISTFIRE)
         CheckStatLT(LastSeenBy(Myself), 100, RESISTCRUSHING)
        CheckStatLT(LastSeenBy(Myself), 100, RESISTMAGIC)
        !GlobalTimerNotExpired("CastingDelay","LOCALS")
        !InMyGroup(LastSeenBy(Myself))
THEN
	RESPONSE #100
                IncrementGlobal("ATTACK","LOCALS",1)
                SetGlobalTimer("CastingDelay","LOCALS",6)
                ForceSpell(LastSeenBy(Myself),WIZARD_COMET)
END
IF
	See(NearestEnemyOf(Myself))
        Global("MAZE","LOCALS",0)
        !GlobalTimerNotExpired("CastingDelay","LOCALS")
THEN
	RESPONSE #100
                SetGlobalTimer("CastingDelay","LOCALS",6)
                SetGlobal("MAZE","LOCALS",1)
                ForceSpell(NearestEnemyOf(Myself),WIZARD_MAZE)
END

IF
	See(NearestEnemyOf(Myself))
        Global("SUMMON","LOCALS",0)
        !GlobalTimerNotExpired("CastingDelay","LOCALS")
THEN
	RESPONSE #25
                SetGlobalTimer("CastingDelay","LOCALS",6)
                SetGlobal("SUMMON","LOCALS",1)
                ForceSpellRES("ru_cmdsa",Myself)
	RESPONSE #25
                SetGlobalTimer("CastingDelay","LOCALS",6)
                SetGlobal("SUMMON","LOCALS",1)
                ForceSpellRES("ru_chaca",Myself)
	RESPONSE #25
                SetGlobalTimer("CastingDelay","LOCALS",6)
                SetGlobal("SUMMON","LOCALS",1)
                ForceSpellRES("SPWI807",Myself)
	RESPONSE #25
                SetGlobalTimer("CastingDelay","LOCALS",6)
                SetGlobal("SUMMON","LOCALS",1)
                ForceSpellRES("ru_cnisa",Myself)
END

IF
        CombatCounter(0)
        OR(3)
          Global("MAZE","LOCALS",1)
          Global("IMPRISONMENT","LOCALS",1)
          Global("SUMMON","LOCALS",1)
THEN
	RESPONSE #100
                SetGlobal("MAZE","LOCALS",0)
                SetGlobal("IMPRISONMENT","LOCALS",0)
                SetGlobal("SUMMON","LOCALS",0)
END