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(3)
    HPLT(Myself,5)
    Dead("TOLMAG02")
    Global("BP_MageMoved","GLOBAL",1)
  Global("BP_IMoved","LOCALS",0)
THEN
  RESPONSE #100
    ClearAllActions()
    StartCutSceneMode()
    ReallyForceSpellPointRES("SPWI402",[1800.600])
    DestroyItem("SUREHP1")  // <Invalid Strref -1>
    ReallyForceSpell(Myself,CLERIC_HEAL)
    SetGlobal("BPSPHERE","GLOBAL",15)
    SetGlobal("BP_MageMoved","GLOBAL",1)
    SetGlobal("BP_IMoved","LOCALS",1)
    EndCutSceneMode()
END

//Double-check to destroy SureHP1
IF
  GlobalGT("BPSPHERE","GLOBAL",14)
  HasItem("SUREHP1",Myself)
THEN
  RESPONSE #100
    DestroyItem("SUREHP1")
END

IF
  CheckStat(Myself,1,127)
  See([EVILCUTOFF.0.0.LONG_BOW.0.ILLUSIONARY])
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
  GlobalLT("BPSPHERE","GLOBAL",14)
THEN
  RESPONSE #100
    NoAction()
END

IF
  HPPercentLT(Myself,25)
  GlobalLT("BPSPHERE","GLOBAL",15)
THEN
  RESPONSE #100
    SetGlobal("BPSPHERE","GLOBAL",15)
    ReallyForceSpellPointRES("SPWI402",[2180.700])
    ReallyForceSpell(Myself,CLERIC_HEAL)
    DestroyItem("SUREHP1")
END

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

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

IF
  GlobalTimerNotExpired("BPCHASE","LOCALS")
  Global("BPCHASER","LOCALS",1)
  OR(2)
    See([GOODCUTOFF])
    See(LastHitter(Myself))
THEN
  RESPONSE #20
    DisplayStringHead(Myself,@0)
    SetGlobal("BPCHASER","LOCALS",0)
    AttackReevaluate(LastSeenBy(Myself),15)
  RESPONSE #20
    DisplayStringHead(Myself,@0)
    SetGlobal("BPCHASER","LOCALS",0)
    SetGlobalTimer("BPT","LOCALS",6)
    ForceSpell(LastSeenBy(Myself),WIZARD_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_STUN)
    RemoveSpell(WIZARD_NPC_SYMBOL_STUN)
  RESPONSE #20
    DisplayStringHead(Myself,@0)
    SetGlobal("BPCHASER","LOCALS",0)
    SetGlobalTimer("BPT","LOCALS",6)
    ForceSpell(LastSeenBy(Myself),WIZARD_NPC_SYMBOL_FEAR)
    RemoveSpell(WIZARD_NPC_SYMBOL_FEAR)
  RESPONSE #10
    DisplayStringHead(Myself,@0)
    SetGlobal("BPCHASER","LOCALS",0)
    SetGlobalTimer("BPT","LOCALS",6)
    ForceSpell(LastSeenBy(Myself),WIZARD_FIREBALL)
    RemoveSpell(WIZARD_FIREBALL)
  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))
THEN
  RESPONSE #100
    DisplayStringHead(Myself,@1)
    SetGlobal("BPCHASER","LOCALS",0)
    ClearActions(Myself)
    Continue()
END

IF
  Global("BP_BOMB","LOCALS",2)
  Global("BP_BOMBSAWAY","MYAREA",1)
  !GlobalTimerNotExpired("BPT","LOCALS")
  See([GOODBUTRED.ARMOR.ROBES.WIZARD_EYE.114])
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",3)
    ForceSpell(LastSeenBy(Myself),WIZARD_ABI_DALZIMS_HORRID_WILTING)
    RemoveSpell(WIZARD_ABI_DALZIMS_HORRID_WILTING)
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",3)
    ForceSpell(LastSeenBy(Myself),WIZARD_NPC_SYMBOL_STUN)
    RemoveSpell(WIZARD_NPC_SYMBOL_STUN)
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",3)
    ForceSpell(LastSeenBy(Myself),WIZARD_NPC_SYMBOL_FEAR)
    RemoveSpell(WIZARD_NPC_SYMBOL_FEAR)
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",3)
    ForceSpell(LastSeenBy(Myself),WIZARD_FIREBALL)
    RemoveSpell(WIZARD_FIREBALL)
  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([GOODBUTRED.ARMOR.ROBES.WIZARD_EYE.114])
