IF
    OR(2)
		!GlobalTimerNotExpired("CAST","LOCALS")
        CheckStatGT(Myself,0,WIZARD_IMPROVED_ALACRITY)
    HaveSpell(WIZARD_LOWER_RESISTANCE)
    See(NearestEnemyOf(Myself))
    OR(3)
        CheckStatLT(LastSeenBy(Myself),75,RESISTMAGIC)
        StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
        CheckStat(LastSeenBy(Myself),1,SANCTUARY)
    See(SecondNearestEnemyOf(Myself))
    OR(3)
        CheckStatLT(LastSeenBy(Myself),75,RESISTMAGIC)
        StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
        CheckStat(LastSeenBy(Myself),1,SANCTUARY)
    See(ThirdNearestEnemyOf(Myself))
    OR(3)
        CheckStatLT(LastSeenBy(Myself),75,RESISTMAGIC)
        StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
        CheckStat(LastSeenBy(Myself),1,SANCTUARY)
    See(FourthNearestEnemyOf(Myself))
    OR(3)
        CheckStatLT(LastSeenBy(Myself),75,RESISTMAGIC)
        StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
        CheckStat(LastSeenBy(Myself),1,SANCTUARY)
    See(FifthNearestEnemyOf(Myself))
    OR(3)
        CheckStatLT(LastSeenBy(Myself),75,RESISTMAGIC)
        StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
        CheckStat(LastSeenBy(Myself),1,SANCTUARY)
    See(SixthNearestEnemyOf(Myself))
    OR(3)
        CheckStatLT(LastSeenBy(Myself),75,RESISTMAGIC)
        StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
        CheckStat(LastSeenBy(Myself),1,SANCTUARY)
    See(NearestEnemyOf(Myself))
    OR(3)
        CheckStatLT(LastSeenBy(Myself),50,RESISTMAGIC)
        StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
        CheckStat(LastSeenBy(Myself),1,SANCTUARY)
    See(SecondNearestEnemyOf(Myself))
    OR(3)
        CheckStatLT(LastSeenBy(Myself),50,RESISTMAGIC)
        StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
        CheckStat(LastSeenBy(Myself),1,SANCTUARY)
    See(ThirdNearestEnemyOf(Myself))
    OR(3)
        CheckStatLT(LastSeenBy(Myself),50,RESISTMAGIC)
        StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
        CheckStat(LastSeenBy(Myself),1,SANCTUARY)
    See(FourthNearestEnemyOf(Myself))
    OR(3)
        CheckStatLT(LastSeenBy(Myself),50,RESISTMAGIC)
        StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
        CheckStat(LastSeenBy(Myself),1,SANCTUARY)
    See(FifthNearestEnemyOf(Myself))
    OR(3)
        CheckStatLT(LastSeenBy(Myself),50,RESISTMAGIC)
        StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
        CheckStat(LastSeenBy(Myself),1,SANCTUARY)
    See(SixthNearestEnemyOf(Myself))
    OR(3)
        CheckStatLT(LastSeenBy(Myself),50,RESISTMAGIC)
        StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
        CheckStat(LastSeenBy(Myself),1,SANCTUARY)
    See(NearestEnemyOf(Myself))
    OR(3)
        CheckStatLT(LastSeenBy(Myself),25,RESISTMAGIC)
        StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
        CheckStat(LastSeenBy(Myself),1,SANCTUARY)
    See(SecondNearestEnemyOf(Myself))
    OR(3)
        CheckStatLT(LastSeenBy(Myself),25,RESISTMAGIC)
        StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
        CheckStat(LastSeenBy(Myself),1,SANCTUARY)
    See(ThirdNearestEnemyOf(Myself))
    OR(3)
        CheckStatLT(LastSeenBy(Myself),25,RESISTMAGIC)
        StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
        CheckStat(LastSeenBy(Myself),1,SANCTUARY)
    See(FourthNearestEnemyOf(Myself))
    OR(3)
        CheckStatLT(LastSeenBy(Myself),25,RESISTMAGIC)
        StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
        CheckStat(LastSeenBy(Myself),1,SANCTUARY)
    See(FifthNearestEnemyOf(Myself))
    OR(3)
        CheckStatLT(LastSeenBy(Myself),25,RESISTMAGIC)
        StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
        CheckStat(LastSeenBy(Myself),1,SANCTUARY)
    See(SixthNearestEnemyOf(Myself))
    OR(3)
        CheckStatLT(LastSeenBy(Myself),25,RESISTMAGIC)
        StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
        CheckStat(LastSeenBy(Myself),1,SANCTUARY)
    See(NearestEnemyOf(Myself))
    OR(3)
        CheckStatLT(LastSeenBy(Myself),15,RESISTMAGIC)
        StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
        CheckStat(LastSeenBy(Myself),1,SANCTUARY)
    See(SecondNearestEnemyOf(Myself))
    OR(3)
        CheckStatLT(LastSeenBy(Myself),15,RESISTMAGIC)
        StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
        CheckStat(LastSeenBy(Myself),1,SANCTUARY)
    See(ThirdNearestEnemyOf(Myself))
    OR(3)
        CheckStatLT(LastSeenBy(Myself),15,RESISTMAGIC)
        StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
        CheckStat(LastSeenBy(Myself),1,SANCTUARY)
    See(FourthNearestEnemyOf(Myself))
    OR(3)
        CheckStatLT(LastSeenBy(Myself),15,RESISTMAGIC)
        StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
        CheckStat(LastSeenBy(Myself),1,SANCTUARY)
    See(FifthNearestEnemyOf(Myself))
    OR(3)
        CheckStatLT(LastSeenBy(Myself),15,RESISTMAGIC)
        StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
        CheckStat(LastSeenBy(Myself),1,SANCTUARY)
    See(SixthNearestEnemyOf(Myself))
    OR(3)
        CheckStatLT(LastSeenBy(Myself),15,RESISTMAGIC)
        StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
        CheckStat(LastSeenBy(Myself),1,SANCTUARY)
	See(NearestEnemyOf(Myself))
	False()
THEN
	RESPONSE #100
		Continue()
END

IF
    OR(2)
		!GlobalTimerNotExpired("CAST","LOCALS")
        CheckStatGT(Myself,0,WIZARD_IMPROVED_ALACRITY)
    HaveSpell(WIZARD_LOWER_RESISTANCE)
    See(LastSeenBy(Myself))
	CheckStatGT(LastSeenBy(Myself),10,RESISTMAGIC)
    !StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
    CheckStat(LastSeenBy(Myself),0,SANCTUARY)
THEN
	RESPONSE #100
		SetGlobalTimer("CAST","LOCALS",6)
        Spell(LastSeenBy(Myself),WIZARD_LOWER_RESISTANCE)
END

