IF
	Dead("TOLGER2")
THEN
	RESPONSE #100
		DestroySelf()
END

IF
	Detect("Valygar")
	Global("TolgSawValygar","LOCALS",0)
	NumTimesTalkedTo(0)
THEN
	RESPONSE #100
		SetGlobal("TolgSawValygar","LOCALS",1)
		ActionOverride("tolger",StartDialogueNoSet([PC]))
END

IF
	!GlobalTimerNotExpired("Cast","LOCALS")
	Allegiance(Myself,ENEMY)
	AreaCheck("ar1002")
	Global("trytoescape","LOCALS",0)
THEN
	RESPONSE #100
		SetGlobalTimer("Cast","LOCALS",6)
		SetGlobal("trytoescape","LOCALS",1)
		SpellNoDec(Myself,DRYAD_TELEPORT)
END

IF
	See(NearestEnemyOf(Myself))
	Global("cowledwizard","LOCALS",0)
THEN
	RESPONSE #100
		ReallyForceSpell(Myself,WIZARD_STONE_SKIN)
		ReallyForceSpell(Myself,WIZARD_IMPROVED_MANTLE)
		ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_ENERGY)
		ReallyForceSpell(Myself,WIZARD_SPELL_DEFLECTION)
		SetGlobal("cowledwizard","LOCALS",1)
END

IF
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("eneblade",Myself)
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("melfmet",Myself)
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_ABI_DALZIMS_HORRID_WILTING)
	RandomNum(2,1)
THEN
	RESPONSE #100
		SetGlobalTimer("Cast","LOCALS",6)
		Spell(NearestEnemyOf(Myself),WIZARD_ABI_DALZIMS_HORRID_WILTING)
END

IF
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("eneblade",Myself)
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("melfmet",Myself)
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_POWER_WORD_KILL)
	RandomNum(2,1)
THEN
	RESPONSE #100
		SetGlobalTimer("Cast","LOCALS",6)
		Spell(NearestEnemyOf(Myself),WIZARD_POWER_WORD_KILL)
END

IF
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("eneblade",Myself)
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("melfmet",Myself)
	See(NearestEnemyOf(Myself))
	!StateCheck(LastSeenBy(Myself),STATE_STUNNED)
	HaveSpell(WIZARD_POWER_WORD_STUN)
	RandomNum(2,1)
THEN
	RESPONSE #100
		SetGlobalTimer("Cast","LOCALS",6)
		Spell(LastSeenBy(Myself),WIZARD_POWER_WORD_STUN)
END

IF
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("eneblade",Myself)
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("melfmet",Myself)
	See(NearestEnemyOf(Myself))
	See([0.0.0.0.0.SUMMONED])
	HaveSpell(WIZARD_DEATH_SPELL)
	RandomNum(2,1)
THEN
	RESPONSE #100
		SetGlobalTimer("Cast","LOCALS",6)
		ReallyForceSpell(Myself,WIZARD_MIRROR_IMAGE)
		Spell([0.0.0.0.0.SUMMONED],WIZARD_DEATH_SPELL)
END

IF
	See(NearestEnemyOf(Myself))
	Global("Prep","LOCALS",0)
	!GlobalTimerNotExpired("PrepTimer","LOCALS")
	CheckStatLT(Myself,2,STONESKINS)
THEN
	RESPONSE #100
		ReallyForceSpell(Myself,WIZARD_STONE_SKIN)
		DisplayString(Myself,39968) // Spell Trigger - Fired
		ReallyForceSpell(Myself,WIZARD_GLOBE_OF_INVULNERABILITY)
		ReallyForceSpell(Myself,WIZARD_SPELL_TURNING)
		ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
		ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
		ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_ELECTRICITY)
		SetGlobal("Prep","LOCALS",1)
END

IF
	See(NearestEnemyOf(Myself))
	Global("Prep","LOCALS",0)
	!GlobalTimerNotExpired("PrepTimer","LOCALS")
	!CheckStatLT(Myself,2,STONESKINS)
	DifficultyGT(EASY)
THEN
	RESPONSE #100
		ReallyForceSpell(Myself,WIZARD_MELF_METEOR)
		DisplayString(Myself,39968) // Spell Trigger - Fired
		ReallyForceSpell(Myself,WIZARD_GLOBE_OF_INVULNERABILITY)
		ReallyForceSpell(Myself,WIZARD_SPELL_TURNING)
		ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
		ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
		ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_ELECTRICITY)
		SetGlobal("Prep","LOCALS",1)
END

IF
	See(NearestEnemyOf(Myself))
	Global("Prep","LOCALS",0)
	!GlobalTimerNotExpired("PrepTimer","LOCALS")
	!CheckStatLT(Myself,2,STONESKINS)
	DifficultyGT(EASY)
