IF
  Die()
THEN
  RESPONSE #100
    CreateVisualEffectObject("SPUNHOLY",Myself)
END

IF
  !Allegiance(Myself,ENEMY)
  AttackedBy([GOODCUTOFF],DEFAULT)
THEN
  RESPONSE #100
    ChangeEnemyAlly(Myself,ENEMY)
END

IF
  HPPercentLT(Myself,60)
  HasItem("POTN52",Myself)  // ~Potion of Extra Healing~
THEN
  RESPONSE #100
    UseItem("POTN52",Myself)  // ~Potion of Extra Healing~
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
  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()
  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()
  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_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)
  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
  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])
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_HOLD_PERSON)
  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)
  !Range(LastSeenBy(Myself),20)
  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(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()
  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()
  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),1,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()
  !Range(NearestEnemyOf(Myself),5)
  !OutOfAmmo()
THEN
  RESPONSE #100
    EquipRanged()
    AttackOneRound(LastSeenBy(Myself))
END

IF
  ActionListEmpty()
THEN
  RESPONSE #50
    EquipMostDamagingMelee()
    MoveToObject(LastSeenBy(Myself))
    AttackOneRound(LastSeenBy(Myself))
  RESPONSE #50
    EquipMostDamagingMelee()
    AttackOneRound(NearestEnemyOf(Myself))
END

