IF
	See([ENEMY])
        !GlobalTimerNotExpired("EXTENSIVECONTINGENCY","LOCALS")
THEN
	RESPONSE #100
                SetGlobalTimer("EXTENSIVECONTINGENCY","LOCALS",60)
                DisplayStringHead(Myself,@80)
                ApplySpell(Myself,WIZARD_PROTECTION_FROM_COLD)
                ApplySpell(Myself,WIZARD_PROTECTION_FROM_FIRE)
                ApplySpell(Myself,WIZARD_SPIRIT_ARMOR)
                ApplySpell(Myself,WIZARD_SPELL_TRAP)
                ApplySpell(Myself,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
                Wait(6)
                Continue()
END

IF
        Allegiance(LastSeenBy(Myself),PC)
        OR(13)
          StateCheck(LastSeenBy(Myself), STATE_INVISIBLE)
          StateCheck(LastSeenBy(Myself), STATE_IMPROVEDINVISIBILITY)
          StateCheck(LastSeenBy(Myself), STATE_MIRRORIMAGE)
          StateCheck(LastSeenBy(Myself), STATE_HASTED)
	  HasBounceEffects(LastSeenBy(Myself))
	  HasImmunityEffects(LastSeenBy(Myself))
	  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)
        GlobalLT("PENE","LOCALS",10)
THEN
	RESPONSE #25
                IncrementGlobal("PENE","LOCALS",1)
                ForceSpell(LastSeenBy(Myself),WIZARD_WARDING_WHIP)
                Continue()
	RESPONSE #25
                IncrementGlobal("PENE","LOCALS",1)
                ForceSpell(LastSeenBy(Myself),WIZARD_BREACH)
                Continue()
	RESPONSE #25
                IncrementGlobal("PENE","LOCALS",1)
                ForceSpell(LastSeenBy(Myself),WIZARD_SECRET_WORD)
                Continue()
	RESPONSE #25
                IncrementGlobal("PENE","LOCALS",1)
                ForceSpell(LastSeenBy(Myself),WIZARD_DISPEL_MAGIC)
                Continue()
END

IF
        OR(2)
          StateCheck(NearestEnemyOf(Myself),STATE_INVISIBLE)
          StateCheck(NearestEnemyOf(Myself),STATE_IMPROVEDINVISIBILITY)
        GlobalLT("WTR","LOCALS",3)
THEN
	RESPONSE #100
                IncrementGlobal("WTR","LOCALS",1)
                ForceSpell(Myself,WIZARD_TRUE_SIGHT)
END

IF
        See([ENEMY])
        CheckStatGT(LastSeenBy(Myself), 0, RESISTMAGIC)
        !StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
        !StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
        GlobalLT("WLR","LOCALS",4)
	!InMyGroup(LastSeenBy(Myself))
        !Allegiance(LastSeenBy(Myself),EVILCUTOFF)
THEN
	RESPONSE #100
                IncrementGlobal("WLR","LOCALS",1)
                ForceSpell(LastSeenBy(Myself),WIZARD_LOWER_RESISTANCE)
END

IF
        See([ENEMY])
        CheckStatLT(LastSeenBy(Myself), 10, SAVEVSDEATH)
        !StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
        !StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
        GlobalLT("WGM","LOCALS",4)
	!InMyGroup(LastSeenBy(Myself))
        !Allegiance(LastSeenBy(Myself),EVILCUTOFF)
THEN
	RESPONSE #100
                IncrementGlobal("WGM","LOCALS",1)
                ForceSpell(LastSeenBy(Myself),WIZARD_GREATER_MALISON)
END

