IF
	Global("BattleBegun","LOCALS",0)
	OR(4)
		Detect([GOODCUTOFF])
		Detect(NearestEnemyOf(Myself))
		HPPercentLT(Myself,100)
		CheckStatLT(Myself,55,RESISTMAGIC)
THEN
	RESPONSE #100
		SetGlobal("BattleBegun","LOCALS",1)
END

IF
	Detect(NearestEnemyOf(Myself))
	!GlobalTimerNotExpired("SpSequencer","LOCALS")
THEN
	RESPONSE #100
		SetGlobalTimer("SpSequencer","LOCALS",1000)
		SetGlobal("SeqUsed","LOCALS",1)
		DisplayString(Myself,39969) // Spell Sequencer - Fired
		ReallyForceSpell(Myself,DRAGON_STONE_SKIN)
		ReallyForceSpell(Myself,CLERIC_DEATH_WARD)
		ForceSpell(LastSeenBy(Myself),WIZARD_DISPEL_MAGIC)
END

IF
	See(NearestEnemyOf(Myself))
	!GlobalTimerNotExpired("DRAGONFEAR","LOCALS")
THEN
	RESPONSE #100
		SetGlobalTimer("DRAGONFEAR","LOCALS",100)
		PlaySound("BLACK01")
		ReallyForceSpell(NearestEnemyOf(Myself),DRAGON_FEAR)
		ReallyForceSpell(NearestEnemyOf(Myself),0)
		ForceSpell(LastSeenBy(Myself),DRAGON_WING_BUFFET)
END

IF
	OR(3)
		SpellCast([GOODCUTOFF],WIZARD_INCENDIARY_CLOUD)
		SpellCast([GOODCUTOFF],WIZARD_STINKING_CLOUD)
		SpellCast([GOODCUTOFF],WIZARD_DEATH_FOG)
	!GlobalTimerNotExpired("WINGBUFFET","LOCALS")
THEN
	RESPONSE #100
		SetGlobalTimer("WINGBUFFET","LOCALS",8)
		ApplySpell(Myself,0)
		ForceSpell(NearestEnemyOf(Myself),DRAGON_WING_BUFFET)
END

IF
	Allegiance(Myself,ENEMY)
	OR(7)
		See([GOODCUTOFF.0.0.0.0.ILLUSIONARY])
		StateCheck(NearestEnemyOf(Myself),STATE_INVISIBLE)
		StateCheck(NearestEnemyOf(Myself),STATE_IMPROVEDINVISIBILITY)
		StateCheck(SecondNearestEnemyOf(Myself),STATE_INVISIBLE)
		StateCheck(SecondNearestEnemyOf(Myself),STATE_IMPROVEDINVISIBILITY)
		StateCheck(ThirdNearestEnemyOf(Myself),STATE_INVISIBLE)
		StateCheck(ThirdNearestEnemyOf(Myself),STATE_IMPROVEDINVISIBILITY)
	!GlobalTimerNotExpired("DragonSight","LOCALS")
THEN
	RESPONSE #100
		SetGlobalTimer("DragonSight","LOCALS",60)
		ReallyForceSpell(Myself,WIZARD_TRUE_SIGHT)
END

IF
	Allegiance(Myself,ENEMY)
	CheckStat(Myself,0,STONESKINS)
	Global("SeqUsed","LOCALS",1)
	Global("BattleBegun","LOCALS",1)
	!GlobalTimerNotExpired("DragonStoneSkin","LOCALS")
	RandomNum(2,1)
THEN
	RESPONSE #100
		SetGlobalTimer("DragonStoneSkin","LOCALS",30)
		ForceSpell(Myself,DRAGON_STONE_SKIN)
END

IF
	!Allegiance(Myself,ENEMY)
THEN
	RESPONSE #100
		NoAction()
END

IF
	See(NearestEnemyOf(Myself))
	!StateCheck(LastSeenBy(Myself),STATE_REALLY_DEAD)
THEN
	RESPONSE #100
		Continue()
END

IF
	OR(3)
		See(SecondNearestEnemyOfType([GOODCUTOFF.0.0.BARD]))
		See(SecondNearestEnemyOfType([GOODCUTOFF.0.0.DRUID_ALL]))
		See(SecondNearestEnemyOfType([GOODCUTOFF.0.0.CLERIC_ALL]))
	!StateCheck(LastSeenBy(Myself),STATE_SILENCED)
	!StateCheck(LastSeenBy(Myself),STATE_REALLY_DEAD)
THEN
	RESPONSE #100
		Continue()
END

IF
	OR(3)
		See(NearestEnemyOfType([GOODCUTOFF.0.0.BARD]))
		See(NearestEnemyOfType([GOODCUTOFF.0.0.DRUID_ALL]))
		See(NearestEnemyOfType([GOODCUTOFF.0.0.CLERIC_ALL]))
	!StateCheck(LastSeenBy(Myself),STATE_SILENCED)
	!StateCheck(LastSeenBy(Myself),STATE_REALLY_DEAD)
THEN
	RESPONSE #100
		Continue()
END

IF
	OR(2)
		See(ThirdNearestEnemyOfType([GOODCUTOFF.0.0.LONG_BOW]))
		See(ThirdNearestEnemyOfType([GOODCUTOFF.0.0.SORCERER]))
	!StateCheck(LastSeenBy(Myself),STATE_SILENCED)
	!StateCheck(LastSeenBy(Myself),STATE_REALLY_DEAD)
THEN
	RESPONSE #100
		Continue()
END