THEN
  RESPONSE #100
    MoveToObject(LastHitter(Myself))
END

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

IF
  TookDamage()
  Global("BPCHASER","LOCALS",0)
  !See(LastHitter(Myself))
  !See([GOODCUTOFF])
  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,WIZARD_GREATER_MALISON)
  CheckStatGT(Myself,5,INT)
  OR(2)
    See(LastAttackerOf(Myself))
    See(LastHitter(Myself))
  CheckStatLT(LastSeenBy(Myself),11,WIZARD_GREATER_MALISON)
  !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,WIZARD_GREATER_MALISON)
  CheckStatGT(Myself,5,INT)
  OR(2)
    See(TenthNearest([GOODCUTOFF]))
    See(TenthNearest([PC]))
  CheckStatLT(LastSeenBy(Myself),11,WIZARD_GREATER_MALISON)
  !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,WIZARD_GREATER_MALISON)
  CheckStatGT(Myself,5,INT)
  See(TenthNearest)
  CheckStatLT(TenthNearest,11,WIZARD_GREATER_MALISON)
  !GlobalTimerNotExpired("BPCHASE","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("BPCHASE","LOCALS",ONE_ROUND)
    DisplayStringHead(Myself,@4)
    MoveToObject(TenthNearest)
END

IF
  CheckStatGT(Myself,10,WIZARD_GREATER_MALISON)
  CheckStatGT(Myself,5,INT)
  !GlobalTimerNotExpired("BPCHASE","LOCALS")
  See(Nearest)
  CheckStatGT(Nearest,10,WIZARD_GREATER_MALISON)
THEN
  RESPONSE #100
    SetGlobalTimer("BPCHASE","LOCALS",ONE_ROUND)
    DisplayStringHead(Myself,@4)
    RunAwayFrom(Nearest,15)
END

IF
  CheckStatGT(Myself,10,WIZARD_GREATER_MALISON)
  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
  Range(NearestEnemyOf(Myself),2)
  OR(2)
    CheckStatGT(NearestEnemyOf(Myself),0,CLERIC_BLADE_BARRIER)
    CheckStatGT(NearestEnemyOf(Myself),0,WIZARD_FIRE_SHIELD)
THEN
  RESPONSE #70
    RunAwayFrom(NearestEnemyOf(Myself),4)
  RESPONSE #30
    Continue()
END

IF
  HPPercentLT(Myself,60)
  !GlobalTimerNotExpired("POT","LOCALS")
  HasItem("POTN52",Myself)  // ~Potion of Extra Healing~
THEN
  RESPONSE #100
    SetGlobalTimer("POT","LOCALS",ONE_ROUND)
    DisplayStringHead(Myself,46150)  // ~quaffs a potion~
    UseItem("POTN52",Myself)  // ~Potion of Extra Healing~
END

IF
  ActionListEmpty()
  See([EVILCUTOFF])
  HPPercentLT(Myself,35)
  !GlobalTimerNotExpired("BPW","LOCALS")
  !HasItem("POTN52",Myself)  // ~Potion of Extra Healing~
THEN
  RESPONSE #80
    SetGlobalTimer("BPW","LOCALS",ONE_ROUND)
    DisplayStringHead(Myself,72808)  // ~I need healing!~
    Shout(123)
  RESPONSE #20
    Continue()
END

IF
  ActionListEmpty()
  StateCheck(Myself,STATE_POISONED)
  !GlobalTimerNotExpired("POIS","LOCALS")
  See([EVILCUTOFF])
  !HasItem("POTN17",Myself)  // ~Elixir of Health~
  !HasItem("POTN20",Myself)  // ~Antidote~
THEN
  RESPONSE #100
    Shout(83)
    DisplayStringHead(Myself,@6)
    SetGlobalTimer("POIS","LOCALS",ONE_ROUND)
END

IF
  Global("SNAFU","LOCALS",0)
  OR(4)
    CheckStatGT(Myself,1,CLERIC_INSECT_PLAGUE)
    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,2,CLERIC_INSECT_PLAGUE)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
  CheckStat(Myself,0,SCRIPTINGSTATE4)
  !StateCheck(Myself,STATE_SILENCED)
