IF
  OR(2)
    HPLT(Myself,10)
    Die()
THEN
  RESPONSE #100
    SetGlobal("BPHorredDeadCheck","GLOBAL",1)
    SetGlobal("BPHorredHit","GLOBAL",66)
    ActionOverride("HORRED",StartDialogNoSet(Player1))
END

IF
  Dead("BPSkully")
  Global("BPHorSkul","LOCALS",0)
THEN
  RESPONSE #100
    SetGlobal("BPHorSkul","LOCALS",1)
    ReallyForceSpell(Myself,CLERIC_SANCTUARY)
    RunAwayFrom(NearestEnemyOf(Myself),10)
    StartDialogNoSet([PC])
END

IF
  Global("BPHorredSpoke","LOCALS",0)
  InMyArea(Player1)
  OR(2)
    Detect([GOODCUTOFF])
    Heard([ANYONE],99)
THEN
  RESPONSE #100
    SetGlobal("BPHorredSpeaks","GLOBAL",1)
    SetGlobal("BPHorredSpoke","LOCALS",1)
    StartDialogNoSet(Player1)
END

IF
  Global("BPHorredSpoke","LOCALS",0)
  !InMyArea(Player1)
  See([GOODCUTOFF])
THEN
  RESPONSE #100
    SetGlobal("BPHorredSpeaks","GLOBAL",2)
    SetGlobal("BPHorredSpoke","LOCALS",1)
    StartDialogNoSet([GOODCUTOFF])
END

IF
  Global("BPHorredSpoke","LOCALS",0)
  !InMyArea(Player1)
  !See([GOODCUTOFF])
  OR(3)
    Detect([GOODCUTOFF])
    Heard("BPSKULLY",154)  // ~Skulley~
    Heard([ANYONE],99)
THEN
  RESPONSE #100
    SetGlobal("BPHorredSpeaks","GLOBAL",3)
    SetGlobal("BPHorredSpoke","LOCALS",1)
    StartDialogNoSet([PC])
END

IF
  Global("BPHorredChanged","GLOBAL",1)
THEN
  RESPONSE #100
    SetGlobal("BPHorredChanged","GLOBAL",2)
    EscapeArea()
END

IF
  Allegiance(Myself,NEUTRAL)
  OR(2)
    Global("BPHorredSpoke","LOCALS",1)
    AttackedBy([GOODCUTOFF],DEFAULT)
THEN
  RESPONSE #100
    ChangeEnemyAlly(Myself,ENEMY)
END

IF
  Global("TimeStop","LOCALS",1)
