IF
	See(NearestEnemyOf(Myself))
	Global("Prep","LOCALS",0)
	!StateCheck(Myself,STATE_REALLY_DEAD)
THEN
	RESPONSE #100
		ApplySpell(Myself,WIZARD_STONE_SKIN) // SPWI408.SPL (Stoneskin)
		ApplySpell(Myself,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS) // SPWI611.SPL (Protection From Magical Weapons)
		ApplySpell(Myself,WIZARD_SPELL_TRAP) // SPWI902.SPL (Spell Trap)
		SetGlobal("Prep","LOCALS",1)
END

IF
	See(NearestEnemyOf(Myself))
	StateCheck(Myself,STATE_SILENCED)
	HaveSpell(WIZARD_VOCALIZE) // SPWI219.SPL (Vocalize)
THEN
	RESPONSE #100
		Spell(Myself,WIZARD_VOCALIZE) // SPWI219.SPL (Vocalize)
END

IF
	Allegiance(Myself,ENEMY)
	Detect([PC])
	!See(LastSeenBy(Myself))
	HaveSpell(WIZARD_TRUE_SIGHT) // SPWI609.SPL (True Sight)
THEN
	RESPONSE #100
		Spell(Myself,WIZARD_TRUE_SIGHT) // SPWI609.SPL (True Sight)
END

IF
	Allegiance(Myself,ENEMY)
	Detect([PC])
	!See(LastSeenBy(Myself))
	!HaveSpell(WIZARD_TRUE_SIGHT) // SPWI609.SPL (True Sight)
	Delay(10)
THEN
	RESPONSE #100
		ReallyForceSpell(Myself,WIZARD_TRUE_SIGHT) // SPWI609.SPL (True Sight)
END

IF
	!HasBounceEffects(Myself)
	!HasImmunityEffects(Myself)
	HaveSpell(WIZARD_SPELL_TURNING) // SPWI701.SPL (Spell Turning)
	Allegiance(Myself,ENEMY)
THEN
	RESPONSE #100
		Spell(Myself,WIZARD_SPELL_TURNING) // SPWI701.SPL (Spell Turning)
END

IF
	See(NearestEnemyOf(Myself))
	CheckStatLT(Myself,1,STONESKINS)
	TookDamage()
	See(SecondNearestEnemyOf(Myself))
	Global("Prep2","LOCALS",0)
	!StateCheck(Myself,STATE_REALLY_DEAD)
THEN
	RESPONSE #100
		DisplayString(Myself,40999)
		DisplayString(Myself,3302) // Chain Contingency—Spell Turning
		ApplySpell(NearestEnemyOf(Myself),WIZARD_SPELL_TURNING) // SPWI701.SPL (Spell Turning)
		DisplayString(Myself,40240) // Chain Contingency—Mislead
		ApplySpell(SecondNearestEnemyOf(Myself),WIZARD_MISLEAD) // SPWI607.SPL (Mislead)
		SetGlobal("Prep2","LOCALS",1)
END

IF
	See(NearestEnemyOf(Myself))
	CheckStatLT(Myself,1,STONESKINS)
	TookDamage()
	Global("Prep2","LOCALS",1)
	!StateCheck(Myself,STATE_REALLY_DEAD)
THEN
	RESPONSE #100
		DisplayString(Myself,41004)
		DisplayString(Myself,40252) // Contingency—Protection From Magical Weapons
		ApplySpell(Myself,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS) // SPWI611.SPL (Protection From Magical Weapons)
		SetGlobal("Prep2","LOCALS",2)
END

IF
	Allegiance(Myself,ENEMY)
	!HasBounceEffects(Myself)
	!HasImmunityEffects(Myself)
	HaveSpell(WIZARD_SPELL_TURNING) // SPWI701.SPL (Spell Turning)
THEN
	RESPONSE #100
		Spell(Myself,WIZARD_SPELL_TURNING) // SPWI701.SPL (Spell Turning)
END

IF
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_TIME_STOP) // SPWI909.SPL (Time Stop)
THEN
	RESPONSE #100
		Spell(Myself,WIZARD_TIME_STOP) // SPWI909.SPL (Time Stop)
END

IF
	See(NearestEnemyOf(Myself))
	Global("SpellTrigger","LOCALS",0)
	!StateCheck(Myself,STATE_REALLY_DEAD)
THEN
	RESPONSE #100
		DisplayString(Myself,39968) // Spell Trigger—Fired
		DisplayString(Myself,40248) // Spell Trigger—True Sight
		ReallyForceSpell(NearestEnemyOf(Myself),WIZARD_TRUE_SIGHT) // SPWI609.SPL (True Sight)
		DisplayString(Myself,40249) // Spell Trigger—Dispel Magic
		ReallyForceSpell(NearestEnemyOf(Myself),WIZARD_DISPEL_MAGIC) // SPWI302.SPL (Remove Magic)
		DisplayString(Myself,45727) // Spell Trigger—Death Spell
		ReallyForceSpell(NearestEnemyOf(Myself),WIZARD_DEATH_SPELL) // SPWI605.SPL (Death Spell)
		SetGlobal("SpellTrigger","LOCALS",1)
