IF
  Die()
THEN
  RESPONSE #100
    Shout(66)
END

IF
  Global("BPCHARM","LOCALS",1)
  !StateCheck(Myself,STATE_CHARMED)
THEN
  RESPONSE #100
    SetGlobal("BPCHARM","LOCALS",0)
    ClearActions(Myself)
    Continue()
END

IF
  OR(2)
    Heard([NEUTRAL],79)
    Heard([EVILCUTOFF],79)
  Allegiance(Myself,NEUTRAL)
  !Global("BP_PlotMan","LOCALS",1)
THEN
  RESPONSE #100
    Enemy()
END

IF
  Global("NOBREACH","LOCALS",0)
  !HaveSpell(WIZARD_BREACH)
  !HaveSpell(WIZARD_SPELL_STRIKE)
  !HaveSpell(WIZARD_PIERCE_SHIELD)
  !HaveSpell(WIZARD_RUBY_RAY_OF_REVERSAL)
  !HaveSpell(WIZARD_WARDING_WHIP)
  !HaveSpell(WIZARD_PIERCE_MAGIC)
  !HaveSpell(WIZARD_SECRET_WORD)
  !HaveSpell(WIZARD_SPELL_THRUST)
THEN
  RESPONSE #100
    SetGlobal("NOBREACH","LOCALS",1)
    Continue()
END

IF
  Global("TimeStop","LOCALS",1)
THEN
  RESPONSE #30
    ForceSpell(LastSeenBy(Myself),WIZARD_POWER_WORD_STUN)
    RemoveSpell(WIZARD_POWER_WORD_STUN)
    ForceSpell(LastSeenBy(Myself),WIZARD_NPC_SYMBOL_STUN)
    RemoveSpell(WIZARD_NPC_SYMBOL_STUN)
    ForceSpell(LastSeenBy(Myself),WIZARD_SUMMON_EFREET)
    RemoveSpell(WIZARD_SUMMON_EFREET)
    ForceSpell(Myself,WIZARD_SHADOW_DOOR)
    RemoveSpell(WIZARD_SHADOW_DOOR)
    SetGlobalTimer("BPIP","LOCALS",15)
    SetGlobal("TimeStop","LOCALS",0)
  RESPONSE #25
    ForceSpell(LastSeenBy(Myself),WIZARD_FINGER_OF_DEATH)
    RemoveSpell(WIZARD_FINGER_OF_DEATH)
    ForceSpell(NearestEnemyOf(Myself),WIZARD_MAZE)
    RemoveSpell(WIZARD_MAZE)
    ForceSpell(SecondNearestEnemyOf(Myself),WIZARD_IMPRISONMENT)
    RemoveSpell(WIZARD_IMPRISONMENT)
    ForceSpell(ThirdNearestEnemyOf(Myself),WIZARD_FLESH_TO_STONE)
    RemoveSpell(WIZARD_FLESH_TO_STONE)
    SetGlobal("TimeStop","LOCALS",0)
  RESPONSE #25
    ForceSpell(LastSeenBy(Myself),WIZARD_METEOR_SWARM)
    RemoveSpell(WIZARD_METEOR_SWARM)
    ForceSpell(LastSeenBy(Myself),WIZARD_ABI_DALZIMS_HORRID_WILTING)
    RemoveSpell(WIZARD_ABI_DALZIMS_HORRID_WILTING)
    MoveToObject(LastSeenBy(Myself))
    ForceSpell(LastSeenBy(Myself),WIZARD_WAIL_OF_THE_BANSHEE)
    RemoveSpell(WIZARD_WAIL_OF_THE_BANSHEE)
    ForceSpell(LastSeenBy(Myself),WIZARD_PRISMATIC_SPRAY)
    RemoveSpell(WIZARD_PRISMATIC_SPRAY)
    SetGlobal("TimeStop","LOCALS",0)
  RESPONSE #20
    ForceSpell(LastSeenBy(Myself),WIZARD_SPELL_STRIKE)
    RemoveSpell(WIZARD_SPELL_STRIKE)
    ForceSpell(LastSeenBy(Myself),WIZARD_DOMINATION)
    RemoveSpell(WIZARD_DOMINATION)
    ForceSpell(SecondNearestEnemyOf(Myself),WIZARD_POLYMORPH_OTHER)
    RemoveSpell(WIZARD_POLYMORPH_OTHER)
    ForceSpell(ThirdNearestEnemyOf(Myself),WIZARD_SLOW)
    RemoveSpell(WIZARD_SLOW)
    SetGlobal("TimeStop","LOCALS",0)
END  

IF
  Global("BP_BOMB","LOCALS",2)
  See([PC])
THEN
  RESPONSE #100
    SetGlobal("BP_BOMB","LOCALS",0)
    SetGlobal("BP_BOMBSAWAY","MYAREA",0)
    SetGlobal("BP_CHASER","LOCALS",0)
    SetGlobal("BP_CHASE","LOCALS",0)
    SmallWait(10)
    ActionOverride("BPTARGET",DestroySelf())
END

IF
  Global("BP_BOMB","LOCALS",1)
THEN
  RESPONSE #100
    SetGlobal("BP_BOMB","LOCALS",2)
    ReallyForceSpellRES("BPTARGET",Myself)
END

IF
  GlobalTimerNotExpired("BPCHASE","LOCALS")
  Global("BPCHASER","LOCALS",1)
  OR(2)
    See([GOODCUTOFF])
    See(LastHitter(Myself))
THEN
  RESPONSE #20
    DisplayStringHead(Myself,@0)
    SetGlobal("BPCHASER","LOCALS",0)
    AttackReevaluate(LastSeenBy(Myself),15)
  RESPONSE #20
    DisplayStringHead(Myself,@0)
    SetGlobal("BPCHASER","LOCALS",0)
    SetGlobalTimer("BPT","LOCALS",6)
    ForceSpell(LastSeenBy(Myself),WIZARD_NPC_SYMBOL_STUN)
    RemoveSpell(WIZARD_NPC_SYMBOL_STUN)
    AttackReevaluate(LastSeenBy(Myself),15)
  RESPONSE #20
    DisplayStringHead(Myself,@0)
    SetGlobal("BPCHASER","LOCALS",0)
    SetGlobalTimer("BPT","LOCALS",6)
    ForceSpell(LastSeenBy(Myself),WIZARD_ABI_DALZIMS_HORRID_WILTING)
    RemoveSpell(WIZARD_ABI_DALZIMS_HORRID_WILTING)
  RESPONSE #20
    DisplayStringHead(Myself,@0)
    SetGlobal("BPCHASER","LOCALS",0)
    SetGlobalTimer("BPT","LOCALS",6)
    ForceSpell(LastSeenBy(Myself),WIZARD_IMPRISONMENT)
    RemoveSpell(WIZARD_IMPRISONMENT)
  RESPONSE #10
    DisplayStringHead(Myself,@0)
    SetGlobal("BPCHASER","LOCALS",0)
    SetGlobalTimer("BPT","LOCALS",6)
    ForceSpell(LastSeenBy(Myself),WIZARD_SUMMON_EFREET)
    RemoveSpell(WIZARD_SUMMON_EFREET)
  RESPONSE #5
    DisplayStringHead(Myself,@0)
    SetGlobal("BPCHASER","LOCALS",0)
    SetGlobalTimer("BPT","LOCALS",6)
    ForceSpell(LastSeenBy(Myself),WIZARD_SPELL_STRIKE)
    RemoveSpell(WIZARD_SPELL_STRIKE)
END

IF
  GlobalTimerExpired("BPCHASE","LOCALS")
  Global("BPCHASER","LOCALS",1)
  !See([GOODCUTOFF])
  !See(LastHitter(Myself))
THEN
  RESPONSE #100
    DisplayStringHead(Myself,@1)
    SetGlobal("BPCHASER","LOCALS",0)
    ClearActions(Myself)
    Continue()
END

IF
  !Allegiance(Myself,ENEMY)
  !Allegiance(Myself,PC)
  OR(2)
    AttackedBy([GOODCUTOFF],DEFAULT)
    Allegiance(LastAttackerOf(Myself),GOODCUTOFF)
THEN
  RESPONSE #100
    Shout(151)
    Enemy()
    Continue()
END

IF
  !Allegiance(Myself,ENEMY)
  !Allegiance(Myself,GOODCUTOFF)
  OR(2)
    HitBy([GOODCUTOFF],CRUSHING)
    Allegiance(LastHitter(Myself),GOODCUTOFF)
THEN
  RESPONSE #100
    Shout(151)
    Enemy()
    Continue()
