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_NPC_SYMBOL_DEATH)
    RemoveSpell(WIZARD_NPC_SYMBOL_DEATH)
    ForceSpell(LastSeenBy(Myself),WIZARD_NPC_SYMBOL_STUN)
    RemoveSpell(WIZARD_NPC_SYMBOL_STUN)
    ForceSpell(LastSeenBy(Myself),WIZARD_WAIL_OF_THE_BANSHEE)
    RemoveSpell(WIZARD_WAIL_OF_THE_BANSHEE)
    ForceSpell(LastSeenBy(Myself),WIZARD_SPHERE_OF_CHAOS)
    RemoveSpell(WIZARD_SPHERE_OF_CHAOS)
    SetGlobal("TimeStop","LOCALS",0)
  RESPONSE #25
    ForceSpell(LastSeenBy(Myself),WIZARD_DRAGONS_BREATH)
    RemoveSpell(WIZARD_DRAGONS_BREATH)
    ForceSpell(LastSeenBy(Myself),WIZARD_ABI_DALZIMS_HORRID_WILTING)
    RemoveSpell(WIZARD_ABI_DALZIMS_HORRID_WILTING)
    ForceSpell(Myself,WIZARD_METEOR_SWARM)
    RemoveSpell(WIZARD_METEOR_SWARM)
    ForceSpell(Myself,WIZARD_TELEPORT_FIELD)
    RemoveSpell(WIZARD_TELEPORT_FIELD)
    SetGlobal("TimeStop","LOCALS",0)
  RESPONSE #25
    ForceSpell(LastSeenBy(Myself),WIZARD_NPC_SYMBOL_FEAR)
    RemoveSpell(WIZARD_NPC_SYMBOL_FEAR)
    ForceSpell(LastSeenBy(Myself),WIZARD_POWER_WORD_BLIND)
    RemoveSpell(WIZARD_POWER_WORD_BLIND)
    ForceSpell(Myself,WIZARD_PRISMATIC_SPRAY)
    RemoveSpell(WIZARD_PRISMATIC_SPRAY)
    ForceSpell(Myself,WIZARD_CHAOS)
    RemoveSpell(WIZARD_CHAOS)
    SetGlobal("TimeStop","LOCALS",0)
  RESPONSE #20
    ForceSpell(Myself,WIZARD_RUBY_RAY_OF_REVERSAL)
    RemoveSpell(WIZARD_RUBY_RAY_OF_REVERSAL)
    ForceSpell(LastSeenBy(Myself),WIZARD_BIGBYS_CRUSHING_HAND)
    RemoveSpell(WIZARD_BIGBYS_CRUSHING_HAND)
    ForceSpell(LastSeenBy(Myself),WIZARD_POWER_WORD_BLIND)
    RemoveSpell(WIZARD_POWER_WORD_BLIND)
    ForceSpell(Myself,WIZARD_BLACK_BLADE_OF_DISASTER)
    RemoveSpell(WIZARD_BLACK_BLADE_OF_DISASTER)
    AttackOneRound(LastSeenBy(Myself))
    AttackOneRound(LastSeenBy(Myself))
    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))
  OR(2)
    General(Myself,HUMANOID)
    General(Myself,GIANTHUMANOID)
THEN
  RESPONSE #15
    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_ABI_DALZIMS_HORRID_WILTING)
    RemoveSpell(WIZARD_ABI_DALZIMS_HORRID_WILTING)
    AttackReevaluate(LastSeenBy(Myself),15)
  RESPONSE #20
    DisplayStringHead(Myself,@0)
    SetGlobal("BPCHASER","LOCALS",0)
    SetGlobalTimer("BPT","LOCALS",6)
    ForceSpell(LastSeenBy(Myself),WIZARD_NPC_SYMBOL_DEATH)
    RemoveSpell(WIZARD_NPC_SYMBOL_DEATH)
  RESPONSE #20
    DisplayStringHead(Myself,@0)
    SetGlobal("BPCHASER","LOCALS",0)
    SetGlobalTimer("BPT","LOCALS",6)
    ForceSpell(LastSeenBy(Myself),WIZARD_METEOR_SWARM)
    RemoveSpell(WIZARD_METEOR_SWARM)
  RESPONSE #15
    DisplayStringHead(Myself,@0)
    SetGlobal("BPCHASER","LOCALS",0)
    SetGlobalTimer("BPT","LOCALS",6)
    ForceSpell(LastSeenBy(Myself),WIZARD_SPELL_STRIKE)
    RemoveSpell(WIZARD_SPELL_STRIKE)
  RESPONSE #5
    DisplayStringHead(Myself,@0)
    SetGlobal("BPCHASER","LOCALS",0)
    SetGlobalTimer("BPT","LOCALS",6)
    ForceSpell(LastSeenBy(Myself),WIZARD_DRAGONS_BREATH)
    RemoveSpell(WIZARD_DRAGONS_BREATH)
END

IF
  GlobalTimerExpired("BPCHASE","LOCALS")
  Global("BPCHASER","LOCALS",1)
  !See([GOODCUTOFF])
  !See(LastHitter(Myself))
  OR(2)
    General(Myself,HUMANOID)
    General(Myself,GIANTHUMANOID)
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([ENEMY.ARMOR.ROBES.WIZARD_EYE.114])
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",3)
    ForceSpell(LastSeenBy(Myself),WIZARD_ABI_DALZIMS_HORRID_WILTING)
    RemoveSpell(WIZARD_ABI_DALZIMS_HORRID_WILTING)
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",3)
    ForceSpell(LastSeenBy(Myself),WIZARD_NPC_SYMBOL_DEATH)
    RemoveSpell(WIZARD_NPC_SYMBOL_DEATH)
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",3)
    ForceSpell(LastSeenBy(Myself),WIZARD_METEOR_SWARM)
    RemoveSpell(WIZARD_METEOR_SWARM)
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",3)
    ForceSpell(LastSeenBy(Myself),WIZARD_COMET)
    RemoveSpell(WIZARD_COMET)
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",3)
    ForceSpell(LastSeenBy(Myself),WIZARD_DEATH_FOG)
    RemoveSpell(WIZARD_DEATH_FOG)
  RESPONSE #50
    SetGlobalTimer("BPT","LOCALS",3)
    ForceSpell(LastSeenBy(Myself),WIZARD_DRAGONS_BREATH)
    RemoveSpell(WIZARD_DRAGONS_BREATH)
END

