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("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.P1TARGET])
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.P1TARGET])
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

IF
  CheckStatGT(Myself,10,180)
  CheckStatGT(Myself,5,INT)
  !GlobalTimerNotExpired("BPCHASE","LOCALS")
  See([ANYONE])
  CheckStatGT(LastSeenBy(Myself),10,180)
THEN
  RESPONSE #100
    SetGlobalTimer("BPCHASE","LOCALS",ONE_ROUND)
    DisplayStringHead(Myself,@4)
    RunAwayFrom(LastSeenBy(Myself),15)
END

IF
  CheckStatGT(Myself,10,180)
  CheckStatGT(Myself,5,INT)
  !GlobalTimerNotExpired("BPCHASE","LOCALS")
  !See([GOODCUTOFF])
THEN
  RESPONSE #100
    SetGlobal("BPCHASER","LOCALS",1)
    SetGlobalTimer("BPCHASE","LOCALS",TWO_ROUNDS)
    DisplayStringHead(Myself,@4)
    MoveToObject(Player1)
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,35)
  See([EVILCUTOFF])
  !GlobalTimerNotExpired("BPW","LOCALS")
  !HasItem("POTN52",Myself)
  !HasItem("POTN55",Myself)
THEN
  RESPONSE #80
    SetGlobalTimer("BPW","LOCALS",ONE_ROUND)
    DisplayStringHead(Myself,72808)
    Shout(123)
  RESPONSE #20
    Continue()
END

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

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

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

IF
  CheckStat(Myself,2,PUPPETTYPE)
  Exists([EVILCUTOFF.0.0.0.NEEDS_BREACH.EXTRA9])
THEN
  RESPONSE #100
END

IF
  ActionListEmpty()
  !GlobalTimerNotExpired("CHE","LOCALS")
  GlobalLT("SCH","LOCALS",3)
  HPGT(Myself,0)
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")
  Global("SNAFU","LOCALS",0)
  StateCheck(Myself,STATE_SILENCED)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_VOCALIZE)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_TRUE_SIGHT)
  CheckStat(Myself,0,118)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  Exists(LastAttackerOf(Myself))
  OR(7)
     StateCheck(NearestEnemyOfType([GOODCUTOFF]), STATE_ILLUSIONS)         // and they're Invisible, Improved Invisible, Mirror Imaged, or Blur'd
     StateCheck(SecondNearest([GOODCUTOFF]), STATE_ILLUSIONS)
     StateCheck(ThirdNearest([GOODCUTOFF]), STATE_ILLUSIONS)
     StateCheck(FourthNearest([GOODCUTOFF]),STATE_ILLUSIONS)
     StateCheck(TenthNearest([GOODCUTOFF]), STATE_ILLUSIONS)
     NumCreatureGT([GOODCUTOFF.0.0.0.0.ILLUSIONARY],0)                     // or there's an illusory creature around.
     NumCreatureGT([GOODCUTOFF.0.0.0.NEEDS_BREACH],0)                     // or there's an illusory creature around.
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(5)
     StateCheck(NearestEnemyOfType([GOODCUTOFF]),STATE_ILLUSIONS)         // and they're Invisible, Improved Invisible, Mirror Imaged, or Blur'd
     StateCheck(SecondNearest([GOODCUTOFF]),STATE_ILLUSIONS)
     StateCheck(ThirdNearest([GOODCUTOFF]),STATE_ILLUSIONS)
     StateCheck(FourthNearest([GOODCUTOFF]),STATE_ILLUSIONS)
     StateCheck(TenthNearest([GOODCUTOFF]),STATE_ILLUSIONS)
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)
  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")
  CheckStat(Myself,0,PUPPETTYPE)
  Global("SNAFU","LOCALS",0)
  RandomNumLT(101,38)
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)
  CheckStat(Myself,0,PUPPETTYPE)
  RandomNumLT(102,38)
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)
  CheckStat(Myself,0,PUPPETTYPE)
  !StateCheck(Myself,STATE_POISONED)
  RandomNumLT(103,36)
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)
  !StateCheck(Myself,STATE_NOT_VISIBLE)
  !StateCheck(Myself,STATE_POISONED)
  RandomNum(4,4)