END

IF
  Global("BP_BOMB","LOCALS",2)
  Global("BP_BOMBSAWAY","MYAREA",1)
  !GlobalTimerNotExpired("BPT","LOCALS")
  See([GOODBUTRED.ARMOR.ROBES.WIZARD_EYE.114])
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",3)
    ForceSpell(LastSeenBy(Myself),WIZARD_NPC_SYMBOL_STUN)
    RemoveSpell(WIZARD_NPC_SYMBOL_STUN)
    SetGlobalTimer("BP_BOMBER","LOCALS",11)
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",3)
    ForceSpell(LastSeenBy(Myself),WIZARD_ABI_DALZIMS_HORRID_WILTING)
    RemoveSpell(WIZARD_ABI_DALZIMS_HORRID_WILTING)
    SetGlobalTimer("BP_BOMBER","LOCALS",11)
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",3)
    ForceSpell(LastSeenBy(Myself),WIZARD_SUMMON_EFREET)
    RemoveSpell(WIZARD_SUMMON_EFREET)
    SetGlobalTimer("BP_BOMBER","LOCALS",11)
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",3)
    ForceSpell(LastSeenBy(Myself),WIZARD_METEOR_SWARM)
    RemoveSpell(WIZARD_METEOR_SWARM)
    SetGlobalTimer("BP_BOMBER","LOCALS",11)
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",3)
    ForceSpell(LastSeenBy(Myself),WIZARD_GREATER_MALISON)
    RemoveSpell(WIZARD_GREATER_MALISON)
    SetGlobalTimer("BP_BOMBER","LOCALS",11)
  RESPONSE #50
    SetGlobalTimer("BPT","LOCALS",3)
    ForceSpell(LastSeenBy(Myself),WIZARD_SLOW)
    RemoveSpell(WIZARD_SLOW)
    SetGlobalTimer("BP_BOMBER","LOCALS",11)
END

IF
  Global("BP_BOMB","LOCALS",2)
  Global("BP_BOMBSAWAY","MYAREA",1)
  !GlobalTimerNotExpired("BPT","LOCALS")
  !See([GOODBUTRED.ARMOR.ROBES.WIZARD_EYE.114])
THEN
  RESPONSE #100
    MoveToObject(LastHitter(Myself))
END

IF
  Global("BP_BOMB","LOCALS",2)
  GlobalTimerExpired("BP_BOMBER","LOCALS")
THEN
  RESPONSE #100
    SetGlobal("BP_BOMB","LOCALS",0)
    SetGlobal("BP_BOMBSAWAY","MYAREA",0)
    SetGlobal("BP_CHASER","LOCALS",0)
    SetGlobal("BP_CHASE","LOCALS",0)
END

IF
  TookDamage()
  Global("BPCHASER","LOCALS",0)
  !See(LastHitter(Myself))
  !See([GOODCUTOFF])
THEN
  RESPONSE #10
    DisplayStringHead(Myself,@2)
    SetGlobalTimer("BPCHASE","LOCALS",12)
    SetGlobal("BPCHASER","LOCALS",1)
    MoveToObject(LastHitter(Myself))
  RESPONSE #10
    DisplayStringHead(Myself,@2)
    SetGlobalTimer("BPCHASE","LOCALS",12)
    SetGlobal("BPCHASER","LOCALS",1)
    ReallyForceSpell(Myself,WIZARD_ABSOLUTE_IMMUNITY)
    ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_ENERGY)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("SCH","LOCALS",1)
    Wait(1)
    MoveToObject(LastHitter(Myself))
  RESPONSE #10
    DisplayStringHead(Myself,@2)
    SetGlobalTimer("BPCHASE","LOCALS",12)
    SetGlobal("BPCHASER","LOCALS",1)
    ReallyForceSpell(Myself,WIZARD_IMPROVED_MANTLE)
    ReallyForceSpell(Myself,WIZARD_SPELL_DEFLECTION)
    ReallyForceSpell(Myself,WIZARD_HASTE)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("SCH","LOCALS",1)
    Wait(1)
    MoveToObject(LastHitter(Myself))
  RESPONSE #10
    DisplayStringHead(Myself,@2)
    SetGlobalTimer("BPCHASE","LOCALS",12)
    SetGlobal("BPCHASER","LOCALS",1)
    ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_THE_ELEMENTS)
    ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_NORMAL_WEAPONS)
    ReallyForceSpell(Myself,WIZARD_MINOR_SPELL_TURNING)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("SCH","LOCALS",1)
    Wait(1)
    MoveToObject(LastHitter(Myself))
  RESPONSE #10
    DisplayStringHead(Myself,@2)
    SetGlobalTimer("BPCHASE","LOCALS",12)
    SetGlobal("BPCHASER","LOCALS",1)
    ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_ENERGY)
    ReallyForceSpell(Myself,WIZARD_SPELL_SHIELD)
    ReallyForceSpell(Myself,WIZARD_STONE_SKIN)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("SCH","LOCALS",1)
    Wait(1)
    MoveToObject(LastHitter(Myself))
  RESPONSE #10
    DisplayStringHead(Myself,@2)
    SetGlobalTimer("BPCHASE","LOCALS",12)
    SetGlobal("BPCHASER","LOCALS",1)
    ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_MAGIC_ENERGY)
    ReallyForceSpell(Myself,WIZARD_SHADOW_DOOR)
    SetGlobalTimer("BPIP","LOCALS",15)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("SCH","LOCALS",1)
    Wait(1)
    RunAwayFrom(LastHitter(Myself),45)
  RESPONSE #30
    DisplayStringHead(Myself,@3)
    SetGlobalTimer("BPCHASE","LOCALS",60)
    SetGlobal("BPCHASER","LOCALS",1)
    SetGlobal("BP_BOMB","LOCALS",1)
  RESPONSE #10
    DisplayStringHead(Myself,@2)
    RunAwayFrom(LastHitter(Myself),45)
END