THEN
  RESPONSE #100
    SetGlobal("SNAFU","LOCALS",0)
END

IF
  ActionListEmpty()
  Global("Prep","LOCALS",0)
  Global("SNAFU","LOCALS",0)
  !HasItem("MELFMET",Myself)  // ~Melf's Minute Meteor~
  !HaveSpell(WIZARD_MELF_METEOR)
THEN
  RESPONSE #100
    DisplayStringHead(Myself,73139)  // ~Contingency - Fired~
    DisplayString(Myself,25942)  // ~Contingency~
    SetGlobal("Prep","LOCALS",1)
    ReallyForceSpell(Myself,WIZARD_PHANTOM_BLADE)
    ReallyForceSpell(Myself,COM_TRUE_STRIKE)
END

IF
  ActionListEmpty()
  SpellCast(Myself,0)
  HaveAnySpells()
  NumCreatureGT([EVILCUTOFF],3)
  !GlobalTimerNotExpired("SBN","LOCALS")
  OR(2)
    Range(SecondNearestEnemyOf(Myself),8)
    Range(NearestEnemyOf(Myself),5)
THEN
  RESPONSE #100
    SetGlobalTimer("SBN","LOCALS",TWO_ROUNDS)
    DisplayStringHead(Myself,64573)  // ~Help! Guards, protect me!~
    Shout(69)
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(COM_AURA_OF_FOCUS)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStat(Myself,0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,COM_AURA_OF_FOCUS)
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,TRUE_SIGHT)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  OR(8)
    !See([GOODCUTOFF])
    !See(LastAttackerOf(Myself))
    StateCheck(NearestEnemyOf(Myself),STATE_MIRRORIMAGE)
    StateCheck(NearestEnemyOf(Myself),STATE_ILLUSIONS)
    StateCheck(NearestEnemyOf(Myself),STATE_BLUR)
    Gender(NearestEnemyOf(Myself),ILLUSIONARY)
    Specifics(NearestEnemyOf(Myself),SIMULACRUM)
    Specifics(NearestEnemyOf(Myself),NEEDS_BREACH)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    DisplayStringHead(Myself,@7)
    Spell(Myself,WIZARD_TRUE_SIGHT)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_MISLEAD)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  CheckStat(Myself,0,WIZARD_MISLEAD)
  !StateCheck(Myself,STATE_INVISIBLE)
  !StateCheck(Myself,STATE_IMPROVEDINVISIBILITY)
  !StateCheck(Myself,STATE_POISONED)
  RandomNumLT(4,4)
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_INVISIBLE)
  !StateCheck(Myself,STATE_IMPROVEDINVISIBILITY)
  !StateCheck(Myself,STATE_POISONED)
  RandomNumLT(5,5)
THEN
  RESPONSE #100
    SetGlobalTimer("BPIP","LOCALS",15)
    Spell(Myself,WIZARD_SHADOW_DOOR)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_SPELL_TRAP)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  CheckStat(Myself,0,WIZARD_SPELL_TRAP)
  OR(5)
    See([GOODCUTOFF.0.0.DRUID_ALL])
    See([GOODCUTOFF.0.0.BARD_ALL])
    See([GOODCUTOFF.0.0.CLERIC_ALL])
    See([GOODCUTOFF.0.0.LONG_BOW])
    See([GOODCUTOFF.0.0.SORCERER])
  CheckStat(Myself,0,WIZARD_SPELL_TURNING)
  CheckStat(Myself,0,WIZARD_SPELL_DEFLECTION)
  RandomNumLT(7,6)
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.DRUID_ALL])
    See([GOODCUTOFF.0.0.BARD_ALL])
    See([GOODCUTOFF.0.0.CLERIC_ALL])
    See([GOODCUTOFF.0.0.LONG_BOW])
    See([GOODCUTOFF.0.0.SORCERER])
  CheckStat(Myself,0,WIZARD_SPELL_TURNING)
  CheckStat(Myself,0,WIZARD_SPELL_TRAP)
  CheckStat(Myself,0,WIZARD_SPELL_DEFLECTION)
  RandomNumLT(8,6)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_SPELL_TURNING)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_IMPROVED_INVISIBILITY)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  !StateCheck(Myself,STATE_INVISIBLE)
  !StateCheck(Myself,STATE_IMPROVEDINVISIBILITY)
  RandomNumLT(6,5)