THEN
	RESPONSE #100
		DisplayString(Myself,39968) // Spell Trigger - Fired
		ReallyForceSpell(Myself,WIZARD_GLOBE_OF_INVULNERABILITY)
		ReallyForceSpell(Myself,WIZARD_SPELL_TURNING)
		ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
		ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
		ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_ELECTRICITY)
		SetGlobal("Prep","LOCALS",1)
END

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

IF
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("eneblade",Myself)
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("melfmet",Myself)
	Detect([PC])
	!See(LastSeenBy(Myself))
	HaveSpell(WIZARD_TRUE_SIGHT)
THEN
	RESPONSE #100
		SetGlobalTimer("Cast","LOCALS",6)
		Spell(Myself,WIZARD_TRUE_SIGHT)
END

IF
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("eneblade",Myself)
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("melfmet",Myself)
	!HasBounceEffects(Myself)
	!HasImmunityEffects(Myself)
	HaveSpell(WIZARD_SPELL_TURNING)
	See(NearestEnemyOf(Myself))
THEN
	RESPONSE #100
		SetGlobalTimer("Cast","LOCALS",6)
		Spell(Myself,WIZARD_SPELL_TURNING)
END

IF
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_STONE_SKIN)
	CheckStatLT(Myself,1,STONESKINS)
	Global("Prep1","LOCALS",0)
	!StateCheck(Myself,STATE_REALLY_DEAD)
THEN
	RESPONSE #100
		DisplayString(Myself,29736) // Contingency - Stoneskin
		ForceSpell(Myself,WIZARD_STONE_SKIN)
		SetGlobal("Prep1","LOCALS",1)
END

IF
	!GlobalTimerNotExpired("Cast","LOCALS")
	See(NearestEnemyOf(Myself))
	!HasItem("melfmet",Myself)
	!HasItem("eneblade",Myself)
	GlobalLT("meteors","LOCALS",1)
	DifficultyGT(EASIEST)
THEN
	RESPONSE #100
		SetGlobalTimer("Cast","LOCALS",6)
		IncrementGlobal("meteors","LOCALS",1)
		SpellNoDec(Myself,WIZARD_MELF_METEOR)
END

IF
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("eneblade",Myself)
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("melfmet",Myself)
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_NPC_SYMBOL_STUN)
THEN
	RESPONSE #100
		SetGlobalTimer("Cast","LOCALS",6)
		Spell(NearestEnemyOf(Myself),WIZARD_NPC_SYMBOL_STUN)
END

IF
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("eneblade",Myself)
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("melfmet",Myself)
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_SIMULACRUM)
	Global("Sim","LOCALS",0)
	!StateCheck(Myself,STATE_REALLY_DEAD)
	DifficultyGT(EASIEST)
THEN
	RESPONSE #100
		ForceSpell(Myself,DO_NOTHING)
		DisplayString(Myself,40600) // Cast Spell: Simulacrum
		CreateCreatureObjectCopy("mage8a",Myself,0,0,0) // Zyntris
		SetGlobal("Sim","LOCALS",1)
END

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

IF
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("eneblade",Myself)
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("melfmet",Myself)
	See(NearestEnemyOf(Myself))
	GlobalLT("chain","LOCALS",2)
	RandomNum(2,1)
THEN
	RESPONSE #100
		SetGlobalTimer("Cast","LOCALS",6)
		SpellNoDec(NearestEnemyOf(Myself),WIZARD_CHAIN_LIGHTNING)
		IncrementGlobal("chain","LOCALS",1)
END

IF
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("eneblade",Myself)
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("melfmet",Myself)
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_MAZE)
THEN
	RESPONSE #100
		SetGlobalTimer("Cast","LOCALS",6)
		Spell(NearestEnemyOf(Myself),WIZARD_MAZE)
END

IF
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("eneblade",Myself)
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("melfmet",Myself)
	See(NearestEnemyOfType([0.0.0.LONG_BOW]))
	HaveSpell(WIZARD_RUBY_RAY_OF_REVERSAL)
THEN
	RESPONSE #100
		SetGlobalTimer("Cast","LOCALS",6)
		Spell(LastSeenBy(Myself),WIZARD_RUBY_RAY_OF_REVERSAL)
END

IF
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("eneblade",Myself)
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("melfmet",Myself)
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_NPC_SYMBOL_FEAR)
THEN
	RESPONSE #100
		SetGlobalTimer("Cast","LOCALS",6)
		Spell(NearestEnemyOf(Myself),WIZARD_NPC_SYMBOL_FEAR)
END

