IF
	See(NearestEnemyOf(Myself))
	Global("Prep","LOCALS",0)
THEN
	RESPONSE #100
		ReallyForceSpell(Myself,WIZARD_STONE_SKIN)
		ReallyForceSpell(Myself,WIZARD_SPELL_TURNING)
		ReallyForceSpell(Myself,WIZARD_MELF_METEOR)
		SetGlobal("Prep","LOCALS",1)
END

IF
	See(NearestEnemyOf(Myself))
	OR(7)
		StateCheck(LastSeenBy(Myself),STATE_HASTED)
		StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
		StateCheck(LastSeenBy(Myself),STATE_BLESS)
		StateCheck(LastSeenBy(Myself),STATE_CHANT)
		StateCheck(LastSeenBy(Myself),STATE_MIRRORIMAGE)
		StateCheck(LastSeenBy(Myself),STATE_BLUR)
		StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
	Global("PrepDef","LOCALS",0)
	!StateCheck(Myself,STATE_REALLY_DEAD)
THEN
	RESPONSE #70
		ReallyForceSpell(LastSeenBy(Myself),WIZARD_DISPEL_MAGIC)
		SetGlobal("PrepDef","LOCALS",1)
	RESPONSE #30
		ReallyForceSpell(Myself,WIZARD_MIRROR_IMAGE)
		SetGlobal("PrepDef","LOCALS",1)
END

IF
	!GlobalTimerNotExpired("Cast","LOCALS")
	See(NearestEnemyOf(Myself))
	StateCheck(Myself,STATE_SILENCED)
	HaveSpell(WIZARD_VOCALIZE)
THEN
	RESPONSE #100
		SetGlobalTimer("Cast","LOCALS",6)
		Spell(Myself,WIZARD_VOCALIZE)
END

IF
	!GlobalTimerNotExpired("Cast","LOCALS")
	Allegiance(Myself,ENEMY)
	Detect([PC])
	!See(LastSeenBy(Myself))
	HaveSpell(WIZARD_TRUE_SIGHT)
THEN
	RESPONSE #100
		SetGlobalTimer("Cast","LOCALS",6)
		Spell(Myself,WIZARD_TRUE_SIGHT)
END

IF
	!GlobalTimerNotExpired("Cast","LOCALS")
	Allegiance(Myself,ENEMY)
	Detect([PC])
	!See(LastSeenBy(Myself))
	!HaveSpell(WIZARD_TRUE_SIGHT)
	Delay(10)
THEN
	RESPONSE #100
		SetGlobalTimer("Cast","LOCALS",6)
		ReallyForceSpell(Myself,WIZARD_TRUE_SIGHT)
END

IF
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_STONE_SKIN)
	CheckStatLT(Myself,1,STONESKINS)
	TookDamage()
	Global("Prep2","LOCALS",0)
	!StateCheck(Myself,STATE_REALLY_DEAD)
THEN
	RESPONSE #100
		DisplayString(Myself,40199) // Chain Contingency - Mirror Image
		ReallyForceSpell(Myself,WIZARD_MIRROR_IMAGE)
		DisplayString(Myself,3302) // Chain Contingency - Spell Turning
		ReallyForceSpell(Myself,WIZARD_SPELL_TURNING)
		DisplayString(Myself,40240) // Chain Contingency - Mislead
		ReallyForceSpell(Myself,WIZARD_MISLEAD)
		DisplayString(Myself,29736) // Contingency - Stoneskin
		ReallyForceSpell(Myself,WIZARD_STONE_SKIN)
		SetGlobal("Prep2","LOCALS",1)
END

IF
	!GlobalTimerNotExpired("Cast","LOCALS")
	Allegiance(Myself,ENEMY)
	!HasBounceEffects(Myself)
	HaveSpell(WIZARD_SPELL_TURNING)
THEN
	RESPONSE #100
		SetGlobalTimer("Cast","LOCALS",6)
		Spell(Myself,WIZARD_SPELL_TURNING)
END

IF
	!GlobalTimerNotExpired("Cast","LOCALS")
	See(NearestEnemyOf(Myself))
	RandomNumGT(6,3)
	HaveSpell(WIZARD_ABI_DALZIMS_HORRID_WILTING)
