IF
  Detect([GOODCUTOFF])
  Global("jarlcaveopen","GLOBAL",0)
THEN
  RESPONSE #100
    ApplySpell(NearestEnemyOf(Myself),WIZARD_SPIDER_SPAWN)
    ApplySpell(NearestEnemyOf(Myself),WIZARD_SPIDER_SPAWN)
    ApplySpell(NearestEnemyOf(Myself),WIZARD_SPIDER_SPAWN)
    SetGlobal("jarlcaveopen","GLOBAL",1)
END

IF
  HaveSpellRES("SPSHAD2")
  !StateCheck(Myself,STATE_INVISIBLE)
  !StateCheck(Myself,STATE_IMPROVEDINVISIBILITY)
  RandomNumLT(3,3)
THEN
  RESPONSE #100
    SpellRES("SPSHAD2",Myself)  // ~Shadow Door~
END

IF
  Detect([GOODCUTOFF])
  Global("jarlcaveprep","GLOBAL",0)
THEN
  RESPONSE #100
    ApplySpell(Myself,WIZARD_MANTLE)
    ReallyForceSpell(Myself,WIZARD_STONE_SKIN)
    SetGlobalTimer("spiders","GLOBAL",10)
    SetGlobal("jarlcaveprep","GLOBAL",1)
END

IF
  Global("cavejarldie","GLOBAL",0)
  HPLT(Myself,50)
THEN
  RESPONSE #100
    ReallyForceSpell(Myself,CLERIC_CURE_CRITICAL_WOUNDS)
    ReallyForceSpell(Myself,CLERIC_CURE_CRITICAL_WOUNDS)
    SetGlobal("cavejarldie","GLOBAL",1)
END

IF
  Detect([GOODCUTOFF])
  Global("jarlcaveprep","GLOBAL",1)
  GlobalTimerExpired("spiders","GLOBAL")
THEN
  RESPONSE #100
    ReallyForceSpell(NearestEnemyOf(Myself),WIZARD_SPIDER_SPAWN)
    ApplySpell(Myself,WIZARD_STONE_SKIN)
    SetGlobal("jarlcaveprep","GLOBAL",2)
    SetGlobalTimer("spiders","GLOBAL",17)
END

IF
  Detect([GOODCUTOFF])
  Global("jarlcaveprep","GLOBAL",2)
  GlobalTimerExpired("spiders","GLOBAL")
THEN
  RESPONSE #100
    ReallyForceSpell(NearestEnemyOf(Myself),WIZARD_SPIDER_SPAWN)
    SetGlobal("jarlcaveprep","GLOBAL",3)
END

IF
  Detect([GOODCUTOFF])
  Global("jarlcaveprep","GLOBAL",3)
THEN
  RESPONSE #100
    ForceSpell(NearestEnemyOf(Myself),WIZARD_DISINTEGRATE)
    SetGlobal("jarlcaveprep","GLOBAL",4)
END

IF
  GlobalLT("BHands","LOCALS",3)
  Range(NearestEnemyOf(Myself),5)
  RandomNum(2,1)
THEN
  RESPONSE #100
    ForceSpell(NearestEnemyOf(Myself),WIZARD_BURNING_HANDS)  // ~Burning Hands~
END

IF
  GlobalGT("jarlcaveprep","GLOBAL",3)
  See(NearestEnemyOf(Myself))
  !Range(NearestEnemyOf(Myself),15)
THEN
  RESPONSE #100
    EquipRanged()
    Attack(NearestEnemyOf(Myself))
END

IF
  GlobalGT("jarlcaveprep","GLOBAL",3)
  See(NearestEnemyOf(Myself))
  Range(NearestEnemyOf(Myself),15)
THEN
  RESPONSE #100
    EquipMostDamagingMelee()
    Attack(NearestEnemyOf(Myself))
END