THEN
  RESPONSE #100
    SetGlobalTimer("BPIP","LOCALS",15)
    Spell(Myself,WIZARD_SHADOW_DOOR)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_IMPROVED_MANTLE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStat(Myself,0,128)
  Global("SNAFU","LOCALS",0)
  OR(2)
    Range(NearestEnemyOf(Myself),6)
    AttackedBy([GOODCUTOFF],DEFAULT)
  RandomNumLT(5,3)
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)
  OR(5)
    See([GOODCUTOFF.0.0.CLERIC_ALL])
    See([GOODCUTOFF.0.0.BARD_ALL])
    See([GOODCUTOFF.0.0.DRUID_ALL])
    See([GOODCUTOFF.0.0.LONG_BOW])
    See([GOODCUTOFF.0.0.SORCERER])
  CheckStat(Myself,0,129)
  CheckStat(Myself,0,116)
  RandomNumLT(6,3)
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)
  OR(5)
    See([GOODCUTOFF.0.0.CLERIC_ALL])
    See([GOODCUTOFF.0.0.BARD_ALL])
    See([GOODCUTOFF.0.0.DRUID_ALL])
    See([GOODCUTOFF.0.0.LONG_BOW])
    See([GOODCUTOFF.0.0.SORCERER])
  CheckStat(Myself,0,129)
  CheckStat(Myself,0,164)
  CheckStat(Myself,0,116)
  RandomNumLT(7,3)
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)
  CheckStat(Myself,0,128)
  OR(2)
    Range(NearestEnemyOf(Myself),6)
    AttackedBy([GOODCUTOFF],DEFAULT)
  RandomNumLT(8,4)
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)
  CheckStat(Myself,0,128)
  OR(2)
    Range(NearestEnemyOf(Myself),6)
    AttackedBy([GOODCUTOFF],DEFAULT)
  RandomNumLT(9,4)
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)
  OR(5)
    See([GOODCUTOFF.0.0.CLERIC_ALL])
    See([GOODCUTOFF.0.0.BARD_ALL])
    See([GOODCUTOFF.0.0.DRUID_ALL])
    See([GOODCUTOFF.0.0.LONG_BOW])
    See([GOODCUTOFF.0.0.SORCERER])
  !HasBounceEffects(Myself)
  CheckStat(Myself,0,164)
  CheckStat(Myself,0,MINORGLOBE)
  CheckStat(Myself,0,116)
  RandomNumLT(10,4)
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)
  OR(5)
    See([GOODCUTOFF.0.0.CLERIC_ALL])
    See([GOODCUTOFF.0.0.BARD_ALL])
    See([GOODCUTOFF.0.0.DRUID_ALL])
    See([GOODCUTOFF.0.0.LONG_BOW])
    See([GOODCUTOFF.0.0.SORCERER])
  !HasBounceEffects(Myself)
  CheckStat(Myself,0,164)
  !CheckStat(Myself,1,162)
  CheckStat(Myself,0,116)
  RandomNumLT(11,3)
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)
  !StateCheck(Myself,STATE_INVISIBLE)
  !StateCheck(Myself,STATE_IMPROVEDINVISIBILITY)
  RandomNumLT(12,4)