THEN
  RESPONSE #100
    ForceSpell(LastSeenBy(Myself),WIZARD_ABI_DALZIMS_HORRID_WILTING)
    RemoveSpell(WIZARD_ABI_DALZIMS_HORRID_WILTING)
    ForceSpell(LastSeenBy(Myself),WIZARD_SKULL_TRAP)
    RemoveSpell(WIZARD_SKULL_TRAP)
    ForceSpell(LastSeenBy(Myself),WIZARD_MAZE)
    RemoveSpell(WIZARD_MAZE)
    SetGlobal("TimeStop","LOCALS",0)
  RESPONSE #100
    ForceSpell(LastSeenBy(Myself),WIZARD_NPC_SYMBOL_DEATH)
    RemoveSpell(WIZARD_NPC_SYMBOL_DEATH)
    ForceSpell(LastSeenBy(Myself),CLERIC_CREEPING_DOOM)
    RemoveSpell(CLERIC_CREEPING_DOOM)
    ForceSpell(Myself,WIZARD_SPHERE_OF_CHAOS)
    RemoveSpell(WIZARD_SPHERE_OF_CHAOS)
    SetGlobal("TimeStop","LOCALS",0)
  RESPONSE #100
    ForceSpell(LastSeenBy(Myself),CLERIC_DISPEL_MAGIC)
    RemoveSpell(CLERIC_DISPEL_MAGIC)
    ForceSpell(LastSeenBy(Myself),CLERIC_UNHOLY_BLIGHT)
    RemoveSpell(CLERIC_UNHOLY_BLIGHT)
    ForceSpell(LastSeenBy(Myself),WIZARD_CHAOS)
    RemoveSpell(WIZARD_CHAOS)
    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 #20
    DisplayStringHead(Myself,@100)
    SetGlobal("BPCHASER","LOCALS",0)
    AttackReevaluate(LastSeenBy(Myself),15)
  RESPONSE #20
    DisplayStringHead(Myself,@100)
    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,@100)
    SetGlobal("BPCHASER","LOCALS",0)
    SetGlobalTimer("BPT","LOCALS",6)
    ForceSpell(LastSeenBy(Myself),WIZARD_NPC_SYMBOL_STUN)
    RemoveSpell(WIZARD_NPC_SYMBOL_STUN)
  RESPONSE #20
    DisplayStringHead(Myself,@100)
    SetGlobal("BPCHASER","LOCALS",0)
    SetGlobalTimer("BPT","LOCALS",6)
    ForceSpell(LastSeenBy(Myself),CLERIC_DOLOROUS_DECAY)
    RemoveSpell(CLERIC_DOLOROUS_DECAY)
  RESPONSE #10
    DisplayStringHead(Myself,@100)
    SetGlobal("BPCHASER","LOCALS",0)
    SetGlobalTimer("BPT","LOCALS",6)
    ForceSpell(LastSeenBy(Myself),WIZARD_CHAIN_LIGHTNING)
    RemoveSpell(WIZARD_CHAIN_LIGHTNING)
  RESPONSE #5
    DisplayStringHead(Myself,@100)
    SetGlobal("BPCHASER","LOCALS",0)
    SetGlobalTimer("BPT","LOCALS",6)
    ForceSpell(LastSeenBy(Myself),WIZARD_IMPRISONMENT)
    RemoveSpell(WIZARD_IMPRISONMENT)
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,@101)
    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 #25
    SetGlobalTimer("BPT","LOCALS",3)
    ForceSpell(LastSeenBy(Myself),WIZARD_ABI_DALZIMS_HORRID_WILTING)
    RemoveSpell(WIZARD_ABI_DALZIMS_HORRID_WILTING)
  RESPONSE #20
    SetGlobalTimer("BPT","LOCALS",3)
    ForceSpell(LastSeenBy(Myself),WIZARD_NPC_SYMBOL_STUN)
    RemoveSpell(WIZARD_NPC_SYMBOL_STUN)
  RESPONSE #20
    SetGlobalTimer("BPT","LOCALS",3)
    ForceSpell(LastSeenBy(Myself),CLERIC_DOLOROUS_DECAY)
    RemoveSpell(CLERIC_DOLOROUS_DECAY)
  RESPONSE #20
    SetGlobalTimer("BPT","LOCALS",3)
    ForceSpell(LastSeenBy(Myself),WIZARD_CHAIN_LIGHTNING)
    RemoveSpell(WIZARD_CHAIN_LIGHTNING)
  RESPONSE #15
    SetGlobalTimer("BPT","LOCALS",3)
    ForceSpell(LastSeenBy(Myself),WIZARD_SKULL_TRAP)
    RemoveSpell(WIZARD_SKULL_TRAP)
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])
  OR(2)
    General(Myself,HUMANOID)
    General(Myself,GIANTHUMANOID)
  CheckStatGT(Myself,5,INT)
THEN
  RESPONSE #10
    DisplayStringHead(Myself,@102)
    SetGlobalTimer("BPCHASE","LOCALS",12)
    SetGlobal("BPCHASER","LOCALS",1)
    MoveToObject(LastHitter(Myself))
  RESPONSE #10
    DisplayStringHead(Myself,@102)
    SetGlobalTimer("BPCHASE","LOCALS",12)
    SetGlobal("BPCHASER","LOCALS",1)
    ReallyForceSpell(Myself,WIZARD_IMPROVED_MANTLE)
    ReallyForceSpell(Myself,WIZARD_SPELL_DEFLECTION)
    ReallyForceSpell(Myself,WIZARD_HASTE)
    MoveToObject(LastHitter(Myself))
  RESPONSE #10
    DisplayStringHead(Myself,@102)
    SetGlobalTimer("BPCHASE","LOCALS",12)
    SetGlobal("BPCHASER","LOCALS",1)
    ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_ENERGY)
    ReallyForceSpell(Myself,WIZARD_SPELL_SHIELD)
    ReallyForceSpell(Myself,WIZARD_STONE_SKIN)
    MoveToObject(LastHitter(Myself))
  RESPONSE #10
    DisplayStringHead(Myself,@102)
    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)
    MoveToObject(LastHitter(Myself))
  RESPONSE #10
    DisplayStringHead(Myself,@102)
    SetGlobalTimer("BPCHASE","LOCALS",12)
    SetGlobal("BPCHASER","LOCALS",1)
    ReallyForceSpell(Myself,WIZARD_MANTLE)
    ReallyForceSpell(Myself,WIZARD_SPELL_DEFLECTION)
    ReallyForceSpell(Myself,WIZARD_ENERGY_BLADES)
    MoveToObject(LastHitter(Myself))
  RESPONSE #10
    DisplayStringHead(Myself,@102)
    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)
    RunAwayFrom(LastHitter(Myself),45)
  RESPONSE #30
    DisplayStringHead(Myself,@103)
    SetGlobalTimer("BPCHASE","LOCALS",60)
    SetGlobal("BPCHASER","LOCALS",1)
    SetGlobal("BP_BOMB","LOCALS",1)
  RESPONSE #10
    DisplayStringHead(Myself,@102)
    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,@104)
    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,@104)
    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,@104)
    MoveToObject(TenthNearest)
