IF
    OR(2)
		!GlobalTimerNotExpired("CAST","LOCALS")
        CheckStatGT(Myself,0,WIZARD_IMPROVED_ALACRITY)
	OR(2)
		HaveSpell(WIZARD_KHELBENS_WARDING_WHIP)
		HaveSpell(WIZARD_SECRET_WORD)
	RandomNumGT(8,1)
	OR(2)
		!See(NearestEnemyOfType([GOODCUTOFF.0.0.MAGE_ALL]))
		!CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_DEFLECTION,0)
	OR(2)
		!See(NearestEnemyOfType([GOODCUTOFF.0.0.MAGE_ALL]))
		!CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_TURNING,0)
	OR(2)
		!See(NearestEnemyOfType([GOODCUTOFF.0.0.MAGE_ALL]))
		!CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_SHIELD,0)
	OR(2)
		!See(NearestEnemyOfType([GOODCUTOFF.0.0.MAGE_ALL]))
		!CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_IMMUNITY,0)
	OR(2)
		!See(SecondNearestEnemyOfType([GOODCUTOFF.0.0.MAGE_ALL]))
		!CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_DEFLECTION,0)
	OR(2)
		!See(SecondNearestEnemyOfType([GOODCUTOFF.0.0.MAGE_ALL]))
		!CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_TURNING,0)
	OR(2)
		!See(SecondNearestEnemyOfType([GOODCUTOFF.0.0.MAGE_ALL]))
		!CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_SHIELD,0)
	OR(2)
		!See(SecondNearestEnemyOfType([GOODCUTOFF.0.0.MAGE_ALL]))
		!CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_IMMUNITY,0)
	OR(2)
		!See(ThirdNearestEnemyOfType([GOODCUTOFF.0.0.MAGE_ALL]))
		!CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_DEFLECTION,0)
	OR(2)
		!See(ThirdNearestEnemyOfType([GOODCUTOFF.0.0.MAGE_ALL]))
		!CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_TURNING,0)
	OR(2)
		!See(ThirdNearestEnemyOfType([GOODCUTOFF.0.0.MAGE_ALL]))
		!CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_SHIELD,0)
	OR(2)
		!See(ThirdNearestEnemyOfType([GOODCUTOFF.0.0.MAGE_ALL]))
		!CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_IMMUNITY,0)
	OR(2)
		!See(NearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_DEFLECTION,0)
	OR(2)
		!See(NearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_TURNING,0)
	OR(2)
		!See(NearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_SHIELD,0)
	OR(2)
		!See(NearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_IMMUNITY,0)
	OR(2)
		!See(SecondNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_DEFLECTION,0)
	OR(2)
		!See(SecondNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_TURNING,0)
	OR(2)
		!See(SecondNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_SHIELD,0)
	OR(2)
		!See(SecondNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_IMMUNITY,0)
	OR(2)
		!See(ThirdNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_DEFLECTION,0)
	OR(2)
		!See(ThirdNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_TURNING,0)
	OR(2)
		!See(ThirdNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_SHIELD,0)
	OR(2)
		!See(ThirdNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_IMMUNITY,0)
	OR(2)
		!See(FourthNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_DEFLECTION,0)
	OR(2)
		!See(FourthNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_TURNING,0)
	OR(2)
		!See(FourthNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_SHIELD,0)
	OR(2)
		!See(FourthNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_IMMUNITY,0)
	OR(2)
		!See(FifthNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_DEFLECTION,0)
	OR(2)
		!See(FifthNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_TURNING,0)
	OR(2)
		!See(FifthNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_SHIELD,0)
	OR(2)
		!See(FifthNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_IMMUNITY,0)
	OR(2)
		!See(SixthNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_DEFLECTION,0)
	OR(2)
		!See(SixthNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_TURNING,0)
	OR(2)
		!See(SixthNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_SHIELD,0)
	OR(2)
		!See(SixthNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_IMMUNITY,0)
	See(NearestEnemyOf(Myself))
	False()
THEN
	RESPONSE #100
		Continue()
END

IF
    OR(2)
		!GlobalTimerNotExpired("CAST","LOCALS")
        CheckStatGT(Myself,0,WIZARD_IMPROVED_ALACRITY)
	See(LastSeenBy(Myself))
	OR(4)
		CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_DEFLECTION,0)
		CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_TURNING,0)
		CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_SHIELD,0)
		CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_IMMUNITY,0)
	HaveSpell(WIZARD_KHELBENS_WARDING_WHIP)
	RandomNumGT(8,1)
THEN
	RESPONSE #100
		SetGlobalTimer("CAST","LOCALS",6)
		Spell(LastSeenBy(Myself),WIZARD_KHELBENS_WARDING_WHIP)