THEN
  RESPONSE #100
    SetGlobalTimer("BPIP","LOCALS",15)
    Spell(Myself,WIZARD_IMPROVED_INVISIBILITY)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_IMPROVED_HASTE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  !StateCheck(Myself,STATE_HASTED)
  CheckStat(Myself,0,IMPROVEDHASTE)
  RandomNumLT(13,4)
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)
  CheckStat(Myself,0,177)
  OR(5)
    CheckStatGT(Myself,0,129)
    CheckStatGT(Myself,0,164)
    CheckStatGT(Myself,0,SHIELDGLOBE)
    CheckStatGT(Myself,0,116)
    CheckStatGT(Myself,3,STONESKINS)
  RandomNumLT(14,4)
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)
  OR(5)
    See([GOODCUTOFF.0.0.CLERIC_ALL])
    See([GOODCUTOFF.0.0.BARD_ALL])
    See([GOODCUTOFF.0.0.DRUID_ALL])
    See([GOODCUTOFF.0.0.LONG_BOW])
    See([GOODCUTOFF.0.0.SORCERER])
  CheckStat(Myself,0,164)
  CheckStat(Myself,0,SHIELDGLOBE)
  CheckStat(Myself,0,MINORGLOBE)
  CheckStat(Myself,0,116)
  CheckStat(Myself,0,129)
  RandomNumLT(15,4)
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)
  OR(5)
    See([GOODCUTOFF.0.0.CLERIC_ALL])
    See([GOODCUTOFF.0.0.BARD_ALL])
    See([GOODCUTOFF.0.0.DRUID_ALL])
    See([GOODCUTOFF.0.0.LONG_BOW])
    See([GOODCUTOFF.0.0.SORCERER])
  CheckStat(Myself,0,129)
  CheckStat(Myself,0,164)
  CheckStat(Myself,0,116)
  CheckStat(Myself,0,SHIELDGLOBE)
  CheckStat(Myself,0,MINORGLOBE)
  RandomNumLT(16,4)
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)
  OR(5)
    See([GOODCUTOFF.0.0.CLERIC_ALL])
    See([GOODCUTOFF.0.0.BARD_ALL])
    See([GOODCUTOFF.0.0.DRUID_ALL])
    See([GOODCUTOFF.0.0.LONG_BOW])
    See([GOODCUTOFF.0.0.SORCERER])
  CheckStat(Myself,0,129)
  CheckStat(Myself,0,164)
  CheckStat(Myself,0,SHIELDGLOBE)
  CheckStat(Myself,0,116)
  RandomNumLT(17,4)
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")
  CheckStatLT(Myself,1,STONESKINS)
  RandomNumLT(18,5)
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)
  CheckStat(Myself,0,128)
  CheckStat(Myself,0,125)
  CheckStat(Myself,0,SHIELDGLOBE)
  Range(NearestEnemyOf(Myself),8)
  RandomNumLT(19,5)
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)
  CheckStat(Myself,0,128)
  CheckStat(Myself,0,125)
  CheckStat(Myself,0,SHIELDGLOBE)
  Range(NearestEnemyOf(Myself),8)
  RandomNumLT(20,5)
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)
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)
  HitBy([ANYONE],FIRE)
  OR(2)
    CheckStatLT(Myself,100,RESISTFIRE)
    CheckStatLT(Myself,80,RESISTMAGICFIRE)
  RandomNumLT(22,5)
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)
  HitBy([ANYONE],COLD)
  OR(2)
    CheckStatLT(Myself,100,RESISTCOLD)
    CheckStatLT(Myself,80,RESISTMAGICCOLD)
  RandomNumLT(23,5)
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)
  StateCheck([ANYONE],STATE_STONE_DEATH)
  RandomNumLT(24,5)
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)
  !StateCheck(Myself,STATE_HASTED)
  CheckStat(Myself,0,IMPROVEDHASTE)
  RandomNumLT(25,6)
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)
  CheckStat(Myself,0,179)
  OR(2)
    !Range(NearestEnemyOf(Myself),6)
    AttackedBy([GOODCUTOFF],RANGED)
  RandomNumLT(26,6)
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)
  CheckStatLT(Myself,5,SCRIPTINGSTATE5)
  CheckStatGT(Myself,0,ARMORCLASS)
  RandomNumLT(27,6)
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)
  OR(6)
    Range([GOODCUTOFF.0.0.THIEF_ALL],10)
    Range([GOODCUTOFF.0.0.FIGHTER_ALL],10)
    Range([GOODCUTOFF.0.0.PALADIN_ALL],10)
    Range([GOODCUTOFF.0.0.MONK],10)
    See([GOODCUTOFF.0.0.RANGER_ALL])
    HitBy([ANYONE],MISSILE)
  !StateCheck(Myself,STATE_MIRRORIMAGE)
  RandomNumLT(28,6)
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)
  OR(6)
    Range([GOODCUTOFF.0.0.THIEF_ALL],10)
    Range([GOODCUTOFF.0.0.FIGHTER_ALL],10)
    Range([GOODCUTOFF.0.0.PALADIN_ALL],10)
    Range([GOODCUTOFF.0.0.MONK],10)
    See([GOODCUTOFF.0.0.RANGER_ALL])
    HitBy([ANYONE],MISSILE)
  !StateCheck(Myself,STATE_BLUR)
  RandomNumLT(29,5)
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)
  CheckStat(Myself,0,SCRIPTINGSTATE5)
  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)
  RandomNumLT(18,4)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_SHIELD)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_IMPROVED_HASTE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  OR(2)
    CheckStatGT(Myself,0,IMPROVEDHASTE)
    StateCheck(Myself,STATE_HASTED)
  !StateCheck([EVILCUTOFF],STATE_HASTED)
  CheckStat([EVILCUTOFF],0,IMPROVEDHASTE)
  RandomNumLT(31,6)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell([EVILCUTOFF],WIZARD_IMPROVED_HASTE)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_HASTE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  OR(3)
    Range([EVILCUTOFF],10)
    CheckStatGT(Myself,0,IMPROVEDHASTE)
    StateCheck(Myself,STATE_HASTED)
  !StateCheck([EVILCUTOFF],STATE_HASTED)
  CheckStat([EVILCUTOFF],0,IMPROVEDHASTE)
  RandomNumLT(32,6)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell([EVILCUTOFF],WIZARD_HASTE)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_RESIST_FEAR)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  OR(6)
    StateCheck(SixthNearest([EVILCUTOFF]),STATE_PANIC)
    StateCheck(FifthNearest([EVILCUTOFF]),STATE_PANIC)
    StateCheck(FourthNearest([EVILCUTOFF]),STATE_PANIC)
    StateCheck(ThirdNearest([EVILCUTOFF]),STATE_PANIC)
    StateCheck(SecondNearest([EVILCUTOFF]),STATE_PANIC)
    StateCheck([EVILCUTOFF],STATE_PANIC)
  See(ThirdNearest([EVILCUTOFF]))
  RandomNumLT(33,6)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_RESIST_FEAR)
