IF
	See(NearestEnemyOf(Myself))
	Global("Prep","LOCALS",0)
THEN
	RESPONSE #100
                DisplayStringHead(Myself,@80)
		ApplySpell(Myself,WIZARD_STONE_SKIN)
		ApplySpell(Myself,WIZARD_SPELL_TRAP)
                ApplySpellRES("SPPR730",Myself)
                ApplySpell(Myself,WIZARD_SPELL_SHIELD)
                ApplySpell(Myself,WIZARD_TENSERS_TRANSFORMATION)
		SetGlobal("Prep","LOCALS",1)
END

IF
        HPPercentGT(Myself,10)
        HPPercentLT(Myself,30)
        !GlobalTimerNotExpired("HEAL_1","LOCALS")
        GlobalLT("HEAL1_INCRE","LOCALS",5)
THEN
	RESPONSE #100
		DisplayStringHead(Myself,46150)
                IncrementGlobal("HEAL1_INCRE","LOCALS",1)
                SetGlobalTimer("HEAL_1","LOCALS",6)
                CreateItem("POTN55",1,0,0)
                UseItem("POTN55",Myself)
END

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

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

IF
        See(NearestEnemyOf(Myself))
        !CheckStat(Myself, 1, WIZARD_SPELL_TRAP)
        GlobalLT("PROTECT3","LOCALS",4)
THEN
	RESPONSE #100
                IncrementGlobal("PROTECT3","LOCALS",1)
                ApplySpell(Myself,WIZARD_SPELL_TRAP)
END

IF
        See(NearestEnemyOf(Myself))
        !CheckStat(Myself,1,WIZARD_SPELL_SHIELD)
        GlobalLT("PROTECT4","LOCALS",4)
THEN
	RESPONSE #100
                IncrementGlobal("PROTECT4","LOCALS",1)
                ApplySpell(Myself,WIZARD_SPELL_SHIELD)
END

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

IF
        See(NearestEnemyOf(Myself))
        !GlobalTimerNotExpired("FIRESHIELD","LOCALS")
THEN
	RESPONSE #100
                SetGlobalTimer("FIRESHIELD","LOCALS",60)
                SpellRES("SPPR730",Myself)
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
        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
        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))
        CheckStatLT(LastSeenBy(Myself), 30, RESISTMAGIC)
        CheckStatGT(LastSeenBy(Myself), 10, SAVEVSDEATH)
        GlobalLT("WWB","LOCALS",3)
	!InMyGroup(LastSeenBy(Myself))
        !Allegiance(LastSeenBy(Myself),EVILCUTOFF)
THEN
	RESPONSE #100
                IncrementGlobal("WWB","LOCALS",1)
                ForceSpell(LastSeenBy(Myself),WIZARD_WAIL_OF_THE_BANSHEE)
END

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

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

IF
	See(NearestEnemyOf(Myself))
        !CheckStat(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
	!GlobalTimerNotExpired("Improved_Haste","LOCALS")
THEN
	RESPONSE #100
		SetGlobalTimer("Improved_Haste","LOCALS",24)
                ApplySpellRES("SPWI613",Myself)
		Continue()
END

IF
	See(NearestEnemyOf(Myself))
        !CheckStat(NearestEnemyOf(Myself),4,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
THEN
	RESPONSE #100
                AttackReevaluate(NearestEnemyOf(Myself),30)
END

IF
	See(NearestEnemyOf(Myself))
        ActionListEmpty()
THEN
	RESPONSE #100
                AttackReevaluate(NearestEnemyOf(Myself),30)
END

IF
	!InActiveArea(Myself)
        OR(14)
          Global("Prep","LOCALS",1)
          GlobalGT("PROTECT1","LOCALS",0)
          GlobalGT("PROTECT2","LOCALS",0)
          GlobalGT("PROTECT3","LOCALS",0)
          GlobalGT("PROTECT4","LOCALS",0)
          GlobalGT("PROTECT5","LOCALS",0)
          GlobalGT("HEAL1_INCRE","LOCALS",0)
          GlobalGT("WTR","LOCALS",0)
          GlobalGT("PENE","LOCALS",0)
          GlobalGT("WGM","LOCALS",0)
          GlobalGT("WLR","LOCALS",0)
          GlobalGT("WPS","LOCALS",0)
          GlobalGT("WPK","LOCALS",0)
          GlobalGT("WWB","LOCALS",0)
THEN
	RESPONSE #100
                SetGlobal("Prep","LOCALS",0)
                SetGlobal("PROTECT1","LOCALS",0)
                SetGlobal("PROTECT2","LOCALS",0)
                SetGlobal("PROTECT3","LOCALS",0)
                SetGlobal("PROTECT4","LOCALS",0)
                SetGlobal("PROTECT5","LOCALS",0)
                SetGlobal("HEAL1_INCRE","LOCALS",0)
          SetGlobal("WTR","LOCALS",0)
          SetGlobal("PENE","LOCALS",0)
          SetGlobal("WGM","LOCALS",0)
          SetGlobal("WLR","LOCALS",0)
          SetGlobal("WPS","LOCALS",0)
          SetGlobal("WPK","LOCALS",0)
          SetGlobal("WWB","LOCALS",0)
END