IF
  OR(5)
    Heard([ANYONE],3010)
    HPPercentLT(Myself,100)
    SpellCastInnateRES("SPCL412",[GOODCUTOFF])
    SpellCastInnateRES("SPCL414",[GOODCUTOFF])
    CheckStatLT(Myself,65,RESISTMAGIC)
  Allegiance(Myself,NEUTRAL)
THEN
  RESPONSE #100
    Enemy()
END

IF
  OR(2)
    !Detect([PC])
    !Detect(LastAttackerOf(Myself))
  Allegiance(Myself,ENEMY)
THEN
  RESPONSE #100
    MoveToObject(Player1)
END

IF
  !StateCheck(SixthNearestEnemyOf(Myself),STATE_HELPLESS)
  See(SixthNearestEnemyOf(Myself))
  False()
THEN
  RESPONSE #100
END

IF
  !StateCheck(FifthNearestEnemyOf(Myself),STATE_HELPLESS)
  See(FifthNearestEnemyOf(Myself))
  False()
THEN
  RESPONSE #100
END

IF
  !StateCheck(FourthNearestEnemyOf(Myself),STATE_HELPLESS)
  See(FourthNearestEnemyOf(Myself))
  False()
THEN
  RESPONSE #100
END

IF
  !StateCheck(ThirdNearestEnemyOf(Myself),STATE_HELPLESS)
  See(ThirdNearestEnemyOf(Myself))
  False()
THEN
  RESPONSE #100
END

IF
  !StateCheck(SecondNearestEnemyOf(Myself),STATE_HELPLESS)
  See(SecondNearestEnemyOf(Myself))
  False()
THEN
  RESPONSE #100
END

IF
  !StateCheck(NearestEnemyOf(Myself),STATE_HELPLESS)
  See(NearestEnemyOf(Myself))
  False()
THEN
  RESPONSE #100
END

IF
  !StateCheck(NearestEnemyOfType([GOODCUTOFF.0.0.BARD_ALL]),STATE_HELPLESS)
  See(NearestEnemyOfType([GOODCUTOFF.0.0.BARD_ALL]))
  False()
THEN
  RESPONSE #100
END

IF
  !StateCheck(SecondNearestEnemyOfType([GOODCUTOFF.0.0.CLERIC_ALL]),STATE_HELPLESS)
  See(SecondNearestEnemyOfType([GOODCUTOFF.0.0.CLERIC_ALL]))
  False()
THEN
  RESPONSE #100
END

IF
  !StateCheck(NearestEnemyOfType([GOODCUTOFF.0.0.CLERIC_ALL]),STATE_HELPLESS)
  See(NearestEnemyOfType([GOODCUTOFF.0.0.CLERIC_ALL]))
  False()
THEN
  RESPONSE #100
END

IF
  !StateCheck(NearestEnemyOfType([GOODCUTOFF.0.0.DRUID_ALL]),STATE_HELPLESS)
  See(NearestEnemyOfType([GOODCUTOFF.0.0.DRUID_ALL]))
  False()
THEN
  RESPONSE #100
END

IF
  !StateCheck(SecondNearestEnemyOfType([GOODCUTOFF.0.0.LONG_BOW]),STATE_HELPLESS)
  See(SecondNearestEnemyOfType([GOODCUTOFF.0.0.LONG_BOW]))
  False()
THEN
  RESPONSE #100
END

IF
  !StateCheck(NearestEnemyOfType([GOODCUTOFF.0.0.LONG_BOW]),STATE_HELPLESS)
  See(NearestEnemyOfType([GOODCUTOFF.0.0.LONG_BOW]))
  False()
THEN
  RESPONSE #100
END

IF
  !StateCheck(NearestEnemyOfType([GOODCUTOFF.0.0.SORCERER]),STATE_HELPLESS)
  See(NearestEnemyOfType([GOODCUTOFF.0.0.SORCERER]))
  False()
THEN
  RESPONSE #100
END

IF
  Global("RemoveMagic","LOCALS",0)
THEN
  RESPONSE #100
    ForceSpell(Myself,DRAGON_STONE_SKIN)
    ForceSpell(LastSeenBy(Myself),0)
    SetGlobal("StoneSkin","LOCALS",1)
    SetGlobal("RemoveMagic","LOCALS",1)
END

IF
  !Detect([PC])
  HPLT(Myself,50)
  CombatCounter(0)
THEN
  RESPONSE #100
    SetGlobal("RemoveMagic","LOCALS",0)
    SetGlobal("WingBuffet","LOCALS",0)
    SetGlobal("Haste","LOCALS",0)
    SetGlobal("DRAGONFEAR","LOCALS",0)
    ForceSpell(Myself,CLERIC_HEAL)
END

IF
  Global("DRAGONFEAR","LOCALS",0)
THEN
  RESPONSE #100
    ReallyForceSpell(LastSeenBy(Myself),DRAGON_FEAR)
    ReallyForceSpell(LastSeenBy(Myself),DRAGON_LOWER_FIRE)
    SetGlobal("DRAGONFEAR","LOCALS",1)
    SetGlobalTimer("REDDRAGONBREATH","GLOBAL",1)
    ForceSpell(LastSeenBy(Myself),DRAGON_WING_BUFFET)
END

IF
  GlobalTimerExpired("REDDRAGONBREATH","GLOBAL")
  Range(LastSeenBy(Myself),11)
  Global("WingBuffet","LOCALS",0)
THEN
  RESPONSE #100
    ForceSpell(LastSeenBy(Myself),DRAGON_WING_BUFFET)
    Wait(1)
    SetGlobal("WingBuffet","LOCALS",1)
  RESPONSE #60
    Continue()
END

IF
  !Range(LastSeenBy(Myself),10)
  GlobalTimerExpired("REDDRAGONBREATH","GLOBAL")
THEN
  RESPONSE #100
    SetGlobal("WingBuffet","LOCALS",0)
    ForceSpell(LastSeenBy(Myself),3396)
    ReallyForceSpell(LastSeenBy(Myself),RED_DRAGON_HIT)
    SetGlobalTimer("REDDRAGONBREATH","GLOBAL",18)
END

IF
  Global("WingBuffet","LOCALS",1)
  Range(LastSeenBy(Myself),11)
THEN
  RESPONSE #100
    SetGlobal("WingBuffet","LOCALS",0)
    SetGlobalTimer("REDDRAGONBREATH","GLOBAL",18)
END

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

IF
  Global("Haste","LOCALS",0)
THEN
  RESPONSE #100
    ForceSpell(Myself,WIZARD_HASTE)
    SetGlobal("Haste","LOCALS",1)
END

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

IF
  Global("Silence","LOCALS",0)
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
  Allegiance(LastSeenBy(Myself),GOODCUTOFF)
THEN
  RESPONSE #100
    EquipMostDamagingMelee()
    AttackReevaluate(NearestEnemyOf(Myself),35)
  RESPONSE #10
    ForceSpell(LastSeenBy(Myself),WIZARD_MELF_ACID_ARROW)
END