IF
  Global("BP_BOMB","LOCALS",2)
  Global("BP_BOMBSAWAY","MYAREA",1)
  !GlobalTimerNotExpired("BPT","LOCALS")
  !See([ENEMY.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])
  OR(2)
    General(Myself,HUMANOID)
    General(Myself,GIANTHUMANOID)
  CheckStatGT(Myself,5,INT)
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_IMPROVED_MANTLE)
    ReallyForceSpell(Myself,WIZARD_SPELL_DEFLECTION)
    ReallyForceSpell(Myself,WIZARD_HASTE)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("SCH","LOCALS",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)
    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_NORMAL_MISSILES)
    ReallyForceSpell(Myself,WIZARD_SPELL_TURNING)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("SCH","LOCALS",1)
    MoveToObject(LastHitter(Myself))
  RESPONSE #10
    DisplayStringHead(Myself,@2)
    SetGlobalTimer("BPCHASE","LOCALS",12)
    SetGlobal("BPCHASER","LOCALS",1)
    ReallyForceSpell(Myself,WIZARD_MANTLE)
    ReallyForceSpell(Myself,WIZARD_SPELL_DEFLECTION)
    ReallyForceSpell(Myself,WIZARD_ENERGY_BLADES)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("SCH","LOCALS",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("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("SCH","LOCALS",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
  CheckStat(Myself,3,PUPPETTYPE)
  See([EVILCUTOFF.0.0.LONG_BOW])
  CheckStat(LastSeenBy(Myself),3,PUPPETMASTERTYPE)
  Range(LastSeenBy(Myself),2)
THEN
  RESPONSE #100
    ActionOverride(LastSeenBy(Myself),RemoveSpell(WIZARD_SIMULACRUM))
    ActionOverride(LastSeenBy(Myself),RemoveSpell(WIZARD_PROJECT_IMAGE))
    ActionOverride(LastSeenBy(Myself),RemoveSpell(WIZARD_MISLEAD))
    ChangeSpecifics(LastSeenBy(Myself),SIMULACRUM)
    ChangeGender(LastSeenBy(Myself),EXTRA3)
    ActionOverride(LastSeenBy(Myself),ChangeAIScript("GPMAGE1",CLASS))
    SpellNoDecRES("SPMISLED",Myself)
    RunAwayFrom(LastSeenBy(Myself),20)
END

IF
  CheckStat(Myself,2,PUPPETTYPE)
  See([EVILCUTOFF.0.0.LONG_BOW.0.ILLUSIONARY])
  CheckStat(LastSeenBy(Myself),2,PUPPETMASTERTYPE)
  Range(LastSeenBy(Myself),2)
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    ActionOverride(LastSeenBy(Myself),RemoveSpell(WIZARD_PROJECT_IMAGE))
    ChangeSpecifics(LastSeenBy(Myself),NEEDS_BREACH)
    ChangeGender(LastSeenBy(Myself),EXTRA9)
    ActionOverride(LastSeenBy(Myself),ChangeAIScript("MAGE14A",CLASS))
    RunAwayFrom(LastSeenBy(Myself),20)
    SmallWait(20)
    ClearActions(Myself)
    SetInterrupt(TRUE)
END

IF
  CheckStat(Myself,1,PUPPETTYPE)
  See([EVILCUTOFF.0.0.LONG_BOW.0.ILLUSIONARY])
  CheckStat(LastSeenBy(Myself),1,PUPPETMASTERTYPE)
  Range(LastSeenBy(Myself),2)
THEN
  RESPONSE #100
    ChangeSpecifics(LastSeenBy(Myself),NEEDS_BREACH)
    ChangeGender(LastSeenBy(Myself),EXTRA2)
    ActionOverride(LastSeenBy(Myself),ChangeAIScript("BPMISLED",OVERRIDE))
    SpellNoDecRES("SPMISLED",Myself)
    RunAwayFrom(LastSeenBy(Myself),20)
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
  CheckStatGT(Myself,0,165)
  GlobalTimerNotExpired("BPT","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",0)
    Continue()
END

IF
  Range(NearestEnemyOf(Myself),4)
  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,40)
  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")
  Exists([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,75,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
  CheckStat(Myself,2,PUPPETTYPE)
  Exists([EVILCUTOFF.0.0.0.NEEDS_BREACH.EXTRA9])
THEN
  RESPONSE #100
END

IF
  ActionListEmpty()
  !GlobalTimerNotExpired("CHE","LOCALS")
  Global("SNAFU","LOCALS",0)
  GlobalLT("SCH","LOCALS",3)
  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_ENERGY_BLADES)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("SCH","LOCALS",1)
  RESPONSE #50
    ReallyForceSpell(Myself,WIZARD_IMPROVED_MANTLE)
    ReallyForceSpell(Myself,WIZARD_BLACK_BLADE_OF_DISASTER)
    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 #25
    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))
  !InWeaponRange(LastSeenBy(Myself)) 
  Delay(3)
THEN
  RESPONSE #100
    ClearActions(Myself)
    Continue()
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_STONE_SKIN)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  CheckStatLT(Myself,1,STONESKINS)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_STONE_SKIN)
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_DETECT_ILLUSION)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  CheckStat(Myself,0,118)
  Detect(NearestEnemyOf(Myself))
  OR(6)
    StateCheck(NearestEnemyOfType([GOODCUTOFF]),0x60200010)
    StateCheck(SecondNearestEnemyOfType([GOODCUTOFF]),0x60200010)
    StateCheck(ThirdNearestEnemyOfType([GOODCUTOFF]),0x60200010)
    StateCheck(FourthNearestEnemyOfType([GOODCUTOFF]),0x60200010)
    StateCheck(FifthNearestEnemyOfType([GOODCUTOFF]),0x60200010)
    StateCheck(SixthNearestEnemyOfType([GOODCUTOFF]),0x60200010)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_DETECT_ILLUSION)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_GLITTERDUST)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  CheckStat(Myself,0,118)
  CheckStatLT(Myself,1,118)
  CheckStatLT(Myself,1,SEEINVISIBLE)
  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)      
  OR(5)
     StateCheck(NearestEnemyOfType([GOODCUTOFF]),STATE_NOT_VISIBLE)         // and they're Invisible, Improved Invisible, Mirror Imaged, or Blur'd
     StateCheck(SecondNearest([GOODCUTOFF]),STATE_NOT_VISIBLE)
     StateCheck(ThirdNearest([GOODCUTOFF]),STATE_NOT_VISIBLE)
     StateCheck(FourthNearest([GOODCUTOFF]),STATE_NOT_VISIBLE)
     StateCheck(TenthNearest([GOODCUTOFF]),STATE_NOT_VISIBLE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_GLITTERDUST)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_SIMULACRUM)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  RandomNumLT(101,38)
  CheckStat(Myself,0,PUPPETTYPE)
  CheckStatLT(Myself,1,127)
  !Specifics(Myself,207)
  NumCreatureLT([EVILCUTOFF.0.0.0.207],1)
  !StateCheck(Myself,0x400010)
  Range(SecondNearestEnemyOf(Myself),6)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_SIMULACRUM)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_PROJECT_IMAGE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  RandomNumLT(102,38)
  CheckStat(Myself,0,PUPPETTYPE)
  CheckStatLT(Myself,1,127)
  !Specifics(Myself,207)
  NumCreatureLT([EVILCUTOFF.0.0.0.207],1)
  !StateCheck(Myself,0x400010)
  Range(SecondNearestEnemyOf(Myself),6)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_PROJECT_IMAGE)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_MISLEAD)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  RandomNumLT(103,36)
  CheckStat(Myself,0,PUPPETTYPE)
  CheckStatLT(Myself,1,127)
  !Specifics(Myself,207)
  NumCreatureLT([EVILCUTOFF.0.0.0.207],1)
  !StateCheck(Myself,0x400010)
  !StateCheck(Myself,STATE_POISONED)
  Range(SecondNearestEnemyOf(Myself),6)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_MISLEAD)
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_IMPROVED_MANTLE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  RandomNumLT(5,3)
  CheckStat(Myself,0,128)
  AttackedBy([ANYTHING],DEFAULT)
  Range(LastAttackerOf(Myself),4)
  CheckStatLT(LastAttackerOf(Myself),4,109)
  HPGT(LastAttackerOf(Myself),35)
  CheckStatLT(Myself,1,STONESKINS)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_IMPROVED_MANTLE)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_SPELL_TRAP)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  CheckStat(Myself,0,164)
  RandomNumLT(6,3)
  CheckStat(Myself,0,129)
  CheckStat(Myself,0,116)
  CheckStatLT(Myself,1,164)
  !HasBounceEffects(Myself)
  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_TRAP)
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_MANTLE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  RandomNumLT(8,4)
  CheckStat(Myself,0,128)
  AttackedBy([ANYTHING],DEFAULT)
  Range(LastAttackerOf(Myself),4)
  HPGT(LastAttackerOf(Myself),35)
  CheckStatLT(LastAttackerOf(Myself),3,109)
  CheckStatLT(Myself,1,STONESKINS)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_MANTLE)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  RandomNumLT(9,4)
  CheckStatLT(Myself,1,181)
  CheckStatLT(Myself,1,128)
  Range(LastAttackerOf(Myself),4)
  HPGT(LastAttackerOf(Myself),35)
  CheckStatLT(Myself,1,STONESKINS)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_GLOBE_OF_INVULNERABILITY)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  RandomNumLT(10,4)
  CheckStat(Myself,0,162)
  CheckStat(Myself,0,164)
  CheckStat(Myself,0,117)
  CheckStat(Myself,0,116)
  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_GLOBE_OF_INVULNERABILITY)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_SPELL_IMMUNITY)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  RandomNumLT(11,3)
  CheckStat(Myself,0,162)
  CheckStat(Myself,0,129)
  CheckStat(Myself,0,164)
  CheckStat(Myself,0,177)
  CheckStat(Myself,0,116)
  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 #70
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_SPELL_IMMUNITY_ABJURATION)
  RESPONSE #50
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_SPELL_IMMUNITY_INVOCATION)
  RESPONSE #50
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_SPELL_IMMUNITY_NECROMANCY)
  RESPONSE #30
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_SPELL_IMMUNITY_DIVINATION)
  RESPONSE #30
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_SPELL_IMMUNITY_ENCHANTMENT)
  RESPONSE #25
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_SPELL_IMMUNITY_ALTERATION)
  RESPONSE #20
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_SPELL_IMMUNITY_ILLUSIONIST)
  RESPONSE #10
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_SPELL_IMMUNITY_CONJURATION)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_IMPROVED_INVISIBILITY)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  RandomNumLT(12,4)
  AttackedBy([ANYTHING],DEFAULT)
  !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_IMPROVED_INVISIBILITY)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_IMPROVED_HASTE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  RandomNumLT(13,4)
  !StateCheck(Myself,STATE_HASTED)
  CheckStat(Myself,0,IMPROVEDHASTE)
  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(Myself,WIZARD_IMPROVED_HASTE)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_SPELL_SHIELD)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  RandomNumLT(14,4)
  CheckStat(Myself,0,177)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
  OR(5)
    CheckStatGT(Myself,0,129)
    CheckStatGT(Myself,0,164)
    CheckStatGT(Myself,0,SHIELDGLOBE)
    CheckStatGT(Myself,0,116)
    CheckStatGT(Myself,3,STONESKINS)
  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_SHIELD)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_MINOR_SPELL_DEFLECTION)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  RandomNumLT(15,4)
  CheckStat(Myself,0,164)
  CheckStat(Myself,0,116)
  CheckStat(Myself,0,129)
  CheckStat(Myself,0,177)
  !HasBounceEffects(Myself)
  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_MINOR_SPELL_DEFLECTION)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_MINOR_GLOBE_OF_INVULNERABILITY)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  RandomNumLT(16,4)
  !HasBounceEffects(Myself)
  CheckStat(Myself,0,164)
  CheckStat(Myself,0,MINORGLOBE)
  CheckStat(Myself,0,116)
  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_MINOR_GLOBE_OF_INVULNERABILITY)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_MINOR_SPELL_TURNING)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  RandomNumLT(17,4)
  CheckStat(Myself,0,164)
  CheckStat(Myself,0,SHIELDGLOBE)
  CheckStat(Myself,0,MINORGLOBE)
  CheckStat(Myself,0,116)
  CheckStat(Myself,0,129)
  !HasBounceEffects(Myself)
  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_MINOR_SPELL_TURNING)
