IF
  Global("CloseCombat","LOCALS",1)
  GlobalTimerExpired("attacked","LOCALS")
THEN
  RESPONSE #100
    SetGlobal("CloseCombat","LOCALS",0)
    SetGlobalTimer("SafeForAWhile","LOCALS",6)
END

IF
  Global("CloseCombat","LOCALS",0)
  Global("safe","LOCALS",0)
  GlobalTimerExpired("SafeForAWhile","LOCALS")
THEN
  RESPONSE #100
    SetGlobal("safe","LOCALS",1)
END

IF
  Global("CloseCombat","LOCALS",0)
  OR(2)
    HitBy([ANYONE],CRUSHING)
    AttackedBy([ANYONE],DEFAULT)
  Range(NearestEnemyOf(Myself),8)
THEN
  RESPONSE #100
    SetGlobal("CloseCombat","LOCALS",1)
    SetGlobal("safe","LOCALS",0)
    SetGlobalTimer("attacked","LOCALS",5)
END

IF
  StateCheck(Myself,STATE_SILENCED)
  !GlobalTimerNotExpired("spell","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("spell","LOCALS",6)
    ForceSpell(Myself,WIZARD_VOCALIZE)
END

IF
  StateCheck(Myself,STATE_INVISIBLE)
  HPPercentLT(Myself,75)
  !GlobalTimerNotExpired("SolarHeal","LOCALS")
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    SetGlobalTimer("SolarHeal","LOCALS",30)
    SetGlobalTimer("spell","LOCALS",6)
    SpellNoDec(Myself,CLERIC_HEAL)
    SetInterrupt(TRUE)
END

IF
  HPPercentLT(Myself,50)
  Exists([GOODCUTOFF])
  OR(2)
    Global("safe","LOCALS",1)
    !Range(NearestEnemyOf(Myself),10)
  !StateCheck(Myself,STATE_SLOWED)
  !GlobalTimerNotExpired("spell","LOCALS")
  !GlobalTimerNotExpired("SolarHeal","LOCALS")
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    SetGlobalTimer("SolarHeal","LOCALS",30)
    SetGlobalTimer("spell","LOCALS",6)
    SpellNoDec(Myself,CLERIC_HEAL)
    SetInterrupt(TRUE)
END

IF
  HPPercentLT(Myself,50)
  !StateCheck(Myself,STATE_INVISIBLE)
  !GlobalTimerNotExpired("invisInt","LOCALS")
  !GlobalTimerNotExpired("SolarHeal","LOCALS")
  Global("safe","LOCALS",0)
  OR(2)
    Range(NearestEnemyOf(Myself),10)
    StateCheck(Myself,STATE_SLOWED)
  !GlobalTimerNotExpired("spell","LOCALS")
THEN
  RESPONSE #60
    SetInterrupt(FALSE)
    SetGlobalTimer("spell","LOCALS",6)
    SetGlobalTimer("invis","LOCALS",7)
    SetGlobalTimer("invisInt","LOCALS",18)
    ForceSpell(Myself,WIZARD_IMPROVED_INVISIBILITY)
    SetGlobalTimer("SolarHeal","LOCALS",30)
    SpellNoDec(Myself,CLERIC_HEAL)
    SetInterrupt(TRUE)
    RandomWalkContinuous()
  RESPONSE #40
    SetInterrupt(FALSE)
    SetGlobalTimer("spell","LOCALS",6)
    SetGlobalTimer("invis","LOCALS",7)
    SetGlobalTimer("invisInt","LOCALS",18)
    SpellNoDec(Myself,WIZARD_IMPROVED_INVISIBILITY)
    SetGlobalTimer("SolarHeal","LOCALS",30)
    SpellNoDec(Myself,CLERIC_HEAL)
    SetInterrupt(TRUE)
    RandomWalkContinuous()
END

IF
  HPPercentLT(Myself,50)
  !StateCheck(Myself,STATE_INVISIBLE)
  !GlobalTimerNotExpired("invisInt","LOCALS")
  !GlobalTimerNotExpired("spell","LOCALS")
  GlobalTimerNotExpired("SolarHeal","LOCALS")
THEN
  RESPONSE #60
    SetInterrupt(FALSE)
    SetGlobalTimer("spell","LOCALS",6)
    SetGlobalTimer("invis","LOCALS",7)
    SetGlobalTimer("invisInt","LOCALS",18)
    ForceSpell(Myself,WIZARD_IMPROVED_INVISIBILITY)
    SetInterrupt(TRUE)
    RandomWalkContinuous()
  RESPONSE #40
    SetInterrupt(FALSE)
    SetGlobalTimer("spell","LOCALS",6)
    SetGlobalTimer("invis","LOCALS",7)
    SetGlobalTimer("invisInt","LOCALS",18)
    SpellNoDec(Myself,WIZARD_IMPROVED_INVISIBILITY)
    SetInterrupt(TRUE)
    RandomWalkContinuous()
END

IF
  HPPercentLT(Myself,50)
  StateCheck(Myself,STATE_INVISIBLE)
  GlobalTimerNotExpired("SolarHeal","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("invis","LOCALS",7)
    SetGlobalTimer("spell","LOCALS",7)
END

IF
  HPPercentLT(Myself,40)
  GlobalTimerNotExpired("invisInt","LOCALS")
  Global("safe","LOCALS",0)
  Range(NearestEnemyOf(Myself),10)
  !StateCheck(Myself,STATE_SLOWED)
THEN
  RESPONSE #100
    EquipMostDamagingMelee()
    SetGlobalTimer("invis","LOCALS",7)
    RandomWalkContinuous()
END

IF
  !GlobalTimerNotExpired("spell","LOCALS")
  !GlobalTimerNotExpired("freeactInt","LOCALS")
  OR(3)
    StateCheck(Myself,STATE_SLOWED)
    CheckStatGT(Myself,0,WEB)
    CheckStatGT(Myself,0,ENTANGLE)
  OR(4)
    StateCheck(Myself,STATE_INVISIBLE)
    GlobalGT("random","LOCALS",5)
    CheckStatGT(Myself,0,WEB)
    CheckStatGT(Myself,0,ENTANGLE)
THEN
  RESPONSE #50
    SetGlobalTimer("spell","LOCALS",6)
    SetGlobalTimer("freeactInt","LOCALS",18)
    SetGlobal("random","LOCALS",0)
    ForceSpell(Myself,CLERIC_FREE_ACTION)
  RESPONSE #50
    SetGlobalTimer("spell","LOCALS",6)
    SetGlobalTimer("freeactInt","LOCALS",18)
    SetGlobal("random","LOCALS",0)
    SpellNoDec(Myself,CLERIC_FREE_ACTION)
END

IF
  !GlobalTimerNotExpired("spell","LOCALS")
  OR(6)
    StateCheck(NearestEnemyOf(Myself),STATE_INVISIBLE)
    StateCheck(NearestEnemyOf(Myself),STATE_IMPROVEDINVISIBILITY)
    StateCheck(SecondNearestEnemyOf(Myself),STATE_INVISIBLE)
    StateCheck(SecondNearestEnemyOf(Myself),STATE_IMPROVEDINVISIBILITY)
    StateCheck(ThirdNearestEnemyOf(Myself),STATE_INVISIBLE)
    StateCheck(ThirdNearestEnemyOf(Myself),STATE_IMPROVEDINVISIBILITY)
  !GlobalTimerNotExpired("SolarSight","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("SolarSight","LOCALS",60)
    SetGlobalTimer("spell","LOCALS",6)
    ForceSpell(Myself,WIZARD_TRUE_SIGHT)
END

IF
  !GlobalTimerNotExpired("SolarHeal","LOCALS")
  !GlobalTimerNotExpired("NoHeal","LOCALS")
  !GlobalTimerNotExpired("spell","LOCALS")
  HPPercentGT(Myself,60)
  Global("CloseCombat","LOCALS",0)
  OR(3)
    !Range(NearestEnemyOf(Myself),6)
    Global("safe","LOCALS",1)
    HPPercentGT(Myself,90)
  See(SecondNearest([EVILCUTOFF]))
  OR(2)
    CheckStatLT(LastSeenBy(Myself),20000,XPVALUE)
    HPPercentGT(LastSeenBy(Myself),65)
  See(ThirdNearest([EVILCUTOFF]))
  OR(2)
    CheckStatLT(LastSeenBy(Myself),20000,XPVALUE)
    HPPercentGT(LastSeenBy(Myself),65)
  See(FourthNearest([EVILCUTOFF]))
  OR(2)
    CheckStatLT(LastSeenBy(Myself),20000,XPVALUE)
    HPPercentGT(LastSeenBy(Myself),65)
  See(FifthNearest([EVILCUTOFF]))
  OR(2)
    CheckStatLT(LastSeenBy(Myself),20000,XPVALUE)
    HPPercentGT(LastSeenBy(Myself),65)
  See([EVILCUTOFF])
  False()
THEN
  RESPONSE #100
END

IF
  !GlobalTimerNotExpired("SolarHeal","LOCALS")
  !GlobalTimerNotExpired("NoHeal","LOCALS")
  !GlobalTimerNotExpired("spell","LOCALS")
  !StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  !InParty(LastSeenBy(Myself))
  HPPercentGT(Myself,60)
  Global("CloseCombat","LOCALS",0)
  OR(4)
    !Range(NearestEnemyOf(Myself),6)
    Global("safe","LOCALS",1)
    HPPercentGT(Myself,90)
    GlobalLT("random","LOCALS",4)
  HPPercentLT(LastSeenBy(Myself),75)
  OR(2)
    GlobalLT("random","LOCALS",3)
    HPPercentLT(LastSeenBy(Myself),64)
  OR(2)
    GlobalLT("random","LOCALS",6)
    HPPercentLT(LastSeenBy(Myself),51)
  OR(2)
    GlobalLT("random","LOCALS",8)
    HPPercentLT(LastSeenBy(Myself),40)
  CheckStatGT(LastSeenBy(Myself),19999,XPVALUE)
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    ActionOverride(SecondNearest([EVILCUTOFF]),SetGlobalTimer("NoHeal","LOCALS",5))
    ActionOverride(ThirdNearest([EVILCUTOFF]),SetGlobalTimer("NoHeal","LOCALS",5))
    ActionOverride(FourthNearest([EVILCUTOFF]),SetGlobalTimer("NoHeal","LOCALS",5))
    ActionOverride(FifthNearest([EVILCUTOFF]),SetGlobalTimer("NoHeal","LOCALS",5))
    SetGlobalTimer("SolarHeal","LOCALS",30)
    SetGlobalTimer("spell","LOCALS",6)
    SetGlobal("random","LOCALS",0)
    SpellNoDec(LastSeenBy(Myself),CLERIC_HEAL)
    SetInterrupt(TRUE)
END

IF
  See(NearestEnemyOf(Myself))
  False()
THEN
  RESPONSE #100
END

IF
  !See(Player1)
  !See(Player2)
  !See(Player3)
  !See(Player4)
  !See(Player5)
  !See(Player6)
  GlobalTimerExpired("attacked","LOCALS")
THEN
  RESPONSE #16
    MoveToObject(Player1)
  RESPONSE #16
    MoveToObject(Player2)
  RESPONSE #17
    MoveToObject(Player3)
  RESPONSE #17
    MoveToObject(Player4)
  RESPONSE #17
    MoveToObject(Player5)
  RESPONSE #17
    MoveToObject(Player6)
END

IF
  StateCheck(LastSeenBy(Myself),STATE_DEAD)
THEN
  RESPONSE #100
    AttackOneRound(NearestEnemyOf(Myself))
END

IF
  !Allegiance(LastSeenBy(Myself),GOODCUTOFF)
  !InParty(LastSeenBy(Myself))
  See(NearestEnemyOf(Myself))
THEN
  RESPONSE #100
    AttackOneRound(NearestEnemyOf(Myself))
END

IF
  Allegiance(Myself,EVILCUTOFF)
  !GlobalTimerNotExpired("spell","LOCALS")
  OR(3)
    See([GOODCUTOFF.GIANTHUMANOID])
    See([GOODCUTOFF.ANIMAL])
    See([GOODCUTOFF.MONSTER])
  Gender(LastSeenBy(Myself),SUMMONED)
  LevelLT(LastSeenBy(Myself),11)
  !GlobalTimerNotExpired("SolarDeathSpell","LOCALS")
THEN
  RESPONSE #50
    SetGlobalTimer("MelissanDeathSpell","LOCALS",30)
    SetGlobalTimer("spell","LOCALS",6)
    ForceSpell(LastSeenBy(Myself),WIZARD_DEATH_SPELL)
  RESPONSE #50
    SetGlobalTimer("MelissanDeathSpell","LOCALS",30)
    SetGlobalTimer("spell","LOCALS",6)
    SpellNoDec(LastSeenBy(Myself),WIZARD_DEATH_SPELL)
END

IF
  Global("random","LOCALS",0)
  See(NearestEnemyOf(Myself))
THEN
  RESPONSE #10
    SetGlobal("random","LOCALS",1)
  RESPONSE #10
    SetGlobal("random","LOCALS",2)
  RESPONSE #10
    SetGlobal("random","LOCALS",3)
  RESPONSE #10
    SetGlobal("random","LOCALS",4)
  RESPONSE #10
    SetGlobal("random","LOCALS",5)
  RESPONSE #10
    SetGlobal("random","LOCALS",6)
  RESPONSE #10
    SetGlobal("random","LOCALS",7)
  RESPONSE #10
    SetGlobal("random","LOCALS",8)
  RESPONSE #10
    SetGlobal("random","LOCALS",9)
END

IF
  Allegiance(Myself,EVILCUTOFF)
  GlobalGT("random","LOCALS",4)
  OR(6)
    See(TenthNearestEnemyOf(Myself))
    See([GOODCUTOFF.0.0.BARD_ALL])
    See([GOODCUTOFF.0.0.CLERIC_ALL])
    See([GOODCUTOFF.0.0.DRUID_ALL])
    See([GOODCUTOFF.0.0.LONG_BOW])
    See([GOODCUTOFF.0.0.SORCERER])
  False()
THEN
  RESPONSE #100
END

IF
  Allegiance(Myself,GOODCUTOFF)
  GlobalGT("random","LOCALS",4)
  OR(6)
    See(TenthNearestEnemyOf(Myself))
    See([EVILCUTOFF.0.0.BARD_ALL])
    See([EVILCUTOFF.0.0.CLERIC_ALL])
    See([EVILCUTOFF.0.0.DRUID_ALL])
    See([EVILCUTOFF.0.0.LONG_BOW])
    See([EVILCUTOFF.0.0.SORCERER])
  False()
THEN
  RESPONSE #100
END

IF
  Allegiance(Myself,EVILCUTOFF)
  GlobalLT("random","LOCALS",5)
  OR(6)
    See(TenthNearestEnemyOf(Myself))
    See(StrongestOf)
    See([GOODCUTOFF.0.0.FIGHTER_ALL])
    See([GOODCUTOFF.0.0.RANGER_ALL])
    See([GOODCUTOFF.0.0.PALADIN_ALL])
    See(BestAC)
  RandomNumGT(5,3)
  See([GOODCUTOFF.0.0.PALADIN_ALL])
  False()
THEN
  RESPONSE #100
END

IF
  Allegiance(Myself,GOODCUTOFF)
  GlobalLT("random","LOCALS",5)
  OR(3)
    See([EVILCUTOFF.0.0.FIGHTER_ALL])
    See([EVILCUTOFF.0.0.RANGER_ALL])
    See([EVILCUTOFF.0.0.PALADIN_ALL])
  RandomNumGT(5,3)
  See([EVILCUTOFF.0.0.PALADIN_ALL])
  False()
THEN
  RESPONSE #100
END

IF
  Global("random","LOCALS",0)
THEN
  RESPONSE #25
    SetGlobal("SolarCreepDoom","LOCALS",1)
    SetGlobalTimer("spell","LOCALS",6)
    SpellNoDec(LastSeenBy(Myself),CLERIC_CREEPING_DOOM)
    SetGlobalTimer("insects","LOCALS",24)
  RESPONSE #25
    SetGlobal("SolarFinger","LOCALS",1)
    SetGlobalTimer("spell","LOCALS",6)
    SpellNoDec(LastSeenBy(Myself),CLERIC_FINGER_OF_DEATH)
  RESPONSE #25
    SetGlobal("SolarSpray","LOCALS",1)
    SetGlobalTimer("spell","LOCALS",6)
    SpellNoDec(LastSeenBy(Myself),WIZARD_PRISMATIC_SPRAY)
  RESPONSE #25
    SetGlobalTimer("spell","LOCALS",6)
    SetGlobalTimer("dispelInt","LOCALS",18)
    SpellNoDec(LastSeenBy(Myself),2302)
END

IF
  Global("random","LOCALS",1)
  !GlobalTimerNotExpired("spell","LOCALS")
  HPPercentGT(LastSeenBy(Myself),50)
  !InPartySlot(LastSeenBy(Myself),0)
  Global("SolarImprisonment","LOCALS",0)
THEN
  RESPONSE #66
    SetGlobal("SolarImprisonment","LOCALS",1)
    SetGlobalTimer("spell","LOCALS",6)
    SetGlobal("random","LOCALS",0)
    ForceSpell(LastSeenBy(Myself),WIZARD_IMPRISONMENT)
  RESPONSE #34
    SetGlobal("SolarImprisonment","LOCALS",1)
    SetGlobalTimer("spell","LOCALS",6)
    SpellNoDec(LastSeenBy(Myself),WIZARD_IMPRISONMENT)
END

IF
  Global("random","LOCALS",1)
  !GlobalTimerNotExpired("spell","LOCALS")
  See(NearestEnemyOf(Myself))
  HPPercentGT(LastSeenBy(Myself),50)
  !InPartySlot(LastSeenBy(Myself),0)
  Global("SolarImprisonment","LOCALS",0)
THEN
  RESPONSE #66
    SetGlobal("SolarImprisonment","LOCALS",1)
    SetGlobalTimer("spell","LOCALS",6)
    SetGlobal("random","LOCALS",0)
    ForceSpell(LastSeenBy(Myself),WIZARD_IMPRISONMENT)
  RESPONSE #34
    SetGlobal("SolarImprisonment","LOCALS",1)
    SetGlobalTimer("spell","LOCALS",6)
    SetGlobal("random","LOCALS",0)
    SpellNoDec(LastSeenBy(Myself),WIZARD_IMPRISONMENT)
END

IF
  !GlobalTimerNotExpired("spell","LOCALS")
  GlobalGT("random","LOCALS",6)
  !StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  Global("SolarCreepDoom","LOCALS",0)
THEN
  RESPONSE #50
    SetGlobal("SolarCreepDoom","LOCALS",1)
    SetGlobalTimer("spell","LOCALS",6)
    SetGlobal("random","LOCALS",0)
    ForceSpell(LastSeenBy(Myself),CLERIC_CREEPING_DOOM)
    SetGlobalTimer("insects","LOCALS",24)
  RESPONSE #50
    SetGlobal("SolarCreepDoom","LOCALS",1)
    SetGlobalTimer("spell","LOCALS",6)
    SetGlobal("random","LOCALS",0)
    SpellNoDec(LastSeenBy(Myself),CLERIC_CREEPING_DOOM)
    SetGlobalTimer("insects","LOCALS",24)
END

IF
  !GlobalTimerNotExpired("spell","LOCALS")
  OR(2)
    GlobalLT("random","LOCALS",2)
    GlobalGT("random","LOCALS",8)
  !StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  Global("SolarFinger","LOCALS",0)
THEN
  RESPONSE #100
    SetGlobal("SolarFinger","LOCALS",1)
    SetGlobalTimer("spell","LOCALS",6)
    SetGlobal("random","LOCALS",0)
    ForceSpell(LastSeenBy(Myself),CLERIC_FINGER_OF_DEATH)
END

IF
  !GlobalTimerNotExpired("spell","LOCALS")
  GlobalGT("random","LOCALS",6)
  !Range(LastSeenBy(Myself),15)
  NumCreatureLT([EVILCUTOFF],3)
  !StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  Global("SolarFirestorm","LOCALS",0)
THEN
  RESPONSE #100
    SetGlobal("SolarFirestorm","LOCALS",1)
    SetGlobalTimer("spell","LOCALS",6)
    SetGlobal("random","LOCALS",0)
    ForceSpell(LastSeenBy(Myself),CLERIC_FIRE_STORM)
END

IF
  !GlobalTimerNotExpired("spell","LOCALS")
  GlobalLT("random","LOCALS",4)
  HPPercentGT(Myself,50)
  !Range(LastSeenBy(Myself),5)
  Global("SolarSpray","LOCALS",0)
THEN
  RESPONSE #100
    SetGlobal("SolarSpray","LOCALS",1)
    SetGlobalTimer("spell","LOCALS",6)
    SetGlobal("random","LOCALS",0)
    ForceSpell(LastSeenBy(Myself),WIZARD_PRISMATIC_SPRAY)
END

IF
  !GlobalTimerNotExpired("spell","LOCALS")
  !GlobalTimerNotExpired("quakeInt","LOCALS")
  GlobalGT("random","LOCALS",6)
  HPPercentGT(Myself,50)
  !StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  GlobalLT("SolarEarthquake","LOCALS",3)
THEN
  RESPONSE #60
    IncrementGlobal("SolarEarthquake","LOCALS",1)
    SetGlobalTimer("spell","LOCALS",6)
    SetGlobalTimer("quakeInt","LOCALS",24)
    SetGlobal("random","LOCALS",0)
    ForceSpell(LastSeenBy(Myself),CLERIC_EARTHQUAKE)
  RESPONSE #40
    IncrementGlobal("SolarEarthquake","LOCALS",1)
    SetGlobalTimer("spell","LOCALS",6)
    SetGlobalTimer("quakeInt","LOCALS",24)
    SetGlobal("random","LOCALS",0)
    SpellNoDec(LastSeenBy(Myself),CLERIC_EARTHQUAKE)
END

IF
  !GlobalTimerNotExpired("spell","LOCALS")
  GlobalGT("random","LOCALS",5)
  Alignment(LastSeenBy(Myself),MASK_GOOD)
  GlobalLT("SolarWord","LOCALS",3)
THEN
  RESPONSE #100
    IncrementGlobal("SolarWord","LOCALS",1)
    SetGlobalTimer("spell","LOCALS",6)
    SetGlobal("random","LOCALS",0)
    ForceSpell(Myself,CLERIC_UNHOLY_WORD)
END

IF
  !GlobalTimerNotExpired("insects","LOCALS")
  !GlobalTimerNotExpired("dispelInt","LOCALS")
  !GlobalTimerNotExpired("spell","LOCALS")
  HPPercentGT(Myself,60)
  GlobalGT("random","LOCALS",4)
  !StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  !StateCheck(LastSeenBy(Myself),STATE_SLOWED)
  !StateCheck(LastSeenBy(Myself),STATE_STUNNED)
  !StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
  !StateCheck(LastSeenBy(Myself),STATE_SLEEPING)
  !StateCheck(LastSeenBy(Myself),STATE_SILENCED)
  !StateCheck(LastSeenBy(Myself),STATE_CONFUSED)
  !StateCheck(LastSeenBy(Myself),STATE_CHARMED)
  !StateCheck(LastSeenBy(Myself),STATE_FEEBLEMINDED)
  !CheckStatGT(LastSeenBy(Myself),0,WEB)
  !CheckStatGT(LastSeenBy(Myself),0,ENTANGLE)
  !CheckStatGT(LastSeenBy(Myself),0,HELD)
  !CheckStatGT(LastSeenBy(Myself),0,GREASE)
  OR(5)
    StateCheck(LastSeenBy(Myself),STATE_HASTED)
    StateCheck(LastSeenBy(Myself),STATE_BLESS)
    StateCheck(LastSeenBy(Myself),STATE_DRAWUPONHOLYMIGHT)
    StateCheck(LastSeenBy(Myself),STATE_BLUR)
    StateCheck(LastSeenBy(Myself),STATE_MIRRORIMAGE)
THEN
  RESPONSE #40
    SetGlobalTimer("spell","LOCALS",6)
    SetGlobalTimer("dispelInt","LOCALS",18)
    SetGlobal("random","LOCALS",0)
    ForceSpell(LastSeenBy(Myself),2302)
  RESPONSE #60
    SetGlobalTimer("spell","LOCALS",6)
    SetGlobalTimer("dispelInt","LOCALS",18)
    SetGlobal("random","LOCALS",0)
    SpellNoDec(LastSeenBy(Myself),2302)
END

IF
  !GlobalTimerNotExpired("spell","LOCALS")
  !GlobalTimerNotExpired("invisInt","LOCALS")
  OR(2)
    GlobalGT("random","LOCALS",4)
    GlobalLT("random","LOCALS",3)
  !StateCheck(Myself,STATE_INVISIBLE)
  HPPercentLT(Myself,100)
THEN
  RESPONSE #50
    SetInterrupt(FALSE)
    SetGlobalTimer("spell","LOCALS",6)
    SetGlobalTimer("invis","LOCALS",7)
    SetGlobalTimer("invisInt","LOCALS",18)
    SetGlobal("random","LOCALS",0)
    ForceSpell(Myself,WIZARD_IMPROVED_INVISIBILITY)
    SetInterrupt(TRUE)
    RandomWalkContinuous()
  RESPONSE #50
    SetInterrupt(FALSE)
    SetGlobalTimer("spell","LOCALS",6)
    SetGlobalTimer("invis","LOCALS",7)
    SetGlobalTimer("invisInt","LOCALS",18)
    SetGlobal("random","LOCALS",0)
    SpellNoDec(Myself,WIZARD_IMPROVED_INVISIBILITY)
    SetInterrupt(TRUE)
    RandomWalkContinuous()
END

IF
  !GlobalTimerNotExpired("spell","LOCALS")
  GlobalLT("random","LOCALS",5)
  !StateCheck(LastSeenBy(Myself),STATE_CONFUSED)
  !StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  GlobalLT("SolarConfuse","LOCALS",3)
THEN
  RESPONSE #70
    IncrementGlobal("SolarConfuse","LOCALS",1)
    SetGlobalTimer("spell","LOCALS",6)
    SetGlobal("random","LOCALS",0)
    ForceSpell(LastSeenBy(Myself),CLERIC_CONFUSION)
  RESPONSE #30
    IncrementGlobal("SolarConfuse","LOCALS",1)
    SetGlobalTimer("spell","LOCALS",6)
    SetGlobal("random","LOCALS",0)
    SpellNoDec(LastSeenBy(Myself),CLERIC_CONFUSION)
END

IF
  !GlobalTimerNotExpired("spell","LOCALS")
  !StateCheck(LastSeenBy(Myself),STATE_CHARMED)
  GlobalLT("SolarCharm","LOCALS",3)
THEN
  RESPONSE #100
    IncrementGlobal("SolarCharm","LOCALS",1)
    SetGlobalTimer("spell","LOCALS",6)
    ForceSpell(LastSeenBy(Myself),ERINYES_CHARM)
END

IF
  See(NearestEnemyOf(Myself))
  See(LastSeenBy([EVILCUTOFF]))
  RandomNumGT(5,2)
  See(WorstAC)
  RandomNumGT(7,3)
  See([GOODCUTOFF.0.ELF])
  False()
THEN
  RESPONSE #100
END

IF
  RandomNumGT(4,1)
  See(NearestEnemyOf(Myself))
  OR(2)
    CheckStatLT(LastSeenBy(Myself),-4,ARMORCLASS)
    Gender(LastSeenBy(Myself),SUMMONED)
  OR(2)
    HPGT(LastSeenBy(Myself),41)
    Gender(LastSeenBy(Myself),SUMMONED)
  !Class(LastSeenBy(Myself),SORCERER)
  See(SecondNearestEnemyOf(Myself))
  OR(2)
    CheckStatLT(LastSeenBy(Myself),-4,ARMORCLASS)
    Gender(LastSeenBy(Myself),SUMMONED)
  OR(2)
    HPGT(LastSeenBy(Myself),41)
    Gender(LastSeenBy(Myself),SUMMONED)
  !Class(LastSeenBy(Myself),SORCERER)
  See(ThirdNearestEnemyOf(Myself))
  OR(2)
    CheckStatLT(LastSeenBy(Myself),-4,ARMORCLASS)
    Gender(LastSeenBy(Myself),SUMMONED)
  OR(2)
    HPGT(LastSeenBy(Myself),41)
    Gender(LastSeenBy(Myself),SUMMONED)
  !Class(LastSeenBy(Myself),SORCERER)
  See(FourthNearestEnemyOf(Myself))
  OR(2)
    CheckStatLT(LastSeenBy(Myself),-4,ARMORCLASS)
    Gender(LastSeenBy(Myself),SUMMONED)
  OR(2)
    HPGT(LastSeenBy(Myself),41)
    Gender(LastSeenBy(Myself),SUMMONED)
  !Class(LastSeenBy(Myself),SORCERER)
  See(FifthNearestEnemyOf(Myself))
  OR(2)
    CheckStatLT(LastSeenBy(Myself),-4,ARMORCLASS)
    Gender(LastSeenBy(Myself),SUMMONED)
  OR(2)
    HPGT(LastSeenBy(Myself),41)
    Gender(LastSeenBy(Myself),SUMMONED)
  !Class(LastSeenBy(Myself),SORCERER)
  See(NearestEnemyOf(Myself))
  OR(2)
    CheckStatLT(LastSeenBy(Myself),-8,ARMORCLASS)
    Gender(LastSeenBy(Myself),SUMMONED)
  OR(2)
    HPGT(LastSeenBy(Myself),61)
    Gender(LastSeenBy(Myself),SUMMONED)
  !Class(LastSeenBy(Myself),LONG_BOW)
  See(SecondNearestEnemyOf(Myself))
  OR(2)
    CheckStatLT(LastSeenBy(Myself),-8,ARMORCLASS)
    Gender(LastSeenBy(Myself),SUMMONED)
  OR(2)
    HPGT(LastSeenBy(Myself),61)
    Gender(LastSeenBy(Myself),SUMMONED)
  !Class(LastSeenBy(Myself),LONG_BOW)
  See(ThirdNearestEnemyOf(Myself))
  OR(2)
    CheckStatLT(LastSeenBy(Myself),-8,ARMORCLASS)
    Gender(LastSeenBy(Myself),SUMMONED)
  OR(2)
    HPGT(LastSeenBy(Myself),61)
    Gender(LastSeenBy(Myself),SUMMONED)
  !Class(LastSeenBy(Myself),LONG_BOW)
  See(FourthNearestEnemyOf(Myself))
  OR(2)
    CheckStatLT(LastSeenBy(Myself),-8,ARMORCLASS)
    Gender(LastSeenBy(Myself),SUMMONED)
  OR(2)
    HPGT(LastSeenBy(Myself),61)
    Gender(LastSeenBy(Myself),SUMMONED)
  !Class(LastSeenBy(Myself),LONG_BOW)
  See(FifthNearestEnemyOf(Myself))
  OR(2)
    CheckStatLT(LastSeenBy(Myself),-8,ARMORCLASS)
    Gender(LastSeenBy(Myself),SUMMONED)
  OR(2)
    HPGT(LastSeenBy(Myself),61)
    Gender(LastSeenBy(Myself),SUMMONED)
  !Class(LastSeenBy(Myself),LONG_BOW)
  See(NearestEnemyOf(Myself))
  !Class(LastSeenBy(Myself),CLERIC_ALL)
  !Class(LastSeenBy(Myself),DRUID_ALL)
  !Class(LastSeenBy(Myself),BARD_ALL)
  OR(2)
    CheckStatLT(LastSeenBy(Myself),-11,ARMORCLASS)
    Gender(LastSeenBy(Myself),SUMMONED)
  See(SecondNearestEnemyOf(Myself))
  !Class(LastSeenBy(Myself),CLERIC_ALL)
  !Class(LastSeenBy(Myself),DRUID_ALL)
  !Class(LastSeenBy(Myself),BARD_ALL)
  OR(2)
    CheckStatLT(LastSeenBy(Myself),-11,ARMORCLASS)
    Gender(LastSeenBy(Myself),SUMMONED)
  See(ThirdNearestEnemyOf(Myself))
  !Class(LastSeenBy(Myself),CLERIC_ALL)
  !Class(LastSeenBy(Myself),DRUID_ALL)
  !Class(LastSeenBy(Myself),BARD_ALL)
  OR(2)
    CheckStatLT(LastSeenBy(Myself),-11,ARMORCLASS)
    Gender(LastSeenBy(Myself),SUMMONED)
  See(FourthNearestEnemyOf(Myself))
  !Class(LastSeenBy(Myself),CLERIC_ALL)
  !Class(LastSeenBy(Myself),DRUID_ALL)
  !Class(LastSeenBy(Myself),BARD_ALL)
  OR(2)
    CheckStatLT(LastSeenBy(Myself),-11,ARMORCLASS)
    Gender(LastSeenBy(Myself),SUMMONED)
  See(FifthNearestEnemyOf(Myself))
  !Class(LastSeenBy(Myself),CLERIC_ALL)
  !Class(LastSeenBy(Myself),DRUID_ALL)
  !Class(LastSeenBy(Myself),BARD_ALL)
  OR(2)
    CheckStatLT(LastSeenBy(Myself),-11,ARMORCLASS)
    Gender(LastSeenBy(Myself),SUMMONED)
  !See([PC])
  See(NearestEnemyOf(Myself))
  False()
THEN
  RESPONSE #100
END

IF
  HasItemEquiped("MAGE01",LastSeenBy(Myself))
  !HasItemEquiped("STALKER",LastSeenBy(Myself))
THEN
  RESPONSE #100
    MoveToObject(Player1)
END

IF
  OR(2)
    !GlobalTimerNotExpired("invis","LOCALS")
    !StateCheck(Myself,STATE_INVISIBLE)
  !GlobalTimerNotExpired("insects","LOCALS")
  OR(2)
    Allegiance(LastSeenBy(Myself),GOODCUTOFF)
    InParty(LastSeenBy(Myself))
  OR(5)
    !Range(NearestEnemyOf(Myself),7)
    CheckStatGT(LastSeenBy(Myself),0,STONESKINS)
    CheckStatGT(LastSeenBy(Myself),0,IMPROVEDHASTE)
    CheckStatGT(LastSeenBy(Myself),0,MINORGLOBE)
    CheckStatGT(LastSeenBy(Myself),0,SHIELDGLOBE)
  !StateCheck(LastSeenBy(Myself),STATE_SLOWED)
  !StateCheck(LastSeenBy(Myself),STATE_STUNNED)
  !StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
  !StateCheck(LastSeenBy(Myself),STATE_SLEEPING)
  !StateCheck(LastSeenBy(Myself),STATE_SILENCED)
  !StateCheck(LastSeenBy(Myself),STATE_CONFUSED)
  !StateCheck(LastSeenBy(Myself),STATE_CHARMED)
  !StateCheck(LastSeenBy(Myself),STATE_FEEBLEMINDED)
  !CheckStatGT(LastSeenBy(Myself),0,WEB)
  !CheckStatGT(LastSeenBy(Myself),0,ENTANGLE)
  !CheckStatGT(LastSeenBy(Myself),0,HELD)
  !CheckStatGT(LastSeenBy(Myself),0,GREASE)
THEN
  RESPONSE #80
    SetGlobalTimer("Interrupt","LOCALS",1)
    EquipRanged()
    AttackOneRound(LastSeenBy(Myself))
  RESPONSE #20
    SetGlobalTimer("Interrupt","LOCALS",1)
    EquipMostDamagingMelee()
    AttackOneRound(LastSeenBy(Myself))
END

IF
  OR(2)
    !GlobalTimerNotExpired("invis","LOCALS")
    !StateCheck(Myself,STATE_INVISIBLE)
  OR(2)
    Allegiance(LastSeenBy(Myself),GOODCUTOFF)
    InParty(LastSeenBy(Myself))
  OR(3)
    GlobalTimerNotExpired("insects","LOCALS")
    Range(NearestEnemyOf(Myself),7)
    Global("CloseCombat","LOCALS",1)
  Range(LastSeenBy(Myself),13)
THEN
  RESPONSE #100
    EquipMostDamagingMelee()
    AttackOneRound(LastSeenBy(Myself))
END

IF
  OR(2)
    !GlobalTimerNotExpired("invis","LOCALS")
    !StateCheck(Myself,STATE_INVISIBLE)
  OR(2)
    Allegiance(LastSeenBy(Myself),GOODCUTOFF)
    InParty(LastSeenBy(Myself))
  OR(3)
    GlobalTimerNotExpired("insects","LOCALS")
    Range(NearestEnemyOf(Myself),7)
    Global("CloseCombat","LOCALS",1)
  !Range(LastSeenBy(Myself),13)
  !StateCheck(Myself,STATE_SLOWED)
THEN
  RESPONSE #40
    EquipMostDamagingMelee()
    AttackOneRound(NearestEnemyOf(Myself))
  RESPONSE #60
    EquipMostDamagingMelee()
    AttackOneRound(LastSeenBy(Myself))
END

IF
  OR(2)
    !GlobalTimerNotExpired("invis","LOCALS")
    !StateCheck(Myself,STATE_INVISIBLE)
  OR(2)
    Allegiance(LastSeenBy(Myself),GOODCUTOFF)
    InParty(LastSeenBy(Myself))
THEN
  RESPONSE #100
    EquipMostDamagingMelee()
    AttackOneRound(NearestEnemyOf(Myself))
END