IF
  CheckStatGT(Myself,10,180)
  CheckStatGT(Myself,5,INT)
  OR(2)
    See(LastAttackerOf(Myself))
    See(LastHitter(Myself))
  CheckStatLT(LastSeenBy(Myself),11,180)
  !GlobalTimerNotExpired("BPCHASE","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("BPCHASE","LOCALS",TWO_ROUNDS)
    DisplayStringHead(Myself,@4)
    EquipMostDamagingMelee()
    MoveToObject(LastSeenBy(Myself))
    AttackOneRound(LastSeenBy(Myself))
END

IF
  CheckStatGT(Myself,10,180)
  CheckStatGT(Myself,5,INT)
  OR(2)
    See(TenthNearest([GOODCUTOFF]))
    See(TenthNearest([PC]))
  CheckStatLT(LastSeenBy(Myself),11,180)
  !GlobalTimerNotExpired("BPCHASE","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("BPCHASE","LOCALS",TWO_ROUNDS)
    DisplayStringHead(Myself,@4)
    EquipMostDamagingMelee()
    MoveToObject(LastSeenBy(Myself))
    AttackOneRound(LastSeenBy(Myself))
END

IF
  CheckStatGT(Myself,10,180)
  CheckStatGT(Myself,5,INT)
  See(TenthNearest)
  CheckStatLT(TenthNearest,11,180)
  !GlobalTimerNotExpired("BPCHASE","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("BPCHASE","LOCALS",ONE_ROUND)
    DisplayStringHead(Myself,@4)
    MoveToObject(TenthNearest)
END

//////////////CLOUDLIKE  EFFECTS//////////////////////

IF
  CheckStat(Myself,11,180) // I'm in a stinking cloud
  CheckStatGT(Myself,5,INT)
  !StateCheck(Myself,STATE_SLEEPING) // not yet affected
  CheckStatGT(Myself,4,SAVEVSSPELL) //and I got a reasonable chance of failing a save throw (25%+)
  OR(2)
    Detect(NearestEnemyOfType([0.0.MORNINGSTAR.FAIRY_NYMPH.65]))
    Detect(NearestMyGroupOfType([0.0.MORNINGSTAR.FAIRY_NYMPH.65]))
  Range(LastSeenBy(Myself),16)
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    RunAwayFrom(LastSeenBy(Myself),30)
    SetInterrupt(TRUE)
END

IF
  CheckStatGT(Myself,11,180) // I'm in a web,entangle, or grease spell
  CheckStatLT(Myself,15,180)
  CheckStatGT(Myself,5,INT)
  CheckStatLT(Myself,1,131) // I don't have free action
  CheckStatLT(Myself,1,WEB) //and not webbed up
  CheckStatLT(Myself,1,ENTANGLE) //nor entangled --I can move
  CheckStatGT(Myself,4,SAVEVSSPELL) //and I got a reasonable chance of failing a save throw (25%+)
  OR(3)
    Detect([0.0.MORNINGSTAR.FAIRY_NYMPH.65])
    Detect(NearestEnemyOfType([0.0.MORNINGSTAR.FAIRY_NYMPH.65]))
    Detect(NearestMyGroupOfType([0.0.MORNINGSTAR.FAIRY_NYMPH.65]))
  Range(LastSeenBy(Myself),16)
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    RunAwayFrom(LastSeenBy(Myself),30)
    SetInterrupt(TRUE)
END

IF
  CheckStat(Myself,15,180) // I'm in an Ice Storm
  CheckStatGT(Myself,5,INT)
  CheckStatLT(Myself,100,RESISTCOLD) // Not Immune
  OR(3)
    Detect([0.0.MORNINGSTAR.FAIRY_NYMPH.65])
    Detect(NearestEnemyOfType([0.0.MORNINGSTAR.FAIRY_NYMPH.65]))
    Detect(NearestMyGroupOfType([0.0.MORNINGSTAR.FAIRY_NYMPH.65]))
  Range(LastSeenBy(Myself),16)
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    RunAwayFrom(LastSeenBy(Myself),30)
    SetInterrupt(TRUE)
END

IF
  CheckStat(Myself,16,180) // I'm in a Cloudkill or Death Fog
  CheckStatGT(Myself,5,INT)
  CheckStatLT(Myself,100,RESISTPOISON) // Not Immune
  OR(3)
    Detect([0.0.MORNINGSTAR.FAIRY_NYMPH.65])
    Detect(NearestEnemyOfType([0.0.MORNINGSTAR.FAIRY_NYMPH.65]))
    Detect(NearestMyGroupOfType([0.0.MORNINGSTAR.FAIRY_NYMPH.65]))
  Range(LastSeenBy(Myself),16)
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    RunAwayFrom(LastSeenBy(Myself),30)
    SetInterrupt(TRUE)
END

IF
  CheckStat(Myself,17,180) // I'm in a Death Fog
  CheckStatGT(Myself,5,INT)
  CheckStatLT(Myself,100,RESISTACID) // Not Immune
  OR(3)
    Detect([0.0.MORNINGSTAR.FAIRY_NYMPH.65])
    Detect(NearestEnemyOfType([0.0.MORNINGSTAR.FAIRY_NYMPH.65]))
    Detect(NearestMyGroupOfType([0.0.MORNINGSTAR.FAIRY_NYMPH.65]))
  Range(LastSeenBy(Myself),16)
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    RunAwayFrom(LastSeenBy(Myself),30)
    SetInterrupt(TRUE)
END

IF
  CheckStat(Myself,18,180) // Incendiary Cloud, Meteor Swarm or Fire Storm -- bad stuff
  CheckStatGT(Myself,5,INT)
  CheckStatLT(Myself,100,RESISTFIRE) // Not Immune
  OR(3)
    Detect([0.0.MORNINGSTAR.FAIRY_NYMPH.65])
    Detect(NearestEnemyOfType([0.0.MORNINGSTAR.FAIRY_NYMPH.65]))
    Detect(NearestMyGroupOfType([0.0.MORNINGSTAR.FAIRY_NYMPH.65]))
  Range(LastSeenBy(Myself),16)
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    RunAwayFrom(LastSeenBy(Myself),30)
    SetInterrupt(TRUE)
END

// This is to try and keep them from going back in to whomp somebody
IF
  CheckStatLT(Myself,11,180) // No longer in the cloud effects
  CheckStatGT(Myself,5,INT)
  OR(3)
    Detect([0.0.MORNINGSTAR.FAIRY_NYMPH.65])
    Detect(NearestEnemyOfType([0.0.MORNINGSTAR.FAIRY_NYMPH.65]))
    Detect(NearestMyGroupOfType([0.0.MORNINGSTAR.FAIRY_NYMPH.65]))
  !Range(LastSeenBy(Myself),16)
  Exists([EVILCUTOFF])
  !Range(NearestEnemyOf(Myself),2)
THEN
  RESPONSE #100
    EquipRanged()  //use your bow, then
    SmallWait(3)
    Continue()
END

//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////

IF
  OR(2)
    !Allegiance(Myself,EVILCUTOFF)
    !Detect([GOODCUTOFF])
THEN
  RESPONSE #100
END

IF
  ActionListEmpty()
  SpellCast(Myself,0)
  HaveAnySpells()
  HitBy([ANYONE],CRUSHING)
  NumCreatureGT([EVILCUTOFF],3)
  !GlobalTimerNotExpired("SBN","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("SBN","LOCALS",15)
    DisplayStringHead(Myself,64573)
    Shout(69)
END

IF
  Range(NearestEnemyOf(Myself),2)
  OR(2)
    CheckStatGT(NearestEnemyOf(Myself),0,121)
    CheckStatGT(NearestEnemyOf(Myself),0,125)
THEN
  RESPONSE #70
    RunAwayFrom(NearestEnemyOf(Myself),4)
  RESPONSE #30
    Continue()
END

IF
  HPPercentLT(Myself,50)
  !GlobalTimerNotExpired("POT","LOCALS")
  HasItem("POTN55",Myself)
THEN
  RESPONSE #100
    SetGlobalTimer("POT","LOCALS",ONE_ROUND)
    DisplayStringHead(Myself,46150)
    UseItem("POTN55",Myself)
END

IF
  HPPercentLT(Myself,60)
  !GlobalTimerNotExpired("POT","LOCALS")
  HasItem("POTN52",Myself)
THEN
  RESPONSE #100
    SetGlobalTimer("POT","LOCALS",ONE_ROUND)
    DisplayStringHead(Myself,46150)
    UseItem("POTN52",Myself)
END

IF
  ActionListEmpty()
  HPPercentLT(Myself,35)
  See([EVILCUTOFF])
  !GlobalTimerNotExpired("BPW","LOCALS")
  !HasItem("POTN52",Myself)
  !HasItem("POTN55",Myself)
THEN
  RESPONSE #80
    SetGlobalTimer("BPW","LOCALS",ONE_ROUND)
    DisplayStringHead(Myself,72808)
    Shout(123)
  RESPONSE #20
    Continue()
END

IF
  ActionListEmpty()
  StateCheck(Myself,STATE_POISONED)
  !GlobalTimerNotExpired("POIS","LOCALS")
  See([EVILCUTOFF])
  !HasItem("POTN17",Myself)
  !HasItem("POTN20",Myself)
THEN
  RESPONSE #100
    Shout(83)
    DisplayStringHead(Myself,@5)
    SetGlobalTimer("POIS","LOCALS",ONE_ROUND)
END

IF
  Global("SNAFU","LOCALS",0)
  OR(3)
    CheckStatGT(Myself,60,SPELLFAILUREMAGE)
    CheckStatGT(Myself,0,SCRIPTINGSTATE4)
    StateCheck(Myself,STATE_SILENCED)
THEN
  RESPONSE #100
    SetGlobal("SNAFU","LOCALS",1)
END

IF
  Global("SNAFU","LOCALS",1)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
  CheckStat(Myself,0,SCRIPTINGSTATE4)
  !StateCheck(Myself,STATE_SILENCED)
THEN
  RESPONSE #100
    SetGlobal("SNAFU","LOCALS",0)
END

IF
  ActionListEmpty()
  !GlobalTimerNotExpired("CHE","LOCALS")
  Global("SNAFU","LOCALS",0)
  GlobalLT("SCH","LOCALS",4)
  Detect(NearestEnemyOf(Myself))
THEN
  RESPONSE #50
    ReallyForceSpell(Myself,WIZARD_ABSOLUTE_IMMUNITY)
    ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_ENERGY)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("SCH","LOCALS",1)
  RESPONSE #50
    ReallyForceSpell(Myself,WIZARD_BLACK_BLADE_OF_DISASTER)
    ReallyForceSpell(Myself,WIZARD_IMPROVED_INVISIBILITY)
    ReallyForceSpell(Myself,WIZARD_STONE_SKIN)
    SetGlobalTimer("BPIP","LOCALS",15)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("SCH","LOCALS",1)
  RESPONSE #50
    ReallyForceSpell(Myself,WIZARD_IMPROVED_MANTLE)
    ReallyForceSpell(Myself,WIZARD_SPELL_DEFLECTION)
    ReallyForceSpell(Myself,WIZARD_HASTE)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("SCH","LOCALS",1)
  RESPONSE #50
    ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_ENERGY)
    ReallyForceSpell(Myself,WIZARD_SPELL_SHIELD)
    ReallyForceSpell(Myself,WIZARD_STONE_SKIN)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("SCH","LOCALS",1)
  RESPONSE #50
    ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
    ReallyForceSpell(Myself,WIZARD_SPELL_TURNING)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("SCH","LOCALS",1)
  RESPONSE #50
    ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_THE_ELEMENTS)
    ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_NORMAL_WEAPONS)
    ReallyForceSpell(Myself,WIZARD_MINOR_SPELL_TURNING)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("SCH","LOCALS",1)
  RESPONSE #50
    ReallyForceSpell(Myself,WIZARD_MANTLE)
    ReallyForceSpell(Myself,WIZARD_SPELL_DEFLECTION)
    ReallyForceSpell(Myself,WIZARD_MELF_METEOR)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("SCH","LOCALS",1)
  RESPONSE #50
    ReallyForceSpell(Myself,WIZARD_IMPROVED_MANTLE)
    ReallyForceSpell(Myself,WIZARD_PHANTOM_BLADE)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("SCH","LOCALS",1)
  RESPONSE #50
    ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_MAGIC_ENERGY)
    ReallyForceSpell(Myself,WIZARD_SHADOW_DOOR)
    SetGlobalTimer("BPIP","LOCALS",15)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("SCH","LOCALS",1)
  RESPONSE #50
    ReallyForceSpell(Myself,WIZARD_TENSERS_TRANSFORMATION)
    ReallyForceSpell(Myself,WIZARD_HASTE)
    ReallyForceSpell(Myself,WIZARD_BLACK_BLADE_OF_DISASTER)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("SCH","LOCALS",1)