END

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

IF
  RandomNumLT(32,21)
  OR(3)
    Heard(ThirdNearest([EVILCUTOFF]),124)
    Heard(SecondNearest([EVILCUTOFF]),124)
    Heard([EVILCUTOFF],124)
  HPGT(LastHeardBy(Myself),1)
  Range(LastHeardBy(Myself),20)
  HPGT(LastHitter(LastHeardBy(Myself)),1)
  !See(LastHitter(LastHeardBy(Myself)))
  HPGT(LastAttackerOf(LastHeardBy(Myself)),1)
  !See(LastAttackerOf(LastHeardBy(Myself)))
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  RandomNumLT(31,21)
  OR(6)
    See(NearestEnemyOf(Myself))
    See(WeakestOf)
    See(WorstAC)
    See(MostDamagedOf)
    See(LastAttackerOf(Myself))
    See(LastHitter(Myself))
  RandomNumLT(28,22)
  OR(4)
    See([GOODCUTOFF.0.0.0.0.SUMMONED_DEMON])
    See([GOODCUTOFF.0.0.0.0.SUMMONED])
    See([GOODCUTOFF.0.0.0.SIMULACRUM])
    See([GOODCUTOFF.0.0.0.0.ILLUSIONARY])
  RandomNumLT(29,23)
  OR(7)
    See([PC.0.0.RANGER_ALL])
    See([PC.0.0.PALADIN_ALL])
    See([PC.0.0.BARD_ALL])
    See([PC.0.0.DRUID_ALL])
    See([PC.0.0.CLERIC_ALL])
    See([PC.0.0.LONG_BOW])
    See([PC.0.0.SORCERER])
  RandomNumLT(30,16)
  See(Protagonist)
  RandomNumLT(26,10)
  OR(4)
    See([GOODCUTOFF.0.0.RANGER_ALL])
    See([GOODCUTOFF.0.0.DRUID_ALL])
    See([GOODCUTOFF.0.0.PALADIN_ALL])
    See([GOODCUTOFF.0.0.CLERIC_ALL])
  RandomNumLT(27,10)
  OR(3)
    See([GOODCUTOFF.0.0.MONK])
    See([GOODCUTOFF.0.0.BARD_ALL])
    See([GOODCUTOFF.0.0.THIEF_ALL])
  RandomNumLT(24,9)
  OR(3)
    See(StrongestOf)
    See(BestAC)
    See(LeastDamagedOf)
  RandomNumLT(25,9)
  See(WeakestOf)
  RandomNumLT(23,8)
  See(WorstAC)
  RandomNumLT(21,8)
  See(MostDamagedOf)
  RandomNumLT(32,11)
  OR(2)
    See(TenthNearest([GOODCUTOFF.0.0.LONG_BOW]))
    See(TenthNearest([GOODCUTOFF.0.0.SORCERER]))
  RandomNumLT(20,8)
  See(TenthNearestEnemyOf(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
  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()
  OR(2)
    StateCheck(Myself,STATE_INVISIBLE)
    StateCheck(Myself,STATE_IMPROVEDINVISIBILITY)
  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)
  !Range([EVILCUTOFF.0.0.0.0.SUMMONED],15)
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)
  !Range(LastSeenBy(Myself),15)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_DEATH_FOG)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_RUBY_RAY_OF_REVERSAL)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStatGT(LastSeenBy(Myself),0,164)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_RUBY_RAY_OF_REVERSAL)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_PROTECTION_FROM_PETRIFICATION)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Race(LastSeenBy(Myself),BASILISK)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_PROTECTION_FROM_PETRIFICATION)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_TENSERS_TRANSFORMATION)
  CheckStat(Myself,0,182)
  !GlobalTimerNotExpired("BPT","LOCALS")
  OR(2)
    HasItem("BLAKBLAD",Myself)
    HasItem("PHANBLAD",Myself)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_TENSERS_TRANSFORMATION)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_DOMINATION)
  Allegiance(LastSeenBy(Myself),EVILCUTOFF)
  StateCheck(LastSeenBy(Myself),STATE_CHARMED)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStat(LastSeenBy(Myself),0,129)
