IF
	See(NearestEnemyOf(Myself))
	Global("Prep","LOCALS",0)
THEN
	RESPONSE #100
                DisplayStringHead(Myself,@80)
                ApplySpell(Myself,WIZARD_PROTECTION_FROM_COLD)
		ApplySpell(Myself,WIZARD_STONE_SKIN)
		ApplySpell(Myself,WIZARD_SPELL_TRAP)
                ApplySpellRES("SPPR730",Myself)
                ApplySpell(Myself,WIZARD_SPELL_SHIELD)
		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)
                Continue()
END

IF
        HPPercentLT(Myself,11)
THEN
	RESPONSE #100
                DisplayStringHead(Myself,@157) // 본체로 돌아가는 건 오래간만이군. 자네들이 평민이 아니라는 건 인정해 주지.
                ReallyForceSpellRES("RU_MONIC",Myself)
END

IF
        See(NearestEnemyOf(Myself))
        GlobalLT("WPMW","LOCALS",5)
        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",5)
        !CheckStatGT(Myself, 0, STONESKINS)
THEN
	RESPONSE #100
                IncrementGlobal("WST","LOCALS",1)
                ForceSpell(Myself,WIZARD_STONE_SKIN)
END

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

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

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

IF
        See(NearestEnemyOf(Myself))
        GlobalLT("WFS","LOCALS",3)
        !GlobalTimerNotExpired("FIRESHIELD","LOCALS")
THEN
	RESPONSE #100
                IncrementGlobal("WFS","LOCALS",1)
                SetGlobalTimer("FIRESHIELD","LOCALS",60)
                ForceSpellRES("SPPR730",Myself)
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",20)
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)
        GlobalLT("WLR","LOCALS",4)
	!InMyGroup(LastSeenBy(Myself))
THEN
	RESPONSE #100
                IncrementGlobal("WLR","LOCALS",1)
                ReallyForceSpell(LastSeenBy(Myself),WIZARD_LOWER_RESISTANCE)
END

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

IF
	See([ENEMY])
        CheckStatLT(LastSeenBy(Myself), 30, RESISTMAGIC)
        CheckStatGT(LastSeenBy(Myself), 10, SAVEVSDEATH)
        GlobalLT("WWB","LOCALS",4)
	!InMyGroup(LastSeenBy(Myself))
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)
	!InMyGroup(LastSeenBy(Myself))
        GlobalLT("WPS","LOCALS",5)
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)
	!InMyGroup(LastSeenBy(Myself))
        GlobalLT("WPK","LOCALS",5)
THEN
	RESPONSE #100
                IncrementGlobal("WPK","LOCALS",1)
                ForceSpell(LastSeenBy(Myself),WIZARD_POWER_WORD_KILL)
END

IF
	See(NearestEnemyOf(Myself))
        !GlobalTimerNotExpired("ProtectionOfDeath","LOCALS")
THEN
	RESPONSE #100
                SetGlobalTimer("ProtectionOfDeath","LOCALS",30)
                ForceSpellRES("SPCL917",Myself)
END

IF
	See(NearestEnemyOf(Myself))
        !GlobalTimerNotExpired("GreaterEvasion","LOCALS")
THEN
	RESPONSE #100
                SetGlobalTimer("GreaterEvasion","LOCALS",30)
                ForceSpellRES("SPCL914",Myself)
END

IF
	GlobalLT("KaiUsed","LOCALS",5)
	Range(NearestEnemyOf(Myself),6)
        !CheckStat(NearestEnemyOf(Myself),4,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
	!GlobalTimerNotExpired("KaiAttack","LOCALS")
THEN
	RESPONSE #100
		SetGlobalTimer("KaiAttack","LOCALS",10)
		IncrementGlobal("KaiUsed","LOCALS",1)
		ReallyForceSpellRES("SPCL144",Myself)
		Continue()
END

IF
	See(NearestEnemyOf(Myself))
        !CheckStat(NearestEnemyOf(Myself),4,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
	!GlobalTimerNotExpired("Improved_Haste","LOCALS")
THEN
	RESPONSE #100
		SetGlobalTimer("Improved_Haste","LOCALS",24)
                ForceSpellRES("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
	!InActiveArea(Myself)
        OR(14)
          GlobalGT("Prep","LOCALS",0)
          GlobalGT("KaiUsed","LOCALS",0)
          GlobalGT("WWB","LOCALS",0)
          GlobalGT("WPK","LOCALS",0)
          GlobalGT("WPS","LOCALS",0)
          GlobalGT("WSS","LOCALS",0)
          GlobalGT("WFS","LOCALS",0)
          GlobalGT("DSS","LOCALS",0)
          GlobalGT("WPMW","LOCALS",0)
          GlobalGT("WGM","LOCALS",0)
          GlobalGT("WLR","LOCALS",0)
          GlobalGT("PENE","LOCALS",0)
          GlobalGT("WSPT","LOCALS",0)
          GlobalGT("WMI","LOCALS",0)
THEN
	RESPONSE #100
          SetGlobal("Prep","LOCALS",0)
          SetGlobal("KaiUsed","LOCALS",0)
          SetGlobal("WWB","LOCALS",0)
          SetGlobal("WPK","LOCALS",0)
          SetGlobal("WPS","LOCALS",0)
          SetGlobal("WSS","LOCALS",0)
          SetGlobal("WFS","LOCALS",0)
          SetGlobal("DSS","LOCALS",0)
          SetGlobal("WPMW","LOCALS",0)
          SetGlobal("WGM","LOCALS",0)
          SetGlobal("WLR","LOCALS",0)
          SetGlobal("PENE","LOCALS",0)
          SetGlobal("WSPT","LOCALS",0)
          SetGlobal("WMI","LOCALS",0)
END