END

IF
  TargetUnreachable(LastSeenBy(Myself))
  Delay(3)
THEN
  RESPONSE #100
    ClearActions(Myself)
    Continue()
END

IF
  ActionListEmpty()
  !GlobalTimerNotExpired("BPT","LOCALS")
  HaveSpell(WIZARD_TIME_STOP)
  HPPercentLT(Myself,50)
  Global("TimeStop","LOCALS",0)
THEN
  RESPONSE #100
    SetGlobal("TimeStop","LOCALS",1)
    ForceSpell(Myself,WIZARD_IMPROVED_ALUCRITY)
    DisplayStringHead(Myself,63217)
    Spell(Myself,WIZARD_TIME_STOP)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_VOCALIZE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  !GlobalTimerNotExpired("BPVOCAL","LOCALS")
  StateCheck(Myself,STATE_SILENCED)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    SetGlobalTimer("BPVOCAL","LOCALS",60)
    Spell(Myself,WIZARD_VOCALIZE)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_TRUE_SIGHT)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  CheckStat(Myself,0,118)
  Exists(NearestEnemyOf(Myself))
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
  OR(9)
    SpellCast([GOODCUTOFF],WIZARD_PROJECT_IMAGE)
    SpellCast([GOODCUTOFF],WIZARD_MISLEAD)
    StateCheck(NearestEnemyOfType([GOODCUTOFF]),0x60400010)
    StateCheck(SecondNearestEnemyOfType([GOODCUTOFF]),0x60400010)
    StateCheck(ThirdNearestEnemyOfType([GOODCUTOFF]),0x60400010)
    StateCheck(FourthNearestEnemyOfType([GOODCUTOFF]),0x60400010)
    StateCheck(FifthNearestEnemyOfType([GOODCUTOFF]),0x60400010)
    StateCheck(SixthNearestEnemyOfType([GOODCUTOFF]),0x60400010)
    NumCreatureGT([GOODCUTOFF.0.0.0.0.ILLUSIONARY],0)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    DisplayStringHead(Myself,@6)
    Spell(Myself,WIZARD_TRUE_SIGHT)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_SHADOW_DOOR)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  RandomNum(4,4)
  AttackedBy([ANYTHING],DEFAULT)
  !StateCheck(Myself,STATE_POISONED)
  !StateCheck(Myself,STATE_BLUR)
  !StateCheck(Myself,STATE_MIRRORIMAGE)
  !StateCheck(Myself,0x400010)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
  CheckStatLT(NearestEnemyOf,1,SEEINVISIBLE)
  CheckStatLT(SecondNearestEnemyOf,1,SEEINVISIBLE)
  CheckStatLT(ThirdNearestEnemyOf,1,SEEINVISIBLE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPIP","LOCALS",15)
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_SHADOW_DOOR)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_SPELL_TURNING)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  RandomNumLT(7,3)
  CheckStat(Myself,0,164)
  CheckStat(Myself,0,116)
  CheckStat(Myself,0,129)
  CheckStat(Myself,0,177)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
  OR(5)
    Exists(NearestEnemyOfType([0.0.0.LONG_BOW]))
    Exists(NearestEnemyOfType([0.0.0.CLERIC_ALL]))
    Exists(NearestEnemyOfType([0.0.0.BARD_ALL]))
    Exists(NearestEnemyOfType([0.0.0.DRUID_ALL]))
    Exists(NearestEnemyOfType([0.0.0.SORCERER]))
  OR(4) // Either nobody's close, or we're protected in some way from melee
    !Range(NearestEnemyOf(Myself),3)
    CheckStatGT(Myself,0,STONESKINS)
    CheckStatGT(Myself,0,181)
    CheckStatGT(Myself,0,128)      
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_SPELL_TURNING)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_FIRE_SHIELD_RED)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  RandomNumLT(19,5)
  CheckStat(Myself,0,128)
  CheckStat(Myself,0,125)
  CheckStat(Myself,0,SHIELDGLOBE)
  Range(NearestEnemyOf(Myself),4)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_FIRE_SHIELD_RED)
END


IF
  OR(3)
    !Race(NearestEnemyOf(Myself),MORNINGSTAR)
    !Class(NearestEnemyOf(Myself),FAIRY_NYMPH)
    !Specifics(NearestEnemyOf(Myself),65)
  See(NearestEnemyOf(Myself))
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  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.SIMULACRUM])
    See([GOODCUTOFF.0.0.0.0.ILLUSIONARY])
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  RandomNumLT(31,26)
  OR(6)
    See(NearestEnemyOf(Myself))
    See(WeakestOf)
    See(WorstAC)
    See(MostDamagedOf)
    See(LastAttackerOf(Myself))
    See(LastHitter(Myself))
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  OR(3)
    Allegiance(LastSeenBy(Myself),ENEMY)
    Allegiance(LastSeenBy(Myself),EVILCUTOFF)
    Allegiance(LastSeenBy(Myself),GOODBUTRED)
THEN
  RESPONSE #100
END

IF
  Race(LastSeenBy(Myself),MORNINGSTAR)
  Class(LastSeenBy(Myself),FAIRY_NYMPH)
  Specifics(LastSeenBy(Myself),65)
THEN
  RESPONSE #100
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_DOMINATION)
  StateCheck(LastSeenBy(Myself),STATE_CHARMED)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStatLT(LastSeenBy(Myself),51,RESISTMAGIC)
  CheckStatGT(LastSeenBy(Myself),5,SAVEVSSPELL)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #80
    Spell(LastSeenBy(Myself),WIZARD_DOMINATION)
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
  RESPONSE #20
    Continue()
END

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


IF
  ActionListEmpty()
  CheckStatGT(Myself,0,182)
THEN
  RESPONSE #100
    AttackOneRound(LastSeenBy(Myself))
END

IF
  ActionListEmpty()
  HPPercentGT(Myself,35)
  OR(4)
    Global("SNAFU","LOCALS",1)
    HasItem("BLAKBLAD",Myself)
    HasItem("PHANBLAD",Myself)
    HasItem("MELFMET",Myself)
THEN
  RESPONSE #75
    AttackOneRound(LastSeenBy(Myself))
  RESPONSE #25
    Continue()
END

IF
  OR(2)
    StateCheck(Myself,STATE_INVISIBLE)
    StateCheck(Myself,STATE_IMPROVEDINVISIBILITY)
  GlobalTimerNotExpired("BPIP","LOCALS")
THEN
  RESPONSE #15
    Continue()
  RESPONSE #60
    IncrementGlobal("BPIP","LOCALS",-1)
  RESPONSE #90
    RunAwayFrom(NearestEnemyOf(Myself),10)
END