THEN
  RESPONSE #100
    SetGlobalTimer("BPIP","LOCALS",15)
    Spell(Myself,WIZARD_IMPROVED_INVISIBILITY)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_MINOR_GLOBE_OF_INVULNERABILITY)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  OR(5)
    See([GOODCUTOFF.0.0.DRUID_ALL])
    See([GOODCUTOFF.0.0.BARD_ALL])
    See([GOODCUTOFF.0.0.CLERIC_ALL])
    See([GOODCUTOFF.0.0.LONG_BOW])
    See([GOODCUTOFF.0.0.SORCERER])
  CheckStat(Myself,0,WIZARD_SPELL_TURNING)
  CheckStat(Myself,0,WIZARD_SPELL_TRAP)
  CheckStat(Myself,0,WIZARD_SPELL_DEFLECTION)
  CheckStat(Myself,0,SHIELDGLOBE)
  CheckStat(Myself,0,MINORGLOBE)
  RandomNumLT(9,6)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_MINOR_GLOBE_OF_INVULNERABILITY)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_HASTE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  !StateCheck(Myself,STATE_HASTED)
  CheckStat(Myself,0,IMPROVEDHASTE)
  RandomNumLT(10,7)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_HASTE)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_INVISIBILITY)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  !StateCheck(Myself,STATE_INVISIBLE)
  !StateCheck(Myself,STATE_IMPROVEDINVISIBILITY)
  RandomNumLT(11,7)
THEN
  RESPONSE #100
    SetGlobalTimer("BPIP","LOCALS",15)
    Spell(Myself,WIZARD_INVISIBILITY)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_MIRROR_IMAGE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  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(12,8)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_MIRROR_IMAGE)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_BLUR)
  !GlobalTimerNotExpired("BPT","LOCALS")
  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(13,8)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_BLUR)
END

IF
  See(NearestEnemyOf(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(2)
    Allegiance(LastSeenBy(Myself),ENEMY)
    Allegiance(LastSeenBy(Myself),EVILCUTOFF)
THEN
  RESPONSE #100
END

IF
  ActionListEmpty()
  OR(2)
    Global("SNAFU","LOCALS",1)
    CheckStatGT(Myself,0,WIZARD_TENSERS_TRANSFORMATION)
THEN
  RESPONSE #100
    AttackOneRound(LastSeenBy(Myself))
END

IF
  ActionListEmpty()
  HPPercentGT(Myself,35)
  OR(2)
    HasItem("PHANBLAD",Myself)  // ~Phantom Blade~
    HasItem("MELFMET",Myself)  // ~Melf's Minute Meteor~
THEN
  RESPONSE #75
    AttackOneRound(LastSeenBy(Myself))
  RESPONSE #25
    Continue()
END

IF
  OR(2)
    StateCheck(Myself,STATE_INVISIBLE)
    StateCheck(Myself,STATE_IMPROVEDINVISIBILITY)
  GlobalTimerNotExpired("BPIP","LOCALS")
THEN
  RESPONSE #15
    Continue()
  RESPONSE #60
    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)
THEN
  RESPONSE #80
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_DEATH_SPELL)
  RESPONSE #20
    Continue()
END

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

IF
  ActionListEmpty()
  HaveSpell(WIZARD_VAMPIRIC_TOUCH)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Range(LastSeenBy(Myself),5)
  HPPercentLT(Myself,85)
  RandomNumLT(30,22)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_LARLOCH_MINOR_DRAIN)
END

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

IF
  ActionListEmpty()
  !GlobalTimerNotExpired("BPT","LOCALS")
  !Range(NearestEnemyOf(Myself),10)
  HaveSpell(WIZARD_TIME_STOP)
  RandomNumLT(31,24)