END

IF
  CheckStatGT(Myself,10,WIZARD_GREATER_MALISON)
  CheckStatGT(Myself,5,INT)
  !GlobalTimerNotExpired("BPCHASE","LOCALS")
  See([ANYONE])
  CheckStatGT(LastSeenBy(Myself),10,WIZARD_GREATER_MALISON)
THEN
  RESPONSE #100
    SetGlobalTimer("BPCHASE","LOCALS",ONE_ROUND)
    DisplayStringHead(Myself,@104)
    RunAwayFrom(LastSeenBy(Myself),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,@104)
    MoveToObject(Player1)
END

IF
  OpenState("DOOR01",FALSE)  // DOOR01
  !Detect([GOODCUTOFF])
THEN
  RESPONSE #100
END

IF
  Range(NearestEnemyOf(Myself),2)
  OR(2)
    CheckStatGT(NearestEnemyOf(Myself),0,CLERIC_BLADE_BARRIER)
    CheckStatGT(NearestEnemyOf(Myself),0,WIZARD_FIRE_SHIELD)
THEN
  RESPONSE #80
    RunAwayFrom(NearestEnemyOf(Myself),4)
  RESPONSE #20
    Continue()
END

IF
  HPPercentLT(Myself,30)
  GlobalLT("BPHorCheat","LOCALS",3)
THEN
  RESPONSE #100
    ForceSpell(Myself,CLERIC_HEAL)
    IncrementGlobal("BPHorCheat","LOCALS",1)
END

IF
  ActionListEmpty()
  HPPercentLT(Myself,50)
  NumCreatureLT([EVILCUTOFF.0.0.0.SIMULACRUM],2)
  !GlobalTimerNotExpired("BPClones","LOCALS")
  GlobalLT("BPHorClone","LOCALS",3)
  See(NearestEnemyOf(Myself))
THEN
  RESPONSE #100
    DisplayStringHead(Myself,@105)
    Wait(1)
    SetGlobalTimer("BPClones","LOCALS",90)
    IncrementGlobal("BPHorClone","LOCALS",1)
    ForceSpell(Myself,HORREDS_EVIL_CLONES)
END

IF
  ActionListEmpty()
  HPPercentLT(Myself,60)
  See(NearestEnemyOf(Myself))
  Range(NearestEnemyOf(Myself),15)
  CheckStat(Myself,0,SANCTUARY)
  GlobalLT("BPHorCopOut","LOCALS",5)
THEN
  RESPONSE #100
    ForceSpell(Myself,CLERIC_SANCTUARY)
    IncrementGlobal("BPHorCopOut","LOCALS",1)
    RunAwayFrom(NearestEnemyOf(Myself),30)
END

IF
  HPPercentLT(Myself,70)
  HasItem("POTN52",Myself)  // ~Potion of Extra Healing~
THEN
  RESPONSE #100
    UseItem("POTN52",Myself)  // ~Potion of Extra Healing~
END

IF
  OR(3)
    AttackedBy([GOODCUTOFF],DEFAULT)
    See(NearestEnemyOf(Myself))
    Detect(NearestEnemyOf(Myself))
  Global("BPHorTrig1","LOCALS",0)
THEN
  RESPONSE #100
    SetGlobal("BPHorTrig1","LOCALS",1)
    ReallyForceSpell(Myself,WIZARD_STONE_SKIN)
    ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
    DisplayStringHead(Myself,39968)  // ~Spell Trigger - Fired~
    SetGlobalTimer("BPHorTrig","LOCALS",FOUR_ROUNDS)
END