IF
  RandomNumLT(30,13)
  OR(6)
    See(NearestEnemyOfType([PC]))
    See(SecondNearestEnemyOfType([PC]))
    See(ThirdNearestEnemyOfType([PC]))
    See(FourthNearestEnemyOfType([PC]))
    See(FifthNearestEnemyOfType([PC]))
    See(SixthNearestEnemyOfType([PC]))
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  RandomNumGT(30,20)
  OR(6)
    See(NearestEnemyOfType([GOODCUTOFF]))
    See(SecondNearestEnemyOfType([GOODCUTOFF]))
    See(ThirdNearestEnemyOfType([GOODCUTOFF]))
    See(FourthNearestEnemyOfType([GOODCUTOFF]))
    See(FifthNearestEnemyOfType([GOODCUTOFF]))
    See(SixthNearestEnemyOfType([GOODCUTOFF]))
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  RandomNumGT(30,15)
  RandomNumLT(30,19)
  See(Protagonist)
  False()
THEN
  RESPONSE #100
    Continue()
END
  
IF
  RandomNumLT(29,20)
  OR(7)
    See(NearestEnemyOfType([PC.0.0.RANGER_ALL]))
    See(NearestEnemyOfType([PC.0.0.PALADIN_ALL]))
    See(NearestEnemyOfType([PC.0.0.BARD_ALL]))
    See(NearestEnemyOfType([PC.0.0.DRUID_ALL]))
    See(NearestEnemyOfType([PC.0.0.CLERIC_ALL]))
    See(NearestEnemyOfType([PC.0.0.LONG_BOW]))
    See(NearestEnemyOfType([PC.0.0.SORCERER]))
  OR(7)
    See(SecondNearestEnemyOfType([PC.0.0.RANGER_ALL]))
    See(SecondNearestEnemyOfType([PC.0.0.PALADIN_ALL]))
    See(SecondNearestEnemyOfType([PC.0.0.BARD_ALL]))
    See(SecondNearestEnemyOfType([PC.0.0.DRUID_ALL]))
    See(SecondNearestEnemyOfType([PC.0.0.CLERIC_ALL]))
    See(SecondNearestEnemyOfType([PC.0.0.LONG_BOW]))
    See(SecondNearestEnemyOfType([PC.0.0.SORCERER]))
  OR(7)
    See(ThirdNearestEnemyOfType([PC.0.0.RANGER_ALL]))
    See(ThirdNearestEnemyOfType([PC.0.0.PALADIN_ALL]))
    See(ThirdNearestEnemyOfType([PC.0.0.BARD_ALL]))
    See(ThirdNearestEnemyOfType([PC.0.0.DRUID_ALL]))
    See(ThirdNearestEnemyOfType([PC.0.0.CLERIC_ALL]))
    See(ThirdNearestEnemyOfType([PC.0.0.LONG_BOW]))
    See(ThirdNearestEnemyOfType([PC.0.0.SORCERER]))
  OR(7)
    See(FourthNearestEnemyOfType([PC.0.0.RANGER_ALL]))
    See(FourthNearestEnemyOfType([PC.0.0.PALADIN_ALL]))
    See(FourthNearestEnemyOfType([PC.0.0.BARD_ALL]))
    See(FourthNearestEnemyOfType([PC.0.0.DRUID_ALL]))
    See(FourthNearestEnemyOfType([PC.0.0.CLERIC_ALL]))
    See(FourthNearestEnemyOfType([PC.0.0.LONG_BOW]))
    See(FourthNearestEnemyOfType([PC.0.0.SORCERER]))
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  RandomNumLT(26,14)
  OR(12)
    See(NearestEnemyOfType([GOODCUTOFF.0.0.BARD_ALL]))
    See(NearestEnemyOfType([GOODCUTOFF.0.0.LONG_BOW]))
    See(NearestEnemyOfType([GOODCUTOFF.0.0.SORCERER]))
    See(SecondNearestEnemyOfType([GOODCUTOFF.0.0.BARD_ALL]))
    See(SecondNearestEnemyOfType([GOODCUTOFF.0.0.LONG_BOW]))
    See(SecondNearestEnemyOfType([GOODCUTOFF.0.0.SORCERER]))
    See(ThirdNearestEnemyOfType([GOODCUTOFF.0.0.BARD_ALL]))
    See(ThirdNearestEnemyOfType([GOODCUTOFF.0.0.LONG_BOW]))
    See(ThirdNearestEnemyOfType([GOODCUTOFF.0.0.SORCERER]))
    See(FourthNearestEnemyOfType([GOODCUTOFF.0.0.BARD_ALL]))
    See(FourthNearestEnemyOfType([GOODCUTOFF.0.0.LONG_BOW]))
    See(FourthNearestEnemyOfType([GOODCUTOFF.0.0.SORCERER]))
  RandomNumLT(27,10)
  OR(12)
    See(NearestEnemyOfType([GOODCUTOFF.0.0.RANGER_ALL]))
    See(NearestEnemyOfType([GOODCUTOFF.0.0.PALADIN_ALL]))
    See(NearestEnemyOfType([GOODCUTOFF.0.0.DRUID_ALL]))
    See(NearestEnemyOfType([GOODCUTOFF.0.0.CLERIC_ALL]))
    See(SecondNearestEnemyOfType([GOODCUTOFF.0.0.RANGER_ALL]))
    See(SecondNearestEnemyOfType([GOODCUTOFF.0.0.PALADIN_ALL]))
    See(SecondNearestEnemyOfType([GOODCUTOFF.0.0.DRUID_ALL]))
    See(SecondNearestEnemyOfType([GOODCUTOFF.0.0.CLERIC_ALL]))
    See(ThirdNearestEnemyOfType([GOODCUTOFF.0.0.RANGER_ALL]))
    See(ThirdNearestEnemyOfType([GOODCUTOFF.0.0.PALADIN_ALL]))
    See(ThirdNearestEnemyOfType([GOODCUTOFF.0.0.DRUID_ALL]))
    See(ThirdNearestEnemyOfType([GOODCUTOFF.0.0.CLERIC_ALL]))
  RandomNumLT(32,12)
  OR(9)
    See(NearestEnemyOfType([GOODCUTOFF.0.0.MONK]))
    See(NearestEnemyOfType([GOODCUTOFF.0.0.THIEF_ALL]))
    See(NearestEnemyOfType([GOODCUTOFF.0.0.BARD_ALL]))
    See(SecondNearestEnemyOfType([GOODCUTOFF.0.0.MONK]))
    See(SecondNearestEnemyOfType([GOODCUTOFF.0.0.THIEF_ALL]))
    See(SecondNearestEnemyOfType([GOODCUTOFF.0.0.BARD_ALL]))
    See(ThirdNearestEnemyOfType([GOODCUTOFF.0.0.MONK]))
    See(ThirdNearestEnemyOfType([GOODCUTOFF.0.0.THIEF_ALL]))
    See(ThirdNearestEnemyOfType([GOODCUTOFF.0.0.BARD_ALL]))
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_WAIL_OF_THE_BANSHEE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(55,35)
  HPGT(LastSeenBy(Myself),50)
  CheckStatGT(LastSeenBy(Myself),5,SAVEVSDEATH)
  CheckStatLT(LastSeenBy(Myself),1,157)
  !StateCheck(LastSeenBy(Myself),STATE_BERSERK)
  !General(LastSeenBy(Myself),UNDEAD)
  !Range(NearestEnemyOf(Myself),8)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
    RESPONSE #100
        SetGlobalTimer("SPL_CAST","LOCALS",6)
        Spell(LastSeenBy(Myself),WIZARD_WAIL_OF_THE_BANSHEE)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_POWER_WORD_STUN)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(48,32)
  OR(2)
    Global("NOBREACH","LOCALS",1)
    RandomNumLT(99,23)
  !StateCheck(LastSeenBy(Myself),0x00102029)  // STATE_HARMLESS (includes sleeping)
  !StateCheck(LastSeenBy(Myself),STATE_BERSERK)
  HPGT(LastSeenBy(Myself),40)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_POWER_WORD_STUN)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_POWER_WORD_STUN)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(48,32)
  Global("NOBREACH","LOCALS",1)
  OR(2)
    CheckStat(LastSeenBy(Myself),0,129)
    RandomNumLT(99,23)
  CheckStat(LastSeenBy(Myself),0,177)
  CheckStat(LastSeenBy(Myself),0,116)
  CheckStat(LastSeenBy(Myself),0,164)
  !StateCheck(LastSeenBy(Myself),0x00102029)  // STATE_HARMLESS (includes sleeping)
  !StateCheck(LastSeenBy(Myself),STATE_BERSERK)
  HPGT(LastSeenBy(Myself),40)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_POWER_WORD_STUN)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_NPC_SYMBOL_STUN)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(51,32)
  !StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
  !StateCheck(LastSeenBy(Myself),STATE_BERSERK)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  OR(4) // Either nobody's close, or we're protected in some way from melee
    !Range(NearestEnemyOf(Myself),3)
    CheckStatGT(Myself,0,STONESKINS)
    CheckStatGT(Myself,0,181)
    CheckStatGT(Myself,0,128)      
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_NPC_SYMBOL_STUN)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_ABI_DALZIMS_HORRID_WILTING)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(58,38)
  CheckStatLT(LastSeenBy(Myself),76,MAGICDAMAGERESISTANCE)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
  OR(4) // Either nobody's close, or we're protected in some way from melee
    !Range(NearestEnemyOf(Myself),3)
    CheckStatGT(Myself,0,STONESKINS)
    CheckStatGT(Myself,0,181)
    CheckStatGT(Myself,0,128)      
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_ABI_DALZIMS_HORRID_WILTING)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_METEOR_SWARM)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(59,36)
  OR(2)
    !Range(LastSeenBy(Myself),16)
    CheckStatGT(Myself,74,RESISTFIRE)
  OR(4)
    !Exists(NearestMyGroupOfType)
    Range(NearestMyGroupOfType,3)
    CheckStatGT(NearestMyGroupOfType,49,RESISTFIRE)
    CheckStatGT(NearestMyGroupOfType,49,RESISTMAGIC)
  OR(4)
    !Exists(SecondNearestMyGroupOfType)
    Range(SecondNearestMyGroupOfType,4)
    CheckStatGT(SecondNearestMyGroupOfType,49,RESISTFIRE)
    CheckStatGT(SecondNearestMyGroupOfType,49,RESISTMAGIC)
  OR(4)
    !Exists(ThirdNearestMyGroupOfType)
    Range(ThirdNearestMyGroupOfType,5)
    CheckStatGT(ThirdNearestMyGroupOfType,49,RESISTFIRE)
    CheckStatGT(ThirdNearestMyGroupOfType,49,RESISTMAGIC)
  !StateCheck(LastSeenBy(Myself),0x00400010)
  CheckStatLT(LastSeenBy(Myself),76,RESISTFIRE)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
  OR(4) // Either nobody's close, or we're protected in some way from melee
    !Range(NearestEnemyOf(Myself),3)
    CheckStatGT(Myself,0,STONESKINS)
    CheckStatGT(Myself,0,181)
    CheckStatGT(Myself,0,128)      
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_METEOR_SWARM)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_PRISMATIC_SPRAY)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(60,36)
  Range(LastSeenBy(Myself),8)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
  OR(4) // Either nobody's close, or we're protected in some way from melee
    !Range(NearestEnemyOf(Myself),3)
    CheckStatGT(Myself,0,STONESKINS)
    CheckStatGT(Myself,0,181)
    CheckStatGT(Myself,0,128)      
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_PRISMATIC_SPRAY)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_IMPRISONMENT)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(59,27)
  OR(2)
    Global("NOBREACH","LOCALS",1)
    RandomNumLT(99,23)
  !CheckStat(LastSeenBy(Myself),1,SCRIPTINGSTATE4)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
  OR(3)
    HPGT(LastSeenBy(Myself),50)
    Class(LastSeenBy(Myself),MAGE_ALL)
    Class(LastSeenBy(Myself),SORCERER)
  OR(4) // Either nobody's close, or we're protected in some way from melee
    !Range(NearestEnemyOf(Myself),3)
    CheckStatGT(Myself,0,STONESKINS)
    CheckStatGT(Myself,0,181)
    CheckStatGT(Myself,0,128)      
