IF
  See(NearestEnemyOf(Myself))
  Global("RemoveMagic","LOCALS",0)
THEN
  RESPONSE #100
    ForceSpell(Myself,DRAGON_STONE_SKIN)
    ForceSpell(Myself,WIZARD_HASTE)
    ForceSpell(LastSeenBy(Myself),2302)//WIZARD_REMOVE_MAGIC)
    SetGlobal("StoneSkin","LOCALS",1)
    SetGlobal("RemoveMagic","LOCALS",1)
END

IF
  See(NearestEnemyOf(Myself))
  Global("animate","Locals",0)
THEN
  RESPONSE #100
    ReallyForceSpell(Myself,WIZARD_ANIMATE_DEAD)
    ReallyForceSpell(Myself,WIZARD_ANIMATE_DEAD)
    ReallyForceSpell(Myself,WIZARD_ANIMATE_DEAD)
    SetGlobal("animate","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
  See(NearestEnemyOf(Myself))
  Global("DRAGONFEAR","LOCALS",0)
THEN
  RESPONSE #100
    ReallyForceSpell(NearestEnemyOf(Myself),DRAGON_FEAR)
    SetGlobal("DRAGONFEAR","LOCALS",1)
    SetGlobalTimer("BLACKDRAGONBREATH","GLOBAL",1)
    SetGlobalTimer("bdFlapping","GLOBAL",1)
    ForceSpell(LastSeenBy(Myself),DRAGON_WING_BUFFET)
END

IF
  GlobalTimerExpired("BLACKDRAGONBREATH","GLOBAL")
  GlobalTimerExpired("bdFlapping","GLOBAL")
  See(NearestEnemyOf(Myself))
  Range(LastSeenBy(Myself),11)
  Global("WingBuffet","LOCALS",0)
THEN
  RESPONSE #100
    ForceSpell(LastSeenBy(Myself),DRAGON_WING_BUFFET)
    SetGlobalTimer("BLACKDRAGONBREATH","GLOBAL",2)
    Wait(1)
    SetGlobal("WingBuffet","LOCALS",1)
  RESPONSE #30
    Continue()
END

IF
  See(NearestEnemyOf(Myself))
  !Range(LastSeenBy(Myself),10)
  Range(LastSeenBy(Myself),17)
  GlobalTimerExpired("BLACKDRAGONBREATH","GLOBAL")
THEN
  RESPONSE #100
    ForceSpell(LastSeenBy(Myself),BLACK_DRAGON_BREATH)
    SetGlobal("WingBuffet","LOCALS",0)
    SetGlobalTimer("BLACKDRAGONBREATH","GLOBAL",THREE_ROUNDS)
END

IF
  Global("WingBuffet","LOCALS",1)
  See(NearestEnemyOf(Myself))
  Range(LastSeenBy(Myself),10)
THEN
  RESPONSE #100
    RunAwayFrom(LastSeenBy(Myself),60)
    SetGlobal("WingBuffet","LOCALS",0)
    SetGlobalTimer("BLACKDRAGONBREATH","GLOBAL",THREE_ROUNDS)
END

IF
  Allegiance(Myself,ENEMY)
  Range(NearestEnemyOf(Myself),15)
  Global("dbPlant","LOCALS",0)
THEN
  RESPONSE #100
    SetGlobalTimer("bdFlapping","GLOBAL",80)
    ForceSpell(Myself,BLACK_DRAGON_PLANT)
    SetGlobal("dbPlant","LOCALS",1)
END

IF
  See(NearestEnemyOf(Myself))
  Global("dbOffense1","LOCALS",0)
THEN
  RESPONSE #100
    ForceSpell(LastSeenBy(Myself),BLACK_DRAGON_INSECT)
    SetGlobal("dbOffense1","LOCALS",1)
END

IF
  HaveSpellRES("SPMI144")
  !GlobalTimerNotExpired("BP_MagicScreen","LOCALS")
THEN
  RESPONSE #100
    SpellRES("SPMI144",Myself)  // ~Anti-Magic Cloud~
    SetGlobalTimer("BP_MagicScreen","LOCALS",ONE_TURN)
END

IF
  See(NearestEnemyOf(Myself))
  !Range(NearestEnemyOf(Myself),10)
  HaveSpell(WIZARD_TIME_STOP)
  RandomNumLT(3,3)
THEN
  RESPONSE #100
    Spell(Myself,WIZARD_TIME_STOP)
END

IF
  HaveSpell(WIZARD_ABI_DALZIMS_HORRID_WILTING)
  OR(4)
    See(NearestEnemyOf(Myself))
    See(SecondNearestEnemyOf(Myself))
    See(ThirdNearestEnemyOf(Myself))
    See(SixthNearestEnemyOf(Myself))
  !Range(LastSeenBy(Myself),10)
  RandomNumLT(40,21)
THEN
  RESPONSE #100
    Spell([ENEMY],WIZARD_ABI_DALZIMS_HORRID_WILTING)
END

IF
  HaveSpell(WIZARD_IMPRISONMENT)
  OR(4)
    See(NearestEnemyOf(Myself))
    See(SecondNearestEnemyOf(Myself))
    See(ThirdNearestEnemyOf(Myself))
    See(SixthNearestEnemyOf(Myself))
  RandomNumLT(14,8)
THEN
  RESPONSE #100
    Spell(LastSeenBy(Myself),WIZARD_IMPRISONMENT)
END

IF
  HaveSpellRES("SPMI103")
THEN
  RESPONSE #100
    SpellRES("SPMI103",NearestEnemyOf(Myself))  // ~Spirit Rot~
END

IF
  HaveSpell(WIZARD_VAMPIRIC_TOUCH)
  HPPercentLT(Myself,75)
  See(NearestEnemyOf(Myself))
  Range(LastSeenBy(Myself),7)
  RandomNumLT(141,71)
THEN
  RESPONSE #100
    Spell(Myself,WIZARD_VAMPIRIC_TOUCH)
    AttackOneRound(LastSeenBy(Myself))
END

IF
  HaveSpell(WIZARD_CONE_OF_COLD)
  OR(4)
    See(NearestEnemyOf(Myself))
    See(SecondNearestEnemyOf(Myself))
    See(ThirdNearestEnemyOf(Myself))
    See(SixthNearestEnemyOf(Myself))
  !HasBounceEffects(LastSeenBy(Myself))
  RandomNumLT(61,31)
THEN
  RESPONSE #100
    Spell(LastSeenBy(Myself),WIZARD_CONE_OF_COLD)
END

IF
  HaveSpell(WIZARD_MAGIC_MISSILE)
  CheckStatLT(LastSeenBy(Myself),50,RESISTMAGIC)
  !HasBounceEffects(LastSeenBy(Myself))
  RandomNumLT(79,28)
THEN
  RESPONSE #100
    Spell(LastSeenBy(Myself),WIZARD_MAGIC_MISSILE)
END

IF
  HaveSpell(WIZARD_HORROR)
  OR(4)
    See(NearestEnemyOf(Myself))
    See(SecondNearestEnemyOf(Myself))
    See(ThirdNearestEnemyOf(Myself))
    See(SixthNearestEnemyOf(Myself))
  CheckStatLT(LastSeenBy(Myself),50,RESISTMAGIC)
  CheckStatGT(LastSeenBy(Myself),8,SAVEVSSPELL)
  RandomNumLT(42,11)
THEN
  RESPONSE #100
    Spell(LastSeenBy(Myself),WIZARD_HORROR)
END

IF
  HaveSpell(WIZARD_LARLOCH_MINOR_DRAIN)
  See(NearestEnemyOf(Myself))
  Range(LastSeenBy(Myself),5)
  HPPercentLT(Myself,90)
  !HasItem("BLAKBLAD",Myself)  // ~Black Blade of Disaster~
  !HasItem("PHANBLAD",Myself)  // ~Phantom Blade~
  !HasItem("MELFMET",Myself)  // ~Melf's Minute Meteor~
  !HasItem("ENEBLADE",Myself)  // ~Energy Blade~
  RandomNumLT(143,29)
THEN
  RESPONSE #100
    Spell(Myself,WIZARD_LARLOCH_MINOR_DRAIN)
    AttackReevaluate(LastSeenBy(Myself),30)
END

IF
  See(NearestEnemyOf(Myself))
THEN
  RESPONSE #100
    EquipMostDamagingMelee()
    AttackReevaluate(NearestEnemyOf(Myself),35)
  RESPONSE #30
    ForceSpell(LastSeenBy(Myself),WIZARD_CHARM_PERSON)
END

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

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