END

IF
  ActionListEmpty()
  HasItem("BOOT12",Myself)  // ~Gargoyle Boots~
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(18,5)
  CheckStatLT(Myself,1,STONESKINS)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    UseItem("BOOT12",Myself)  // ~Gargoyle Boots~
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
  ActionListEmpty()
  HaveSpell(WIZARD_FIRE_SHIELD_BLUE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  RandomNumLT(20,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_BLUE)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_TELEPORT_FIELD)
  !GlobalTimerNotExpired("BPT","LOCALS")
  !GlobalTimerNotExpired("TFO","LOCALS")
  Global("SNAFU","LOCALS",0)
  RandomNumLT(21,6)
  OR(3)
    Range(NearestEnemyOf(Myself),6)
    Range(SecondNearestEnemyOf(Myself),10)
    Range(ThirdNearestEnemyOf(Myself),15)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("TFO","LOCALS",ONE_TURN)
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_TELEPORT_FIELD)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_PROTECTION_FROM_FIRE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  RandomNumLT(22,5)
  HitBy([ANYONE],FIRE)
  !HasBounceEffects(Myself)
  OR(2)
    CheckStatLT(Myself,41,RESISTMAGICFIRE)
    CheckStatLT(Myself,81,RESISTFIRE)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_PROTECTION_FROM_FIRE)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_PROTECTION_FROM_COLD)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  RandomNumLT(23,5)
  HitBy([ANYONE],COLD)
  !HasBounceEffects(Myself)
  OR(2)
    CheckStatLT(Myself,41,RESISTMAGICCOLD)
    CheckStatLT(Myself,81,RESISTCOLD)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_PROTECTION_FROM_COLD)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_PROTECTION_FROM_PETRIFICATION)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  RandomNumLT(24,5)
  OR(2)
    StateCheck([ANYONE],STATE_STONE_DEATH)
    SpellCast([GOODCUTOFF],WIZARD_FLESH_TO_STONE)
  !HasBounceEffects(Myself)
  CheckStatLT(Myself,1,176)
  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(Myself,WIZARD_PROTECTION_FROM_PETRIFICATION)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_HASTE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  RandomNumLT(25,6)
  !StateCheck(Myself,STATE_HASTED)
  CheckStat(Myself,0,IMPROVEDHASTE)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_HASTE)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  RandomNumLT(26,6)
  CheckStat(Myself,0,179)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
  OR(8)
    !Range(LastAttackerOf(Myself),4)
    HasItemEquiped("AROW01",LastAttackerOf(Myself)) // Arrow
    HasItemEquiped("AROW02",LastAttackerOf(Myself)) // Arrow +1
    HasItemEquiped("AX1H04",LastAttackerOf(Myself)) // Throwing Axe
    HasItemEquiped("BOLT01",LastAttackerOf(Myself)) // Bolt
    HasItemEquiped("BULL01",LastAttackerOf(Myself)) // Bullet
    HasItemEquiped("DAGG05",LastAttackerOf(Myself)) // Throwing Dagger
    HasItemEquiped("DART01",LastAttackerOf(Myself)) // Dart
  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_PROTECTION_FROM_NORMAL_MISSILES)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_SPIRIT_ARMOR)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  RandomNumLT(27,6)
  CheckStatLT(Myself,15,DEX)
  CheckStatGT(Myself,1,ARMORCLASS)
  CheckStatLT(Myself,5,SCRIPTINGSTATE5)
  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(Myself,WIZARD_SPIRIT_ARMOR)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_SPIRIT_ARMOR)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  RandomNumLT(27,6)
  CheckStat(Myself,15,DEX)
  CheckStatGT(Myself,0,ARMORCLASS)
  CheckStatLT(Myself,5,SCRIPTINGSTATE5)
  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(Myself,WIZARD_SPIRIT_ARMOR)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_SPIRIT_ARMOR)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  RandomNumLT(27,6)
  CheckStat(Myself,16,DEX)
  CheckStatGT(Myself,-1,ARMORCLASS)
  CheckStatLT(Myself,5,SCRIPTINGSTATE5)
  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(Myself,WIZARD_SPIRIT_ARMOR)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_SPIRIT_ARMOR)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  RandomNumLT(27,6)
  CheckStat(Myself,17,DEX)
  CheckStatGT(Myself,-2,ARMORCLASS)
  CheckStatLT(Myself,5,SCRIPTINGSTATE5)
  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(Myself,WIZARD_SPIRIT_ARMOR)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_SPIRIT_ARMOR)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  RandomNumLT(27,6)
  CheckStatLT(Myself,21,DEX)
  CheckStatGT(Myself,17,DEX)
  CheckStatGT(Myself,-3,ARMORCLASS)
  CheckStatLT(Myself,5,SCRIPTINGSTATE5)
  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(Myself,WIZARD_SPIRIT_ARMOR)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_SPIRIT_ARMOR)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  RandomNumLT(27,6)
  CheckStatGT(Myself,20,DEX)
  CheckStatGT(Myself,-4,ARMORCLASS)
  CheckStatLT(Myself,5,SCRIPTINGSTATE5)
  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(Myself,WIZARD_SPIRIT_ARMOR)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_MIRROR_IMAGE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  RandomNumLT(28,6)
  AttackedBy([ANYTHING],DEFAULT)
  !StateCheck(Myself,STATE_MIRRORIMAGE)
  !StateCheck(Myself,STATE_BLUR)
  !StateCheck(Myself,0x400010)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_MIRROR_IMAGE)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_BLUR)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  RandomNumLT(29,5)
  AttackedBy([ANYTHING],DEFAULT)
  !StateCheck(Myself,STATE_MIRRORIMAGE)
  !StateCheck(Myself,STATE_BLUR)
  !StateCheck(Myself,0x400010)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_BLUR)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_RESIST_FEAR)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  CheckStat(Myself,0,178)
  OR(4)
    SpellCast([GOODCUTOFF],WIZARD_HORROR)
    SpellCast([GOODCUTOFF],WIZARD_SYMBOL_FEAR)
    SpellCastPriest([GOODCUTOFF],CLERIC_SYMBOL_FEAR)
    SpellCastPriest([GOODCUTOFF],CLERIC_CLOAK_OF_FEAR)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    SetInterrupt(FALSE)
    Spell(Myself,WIZARD_RESIST_FEAR)
    SetInterrupt(TRUE)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_SHIELD)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  RandomNumLT(18,4)
  CheckStatLT(Myself,2,SCRIPTINGSTATE5)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
  OR(5)
    See([GOODCUTOFF.0.0.LONG_BOW])
    See([GOODCUTOFF.0.0.BARD_ALL])
    See([GOODCUTOFF.0.0.SORCERER])
    SpellCast([GOODCUTOFF],WIZARD_MAGIC_MISSILE)
    SpellCastOnMe([GOODCUTOFF],WIZARD_MAGIC_MISSILE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_SHIELD)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_SHIELD)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  RandomNumLT(18,4)
  CheckStatLT(Myself,15,DEX)
  CheckStatGT(Myself,4,ARMORCLASS)
  CheckStatLT(Myself,2,SCRIPTINGSTATE5)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_SHIELD)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_SHIELD)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  RandomNumLT(18,4)
  CheckStat(Myself,15,DEX)
  CheckStatGT(Myself,3,ARMORCLASS)
  CheckStatLT(Myself,2,SCRIPTINGSTATE5)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_SHIELD)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_SHIELD)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  RandomNumLT(18,4)
  CheckStat(Myself,16,DEX)
  CheckStatGT(Myself,2,ARMORCLASS)
  CheckStatLT(Myself,2,SCRIPTINGSTATE5)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_SHIELD)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_SHIELD)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  RandomNumLT(18,4)
  CheckStat(Myself,17,DEX)
  CheckStatGT(Myself,1,ARMORCLASS)
  CheckStatLT(Myself,2,SCRIPTINGSTATE5)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_SHIELD)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_SHIELD)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  RandomNumLT(18,4)
  CheckStatGT(Myself,17,DEX)
  CheckStatLT(Myself,21,DEX)
  CheckStatGT(Myself,0,ARMORCLASS)
  CheckStatLT(Myself,2,SCRIPTINGSTATE5)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_SHIELD)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_SHIELD)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  RandomNumLT(18,4)
  CheckStatGT(Myself,20,DEX)
  CheckStatGT(Myself,-1,ARMORCLASS)
  CheckStatLT(Myself,2,SCRIPTINGSTATE5)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_SHIELD)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_IMPROVED_HASTE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(31,6)
  Range(NearestMyGroupOfType,10)
  OR(2)
    Class(NearestMyGroupOfType,FIGHTER_ALL)
    HPGT(NearestMyGroupOfType,50)
  !StateCheck(NearestMyGroupOfType,STATE_HASTED)
  CheckStat(NearestMyGroupOfType,0,IMPROVEDHASTE)
  !StateCheck(NearestMyGroupOfType,0x400010)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(NearestMyGroupOfType,WIZARD_IMPROVED_HASTE)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_HASTE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(32,6)
  Range(SecondNearestMyGroupOfType,12)
  CheckStatGT(Myself,0,IMPROVEDHASTE)
  StateCheck(Myself,STATE_HASTED)
  !StateCheck(SecondNearestMyGroupOfType,STATE_HASTED)
  CheckStat(SecondNearestMyGroupOfType,0,IMPROVEDHASTE)
  !StateCheck(SecondNearestMyGroupOfType,0x400010)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(SecondNearestMyGroupOfType,WIZARD_HASTE)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_RESIST_FEAR)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  Exists(NearestMyGroupOfType)
  CheckStat(NearestMyGroupOfType,0,178)
  StateCheck(NearestMyGroupOfType,STATE_PANIC)
  !StateCheck(NearestMyGroupOfType,0x400010)
  LOS(NearestMyGroupOfType,12)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("SPL_CAST","LOCALS",6)
    Spell(NearestMyGroupOfType,WIZARD_RESIST_FEAR)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_RESIST_FEAR)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  Exists(SecondNearestMyGroupOfType)
  CheckStat(SecondNearestMyGroupOfType,0,178)
  StateCheck(SecondNearestMyGroupOfType,STATE_PANIC)
  !StateCheck(SecondNearestMyGroupOfType,0x400010)
  LOS(SecondNearestMyGroupOfType,12)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("SPL_CAST","LOCALS",6)
    Spell(SecondNearestMyGroupOfType,WIZARD_RESIST_FEAR)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_RESIST_FEAR)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  RandomNumLT(33,6)
  Exists(ThirdNearestMyGroupOfType([EVILCUTOFF]))
  OR(6)
    StateCheck(SixthNearestMyGroupOfType([EVILCUTOFF]),STATE_PANIC)
    StateCheck(FifthNearestMyGroupOfType([EVILCUTOFF]),STATE_PANIC)
    StateCheck(FourthNearestMyGroupOfType([EVILCUTOFF]),STATE_PANIC)
    StateCheck(ThirdNearestMyGroupOfType([EVILCUTOFF]),STATE_PANIC)
    StateCheck(SecondNearestMyGroupOfType([EVILCUTOFF]),STATE_PANIC)
    StateCheck(NearestMyGroupOfType([EVILCUTOFF]),STATE_PANIC)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(ThirdNearestMyGroupOfType([EVILCUTOFF]),WIZARD_RESIST_FEAR)
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
  ActionListEmpty()
  HaveSpell(WIZARD_DIRE_CHARM)
  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_DIRE_CHARM)
    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(5)
    Global("SNAFU","LOCALS",1)
    HasItem("BLAKBLAD",Myself)
    HasItem("PHANBLAD",Myself)
    HasItem("ENEBLADE",Myself)
    HasItem("MELFMET",Myself)