THEN
  RESPONSE #100
    Spell(Myself,WIZARD_TIME_STOP)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_SYMBOL_STUN)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStat(LastSeenBy(Myself),0,WIZARD_SPELL_TURNING)
  !StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
  !Range(LastSeenBy(Myself),5)
  RandomNumLT(32,22)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_SYMBOL_STUN)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_SYMBOL_FEAR)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStat(LastSeenBy(Myself),0,WIZARD_SPELL_TURNING)
  !Range(LastSeenBy(Myself),5)
  !StateCheck(LastSeenBy(Myself),STATE_PANIC)
  RandomNumLT(33,22)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_SYMBOL_FEAR)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_POWER_WORD_STUN)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStat(LastSeenBy(Myself),0,WIZARD_SPELL_TURNING)
  !StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
  OR(6)
    Class(LastSeenBy(Myself),DRUID_ALL)
    Class(LastSeenBy(Myself),BARD_ALL)
    Class(LastSeenBy(Myself),CLERIC_ALL)
    Class(LastSeenBy(Myself),LONG_BOW)
    Class(LastSeenBy(Myself),SORCERER)
    InPartySlot(LastSeenBy(Myself),0)
  RandomNumLT(34,24)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_POWER_WORD_STUN)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_SPHERE_OF_CHAOS)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStat(LastSeenBy(Myself),0,WIZARD_SPELL_TURNING)
  Range(LastSeenBy(Myself),10)
  RandomNumLT(35,23)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_SPHERE_OF_CHAOS)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_ABI_DALZIMS_HORRID_WILTING)
  !GlobalTimerNotExpired("BPT","LOCALS")
  !Range(LastSeenBy(Myself),10)
  CheckStatLT(LastSeenBy(Myself),70,RESISTMAGIC)
  RandomNumLT(36,26)
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(37,24)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_METEOR_SWARM)
END

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

IF
  ActionListEmpty()
  HaveSpell(WIZARD_CHAIN_LIGHTNING)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStat(LastSeenBy(Myself),0,WIZARD_SPELL_TURNING)
  CheckStatLT(LastSeenBy(Myself),60,RESISTELECTRICITY)
  CheckStatLT(LastSeenBy(Myself),60,RESISTMAGIC)
  !Range(LastSeenBy(Myself),10)
  RandomNumLT(39,24)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_CHAIN_LIGHTNING)
END

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

IF
  ActionListEmpty()
  HaveSpell(WIZARD_BREACH)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStat(LastSeenBy(Myself),0,WIZARD_SPELL_TRAP)
  CheckStat(LastSeenBy(Myself),0,WIZARD_SPELL_SHIELD)
  OR(13)
    CheckStatGT(LastSeenBy(Myself),0,WIZARD_RESIST_FEAR)
    CheckStatGT(LastSeenBy(Myself),50,RESISTMAGICFIRE)
    CheckStatGT(LastSeenBy(Myself),50,RESISTMAGICCOLD)
    CheckStatGT(LastSeenBy(Myself),50,RESISTACID)
    CheckStatGT(LastSeenBy(Myself),50,RESISTELECTRICITY)
    CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_MAGIC_ENERGY)
    CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_THE_ELEMENTS)
    CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_ENERGY)
    CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
    CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_NORMAL_WEAPONS)
    CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    CheckStatGT(LastSeenBy(Myself),3,STONESKINS)
    CheckStatGT(LastSeenBy(Myself),0,SCRIPTINGSTATE5)
  RandomNumLT(41,27)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_BREACH)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_RUBY_RAY_OF_REVERSAL)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStat(LastSeenBy(Myself),0,WIZARD_SPELL_SHIELD)
  OR(3)
    CheckStatGT(LastSeenBy(Myself),0,SHIELDGLOBE)
    CheckStatGT(LastSeenBy(Myself),0,WIZARD_SPELL_IMMUNITY)
    CheckStatGT(LastSeenBy(Myself),0,WIZARD_SPELL_TRAP)
  RandomNumLT(42,28)
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")
  !Range(LastSeenBy(Myself),5)
  !StateCheck(LastSeenBy(Myself),STATE_SLEEPING)
  !StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
  RandomNumLT(43,26)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_EMOTION_HOPELESSNESS)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_SUMMON_NISHRUU)
  !GlobalTimerNotExpired("BPT","LOCALS")
  !Range(NearestEnemyOf(Myself),5)
  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(44,28)
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,WIZARD_SPELL_TURNING)
  !Range(LastSeenBy(Myself),5)
  !StateCheck(LastSeenBy(Myself),STATE_CHARMED)
  RandomNumLT(45,28)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_DOMINATION)