IF
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_MIRROR_IMAGE)
	Global("Prep","LOCALS",1)
	!StateCheck(Myself,STATE_REALLY_DEAD)
THEN
	RESPONSE #100
		DisplayString(Myself,39969) // Spell Sequencer - Fired
		ReallyForceSpell(Myself,WIZARD_STONE_SKIN)
		ReallyForceSpell(Myself,WIZARD_MIRROR_IMAGE)
		ReallyForceSpell(Myself,WIZARD_FIRE_SHIELD_RED)
		SetGlobal("Prep","LOCALS",2)
END

IF
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("eneblade",Myself)
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("melfmet",Myself)
	See(NearestEnemyOf(Myself))
	!StateCheck(LastSeenBy(Myself),STATE_STUNNED)
	HaveSpell(WIZARD_POWER_WORD_STUN)
THEN
	RESPONSE #100
		SetGlobalTimer("Cast","LOCALS",6)
		Spell(NearestEnemyOf(Myself),WIZARD_POWER_WORD_STUN)
END

IF
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("eneblade",Myself)
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("melfmet",Myself)
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_SUN_FIRE)
THEN
	RESPONSE #100
		SetGlobalTimer("Cast","LOCALS",6)
		Spell(Myself,WIZARD_SUN_FIRE)
END

IF
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("eneblade",Myself)
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("melfmet",Myself)
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_MISLEAD)
THEN
	RESPONSE #100
		SetGlobalTimer("Cast","LOCALS",6)
		Spell(Myself,WIZARD_MISLEAD)
END

IF
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("eneblade",Myself)
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("melfmet",Myself)
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_TRUE_SIGHT)
THEN
	RESPONSE #100
		SetGlobalTimer("Cast","LOCALS",6)
		Spell(NearestEnemyOf(Myself),WIZARD_TRUE_SIGHT)
END

IF
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("eneblade",Myself)
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("melfmet",Myself)
	See(NearestEnemyOfType([0.0.0.LONG_BOW]))
	HaveSpell(WIZARD_RUBY_RAY_OF_REVERSAL)
	OR(2)
		HasBounceEffects(LastSeenBy(Myself))
		HasImmunityEffects(LastSeenBy(Myself))
THEN
	RESPONSE #100
		SetGlobalTimer("Cast","LOCALS",6)
		Spell(LastSeenBy(Myself),WIZARD_RUBY_RAY_OF_REVERSAL)
END

IF
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("eneblade",Myself)
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("melfmet",Myself)
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_DISINTEGRATE)
THEN
	RESPONSE #100
		SetGlobalTimer("Cast","LOCALS",6)
		Spell(NearestEnemyOf(Myself),WIZARD_DISINTEGRATE)
END

IF
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("eneblade",Myself)
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("melfmet",Myself)
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_CHAIN_LIGHTNING)
THEN
	RESPONSE #100
		SetGlobalTimer("Cast","LOCALS",6)
		Spell(NearestEnemyOf(Myself),WIZARD_CHAIN_LIGHTNING)
END

IF
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("eneblade",Myself)
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("melfmet",Myself)
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_CHAOS)
THEN
	RESPONSE #100
		SetGlobalTimer("Cast","LOCALS",6)
		Spell(NearestEnemyOf(Myself),WIZARD_CHAOS)
END

IF
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("eneblade",Myself)
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("melfmet",Myself)
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_DOMINATION)
THEN
	RESPONSE #100
		SetGlobalTimer("Cast","LOCALS",6)
		Spell(NearestEnemyOf(Myself),WIZARD_DOMINATION)
END

IF
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("eneblade",Myself)
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("melfmet",Myself)
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_FLAME_ARROW)
THEN
	RESPONSE #100
		SetGlobalTimer("Cast","LOCALS",6)
		Spell(NearestEnemyOf(Myself),WIZARD_FLAME_ARROW)
END

IF
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("eneblade",Myself)
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("melfmet",Myself)
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_MELF_ACID_ARROW)
THEN
	RESPONSE #100
		SetGlobalTimer("Cast","LOCALS",6)
		Spell(NearestEnemyOf(Myself),WIZARD_MELF_ACID_ARROW)
END

IF
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("eneblade",Myself)
	OR(2)
		!GlobalTimerNotExpired("Cast","LOCALS")
		!HasItem("melfmet",Myself)
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_MAGIC_MISSILE)
THEN
	RESPONSE #100
		SetGlobalTimer("Cast","LOCALS",6)
		Spell(NearestEnemyOf(Myself),WIZARD_MAGIC_MISSILE)
END

IF
	See(NearestEnemyOf(Myself))
THEN
	RESPONSE #100
		Attack(NearestEnemyOf(Myself))
END