THEN
  RESPONSE #80
    Spell(LastSeenBy(Myself),WIZARD_DOMINATION)
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
  RESPONSE #20
    Continue()
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_DIRE_CHARM)
  Allegiance(LastSeenBy(Myself),EVILCUTOFF)
  StateCheck(LastSeenBy(Myself),STATE_CHARMED)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStat(LastSeenBy(Myself),0,129)
THEN
  RESPONSE #80
    Spell(LastSeenBy(Myself),WIZARD_DIRE_CHARM)
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
  RESPONSE #20
    Continue()
END

IF
  ActionListEmpty()
  !GlobalTimerNotExpired("BPT","LOCALS")
  HaveSpell(WIZARD_TIME_STOP)
  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")
  !Range(LastSeenBy(Myself),5)
  RandomNumLT(50,32)
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")
  CheckStat(LastSeenBy(Myself),0,129)
  !StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
  RandomNumLT(51,32)
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")
  CheckStat(LastSeenBy(Myself),0,129)
  !StateCheck(LastSeenBy(Myself),STATE_PANIC)
  RandomNumLT(52,31)
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")
  CheckStat(LastSeenBy(Myself),0,129)
  !StateCheck(LastSeenBy(Myself),STATE_SILENCED)
  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)
  CheckStat(LastSeenBy(Myself),0,129)
  RandomNumLT(53,36)
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")
  !HasBounceEffects(LastSeenBy(Myself))
  Range(LastSeenBy(Myself),15)
  RandomNumLT(54,31)
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")
  !Range([EVILCUTOFF],15)
  RandomNumLT(55,35)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_WAIL_OF_THE_BANSHEE)
END

IF
  ActionListEmpty()
  HaveSpell(KAISHAS_CHANGE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStatLT(LastSeenBy(Myself),75,RESISTMAGIC)
  RandomNumLT(56,38)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),KAISHAS_CHANGE)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_DRAGONS_BREATH)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStatLT(LastSeenBy(Myself),65,RESISTMAGICFIRE)
  RandomNumLT(57,37)
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")
  CheckStatLT(LastSeenBy(Myself),70,RESISTMAGIC)
  RandomNumLT(58,38)
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")
  !Range(LastSeenBy(Myself),15)
  CheckStatLT(LastSeenBy(Myself),80,RESISTMAGICFIRE)
  CheckStatLT(LastSeenBy(Myself),80,RESISTMAGIC)
  RandomNumLT(59,36)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_METEOR_SWARM)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_PRISMATIC_SPRAY)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStatLT(LastSeenBy(Myself),80,RESISTMAGIC)
  RandomNumLT(60,36)
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")
  LevelGT(LastSeenBy(Myself),13)
  RandomNumLT(61,38)
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")
  LevelGT(LastSeenBy(Myself),9)
  RandomNumLT(62,38)
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")
  !GlobalTimerNotExpired("DEVA","GLOBAL")
  NumCreatureLT([EVILCUTOFF.0.0.0.0.SUMMONED],7)
  RandomNumLT(63,36)