THEN
  RESPONSE #75
    AttackOneRound(LastSeenBy(Myself))
  RESPONSE #25
    Continue()
END

IF
  ActionListEmpty()
  StateCheck(Myself,0x400010)
  GlobalTimerNotExpired("BPIP","LOCALS")
THEN
  RESPONSE #15
    Continue()
  RESPONSE #60
    SetGlobalTimer("BPT","LOCALS",0)
  RESPONSE #90
    SetGlobalTimer("BPT","LOCALS",0)
    RunAwayFrom(NearestEnemyOf(Myself),10)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_DEATH_SPELL)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Gender(LastSeenBy(Myself),SUMMONED)
  OR(3)
    NumCreatureLT([EVILCUTOFF.0.0.0.0.SUMMONED],1)
    Range([EVILCUTOFF.0.0.0.0.SUMMONED],4)
    !Range(LastSeenBy(Myself),16)
  !StateCheck(LastSeenBy(Myself),STATE_BERSERK)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  CheckStatLT(LastSeenBy(Myself),10,LEVEL)
  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_DEATH_SPELL)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_DEATH_FOG)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Gender(LastSeenBy(Myself),SUMMONED)
  OR(3)
    NumCreatureLT([EVILCUTOFF.0.0.0.0.SUMMONED],1)
    Range([EVILCUTOFF.0.0.0.0.SUMMONED],4)
    !Range(LastSeenBy(Myself),16)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  CheckStatLT(LastSeenBy(Myself),10,LEVEL)
  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_DEATH_FOG)
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_RUBY_RAY_OF_REVERSAL)
  !GlobalTimerNotExpired("BPT","LOCALS")
  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)      
  OR(7)
    CheckStatGT(LastSeenBy(Myself),0,177)
    CheckStatGT(LastSeenBy(Myself),0,MINORGLOBE)
    CheckStatGT(LastSeenBy(Myself),0,116)
    CheckStatGT(LastSeenBy(Myself),0,132)
    CheckStatGT(LastSeenBy(Myself),1,162)
    CheckStatGT(LastSeenBy(Myself),0,164)
    Specifics(LastSeenBy(Myself),202)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_RUBY_RAY_OF_REVERSAL)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_TENSERS_TRANSFORMATION)
  CheckStat(Myself,0,182)
  !GlobalTimerNotExpired("BPT","LOCALS")
  OR(2)
    HasItem("BLAKBLAD",Myself)
    HasItem("PHANBLAD",Myself)
  Range(NearestEnemyOf(Myself),4)
  AttackedBy([ANYTHING],DEFAULT)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_TENSERS_TRANSFORMATION)
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_NPC_SYMBOL_DEATH)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(50,32)
  HPGT(LastSeenBy(Myself),20)
  HPLT(LastSeenBy(Myself),60)
  CheckStatLT(LastSeenBy(Myself),1,157) // Death Ward
  !StateCheck(LastSeenBy(Myself),STATE_BERSERK)
  CheckStatGT(LastSeenBy(Myself),5,SAVEVSSPELL)
  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_NPC_SYMBOL_DEATH)
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_NPC_SYMBOL_FEAR)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(52,31)
  CheckStat(LastSeenBy(Myself),0,178)
  !StateCheck(LastSeenBy(Myself),STATE_PANIC)
  !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_FEAR)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_POWER_WORD_SILENCE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(53,36)
  Global("NOBREACH","LOCALS",1)
  OR(2)
    CheckStat(LastSeenBy(Myself),0,129) // either they have no spell turning
    RandomNumLT(99,23) //or we'll just shoot the moon
  !StateCheck(LastSeenBy(Myself),STATE_SILENCED)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  OR(5)
    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_POWER_WORD_SILENCE)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_POWER_WORD_SILENCE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("NOBREACH","LOCALS",0)
  RandomNumLT(53,36)
  !StateCheck(LastSeenBy(Myself),STATE_SILENCED)
  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(Myself,61,SPELLFAILUREMAGE)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  OR(5)
    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_POWER_WORD_SILENCE)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_SPHERE_OF_CHAOS)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(54,31)
  !HasBounceEffects(LastSeenBy(Myself))
  Range(LastSeenBy(Myself),15)
  !General(LastSeenBy(Myself),UNDEAD)
  !StateCheck(LastSeenBy(Myself),STATE_CONFUSED)
  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(Myself,WIZARD_SPHERE_OF_CHAOS)
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(2925) // Wizard Comet
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(56,38)
  !Range(LastSeenBy(Myself),4)
  CheckStatLT(LastSeenBy(Myself),76,RESISTFIRE)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),2925)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_DRAGONS_BREATH)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(57,37)
  CheckStatLT(LastSeenBy(Myself),51,RESISTFIRE)
  CheckStatGT(LastSeenBy(Myself),8,SAVEVSBREATH)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_DRAGONS_BREATH)
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_BIGBYS_CRUSHING_HAND)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(61,38)
  Global("NOBREACH","LOCALS",1)
  OR(2)
    CheckStat(LastSeenBy(Myself),0,129) // either they have no spell turning
    RandomNumLT(99,23) //or we'll just shoot the moon
  LevelGT(LastSeenBy(Myself),13)
  HPGT(LastSeenBy(Myself),35)
  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_BIGBYS_CRUSHING_HAND)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_BIGBYS_CRUSHING_HAND)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(61,38)
  Global("NOBREACH","LOCALS",0)
  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)
  LevelGT(LastSeenBy(Myself),13)
  HPGT(LastSeenBy(Myself),35)
  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_BIGBYS_CRUSHING_HAND)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_BIGBYS_CLENCHED_FIST)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(62,38)
  Global("NOBREACH","LOCALS",1)
  OR(2)
    CheckStat(LastSeenBy(Myself),0,129) // either they have no spell turning
    RandomNumLT(99,23) //or we'll just shoot the moon
  LevelGT(LastSeenBy(Myself),9)
  HPGT(LastSeenBy(Myself),25)
  !HasBounceEffects(LastSeenBy(Myself))
  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_BIGBYS_CLENCHED_FIST)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_BIGBYS_CLENCHED_FIST)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("NOBREACH","LOCALS",0)
  RandomNumLT(62,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)
  LevelGT(LastSeenBy(Myself),9)
  HPGT(LastSeenBy(Myself),25)
  !HasBounceEffects(LastSeenBy(Myself))
  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_BIGBYS_CLENCHED_FIST)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_SUMMON_PLANATAR_GOOD)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(63,36)
  NumCreatureLT([EVILCUTOFF.0.0.0.0.SUMMONED],7)
  NumCreature([EVILCUTOFF.0.SOLAR],0)
  NumCreature([EVILCUTOFF.0.ANTISOLAR],0)
  NumCreature([EVILCUTOFF.0.PLANATAR],0)
  NumCreature([EVILCUTOFF.0.DARKPLANATAR],0)
  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(Myself,WIZARD_SUMMON_PLANATAR_GOOD)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_SUMMON_PLANATAR_EVIL)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(64,36)
  NumCreatureLT([EVILCUTOFF.0.0.0.0.SUMMONED],7)
  NumCreature([EVILCUTOFF.0.SOLAR],0)
  NumCreature([EVILCUTOFF.0.ANTISOLAR],0)
  NumCreature([EVILCUTOFF.0.PLANATAR],0)
  NumCreature([EVILCUTOFF.0.DARKPLANATAR],0)
  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(Myself,WIZARD_SUMMON_PLANATAR_EVIL)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_CHAOS)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(65,38)
  !StateCheck(LastSeenBy(Myself),STATE_CONFUSED)
  !StateCheck(LastSeenBy(Myself),STATE_PANIC)
  CheckStat(LastSeenBy(Myself),0,HELD)
  !StateCheck(LastSeenBy(Myself),0x00102029)  // STATE_HARMLESS
  !StateCheck(LastSeenBy(Myself),STATE_BERSERK)
  !General(LastSeenBy(Myself),UNDEAD)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_CHAOS)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_POWER_WORD_BLIND)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(66,38)
  !StateCheck(LastSeenBy(Myself),0x00102029)  // STATE_HARMLESS  
  !StateCheck(LastSeenBy(Myself),STATE_BLIND)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_POWER_WORD_BLIND)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_CHAIN_LIGHTNING)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(67,42)
  CheckStatLT(LastSeenBy(Myself),76,RESISTELECTRICITY)
  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_CHAIN_LIGHTNING)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_FINGER_OF_DEATH)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(68,38)
  Global("NOBREACH","LOCALS",1)
  OR(2)
    CheckStat(LastSeenBy(Myself),0,129) // either they have no spell turning
    RandomNumLT(99,23) //or we'll just shoot the moon
  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_MAZE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(69,42)
  Global("NOBREACH","LOCALS",1)
  OR(2)
    CheckStat(LastSeenBy(Myself),0,129) // either they have no spell turning
    RandomNumLT(99,23) //or we'll just shoot the moon
  OR(3)
    HPGT(LastSeenBy(Myself),50)
    Class(LastSeenBy(Myself),MAGE_ALL)
    Class(LastSeenBy(Myself),SORCERER)
  CheckStatLT(LastSeenBy(Myself),0,119)
  !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_MORDENKAINENS_SWORD)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(70,40)
  NumCreatureLT([EVILCUTOFF.0.0.0.0.SUMMONED],7)
  HPGT(LastSeenBy(Myself),30)
  Range(LastSeenBy(Myself),16)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_MORDENKAINENS_SWORD)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_DISINTEGRATE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(71,36)
  Global("NOBREACH","LOCALS",1)
  OR(2)
    CheckStat(LastSeenBy(Myself),0,129) // either they have no spell turning
    RandomNumLT(99,23) //or we'll just shoot the moon
  CheckStat(LastSeenBy(Myself),0,157)
  OR(3)
    HPGT(LastSeenBy(Myself),40)
    Class(LastSeenBy(Myself),MAGE_ALL)
    Class(LastSeenBy(Myself),SORCERER)
  !StateCheck(LastSeenBy(Myself),STATE_BERSERK)
  CheckStatGT(LastSeenBy(Myself),5,SAVEVSSPELL)
  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_DISINTEGRATE)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_DISINTEGRATE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("NOBREACH","LOCALS",0)
  RandomNumLT(71,36)
  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)
  OR(3)
    HPGT(LastSeenBy(Myself),40)
    Class(LastSeenBy(Myself),MAGE_ALL)
    Class(LastSeenBy(Myself),SORCERER)
  !StateCheck(LastSeenBy(Myself),STATE_BERSERK)
  CheckStatGT(LastSeenBy(Myself),5,SAVEVSSPELL)
  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_DISINTEGRATE)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_FLESH_TO_STONE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(72,37)
  Global("NOBREACH","LOCALS",1)
  OR(2)
    CheckStat(LastSeenBy(Myself),0,129) // either they have no spell turning
    RandomNumLT(99,23) //or we'll just shoot the moon
  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_ENERGY_DRAIN)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(73,38)
  Global("NOBREACH","LOCALS",1)
  OR(2)
    CheckStat(LastSeenBy(Myself),0,129) // either they have no spell turning
    RandomNumLT(99,23) //or we'll just shoot the moon
  Range(LastSeenBy(Myself),4) // touch attack
  !StateCheck(LastSeenBy(Myself),STATE_BERSERK)
  LevelGT(LastSeenBy(Myself),9)
  !Race(LastSeenBy(Myself),DEMONIC)
  !General(LastSeenBy(Myself),UNDEAD)
  CheckStatLT(LastSeenBy(Myself),1,158)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_ENERGY_DRAIN)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_ENERGY_DRAIN)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("NOBREACH","LOCALS",0)
  RandomNumLT(73,38)
  Range(LastSeenBy(Myself),4) // touch attack
  CheckStat(LastSeenBy(Myself),0,129)
  CheckStat(LastSeenBy(Myself),0,177)
  CheckStat(LastSeenBy(Myself),0,116)
  CheckStat(LastSeenBy(Myself),0,164)
  !StateCheck(LastSeenBy(Myself),STATE_BERSERK)
  LevelGT(LastSeenBy(Myself),9)
  !Race(LastSeenBy(Myself),DEMONIC)
  !General(LastSeenBy(Myself),UNDEAD)
  CheckStatLT(LastSeenBy(Myself),1,158)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_ENERGY_DRAIN)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_SPELL_THRUST)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(74,24)
  CheckStat(LastSeenBy(Myself),0,177)
  !StateCheck(LastSeenBy(Myself),0x400010)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
  OR(4)
    CheckStatGT(LastSeenBy(Myself),0,MINORGLOBE)
    CheckStat(LastSeenBy(Myself),1,116)
    CheckStat(LastSeenBy(Myself),1,129)
    CheckStatGT(LastSeenBy(Myself),0,162)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_SPELL_THRUST)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_BREACH)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(75,45)
  CheckStat(LastSeenBy(Myself),0,164)
  CheckStat(LastSeenBy(Myself),0,177)
  CheckStat(LastSeenBy(Myself),0,177)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
  OR(11)
    CheckStatGT(LastSeenBy(Myself),0,SHIELDGLOBE)
    CheckStatGT(LastSeenBy(Myself),0,STONESKINS)
    CheckStatGT(LastSeenBy(Myself),0,181)
    CheckStatGT(LastSeenBy(Myself),0,128)
    CheckStatGT(LastSeenBy(Myself),0,179)
    CheckStatGT(LastSeenBy(Myself),0,SCRIPTINGSTATE5)
    CheckStatGT(LastSeenBy(Myself),0,126)
    CheckStatGT(LastSeenBy(Myself),0,130)
    CheckStatGT(LastSeenBy(Myself),0,119)
    CheckStatGT(LastSeenBy(Myself),0,SCRIPTINGSTATE2) 
    CheckStatGT(LastSeenBy(Myself),0,122)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_BREACH)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_PIERCE_MAGIC)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(76,46)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
  OR(7)
    CheckStatGT(LastSeenBy(Myself),0,177)
    CheckStatGT(LastSeenBy(Myself),0,129)
    CheckStatGT(LastSeenBy(Myself),0,116)
    CheckStatGT(LastSeenBy(Myself),0,MINORGLOBE)
    CheckStatGT(LastSeenBy(Myself),0,162)
    CheckStatGT(LastSeenBy(Myself),0,123)
    CheckStatGT(LastSeenBy(Myself),20,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_PIERCE_MAGIC)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_WARDING_WHIP)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(77,47)
  CheckStat(LastSeenBy(Myself),0,164)
  OR(6)
     CheckStatGT(LastSeenBy(Myself),0,177)
     CheckStatGT(LastSeenBy(Myself),0,MINORGLOBE)
     CheckStatGT(LastSeenBy(Myself),0,116)
     CheckStatGT(LastSeenBy(Myself),0,129)
     CheckStatGT(LastSeenBy(Myself),0,162)
     CheckStatGT(LastSeenBy(Myself),0,123)
  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_WARDING_WHIP)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_RUBY_RAY_OF_REVERSAL)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(78,48)
  OR(7)
    CheckStatGT(LastSeenBy(Myself),0,129)
    CheckStatGT(LastSeenBy(Myself),0,116)
    CheckStatGT(LastSeenBy(Myself),0,MINORGLOBE)
    CheckStatGT(LastSeenBy(Myself),0,162)
    CheckStatGT(LastSeenBy(Myself),0,177)
    CheckStatGT(LastSeenBy(Myself),0,164)
    CheckStatGT(LastSeenBy(Myself),0,123)
  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_RUBY_RAY_OF_REVERSAL)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_EMOTION_HOPELESSNESS)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(79,45)
  !StateCheck(LastSeenBy(Myself),STATE_SLEEPING)
  !StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
  !StateCheck(LastSeenBy(Myself),0x00102029)  // STATE_HARMLESS  
  !StateCheck(LastSeenBy(Myself),STATE_BERSERK)
  !General(LastSeenBy(Myself),UNDEAD)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_EMOTION_HOPELESSNESS)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_CONFUSION)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(80,46)
  !StateCheck(LastSeenBy(Myself),STATE_CONFUSED)
  !StateCheck(LastSeenBy(Myself),STATE_PANIC)
  !StateCheck(LastSeenBy(Myself),STATE_BERSERK)
  CheckStat(LastSeenBy(Myself),0,HELD)
  !StateCheck(LastSeenBy(Myself),0x00102029)  
  !General(LastSeenBy(Myself),UNDEAD)
  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_CONFUSION)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_FEEBLEMIND)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(81,51)
  Global("NOBREACH","LOCALS",1)
  OR(2)
    CheckStat(LastSeenBy(Myself),0,129) // either they have no spell turning
    RandomNumLT(99,23) //or we'll just shoot the moon
  CheckStatGT(LastSeenBy(Myself),5,INT)
  !StateCheck(LastSeenBy(Myself),STATE_BERSERK)
  !General(LastSeenBy(Myself),UNDEAD)
  CheckStatGT(LastSeenBy(Myself),5,SAVEVSSPELL)
  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)      
  OR(6)
    HPGT(LastSeenBy(Myself),60)
    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_FEEBLEMIND)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_FEEBLEMIND)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("NOBREACH","LOCALS",0)
  RandomNumLT(81,51)
  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)
  CheckStatGT(LastSeenBy(Myself),5,INT)
  !StateCheck(LastSeenBy(Myself),STATE_BERSERK)
  !General(LastSeenBy(Myself),UNDEAD)
  CheckStatGT(LastSeenBy(Myself),5,SAVEVSSPELL)
  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)      
  OR(6)
    HPGT(LastSeenBy(Myself),60)
    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_FEEBLEMIND)
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_NISHRUU)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(83,53)
  OR(3)
    Class(LastSeenBy(Myself),BARD_ALL)
    Class(LastSeenBy(Myself),LONG_BOW)
    Class(LastSeenBy(Myself),SORCERER)
  NumCreatureLT([EVILCUTOFF.0.0.0.0.SUMMONED],7)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_SUMMON_NISHRUU)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_DOMINATION)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(84,46)
  Global("NOBREACH","LOCALS",1)
  OR(2)
    CheckStat(LastSeenBy(Myself),0,129) // either they have no spell turning
    RandomNumLT(99,23) //or we'll just shoot the moon
  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_SUMMON_DJINNI)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(85,45)
  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_DJINNI)
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_DEATH_SPELL)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(87,45)
  OR(2)
    CheckStatLT(LastSeenBy(Myself),9,LEVEL)
    Exists(LastSummonerOf(LastSeenBy(Myself))) // backwards way to determine summoned status
  CheckStat(LastSeenBy(Myself),0,157)
  CheckStatGT(LastSeenBy(Myself),5,SAVEVSDEATH)
  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_DEATH_SPELL)