THEN
  RESPONSE #100
    Spell(LastSeenBy(Myself),WIZARD_IMPRISONMENT)
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_MAZE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  OR(2)
    Global("NOBREACH","LOCALS",1)
    RandomNumLT(99,23)
  RandomNumLT(69,42)
  OR(3)
    HPGT(LastSeenBy(Myself),50)
    Class(LastSeenBy(Myself),MAGE_ALL)
    Class(LastSeenBy(Myself),SORCERER)
  !StateCheck(LastSeenBy(Myself),STATE_BERSERK)
  Range(LastSeenBy(Myself),5) // only has a range of 3
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_MAZE)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_MAZE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("NOBREACH","LOCALS",0)
  RandomNumLT(69,42)
  OR(3)
    HPGT(LastSeenBy(Myself),50)
    Class(LastSeenBy(Myself),MAGE_ALL)
    Class(LastSeenBy(Myself),SORCERER)
  OR(2)
    CheckStat(LastSeenBy(Myself),0,129)
    RandomNumLT(99,23)
  CheckStat(LastSeenBy(Myself),0,177)
  CheckStat(LastSeenBy(Myself),0,116)
  CheckStat(LastSeenBy(Myself),0,164)
  !StateCheck(LastSeenBy(Myself),STATE_BERSERK)
  Range(LastSeenBy(Myself),5) // only has a range of 3
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_MAZE)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_FLESH_TO_STONE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  OR(2)
    Global("NOBREACH","LOCALS",1)
    RandomNumLT(99,23)
  RandomNumLT(72,37)
  CheckStat(LastSeenBy(Myself),0,176)
  CheckStatGT(LastSeenBy(Myself),5,SAVEVSSPELL)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_FLESH_TO_STONE)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_FLESH_TO_STONE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("NOBREACH","LOCALS",0)
  RandomNumLT(72,37)
  OR(2)
    CheckStat(LastSeenBy(Myself),0,129)
    RandomNumLT(99,23)
  CheckStat(LastSeenBy(Myself),0,177)
  CheckStat(LastSeenBy(Myself),0,116)
  CheckStat(LastSeenBy(Myself),0,164)
  CheckStat(LastSeenBy(Myself),0,176)
  CheckStatGT(LastSeenBy(Myself),5,SAVEVSSPELL)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_FLESH_TO_STONE)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_SPELL_STRIKE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(52,34)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
  OR(13)
    Specifics(LastSeenBy(Myself),211)
    Specifics(LastSeenBy(Myself),212)
    Specifics(LastSeenBy(Myself),205)
    CheckStatGT(LastSeenBy(Myself),0,STONESKINS)
    CheckStatGT(LastSeenBy(Myself),0,SHIELDGLOBE)
    CheckStatGT(LastSeenBy(Myself),0,MINORGLOBE)
    CheckStatGT(LastSeenBy(Myself),0,116)
    CheckStatGT(LastSeenBy(Myself),0,128)
    CheckStatGT(LastSeenBy(Myself),0,129)
    CheckStatGT(LastSeenBy(Myself),1,162)
    CheckStatGT(LastSeenBy(Myself),1,164)
    CheckStatGT(LastSeenBy(Myself),0,177)
    CheckStatGT(LastSeenBy(Myself),0,181)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_SPELL_STRIKE)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_FINGER_OF_DEATH)
  !GlobalTimerNotExpired("BPT","LOCALS")
  OR(2)
    Global("NOBREACH","LOCALS",1)
    RandomNumLT(99,23)
  RandomNumLT(68,38)
  CheckStat(LastSeenBy(Myself),0,157)
  CheckStatGT(LastSeenBy(Myself),5,SAVEVSSPELL)
  !StateCheck(LastSeenBy(Myself),STATE_BERSERK)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
  OR(4) // Either nobody's close, or we're protected in some way from melee
    !Range(NearestEnemyOf(Myself),3)
    CheckStatGT(Myself,0,STONESKINS)
    CheckStatGT(Myself,0,181)
    CheckStatGT(Myself,0,128)      
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_FINGER_OF_DEATH)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_FINGER_OF_DEATH)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("NOBREACH","LOCALS",0)
  RandomNumLT(68,38)
  OR(2)
    CheckStat(LastSeenBy(Myself),0,129)
    RandomNumLT(99,23)
  CheckStat(LastSeenBy(Myself),0,177)
  CheckStat(LastSeenBy(Myself),0,116)
  CheckStat(LastSeenBy(Myself),0,164)
  CheckStat(LastSeenBy(Myself),0,157)
  CheckStatGT(LastSeenBy(Myself),5,SAVEVSSPELL)
  !StateCheck(LastSeenBy(Myself),STATE_BERSERK)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
  OR(4) // Either nobody's close, or we're protected in some way from melee
    !Range(NearestEnemyOf(Myself),3)
    CheckStatGT(Myself,0,STONESKINS)
    CheckStatGT(Myself,0,181)
    CheckStatGT(Myself,0,128)      
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_FINGER_OF_DEATH)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_SLOW)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(82,48)
  !StateCheck(LastSeenBy(Myself),STATE_SLOWED)
  CheckStatLT(LastSeenBy(Myself),1,131)
  CheckStatGT(LastSeenBy(Myself),5,SAVEVSSPELL)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_SLOW)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_SUMMON_EFREET)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(86,46)
  NumCreatureLT([EVILCUTOFF.0.0.0.0.SUMMONED],7)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
  OR(4) // Either nobody's close, or we're protected in some way from melee
    !Range(NearestEnemyOf(Myself),3)
    CheckStatGT(Myself,0,STONESKINS)
    CheckStatGT(Myself,0,181)
    CheckStatGT(Myself,0,128)      
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_SUMMON_EFREET)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_DOMINATION)
  !GlobalTimerNotExpired("BPT","LOCALS")
  OR(2)
    Global("NOBREACH","LOCALS",1)
    RandomNumLT(99,23)
  RandomNumLT(84,46)
  CheckStat(LastSeenBy(Myself),0,119)
  !StateCheck(LastSeenBy(Myself),STATE_CHARMED)
  !StateCheck(LastSeenBy(Myself),STATE_BERSERK)
  !General(LastSeenBy(Myself),UNDEAD)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
  OR(6)
    HPGT(LastSeenBy(Myself),40)
    Class(LastSeenBy(Myself),DRUID_ALL)
    Class(LastSeenBy(Myself),BARD_ALL)
    Class(LastSeenBy(Myself),CLERIC_ALL)
    Class(LastSeenBy(Myself),LONG_BOW)
    Class(LastSeenBy(Myself),SORCERER)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_DOMINATION)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_DOMINATION)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("NOBREACH","LOCALS",0)
  RandomNumLT(84,46)
  CheckStat(LastSeenBy(Myself),0,119)
  OR(2)
    CheckStat(LastSeenBy(Myself),0,129)
    RandomNumLT(99,23)
  CheckStat(LastSeenBy(Myself),0,177)
  CheckStat(LastSeenBy(Myself),0,116)
  CheckStat(LastSeenBy(Myself),0,164)
  !StateCheck(LastSeenBy(Myself),STATE_CHARMED)
  !StateCheck(LastSeenBy(Myself),STATE_BERSERK)
  !General(LastSeenBy(Myself),UNDEAD)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
  OR(6)
    HPGT(LastSeenBy(Myself),40)
    Class(LastSeenBy(Myself),DRUID_ALL)
    Class(LastSeenBy(Myself),BARD_ALL)
    Class(LastSeenBy(Myself),CLERIC_ALL)
    Class(LastSeenBy(Myself),LONG_BOW)
    Class(LastSeenBy(Myself),SORCERER)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_DOMINATION)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_FLAME_ARROW)
  !GlobalTimerNotExpired("BPT","LOCALS")
  OR(2)
    Global("NOBREACH","LOCALS",1)
    RandomNumLT(99,23)
  RandomNumLT(113,60)
  CheckStatLT(LastSeenBy(Myself),51,RESISTFIRE)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  CheckStat(LastSeenBy(Myself),0,MINORGLOBE)
  CheckStatGT(LastSeenBy(Myself),5,SAVEVSSPELL)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_FLAME_ARROW)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_FLAME_ARROW)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("NOBREACH","LOCALS",0)
  RandomNumLT(113,60)
  OR(2)
    CheckStat(LastSeenBy(Myself),0,129)
    RandomNumLT(99,23)
  CheckStat(LastSeenBy(Myself),0,177)
  CheckStat(LastSeenBy(Myself),0,116)
  CheckStat(LastSeenBy(Myself),0,164)
  CheckStatLT(LastSeenBy(Myself),51,RESISTFIRE)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  CheckStat(LastSeenBy(Myself),0,MINORGLOBE)
  CheckStatGT(LastSeenBy(Myself),5,SAVEVSSPELL)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_FLAME_ARROW)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_POLYMORPH_OTHER)
  !GlobalTimerNotExpired("BPT","LOCALS")
  OR(2)
    Global("NOBREACH","LOCALS",1)
    RandomNumLT(99,23)
  RandomNumLT(105,39)
  CheckStat(LastSeenBy(Myself),0,POLYMORPHED)
  CheckStatGT(LastSeenBy(Myself),5,SAVEVSPOLY)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
  OR(6)
    HPGT(LastSeenBy(Myself),40)
    Class(LastSeenBy(Myself),DRUID_ALL)
    Class(LastSeenBy(Myself),BARD_ALL)
    Class(LastSeenBy(Myself),CLERIC_ALL)
    Class(LastSeenBy(Myself),LONG_BOW)
    Class(LastSeenBy(Myself),SORCERER)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_POLYMORPH_OTHER)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_POLYMORPH_OTHER)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("NOBREACH","LOCALS",0)
  RandomNumLT(105,39)
  OR(2)
    CheckStat(LastSeenBy(Myself),0,129)
    RandomNumLT(99,23)
  CheckStat(LastSeenBy(Myself),0,177)
  CheckStat(LastSeenBy(Myself),0,116)
  CheckStat(LastSeenBy(Myself),0,164)
  CheckStat(LastSeenBy(Myself),0,POLYMORPHED)
  CheckStatGT(LastSeenBy(Myself),5,SAVEVSPOLY)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
  OR(6)
    HPGT(LastSeenBy(Myself),40)
    Class(LastSeenBy(Myself),DRUID_ALL)
    Class(LastSeenBy(Myself),BARD_ALL)
    Class(LastSeenBy(Myself),CLERIC_ALL)
    Class(LastSeenBy(Myself),LONG_BOW)
    Class(LastSeenBy(Myself),SORCERER)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_POLYMORPH_OTHER)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_MELF_ACID_ARROW)
  !GlobalTimerNotExpired("BPT","LOCALS")
  OR(2)
    Global("NOBREACH","LOCALS",1)
    RandomNumLT(99,23)
  RandomNumLT(108,38)
  CheckStat(LastSeenBy(Myself),0,MINORGLOBE)
  CheckStatLT(LastSeenBy(Myself),51,RESISTACID)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_MELF_ACID_ARROW)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_MELF_ACID_ARROW)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("NOBREACH","LOCALS",0)
  RandomNumLT(108,38)
  OR(2)
    CheckStat(LastSeenBy(Myself),0,129)
    RandomNumLT(99,23)
  CheckStat(LastSeenBy(Myself),0,177)
  CheckStat(LastSeenBy(Myself),0,116)
  CheckStat(LastSeenBy(Myself),0,164)
  CheckStat(LastSeenBy(Myself),0,MINORGLOBE)
  CheckStatLT(LastSeenBy(Myself),51,RESISTACID)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_MELF_ACID_ARROW)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_LARLOCH_MINOR_DRAIN)
  !GlobalTimerNotExpired("BPT","LOCALS")
  OR(2)
    Global("NOBREACH","LOCALS",1)
    RandomNumLT(99,23)
  RandomNumLT(112,42)
  OR(2)
    DamageTakenGT(4)
    HPPercentLT(Myself,81)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  CheckStat(LastSeenBy(Myself),0,MINORGLOBE)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_LARLOCH_MINOR_DRAIN)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_LARLOCH_MINOR_DRAIN)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("NOBREACH","LOCALS",0)
  RandomNumLT(112,42)
  OR(2)
    DamageTakenGT(4)
    HPPercentLT(Myself,81)
  OR(2)
    CheckStat(LastSeenBy(Myself),0,129)
    RandomNumLT(99,23)
  CheckStat(LastSeenBy(Myself),0,177)
  CheckStat(LastSeenBy(Myself),0,116)
  CheckStat(LastSeenBy(Myself),0,164)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  CheckStat(LastSeenBy(Myself),0,MINORGLOBE)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_LARLOCH_MINOR_DRAIN)