THEN
  RESPONSE #100
    SetGlobalTimer("DEVA","GLOBAL",96)
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_SUMMON_PLANATAR_GOOD)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_SUMMON_PLANATAR_EVIL)
  !GlobalTimerNotExpired("BPT","LOCALS")
  !GlobalTimerNotExpired("DEVA","GLOBAL")
  NumCreatureLT([EVILCUTOFF.0.0.0.0.SUMMONED],7)
  RandomNumLT(64,36)
THEN
  RESPONSE #100
    SetGlobalTimer("DEVA","GLOBAL",96)
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_SUMMON_PLANATAR_EVIL)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_CHAOS)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStat(LastSeenBy(Myself),0,129)
  !StateCheck(LastSeenBy(Myself),STATE_CONFUSED)
  RandomNumLT(65,38)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_CHAOS)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_POWER_WORD_BLIND)
  !GlobalTimerNotExpired("BPT","LOCALS")
  !StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
  !StateCheck(LastSeenBy(Myself),STATE_BLIND)
  CheckStat(LastSeenBy(Myself),0,129)
  RandomNumLT(66,38)
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")
  CheckStat(LastSeenBy(Myself),0,129)
  CheckStatLT(LastSeenBy(Myself),60,RESISTELECTRICITY)
  CheckStatLT(LastSeenBy(Myself),60,RESISTMAGIC)
  RandomNumLT(67,42)
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")
  CheckStat(LastSeenBy(Myself),0,129)
  CheckStatGT(LastSeenBy(Myself),6,SAVEVSDEATH)
  RandomNumLT(68,38)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_FINGER_OF_DEATH)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_MAZE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  HPGT(LastSeenBy(Myself),50)
  CheckStat(LastSeenBy(Myself),0,129)
  RandomNumLT(69,42)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_MAZE)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_MORDENKAINENS_SWORD)
  !GlobalTimerNotExpired("BPT","LOCALS")
  NumCreatureLT([EVILCUTOFF.0.0.0.0.SUMMONED],7)
  RandomNumLT(70,40)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_MORDENKAINENS_SWORD)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_DISINTEGRATE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStat(LastSeenBy(Myself),0,129)
  CheckStatLT(LastSeenBy(Myself),70,RESISTMAGIC)
  RandomNumLT(71,36)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_DISINTEGRATE)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_FLESH_TO_STONE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStat(LastSeenBy(Myself),0,129)
  RandomNumLT(72,37)
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")
  CheckStat(LastSeenBy(Myself),0,129)
  LevelGT(LastSeenBy(Myself),13)
  RandomNumLT(73,38)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_ENERGY_DRAIN)
END

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

IF
  ActionListEmpty()
  HaveSpell(WIZARD_BREACH)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStat(LastSeenBy(Myself),0,164)
  CheckStat(LastSeenBy(Myself),0,177)
  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)
  RandomNumLT(75,45)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_BREACH)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_PIERCE_MAGIC)
  !GlobalTimerNotExpired("BPT","LOCALS")
  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),29,RESISTMAGIC)
  RandomNumLT(76,46)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_PIERCE_MAGIC)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_WARDING_WHIP)
  !GlobalTimerNotExpired("BPT","LOCALS")
  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)
  RandomNumLT(77,47)
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")
  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)
  RandomNumLT(78,48)
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")
  !StateCheck(LastSeenBy(Myself),STATE_SLEEPING)
  !StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
  RandomNumLT(79,45)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_EMOTION_HOPELESSNESS)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_CONFUSION)
  !GlobalTimerNotExpired("BPT","LOCALS")
  !StateCheck(LastSeenBy(Myself),STATE_CONFUSED)
  RandomNumLT(80,46)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_CONFUSION)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_FEEBLEMIND)
  !GlobalTimerNotExpired("BPT","LOCALS")
  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)
  CheckStat(LastSeenBy(Myself),0,129)
  RandomNumLT(81,51)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_FEEBLEMIND)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_SLOW)
  !GlobalTimerNotExpired("BPT","LOCALS")
  !StateCheck(LastSeenBy(Myself),STATE_SLOWED)
  RandomNumLT(82,48)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_SLOW)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_SUMMON_NISHRUU)
  !GlobalTimerNotExpired("BPT","LOCALS")
  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)
  NumCreatureLT([EVILCUTOFF.0.0.0.0.SUMMONED],7)
  RandomNumLT(83,53)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_SUMMON_NISHRUU)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_DOMINATION)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStat(LastSeenBy(Myself),0,129)
  !StateCheck(LastSeenBy(Myself),STATE_CHARMED)
  RandomNumLT(84,46)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_DOMINATION)