END

IF
  ActionListEmpty()
  HasItem("WAND10",Myself)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(88,38)
  NumCreatureLT([EVILCUTOFF.0.0.0.0.SUMMONED],7)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    DisplayStringHead(Myself,31971)
    UseItem("WAND10",LastSeenBy(Myself))
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_MONSTER_SUMMONING_3)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(89,45)
  NumCreatureLT([EVILCUTOFF.0.0.0.0.SUMMONED],7)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_MONSTER_SUMMONING_3)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_ANIMATE_DEAD)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(90,46)
  NumCreatureLT([EVILCUTOFF.0.0.0.0.SUMMONED],7)
  NumCreatureLT([EVILCUTOFF.UNDEAD.0.0.0.SUMMONED],5)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_ANIMATE_DEAD)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_CONE_OF_COLD)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(91,49)
  OR(2)
    LOS(LastSeenBy(Myself),12)
    Range(LastSeenBy(Myself),8)
  CheckStatLT(LastSeenBy(Myself),76,RESISTCOLD)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
  OR(5)
    !Exists(NearestMyGroupOfType)
    Range(NearestMyGroupOfType,2)
    !LOS(NearestMyGroupOfType,12)
    CheckStatGT(NearestMyGroupOfType,49,RESISTCOLD)
    CheckStatGT(NearestMyGroupOfType,49,RESISTMAGIC)
  OR(5)
    !Exists(SecondNearestMyGroupOfType)
    Range(SecondNearestMyGroupOfType,3)
    !LOS(SecondNearestMyGroupOfType,12)
    CheckStatGT(SecondNearestMyGroupOfType,49,RESISTCOLD)    
    CheckStatGT(SecondNearestMyGroupOfType,49,RESISTMAGIC)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_CONE_OF_COLD)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_SUN_FIRE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(92,48)
  Range(SecondNearestEnemyOf(Myself),15)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
  OR(4)
    CheckStatLT(SecondNearestEnemyOf(Myself),51,RESISTFIRE)
    CheckStatLT(SecondNearestEnemyOf(Myself),51,RESISTMAGIC)
    CheckStatLT(NearestEnemyOf(Myself),51,RESISTFIRE)
    CheckStatLT(NearestEnemyOf(Myself),51,RESISTMAGIC)
  OR(4)
    !Exists(NearestMyGroupOfType)
    !Range(NearestMyGroupOfType,15)
    CheckStatGT(NearestMyGroupOfType,49,RESISTFIRE)
    CheckStatGT(NearestMyGroupOfType,49,RESISTMAGIC)
  OR(4)
    !Exists(SecondNearestMyGroupOfType)
    !Range(SecondNearestMyGroupOfType,15)
    CheckStatGT(SecondNearestMyGroupOfType,49,RESISTFIRE)    
    CheckStatGT(SecondNearestMyGroupOfType,49,RESISTMAGIC)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_SUN_FIRE)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_ENERGY_BLADES)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(93,47)
  OR(2)
    !Range(LastAttackerOf(Myself),3)
    !Range(NearestEnemyOf(Myself),4)
  !HasItem("BLAKBLAD",Myself)
  !HasItem("PHANBLAD",Myself)
  !HasItem("MELFMET",Myself)
  !HasItem("ENEBLADE",Myself)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_ENERGY_BLADES)
    AttackOneRound(LastSeenBy(Myself))
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_SPIDER_SPAWN)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(94,42)
  NumCreatureLT([EVILCUTOFF.0.0.0.0.SUMMONED],7)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_SPIDER_SPAWN)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_MONSTER_SUMMONING_1)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(95,41)
  NumCreatureLT([EVILCUTOFF.0.0.0.0.SUMMONED],7)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_MONSTER_SUMMONING_1)
