IF
  OR(2)
    See([GOODCUTOFF])
    See([PC])
  False()
THEN
  RESPONSE #100
END

IF
  Global("GB_DoOnce","LOCALS",0)
  !GlobalTimerNotExpired("GB_SpellPrep","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("GB_SpellPrep","LOCALS",2880)
    SetGlobal("GB_DoOnce","LOCALS",1)
END

IF
  Global("GB_DoOnce","LOCALS",1)
  !GlobalTimerNotExpired("GB_SpellPrep","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("GB_SpellPrep","LOCALS",2880)
    Rest()
END

IF
  Allegiance(Myself,NEUTRAL)
  AttackedBy([GOODCUTOFF],DEFAULT)
THEN
  RESPONSE #100
    Enemy()
    GlobalShout(10000)
    SetGlobal("GB_Attacked","LOCALS",1)
END

IF
  Allegiance(Myself,NEUTRAL)
  SpellCastOnMe([GOODCUTOFF],0)
THEN
  RESPONSE #100
    Enemy()
    GlobalShout(10000)
    SetGlobal("GB_Attacked","LOCALS",1)
END

IF
  Allegiance(Myself,NEUTRAL)
  OR(3)
    SpellCast([PC],0)
    SpellCastPriest([PC],0)
    SpellCastInnate([PC],0)
THEN
  RESPONSE #100
    Enemy()
    GlobalShout(10000)
    SetGlobal("GB_Attacked","LOCALS",1)
END

IF
  Allegiance(Myself,NEUTRAL)
  Heard([EVILCUTOFF],10000)
THEN
  RESPONSE #100
    Enemy()
    GlobalShout(10000)
    SetGlobal("GB_Attacked","LOCALS",1)
END

IF
  Allegiance(Myself,NEUTRAL)
THEN
  RESPONSE #100
    NoAction()
END

IF
  HasItem("POTN52",Myself)  // ~Potion of Extra Healing~
  !GlobalTimerNotExpired("GB_Cast","LOCALS")
  OR(2)
    HPPercentLT(Myself,50)
    DamageTakenGT(26)
  OR(3)
    !Detect([PC])
    StateCheck(Myself,STATE_INVISIBLE)
    HPPercentLT(Myself,35)
THEN
  RESPONSE #100
    ActionOverride(Myself,UseItem("POTN52",Myself))  // ~Potion of Extra Healing~
    DisplayStringHead(Myself,46150)  // ~quaffs a potion~
    SetGlobalTimer("GB_Cast","LOCALS",6)
END

IF
  Global("GB_Attacked","LOCALS",0)
  OR(6)
    Heard([EVILCUTOFF],10000)
    Heard([EVILCUTOFF],10001)
    SpellCastOnMe([GOODCUTOFF],0)
    See(NearestEnemyOf(Myself))
    TookDamage()
    Allegiance(Myself,EVILCUTOFF)
THEN
  RESPONSE #100
    GlobalShout(10000)
    SetGlobal("GB_Attacked","LOCALS",1)
END

IF
  Heard([EVILCUTOFF],10000)
  !See([PC])
  !Range(LastHeardBy(Myself),0)
  !GlobalTimerNotExpired("GB_OnMyWay","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("GB_OnMyWay","LOCALS",24)
    MoveToObject(LastHeardBy(Myself))
    MoveToObject(LastSeenBy(LastHeardBy(Myself)))
END

IF
  Heard([EVILCUTOFF],10001)
  !See([PC])
  !Range(LastHeardBy(Myself),0)
  !GlobalTimerNotExpired("GB_OnMyWay","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("GB_OnMyWay","LOCALS",24)
    MoveToObject(LastHeardBy(Myself))
    MoveToObject(LastSeenBy(LastHeardBy(Myself)))
END

IF
  StateCheck(Myself,STATE_BLIND)
  !See([PC])
THEN
  RESPONSE #100
    RandomWalkContinuous()
END

IF
  Global("GB_Attacked","LOCALS",0)
THEN
  RESPONSE #100
END

IF
  !See([PC])
  !StateCheck(Player1,STATE_INVISIBLE)
  !GlobalTimerNotExpired("GB_OnMyWay","LOCALS")
  OR(4)
    See([GOODCUTOFF])
    SpellCastOnMe([GOODCUTOFF],0)
    TookDamage()
    Exists(Player1)
THEN
  RESPONSE #100
    GlobalShout(10000)
    MoveToObject(Player1)
END

IF
  Delay(18)
  !See([PC])
  !GlobalTimerNotExpired("GB_OnMyWay","LOCALS")
THEN
  RESPONSE #100
    RandomWalkContinuous()
END

IF
  Delay(18)
  See([PC])
  !GlobalTimerNotExpired("GB_OnMyWay","LOCALS")
THEN
  RESPONSE #100
    GlobalShout(10001)
END

IF
  StateCheck(LastSeenBy(Myself),STATE_DEAD)
  See(NearestEnemyOf(Myself))
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  Heard([EVILCUTOFF],10002)
  InParty(LastTargetedBy(LastHeardBy(Myself)))
  Range(LastTargetedBy(LastHeardBy(Myself)),7)
THEN
  RESPONSE #100
    DisplayStringHead(Myself,35124)  // ~Worthless worm! You will die here and now!~
    EquipMostDamagingMelee()
    AttackOneRound(LastTargetedBy(LastHeardBy(Myself)))
END

IF
  Heard([EVILCUTOFF],10002)
  InParty(LastTargetedBy(LastHeardBy(Myself)))
  !Range(LastTargetedBy(LastHeardBy(Myself)),7)
THEN
  RESPONSE #100
    DisplayStringHead(Myself,35124)  // ~Worthless worm! You will die here and now!~
    EquipRanged()
    AttackOneRound(LastTargetedBy(LastHeardBy(Myself)))
END

IF
  OR(4)
    CheckStatGT(LastSeenBy(Myself),0,HELD)
    StateCheck(LastSeenBy(Myself),STATE_STUNNED)
    StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
    StateCheck(LastSeenBy(Myself),STATE_SLEEPING)
  InParty(LastSeenBy(Myself))
  Range(LastSeenBy(Myself),7)
THEN
  RESPONSE #100
    DisplayStringHead(Myself,18450)  // ~At 'em lads! No mercy!~
    GlobalShout(10002)
    EquipMostDamagingMelee()
    AttackOneRound(LastSeenBy(Myself))
END

IF
  OR(4)
    CheckStatGT(LastSeenBy(Myself),0,HELD)
    StateCheck(LastSeenBy(Myself),STATE_STUNNED)
    StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
    StateCheck(LastSeenBy(Myself),STATE_SLEEPING)
  InParty(LastSeenBy(Myself))
  !Range(LastSeenBy(Myself),7)
THEN
  RESPONSE #100
    DisplayStringHead(Myself,18450)  // ~At 'em lads! No mercy!~
    GlobalShout(10002)
    EquipRanged()
    AttackOneRound(LastSeenBy(Myself))
END

IF
  GlobalTimerNotExpired("GB_Cast","LOCALS")
  See([PC])
  InParty(LastSeenBy(Myself))
  Range(LastSeenBy(Myself),7)
THEN
  RESPONSE #100
    GlobalShout(10001)
    EquipMostDamagingMelee()
    AttackOneRound(LastSeenBy(Myself))
END

IF
  GlobalTimerNotExpired("GB_Cast","LOCALS")
  OR(3)
    See([PC])
    See(TenthNearest([PC.0.0.CLERIC_ALL]))
    See(TenthNearest([PC.0.0.LONG_BOW]))
  InParty(LastSeenBy(Myself))
  !Range(LastSeenBy(Myself),7)
THEN
  RESPONSE #100
    GlobalShout(10001)
    EquipRanged()
    AttackOneRound(LastSeenBy(Myself))
END

IF
  HasItem("POTN21",Myself)  // ~Potion of Clarity~
  !GlobalTimerNotExpired("Clarity","LOCALS")
THEN
  RESPONSE #100
    DisplayStringHead(Myself,46150)  // ~quaffs a potion~
    UseItem("POTN21",Myself)  // ~Potion of Clarity~
    SetGlobalTimer("Clarity","LOCALS",300)
    SetGlobalTimer("GB_Cast","LOCALS",6)
END

IF
  HasItem("POTN52",Myself)  // ~Potion of Extra Healing~
  HPPercentLT(Myself,50)
THEN
  RESPONSE #100
    DisplayStringHead(Myself,46150)  // ~quaffs a potion~
    UseItem("POTN52",Myself)  // ~Potion of Extra Healing~
    SetGlobalTimer("GB_Cast","LOCALS",6)
END

IF
  See([GOODCUTOFF.UNDEAD])
  !GlobalTimerNotExpired("GB_TurnedUndead","LOCALS")
  Range(LastSeenBy(Myself),7)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_TurnedUndead","LOCALS",18)
    Turn()
    Wait(6)
END

IF
  CheckStatGT("gbene01a",0,HELD)  // ~Fighter~
  HaveSpell(CLERIC_REMOVE_PARALYSIS)
  !StateCheck("gbene01a",STATE_IMPROVEDINVISIBILITY)  // ~Fighter~
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_Cast","LOCALS",6)
    Spell("gbene01a",CLERIC_REMOVE_PARALYSIS)
END

IF
  CheckStatGT("gbene01b",0,HELD)  // ~Fighter~
  HaveSpell(CLERIC_REMOVE_PARALYSIS)
  !StateCheck("gbene01b",STATE_IMPROVEDINVISIBILITY)  // ~Fighter~
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_Cast","LOCALS",6)
    Spell("gbene01b",CLERIC_REMOVE_PARALYSIS)
END

IF
  CheckStatGT("gbene01c",0,HELD)  // ~Fighter / Mage~
  HaveSpell(CLERIC_REMOVE_PARALYSIS)
  !StateCheck("gbene01c",STATE_IMPROVEDINVISIBILITY)  // ~Fighter / Mage~
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_Cast","LOCALS",6)
    Spell("gbene01c",CLERIC_REMOVE_PARALYSIS)
END

IF
  CheckStatGT("gbene01d",0,HELD)  // ~Cleric~
  HaveSpell(CLERIC_REMOVE_PARALYSIS)
  !StateCheck("gbene01d",STATE_IMPROVEDINVISIBILITY)  // ~Cleric~
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_Cast","LOCALS",6)
    Spell("gbene01d",CLERIC_REMOVE_PARALYSIS)
END

IF
  CheckStatGT("gbene01e",0,HELD)  // ~Assassin~
  HaveSpell(CLERIC_REMOVE_PARALYSIS)
  !StateCheck("gbene01e",STATE_IMPROVEDINVISIBILITY)  // ~Assassin~
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_Cast","LOCALS",6)
    Spell("gbene01e",CLERIC_REMOVE_PARALYSIS)
END

IF
  CheckStatGT("gbene01f",0,HELD)  // ~Necromancer~
  HaveSpell(CLERIC_REMOVE_PARALYSIS)
  !StateCheck("gbene01f",STATE_IMPROVEDINVISIBILITY)  // ~Necromancer~
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_Cast","LOCALS",6)
    Spell("gbene01f",CLERIC_REMOVE_PARALYSIS)
END

IF
  StateCheck("gbene01a",STATE_PANIC)  // ~Fighter~
  HaveSpell(CLERIC_REMOVE_FEAR)
  !StateCheck("gbene01a",STATE_IMPROVEDINVISIBILITY)  // ~Fighter~
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_Cast","LOCALS",6)
    Spell("gbene01a",CLERIC_REMOVE_FEAR)
END

IF
  StateCheck("gbene01b",STATE_PANIC)  // ~Fighter~
  HaveSpell(CLERIC_REMOVE_FEAR)
  !StateCheck("gbene01b",STATE_IMPROVEDINVISIBILITY)  // ~Fighter~
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_Cast","LOCALS",6)
    Spell("gbene01b",CLERIC_REMOVE_FEAR)
END

IF
  StateCheck("gbene01c",STATE_PANIC)  // ~Fighter / Mage~
  HaveSpell(CLERIC_REMOVE_FEAR)
  !StateCheck("gbene01c",STATE_IMPROVEDINVISIBILITY)  // ~Fighter / Mage~
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_Cast","LOCALS",6)
    Spell("gbene01c",CLERIC_REMOVE_FEAR)
END

IF
  StateCheck("gbene01d",STATE_PANIC)  // ~Cleric~
  HaveSpell(CLERIC_REMOVE_FEAR)
  !StateCheck("gbene01d",STATE_IMPROVEDINVISIBILITY)  // ~Cleric~
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_Cast","LOCALS",6)
    Spell("gbene01d",CLERIC_REMOVE_FEAR)
END

IF
  StateCheck("gbene01e",STATE_PANIC)  // ~Assassin~
  HaveSpell(CLERIC_REMOVE_FEAR)
  !StateCheck("gbene01e",STATE_IMPROVEDINVISIBILITY)  // ~Assassin~
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_Cast","LOCALS",6)
    Spell("gbene01e",CLERIC_REMOVE_FEAR)
END

IF
  StateCheck("gbene01f",STATE_PANIC)  // ~Necromancer~
  HaveSpell(CLERIC_REMOVE_FEAR)
  !StateCheck("gbene01f",STATE_IMPROVEDINVISIBILITY)  // ~Necromancer~
  !CheckStatGT(Myself,35,0)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_Cast","LOCALS",6)
    Spell("gbene01f",CLERIC_REMOVE_PARALYSIS)
END

IF
  StateCheck("gbene01a",STATE_POISONED)  // ~Fighter~
  HaveSpell(CLERIC_NEUTRALIZE_POISON)
  !StateCheck("gbene01a",STATE_IMPROVEDINVISIBILITY)  // ~Fighter~
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_Cast","LOCALS",6)
    Spell("gbene01a",CLERIC_NEUTRALIZE_POISON)
END

IF
  StateCheck("gbene01b",STATE_POISONED)  // ~Fighter~
  HaveSpell(CLERIC_NEUTRALIZE_POISON)
  !StateCheck("gbene01b",STATE_IMPROVEDINVISIBILITY)  // ~Fighter~
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_Cast","LOCALS",6)
    Spell("gbene01b",CLERIC_NEUTRALIZE_POISON)
END

IF
  StateCheck("gbene01c",STATE_POISONED)  // ~Fighter / Mage~
  HaveSpell(CLERIC_NEUTRALIZE_POISON)
  !StateCheck("gbene01c",STATE_IMPROVEDINVISIBILITY)  // ~Fighter / Mage~
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_Cast","LOCALS",6)
    Spell("gbene01c",CLERIC_NEUTRALIZE_POISON)
END

IF
  StateCheck("gbene01d",STATE_POISONED)  // ~Cleric~
  HaveSpell(CLERIC_NEUTRALIZE_POISON)
  !StateCheck("gbene01d",STATE_IMPROVEDINVISIBILITY)  // ~Cleric~
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_Cast","LOCALS",6)
    Spell("gbene01d",CLERIC_NEUTRALIZE_POISON)
END

IF
  StateCheck("gbene01e",STATE_POISONED)  // ~Assassin~
  HaveSpell(CLERIC_NEUTRALIZE_POISON)
  !StateCheck("gbene01e",STATE_IMPROVEDINVISIBILITY)  // ~Assassin~
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_Cast","LOCALS",6)
    Spell("gbene01e",CLERIC_NEUTRALIZE_POISON)
END

IF
  StateCheck("gbene01f",STATE_POISONED)  // ~Necromancer~
  HaveSpell(CLERIC_NEUTRALIZE_POISON)
  !StateCheck("gbene01f",STATE_IMPROVEDINVISIBILITY)  // ~Necromancer~
  !CheckStatGT(Myself,35,0)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_Cast","LOCALS",6)
    Spell("gbene01f",CLERIC_NEUTRALIZE_POISON)
END

IF
  HaveSpell(CLERIC_STRENGTH_OF_ONE)
  See([PC])
  InParty(LastSeenBy(Myself))
  CheckStatLT(Myself,19,STR)
  CheckStatLT(Myself,75,STREXTRA)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_Cast","LOCALS",6)
    Spell(Myself,CLERIC_STRENGTH_OF_ONE)
END

IF
  HaveSpell(CLERIC_ARMOR_OF_FAITH)
  See([PC])
  InParty(LastSeenBy(Myself))
  !GlobalTimerNotExpired("GB_ClrArmorFaith","LOCALS")
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_ClrArmorFaith","LOCALS",90)
    SetGlobalTimer("GB_Cast","LOCALS",6)
    Spell(Myself,CLERIC_ARMOR_OF_FAITH)
END

IF
  HaveSpell(CLERIC_BLESS)
  See([PC])
  InParty(LastSeenBy(Myself))
  !StateCheck(Myself,STATE_BLESS)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_Cast","LOCALS",6)
    Spell(Myself,CLERIC_BLESS)
END

IF
  HaveSpell(CLERIC_MENTAL_DOMINATION)
  See([PC])
  InParty(LastSeenBy(Myself))
  !CheckStatGT(LastSeenBy(Myself),50,RESISTMAGIC)
  !StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  !StateCheck(LastSeenBy(Myself),STATE_CHARMED)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_Cast","LOCALS",6)
    Spell(LastSeenBy(Myself),CLERIC_MENTAL_DOMINATION)
END

IF
  HaveSpell(CLERIC_HOLD_PERSON)
  See([PC])
  InParty(LastSeenBy(Myself))
  !CheckStatGT(LastSeenBy(Myself),50,RESISTMAGIC)
  !StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  !StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_Cast","LOCALS",6)
    Spell(LastSeenBy(Myself),CLERIC_HOLD_PERSON)
END

IF
  HaveSpell(CLERIC_COMMAND)
  See([PC])
  InParty(LastSeenBy(Myself))
  !CheckStatGT(LastSeenBy(Myself),50,RESISTMAGIC)
  !StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  !StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_Cast","LOCALS",6)
    Spell(LastSeenBy(Myself),CLERIC_COMMAND)
END

IF
  HaveSpell(CLERIC_DRAW_UPON_HOLY_MIGHT)
  See([PC])
  InParty(LastSeenBy(Myself))
  !GlobalTimerNotExpired("GB_ClrDUHM","LOCALS")
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_ClrDUHM","LOCALS",90)
    SetGlobalTimer("GB_Cast","LOCALS",6)
    Spell(Myself,CLERIC_DRAW_UPON_HOLY_MIGHT)
END

IF
  See([PC])
  InParty(LastSeenBy(Myself))
  Range(LastSeenBy(Myself),7)
THEN
  RESPONSE #100
    GlobalShout(10001)
    EquipMostDamagingMelee()
    AttackOneRound(LastSeenBy(Myself))
END

IF
  OR(3)
    See([PC])
    See(TenthNearest([PC.0.0.CLERIC_ALL]))
    See(TenthNearest([PC.0.0.LONG_BOW]))
  InParty(LastSeenBy(Myself))
  !Range(LastSeenBy(Myself),7)
THEN
  RESPONSE #100
    GlobalShout(10001)
    EquipRanged()
    AttackOneRound(LastSeenBy(Myself))
END

IF
  See([GOODCUTOFF])
  Range(LastSeenBy(Myself),7)
THEN
  RESPONSE #100
    EquipMostDamagingMelee()
    AttackOneRound(LastSeenBy(Myself))
END

IF
  See([GOODCUTOFF])
  !Range(LastSeenBy(Myself),7)
THEN
  RESPONSE #100
    EquipRanged()
    AttackOneRound(LastSeenBy(Myself))
END
