IF
  HPPercentLT(Myself,50)
  Global("KR_CONT_FIRED","LOCALS",0)
THEN
  RESPONSE #100
    DisplayString(Myself,25942)  // ~Contingency~
    SetGlobal("KR_CONT_FIRED","LOCALS",1)
    ApplySpell(Myself,WIZARD_MISLEAD)
END

IF
  See(NearestEnemyOfType([GOODCUTOFF.0.0.LONG_BOW]))
  OR(2)
    CheckStatGT(LastSeenBy(Myself),35,RESISTMAGIC)
    HasBounceEffects(LastSeenBy(Myself))
  Global("KR_CHAIN_CONT_FIRED","LOCALS",0)
THEN
  RESPONSE #100
    DisplayString(Myself,26328)  // ~Chain Contingency~
    ReallyForceSpell(LastSeenBy(Myself),WIZARD_PIERCE_SHIELD)
    ReallyForceSpell(LastSeenBy(Myself),WIZARD_PIERCE_SHIELD)
    ReallyForceSpell(LastSeenBy(Myself),WIZARD_PIERCE_SHIELD)
    SetGlobal("KR_CHAIN_CONT_FIRED","LOCALS",0)
END

IF
  See(NearestEnemyOfType([GOODCUTOFF.0.0.LONG_BOW]))
  CheckStatGT(LastSeenBy(Myself),35,RESISTMAGIC)
  Global("KR_SPELL_SEQ_FIRED","LOCALS",0)
THEN
  RESPONSE #100
    DisplayString(Myself,39969)  // ~Spell Sequencer - Fired~
    ReallyForceSpell(LastSeenBy(Myself),WIZARD_PIERCE_SHIELD)
    SetGlobal("KR_SPELL_SEQ_FIRED","LOCALS",1)
END

IF
  See(NearestEnemyOfType([GOODCUTOFF]))
  CheckStatGT(LastSeenBy(Myself),35,RESISTMAGIC)
  Global("KR_SPELL_SEQ_FIRED","LOCALS",0)
THEN
  RESPONSE #100
    DisplayString(Myself,39969)  // ~Spell Sequencer - Fired~
    ReallyForceSpell(LastSeenBy(Myself),WIZARD_PIERCE_SHIELD)
    SetGlobal("KR_SPELL_SEQ_FIRED","LOCALS",1)
END

IF
  See(TenthNearestEnemyOfType([GOODCUTOFF]))
  CheckStatGT(LastSeenBy(Myself),35,RESISTMAGIC)
  Global("KR_SPELL_SEQ_FIRED","LOCALS",0)
THEN
  RESPONSE #100
    DisplayString(Myself,39969)  // ~Spell Sequencer - Fired~
    ReallyForceSpell(LastSeenBy(Myself),WIZARD_PIERCE_SHIELD)
    SetGlobal("KR_SPELL_SEQ_FIRED","LOCALS",1)
END

IF
  OR(4)
    See(NearestEnemyOfType([GOODCUTOFF]))
    See(NearestEnemyOfType([GOODCUTOFF.0.0.BARD_ALL]))
    See(NearestEnemyOfType([GOODCUTOFF.0.0.CLERIC_ALL]))
    See(NearestEnemyOfType([GOODCUTOFF.0.0.LONG_BOW]))
  Global("KR_SPELL_TRIG","LOCALS",0)
THEN
  RESPONSE #100
    SetGlobal("KR_SPELL_TRIG","LOCALS",1)
    DisplayString(Myself,39968)  // ~Spell Trigger - Fired~
    ReallyForceSpell("KRGNOME",WIZARD_IMPROVED_HASTE)
    ApplySpell(Myself,WIZARD_STONE_SKIN)
    ApplySpell(Myself,WIZARD_MIRROR_IMAGE)
END

IF
  RandomNumGT(4,2)
  Global("KR_OFFENSIVE_TIME","LOCALS",0)
THEN
  RESPONSE #100
    SetGlobal("KR_OFFENSIVE_TIME","LOCALS",1)
    SetGlobal("KR_DEFENSIVE_TIME","LOCALS",0)
END

IF
  RandomNumLT(4,2)
  Global("KR_DEFENSIVE_TIME","LOCALS",0)
THEN
  RESPONSE #100
    SetGlobal("KR_DEFENSIVE_TIME","LOCALS",1)
    SetGlobal("KR_OFFENSIVE_TIME","LOCALS",0)
END

