IF
	OnCreation()
	Global("CbYuanTiGotEquip","LOCALS",0)
THEN
	RESPONSE #20
		SetGlobal("CbYuanTiGotEquip","LOCALS",1)
		GiveItemCreate("BELT10",Myself,1,0,0) // Belt of Inertial Barrier
		EquipItem("BELT10") // Belt of Inertial Barrier
		GiveItemCreate("HELM04",Myself,1,0,0) // Helmet of Defense
		EquipItem("HELM04") // Helmet of Defense
		GiveItemCreate("RING07",Myself,1,0,0) // Ring of Protection +3
		EquipItem("RING07") // Ring of Protection +3
		GiveItemCreate("CLCK20",Myself,1,0,0) // Cloak of Mirroring
		EquipItem("CLCK20") // Cloak of Mirroring
		GiveItemCreate("RNDTRE06",Myself,1,0,0)
		GiveItemCreate("SW2H08",Myself,1,0,0) // Spectral Brand +4
		EquipItem("SW2H08") // Spectral Brand +4
	RESPONSE #20
		SetGlobal("CbYuanTiGotEquip","LOCALS",1)
		GiveItemCreate("BELT08",Myself,1,0,0) // Girdle of Frost Giant Strength
		EquipItem("BELT08") // Girdle of Frost Giant Strength
		GiveItemCreate("HELM20",Myself,1,0,0) // Pale Green Ioun Stone
		EquipItem("HELM20") // Pale Green Ioun Stone
		GiveItemCreate("RING07",Myself,1,0,0) // Ring of Protection +2
		EquipItem("RING07") // Ring of Protection +2
		GiveItemCreate("CLCK02",Myself,1,0,0) // Improved Cloak of Protection +2
		EquipItem("CLCK02") // Improved Cloak of Protection +2
		GiveItemCreate("RNDTRE06",Myself,1,0,0)
		GiveItemCreate("SW2H11",Myself,1,0,0) // Soul Reaver +4
		EquipItem("SW2H11") // Soul Reaver +4
	RESPONSE #20
		SetGlobal("CbYuanTiGotEquip","LOCALS",1)
		GiveItemCreate("BELT03",Myself,1,0,0) // Girdle of Bluntness
		EquipItem("BELT03") // Girdle of Bluntness
		GiveItemCreate("HELM24",Myself,1,0,0) // Obsidian Ioun Stone
		EquipItem("HELM24") // Obsidian Ioun Stone
		GiveItemCreate("RING09",Myself,1,0,0) // Ring of Free Action
		EquipItem("RING09") // Ring of Free Action
		GiveItemCreate("CLCK20",Myself,1,0,0) // Cloak of the Shield
		EquipItem("CLCK20") // Cloak of the Shield
		GiveItemCreate("RNDTRE06",Myself,1,0,0)
		GiveItemCreate("SW1H40",Myself,1,0,0) // Blade of Roses +3
		EquipItem("SW1H40") // Blade of Roses +3
	RESPONSE #20
		SetGlobal("CbYuanTiGotEquip","LOCALS",1)
		GiveItemCreate("BELT09",Myself,1,0,0) // Girdle of Fortitude
		EquipItem("BELT09") // Girdle of Fortitude
		GiveItemCreate("HELM30",Myself,1,0,0) // Thieves' Hood
		EquipItem("HELM30") // Thieves' Hood
		GiveItemCreate("RING27",Myself,1,0,0) // Ring of Fire Control
		EquipItem("RING27") // Ring of Fire Control
		GiveItemCreate("CLCK02",Myself,1,0,0) // Cloak of Protection +2
		EquipItem("CLCK02") // Cloak of Protection +2
		GiveItemCreate("RNDTRE06",Myself,1,0,0)
		GiveItemCreate("SW1H55",Myself,1,0,0) // Celestial Fury
		EquipItem("SW1H55") // Celestial Fury
	RESPONSE #20
		SetGlobal("CbYuanTiGotEquip","LOCALS",1)
		GiveItemCreate("BELT06",Myself,1,0,0) // Girdle of Fire Giant Strength
		EquipItem("BELT06") // Girdle of Fire Giant Strength
		GiveItemCreate("RING31",Myself,1,0,0) // Ring of Regeneration
		EquipItem("RING31") // Ring of Regeneration
		GiveItemCreate("CLCK24",Myself,1,0,0) // Cloak of Reflection
		EquipItem("CLCK24") // Cloak of Reflection
		GiveItemCreate("RNDTRE06",Myself,1,0,0)
		GiveItemCreate("SW1H22",Myself,1,0,0) // Short Sword of Mask +4
		EquipItem("SW1H22") // Short Sword of Mask +4