IF
	OR(2)
		See(SecondNearestEnemyOfType([GOODCUTOFF.0.0.LONG_BOW]))
		See(SecondNearestEnemyOfType([GOODCUTOFF.0.0.SORCERER]))
	!StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
	!StateCheck(LastSeenBy(Myself),STATE_STUNNED)
	!StateCheck(LastSeenBy(Myself),STATE_PANIC)
	!StateCheck(LastSeenBy(Myself),STATE_SILENCED)
	!StateCheck(LastSeenBy(Myself),STATE_REALLY_DEAD)
THEN
	RESPONSE #100
		Continue()
END

IF
	OR(2)
		See(NearestEnemyOfType([GOODCUTOFF.0.0.LONG_BOW]))
		See(NearestEnemyOfType([GOODCUTOFF.0.0.SORCERER]))
	!StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
	!StateCheck(LastSeenBy(Myself),STATE_STUNNED)
	!StateCheck(LastSeenBy(Myself),STATE_PANIC)
	!StateCheck(LastSeenBy(Myself),STATE_SILENCED)
	!StateCheck(LastSeenBy(Myself),STATE_REALLY_DEAD)
THEN
	RESPONSE #100
		Continue()
END

IF
	AttackedBy([ANYONE],DEFAULT)
	See(LastAttackerOf(Myself))
	!StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
	!StateCheck(LastSeenBy(Myself),STATE_STUNNED)
	!StateCheck(LastSeenBy(Myself),STATE_PANIC)
	!StateCheck(LastSeenBy(Myself),STATE_REALLY_DEAD)
THEN
	RESPONSE #100
		Continue()
END

IF
	Range(NearestEnemyOf(Myself),4)
	See(NearestEnemyOf(Myself))
	!StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
	!StateCheck(LastSeenBy(Myself),STATE_STUNNED)
	!StateCheck(LastSeenBy(Myself),STATE_PANIC)
	!StateCheck(LastSeenBy(Myself),STATE_REALLY_DEAD)
THEN
	RESPONSE #100
		Continue()
END

IF
	!Allegiance(LastSeenBy(Myself),GOODCUTOFF)
	See([GOODCUTOFF])
THEN
	RESPONSE #100
		MoveToObject([GOODCUTOFF])
END

IF
	OR(2)
		!Allegiance(LastSeenBy(Myself),GOODCUTOFF)
		!See([GOODCUTOFF])
	HPPercentLT(Myself,50)
THEN
	RESPONSE #100
		SpellNoDec(Myself,CLERIC_HEAL)
END

IF
	OR(2)
		!Allegiance(LastSeenBy(Myself),GOODCUTOFF)
		!See([GOODCUTOFF])
	!HPPercentLT(Myself,50)
	Global("BattleBegun","LOCALS",1)
THEN
	RESPONSE #100
		RandomWalkContinuous()
END

IF
	OR(2)
		!Allegiance(LastSeenBy(Myself),GOODCUTOFF)
		!See([GOODCUTOFF])
	!HPPercentLT(Myself,50)
	Global("BattleBegun","LOCALS",0)
THEN
	RESPONSE #100
		NoAction()
END

IF
	!GlobalTimerNotExpired("WINGBUFFET","LOCALS")
	Range(LastSeenBy(Myself),10)
	RandomNum(2,1)
THEN
	RESPONSE #100
		SetGlobalTimer("WINGBUFFET","LOCALS",8)
		ForceSpell(LastSeenBy(Myself),DRAGON_WING_BUFFET)
		Wait(1)
END

IF
	!Range(LastSeenBy(Myself),10)
	!GlobalTimerNotExpired("GREENDRAGONBREATH","LOCALS")
THEN
	RESPONSE #100
		SetGlobalTimer("GREENDRAGONBREATH","LOCALS",8)
		ForceSpell(LastSeenBy(Myself),GREEN_DRAGON_BREATH)
		ReallyForceSpellRES("DrGrBrHt",LastSeenBy(Myself)) // No such index
END

IF
	Allegiance(Myself,ENEMY)
	Range(LastSeenBy(Myself),15)
	RandomNum(3,1)
	!GlobalTimerNotExpired("dbPlant","LOCALS")
THEN
	RESPONSE #100
		SetGlobalTimer("dbPlant","LOCALS",1000)
		ForceSpell(Myself,BLACK_DRAGON_PLANT)
END

IF
	!GlobalTimerNotExpired("dbOffense1","LOCALS")
	RandomNum(2,1)
	OR(5)
		Class(LastSeenBy(Myself),DRUID_ALL)
		Class(LastSeenBy(Myself),CLERIC_ALL)
		Class(LastSeenBy(Myself),BARD_ALL)
		Class(LastSeenBy(Myself),LONG_BOW)
		Class(LastSeenBy(Myself),SORCERER)
	!CheckStatGT(LastSeenBy(Myself),50,RESISTMAGIC)
THEN
	RESPONSE #100
		ForceSpell(LastSeenBy(Myself),BLACK_DRAGON_INSECT)
		SetGlobalTimer("dbOffense1","LOCALS",21)
END

IF
	!GlobalTimerNotExpired("dbCharm","LOCALS")
	RandomNum(3,1)
	!CheckStatGT(LastSeenBy(Myself),50,RESISTMAGIC)
	HasBounceEffects(LastSeenBy(Myself))
	!StateCheck(LastSeenBy(Myself),STATE_CHARMED)
THEN
	RESPONSE #100
		SetGlobalTimer("dbCharm","LOCALS",100)
		ForceSpell(LastSeenBy(Myself),WIZARD_DOMINATION)
END

IF
	True()
THEN
	RESPONSE #100
		EquipMostDamagingMelee()
		AttackReevaluate(LastSeenBy(Myself),30)
END