END

IF
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_NPC_SYMBOL_STUN) // SPWI898.SPL (Symbol, Stun)
THEN
	RESPONSE #100
		Spell(NearestEnemyOf(Myself),WIZARD_NPC_SYMBOL_STUN) // SPWI898.SPL (Symbol, Stun)
END

IF
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_NPC_SYMBOL_FEAR) // SPWI899.SPL (Symbol, Fear)
THEN
	RESPONSE #100
		Spell(NearestEnemyOf(Myself),WIZARD_NPC_SYMBOL_FEAR) // SPWI899.SPL (Symbol, Fear)
END

IF
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_NPC_SYMBOL_DEATH) // SPWI897.SPL (Symbol, Death)
THEN
	RESPONSE #100
		Spell(NearestEnemyOf(Myself),WIZARD_NPC_SYMBOL_DEATH) // SPWI897.SPL (Symbol, Death)
END

IF
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_SUN_FIRE) // SPWI523.SPL (Sunfire)
THEN
	RESPONSE #100
		Spell(Myself,WIZARD_SUN_FIRE) // SPWI523.SPL (Sunfire)
END

IF
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_WAIL_OF_THE_BANSHEE) // SPWI913.SPL (Wail of the Banshee)
THEN
	RESPONSE #100
		Spell(NearestEnemyOf(Myself),WIZARD_WAIL_OF_THE_BANSHEE) // SPWI913.SPL (Wail of the Banshee)
END

IF
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_SHADOW_DOOR) // SPWI505.SPL (Shadow Door)
THEN
	RESPONSE #100
		Spell(Myself,WIZARD_SHADOW_DOOR) // SPWI505.SPL (Shadow Door)
END

IF
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_ABI_DALZIMS_HORRID_WILTING) // SPWI812.SPL (Abi-Dalzim's Horrid Wilting)
THEN
	RESPONSE #100
		Spell(NearestEnemyOf(Myself),WIZARD_ABI_DALZIMS_HORRID_WILTING) // SPWI812.SPL (Abi-Dalzim's Horrid Wilting)
END

IF
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_FINGER_OF_DEATH) // SPWI713.SPL (Finger of Death)
THEN
	RESPONSE #100
		Spell(NearestEnemyOf(Myself),WIZARD_FINGER_OF_DEATH) // SPWI713.SPL (Finger of Death)
END

IF
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_SUMMON_EFREET) // SPWI717.SPL (Summon Efreeti)
THEN
	RESPONSE #100
		Spell(Myself,WIZARD_SUMMON_EFREET) // SPWI717.SPL (Summon Efreeti)
END

IF
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_FLESH_TO_STONE) // SPWI604.SPL (Flesh to Stone)
THEN
	RESPONSE #100
		Spell(NearestEnemyOf(Myself),WIZARD_FLESH_TO_STONE) // SPWI604.SPL (Flesh to Stone)
END

IF
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_DISINTEGRATE) // SPWI616.SPL (Disintegrate)
THEN
	RESPONSE #100
		Spell(NearestEnemyOf(Myself),WIZARD_DISINTEGRATE) // SPWI616.SPL (Disintegrate)
END

IF
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_DOMINATION) // SPWI506.SPL (Domination)
THEN
	RESPONSE #100
		Spell(NearestEnemyOf(Myself),WIZARD_DOMINATION) // SPWI506.SPL (Domination)
END

IF
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_FIRE_SHIELD_RED) // SPWI418.SPL (Fire Shield (Red))
THEN
	RESPONSE #100
		Spell(Myself,WIZARD_FIRE_SHIELD_RED) // SPWI418.SPL (Fire Shield (Red))
END

IF
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_SLOW) // SPWI312.SPL (Slow)
THEN
	RESPONSE #100
		Spell(NearestEnemyOf(Myself),WIZARD_SLOW) // SPWI312.SPL (Slow)
END

IF
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_FLAME_ARROW) // SPWI303.SPL (Flame Arrow)
THEN
	RESPONSE #100
		Spell(NearestEnemyOf(Myself),WIZARD_FLAME_ARROW) // SPWI303.SPL (Flame Arrow)
END

IF
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_MELF_ACID_ARROW) // SPWI211.SPL (Melf's Acid Arrow)
THEN
	RESPONSE #100
		Spell(NearestEnemyOf(Myself),WIZARD_MELF_ACID_ARROW) // SPWI211.SPL (Melf's Acid Arrow)
END

IF
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_LARLOCH_MINOR_DRAIN) // SPWI119.SPL (Larloch's Minor Drain)
THEN
	RESPONSE #100
		Spell(NearestEnemyOf(Myself),WIZARD_LARLOCH_MINOR_DRAIN) // SPWI119.SPL (Larloch's Minor Drain)
END

IF
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_POLYMORPH_OTHER) // SPWI415.SPL (Polymorph Other)
THEN
	RESPONSE #100
		Spell(NearestEnemyOf(Myself),WIZARD_POLYMORPH_OTHER) // SPWI415.SPL (Polymorph Other)
END

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