END

IF
	AreaCheck("AR3646")
	Global("CbSuperBoss","LOCALS",0)
THEN
	RESPONSE #100
		SetGlobal("CbSuperBoss","LOCALS",1)
                ApplySpellRES("CBYT4446",Myself)
END

IF
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_SHADOW_DOOR)
THEN
	RESPONSE #100
		Spell(Myself,WIZARD_SHADOW_DOOR)
END

IF
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_SPELL_TURNING)
THEN
	RESPONSE #100
		Spell(Myself,WIZARD_SPELL_TURNING)
END

IF
	See(NearestEnemyOfType([0.0.0.MAGE]))
	HaveSpell(WIZARD_SUMMON_NISHRUU)
THEN
	RESPONSE #100
		Spell(Myself,WIZARD_SUMMON_NISHRUU)
END

IF
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_STONE_SKIN)
	Global("skin","LOCALS",0)
	HPGT(Myself,0)
THEN
	RESPONSE #100
		Spell(Myself,WIZARD_STONE_SKIN)
		SetGlobal("skin","LOCALS",1)
END

IF
	HitBy([ANYONE],MISSILE)
	HaveSpell(WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
THEN
	RESPONSE #100
		Spell(Myself,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
END

IF
	Allegiance(Myself,ENEMY)
	Detect([PC])
	!See(LastSeenBy(Myself))
	HaveSpell(WIZARD_TRUE_SIGHT)
THEN
	RESPONSE #100
		Spell(Myself,WIZARD_TRUE_SIGHT)
END

IF
	See(NearestEnemyOf(Myself))
	StateCheck(Myself,STATE_SILENCED)
	HaveSpell(WIZARD_VOCALIZE)
THEN
	RESPONSE #100
		Spell(Myself,WIZARD_VOCALIZE)
END

IF
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_STONE_SKIN)
	CheckStatLT(Myself,1,STONESKINS)
	TookDamage()
	Global("Sequencer","LOCALS",0)
	HPGT(Myself,0)
THEN
	RESPONSE #100
		DisplayString(Myself,39969) // Spell Sequencer - Fired
		DisplayString(Myself,40241) // Spell Sequencer - Stoneskins
		ApplySpell(Myself,WIZARD_STONE_SKIN)
		DisplayString(Myself,40243) // Spell Sequencer - Fireshield Red
		ApplySpell(Myself,WIZARD_FIRE_SHIELD_RED)
		DisplayString(Myself,8638) // Spell Sequencer - Melf's Minute Meteors
		ApplySpell(Myself,WIZARD_MELF_METEOR)
		AttackOneRound(LastSeenBy(Myself))
		AttackOneRound(LastSeenBy(Myself))
		AttackOneRound(LastSeenBy(Myself))
		SetGlobal("Sequencer","LOCALS",1)
END

IF
	Allegiance(Myself,ENEMY)
	!HasBounceEffects(Myself)
	Global("Contingency","LOCALS",0)
	HPGT(Myself,0)
THEN
	RESPONSE #100
		DisplayString(Myself,36209) // Contingency - Minor Spell Turning
		ApplySpell(Myself,WIZARD_MINOR_SPELL_TURNING)
		SetGlobal("Contingency","LOCALS",1)
END

IF
	See(NearestEnemyOfType([0.0.0.MAGE]))
	!HasBounceEffects(LastSeenBy(Myself))
	!HasImmunityEffects(LastSeenBy(Myself))
	Global("MinorSequencer","LOCALS",0)
	HPGT(Myself,0)
THEN
	RESPONSE #100
		DisplayString(Myself,8635) // Minor Sequencer Activated
		ForceSpell(LastSeenBy(Myself),WIZARD_MELF_ACID_ARROW)
		ForceSpell(LastSeenBy(Myself),WIZARD_MAGIC_MISSILE)
		SetGlobal("MinorSequencer","LOCALS",1)
END

IF
	See(NearestEnemyOfType([0.0.0.MAGE]))
	!HasBounceEffects(Myself)
	!HasImmunityEffects(Myself)
	HaveSpell(WIZARD_MINOR_SPELL_DEFLECTION)
	HPGT(Myself,0)
THEN
	RESPONSE #100
		Spell(Myself,WIZARD_MINOR_SPELL_DEFLECTION)
END

IF
	See(NearestEnemyOf(Myself))
	!Class(LastSeenBy(Myself),MAGE)
	HaveSpell(WIZARD_DEATH_SPELL)
	OR(8)
		SpellCast([ANYONE],WIZARD_MONSTER_SUMMONING_1)
		SpellCast([ANYONE],WIZARD_MONSTER_SUMMONING_2)
		SpellCast([ANYONE],WIZARD_MONSTER_SUMMONING_3)
		SpellCast([ANYONE],WIZARD_MONSTER_SUMMONING_4)
		SpellCast([ANYONE],WIZARD_INVISIBLE_STALKER)
		SpellCast([ANYONE],WIZARD_SUMMON_NISHRUU)
		SpellCast([ANYONE],WIZARD_SUMMON_EFREET)
		SpellCast([ANYONE],WIZARD_CARRION)
THEN
	RESPONSE #100
		Spell(LastSeenBy(Myself),WIZARD_DEATH_SPELL)
END

/*IF
	NumCreatureGT([GOODCUTOFF],6)
	See(NearestEnemyOf(Myself))
	!Class(LastSeenBy(Myself),MAGE)
	HaveSpell(0)
THEN
	RESPONSE #100
		Spell(LastSeenBy(Myself),0)
END*/

IF
	See(NearestEnemyOfType([0.0.0.MAGE]))
	HaveSpell(WIZARD_MONSTER_SUMMONING_3)
	OR(8)
		SpellCast([ANYONE],WIZARD_MONSTER_SUMMONING_1)
		SpellCast([ANYONE],WIZARD_MONSTER_SUMMONING_2)
		SpellCast([ANYONE],WIZARD_MONSTER_SUMMONING_3)
		SpellCast([ANYONE],WIZARD_MONSTER_SUMMONING_4)
		SpellCast([ANYONE],WIZARD_INVISIBLE_STALKER)
		SpellCast([ANYONE],WIZARD_SUMMON_NISHRUU)
		SpellCast([ANYONE],WIZARD_SUMMON_EFREET)
		SpellCast([ANYONE],WIZARD_CARRION)
THEN
	RESPONSE #100
		Spell(Myself,WIZARD_MONSTER_SUMMONING_3)
		Spell(Myself,WIZARD_HASTE)
END

IF
	HaveSpell(WIZARD_PROTECTION_FROM_EVIL)
	OR(4)
		SpellCast([ANYONE],WIZARD_CACOFIEND)
		SpellCast([ANYONE],WIZARD_SUMMON_FIEND)
		SpellCast([ANYONE],WIZARD_GATE)
		SpellCastPriest([ANYONE],CLERIC_GATE)
THEN
	RESPONSE #100
		Spell(Myself,WIZARD_PROTECTION_FROM_EVIL)
END

IF
	Allegiance(Myself,ENEMY)
	HaveSpell(WIZARD_TRUE_SIGHT)
	OR(5)
		SpellCast(NearestEnemyOfType([0.0.0.MAGE]),WIZARD_MISLEAD)
		SpellCast(NearestEnemyOfType([0.0.0.MAGE]),WIZARD_SHADOW_DOOR)
		SpellCast(NearestEnemyOfType([0.0.0.MAGE]),WIZARD_PROJECT_IMAGE)
		SpellCast(NearestEnemyOfType([0.0.0.MAGE]),WIZARD_INVISIBILITY)
		SpellCast(NearestEnemyOfType([0.0.0.MAGE]),WIZARD_IMPROVED_INVISIBILITY)
THEN
	RESPONSE #100
		Spell(Myself,WIZARD_TRUE_SIGHT)
END

IF
	Allegiance(Myself,ENEMY)
	HaveSpell(WIZARD_DETECT_INVISIBILITY)
	OR(2)
		SpellCast(NearestEnemyOfType([0.0.0.MAGE]),WIZARD_INVISIBILITY)
		SpellCast(NearestEnemyOfType([0.0.0.MAGE]),WIZARD_IMPROVED_INVISIBILITY)
THEN
	RESPONSE #100
		Spell(Myself,WIZARD_DETECT_INVISIBILITY)
END

IF
	See(NearestEnemyOfType([0.0.0.MAGE]))
	HaveSpell(WIZARD_SECRET_WORD)
	SpellCast(LastSeenBy(Myself),WIZARD_MINOR_SPELL_TURNING)
THEN
	RESPONSE #100
		Spell(LastSeenBy(Myself),WIZARD_SECRET_WORD)
END

IF
	See(NearestEnemyOfType([0.0.0.MAGE]))
	HaveSpell(WIZARD_WARDING_WHIP)
	OR(2)
		SpellCast(LastSeenBy(Myself),WIZARD_SPELL_TURNING)
		SpellCast(LastSeenBy(Myself),WIZARD_SPELL_SHIELD)
THEN
	RESPONSE #100
		Spell(LastSeenBy(Myself),WIZARD_WARDING_WHIP)
END

IF
	See(NearestEnemyOfType([0.0.0.MAGE]))
	HaveSpell(WIZARD_WARDING_WHIP)
	OR(2)
		HasBounceEffects(LastSeenBy(Myself))
		HasImmunityEffects(LastSeenBy(Myself))
THEN
	RESPONSE #100
		Spell(LastSeenBy(Myself),WIZARD_WARDING_WHIP)
END

IF
	See(NearestEnemyOfType([0.0.0.MAGE]))
	HaveSpell(WIZARD_BREACH)
	OR(12)
		SpellCast(LastSeenBy(Myself),WIZARD_PROTECTION_FROM_MAGIC_ENERGY)
		SpellCast(LastSeenBy(Myself),WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
		SpellCast(LastSeenBy(Myself),WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
		SpellCast(LastSeenBy(Myself),WIZARD_PROTECTION_FROM_NORMAL_WEAPONS)
		SpellCast(LastSeenBy(Myself),WIZARD_PROTECTION_FROM_PETRIFICATION)
		SpellCast(LastSeenBy(Myself),WIZARD_PROTECTION_FROM_THE_ELEMENTS)
		SpellCast(LastSeenBy(Myself),WIZARD_PROTECTION_FROM_ACID)
		SpellCast(LastSeenBy(Myself),WIZARD_PROTECTION_FROM_COLD)
		SpellCast(LastSeenBy(Myself),WIZARD_PROTECTION_FROM_ELECTRICITY)
		SpellCast(LastSeenBy(Myself),WIZARD_PROTECTION_FROM_ENERGY)
		SpellCast(LastSeenBy(Myself),WIZARD_PROTECTION_FROM_EVIL)
		SpellCast(LastSeenBy(Myself),WIZARD_PROTECTION_FROM_FIRE)
THEN
	RESPONSE #100
		Spell(LastSeenBy(Myself),WIZARD_BREACH)
END

IF
	See(NearestEnemyOfType([0.0.0.MAGE]))
	HaveSpell(WIZARD_DISPEL_MAGIC)
	OR(4)
		SpellCast(LastSeenBy(Myself),WIZARD_HASTE)
		SpellCast(LastSeenBy(Myself),WIZARD_ARMOR)
		SpellCast(LastSeenBy(Myself),WIZARD_GHOST_ARMOR)
		SpellCast(LastSeenBy(Myself),WIZARD_SPIRIT_ARMOR)
THEN
	RESPONSE #100
		Spell(LastSeenBy(Myself),WIZARD_DISPEL_MAGIC)
END

IF
	See(NearestEnemyOfType([0.0.0.MAGE]))
	HaveSpell(WIZARD_POWER_WORD_SILENCE)
	!HasBounceEffects(LastSeenBy(Myself))
	!HasImmunityEffects(LastSeenBy(Myself))
THEN
	RESPONSE #100
		Spell(NearestEnemyOf(Myself),WIZARD_POWER_WORD_SILENCE)
END

IF
	See(NearestEnemyOfType([0.0.0.MAGE]))
	HaveSpell(WIZARD_IMPROVED_INVISIBILITY)
	!HasBounceEffects(Myself)
	HasBounceEffects(LastSeenBy(Myself))
	!HasImmunityEffects(LastSeenBy(Myself))
THEN
	RESPONSE #100
		Spell(LastSeenBy(Myself),WIZARD_IMPROVED_INVISIBILITY)
END

IF
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_CONE_OF_COLD)
THEN
	RESPONSE #100
		Spell(NearestEnemyOf(Myself),WIZARD_CONE_OF_COLD)
END

IF
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_CONTAGION)
THEN
	RESPONSE #100
		Spell(LastSeenBy(Myself),WIZARD_CONTAGION)
END

IF
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_FLAME_ARROW)
THEN
	RESPONSE #100
		Spell(NearestEnemyOf(Myself),WIZARD_FLAME_ARROW)