END

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

IF
  ActionListEmpty()
  HaveSpell(WIZARD_SUMMON_EFREET)
  !GlobalTimerNotExpired("BPT","LOCALS")
  NumCreatureLT([EVILCUTOFF.0.0.0.0.SUMMONED],7)
  RandomNumLT(86,46)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_SUMMON_EFREET)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_DEATH_SPELL)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStat(LastSeenBy(Myself),0,129)
  CheckStatGT(LastSeenBy(Myself),6,SAVEVSDEATH)
  NumCreatureGT([GOODCUTOFF],3)
  RandomNumLT(87,45)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_DEATH_SPELL)
END

IF
  ActionListEmpty()
  HasItem("WAND10",Myself)
  !GlobalTimerNotExpired("BPT","LOCALS")
  NumCreatureLT([EVILCUTOFF.0.0.0.0.SUMMONED],7)
  RandomNumLT(88,38)
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")
  NumCreatureLT([EVILCUTOFF.0.0.0.0.SUMMONED],7)
  RandomNumLT(89,45)
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")
  NumCreatureLT([EVILCUTOFF.0.0.0.0.SUMMONED],7)
  RandomNumLT(90,46)
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")
  CheckStat(LastSeenBy(Myself),0,129)
  CheckStatLT(LastSeenBy(Myself),70,RESISTMAGICCOLD)
  RandomNumLT(91,49)
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")
  Range(ThirdNearestEnemyOf(Myself),15)
  !Range(Nearest([EVILCUTOFF]),15)
  CheckStatLT(LastSeenBy(Myself),70,RESISTMAGICFIRE)
  RandomNumLT(92,48)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_SUN_FIRE)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_ENERGY_BLADES)
  !GlobalTimerNotExpired("BPT","LOCALS")
  !Range(NearestEnemyOf(Myself),5)
  !HasItem("BLAKBLAD",Myself)
  !HasItem("PHANBLAD",Myself)
  !HasItem("MELFMET",Myself)
  !HasItem("ENEBLADE",Myself)
  RandomNumLT(93,47)
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")
  NumCreatureLT([EVILCUTOFF.0.0.0.0.SUMMONED],7)
  RandomNumLT(94,42)
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")
  NumCreatureLT([EVILCUTOFF.0.0.0.0.SUMMONED],7)
  RandomNumLT(95,41)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_MONSTER_SUMMONING_1)
END