END

IF
    OR(2)
		!GlobalTimerNotExpired("CAST","LOCALS")
        CheckStatGT(Myself,0,WIZARD_IMPROVED_ALACRITY)
	See(LastSeenBy(Myself))
	OR(4)
		CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_DEFLECTION,0)
		CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_TURNING,0)
		CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_SHIELD,0)
		CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_IMMUNITY,0)
	HaveSpell(WIZARD_SECRET_WORD)
	RandomNumGT(8,1)
THEN
	RESPONSE #100
		SetGlobalTimer("CAST","LOCALS",6)
		Spell(LastSeenBy(Myself),WIZARD_SECRET_WORD)
END

IF
    OR(2)
		!GlobalTimerNotExpired("CAST","LOCALS")
        CheckStatGT(Myself,0,WIZARD_IMPROVED_ALACRITY)
	HaveSpell(WIZARD_SPELL_THRUST)
	RandomNumGT(8,1)
	OR(2)
		!See(NearestEnemyOfType([GOODCUTOFF.0.0.MAGE_ALL]))
		!CheckStat(LastSeenBy(Myself),1,WIZARD_SPELL_DEFLECTION,)
	OR(2)
		!See(NearestEnemyOfType([GOODCUTOFF.0.0.MAGE_ALL]))
		!CheckStat(LastSeenBy(Myself),1,WIZARD_SPELL_TURNING)
	OR(2)
		!See(NearestEnemyOfType([GOODCUTOFF.0.0.MAGE_ALL]))
		!CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_IMMUNITY,0)
	OR(2)
		!See(SecondNearestEnemyOfType([GOODCUTOFF.0.0.MAGE_ALL]))
		!CheckStat(LastSeenBy(Myself),1,WIZARD_SPELL_DEFLECTION,)
	OR(2)
		!See(SecondNearestEnemyOfType([GOODCUTOFF.0.0.MAGE_ALL]))
		!CheckStat(LastSeenBy(Myself),1,WIZARD_SPELL_TURNING)
	OR(2)
		!See(SecondNearestEnemyOfType([GOODCUTOFF.0.0.MAGE_ALL]))
		!CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_IMMUNITY,0)
	OR(2)
		!See(ThirdNearestEnemyOfType([GOODCUTOFF.0.0.MAGE_ALL]))
		!CheckStat(LastSeenBy(Myself),1,WIZARD_SPELL_DEFLECTION,)
	OR(2)
		!See(ThirdNearestEnemyOfType([GOODCUTOFF.0.0.MAGE_ALL]))
		!CheckStat(LastSeenBy(Myself),1,WIZARD_SPELL_TURNING)
	OR(2)
		!See(ThirdNearestEnemyOfType([GOODCUTOFF.0.0.MAGE_ALL]))
		!CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_IMMUNITY,0)
	OR(2)
		!See(NearestEnemyOf(Myself))
		!CheckStat(LastSeenBy(Myself),1,WIZARD_SPELL_DEFLECTION,)
	OR(2)
		!See(NearestEnemyOf(Myself))
		!CheckStat(LastSeenBy(Myself),1,WIZARD_SPELL_TURNING)
	OR(2)
		!See(NearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_IMMUNITY,0)
	OR(2)
		!See(SecondNearestEnemyOf(Myself))
		!CheckStat(LastSeenBy(Myself),1,WIZARD_SPELL_DEFLECTION,)
	OR(2)
		!See(SecondNearestEnemyOf(Myself))
		!CheckStat(LastSeenBy(Myself),1,WIZARD_SPELL_TURNING)
	OR(2)
		!See(SecondNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_IMMUNITY,0)
	OR(2)
		!See(ThirdNearestEnemyOf(Myself))
		!CheckStat(LastSeenBy(Myself),1,WIZARD_SPELL_DEFLECTION,)
	OR(2)
		!See(ThirdNearestEnemyOf(Myself))
		!CheckStat(LastSeenBy(Myself),1,WIZARD_SPELL_TURNING)
	OR(2)
		!See(ThirdNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_IMMUNITY,0)
	OR(2)
		!See(FourthNearestEnemyOf(Myself))
		!CheckStat(LastSeenBy(Myself),1,WIZARD_SPELL_DEFLECTION,)
	OR(2)
		!See(FourthNearestEnemyOf(Myself))
		!CheckStat(LastSeenBy(Myself),1,WIZARD_SPELL_TURNING)
	OR(2)
		!See(FourthNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_IMMUNITY,0)
	OR(2)
		!See(FifthNearestEnemyOf(Myself))
		!CheckStat(LastSeenBy(Myself),1,WIZARD_SPELL_DEFLECTION,)
	OR(2)
		!See(FifthNearestEnemyOf(Myself))
		!CheckStat(LastSeenBy(Myself),1,WIZARD_SPELL_TURNING)
	OR(2)
		!See(FifthNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_IMMUNITY,0)
	OR(2)
		!See(SixthNearestEnemyOf(Myself))
		!CheckStat(LastSeenBy(Myself),1,WIZARD_SPELL_DEFLECTION,)
	OR(2)
		!See(SixthNearestEnemyOf(Myself))
		!CheckStat(LastSeenBy(Myself),1,WIZARD_SPELL_TURNING)
	OR(2)
		!See(SixthNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_IMMUNITY,0)
	See(NearestEnemyOf(Myself))
	False()