IF
  ActionListEmpty()
  !GlobalTimerNotExpired("BPHorTrig","LOCALS")
  HaveSpell(WIZARD_MANTLE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPHorTrig","LOCALS",FOUR_ROUNDS)
    Spell(Myself,WIZARD_MANTLE)
    ForceSpell(Myself,WIZARD_STONE_SKIN)
END

IF
  ActionListEmpty()
  See(NearestEnemyOf(Myself))
  HaveSpell(CLERIC_ARMOR_OF_FAITH)
  !GlobalTimerNotExpired("BPHorTrig","LOCALS")
  GlobalLT("BPHorredBackup","LOCALS",2)
THEN
  RESPONSE #100
    ReallyForceSpell(Myself,CLERIC_ARMOR_OF_FAITH)
    ReallyForceSpell(Myself,CLERIC_CLOAK_OF_FEAR)
    ReallyForceSpell(Myself,WIZARD_IMPROVED_HASTE)
    IncrementGlobal("BPHorredBackup","LOCALS",1)
    SetGlobalTimer("BPHorTrig","LOCALS",ONE_TURN)
END

IF
  OR(2)
    See(NearestEnemyOf(Myself))
    TookDamage()
  CheckStatLT(Myself,2,STONESKINS)
  HaveSpell(WIZARD_STONE_SKIN)
THEN
  RESPONSE #100
    Spell(Myself,WIZARD_STONE_SKIN)
END

IF
  !See(NearestEnemyOf(Myself))
  Detect(NearestEnemyOf(Myself))
  CheckStat(Myself,0,TRUE_SIGHT)
  GlobalLT("BPHorSeesAll","LOCALS",2)
THEN
  RESPONSE #100
    ForceSpell(Myself,CLERIC_TRUE_SIGHT)
    IncrementGlobal("BPHorSeesAll","LOCALS",1)
END

IF
  StateCheck(Myself,STATE_SILENCED)
  GlobalLT("BPHorTalk","LOCALS",2)
THEN
  RESPONSE #100
    ReallyForceSpell(Myself,WIZARD_VOCALIZE)
    IncrementGlobal("BPHorTalk","LOCALS",1)
END

IF
  StateCheck(Myself,STATE_POISONED)
THEN
  RESPONSE #100
    ReallyForceSpell(Myself,CLERIC_NEUTRALIZE_POISON)
END

IF
  ActionListEmpty()
  Dead("BPSkully")  // ~Skulley~
  HaveSpell(WIZARD_SPHERE_OF_CHAOS)
  See(SixthNearestEnemyOf(Myself))
  !Range(LastSeenBy(Myself),15)
  NotStateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  NotStateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  NotStateCheck(LastSeenBy(Myself),STATE_CONFUSED)
THEN
  RESPONSE #80
    Spell(LastSeenBy(Myself),WIZARD_SPHERE_OF_CHAOS)
  RESPONSE #20
    Continue()
END

IF
  ActionListEmpty()
  Dead("BPSkully")  // ~Skulley~
  HaveSpell(WIZARD_SKULL_TRAP)
  See(SixthNearestEnemyOf(Myself))
  !Range(LastSeenBy(Myself),15)
  NotStateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  NotStateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
THEN
  RESPONSE #80
    Spell(LastSeenBy(Myself),WIZARD_SKULL_TRAP)
  RESPONSE #20
    Continue()
END

IF
  ActionListEmpty()
  Dead("BPSkully")  // ~Skulley~
  GlobalLT("BPHorPest","LOCALS",2)
  !GlobalTimerNotExpired("BPHorCloud","LOCALS")
  See(TenthNearestEnemyOf(Myself))
  !Range(LastSeenBy(Myself),18)
  NotStateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  NotStateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
THEN
  RESPONSE #100
    ForceSpell(LastSeenBy(Myself),COM_PRIEST_CLOUD_OF_PESTILENCE)
    IncrementGlobal("BPHorPest","LOCALS",1)
    SetGlobalTimer("BPHorCloud","LOCALS",ONE_TURN)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_TIME_STOP)
  Global("TimeStop","LOCALS",0)
  RandomNum(2,1)
THEN
  RESPONSE #80
    SetGlobal("TimeStop","LOCALS",1)
    ReallyForceSpell(Myself,WIZARD_IMPROVED_ALUCRITY)
    Spell(Myself,WIZARD_TIME_STOP)
    Continue()
  RESPONSE #20
    Continue()
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_IMPRISONMENT)
  OR(4)
    See(NearestEnemyOf(Myself))
    See(SecondNearestEnemyOf(Myself))
    See(LastAttackerOf(Myself))
    See(LastHitter(Myself))
  NotStateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  NotStateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  RandomNum(3,1)
