IF
  See(NearestEnemyOf(Myself))
  Global("Prepare","LOCALS",0)
  !Dead("d0magcle")
THEN
  RESPONSE #100
    ReallyForceSpell(Myself,WIZARD_IMPROVED_MANTLE)
    ReallyForceSpell(Myself,WIZARD_STONE_SKIN)
    SetGlobal("Prepare","LOCALS",1)
END

IF
  See(NearestEnemyOf(Myself))
  Global("SpellTrigger","LOCALS",0)
  !Dead("d0magcle")
THEN
  RESPONSE #100
    DisplayString(Myself,39968) // Spell Trigger - Fired
    DisplayString(Myself,43046) // Spell Trigger - Mislead
    ReallyForceSpell(Myself,WIZARD_MISLEAD)
    DisplayString(Myself,43047) // Spell Trigger - Fire Shield Red
    ReallyForceSpell(Myself,WIZARD_FIRE_SHIELD_RED)
    DisplayString(Myself,40245) // Spell Trigger - Globe of Invulnerability
    ReallyForceSpell(Myself,WIZARD_GLOBE_OF_INVULNERABILITY)
    ReallyForceSpell(Myself,WIZARD_PHANTOM_BLADE)
    SetGlobal("SpellTrigger","LOCALS",1)
END

IF
  !GlobalTimerNotExpired("CAST","LOCALS")
  See(NearestEnemyOf(Myself))
  StateCheck(Myself,STATE_SILENCED)
  HaveSpell(WIZARD_VOCALIZE)
THEN
  RESPONSE #100
    SetGlobalTimer("CAST","LOCALS",6)
    Spell(Myself,WIZARD_VOCALIZE)
END

IF
  !GlobalTimerNotExpired("CAST","LOCALS")
  Allegiance(Myself,ENEMY)
  Detect([PC])
  !See(LastSeenBy(Myself))
  HaveSpell(WIZARD_TRUE_SIGHT)
THEN
  RESPONSE #100
    SetGlobalTimer("CAST","LOCALS",6)
    Spell(Myself,WIZARD_TRUE_SIGHT)
END

IF
  !GlobalTimerNotExpired("CAST","LOCALS")
  Allegiance(Myself,ENEMY)
  Detect([PC])
  !See(LastSeenBy(Myself))
  !HaveSpell(WIZARD_TRUE_SIGHT)
  Delay(10)
THEN
  RESPONSE #100
    SetGlobalTimer("CAST","LOCALS",6)
    ReallyForceSpell(Myself,WIZARD_TRUE_SIGHT)
END

IF
  !GlobalTimerNotExpired("CAST","LOCALS")
  See(NearestEnemyOf(Myself))
  Global("Prepare","LOCALS",1)
  !Dead("d0magcle")
THEN
  RESPONSE #100
    SetGlobalTimer("CAST","LOCALS",6)
    Spell(Myself,WIZARD_SPELL_TURNING)
    SetGlobal("Prepare","LOCALS",2)
END

IF
  !GlobalTimerNotExpired("CAST","LOCALS")
  See(NearestEnemyOf(Myself))
  !HasBounceEffects(Myself)
  !HasImmunityEffects(Myself)
  HaveSpell(WIZARD_SPELL_TURNING)
  Allegiance(Myself,ENEMY)
THEN
  RESPONSE #100
    SetGlobalTimer("CAST","LOCALS",6)
    Spell(Myself,WIZARD_SPELL_TURNING)
END

IF
  See(NearestEnemyOf(Myself))
  TookDamage()
  Global("Prepare2","LOCALS",0)
  !Dead("d0magcle")
THEN
  RESPONSE #100
    DisplayString(Myself,43050) // Chain Contingency - Improved Mantle
    ReallyForceSpell(Myself,WIZARD_IMPROVED_MANTLE)
    DisplayString(Myself,3302) // Chain Contingency - Spell Turning
    ReallyForceSpell(Myself,WIZARD_SPELL_TURNING)
    DisplayString(Myself,40240) // Chain Contingency - Mislead
    ReallyForceSpell(Myself,WIZARD_MISLEAD)
    SetGlobal("Prepare2","LOCALS",1)
END

IF
  See(NearestEnemyOf(Myself))
  TookDamage()
  Global("Prepare2","LOCALS",1)
  !Dead("d0magcle")
THEN
  RESPONSE #100
    DisplayString(Myself,40252) // Contingency - Protection from Magical Weapons
    ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    SetGlobal("Prepare2","LOCALS",2)
END

IF
  See(NearestEnemyOf(Myself))
  See([GOODCUTOFF.0.0.0.0.SUMMONED])
  Global("Summon","LOCALS",0)
THEN
  RESPONSE #100
    FaceObject(LastSeenBy(Myself))
    ReallyForceSpell(LastSeenBy(Myself),WIZARD_DEATH_SPELL)
    SetGlobal("Summon","LOCALS",1)
END

IF
  !GlobalTimerNotExpired("CAST","LOCALS")
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_TIME_STOP)
THEN
  RESPONSE #100
    SetGlobalTimer("CAST","LOCALS",6)
    Spell(Myself,WIZARD_TIME_STOP)