IF
  ActionListEmpty()
  HasItem("WAND06",Myself)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStat(LastSeenBy(Myself),0,129)
  RandomNumLT(96,49)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    DisplayStringHead(Myself,31971)
    UseItem("WAND06",LastSeenBy(Myself))
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_FIREBALL)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStatLT(LastSeenBy(Myself),50,RESISTMAGICFIRE)
  CheckStatLT(LastSeenBy(Myself),50,RESISTMAGIC)
  !Range(LastSeenBy(Myself),15)
  RandomNumLT(97,53)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_FIREBALL)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_ICE_STORM)
  !GlobalTimerNotExpired("BPT","LOCALS")
  !Range(LastSeenBy(Myself),15)
  CheckStatLT(LastSeenBy(Myself),60,RESISTMAGICCOLD)
  RandomNumLT(98,52)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_ICE_STORM)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_LIGHTNING_BOLT)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStatLT(LastSeenBy(Myself),50,RESISTELECTRICITY)
  CheckStatLT(LastSeenBy(Myself),50,RESISTMAGIC)
  CheckStat(LastSeenBy(Myself),0,129)
  RandomNumLT(99,51)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_LIGHTNING_BOLT)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_FLAME_ARROW)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStat(LastSeenBy(Myself),0,129)
  CheckStatLT(LastSeenBy(Myself),50,RESISTMAGICFIRE)
  RandomNumLT(113,60)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_FLAME_ARROW)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_MELF_METEOR)
  !GlobalTimerNotExpired("BPT","LOCALS")
  !Range(LastSeenBy(Myself),5)
  !HasItem("BLAKBLAD",Myself)
  !HasItem("PHANBLAD",Myself)
  !HasItem("MELFMET",Myself)
  !HasItem("ENEBLADE",Myself)
  RandomNumLT(100,55)
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")
  !Range(LastSeenBy(Myself),15)
  !StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
  !StateCheck(LastSeenBy(Myself),STATE_HARMLESS)
  RandomNumLT(101,48)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_WEB)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_STINKING_CLOUD)
  !GlobalTimerNotExpired("BPT","LOCALS")
  !Range(LastSeenBy(Myself),15)
  !StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
  !StateCheck(LastSeenBy(Myself),STATE_SLEEPING)
  RandomNumLT(102,46)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_STINKING_CLOUD)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_BLACK_BLADE_OF_DISASTER)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Range(LastSeenBy(Myself),8)
  !HasItem("BLAKBLAD",Myself)
  !HasItem("PHANBLAD",Myself)
  !HasItem("ENEBLADE",Myself)
  !HasItem("MELFMET",Myself)
  RandomNumLT(103,43)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_BLACK_BLADE_OF_DISASTER)
    AttackOneRound(LastSeenBy(Myself))
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_DIRE_CHARM)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStat(LastSeenBy(Myself),0,129)
  !StateCheck(LastSeenBy(Myself),STATE_CHARMED)
  RandomNumLT(104,42)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_DIRE_CHARM)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_POLYMORPH_OTHER)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStat(LastSeenBy(Myself),0,129)
  CheckStatLT(LastSeenBy(Myself),50,RESISTMAGIC)
  CheckStat(LastSeenBy(Myself),0,POLYMORPHED)
  HPGT(LastSeenBy(Myself),40)
  RandomNumLT(105,39)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_POLYMORPH_OTHER)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_GREASE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  !Range(LastSeenBy(Myself),15)
  !StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
  !StateCheck(LastSeenBy(Myself),STATE_SLEEPING)
  CheckStat(LastSeenBy(Myself),0,GREASE)
  RandomNumLT(106,36)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_GREASE)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_AGANNAZAR_SCORCHER)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStat(LastSeenBy(Myself),0,129)
  CheckStatLT(LastSeenBy(Myself),50,RESISTMAGIC)
  CheckStatLT(LastSeenBy(Myself),50,RESISTMAGICFIRE)
  RandomNumLT(107,37)
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")
  CheckStat(LastSeenBy(Myself),0,129)
  CheckStatLT(LastSeenBy(Myself),50,RESISTMAGIC)
  CheckStatLT(LastSeenBy(Myself),50,RESISTACID)
  RandomNumLT(108,38)
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")
  CheckStatLT(LastSeenBy(Myself),50,RESISTMAGIC)
  !CheckStat(LastSeenBy(Myself),2,SCRIPTINGSTATE5)
  CheckStat(LastSeenBy(Myself),0,129)
  RandomNumLT(109,38)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_MAGIC_MISSILE)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_BURNING_HANDS)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStat(LastSeenBy(Myself),0,129)
  CheckStatLT(LastSeenBy(Myself),50,RESISTMAGIC)
  CheckStatLT(LastSeenBy(Myself),50,RESISTMAGICFIRE)
  Range(LastSeenBy(Myself),5)
  RandomNumLT(110,34)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_BURNING_HANDS)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_PHANTOM_BLADE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Range(LastSeenBy(Myself),8)
  !HasItemSlot(Myself,SLOT_MISC19)                                         // more robust check to see if I already have anything in the magically created item slot
  RandomNumLT(111,46)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_PHANTOM_BLADE)
    AttackOneRound(LastSeenBy(Myself))
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_LARLOCH_MINOR_DRAIN)
  !GlobalTimerNotExpired("BPT","LOCALS")
  !GlobalTimerNotExpired("BPVampT","LOCALS")
  Range(LastSeenBy(Myself),8)
  HPPercentLT(Myself,90)
  RandomNumLT(112,32)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    SetGlobalTimer("BPVampT","LOCALS",ONE_TURN)
    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
  ActionListEmpty()
  HPPercentLT(Myself,25)
  Range(LastHitter(Myself),10)
  !GlobalTimerNotExpired("BPW","LOCALS")
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)
THEN
  RESPONSE #100
    EquipMostDamagingMelee()
    AttackOneRound(NearestEnemyOf(Myself))
END

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