THEN
	RESPONSE #100
		SetGlobalTimer("Cast","LOCALS",6)
		Spell(NearestEnemyOf(Myself),WIZARD_ABI_DALZIMS_HORRID_WILTING)
END

IF
	!GlobalTimerNotExpired("Cast","LOCALS")
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_ABI_DALZIMS_HORRID_WILTING)
	!StateCheck(Myself,STATE_REALLY_DEAD)
	RandomNumGT(7,2)
THEN
	RESPONSE #100
		DisplayString(Myself,39968) // Spell Trigger - Fired
		DisplayString(Myself,40244) // Spell Trigger - Stoneskins
		ReallyForceSpell(Myself,WIZARD_STONE_SKIN)
		DisplayString(Myself,40245) // Spell Trigger - Globe of Invulnerability
		ReallyForceSpell(Myself,WIZARD_GLOBE_OF_INVULNERABILITY)
		DisplayString(Myself,40246) // Spell Trigger - Minor Spell Turning
		ReallyForceSpell(Myself,WIZARD_MINOR_SPELL_TURNING)
		SetGlobalTimer("Cast","LOCALS",6)
		Spell(NearestEnemyOf(Myself),WIZARD_ABI_DALZIMS_HORRID_WILTING)
END

IF
	!GlobalTimerNotExpired("Cast","LOCALS")
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_FLESH_TO_STONE)
	RandomNumGT(9,3)
THEN
	RESPONSE #100
		DisplayString(Myself,39969) // Spell Sequencer - Fired
		DisplayString(Myself,40241) // Spell Sequencer - Stoneskins
		ReallyForceSpell(Myself,WIZARD_STONE_SKIN)
		DisplayString(Myself,40242) // Spell Sequencer - Improved Invisibility
		ReallyForceSpell(Myself,WIZARD_IMPROVED_INVISIBILITY)
		DisplayString(Myself,40243) // Spell Sequencer - Fireshield Red
		ReallyForceSpell(Myself,WIZARD_FIRE_SHIELD_RED)
		SetGlobalTimer("Cast","LOCALS",6)
		Spell(NearestEnemyOf(Myself),WIZARD_FLESH_TO_STONE)
END

IF
	See(NearestEnemyOf(Myself))
	!GlobalTimerNotExpired("Cast","LOCALS")
	HaveSpell(WIZARD_CHAOS)
	Range(NearestEnemyOf(Myself),6)
	RandomNum(2,1)
THEN
	RESPONSE #100
		SetGlobalTimer("Cast","LOCALS",6)
		Spell(Myself,WIZARD_CHAOS)
END

IF
	!GlobalTimerNotExpired("Cast","LOCALS")
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_SHADOW_DOOR)
	!StateCheck(Myself,STATE_INVISIBLE)
	!StateCheck(Myself,STATE_IMPROVEDINVISIBILITY)
THEN
	RESPONSE #100
		SetGlobalTimer("Cast","LOCALS",6)
		Spell(Myself,WIZARD_SHADOW_DOOR)
END

IF
	!GlobalTimerNotExpired("Cast","LOCALS")
	HaveSpell(WIZARD_POWER_WORD_KILL)
	See(NearestEnemyOf(Myself))
	RandomNumGT(9,4)
	OR(2)
		!See(NearestEnemyOf(Myself))
		HPGT(NearestEnemyOf(Myself),60)
	OR(2)
		!See(SecondNearestEnemyOf(Myself))
		HPGT(SecondNearestEnemyOf(Myself),60)
	OR(2)
		!See(ThirdNearestEnemyOf(Myself))
		HPGT(ThirdNearestEnemyOf(Myself),60)
	OR(2)
		!See(FourthNearestEnemyOf(Myself))
		HPGT(FourthNearestEnemyOf(Myself),60)
	OR(2)
		!See(FifthNearestEnemyOf(Myself))
		HPGT(FifthNearestEnemyOf(Myself),60)
	OR(2)
		!See(SixthNearestEnemyOf(Myself))
		HPGT(SixthNearestEnemyOf(Myself),60)
	OR(2)
		!See(SeventhNearestEnemyOf(Myself))
		HPGT(SeventhNearestEnemyOf(Myself),60)
	OR(2)
		!See(EighthNearestEnemyOf(Myself))
		HPGT(EighthNearestEnemyOf(Myself),60)
	OR(2)
		!See(NinthNearestEnemyOf(Myself))
		HPGT(NinthNearestEnemyOf(Myself),60)
	OR(2)
		!See(TenthNearestEnemyOf(Myself))
		HPGT(TenthNearestEnemyOf(Myself),60)
	See(NearestEnemyOf(Myself))
	False()