IF
  Global("KR_DEFENSIVE_TIME","LOCALS",1)
  !HasItem("Melfmet",Myself)  // ~Melf's Minute Meteor~
  HaveSpell(WIZARD_MELF_METEOR)
THEN
  RESPONSE #100
    SetGlobal("KR_DEFENSIVE_TIME","LOCALS",0)
    Spell(Myself,WIZARD_MELF_METEOR)
    Continue()
END

IF
  Global("KR_OFFENSIVE_TIME","LOCALS",1)
  See(NearestEnemyOfType([GOODCUTOFF.0.0.LONG_BOW]))
  HaveSpell(WIZARD_PIERCE_SHIELD)
  OR(2)
    CheckStatGT(LastSeenBy(Myself),35,RESISTMAGIC)
    HasBounceEffects(LastSeenBy(Myself))
THEN
  RESPONSE #100
    SetGlobal("KR_OFFENSIVE_TIME","LOCALS",0)
    Spell(LastSeenBy(Myself),WIZARD_PIERCE_SHIELD)
END

IF
  Global("KR_OFFENSIVE_TIME","LOCALS",1)
  See(NearestEnemyOfType([GOODCUTOFF]))
  HaveSpell(WIZARD_PIERCE_SHIELD)
  OR(2)
    HasBounceEffects(LastSeenBy(Myself))
    CheckStatGT(LastSeenBy(Myself),35,RESISTMAGIC)
THEN
  RESPONSE #100
    SetGlobal("KR_OFFENSIVE_TIME","LOCALS",0)
    Spell(LastSeenBy(Myself),WIZARD_PIERCE_SHIELD)
END

IF
  Global("KR_OFFENSIVE_TIME","LOCALS",1)
  See(NearestEnemyOfType([GOODCUTOFF.0.0.LONG_BOW]))
  HaveSpell(WIZARD_SPELL_THRUST)
THEN
  RESPONSE #100
    SetGlobal("KR_OFFENSIVE_TIME","LOCALS",0)
    Spell(LastSeenBy(Myself),WIZARD_SPELL_THRUST)
    Continue()
END

IF
  Global("KR_OFFENSIVE_TIME","LOCALS",1)
  See(SecondNearestEnemyOfType([GOODCUTOFF.0.0.LONG_BOW]))
  HaveSpell(WIZARD_SECRET_WORD)
THEN
  RESPONSE #100
    SetGlobal("KR_OFFENSIVE_TIME","LOCALS",0)
    Spell(LastSeenBy(Myself),WIZARD_SECRET_WORD)
END

IF
  Global("KR_OFFENSIVE_TIME","LOCALS",1)
  See(ThirdNearestEnemyOfType([GOODCUTOFF.0.0.LONG_BOW]))
  HaveSpell(WIZARD_BREACH)
THEN
  RESPONSE #100
    SetGlobal("KR_OFFENSIVE_TIME","LOCALS",0)
    Spell(LastSeenBy(Myself),WIZARD_BREACH)
    Continue()
END

IF
  Global("KR_OFFENSIVE_TIME","LOCALS",1)
  See(SecondNearestEnemyOfType([GOODCUTOFF.0.0.LONG_BOW]))
  HaveSpell(WIZARD_BREACH)
THEN
  RESPONSE #100
    SetGlobal("KR_OFFENSIVE_TIME","LOCALS",0)
    Spell(LastSeenBy(Myself),WIZARD_BREACH)
    Continue()
END

IF
  Global("KR_OFFENSIVE_TIME","LOCALS",1)
  See(NearestEnemyOfType([GOODCUTOFF.0.0.LONG_BOW]))
  HaveSpell(WIZARD_BREACH)
THEN
  RESPONSE #100
    SetGlobal("KR_OFFENSIVE_TIME","LOCALS",0)
    Spell(LastSeenBy(Myself),WIZARD_BREACH)
    Continue()
END

IF
  Global("KR_OFFENSIVE_TIME","LOCALS",1)
  See(SecondNearestEnemyOfType([GOODCUTOFF.0.0.LONG_BOW]))
  HaveSpell(WIZARD_WARDING_WHIP)
THEN
  RESPONSE #100
    SetGlobal("KR_OFFENSIVE_TIME","LOCALS",0)
    Spell(LastSeenBy(Myself),WIZARD_WARDING_WHIP)
    Continue()
END

IF
  Global("KR_OFFENSIVE_TIME","LOCALS",1)
  See(ThirdNearestEnemyOfType([GOODCUTOFF.0.0.LONG_BOW]))
  HaveSpell(WIZARD_WARDING_WHIP)