END

IF
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_STONE_SKIN)
	CheckStatLT(Myself,1,STONESKINS)
	HPGT(Myself,0)
THEN
	RESPONSE #100
		Spell(Myself,WIZARD_STONE_SKIN)
END

IF
	See(NearestEnemyOfType([0.0.0.MAGE]))
	HaveSpell(WIZARD_SLOW)
THEN
	RESPONSE #100
		Spell(LastSeenBy(Myself),WIZARD_SLOW)
END

IF
	See(NearestEnemyOf(Myself))
	Range(LastSeenBy(Myself),5)
	HaveSpell(WIZARD_SUN_FIRE)
THEN
	RESPONSE #100
		Spell(Myself,WIZARD_SUN_FIRE)
END

IF
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_MELF_ACID_ARROW)
THEN
	RESPONSE #100
		Spell(NearestEnemyOf(Myself),WIZARD_MELF_ACID_ARROW)
END

IF
	See(NearestEnemyOf(Myself))
	!Class(LastSeenBy(Myself),MAGE)
	HaveSpell(WIZARD_BLUR)
	HaveSpell(WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
THEN
	RESPONSE #100
		Spell(Myself,WIZARD_BLUR)
		Spell(Myself,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
END

IF
	See(NearestEnemyOf(Myself))
	!Class(LastSeenBy(Myself),MAGE)
	HaveSpell(WIZARD_POWER_WORD_SLEEP)
THEN
	RESPONSE #100
		Spell(LastSeenBy(Myself),WIZARD_POWER_WORD_SLEEP)
END

IF
	See(NearestEnemyOf(Myself))
	!Class(LastSeenBy(Myself),MAGE)
	HaveSpell(WIZARD_CHARM_PERSON)
THEN
	RESPONSE #100
		Spell(LastSeenBy(Myself),WIZARD_CHARM_PERSON)
END

IF
	See(NearestEnemyOf(Myself))
	!Class(LastSeenBy(Myself),MAGE)
	HaveSpell(WIZARD_SPOOK)
THEN
	RESPONSE #100
		Spell(LastSeenBy(Myself),WIZARD_SPOOK)
END

IF
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_MAGIC_MISSILE)
THEN
	RESPONSE #100
		Spell(NearestEnemyOf(Myself),WIZARD_MAGIC_MISSILE)
END

IF
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_HOLD_PERSON)
THEN
	RESPONSE #100
		Spell(NearestEnemyOf(Myself),WIZARD_HOLD_PERSON)