THEN
	RESPONSE #100
		Continue()
END

IF
	!GlobalTimerNotExpired("Cast","LOCALS")
	Allegiance(Myself,ENEMY)
	Allegiance(LastSeenBy(Myself),GOODCUTOFF)
	See(LastSeenBy(Myself))
	HPLT(LastSeenBy(Myself),61)
	HaveSpell(WIZARD_POWER_WORD_KILL)
	RandomNumGT(9,4)
THEN
	RESPONSE #100
		SetGlobalTimer("CAST","LOCALS",6)
		Spell(LastSeenBy(Myself),WIZARD_POWER_WORD_KILL)
END

IF
	!GlobalTimerNotExpired("Cast","LOCALS")
	HaveSpell(WIZARD_POWER_WORD_STUN)
	See(NearestEnemyOf(Myself))
	RandomNumGT(7,2)
	OR(2)
		!See(NearestEnemyOf(Myself))
		HPGT(NearestEnemyOf(Myself),89)
	OR(2)
		!See(SecondNearestEnemyOf(Myself))
		HPGT(SecondNearestEnemyOf(Myself),89)
	OR(2)
		!See(ThirdNearestEnemyOf(Myself))
		HPGT(ThirdNearestEnemyOf(Myself),89)
	OR(2)
		!See(FourthNearestEnemyOf(Myself))
		HPGT(FourthNearestEnemyOf(Myself),89)
	OR(2)
		!See(FifthNearestEnemyOf(Myself))
		HPGT(FifthNearestEnemyOf(Myself),89)
	OR(2)
		!See(SixthNearestEnemyOf(Myself))
		HPGT(SixthNearestEnemyOf(Myself),89)
	OR(2)
		!See(SeventhNearestEnemyOf(Myself))
		HPGT(SeventhNearestEnemyOf(Myself),89)
	OR(2)
		!See(EighthNearestEnemyOf(Myself))
		HPGT(EighthNearestEnemyOf(Myself),89)
	OR(2)
		!See(NinthNearestEnemyOf(Myself))
		HPGT(NinthNearestEnemyOf(Myself),89)
	OR(2)
		!See(TenthNearestEnemyOf(Myself))
		HPGT(TenthNearestEnemyOf(Myself),89)
	See(NearestEnemyOf(Myself))
	False()
THEN
	RESPONSE #100
		Continue()
END

IF
	!GlobalTimerNotExpired("Cast","LOCALS")
	Allegiance(Myself,ENEMY)
	Allegiance(LastSeenBy(Myself),GOODCUTOFF)
	See(LastSeenBy(Myself))
	HPLT(LastSeenBy(Myself),90)
	HaveSpell(WIZARD_POWER_WORD_STUN)
	RandomNumGT(7,2)
THEN
	RESPONSE #100
		SetGlobalTimer("CAST","LOCALS",6)
		Spell(LastSeenBy(Myself),WIZARD_POWER_WORD_STUN)
END

