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

IF
  Global("BPCHARM","LOCALS",1)
  !StateCheck(Myself,STATE_CHARMED)
THEN
  RESPONSE #100
    SetGlobal("BPCHARM","LOCALS",0)
    ClearActions(Myself)
    Continue()
END

IF
  Allegiance(LastSummonerOf(Myself),EVILCUTOFF)
THEN
  RESPONSE #100
    ChangeAIScript("BADDEVA",OVERRIDE)
END

IF
  HPPercentLT(Myself,25)
  Global("DevaHeal","LOCALS",0)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    ForceSpell(Myself,CLERIC_HEAL)
    SetGlobal("DevaHeal","LOCALS",1)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_NEUTRALIZE_POISON)
  !GlobalTimerNotExpired("BPT","LOCALS")
  See([PC])
  StateCheck(LastSeenBy(Myself),STATE_POISONED)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),CLERIC_NEUTRALIZE_POISON)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_REMOVE_FEAR)
  !GlobalTimerNotExpired("BPT","LOCALS")
  See([PC])
  StateCheck(LastSeenBy(Myself),STATE_PANIC)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),CLERIC_REMOVE_FEAR)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_CURE_DISEASE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  See([PC])
  StateCheck(LastSeenBy(Myself),STATE_DISEASED)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),CLERIC_CURE_DISEASE)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_CURE_CRITICAL_WOUNDS)
  !GlobalTimerNotExpired("BPT","LOCALS")
  See(MostDamagedOf)
  HPPercentLT(MostDamagedOf,25)
  !StateCheck(MostDamagedOf,STATE_INVISIBLE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(MostDamagedOf,CLERIC_CURE_CRITICAL_WOUNDS)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_GLOBE_OF_BLADES)
  CheckStat(Myself,0,121)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(80,41)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,CLERIC_GLOBE_OF_BLADES)
    DisplayStringHead(Myself,63801)  // ~Globe of Blades~
END

IF
  HaveSpell(CLERIC_LESSER_RESTORATION)
  See([PC])
  CheckStat(LastSeenBy(Myself),1,134)
THEN
  RESPONSE #100
    Spell(LastSeenBy(Myself),CLERIC_LESSER_RESTORATION)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_CHAOS)
  !GlobalTimerNotExpired("BPT","LOCALS")
  See(NearestEnemyOf(Myself))
  !HasBounceEffects(LastSeenBy(Myself))
  !StateCheck(LastSeenBy(Myself),STATE_CONFUSED)
  !Range(LastSeenBy(Myself),10)
  RandomNumLT(32,17)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_CHAOS)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_DISPEL_MAGIC)
  !GlobalTimerNotExpired("BPT","LOCALS")
  OR(9)
    StateCheck(LastSummonerOf(Myself),STATE_CHARMED)
    StateCheck(LastSummonerOf(Myself),STATE_CONFUSED)
    StateCheck(LastSummonerOf(Myself),STATE_SILENCED)
    StateCheck(LastSummonerOf(Myself),STATE_HELPLESS)
    StateCheck(LastSummonerOf(Myself),STATE_BLIND)
    StateCheck(LastSummonerOf(Myself),STATE_STUNNED)
    StateCheck(LastSummonerOf(Myself),STATE_SLOWED)
    StateCheck(LastSummonerOf(Myself),STATE_SLEEPING)
    StateCheck(LastSummonerOf(Myself),STATE_FEEBLEMINDED)
  OR(2)
    !HasImmunityEffects(Myself)
    !Range(LastSummonerOf(Myself),15)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSummonerOf(Myself),CLERIC_DISPEL_MAGIC)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_DISPEL_MAGIC)
  !GlobalTimerNotExpired("BPT","LOCALS")
  OR(2)
    StateCheck(Myself,STATE_BLIND)
    StateCheck(Myself,STATE_SLOWED)
  OR(2)
    !HasImmunityEffects(LastSummonerOf(Myself))
    !Range(LastSummonerOf(Myself),15)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,CLERIC_DISPEL_MAGIC)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_DISPEL_MAGIC)
  !GlobalTimerNotExpired("BPT","LOCALS")
  OR(9)
    StateCheck([GOODCUTOFF],STATE_CHARMED)
    StateCheck([GOODCUTOFF],STATE_CONFUSED)
    StateCheck([GOODCUTOFF],STATE_SILENCED)
    StateCheck([GOODCUTOFF],STATE_HELPLESS)
    StateCheck([GOODCUTOFF],STATE_BLIND)
    StateCheck([GOODCUTOFF],STATE_STUNNED)
    StateCheck([GOODCUTOFF],STATE_SLOWED)
    StateCheck([GOODCUTOFF],STATE_SLEEPING)
    StateCheck([GOODCUTOFF],STATE_FEEBLEMINDED)
  OR(2)
    !HasImmunityEffects(Myself)
    !Range([GOODCUTOFF],15)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell([GOODCUTOFF],CLERIC_DISPEL_MAGIC)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_DISPEL_MAGIC)
  !GlobalTimerNotExpired("BPT","LOCALS")
  OR(9)
    StateCheck(SecondNearest([GOODCUTOFF]),STATE_CHARMED)
    StateCheck(SecondNearest([GOODCUTOFF]),STATE_CONFUSED)
    StateCheck(SecondNearest([GOODCUTOFF]),STATE_SILENCED)
    StateCheck(SecondNearest([GOODCUTOFF]),STATE_HELPLESS)
    StateCheck(SecondNearest([GOODCUTOFF]),STATE_BLIND)
    StateCheck(SecondNearest([GOODCUTOFF]),STATE_STUNNED)
    StateCheck(SecondNearest([GOODCUTOFF]),STATE_SLOWED)
    StateCheck(SecondNearest([GOODCUTOFF]),STATE_SLEEPING)
    StateCheck(SecondNearest([GOODCUTOFF]),STATE_FEEBLEMINDED)
  OR(2)
    !HasImmunityEffects(Myself)
    !Range(SecondNearest([GOODCUTOFF]),15)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(SecondNearest([GOODCUTOFF]),CLERIC_DISPEL_MAGIC)
END