END

IF
  Global("BPMRC","LOCALS",0)
  OR(3)
    Class(Myself,LONG_BOW)
    Class(Myself,BARD)
    Class(Myself,SORCERER)
THEN
  RESPONSE #100
    SetGlobal("BPMRC","LOCALS",1)
END

IF
  Global("BPMRC","LOCALS",0)
THEN
  RESPONSE #100
    ChangeClass(Myself,MAGE)
    SetGlobal("BPMRC","LOCALS",1)
END


IF
  RandomNumLT(23,14)
  OR(3)
    See(NearestEnemyOfType([GOODCUTOFF.0.0.BARD_ALL]))
    See(NearestEnemyOfType([GOODCUTOFF.0.0.LONG_BOW]))
    See(NearestEnemyOfType([GOODCUTOFF.0.0.SORCERER]))
  RandomNumLT(24,11)
  OR(4)
    See(NearestEnemyOfType([GOODCUTOFF.0.0.RANGER_ALL]))
    See(NearestEnemyOfType([GOODCUTOFF.0.0.PALADIN_ALL]))
    See(NearestEnemyOfType([GOODCUTOFF.0.0.DRUID_ALL]))
    See(NearestEnemyOfType([GOODCUTOFF.0.0.CLERIC_ALL]))
  RandomNumLT(25,10)
  OR(3)
    See(NearestEnemyOfType([GOODCUTOFF.0.0.MONK]))
    See(NearestEnemyOfType([GOODCUTOFF.0.0.THIEF_ALL]))
    See(NearestEnemyOfType([GOODCUTOFF.0.0.BARD_ALL]))
  RandomNumLT(21,7)
  OR(3)
    See(NearestEnemyOfType([GOODCUTOFF.0.0.FIGHTER_ALL]))
    See(NearestEnemyOfType([GOODCUTOFF.0.0.RANGER_ALL]))
    See(NearestEnemyOfType([GOODCUTOFF.0.0.PALADIN_ALL]))
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  RandomNumLT(32,25)
  OR(3)
    Heard(ThirdNearestMyGroupOfType([EVILCUTOFF]),124)
    Heard(SecondNearestMyGroupOfType([EVILCUTOFF]),124)
    Heard(NearestMyGroupOfType([EVILCUTOFF]),124)
  HPGT(LastHeardBy(Myself),1)
  Range(LastHeardBy(Myself),20)
  Exists(LastAttackerOf(LastHeardBy(Myself)))
  !Allegiance(LastAttackerOf(LastHeardBy(Myself)),EVILCUTOFF)
  !StateCheck(LastAttackerOf(LastHeardBy(Myself)),STATE_CHARMED)
  OR(3)
    !Race(LastAttackerOf(LastHeardBy(Myself)),MORNINGSTAR)
    !Class(LastAttackerOf(LastHeardBy(Myself)),FAIRY_NYMPH)
    !Specifics(LastAttackerOf(LastHeardBy(Myself)),65)
  OR(3)  
    !StateCheck(LastAttackerOf(LastHeardBy(Myself)),0x00400010)
    CheckStatGT(Myself,0,SEEINVISIBLE)
    CheckStatGT(Myself,0,118)
  !Class(LastAttackerOf(LastHeardBy(Myself)),INNOCENT)
  See(LastAttackerOf(LastHeardBy(Myself)))
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  RandomNumLT(33,13)
  HitBy([0],0x0000)
  !Allegiance(LastHitter(Myself),EVILCUTOFF)
  !StateCheck(LastHitter(Myself),STATE_CHARMED)
  OR(3)
    !Race(LastHitter(Myself),MORNINGSTAR)
    !Class(LastHitter(Myself),FAIRY_NYMPH)
    !Specifics(LastHitter(Myself),65)
  OR(3)  
    !StateCheck(LastHitter(Myself),0x00400010)
    CheckStatGT(Myself,0,SEEINVISIBLE)
    CheckStatGT(Myself,0,118)
  See(LastHitter(Myself))
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  RandomNumGT(33,22)
  AttackedBy([0],DEFAULT)
  !Allegiance(LastAttackerOf(Myself),EVILCUTOFF)
  !StateCheck(LastAttackerOf(Myself),STATE_CHARMED)
  OR(3)
    !Race(LastAttackerOf(Myself),MORNINGSTAR)
    !Class(LastAttackerOf(Myself),FAIRY_NYMPH)
    !Specifics(LastAttackerOf(Myself),65)
  OR(3)  
    !StateCheck(LastAttackerOf(Myself),0x00400010)
    CheckStatGT(Myself,0,SEEINVISIBLE)
    CheckStatGT(Myself,0,118)
  See(LastAttackerOf(Myself))
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  OR(3)
    Allegiance(LastSeenBy(Myself),ENEMY)
    Allegiance(LastSeenBy(Myself),EVILCUTOFF)
    Allegiance(LastSeenBy(Myself),GOODBUTRED)