IF
	See(NearestEnemyOf(Myself))
	!GlobalTimerNotExpired("Cast","LOCALS")
	OR(4)
		HasBounceEffects(NearestEnemyOfType([GOODCUTOFF.0.0.MAGE_ALL]))
		HasImmunityEffects(NearestEnemyOfType([GOODCUTOFF.0.0.MAGE_ALL]))
		!See(NearestEnemyOfType([GOODCUTOFF.0.0.MAGE_ALL]))
		RandomNumGT(20,1)
	OR(4)
		HasBounceEffects(SecondNearestEnemyOfType([GOODCUTOFF.0.0.MAGE_ALL]))
		HasImmunityEffects(SecondNearestEnemyOfType([GOODCUTOFF.0.0.MAGE_ALL]))
		!See(SecondNearestEnemyOfType([GOODCUTOFF.0.0.MAGE_ALL]))
		RandomNumGT(20,2)
	OR(4)
		HasBounceEffects(NearestEnemyOfType([GOODCUTOFF.0.0.CLERIC_ALL]))
		HasImmunityEffects(NearestEnemyOfType([GOODCUTOFF.0.0.CLERIC_ALL]))
		!See(NearestEnemyOfType([GOODCUTOFF.0.0.CLERIC_ALL]))
		RandomNumGT(20,3)
	OR(4)
		HasBounceEffects(SecondNearestEnemyOfType([GOODCUTOFF.0.0.CLERIC_ALL]))
		HasImmunityEffects(SecondNearestEnemyOfType([GOODCUTOFF.0.0.CLERIC_ALL]))
		!See(SecondNearestEnemyOfType([GOODCUTOFF.0.0.CLERIC_ALL]))
		RandomNumGT(20,4)
	OR(4)
		HasBounceEffects(SecondNearestEnemyOfType([GOODCUTOFF.0.0.DRUID_ALL]))
		HasImmunityEffects(SecondNearestEnemyOfType([GOODCUTOFF.0.0.DRUID_ALL]))
		!See(SecondNearestEnemyOfType([GOODCUTOFF.0.0.DRUID_ALL]))
		RandomNumGT(20,5)
	OR(4)
		HasBounceEffects(SecondNearestEnemyOfType([GOODCUTOFF.0.0.BARD_ALL]))
		HasImmunityEffects(SecondNearestEnemyOfType([GOODCUTOFF.0.0.BARD_ALL]))
		!See(SecondNearestEnemyOfType([GOODCUTOFF.0.0.BARD_ALL]))
		RandomNumGT(20,6)
	OR(7)
		!See(NearestEnemyOf(Myself))
		!See(SecondNearestEnemyOf(Myself))
		!See(ThirdNearestEnemyOf(Myself))
		!See(FourthNearestEnemyOf(Myself))
		!See(FifthNearestEnemyOf(Myself))
		!See(SixthNearestEnemyOf(Myself))
		RandomNum(2,1)
	OR(7)
		!See(SixthNearestEnemyOf(Myself))
		!See(FifthNearestEnemyOf(Myself))
		!See(FourthNearestEnemyOf(Myself))
		!See(ThirdNearestEnemyOf(Myself))
		!See(SecondNearestEnemyOf(Myself))
		!See(NearestEnemyOf(Myself))
		RandomNumGT(5,2)
	OR(6)
		!See(FifthNearestEnemyOf(Myself))
		!See(SecondNearestEnemyOf(Myself))
		!See(NearestEnemyOf(Myself))
		!See(FourthNearestEnemyOf(Myself))
		!See(ThirdNearestEnemyOf(Myself))
		!See(SixthNearestEnemyOf(Myself))
	False()
THEN
	RESPONSE #100
		Continue()
END

IF
	!GlobalTimerNotExpired("Cast","LOCALS")
	See(LastSeenBy(Myself))
	Allegiance(LastSeenBy(Myself),GOODCUTOFF)
	Allegiance(Myself,ENEMY)
	!HasBounceEffects(LastSeenBy(Myself))
	!StateCheck(LastSeenBy(Myself),STATE_STUNNED)
	HaveSpell(WIZARD_NPC_SYMBOL_STUN)
	RandomNum(2,1)
THEN
	RESPONSE #100
		SetGlobalTimer("Cast","LOCALS",6)
		Spell(LastSeenBy(Myself),WIZARD_NPC_SYMBOL_STUN)
END

IF
	!GlobalTimerNotExpired("Cast","LOCALS")
	See(LastSeenBy(Myself))
	Allegiance(LastSeenBy(Myself),GOODCUTOFF)
	Allegiance(Myself,ENEMY)
	!HasBounceEffects(LastSeenBy(Myself))
	GlobalLT("chain","LOCALS",2)
	RandomNumGT(5,3)
THEN
	RESPONSE #100
		SetGlobalTimer("Cast","LOCALS",6)
		SpellNoDec(LastSeenBy(Myself),WIZARD_CHAIN_LIGHTNING)
		IncrementGlobal("chain","LOCALS",1)