THEN
  RESPONSE #100
    SetGlobal("KR_OFFENSIVE_TIME","LOCALS",0)
    Spell(LastSeenBy(Myself),WIZARD_WARDING_WHIP)
END

IF
  Global("KR_OFFENSIVE_TIME","LOCALS",1)
  See(NearestEnemyOfType([GOODCUTOFF.0.0.LONG_BOW]))
  HaveSpell(WIZARD_RUBY_RAY_OF_REVERSAL)
THEN
  RESPONSE #100
    SetGlobal("KR_OFFENSIVE_TIME","LOCALS",0)
    Spell(LastSeenBy(Myself),WIZARD_RUBY_RAY_OF_REVERSAL)
    Continue()
END

IF
  Global("KR_DEFENSIVE_TIME","LOCALS",1)
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_SPIDER_SPAWN)
THEN
  RESPONSE #100
    SetGlobal("KR_DEFENSIVE_TIME","LOCALS",0)
    Spell(LastSeenBy(Myself),WIZARD_SPIDER_SPAWN)
END

IF
  Global("KR_OFFENSIVE_TIME","LOCALS",1)
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_WEB)
THEN
  RESPONSE #100
    SetGlobal("KR_OFFENSIVE_TIME","LOCALS",0)
    Spell(LastSeenBy(Myself),WIZARD_WEB)
END

IF
  Global("KR_DEFENSIVE_TIME","LOCALS",1)
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_INVISIBLE_STALKER)
THEN
  RESPONSE #100
    SetGlobal("KR_DEFENSIVE_TIME","LOCALS",0)
    Spell(LastSeenBy(Myself),WIZARD_INVISIBLE_STALKER)
END

IF
  Global("KR_OFFENSIVE_TIME","LOCALS",1)
  See(StrongestOf(NearestEnemyOf(Myself)))
  HaveSpell(WIZARD_GREATER_MALISON)
  HaveSpell(WIZARD_RAY_OF_ENFEEBLEMENT)
THEN
  RESPONSE #100
    SetGlobal("KR_OFFENSIVE_TIME","LOCALS",0)
    Spell(LastSeenBy(Myself),WIZARD_GREATER_MALISON)
    Spell(LastSeenBy(Myself),WIZARD_RAY_OF_ENFEEBLEMENT)
END

IF
  Global("KR_OFFENSIVE_TIME","LOCALS",1)
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_STINKING_CLOUD)
THEN
  RESPONSE #100
    SetGlobal("KR_OFFENSIVE_TIME","LOCALS",0)
    Spell(LastSeenBy(Myself),WIZARD_STINKING_CLOUD)
END

IF
  Global("KR_OFFENSIVE_TIME","LOCALS",1)
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_GREASE)
THEN
  RESPONSE #100
    SetGlobal("KR_OFFENSIVE_TIME","LOCALS",0)
    Spell(LastSeenBy(Myself),WIZARD_GREASE)
END

IF
  Global("KR_OFFENSIVE_TIME","LOCALS",1)
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_BLINDNESS)
THEN
  RESPONSE #100
    SetGlobal("KR_OFFENSIVE_TIME","LOCALS",0)
    Spell(LastSeenBy(Myself),WIZARD_BLINDNESS)
END

IF
  OR(4)
    See(NearestEnemyOfType([GOODCUTOFF.0.0.LONG_BOW]))
    See(NearestEnemyOfType([GOODCUTOFF.0.0.CLERIC_ALL]))
    See(NearestEnemyOfType([GOODCUTOFF.0.0.BARD_ALL]))
    See(NearestEnemyOfType([GOODCUTOFF]))
  Global("KR_OFFENSIVE_TIME","LOCALS",1)
  HasItem("Melfmet",Myself)  // ~Melf's Minute Meteor~
THEN
  RESPONSE #100
    SetGlobal("KR_OFFENSIVE_TIME","LOCALS",0)
    SetGlobal("KR_DEFENSIVE_TIME","LOCALS",0)
    Attack(LastSeenBy(Myself))
END

IF
  OR(3)
    Global("KR_OFFENSIVE_TIME","LOCALS",1)
    Global("KR_DEFENSIVE_TIME","LOCALS",1)
    Global("NOT_BEEN_HERE","LOCALS",0)
THEN
  RESPONSE #100
    SetGlobal("NOT_BEEN_HERE","LOCALS",0)
    SetGlobal("KR_OFFENSIVE_TIME","LOCALS",0)
    SetGlobal("KR_DEFENSIVE_TIME","LOCALS",0)
END