THEN
	RESPONSE #100
		Continue()
END

IF
    OR(2)
		!GlobalTimerNotExpired("CAST","LOCALS")
        CheckStatGT(Myself,0,WIZARD_IMPROVED_ALACRITY)
	See(LastSeenBy(Myself))
	OR(4)
		CheckStat(LastSeenBy(Myself),1,WIZARD_SPELL_DEFLECTION)
		CheckStat(LastSeenBy(Myself),1,WIZARD_SPELL_TURNING)
		CheckStatGT(LastSeenBy(Myself),WIZARD_SPELL_IMMUNITY,0)
	HaveSpell(WIZARD_SPELL_THRUST)
	RandomNumGT(8,1)
THEN
	RESPONSE #100
		SetGlobalTimer("CAST","LOCALS",6)
		Spell(LastSeenBy(Myself),WIZARD_SPELL_THRUST)
END

IF
    OR(2)
		!GlobalTimerNotExpired("CAST","LOCALS")
        CheckStatGT(Myself,0,WIZARD_IMPROVED_ALACRITY)
	HaveSpell(WIZARD_BREACH)
	OR(2)
		!See(NearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),0,STONESKINS)
	OR(2)
		!See(NearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
	OR(2)
		!See(NearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_NORMAL_WEAPONS)
	OR(2)
		!See(NearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
	OR(2)
		!See(NearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_MAGIC_ENERGY)
	OR(2)
		!See(SecondNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),0,STONESKINS)
	OR(2)
		!See(SecondNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
	OR(2)
		!See(SecondNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_NORMAL_WEAPONS)
	OR(2)
		!See(SecondNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
	OR(2)
		!See(SecondNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_MAGIC_ENERGY)
	OR(2)
		!See(ThirdNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),0,STONESKINS)
	OR(2)
		!See(ThirdNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
	OR(2)
		!See(ThirdNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_NORMAL_WEAPONS)
	OR(2)
		!See(ThirdNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
	OR(2)
		!See(ThirdNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_MAGIC_ENERGY)
	OR(2)
		!See(FourthNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),0,STONESKINS)
	OR(2)
		!See(FourthNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
	OR(2)
		!See(FourthNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_NORMAL_WEAPONS)
	OR(2)
		!See(FourthNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
	OR(2)
		!See(FourthNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_MAGIC_ENERGY)
	OR(2)
		!See(FifthNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),0,STONESKINS)
	OR(2)
		!See(FifthNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
	OR(2)
		!See(FifthNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_NORMAL_WEAPONS)
	OR(2)
		!See(FifthNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
	OR(2)
		!See(FifthNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_MAGIC_ENERGY)
	OR(2)
		!See(SixthNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),0,STONESKINS)
	OR(2)
		!See(SixthNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
	OR(2)
		!See(SixthNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_NORMAL_WEAPONS)
	OR(2)
		!See(SixthNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
	OR(2)
		!See(SixthNearestEnemyOf(Myself))
		!CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_MAGIC_ENERGY)
	See(NearestEnemyOf(Myself))
	False()
THEN
	RESPONSE #100
		Continue()
END

IF
    OR(2)
		!GlobalTimerNotExpired("CAST","LOCALS")
        CheckStatGT(Myself,0,WIZARD_IMPROVED_ALACRITY)
	See(LastSeenBy(Myself))
	OR(9)
		CheckStatGT(LastSeenBy(Myself),0,STONESKINS)
		CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
		CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_NORMAL_WEAPONS)
		CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
		CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_MAGIC_ENERGY)
		CheckStatGT(LastSeenBy(Myself),0,WIZARD_RESIST_FEAR)
		CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_ENERGY)
		CheckStatGT(LastSeenBy(Myself),0,WIZARD_SCRIPTINGSTATE5)
		CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_THE_ELEMENTS)
	HaveSpell(WIZARD_BREACH)
THEN
	RESPONSE #100
		SetGlobalTimer("CAST","LOCALS",6)
		Spell(LastSeenBy(Myself),WIZARD_BREACH)
END