END

IF
  !GlobalTimerNotExpired("CAST","LOCALS")
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_NPC_SYMBOL_STUN)
  RandomNumGT(4,2)
THEN
  RESPONSE #100
    SetGlobalTimer("CAST","LOCALS",6)
    Spell(NearestEnemyOf(Myself),WIZARD_NPC_SYMBOL_STUN)
END

IF
  !GlobalTimerNotExpired("CAST","LOCALS")
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_NPC_SYMBOL_FEAR)
  RandomNumGT(6,3)
THEN
  RESPONSE #100
    SetGlobalTimer("CAST","LOCALS",6)
    Spell(NearestEnemyOf(Myself),WIZARD_NPC_SYMBOL_FEAR)
END

IF
  !GlobalTimerNotExpired("CAST","LOCALS")
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_WAIL_OF_THE_BANSHEE)
  RandomNumGT(7,3)
THEN
  RESPONSE #100
    SetGlobalTimer("CAST","LOCALS",6)
    Spell(NearestEnemyOf(Myself),WIZARD_WAIL_OF_THE_BANSHEE)
END

IF
  !GlobalTimerNotExpired("CAST","LOCALS")
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_SUN_FIRE)
  RandomNumGT(3,1)
THEN
  RESPONSE #100
    SetGlobalTimer("CAST","LOCALS",6)
    Spell(NearestEnemyOf(Myself),WIZARD_SUN_FIRE)
END

IF
  !GlobalTimerNotExpired("CAST","LOCALS")
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_ABI_DALZIMS_HORRID_WILTING)
THEN
  RESPONSE #100
    SetGlobalTimer("CAST","LOCALS",6)
    Spell(NearestEnemyOf(Myself),WIZARD_ABI_DALZIMS_HORRID_WILTING)
END

IF
  !GlobalTimerNotExpired("CAST","LOCALS")
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_FINGER_OF_DEATH)
  RandomNumGT(8,1)
THEN
  RESPONSE #100
    SetGlobalTimer("CAST","LOCALS",6)
    Spell(NearestEnemyOf(Myself),WIZARD_FINGER_OF_DEATH)
END

IF
  !GlobalTimerNotExpired("CAST","LOCALS")
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_PRISMATIC_SPRAY)
  RandomNumGT(7,4)
THEN
  RESPONSE #100
    SetGlobalTimer("CAST","LOCALS",6)
    Spell(NearestEnemyOf(Myself),WIZARD_PRISMATIC_SPRAY)
END

IF
  !GlobalTimerNotExpired("CAST","LOCALS")
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_SUMMON_EFREET)
  RandomNumGT(9,6)
THEN
  RESPONSE #100
    SetGlobalTimer("CAST","LOCALS",6)
    Spell(Myself,WIZARD_SUMMON_EFREET)
END

IF
  !GlobalTimerNotExpired("CAST","LOCALS")
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_MAZE)
  RandomNumGT(9,7)
THEN
  RESPONSE #100
    SetGlobalTimer("CAST","LOCALS",6)
    Spell(NearestEnemyOf(Myself),WIZARD_MAZE)
END

IF
  !GlobalTimerNotExpired("CAST","LOCALS")
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_FLESH_TO_STONE)
  RandomNumGT(10,4)
THEN
  RESPONSE #100
    SetGlobalTimer("CAST","LOCALS",6)
    Spell(NearestEnemyOf(Myself),WIZARD_FLESH_TO_STONE)
END

IF
  !GlobalTimerNotExpired("CAST","LOCALS")
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_DISINTEGRATE)
  RandomNumGT(10,1)
THEN
  RESPONSE #100
    SetGlobalTimer("CAST","LOCALS",6)
    Spell(NearestEnemyOf(Myself),WIZARD_DISINTEGRATE)
END

IF
  !GlobalTimerNotExpired("CAST","LOCALS")
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_DOMINATION)
  RandomNumGT(6,2)
THEN
  RESPONSE #100
    SetGlobalTimer("CAST","LOCALS",6)
    Spell(NearestEnemyOf(Myself),WIZARD_DOMINATION)
END

IF
  HPPercentLT(Myself,25)
  HPGT(Myself,1)
  !Dead("d0magcle")
  Global("Whined","LOCALS",0)
  See(NearestMyGroupOfType)
  Allegiance(Myself,ENEMY)
THEN
  RESPONSE #100
    SetGlobal("Whined","LOCALS",1)
    Shout(153)
    DisplayStringHead(Myself,46151) // help!
END

IF
  See(NearestEnemyOf(Myself))
  !Range(LastSeenBy(Myself),5)
THEN
  RESPONSE #100
    EquipRanged()
    AttackReevaluate(LastSeenBy(Myself),30)
END

IF
  See(NearestEnemyOf(Myself))
  Range(LastSeenBy(Myself),5)
THEN
  RESPONSE #100
    EquipMostDamagingMelee()
    AttackReevaluate(LastSeenBy(Myself),30)
END