END

IF
  ActionListEmpty()
  HasItem("WAND06",Myself)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(96,49)
  CheckStatGT(Myself,8,INT) //accurate item read
  OR(2)
    LOS(LastSeenBy(Myself),12)
    Range(LastSeenBy(Myself),8)
  CheckStatLT(LastSeenBy(Myself),76,RESISTCOLD)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  CheckStat(LastSeenBy(Myself),0,MINORGLOBE)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
  OR(5)
    !Exists(NearestMyGroupOfType)
    Range(NearestMyGroupOfType,2)
    !LOS(NearestMyGroupOfType,12)
    CheckStatGT(NearestMyGroupOfType,49,RESISTCOLD)
    CheckStatGT(NearestMyGroupOfType,49,RESISTMAGIC)
  OR(5)
    !Exists(SecondNearestMyGroupOfType)
    Range(SecondNearestMyGroupOfType,3)
    !LOS(SecondNearestMyGroupOfType,12)
    CheckStatGT(SecondNearestMyGroupOfType,49,RESISTCOLD)    
    CheckStatGT(SecondNearestMyGroupOfType,49,RESISTMAGIC)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    DisplayStringHead(Myself,31971)
    UseItem("WAND06",LastSeenBy(Myself))
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_FIREBALL)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(97,53)
  !StateCheck(LastSeenBy(Myself),0x00400010)
  CheckStatLT(LastSeenBy(Myself),76,RESISTFIRE)
  CheckStatGT(LastSeenBy(Myself),5,SAVEVSSPELL)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  CheckStat(LastSeenBy(Myself),0,MINORGLOBE)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
  OR(2)
    !Range(LastSeenBy(Myself),15)
    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)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_FIREBALL)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_ICE_STORM)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(98,52)
  !StateCheck(LastSeenBy(Myself),0x00400010)
  CheckStatLT(LastSeenBy(Myself),76,RESISTCOLD)
  CheckStatGT(LastSeenBy(Myself),5,SAVEVSSPELL)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
  OR(2)
    !Range(LastSeenBy(Myself),15)
    CheckStatGT(Myself,74,RESISTCOLD)
  OR(4)
    !Exists(NearestMyGroupOfType)
    Range(NearestMyGroupOfType,3)
    CheckStatGT(NearestMyGroupOfType,49,RESISTCOLD)
    CheckStatGT(NearestMyGroupOfType,49,RESISTMAGIC)
  OR(4)
    !Exists(SecondNearestMyGroupOfType)
    Range(SecondNearestMyGroupOfType,4)
    CheckStatGT(SecondNearestMyGroupOfType,49,RESISTCOLD)
    CheckStatGT(SecondNearestMyGroupOfType,49,RESISTMAGIC)
  OR(4)
    !Exists(ThirdNearestMyGroupOfType)
    Range(ThirdNearestMyGroupOfType,5)
    CheckStatGT(ThirdNearestMyGroupOfType,49,RESISTCOLD)
    CheckStatGT(ThirdNearestMyGroupOfType,49,RESISTMAGIC)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_ICE_STORM)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_LIGHTNING_BOLT)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(99,51)
  LOS(LastSeenBy(Myself),25)
  CheckStatLT(LastSeenBy(Myself),76,RESISTELECTRICITY)
  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_LIGHTNING_BOLT)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_FLAME_ARROW)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(113,60)
  Global("NOBREACH","LOCALS",1)
  OR(2)
    CheckStat(LastSeenBy(Myself),0,129) // either they have no spell turning
    RandomNumLT(99,23) //or we'll just shoot the moon
  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_MELF_METEOR)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(100,55)
  OR(2)
    !Range(LastAttackerOf(Myself),3)
    !Range(NearestEnemyOf(Myself),4)
  !HasItemSlot(Myself,SLOT_MISC19)                                         // more robust check to see if I already have anything in the magically created item slot
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_MELF_METEOR)
    AttackOneRound(LastSeenBy(Myself))
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_WEB)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(101,48)
  !Range(LastSeenBy(Myself),15)
  CheckStatLT(LastSeenBy(Myself),1,131) //Free Action
  !StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
  !StateCheck(LastSeenBy(Myself),STATE_HARMLESS)
  !StateCheck(LastSeenBy(Myself),STATE_BERSERK)
  CheckStatLT(LastSeenBy(Myself),1,HELD)
  CheckStatLT(LastSeenBy(Myself),1,WEB)
  CheckStatGT(LastSeenBy(Myself),5,SAVEVSSPELL)
  CheckStat(LastSeenBy(Myself),0,MINORGLOBE)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
  OR(4)
    !Exists(NearestMyGroupOfType)
    Range(NearestMyGroupOfType,4)
    CheckStatGT(NearestMyGroupOfType,0,131)
    CheckStatGT(NearestMyGroupOfType,49,RESISTMAGIC)
  OR(4)
    !Exists(SecondNearestMyGroupOfType)
    Range(SecondNearestMyGroupOfType,4)
    CheckStatGT(SecondNearestMyGroupOfType,0,131)
    CheckStatGT(SecondNearestMyGroupOfType,49,RESISTMAGIC)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_WEB)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_STINKING_CLOUD)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(102,46)
  !Range(LastSeenBy(Myself),15)
  !StateCheck(LastSeenBy(Myself),270381)
  !StateCheck(LastSeenBy(Myself),0x80100000)
  CheckStat(LastSeenBy(Myself),0,MINORGLOBE)
  !StateCheck(LastSeenBy(Myself),STATE_BERSERK)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  CheckStatGT(LastSeenBy(Myself),5,SAVEVSDEATH)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
  OR(4)
    !Exists(NearestMyGroupOfType)
    Range(NearestMyGroupOfType,4)
    CheckStatGT(NearestMyGroupOfType,9,SAVEVSDEATH)
    CheckStatGT(NearestMyGroupOfType,49,RESISTMAGIC)
  OR(4)
    !Exists(SecondNearestMyGroupOfType)
    Range(SecondNearestMyGroupOfType,4)
    CheckStatGT(SecondNearestMyGroupOfType,9,SAVEVSDEATH)
    CheckStatGT(SecondNearestMyGroupOfType,49,RESISTMAGIC)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_STINKING_CLOUD)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_DIRE_CHARM)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(104,42)
  Global("NOBREACH","LOCALS",1)
  OR(2)
    CheckStat(LastSeenBy(Myself),0,129) // either they have no spell turning
    RandomNumLT(99,23) //or we'll just shoot the moon
  !StateCheck(LastSeenBy(Myself),0x102029)
  !StateCheck(LastSeenBy(Myself),STATE_BERSERK)
  !General(LastSeenBy(Myself),UNDEAD)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
  OR(6)
    HPGT(LastSeenBy(Myself),25)
    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_DIRE_CHARM)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_DIRE_CHARM)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("NOBREACH","LOCALS",0)
  RandomNumLT(104,42)
  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),0x102029) //state_harmless
  !StateCheck(LastSeenBy(Myself),STATE_BERSERK)
  !General(LastSeenBy(Myself),UNDEAD)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
  OR(6)
    HPGT(LastSeenBy(Myself),25)
    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_DIRE_CHARM)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_POLYMORPH_OTHER)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(105,39)
  Global("NOBREACH","LOCALS",1)
  OR(2)
    CheckStat(LastSeenBy(Myself),0,129) // either they have no spell turning
    RandomNumLT(99,23) //or we'll just shoot the moon
  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_GREASE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(106,36)
  !Range(LastSeenBy(Myself),15)
  !StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
  !StateCheck(LastSeenBy(Myself),STATE_SLEEPING)
  CheckStatLT(LastSeenBy(Myself),1,131) //Free Action
  CheckStat(LastSeenBy(Myself),0,MINORGLOBE)
  CheckStat(LastSeenBy(Myself),0,GREASE)
  !StateCheck(LastSeenBy(Myself),STATE_SLOWED)    
  CheckStatLT(LastSeenBy(Myself),1,ENTANGLE)
  CheckStatLT(LastSeenBy(Myself),1,HELD)
  CheckStatGT(LastSeenBy(Myself),5,SAVEVSSPELL)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
  OR(4)
    !Exists(NearestMyGroupOfType)
    Range(NearestMyGroupOfType,4)
    CheckStatGT(NearestMyGroupOfType,0,131)
    CheckStatGT(NearestMyGroupOfType,49,RESISTMAGIC)
  OR(4)
    !Exists(SecondNearestMyGroupOfType)
    Range(SecondNearestMyGroupOfType,4)
    CheckStatGT(SecondNearestMyGroupOfType,0,131)
    CheckStatGT(SecondNearestMyGroupOfType,49,RESISTMAGIC)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_GREASE)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_AGANNAZAR_SCORCHER)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(107,37)
  Global("NOBREACH","LOCALS",1)
  OR(2)
    CheckStat(LastSeenBy(Myself),0,129) // either they have no spell turning
    RandomNumLT(99,23) //or we'll just shoot the moon
  Range(LastSeenBy(Myself),16)
  CheckStat(LastSeenBy(Myself),0,MINORGLOBE)
  CheckStatLT(LastSeenBy(Myself),51,RESISTFIRE)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_AGANNAZAR_SCORCHER)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_AGANNAZAR_SCORCHER)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("NOBREACH","LOCALS",0)
  RandomNumLT(107,37)
  Range(LastSeenBy(Myself),16)
  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,RESISTFIRE)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_AGANNAZAR_SCORCHER)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_MELF_ACID_ARROW)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(108,38)
  Global("NOBREACH","LOCALS",1)
  OR(2)
    CheckStat(LastSeenBy(Myself),0,129) // either they have no spell turning
    RandomNumLT(99,23) //or we'll just shoot the moon
  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_MAGIC_MISSILE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(109,38)
  Global("NOBREACH","LOCALS",1)
  OR(2)
    CheckStat(LastSeenBy(Myself),0,129) // either they have no spell turning
    RandomNumLT(99,23) //or we'll just shoot the moon
  !CheckStat(LastSeenBy(Myself),2,SCRIPTINGSTATE5)
  CheckStat(LastSeenBy(Myself),0,MINORGLOBE)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_MAGIC_MISSILE)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_MAGIC_MISSILE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("NOBREACH","LOCALS",0)
  RandomNumLT(109,38)
  !CheckStat(LastSeenBy(Myself),2,SCRIPTINGSTATE5)
  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),61,RESISTMAGIC)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_MAGIC_MISSILE)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_BURNING_HANDS)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(110,34)
  Range(LastSeenBy(Myself),5)
  CheckStatLT(LastSeenBy(Myself),51,RESISTFIRE)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  CheckStatGT(LastSeenBy(Myself),10,SAVEVSSPELL)
  CheckStat(LastSeenBy(Myself),0,MINORGLOBE)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
  OR(4)
    !Exists(NearestMyGroupOfType)
    !Range(NearestMyGroupOfType,5)
    CheckStatGT(NearestMyGroupOfType,49,RESISTFIRE)
    CheckStatGT(NearestMyGroupOfType,49,RESISTMAGIC)
  OR(4)
    !Exists(SecondNearestMyGroupOfType)
    !Range(SecondNearestMyGroupOfType,5)
    CheckStatGT(SecondNearestMyGroupOfType,49,RESISTFIRE)
    CheckStatGT(SecondNearestMyGroupOfType,49,RESISTMAGIC)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_BURNING_HANDS)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_LARLOCH_MINOR_DRAIN)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(112,42)
  Global("NOBREACH","LOCALS",1)
  OR(2)
    CheckStat(LastSeenBy(Myself),0,129) // either they have no spell turning
    RandomNumLT(99,23) //or we'll just shoot the moon
  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()
  HaveSpell(WIZARD_BLACK_BLADE_OF_DISASTER)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(103,43)
  Range(LastSeenBy(Myself),8)
  !HasItemSlot(Myself,SLOT_MISC19)                                         // more robust check to see if I already have anything in the magically created item slot
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_BLACK_BLADE_OF_DISASTER)
    AttackOneRound(LastSeenBy(Myself))
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_PHANTOM_BLADE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(111,46)
  Range(LastSeenBy(Myself),8)
  !HasItemSlot(Myself,SLOT_MISC19)                                         // more robust check to see if I already have anything in the magically created item slot
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_PHANTOM_BLADE)
    AttackOneRound(LastSeenBy(Myself))
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 #15
    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("BLAKBLAD",Myself)
  !HasItem("PHANBLAD",Myself)
  CheckStatGT(LastSeenBy(Myself),10,180)
  CheckStatLT(Myself,11,180)
THEN
  RESPONSE #100
    EquipRanged()
    AttackOneRound(LastSeenBy(Myself))
END

IF
  ActionListEmpty()
  !HasItem("BLAKBLAD",Myself)
  !HasItem("PHANBLAD",Myself)
  OR(5)
    !Range(NearestEnemyOf(Myself),5)
    CheckStatGT(LastSeenBy(Myself),0,121)
    CheckStatGT(LastSeenBy(Myself),0,125)
    HasItem("ENEBLADE",Myself)
    HasItem("MELFMET",Myself)
THEN
  RESPONSE #100
    EquipRanged()
    AttackReevaluate(LastSeenBy(Myself),45)
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)
THEN
  RESPONSE #100
    EquipMostDamagingMelee()
    AttackOneRound(NearestEnemyOf(Myself))
END

IF
  ActionListEmpty()
THEN
  RESPONSE #100
    EquipMostDamagingMelee()
    AttackOneRound(LastSeenBy(Myself))
END

IF
  ActionListEmpty()
  OR(4)
    HasItem("BLAKBLAD",Myself)
    HasItem("PHANBLAD",Myself)
    HasItem("ENEBLADE",Myself)
    HasItem("MELFMET",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