END

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

IF
  ActionListEmpty()
  HaveSpell(WIZARD_SUN_FIRE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Range(LastSeenBy(Myself),15)
  !Range([EVILCUTOFF],10)
  CheckStatLT(LastSeenBy(Myself),70,RESISTMAGICFIRE)
  RandomNumLT(47,27)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_SUN_FIRE)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_FLAME_ARROW)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStat(LastSeenBy(Myself),0,WIZARD_SPELL_TURNING)
  CheckStatLT(LastSeenBy(Myself),50,RESISTMAGIC)
  CheckStatLT(LastSeenBy(Myself),50,RESISTMAGICFIRE)
  Range(LastSeenBy(Myself),5)
  RandomNumLT(48,25)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_FLAME_ARROW)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_MELF_METEOR)
  !GlobalTimerNotExpired("BPT","LOCALS")
  !HasItem("PHANBLAD",Myself)  // ~Phantom Blade~
  !HasItem("MELFMET",Myself)  // ~Melf's Minute Meteor~
  RandomNumLT(49,23)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_MELF_METEOR)
    AttackOneRound(LastSeenBy(Myself))
END

IF
  ActionListEmpty()
  HaveSpell(COM_STEAM)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStat(LastSeenBy(Myself),0,WIZARD_SPELL_TURNING)
  CheckStatLT(LastSeenBy(Myself),50,RESISTMAGIC)
  RandomNumLT(50,26)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),COM_STEAM)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_MAGIC_MISSILE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStatLT(LastSeenBy(Myself),50,RESISTMAGIC)
  !CheckStat(LastSeenBy(Myself),2,SCRIPTINGSTATE5)
  CheckStat(LastSeenBy(Myself),0,WIZARD_SPELL_TURNING)
  RandomNumLT(51,26)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_MAGIC_MISSILE)
END

IF
  ActionListEmpty()
  !HasItem("PHANBLAD",Myself)  // ~Phantom Blade~
  CheckStatGT(LastSeenBy(Myself),10,WIZARD_GREATER_MALISON)
  CheckStatLT(Myself,11,WIZARD_GREATER_MALISON)
THEN
  RESPONSE #100
    EquipRanged()
    AttackOneRound(LastSeenBy(Myself))
END

IF
  ActionListEmpty()
  !Range(NearestEnemyOf(Myself),3)
  !HasItem("PHANBLAD",Myself)  // ~Phantom Blade~
  OR(2)
    CheckStatGT(LastSeenBy(Myself),0,CLERIC_BLADE_BARRIER)
    CheckStatGT(LastSeenBy(Myself),0,WIZARD_FIRE_SHIELD)
THEN
  RESPONSE #100
    EquipRanged()
    AttackReevaluate(LastSeenBy(Myself),45)
END

IF
  ActionListEmpty()
  !Range(NearestEnemyOf(Myself),5)
  !HasItem("PHANBLAD",Myself)  // ~Phantom Blade~
  OR(2)
    HasItem("MELFMET",Myself)  // ~Melf's Minute Meteor~
    !HaveAnySpells()
THEN
  RESPONSE #100
    EquipRanged()
    AttackOneRound(LastSeenBy(Myself))
END

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

IF
  ActionListEmpty()
  Range(NearestEnemyOf(Myself),5)
  OR(4)
    HasItem("PHANBLAD",Myself)  // ~Phantom Blade~
    CheckStatLT(Myself,10,THAC0)
    CheckStatLT(Myself,0,ARMORCLASS)
    !HaveAnySpells()
THEN
  RESPONSE #100
    EquipMostDamagingMelee()
    AttackReevaluate(NearestEnemyOf(Myself),45)
END