THEN
  RESPONSE #100
END

IF
  Race(LastSeenBy(Myself),MORNINGSTAR)
  Class(LastSeenBy(Myself),FAIRY_NYMPH)
  Specifics(LastSeenBy(Myself),65)
THEN
  RESPONSE #100
END

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


IF
  ActionListEmpty()
  HPPercentLT(Myself,25)
  Range(LastHitter(Myself),10)
  !GlobalTimerNotExpired("BPW","LOCALS")
  OR(3)
    !Race(LastHitter(Myself),MORNINGSTAR)
    !Class(LastHitter(Myself),FAIRY_NYMPH)
    !Specifics(LastHitter(Myself),65)
THEN
  RESPONSE #30
    DisplayStringHead(Myself,49767)
    Shout(124)
    SetGlobalTimer("BPW","LOCALS",10)
    RunAwayFrom(LastHitter(Myself),40)
  RESPONSE #10
    DisplayStringHead(Myself,@7)
    Shout(124)
    SetGlobalTimer("BPW","LOCALS",10)
    Attack(LastHitter(Myself))
  RESPONSE #40
    DisplayStringHead(Myself,49766)
    Shout(123)
    SetGlobalTimer("BPW","LOCALS",10)
    AttackReevaluate(LastSeenBy(Myself),15)
END

IF
  ActionListEmpty()
  !HasItem("PHANBLAD",Myself)
  !HasItem("BLAKBLAD",Myself)
  CheckStatGT(LastSeenBy(Myself),10,180)
  CheckStatLT(Myself,11,180)
  !HasItemSlot(Myself,SLOT_MISC0)
  !HasItemSlot(Myself,SLOT_MISC1)
  !HasItemSlot(Myself,SLOT_MISC2)
THEN
  RESPONSE #100
    EquipRanged()
    AttackOneRound(LastSeenBy(Myself))
END

IF
  ActionListEmpty()
  !HasItem("PHANBLAD",Myself)
  !HasItem("BLAKBLAD",Myself)
  !HasItemSlot(Myself,SLOT_MISC0)
  !HasItemSlot(Myself,SLOT_MISC1)
  !HasItemSlot(Myself,SLOT_MISC2)
  OR(4)
    !Range(NearestEnemyOf(Myself),5)
    CheckStatGT(LastSeenBy(Myself),0,121)
    CheckStatGT(LastSeenBy(Myself),0,125)
    HasItem("MELFMET",Myself)
THEN
  RESPONSE #100
    EquipRanged()
    AttackOneRound(LastSeenBy(Myself))
END

IF
  OR(2)
    CheckStatGT(NearestEnemyOf(Myself),0,121)
    CheckStatGT(LastSeenBy(Myself),0,125)
THEN
  RESPONSE #25
    Continue()
  RESPONSE #75
END

IF
  ActionListEmpty()
  !Range(LastSeenBy(Myself),8)
  OR(3)
    !Race(NearestEnemyOf(Myself),MORNINGSTAR)
    !Class(NearestEnemyOf(Myself),FAIRY_NYMPH)
    !Specifics(NearestEnemyOf(Myself),65)
  !HasItemSlot(Myself,SLOT_MISC0)
  !HasItemSlot(Myself,SLOT_MISC1)
  !HasItemSlot(Myself,SLOT_MISC2)
THEN
  RESPONSE #90
    EquipMostDamagingMelee()
    AttackOneRound(NearestEnemyOf(Myself))
  RESPONSE #40
    EquipMostDamagingMelee()
    AttackOneRound(LastSeenBy(Myself))
END

IF
  ActionListEmpty()
  !HasItemSlot(Myself,SLOT_MISC0)
  !HasItemSlot(Myself,SLOT_MISC1)
  !HasItemSlot(Myself,SLOT_MISC2)
THEN
  RESPONSE #100
    EquipMostDamagingMelee()
    AttackOneRound(LastSeenBy(Myself))
END

IF
  ActionListEmpty()
  OR(2)
    HasItem("BLAKBLAD",Myself)
    HasItem("PHANBLAD",Myself)
  OR(3)
    HasItemSlot(Myself,SLOT_MISC0)
    HasItemSlot(Myself,SLOT_MISC1)
    HasItemSlot(Myself,SLOT_MISC2)
THEN
  RESPONSE #75
    AttackOneRound(LastSeenBy(Myself))
  RESPONSE #25
    Continue()
END