END

IF
	!GlobalTimerNotExpired("Cast","LOCALS")
	See(LastSeenBy(Myself))
	Allegiance(LastSeenBy(Myself),GOODCUTOFF)
	Allegiance(Myself,ENEMY)
	!HasBounceEffects(LastSeenBy(Myself))
	HaveSpell(WIZARD_FINGER_OF_DEATH)
	RandomNumGT(8,3)
THEN
	RESPONSE #100
		SetGlobalTimer("Cast","LOCALS",6)
		Spell(NearestEnemyOf(Myself),WIZARD_FINGER_OF_DEATH)
END

IF
	!GlobalTimerNotExpired("Cast","LOCALS")
	See(LastSeenBy(Myself))
	Allegiance(LastSeenBy(Myself),GOODCUTOFF)
	Allegiance(Myself,ENEMY)
	!HasBounceEffects(LastSeenBy(Myself))
	HaveSpell(WIZARD_DISINTEGRATE)
	RandomNumGT(3,1)
THEN
	RESPONSE #100
		SetGlobalTimer("Cast","LOCALS",6)
		Spell(LastSeenBy(Myself),WIZARD_DISINTEGRATE)
END

IF
	!GlobalTimerNotExpired("Cast","LOCALS")
	HaveSpell(WIZARD_MAGIC_MISSILE)
	See(LastSeenBy(Myself))
	Allegiance(LastSeenBy(Myself),GOODCUTOFF)
	Allegiance(Myself,ENEMY)
	RandomNumGT(10,2)
THEN
	RESPONSE #100
		SetGlobalTimer("Cast","LOCALS",6)
		Spell(LastSeenBy(Myself),WIZARD_MAGIC_MISSILE)
END

IF
	!GlobalTimerNotExpired("Cast","LOCALS")
	HaveSpell(WIZARD_MAGIC_MISSILE)
	See(LastSeenBy(Myself))
	Allegiance(LastSeenBy(Myself),GOODCUTOFF)
	Allegiance(Myself,ENEMY)
	GlobalLT("Orb","LOCALS",2)
	RandomNumGT(6,3)
THEN
	RESPONSE #100
		SetGlobalTimer("Cast","LOCALS",6)
		IncrementGlobal("Orb","LOCALS",1)
		SpellNoDec(LastSeenBy(Myself),WIZARD_CHROMATIC_ORB)
END

IF
	!GlobalTimerNotExpired("Cast","LOCALS")
	HaveSpell(WIZARD_MAGIC_MISSILE)
	See(LastSeenBy(Myself))
	Allegiance(LastSeenBy(Myself),GOODCUTOFF)
	Allegiance(Myself,ENEMY)
	HaveSpell(WIZARD_FLAME_ARROW)
	RandomNumGT(8,3)
THEN
	RESPONSE #100
		SetGlobalTimer("Cast","LOCALS",6)
		Spell(LastSeenBy(Myself),WIZARD_FLAME_ARROW)
END

IF
	!GlobalTimerNotExpired("Cast","LOCALS")
	HaveSpell(WIZARD_MAGIC_MISSILE)
	See(LastSeenBy(Myself))
	Allegiance(LastSeenBy(Myself),GOODCUTOFF)
	Allegiance(Myself,ENEMY)
	HaveSpell(WIZARD_MELF_ACID_ARROW)
	RandomNumGT(9,3)
THEN
	RESPONSE #100
		SetGlobalTimer("Cast","LOCALS",6)
		Spell(LastSeenBy(Myself),WIZARD_MELF_ACID_ARROW)
END

IF
	See(NearestEnemyOf(Myself))
	OR(2)
		HasItem("melfmet",Myself)
		RandomNum(2,1)
THEN
	RESPONSE #100
		Attack(NearestEnemyOf(Myself))
END

IF
	InMyArea([GOODCUTOFF])
	!Detect([GOODCUTOFF])
THEN
	RESPONSE #100
		MoveToObject([GOODCUTOFF])
END

IF
	True()
THEN
	RESPONSE #100
		RandomWalkContinuous()
END