THEN
  RESPONSE #100
    Spell(LastSeenBy(Myself),WIZARD_IMPRISONMENT)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_FEEBLEMIND)
  OR(5)
    See([PC.0.0.DRUID_ALL])
    See([PC.0.0.BARD_ALL])
    See([PC.0.0.CLERIC_ALL])
    See([PC.0.0.LONG_BOW])
    See([PC.0.0.SORCERER])
  NotStateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  NotStateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  NotStateCheck(LastSeenBy(Myself),STATE_FEEBLEMINDED)
  RandomNumLT(4,3)
THEN
  RESPONSE #100
    Spell(LastSeenBy(Myself),WIZARD_FEEBLEMIND)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_ABI_DALZIMS_HORRID_WILTING)
  See(SixthNearestEnemyOf(Myself))
  NotStateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  NotStateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  RandomNumLT(6,4)
THEN
  RESPONSE #100
    Spell(LastSeenBy(Myself),WIZARD_ABI_DALZIMS_HORRID_WILTING)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_CLOUDKILL)
  See(SixthNearestEnemyOf(Myself))
  !Range(LastSeenBy(Myself),15)
  NotStateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  NotStateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  RandomNumLT(8,5)
THEN
  RESPONSE #100
    Spell(LastSeenBy(Myself),WIZARD_CLOUDKILL)
END

IF
  ActionListEmpty()
  !GlobalTimerNotExpired("BPHorPot","LOCALS")
  See([GOODCUTOFF.0.0.0.0.0.MASK_GOOD])
  HaveSpell(CLERIC_UNHOLY_WORD)
  RandomNumLT(10,6)
THEN
  RESPONSE #100
    Spell(LastSeenBy(Myself),CLERIC_UNHOLY_WORD)
    SetGlobalTimer("BPHorPot","LOCALS",ONE_TURN)
END

IF
  ActionListEmpty()
  See(NearestEnemyOf(Myself))
  NumCreatureVsPartyLT([EVILCUTOFF.0.0.0.0.SUMMONED],7)
  Global("BPHorFiend","LOCALS",0)
  RandomNumLT(12,7)
THEN
  RESPONSE #100
    ForceSpell(Myself,0)
    ForceSpell(NearestEnemyOf(Myself),WIZARD_SUMMON_FIEND)
    SetGlobal("BPHorFiend","LOCALS",1)
    SetGlobalTimer("BPHorSumm","LOCALS",15)
    RunAwayFrom(NearestEnemyOf(Myself),30)
END

IF
  ActionListEmpty()
  See(NearestEnemyOf(Myself))
  NumCreatureVsPartyLT([EVILCUTOFF.0.0.0.0.SUMMONED],7)
  GlobalLT("BPHorAnDead","LOCALS",4)
  !GlobalTimerNotExpired("BPHorSumm","LOCALS")
  RandomNumLT(16,9)
THEN
  RESPONSE #100
    IncrementGlobal("BPHorAnDead","LOCALS",1)
    ForceSpell(NearestEnemyOf(Myself),CLERIC_ANIMATE_DEAD)
    SetGlobalTimer("BPHorredSummons","LOCALS",15)
    RunAwayFrom(NearestEnemyOf(Myself),30)
END

IF
  ActionListEmpty()
  See(NearestEnemyOf(Myself))
  NumCreatureVsPartyLT([EVILCUTOFF.0.0.0.0.SUMMONED],7)
  GlobalLT("BPHorSpidSp","LOCALS",2)
  !GlobalTimerNotExpired("BPHorSumm","LOCALS")
  RandomNumLT(18,10)
THEN
  RESPONSE #100
    IncrementGlobal("BPHorSpidSp","LOCALS",1)
    ForceSpell(NearestEnemyOf(Myself),WIZARD_SPIDER_SPAWN)
    SetGlobalTimer("BPHorSumm","LOCALS",15)
    RunAwayFrom(NearestEnemyOf(Myself),30)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_HOLD_PERSON)
  OR(10)
    See([PC.0.0.THIEF_ALL])
    See([PC.0.0.FIGHTER_ALL])
    See([PC.0.0.RANGER_ALL])
    See([PC.0.0.PALADIN_ALL])
    See([PC.0.0.MONK])
    See([PC.0.0.DRUID_ALL])
    See([PC.0.0.BARD_ALL])
    See([PC.0.0.CLERIC_ALL])
    See([PC.0.0.LONG_BOW])
    See([PC.0.0.SORCERER])
  NotStateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  NotStateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  NotStateCheck(LastSeenBy(Myself),STATE_HELPLESS)
  RandomNum(3,1)