END

IF
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_REFLECTED_IMAGE)
THEN
	RESPONSE #100
		Spell(Myself,WIZARD_REFLECTED_IMAGE)
END

IF
	See(NearestEnemyOf(Myself))
	HaveSpell(WIZARD_GHOUL_TOUCH)
THEN
	RESPONSE #100
		Spell(Myself,WIZARD_GHOUL_TOUCH)
		AttackOneRound(LastSeenBy(Myself))
		AttackOneRound(LastSeenBy(Myself))
		AttackOneRound(LastSeenBy(Myself))
END

IF
	See(NearestEnemyOf(Myself))
THEN
	RESPONSE #30
		ForceSpell(LastSeenBy(Myself),WIZARD_MAGIC_MISSILE)
	RESPONSE #30
		ForceSpell(LastSeenBy(Myself),WIZARD_CHROMATIC_ORB)
	RESPONSE #30
		ForceSpell(LastSeenBy(Myself),WIZARD_LARLOCH_MINOR_DRAIN)
	RESPONSE #30
		ForceSpell(LastSeenBy(Myself),WIZARD_BURNING_HANDS)
	RESPONSE #30
		EquipMostDamagingMelee()
		AttackReevaluate(LastSeenBy(Myself),15)
END

IF
	!See(NearestEnemyOf(Myself))
THEN
	RESPONSE #100
		RandomWalk()
END