IF
        See(NearestEnemyOf(Myself))
        GlobalLT("WPMW","LOCALS",4)
        CheckStat(Myself,0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
THEN
	RESPONSE #100
                IncrementGlobal("WPMW","LOCALS",1)
                ForceSpell(Myself,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
END

IF
        See(NearestEnemyOf(Myself))
        GlobalLT("WST","LOCALS",4)
        !CheckStatGT(Myself, 0, STONESKINS)
THEN
	RESPONSE #100
                IncrementGlobal("WST","LOCALS",1)
                ForceSpell(Myself,WIZARD_STONE_SKIN)
END

IF
        See(NearestEnemyOf(Myself))
        GlobalLT("WMI","LOCALS",4)
	!StateCheck(Myself,STATE_MIRRORIMAGE)
THEN
	RESPONSE #100
                IncrementGlobal("WMI","LOCALS",1)
                ForceSpell(Myself,WIZARD_MIRROR_IMAGE)
END

IF
        See(NearestEnemyOf(Myself))
        GlobalLT("WSS","LOCALS",3)
        CheckStat(Myself,0,WIZARD_SPELL_SHIELD)
THEN
	RESPONSE #100
                IncrementGlobal("WSS","LOCALS",1)
                ForceSpell(Myself,WIZARD_SPELL_SHIELD)
END

IF
        See([ENEMY])
        !GlobalTimerNotExpired("MAZE","LOCALS")
        !HasBounceEffects(LastSeenBy(Myself))
        !HasImmunityEffects(LastSeenBy(Myself))
        GlobalLT("WM","LOCALS",3)
	!InMyGroup(LastSeenBy(Myself))
        !Allegiance(LastSeenBy(Myself),EVILCUTOFF)
THEN
	RESPONSE #100
                SetGlobalTimer("MAZE","LOCALS",6)
                IncrementGlobal("WM","LOCALS",1)
                ForceSpell(LastSeenBy(Myself),WIZARD_MAZE)
END

IF
        See([ENEMY])
        HPLT(LastSeenBy(Myself), 90)
        CheckStatLT(LastSeenBy(Myself), 100, RESISTMAGIC)
	!StateCheck(LastSeenBy(Myself),STATE_STUNNED)
        GlobalLT("PS","LOCALS",5)
	!InMyGroup(LastSeenBy(Myself))
        !Allegiance(LastSeenBy(Myself),EVILCUTOFF)
THEN
	RESPONSE #100
                IncrementGlobal("PS","LOCALS",1)
                ForceSpell(LastSeenBy(Myself),WIZARD_POWER_WORD_STUN)
END

IF
	See([ENEMY])
        CheckStatLT(LastSeenBy(Myself), 100, RESISTMAGIC)
        HPLT(LastSeenBy(Myself), 60)
        GlobalLT("PK","LOCALS",3)
	!InMyGroup(LastSeenBy(Myself))
        !Allegiance(LastSeenBy(Myself),EVILCUTOFF)
THEN
	RESPONSE #100
                IncrementGlobal("PK","LOCALS",1)
                ForceSpell(LastSeenBy(Myself),WIZARD_POWER_WORD_KILL)
END

IF
        See(NearestEnemyOf(Myself))
        CheckStatLT(LastSeenBy(Myself), 100, MAGICDAMAGERESISTANCE)
        CheckStatLT(LastSeenBy(Myself), 100, RESISTMAGIC)
        GlobalLT("ABI","LOCALS",5)
	!InMyGroup(LastSeenBy(Myself))
        !Allegiance(LastSeenBy(Myself),EVILCUTOFF)
THEN
	RESPONSE #100
                IncrementGlobal("ABI","LOCALS",1)
                ForceSpell(LastSeenBy(Myself),WIZARD_ABI_DALZIMS_HORRID_WILTING)
END

IF
        See(NearestEnemyOf(Myself))
        GlobalLT("SSPS","LOCALS",10)
        CheckStatLT(LastSeenBy(Myself), 100, RESISTFIRE)
	!InMyGroup(LastSeenBy(Myself))
        !Allegiance(LastSeenBy(Myself),EVILCUTOFF)
THEN
	RESPONSE #50
                IncrementGlobal("SSPS","LOCALS",1)
                ForceSpellRES("SPWI922",LastSeenBy(Myself))
                Continue()
	RESPONSE #50
                IncrementGlobal("SSPS","LOCALS",1)
                ForceSpellRES("SPWI925",NearestEnemyOf(Myself))
                Continue()
END

IF
        See(NearestEnemyOf(Myself))
        CheckStatLT(LastSeenBy(Myself), 80, RESISTMAGIC)
        CheckStatLT(LastSeenBy(Myself),80,RESISTELECTRICITY)
        GlobalLT("WCL","LOCALS",3)
        !Allegiance(LastSeenBy(Myself),EVILCUTOFF)
	!InMyGroup(LastSeenBy(Myself))
THEN
	RESPONSE #100
                IncrementGlobal("WCL","LOCALS",1)
                ForceSpell(LastSeenBy(Myself),WIZARD_CHAIN_LIGHTNING)
                Continue()
END

IF
	See(NearestEnemyOf(Myself))
        CheckStatLT(LastSeenBy(Myself), 30, RESISTMAGIC)
        CheckStatGT(LastSeenBy(Myself), 10, SAVEVSDEATH)
        GlobalLT("BANSHEE","LOCALS",3)
	!InMyGroup(LastSeenBy(Myself))
        !Allegiance(LastSeenBy(Myself),EVILCUTOFF)
THEN
	RESPONSE #100
                IncrementGlobal("BANSHEE","LOCALS",1)
                ForceSpell(LastSeenBy(Myself),WIZARD_WAIL_OF_THE_BANSHEE)
END

IF
        See(NearestEnemyOf(Myself))
        GlobalLT("WBBCH","LOCALS",4)
THEN
	RESPONSE #100
                IncrementGlobal("WBBCH","LOCALS",1)
                ForceSpellRES("SPWI918",NearestEnemyOf(Myself))
                Continue()
END

IF
	See(NearestEnemyOf(Myself))
        Global("SUMMON","LOCALS",0)
THEN
	RESPONSE #25
                SetGlobal("SUMMON","LOCALS",1)
                ForceSpellRES("SPWI719",Myself)
	RESPONSE #25
                SetGlobal("SUMMON","LOCALS",1)
                ForceSpellRES("SPWI716",Myself)
	RESPONSE #25
                SetGlobal("SUMMON","LOCALS",1)
                ForceSpellRES("SPWI718",Myself)
	RESPONSE #25
                SetGlobal("SUMMON","LOCALS",1)
                ForceSpellRES("SPWI601",Myself)
END

IF
	!InActiveArea(Myself)
        OR(18)
          GlobalGT("SUMMON","LOCALS",0)
          GlobalGT("TRIGGER","LOCALS",0)
          GlobalGT("WBBCH","LOCALS",0)
          GlobalGT("WCL","LOCALS",0)
          GlobalGT("BANSHEE","LOCALS",0)
          GlobalGT("SSPS","LOCALS",0)
          GlobalGT("ABI","LOCALS",0)
          GlobalGT("PK","LOCALS",0)
          GlobalGT("PS","LOCALS",0)
          GlobalGT("WM","LOCALS",0)
          GlobalGT("WSS","LOCALS",0)
          GlobalGT("WMI","LOCALS",0)
          GlobalGT("WST","LOCALS",0)
          GlobalGT("WPMW","LOCALS",0)
          GlobalGT("WGM","LOCALS",0)
          GlobalGT("WLR","LOCALS",0)
          GlobalGT("WTR","LOCALS",0)
          GlobalGT("PENE","LOCALS",0)
THEN
	RESPONSE #100
                SetGlobal("SUMMON","LOCALS",0)
                SetGlobal("TRIGGER","LOCALS",0)
                SetGlobal("WBBCH","LOCALS",0)
                SetGlobal("WCL","LOCALS",0)
                SetGlobal("BANSHEE","LOCALS",0)
                SetGlobal("SSPS","LOCALS",0)
                SetGlobal("ABI","LOCALS",0)
                SetGlobal("PK","LOCALS",0)
                SetGlobal("PS","LOCALS",0)
                SetGlobal("WM","LOCALS",0)
                SetGlobal("WSS","LOCALS",0)
                SetGlobal("WMI","LOCALS",0)
                SetGlobal("WST","LOCALS",0)
                SetGlobal("WPMW","LOCALS",0)
                SetGlobal("WGM","LOCALS",0)
                SetGlobal("WLR","LOCALS",0)
                SetGlobal("WTR","LOCALS",0)
                SetGlobal("PENE","LOCALS",0)
END