THEN
  RESPONSE #100
    Spell(LastSeenBy(Myself),CLERIC_HOLD_PERSON)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_SILENCE_15_FOOT)
  OR(7)
    See([PC.0.0.RANGER_ALL])
    See([PC.0.0.PALADIN_ALL])
    See([PC.0.0.DRUID_ALL])
    See([PC.0.0.BARD_ALL])
    See([PC.0.0.CLERIC_ALL])
    See([PC.0.0.LONG_BOW])
    See([PC.0.0.SORCERER])
  !Range(LastSeenBy(Myself),15)
  NotStateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  NotStateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  NotStateCheck(LastSeenBy(Myself),STATE_SILENCED)
  RandomNumLT(9,4)
THEN
  RESPONSE #100
    Spell(LastSeenBy(Myself),CLERIC_SILENCE_15_FOOT)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_DEATH_SPELL)
  See(SixthNearestEnemyOfType)
  !Range(LastSeenBy(Myself),15)
  NotStateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  NotStateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
THEN
  RESPONSE #100
    Spell(LastSeenBy(Myself),WIZARD_DEATH_SPELL)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_CREEPING_DOOM)
  See(ThirdNearestEnemyOf(Myself))
  CheckStat(LastSeenBy(Myself),0,CLERIC_INSECT_PLAGUE)
  CheckStat(LastSeenBy(Myself),0,WIZARD_SPELL_TURNING)
  NotStateCheck(ThirdNearestEnemyOf(Myself),STATE_INVISIBLE)
  NotStateCheck(ThirdNearestEnemyOf(Myself),STATE_IMPROVEDINVISIBILITY)
  RandomNumLT(22,12)
THEN
  RESPONSE #100
    Spell(ThirdNearestEnemyOf(Myself),CLERIC_CREEPING_DOOM)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_INSECT_PLAGUE)
  See(ThirdNearestEnemyOf(Myself))
  CheckStat(LastSeenBy(Myself),0,CLERIC_INSECT_PLAGUE)
  CheckStat(LastSeenBy(Myself),0,WIZARD_SPELL_TURNING)
  NotStateCheck(ThirdNearestEnemyOf(Myself),STATE_INVISIBLE)
  NotStateCheck(ThirdNearestEnemyOf(Myself),STATE_IMPROVEDINVISIBILITY)
  RandomNumLT(24,13)
THEN
  RESPONSE #100
    Spell(ThirdNearestEnemyOf(Myself),CLERIC_INSECT_PLAGUE)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_CHAIN_LIGHTNING)
  See(ThirdNearestEnemyOf(Myself))
  NotStateCheck(ThirdNearestEnemyOf(Myself),STATE_INVISIBLE)
  NotStateCheck(ThirdNearestEnemyOf(Myself),STATE_IMPROVEDINVISIBILITY)
  RandomNumLT(5,3)
THEN
  RESPONSE #100
    Spell(ThirdNearestEnemyOf(Myself),WIZARD_CHAIN_LIGHTNING)
END

IF
  ActionListEmpty()
  See(FourthNearestEnemyOf(Myself))
  HaveSpell(CLERIC_UNHOLY_BLIGHT)
  See(FourthNearestEnemyOf(Myself))
  Alignment(LastSeenBy(Myself),MASK_GOOD)
  NotStateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  NotStateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  RandomNumLT(7,4)
THEN
  RESPONSE #100
    Spell(LastSeenBy(Myself),CLERIC_UNHOLY_BLIGHT)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_GREATER_COMMAND)
  See(SixthNearestEnemyOf(Myself))
  !Range(LastSeenBy(Myself),30)
  NotStateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  NotStateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  NotStateCheck(LastSeenBy(Myself),STATE_HELPLESS)
  NotStateCheck(LastSeenBy(Myself),STATE_SLEEPING)
  NotStateCheck(LastSeenBy(Myself),STATE_STUNNED)
  RandomNumLT(11,6)
THEN
  RESPONSE #100
    Spell(LastSeenBy(Myself),CLERIC_GREATER_COMMAND)
END

IF
  ActionListEmpty()
  See(LastAttackerOf(Myself))
  HaveSpell(ENEMY_CLERIC_HARM)
  HPGT(LastAttackerOf(Myself),80)
  Range(LastAttackerOf(Myself),10)
  RandomNumLT(13,7)
THEN
  RESPONSE #100
    Spell(LastAttackerOf(Myself),ENEMY_CLERIC_HARM)
    AttackOneRound(LastAttackerOf(Myself))
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_FLESH_TO_STONE)
  See(LastAttackerOf(Myself))
  NotStateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  NotStateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  CheckStat(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_PETRIFICATION)
  RandomNumLT(15,6)
