IF
  HPLT(Myself,20)
  Global("Death","LOCALS",0)
THEN
  RESPONSE #100
    SetGlobal("Death","LOCALS",1)
    StartDialogNoSet(Player1)
END

IF
  OnCreation()
THEN
  RESPONSE #100
    Face(0)
END

IF
  AttackedBy([GOODCUTOFF],DEFAULT)
  Allegiance(Myself,NEUTRAL)
THEN
  RESPONSE #100
    Enemy()
END

IF
  See(NearestEnemyOf(Myself))
  Global("Prepare2","LOCALS",0)
  HPGT(Myself,1)
THEN
  RESPONSE #100
    SetGlobal("Prepare2","LOCALS",1)
    DisplayString(Myself,73139)
    ApplySpell(Myself,DRAGON_STONE_SKIN)
    ReallyForceSpell(Myself,BEHOLDER_SPELL_TURNING)
    ReallyForceSpell(NearestEnemyOf(Myself),2302)
END

IF
  ActionListEmpty()
  See(NearestEnemyOf(Myself))
  HPPercentLT(Myself,100)
  See(LastAttackerOf(Myself))
  !GlobalTimerNotExpired("SpellTrigger1","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("SpellTrigger1","LOCALS",1000)
    DisplayString(Myself,39968)
    ReallyForceSpell(Myself,WIZARD_IMPROVED_HASTE)
    ReallyForceSpell(Myself,HEAL_NO_VISUAL)
    ReallyForceSpell(Myself,CLERIC_RIGHTEOUS_MAGIC)
    ReallyForceSpell(Myself,CLERIC_ARMOR_OF_FAITH)
END

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

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

IF
  Allegiance(Myself,ENEMY)
  !StateCheck(Myself,STATE_INVISIBLE)
  !CheckStatGT(Myself,0,STONESKINS)
  !GlobalTimerNotExpired("DragonStoneSkin","LOCALS")
  RandomNum(2,1)
THEN
  RESPONSE #100
    SetGlobalTimer("DragonStoneSkin","LOCALS",30)
    ForceSpell(Myself,DRAGON_STONE_SKIN)
END

IF
  See(NearestEnemyOf(Myself))
  CheckStatLT(Myself,50,RESISTMAGIC)
  RandomNum(3,1)
  !GlobalTimerNotExpired("RegainMagic","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("RegainMagic","LOCALS",15)
    ApplySpell(Myself,WARRIOR_RESIST_MAGIC)
END

IF
  See(NearestEnemyOf(Myself))
  !HasBounceEffects(Myself)
  OR(3)
    See([PC.0.0.BARD_ALL])
    See([PC.0.0.MAGE_ALL])
    See([PC.0.0.SORCERER])
  !StateCheck(LastSeenBy(Myself),STATE_SILENCED)
  RandomNum(2,1)
  !GlobalTimerNotExpired("SpellTurn","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("SpellTurn","LOCALS",15)
    ForceSpell(Myself,BEHOLDER_SPELL_TURNING)
END

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

IF
  See(NearestEnemyOf(Myself))
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  RandomNumLT(31,21)
  OR(6)
    See(NearestEnemyOf(Myself))
    See(WeakestOf)
    See(WorstAC)
    See(MostDamagedOf)
    See(LastAttackerOf(Myself))
    See(LastHitter(Myself))
  RandomNumLT(28,22)
  OR(4)
    See([GOODCUTOFF.0.0.0.0.SUMMONED_DEMON])
    See([GOODCUTOFF.0.0.0.0.SUMMONED])
    See([GOODCUTOFF.0.0.0.207])
    See([GOODCUTOFF.0.0.0.0.ILLUSIONARY])
  RandomNumLT(29,23)
  OR(7)
    See([PC.0.0.RANGER_ALL])
    See([PC.0.0.PALADIN_ALL])
    See([PC.0.0.BARD_ALL])
    See([PC.0.0.DRUID_ALL])
    See([PC.0.0.CLERIC_ALL])
    See([PC.0.0.MAGE_ALL])
    See([PC.0.0.SORCERER])
  RandomNumLT(30,16)
  See(Protagonist)
  RandomNumLT(26,10)
  OR(4)
    See([GOODCUTOFF.0.0.RANGER_ALL])
    See([GOODCUTOFF.0.0.DRUID_ALL])
    See([GOODCUTOFF.0.0.PALADIN_ALL])
    See([GOODCUTOFF.0.0.CLERIC_ALL])
  RandomNumLT(27,10)
  OR(3)
    See([GOODCUTOFF.0.0.MONK])
    See([GOODCUTOFF.0.0.BARD_ALL])
    See([GOODCUTOFF.0.0.THIEF_ALL])
  RandomNumLT(24,9)
  OR(3)
    See(StrongestOf)
    See(BestAC)
    See(LeastDamagedOf)
  RandomNumLT(25,9)
  See(WeakestOf)
  RandomNumLT(23,8)
  See(WorstAC)
  RandomNumLT(21,8)
  See(MostDamagedOf)
  RandomNumLT(32,11)
  OR(2)
    See(TenthNearest([GOODCUTOFF.0.0.MAGE_ALL]))
    See(TenthNearest([GOODCUTOFF.0.0.SORCERER]))
  RandomNumLT(20,8)
  See(TenthNearestEnemyOf(Myself))
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  OR(2)
    !Allegiance(LastSeenBy(Myself),GOODCUTOFF)
    !See([GOODCUTOFF])
  HPPercentLT(Myself,50)
  GlobalLT("BP_Heal","LOCALS",5)
THEN
  RESPONSE #100
    IncrementGlobal("BP_Heal","LOCALS",1)
    SpellNoDec(Myself,CLERIC_HEAL)
END

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

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

IF
  StateCheck(LastSeenBy(Myself),STATE_CHARMED)
THEN
  RESPONSE #80
    Continue()
  RESPONSE #20
END

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

IF
  !GlobalTimerNotExpired("WINGBUFFET","LOCALS")
  !StateCheck(Myself,STATE_INVISIBLE)
  Range(NearestEnemyOf(Myself),10)
  Range(SecondNearestEnemyOf(Myself),10)
  RandomNum(3,1)
THEN
  RESPONSE #100
    SetGlobalTimer("WINGBUFFET","LOCALS",12)
    ForceSpell(NearestEnemyOf(Myself),DRAGON_WING_BUFFET)
    Wait(1)
END

IF
  !GlobalTimerNotExpired("ElectrifiedFloorTimer","AR6005")
THEN
  RESPONSE #100
    SetGlobalTimer("ElectrifiedFloorTimer","AR6005",30)
    DisplayString(Myself,72905)
    ForceSpell(Myself,ABAZIGAL_SHOCKWAVE)
    PlaySound("am6005e")
END

IF
  Range(LastSeenBy(Myself),30)
  !GlobalTimerNotExpired("BROWNDRAGONBREATH","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("BROWNDRAGONBREATH","LOCALS",12)
    ForceSpell(LastSeenBy(Myself),BROWN_DRAGON_BREATH)
END

IF
  See(NearestEnemyOf(Myself))
  !Range(NearestEnemyOf(Myself),10)
  GlobalTimerExpired("BLUEDRAGONBREATH","GLOBAL")
THEN
  RESPONSE #100
    SetGlobal("WingBuffet","LOCALS",0)
    ForceSpell(NearestEnemyOf(Myself),BLUE_DRAGON_BREATH)
    ReallyForceSpell(NearestEnemyOf(Myself),SILVER_DRAGON_BREATH_PARALIZATION)
    SetGlobalTimer("BLUEDRAGONBREATH","GLOBAL",18)
END

IF
  See(NearestEnemyOf(Myself))
  Global("Offense1","LOCALS",0)
THEN
  RESPONSE #100
    ForceSpell(NearestEnemyOf(Myself),WIZARD_GREATER_MALISON)
    SetGlobal("Offense1","LOCALS",1)
END

IF
  See(NearestEnemyOf(Myself))
  Global("HoldPerson","LOCALS",0)
THEN
  RESPONSE #100
    ForceSpell(NearestEnemyOf(Myself),CLERIC_HOLD_PERSON)
    SetGlobal("HoldPerson","LOCALS",1)
END

IF
  Global("Silence","LOCALS",0)
  OR(5)
    Class(LastSeenBy(Myself),DRUID_ALL)
    Class(LastSeenBy(Myself),BARD_ALL)
    Class(LastSeenBy(Myself),CLERIC_ALL)
    Class(LastSeenBy(Myself),MAGE_ALL)
    Class(LastSeenBy(Myself),SORCERER)
THEN
  RESPONSE #100
    ForceSpell(LastSeenBy(Myself),DRAGON_SILENCE)
    SetGlobal("Silence","LOCALS",1)
    AttackOneRound(LastSeenBy(Myself))
    AttackOneRound(LastSeenBy(Myself))
END

IF
  Delay(6)
  GlobalLT("CharmPerson","LOCALS",3)
THEN
  RESPONSE #100
    ForceSpell(LastSeenBy(Myself),WIZARD_CHARM_PERSON)
    IncrementGlobal("CharmPerson","LOCALS",1)
END

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

IF
  Allegiance(Myself,ENEMY)
THEN
  RESPONSE #100
    MoveToObject(NearestEnemyOf(Myself))
END