THEN
  RESPONSE #100
    Spell(LastSeenBy(Myself),WIZARD_FLESH_TO_STONE)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_DISINTEGRATE)
  See(LastAttackerOf(Myself))
  NotStateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  NotStateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  RandomNumLT(17,7)
THEN
  RESPONSE #100
    Spell(LastSeenBy(Myself),WIZARD_DISINTEGRATE)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_DOLOROUS_DECAY)
  See(LastAttackerOf(Myself))
  NotStateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  NotStateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  RandomNumLT(19,9)
THEN
  RESPONSE #100
    Spell(LastSeenBy(Myself),CLERIC_DOLOROUS_DECAY)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_POISON)
  See(LastAttackerOf(Myself))
  Range(LastSeenBy(Myself),10)
  NotStateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  NotStateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  RandomNumLT(21,8)
THEN
  RESPONSE #100
    Spell(LastSeenBy(Myself),CLERIC_POISON)
END

IF
  ActionListEmpty()
  See(LastAttackerOf(Myself))
  Range(LastAttackerOf(Myself),10)
  HaveSpell(CLERIC_CAUSE_CRITICAL_WOUNDS)
  HPLT(LastAttackerOf(Myself),50)
  RandomNumLT(23,8)
THEN
  RESPONSE #100
    Spell(Myself,CLERIC_CAUSE_CRITICAL_WOUNDS)
    AttackReevaluate(LastAttackerOf(Myself),180)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_VAMPIRIC_TOUCH)
  HPPercentLT(Myself,70)
  See(NearestEnemyOf(Myself))
  Range(LastSeenBy(Myself),10)
  RandomNumLT(25,13)
THEN
  RESPONSE #100
    Spell(LastSeenBy(Myself),WIZARD_VAMPIRIC_TOUCH)
END

IF
  OR(8)
    See([PC.0.0.THIEF_ALL])
    See([PC.0.0.DRUID_ALL])
    See([PC.0.0.BARD_ALL])
    See([PC.0.0.CLERIC_ALL])
    See([PC.0.0.LONG_BOW])
    See([PC.0.0.FIGHTER_ALL])
    See([PC.0.0.RANGER_ALL])
    See([PC.0.0.PALADIN_ALL])
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  ActionListEmpty()
  RandomNumLT(26,14)
  HaveSpell(WIZARD_DOMINATION)
  NotStateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  NotStateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  NotStateCheck(LastSeenBy(Myself),STATE_HELPLESS)
  NotStateCheck(LastSeenBy(Myself),STATE_FEEBLEMINDED)
  NotStateCheck(LastSeenBy(Myself),STATE_SLEEPING)
  NotStateCheck(LastSeenBy(Myself),STATE_STUNNED)
  NotStateCheck(LastSeenBy(Myself),STATE_CONFUSED)
THEN
  RESPONSE #100
    Spell(LastSeenBy(Myself),WIZARD_DOMINATION)
END

IF
  ActionListEmpty()
  RandomNumLT(27,14)
  HaveSpell(WIZARD_DIRE_CHARM)
  NotStateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  NotStateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  NotStateCheck(LastSeenBy(Myself),STATE_HELPLESS)
  NotStateCheck(LastSeenBy(Myself),STATE_FEEBLEMINDED)
  NotStateCheck(LastSeenBy(Myself),STATE_SLEEPING)
  NotStateCheck(LastSeenBy(Myself),STATE_STUNNED)
  NotStateCheck(LastSeenBy(Myself),STATE_CONFUSED)
THEN
  RESPONSE #100
    Spell(LastSeenBy(Myself),WIZARD_DIRE_CHARM)
END

IF
  ActionListEmpty()
  RandomNumLT(31,16)
  HaveSpell(WIZARD_RAY_OF_ENFEEBLEMENT)
  NotStateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  NotStateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
THEN
  RESPONSE #100
    Spell(LastSeenBy(Myself),WIZARD_RAY_OF_ENFEEBLEMENT)
END

IF
  ActionListEmpty()
  RandomNumLT(28,13)
  HaveSpell(WIZARD_BLINDNESS)
  NotStateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  NotStateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  NotStateCheck(LastSeenBy(Myself),STATE_HELPLESS)
  NotStateCheck(LastSeenBy(Myself),STATE_SLEEPING)
  NotStateCheck(LastSeenBy(Myself),STATE_CONFUSED)
  NotStateCheck(LastSeenBy(Myself),STATE_STUNNED)
  NotStateCheck(LastSeenBy(Myself),STATE_BLIND)
THEN
  RESPONSE #100
    Spell(LastSeenBy(Myself),WIZARD_BLINDNESS)
END

IF
  ActionListEmpty()
  RandomNumLT(29,12)
  HaveSpell(CLERIC_DOOM)
  NotStateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  NotStateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  NotStateCheck(LastSeenBy(Myself),STATE_PANIC)
  NotStateCheck(LastSeenBy(Myself),STATE_HELPLESS)
  NotStateCheck(LastSeenBy(Myself),STATE_SLEEPING)
  NotStateCheck(LastSeenBy(Myself),STATE_STUNNED)
  NotStateCheck(LastSeenBy(Myself),STATE_CONFUSED)
THEN
  RESPONSE #100
    Spell(LastSeenBy(Myself),CLERIC_DOOM)
END

IF
  ActionListEmpty()
  RandomNumLT(30,12)
  HaveSpell(CLERIC_COMMAND)
  NotStateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  NotStateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  NotStateCheck(LastSeenBy(Myself),STATE_PANIC)
  NotStateCheck(LastSeenBy(Myself),STATE_HELPLESS)
  NotStateCheck(LastSeenBy(Myself),STATE_SLEEPING)
  NotStateCheck(LastSeenBy(Myself),STATE_STUNNED)
  NotStateCheck(LastSeenBy(Myself),STATE_CONFUSED)
THEN
  RESPONSE #100
    Spell(LastSeenBy(Myself),CLERIC_COMMAND)
END

IF
  OR(8)
    See([PC.0.0.THIEF_ALL])
    See([PC.0.0.FIGHTER_ALL])
    See([PC.0.0.RANGER_ALL])
    See([PC.0.0.PALADIN_ALL])
    See([PC.0.0.DRUID_ALL])
    See([PC.0.0.BARD_ALL])
    See([PC.0.0.CLERIC_ALL])
    See([PC.0.0.LONG_BOW])
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  ActionListEmpty()
  RandomNum(32,17)
  HaveSpell(WIZARD_CONTAGION)
  !StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  !StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  !StateCheck(LastSeenBy(Myself),STATE_DISEASED)
  !StateCheck(LastSeenBy(Myself),STATE_POISONED)
THEN
  RESPONSE #100
    Spell(LastSeenBy(Myself),WIZARD_CONTAGION)
END

IF
  ActionListEmpty()
  RandomNum(33,17)
  GlobalLT("BPHorredPlague","LOCALS",4)
  !StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  !StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  !StateCheck(LastSeenBy(Myself),STATE_DISEASED)
  !StateCheck(LastSeenBy(Myself),STATE_POISONED)
THEN
  RESPONSE #100
    ForceSpell(LastSeenBy(Myself),COM_PRIEST_CAUSE_DISEASE)
    IncrementGlobal("BPHorredPlague","LOCALS",1)
END

IF
  ActionListEmpty()
  RandomNum(34,18)
  HaveSpell(CLERIC_SUMMON_INSECTS)
  !StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  !StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  CheckStat(LastSeenBy(Myself),0,CLERIC_INSECT_PLAGUE)
THEN
  RESPONSE #100
    Spell(LastSeenBy(Myself),CLERIC_SUMMON_INSECTS)
END

IF
  ActionListEmpty()
  RandomNum(35,18)
  HaveSpell(WIZARD_MAGIC_MISSILE)
  !StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  !StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
THEN
  RESPONSE #100
    Spell(LastSeenBy(Myself),WIZARD_MAGIC_MISSILE)
END

IF
  ActionListEmpty()
  CheckStatGT(LastSeenBy(Myself),10,WIZARD_GREATER_MALISON)
  CheckStatLT(Myself,11,WIZARD_GREATER_MALISON)
THEN
  RESPONSE #100
    EquipRanged()
    AttackOneRound(LastSeenBy(Myself))
END

IF
  ActionListEmpty()
  OR(3)
    !Range(NearestEnemyOf(Myself),3)
    CheckStatGT(LastSeenBy(Myself),0,CLERIC_BLADE_BARRIER)
    CheckStatGT(LastSeenBy(Myself),0,WIZARD_FIRE_SHIELD)
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()
THEN
  RESPONSE #50
    EquipMostDamagingMelee()
    MoveToObject(LastSeenBy(Myself))
    AttackOneRound(LastSeenBy(Myself))
  RESPONSE #50
    EquipMostDamagingMelee()
    AttackOneRound(NearestEnemyOf(Myself))
END

