IF
  Global("Seen","LOCALS",0)
  !Allegiance(Myself,GOODCUTOFF)
  OR(2)
    Detect([GOODCUTOFF])
    HitBy([GOODCUTOFF],CRUSHING)
THEN
  RESPONSE #100
    SetGlobal("Seen","LOCALS",1)
END

IF
  Global("Seen","LOCALS",0)
  !Allegiance(Myself,GOODCUTOFF)
  OR(2)
    AttackedBy([ANYONE],DEFAULT)
    HitBy([ANYONE],CRUSHING)
THEN
  RESPONSE #100
    RunAwayFrom(LastAttackerOf(Myself),15)
END

IF
  Global("Seen","LOCALS",0)
  !Allegiance(Myself,GOODCUTOFF)
  Range(NearestEnemyOf(Myself),10)
THEN
  RESPONSE #100
    RunAwayFrom(NearestEnemyOf(Myself),15)
END

IF
  Global("Seen","LOCALS",0)
  !Allegiance(Myself,GOODCUTOFF)
THEN
  RESPONSE #100
    RandomWalkContinuous()
END

IF
  ActionListEmpty()
  OR(2)
    Allegiance(Myself,GOODCUTOFF)
    Global("Seen","LOCALS",0)
THEN
  RESPONSE #100
    NoAction()
END

IF
  OR(2)
    Allegiance(Myself,GOODCUTOFF)
    Global("Seen","LOCALS",0)
THEN
  RESPONSE #100
END

IF
  See(NearestEnemyOf(Myself))
  Global("TimerPrep","LOCALS",0)
THEN
  RESPONSE #100
    SetGlobal("TimerPrep","LOCALS",1)
    SetGlobalTimer("DrankPotionTimer","LOCALS",0)
    SetGlobalTimer("CalledForHealing","LOCALS",0)
    SetGlobalTimer("GaveAwayPotion","LOCALS",0)
    SetGlobalTimer("TrueSight_Used","LOCALS",0)
    SetGlobalTimer("SpecialDefenseUp","LOCALS",0)
    SetGlobalTimer("SpellDefense1_On","LOCALS",0)
    SetGlobalTimer("WeaponDefense_On","LOCALS",0)
    SetGlobalTimer("FireShield_On","LOCALS",0)
    SetGlobalTimer("Shield_On","LOCALS",0)
    SetGlobalTimer("TeleportField_On","LOCALS",0)
END

IF
  See(NearestEnemyOf(Myself))
  !Global("ShoutedAlert","LOCALS",0)
THEN
  RESPONSE #100
    SetGlobal("ShoutedAlert","LOCALS",1)
    Shout(125)
    Continue()
END

IF
  !See(NearestEnemyOf(Myself))
  Heard(NearestMyGroupOfType,0)
  ActionListEmpty()
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    MoveToObject(LastHeardBy(Myself))
    SetInterrupt(TRUE)
    MoveToOffset([0.-4])
    FaceObject(LastHeardBy(Myself))
END

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

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

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  Detect(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_TRUE_SIGHT)
  OR(2)
    !See(NearestEnemyOf(Myself))
    StateCheck(NearestEnemyOf(Myself),STATE_MIRRORIMAGE)
  !GlobalTimerNotExpired("TrueSight_Used","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    SetGlobalTimer("TrueSight_Used","LOCALS",60)
    Spell(Myself,WIZARD_TRUE_SIGHT)
END

IF
  GlobalTimerExpired("SpecialDefenseUp","LOCALS")
THEN
  RESPONSE #100
    IncrementGlobal("NumDefenses","LOCALS",-1)
    Continue()
END

IF
  GlobalTimerExpired("SpellDefense1_On","LOCALS")
THEN
  RESPONSE #100
    IncrementGlobal("NumDefenses","LOCALS",-1)
    Continue()
END

IF
  GlobalTimerExpired("FireShield_On","LOCALS")
THEN
  RESPONSE #100
    IncrementGlobal("NumDefenses","LOCALS",-1)
    Continue()
END

IF
  OR(9)
    SpellCastOnMe([GOODCUTOFF],2302) // WIZARD_REMOVE_MAGIC
    SpellCastOnMe([GOODCUTOFF],2326) // WIZARD_TRUE_DISPEL_MAGIC
    SpellCastOnMe([GOODCUTOFF],CLERIC_DISPEL_MAGIC)
    SpellCastOnMe([GOODCUTOFF],WIZARD_BREACH)
    SpellCastOnMe([GOODCUTOFF],WIZARD_PIERCE_MAGIC)
    SpellCastOnMe([GOODCUTOFF],WIZARD_WARDING_WHIP)
    SpellCastOnMe([GOODCUTOFF],WIZARD_RUBY_RAY_OF_REVERSAL)
    SpellCastOnMe([GOODCUTOFF],WIZARD_SPELL_STRIKE)
    SpellCastOnMe([GOODCUTOFF],INQUIS_DISPEL_MAGIC)
  OR(6)
    GlobalTimerNotExpired("SpecialDefenseUp","LOCALS")
    GlobalTimerNotExpired("SpellDefense1_On","LOCALS")
    GlobalTimerNotExpired("WeaponDefense_On","LOCALS")
    GlobalTimerNotExpired("FireShield_On","LOCALS")
    GlobalTimerNotExpired("Shield_On","LOCALS")
    GlobalGT("NumDefenses","LOCALS",0)
THEN
  RESPONSE #100
    SetGlobal("NumDefenses","LOCALS",0)
    SetGlobalTimer("SpecialDefenseUp","LOCALS",0)
    SetGlobalTimer("SpellDefense1_On","LOCALS",0)
    SetGlobalTimer("WeaponDefense_On","LOCALS",0)
    SetGlobalTimer("FireShield_On","LOCALS",0)
    SetGlobalTimer("Shield_On","LOCALS",0)
END

IF
  SpellCastOnMe([GOODCUTOFF],WIZARD_TRUE_SIGHT)
  SpellCastOnMe([GOODCUTOFF],CLERIC_TRUE_SIGHT)
  SpellCastOnMe([GOODCUTOFF],INQUIS_TRUE_SIGHT)
  GlobalTimerNotExpired("SpecialDefenseUp","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("SpecialDefenseUp","LOCALS",0)
    IncrementGlobal("NumDefenses","LOCALS",-1)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_SHADOW_DOOR)
  !StateCheck(Myself,STATE_INVISIBLE)
  !StateCheck(Myself,STATE_IMPROVEDINVISIBILITY)
  !StateCheck(Myself,STATE_POISONED)
  !GlobalTimerNotExpired("SpecialDefenseUp","LOCALS")
  GlobalLT("NumDefenses","LOCALS",2)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    SetGlobalTimer("SpecialDefenseUp","LOCALS",54)
    IncrementGlobal("NumDefenses","LOCALS",1)
    Spell(Myself,WIZARD_SHADOW_DOOR)
    Continue()
END

IF
  !HasBounceEffects(Myself)
  !HasImmunityEffects(Myself)
  !CheckStatGT(Myself,0,MINORGLOBE)
  GlobalTimerNotExpired("SpellDefense1_On","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("SpellDefense1_On","LOCALS",0)
    Continue()
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_SPELL_TRAP)
  !GlobalTimerNotExpired("SpellDefense1_On","LOCALS")
  GlobalLT("NumDefenses","LOCALS",2)
  OR(5)
    See(NearestEnemyOfType([0.0.0.DRUID_ALL]))
    See(NearestEnemyOfType([0.0.0.BARD_ALL]))
    See(NearestEnemyOfType([0.0.0.CLERIC_ALL]))
    See(NearestEnemyOfType([0.0.0.MAGE_ALL]))
    See(NearestEnemyOfType([0.0.0.SORCERER]))
  !CheckStatGT(Myself,0,MINORGLOBE)
  !HasBounceEffects(Myself)
  !HasImmunityEffects(Myself)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    SetGlobalTimer("SpellDefense1_On","LOCALS",30)
    IncrementGlobal("NumDefenses","LOCALS",1)
    Spell(Myself,WIZARD_SPELL_TRAP)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_SPELL_TURNING)
  !GlobalTimerNotExpired("SpellDefense1_On","LOCALS")
  GlobalLT("NumDefenses","LOCALS",2)
  OR(5)
    See(NearestEnemyOfType([0.0.0.DRUID_ALL]))
    See(NearestEnemyOfType([0.0.0.BARD_ALL]))
    See(NearestEnemyOfType([0.0.0.CLERIC_ALL]))
    See(NearestEnemyOfType([0.0.0.MAGE_ALL]))
    See(NearestEnemyOfType([0.0.0.SORCERER]))
  !CheckStatGT(Myself,0,MINORGLOBE)
  !HasBounceEffects(Myself)
  !HasImmunityEffects(Myself)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    SetGlobalTimer("SpellDefense1_On","LOCALS",30)
    IncrementGlobal("NumDefenses","LOCALS",1)
    Spell(Myself,WIZARD_SPELL_TURNING)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_SPELL_DEFLECTION)
  !GlobalTimerNotExpired("SpellDefense1_On","LOCALS")
  GlobalLT("NumDefenses","LOCALS",2)
  OR(5)
    See(NearestEnemyOfType([0.0.0.DRUID_ALL]))
    See(NearestEnemyOfType([0.0.0.BARD_ALL]))
    See(NearestEnemyOfType([0.0.0.CLERIC_ALL]))
    See(NearestEnemyOfType([0.0.0.MAGE_ALL]))
    See(NearestEnemyOfType([0.0.0.SORCERER]))
  !CheckStatGT(Myself,0,MINORGLOBE)
  !HasBounceEffects(Myself)
  !HasImmunityEffects(Myself)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    SetGlobalTimer("SpellDefense1_On","LOCALS",30)
    IncrementGlobal("NumDefenses","LOCALS",1)
    Spell(Myself,WIZARD_SPELL_DEFLECTION)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_MINOR_SPELL_DEFLECTION)
  !GlobalTimerNotExpired("SpellDefense1_On","LOCALS")
  GlobalLT("NumDefenses","LOCALS",2)
  OR(5)
    See(NearestEnemyOfType([0.0.0.DRUID_ALL]))
    See(NearestEnemyOfType([0.0.0.BARD_ALL]))
    See(NearestEnemyOfType([0.0.0.CLERIC_ALL]))
    See(NearestEnemyOfType([0.0.0.MAGE_ALL]))
    See(NearestEnemyOfType([0.0.0.SORCERER]))
  !CheckStatGT(Myself,0,MINORGLOBE)
  !HasBounceEffects(Myself)
  !HasImmunityEffects(Myself)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    SetGlobalTimer("SpellDefense1_On","LOCALS",30)
    IncrementGlobal("NumDefenses","LOCALS",1)
    Spell(Myself,WIZARD_MINOR_SPELL_DEFLECTION)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_GLOBE_OF_INVULNERABILITY)
  !GlobalTimerNotExpired("SpellDefense1_On","LOCALS")
  GlobalLT("NumDefenses","LOCALS",2)
  OR(5)
    See(NearestEnemyOfType([0.0.0.DRUID_ALL]))
    See(NearestEnemyOfType([0.0.0.BARD_ALL]))
    See(NearestEnemyOfType([0.0.0.CLERIC_ALL]))
    See(NearestEnemyOfType([0.0.0.MAGE_ALL]))
    See(NearestEnemyOfType([0.0.0.SORCERER]))
  !CheckStatGT(Myself,0,MINORGLOBE)
  !HasBounceEffects(Myself)
  !HasImmunityEffects(Myself)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    SetGlobalTimer("SpellDefense1_On","LOCALS",30)
    IncrementGlobal("NumDefenses","LOCALS",1)
    Spell(Myself,WIZARD_GLOBE_OF_INVULNERABILITY)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_MINOR_GLOBE_OF_INVULNERABILITY)
  !GlobalTimerNotExpired("SpellDefense1_On","LOCALS")
  GlobalLT("NumDefenses","LOCALS",2)
  OR(5)
    See(NearestEnemyOfType([0.0.0.DRUID_ALL]))
    See(NearestEnemyOfType([0.0.0.BARD_ALL]))
    See(NearestEnemyOfType([0.0.0.CLERIC_ALL]))
    See(NearestEnemyOfType([0.0.0.MAGE_ALL]))
    See(NearestEnemyOfType([0.0.0.SORCERER]))
  !CheckStatGT(Myself,0,MINORGLOBE)
  !HasBounceEffects(Myself)
  !HasImmunityEffects(Myself)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    SetGlobalTimer("SpellDefense1_On","LOCALS",30)
    IncrementGlobal("NumDefenses","LOCALS",1)
    Spell(Myself,WIZARD_MINOR_GLOBE_OF_INVULNERABILITY)
END

IF
  !HasImmunityEffects(Myself)
  GlobalTimerNotExpired("WeaponDefense_On","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("WeaponDefense_On","LOCALS",0)
    Continue()
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_ABSOLUTE_IMMUNITY)
  !GlobalTimerNotExpired("WeaponDefense_On","LOCALS")
  OR(2)
    Range(NearestEnemyOf(Myself),4)
    AttackedBy([GOODCUTOFF],DEFAULT)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    SetGlobalTimer("WeaponDefense_On","LOCALS",28)
    Spell(Myself,WIZARD_ABSOLUTE_IMMUNITY)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_IMPROVED_MANTLE)
  !GlobalTimerNotExpired("WeaponDefense_On","LOCALS")
  OR(2)
    Range(NearestEnemyOf(Myself),4)
    AttackedBy([GOODCUTOFF],DEFAULT)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    SetGlobalTimer("WeaponDefense_On","LOCALS",24)
    Spell(Myself,WIZARD_IMPROVED_MANTLE)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_MANTLE)
  !GlobalTimerNotExpired("WeaponDefense_On","LOCALS")
  OR(2)
    Range(NearestEnemyOf(Myself),4)
    AttackedBy([GOODCUTOFF],DEFAULT)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    SetGlobalTimer("WeaponDefense_On","LOCALS",24)
    Spell(Myself,WIZARD_MANTLE)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
  !GlobalTimerNotExpired("WeaponDefense_On","LOCALS")
  OR(2)
    Range(NearestEnemyOf(Myself),4)
    AttackedBy([GOODCUTOFF],DEFAULT)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    SetGlobalTimer("WeaponDefense_On","LOCALS",24)
    Spell(Myself,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  See(NearestEnemyOf(Myself))
  !GlobalTimerNotExpired("FireShield_On","LOCALS")
  GlobalLT("NumDefenses","LOCALS",2)
  HaveSpell(WIZARD_FIRE_SHIELD_RED)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    SetGlobalTimer("FireShield_On","LOCALS",60)
    IncrementGlobal("NumDefenses","LOCALS",1)
    Spell(Myself,WIZARD_FIRE_SHIELD_RED)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  See(NearestEnemyOf(Myself))
  !GlobalTimerNotExpired("FireShield_On","LOCALS")
  GlobalLT("NumDefenses","LOCALS",2)
  HaveSpell(WIZARD_FIRE_SHIELD_BLUE)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    SetGlobalTimer("FireShield_On","LOCALS",60)
    IncrementGlobal("NumDefenses","LOCALS",1)
    Spell(Myself,WIZARD_FIRE_SHIELD_BLUE)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_IMPROVED_INVISIBILITY)
  !StateCheck(Myself,STATE_INVISIBLE)
  !StateCheck(Myself,STATE_IMPROVEDINVISIBILITY)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(Myself,WIZARD_IMPROVED_INVISIBILITY)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_IMPROVED_HASTE)
  !StateCheck(Myself,STATE_HASTED)
  CheckStat(Myself,0,IMPROVEDHASTE)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(Myself,WIZARD_IMPROVED_HASTE)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  See(NearestEnemyOf(Myself))
  OR(2)
    CheckStatGT(Myself,0,IMPROVEDHASTE)
    StateCheck(Myself,0)
  HaveSpell(WIZARD_IMPROVED_HASTE)
  See(NearestMyGroupOfType)
  !StateCheck(LastSeenBy(Myself),STATE_HASTED)
  CheckStat(LastSeenBy(Myself),0,IMPROVEDHASTE)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_IMPROVED_HASTE)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_HASTE)
  !StateCheck(Myself,STATE_HASTED)
  CheckStat(Myself,0,IMPROVEDHASTE)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(Myself,WIZARD_HASTE)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  See(NearestEnemyOf(Myself))
  OR(2)
    CheckStatGT(Myself,0,IMPROVEDHASTE)
    StateCheck(Myself,STATE_HASTED)
  HaveSpell(WIZARD_HASTE)
  See(NearestMyGroupOfType)
  !StateCheck(LastSeenBy(Myself),STATE_HASTED)
  CheckStat(LastSeenBy(Myself),0,IMPROVEDHASTE)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_HASTE)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_STONE_SKIN)
  CheckStatLT(Myself,1,STONESKINS)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(Myself,WIZARD_STONE_SKIN)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_RESIST_FEAR)
  OR(4)
    SpellCast([GOODCUTOFF],WIZARD_HORROR)
    SpellCast([GOODCUTOFF],WIZARD_SYMBOL_FEAR)
    SpellCastPriest([GOODCUTOFF],CLERIC_SYMBOL_FEAR)
    SpellCastPriest([GOODCUTOFF],0)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    SetInterrupt(FALSE)
    Spell(Myself,WIZARD_RESIST_FEAR)
    SetInterrupt(TRUE)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_RESIST_FEAR)
  See(NearestMyGroupOfType)
  StateCheck(LastSeenBy(Myself),STATE_PANIC)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_RESIST_FEAR)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_SHIELD)
  !GlobalTimerNotExpired("Shield_On","LOCALS")
  OR(2)
    See(NearestEnemyOfType([0.0.0.MAGE_ALL]))
    See(NearestEnemyOfType([0.0.0.BARD_ALL]))
  OR(2)
    SpellCast([GOODCUTOFF],WIZARD_MAGIC_MISSILE)
    SpellCastOnMe([GOODCUTOFF],WIZARD_MAGIC_MISSILE)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    SetGlobalTimer("Shield_On","LOCALS",300)
    Spell(Myself,WIZARD_SHIELD)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_MIRROR_IMAGE)
  OR(5)
    Range([GOODCUTOFF.0.0.THIEF_ALL],10)
    Range([GOODCUTOFF.0.0.FIGHTER_ALL],10)
    Range([GOODCUTOFF.0.0.PALADIN],10)
    See([GOODCUTOFF.0.0.RANGER])
    HitBy([ANYONE],MISSILE)
  !StateCheck(Myself,STATE_MIRRORIMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(Myself,WIZARD_MIRROR_IMAGE)
END

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

IF
  NumCreatureGT([GOODCUTOFF],1)
  See(SecondNearestEnemyOf(Myself))
THEN
  RESPONSE #100
    Continue()
END

IF
  NumCreatureGT([GOODCUTOFF],2)
  See(ThirdNearestEnemyOf(Myself))
THEN
  RESPONSE #100
    Continue()
END

IF
  NumCreatureGT([GOODCUTOFF],3)
  See(FourthNearestEnemyOf(Myself))
THEN
  RESPONSE #100
    Continue()
END

IF
  NumCreatureGT([GOODCUTOFF],4)
  See(FifthNearestEnemyOf(Myself))
THEN
  RESPONSE #100
    Continue()
END

IF
  NumCreatureGT([GOODCUTOFF],5)
  See(SixthNearestEnemyOf(Myself))
THEN
  RESPONSE #100
    Continue()
END

IF
  OR(3)
    See(SecondNearestEnemyOfType([0.0.0.BARD]))
    See(SecondNearestEnemyOfType([0.0.0.DRUID_ALL]))
    See(SecondNearestEnemyOfType([0.0.0.CLERIC_ALL]))
THEN
  RESPONSE #100
    Continue()
END

IF
  OR(3)
    See(NearestEnemyOfType([0.0.0.BARD]))
    See(NearestEnemyOfType([0.0.0.DRUID_ALL]))
    See(NearestEnemyOfType([0.0.0.CLERIC_ALL]))
THEN
  RESPONSE #100
    Continue()
END

IF
  OR(2)
    See(ThirdNearestEnemyOfType([0.0.0.SORCERER]))
    See(ThirdNearestEnemyOfType([0.0.0.MAGE_ALL]))
THEN
  RESPONSE #100
    Continue()
END

IF
  OR(2)
    See(SecondNearestEnemyOfType([0.0.0.SORCERER]))
    See(SecondNearestEnemyOfType([0.0.0.MAGE_ALL]))
THEN
  RESPONSE #100
    Continue()
END

IF
  OR(2)
    See(NearestEnemyOfType([0.0.0.SORCERER]))
    See(NearestEnemyOfType([0.0.0.MAGE_ALL]))
THEN
  RESPONSE #100
    Continue()
END

IF
  Heard(NearestMyGroupOfType,0)
  !StateCheck(LastHeardBy(Myself),STATE_REALLY_DEAD)
  !StateCheck(LastAttackerOf(LastHeardBy(Myself)),STATE_INVISIBLE)
  !StateCheck(LastAttackerOf(LastHeardBy(Myself)),STATE_IMPROVEDINVISIBILITY)
  !StateCheck(LastAttackerOf(LastHeardBy(Myself)),STATE_CHARMED)
  !StateCheck(LastAttackerOf(LastHeardBy(Myself)),STATE_HELPLESS)
  !StateCheck(LastAttackerOf(LastHeardBy(Myself)),STATE_SLEEPING)
  !StateCheck(LastAttackerOf(LastHeardBy(Myself)),STATE_STUNNED)
  !StateCheck(LastAttackerOf(LastHeardBy(Myself)),STATE_CONFUSED)
  See(LastAttackerOf(LastHeardBy(Myself)))
THEN
  RESPONSE #100
    Continue()
END

IF
  Heard(NearestMyGroupOfType,0)
  See(LastHeardBy(Myself))
  !See(LastAttackerOf(LastHeardBy(Myself)))
  !StateCheck(LastHeardBy(Myself),STATE_REALLY_DEAD)
  !StateCheck(LastAttackerOf(LastHeardBy(Myself)),STATE_INVISIBLE)
  !StateCheck(LastAttackerOf(LastHeardBy(Myself)),STATE_IMPROVEDINVISIBILITY)
  !StateCheck(LastAttackerOf(LastHeardBy(Myself)),STATE_CHARMED)
  !StateCheck(LastAttackerOf(LastHeardBy(Myself)),STATE_HELPLESS)
  !StateCheck(LastAttackerOf(LastHeardBy(Myself)),STATE_SLEEPING)
  !StateCheck(LastAttackerOf(LastHeardBy(Myself)),STATE_STUNNED)
  !StateCheck(LastAttackerOf(LastHeardBy(Myself)),STATE_CONFUSED)
  !HPPercentLT(Myself,50)
  !Range(NearestEnemyOf(Myself),5)
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    MoveToObject(LastHeardBy(Myself))
    SetInterrupt(TRUE)
    MoveToOffset([0.-4])
    FaceObject(LastHeardBy(Myself))
END

IF
  AttackedBy([ANYONE],DEFAULT)
  See(LastAttackerOf(Myself))
THEN
  RESPONSE #100
    Continue()
END

IF
  Range(NearestEnemyOf(Myself),4)
  See(NearestEnemyOf(Myself))
THEN
  RESPONSE #100
    Continue()
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  Gender(LastSeenBy(Myself),SUMMONED)
  HaveSpell(WIZARD_DEATH_SPELL)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_DEATH_SPELL)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_POWER_WORD_KILL)
  RandomNum(2,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_POWER_WORD_KILL)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_SYMBOL_DEATH)
  !HasBounceEffects(LastSeenBy(Myself))
  !Range(LastSeenBy(Myself),5)
  RandomNum(2,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_SYMBOL_DEATH)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_SYMBOL_STUN)
  !StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
  !HasBounceEffects(LastSeenBy(Myself))
  !Range(LastSeenBy(Myself),5)
  RandomNum(2,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_SYMBOL_STUN)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_SYMBOL_FEAR)
  !HasBounceEffects(LastSeenBy(Myself))
  !Range(LastSeenBy(Myself),5)
  RandomNum(2,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_SYMBOL_FEAR)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_SPHERE_OF_CHAOS)
  Range(LastSeenBy(Myself),10)
  !StateCheck(LastSeenBy(Myself),STATE_CONFUSED)
  RandomNum(2,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(Myself,WIZARD_SPHERE_OF_CHAOS)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_POWER_WORD_SILENCE)
  OR(6)
    Class(LastSeenBy(Myself),DRUID_ALL)
    Class(LastSeenBy(Myself),BARD)
    Class(LastSeenBy(Myself),CLERIC_ALL)
    Class(LastSeenBy(Myself),MAGE_ALL)
    Class(LastSeenBy(Myself),SORCERER)
    InPartySlot(LastSeenBy(Myself),0)
  !HasBounceEffects(LastSeenBy(Myself))
  !StateCheck(LastSeenBy(Myself),STATE_SILENCED)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_POWER_WORD_SILENCE)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_WAIL_OF_THE_BANSHEE)
  Range(LastSeenBy(Myself),3)
  NumCreatureVsPartyLT([ENEMY],0)
  RandomNum(2,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(Myself,WIZARD_WAIL_OF_THE_BANSHEE)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_POWER_WORD_KILL)
  !StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
  !HasBounceEffects(LastSeenBy(Myself))
  HPLT(LastSeenBy(Myself),60)
  RandomNum(2,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_POWER_WORD_KILL)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_POWER_WORD_BLIND)
  !StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
  !HasBounceEffects(LastSeenBy(Myself))
  RandomNum(2,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_POWER_WORD_BLIND)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_POWER_WORD_STUN)
  !StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
  !HasBounceEffects(LastSeenBy(Myself))
  HPLT(LastSeenBy(Myself),90)
  RandomNum(2,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_POWER_WORD_STUN)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_IMPRISONMENT)
  RandomNum(2,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_IMPRISONMENT)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_FINGER_OF_DEATH)
  RandomNum(2,1)
  !Range(LastSeenBy(Myself),5)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_FINGER_OF_DEATH)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_PRISMATIC_SPRAY)
  RandomNum(3,1)
  !Range(LastSeenBy(Myself),10)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_PRISMATIC_SPRAY)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_ENERGY_DRAIN)
  RandomNum(3,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_ENERGY_DRAIN)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_FLESH_TO_STONE)
  !HasBounceEffects(LastSeenBy(Myself))
  !Range(LastSeenBy(Myself),5)
  RandomNum(3,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_FLESH_TO_STONE)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_TELEPORT_FIELD)
  !GlobalTimerNotExpired("TeleportField_On","LOCALS")
  RandomNum(4,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    SetGlobalTimer("TeleportField_On","LOCALS",100)
    Spell(Myself,WIZARD_TELEPORT_FIELD)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_LOWER_RESISTANCE)
  RandomNum(2,1)
  CheckStatGT(LastSeenBy(Myself),50,RESISTMAGIC)
  !Range(LastSeenBy(Myself),5)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_LOWER_RESISTANCE)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  !HasBounceEffects(LastSeenBy(Myself))
  HaveSpell(WIZARD_CHAOS)
  !StateCheck(LastSeenBy(Myself),STATE_CONFUSED)
  RandomNum(2,1)
  !Range(LastSeenBy(Myself),10)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell([ENEMY],WIZARD_CHAOS)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  OR(5)
    Class(LastSeenBy(Myself),DRUID_ALL)
    Class(LastSeenBy(Myself),BARD)
    Class(LastSeenBy(Myself),CLERIC_ALL)
    Class(LastSeenBy(Myself),MAGE_ALL)
    Class(LastSeenBy(Myself),SORCERER)
  HaveSpell(WIZARD_FEEBLEMIND)
  !HasBounceEffects(LastSeenBy(Myself))
  RandomNum(2,1)
  !Range(LastSeenBy(Myself),10)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_FEEBLEMIND)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_DOMINATION)
  !HasBounceEffects(LastSeenBy(Myself))
  !Range(LastSeenBy(Myself),5)
  RandomNum(2,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_DOMINATION)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_EMOTION_HOPELESSNESS)
  !Range(LastSeenBy(Myself),5)
  !HasBounceEffects(LastSeenBy(Myself))
  RandomNum(2,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_EMOTION_HOPELESSNESS)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_CONFUSION)
  !StateCheck(LastSeenBy(Myself),STATE_CONFUSED)
  !Range(LastSeenBy(Myself),5)
  RandomNum(2,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell([ENEMY],WIZARD_CONFUSION)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_SLOW)
  !StateCheck(LastSeenBy(Myself),STATE_SLOWED)
  !Range(LastSeenBy(Myself),10)
  RandomNum(2,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_SLOW)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_RAY_OF_ENFEEBLEMENT)
  !Range(LastSeenBy(Myself),10)
  !HasBounceEffects(LastSeenBy(Myself))
  RandomNum(2,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_RAY_OF_ENFEEBLEMENT)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  !HasBounceEffects(LastSeenBy(Myself))
  !Range(LastSeenBy(Myself),5)
  HaveSpell(WIZARD_FINGER_OF_DEATH)
  RandomNum(2,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_FINGER_OF_DEATH)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_ABI_DALZIMS_HORRID_WILTING)
  !Range(LastSeenBy(Myself),10)
  RandomNum(2,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell([ENEMY],WIZARD_ABI_DALZIMS_HORRID_WILTING)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HPGT(LastSeenBy(Myself),50)
  !HasBounceEffects(LastSeenBy(Myself))
  HaveSpell(WIZARD_MAZE)
  RandomNum(2,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_MAZE)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_HORROR)
  CheckStatLT(LastSeenBy(Myself),50,RESISTMAGIC)
  CheckStatGT(LastSeenBy(Myself),8,SAVEVSSPELL)
  RandomNum(4,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_HORROR)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_MORDENKAINENS_SWORD)
  !Range(LastSeenBy(Myself),5)
  NumCreatureLT([EVILCUTOFF.0.0.0.0.SUMMONED],7)
  RandomNum(4,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(Myself,WIZARD_MORDENKAINENS_SWORD)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_CARRION)
  !Range(LastSeenBy(Myself),10)
  NumCreatureLT([EVILCUTOFF.0.0.0.0.SUMMONED],7)
  RandomNum(4,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(Myself,WIZARD_CARRION)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_SUMMON_HAKEASHAR)
  !Range(LastSeenBy(Myself),10)
  NumCreatureLT([EVILCUTOFF.0.0.0.0.SUMMONED],7)
  RandomNum(4,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(Myself,WIZARD_SUMMON_HAKEASHAR)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_SUMMON_NISHRUU)
  !Range(LastSeenBy(Myself),10)
  NumCreatureLT([EVILCUTOFF.0.0.0.0.SUMMONED],7)
  RandomNum(4,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(Myself,WIZARD_SUMMON_NISHRUU)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_SUMMON_DJINNI)
  !Range(LastSeenBy(Myself),10)
  NumCreatureLT([EVILCUTOFF.0.0.0.0.SUMMONED],7)
  RandomNum(4,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(Myself,WIZARD_SUMMON_DJINNI)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_SUMMON_EFREET)
  !Range(LastSeenBy(Myself),10)
  NumCreatureLT([EVILCUTOFF.0.0.0.0.SUMMONED],7)
  RandomNum(4,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(Myself,WIZARD_SUMMON_EFREET)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_SPIDER_SPAWN)
  !Range(LastSeenBy(Myself),10)
  NumCreatureLT([EVILCUTOFF.0.0.0.0.SUMMONED],7)
  RandomNum(4,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(Myself,WIZARD_SPIDER_SPAWN)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  !Range(LastSeenBy(Myself),20)
  HaveSpell(WIZARD_CONJURE_EARTH_ELEMENTAL)
  NumCreatureLT([EVILCUTOFF.0.0.0.0.SUMMONED],7)
  !NumCreatureVsPartyLT([ENEMY],-1)
  RandomNum(4,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(Myself,WIZARD_CONJURE_EARTH_ELEMENTAL)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  !Range(LastSeenBy(Myself),20)
  HaveSpell(WIZARD_CONJURE_AIR_ELEMENTAL)
  NumCreatureLT([EVILCUTOFF.0.0.0.0.SUMMONED],7)
  !NumCreatureVsPartyLT([ENEMY],-1)
  RandomNum(4,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(Myself,WIZARD_CONJURE_AIR_ELEMENTAL)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  !Range(LastSeenBy(Myself),20)
  HaveSpell(WIZARD_CONJURE_FIRE_ELEMENTAL)
  NumCreatureLT([EVILCUTOFF.0.0.0.0.SUMMONED],7)
  !NumCreatureVsPartyLT([ENEMY],-1)
  RandomNum(4,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(Myself,WIZARD_CONJURE_FIRE_ELEMENTAL)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_MONSTER_SUMMONING_4)
  !Range(LastSeenBy(Myself),10)
  NumCreatureLT([EVILCUTOFF.0.0.0.0.SUMMONED],7)
  RandomNum(4,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(Myself,WIZARD_MONSTER_SUMMONING_4)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_MONSTER_SUMMONING_3)
  !Range(LastSeenBy(Myself),10)
  NumCreatureLT([EVILCUTOFF.0.0.0.0.SUMMONED],7)
  RandomNum(4,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(Myself,WIZARD_MONSTER_SUMMONING_3)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_ANIMATE_DEAD)
  !Range(LastSeenBy(Myself),10)
  NumCreatureLT([EVILCUTOFF.0.0.0.0.SUMMONED],7)
  RandomNum(4,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(Myself,WIZARD_ANIMATE_DEAD)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  !HasBounceEffects(LastSeenBy(Myself))
  HaveSpell(WIZARD_CONE_OF_COLD)
  RandomNum(2,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_CONE_OF_COLD)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  General(LastSeenBy(Myself),UNDEAD)
  !StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
  HaveSpell(WIZARD_CONTROL_UNDEAD)
  RandomNum(2,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_CONTROL_UNDEAD)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_DEATH_SPELL)
  !HasBounceEffects(LastSeenBy(Myself))
  NumCreatureGT([GOODCUTOFF],4)
  RandomNum(2,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_DEATH_SPELL)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_SUN_FIRE)
  Range(LastSeenBy(Myself),3)
  RandomNum(2,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(Myself,WIZARD_SUN_FIRE)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_ICE_STORM)
  !Range(LastSeenBy(Myself),15)
  NumCreatureGT([GOODCUTOFF],4)
  !HasBounceEffects(LastSeenBy(Myself))
  RandomNum(2,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_ICE_STORM)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  !HasBounceEffects(LastSeenBy(Myself))
  HaveSpell(WIZARD_DISINTEGRATE)
  RandomNum(2,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell([ENEMY],WIZARD_DISINTEGRATE)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_METEOR_SWARM)
  !Range(LastSeenBy(Myself),15)
  RandomNum(2,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_METEOR_SWARM)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_MELF_METEOR)
  !HasItem("BLAKBLAD",Myself) // Black Blade of Disaster
  !HasItem("PHANBLAD",Myself) // Phantom Blade
  !HasItem("MELFMET",Myself) // Melf's Minute Meteor
  RandomNum(3,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(Myself,WIZARD_MELF_METEOR)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_FIREBALL)
  CheckStatLT(LastSeenBy(Myself),50,RESISTMAGICFIRE)
  CheckStatLT(LastSeenBy(Myself),50,RESISTMAGIC)
  !Range(LastSeenBy(Myself),10)
  RandomNum(2,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_FIREBALL)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_CHAIN_LIGHTNING)
  !HasBounceEffects(LastSeenBy(Myself))
  !Range(LastSeenBy(Myself),10)
  RandomNum(2,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_CHAIN_LIGHTNING)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_LIGHTNING_BOLT)
  CheckStatLT(LastSeenBy(Myself),50,RESISTELECTRICITY)
  CheckStatLT(LastSeenBy(Myself),50,RESISTMAGIC)
  !HasBounceEffects(LastSeenBy(Myself))
  !Range(LastSeenBy(Myself),6)
  RandomNum(2,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_LIGHTNING_BOLT)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_DELAYED_BLAST_FIREBALL)
  CheckStatLT(LastSeenBy(Myself),50,RESISTMAGICFIRE)
  CheckStatLT(LastSeenBy(Myself),50,RESISTMAGIC)
  !Range(LastSeenBy(Myself),20)
  RandomNum(2,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_DELAYED_BLAST_FIREBALL)
    RunAwayFrom(LastSeenBy(Myself),100)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  !HasBounceEffects(LastSeenBy(Myself))
  Range(LastSeenBy(Myself),5)
  HaveSpell(WIZARD_BURNING_HANDS)
  RandomNum(3,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_BURNING_HANDS)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  CheckStatLT(LastSeenBy(Myself),50,RESISTMAGIC)
  CheckStatLT(LastSeenBy(Myself),50,RESISTMAGICFIRE)
  HaveSpell(WIZARD_AGANNAZAR_SCORCHER)
  RandomNum(3,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_AGANNAZAR_SCORCHER)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  CheckStatLT(LastSeenBy(Myself),50,RESISTMAGIC)
  HaveSpell(WIZARD_MELF_ACID_ARROW)
  RandomNum(3,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_MELF_ACID_ARROW)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  CheckStatLT(LastSeenBy(Myself),50,RESISTMAGIC)
  HaveSpell(WIZARD_FLAME_ARROW)
  RandomNum(2,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_FLAME_ARROW)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  CheckStatLT(LastSeenBy(Myself),50,RESISTMAGIC)
  HaveSpell(WIZARD_POLYMORPH_OTHER)
  HPGT(LastSeenBy(Myself),40)
  RandomNum(3,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_POLYMORPH_OTHER)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  CheckStatLT(LastSeenBy(Myself),50,RESISTMAGIC)
  !HasBounceEffects(LastSeenBy(Myself))
  HaveSpell(WIZARD_MAGIC_MISSILE)
  RandomNum(2,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_MAGIC_MISSILE)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  !HasBounceEffects(LastSeenBy(Myself))
  HaveSpell(WIZARD_CHROMATIC_ORB)
  RandomNum(2,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_CHROMATIC_ORB)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_TENSERS_TRANSFORMATION)
  OR(3)
    Range(LastSeenBy(Myself),5)
    HasItem("BLAKBLAD",Myself) // Black Blade of Disaster
    HasItem("PHANBLAD",Myself) // Phantom Blade
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(Myself,WIZARD_TENSERS_TRANSFORMATION)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_BLACK_BLADE_OF_DISASTER)
  Range(LastSeenBy(Myself),5)
  !HasItem("BLAKBLAD",Myself) // Black Blade of Disaster
  !HasItem("PHANBLAD",Myself) // Phantom Blade
  !HasItem("MELFMET",Myself) // Melf's Minute Meteor
  RandomNum(2,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(Myself,WIZARD_BLACK_BLADE_OF_DISASTER)
    AttackReevaluate(LastSeenBy(Myself),30)
END

IF
  !GlobalTimerNotExpired("Cast","LOCALS")
  HaveSpell(WIZARD_PHANTOM_BLADE)
  Range(LastSeenBy(Myself),5)
  !HasItem("BLAKBLAD",Myself) // Black Blade of Disaster
  !HasItem("PHANBLAD",Myself) // Phantom Blade
  !HasItem("MELFMET",Myself) // Melf's Minute Meteor
  RandomNum(2,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Cast","LOCALS",6)
    Spell(Myself,WIZARD_PHANTOM_BLADE)
    AttackReevaluate(LastSeenBy(Myself),30)
END

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

IF
  Range(LastSeenBy(Myself),5)
  NumCreatureGT(NearestMyGroupOfType([0.0.0.FIGHTER_ALL]),0)
  Range(NearestMyGroupOfType([0.0.0.FIGHTER_ALL]),10)
  OR(5)
    HasItem("BLAKBLAD",Myself) // Black Blade of Disaster
    HasItem("PHANBLAD",Myself) // Phantom Blade
    CheckStatLT(Myself,10,THAC0)
    CheckStatLT(Myself,0,ARMORCLASS)
    !HaveAnySpells()
THEN
  RESPONSE #100
    EquipMostDamagingMelee()
    AttackReevaluate(LastSeenBy(Myself),30)
END

IF
  Range(LastSeenBy(Myself),5)
  !NumCreatureGT(NearestMyGroupOfType([0.0.0.FIGHTER_ALL]),0)
  OR(5)
    HasItem("BLAKBLAD",Myself) // Black Blade of Disaster
    HasItem("PHANBLAD",Myself) // Phantom Blade
    CheckStatLT(Myself,10,THAC0)
    CheckStatLT(Myself,0,ARMORCLASS)
    !HaveAnySpells()
THEN
  RESPONSE #100
    EquipMostDamagingMelee()
    AttackReevaluate(LastSeenBy(Myself),30)
END

IF
  Range(LastSeenBy(Myself),5)
  NumCreatureGT(NearestMyGroupOfType([0.0.0.FIGHTER_ALL]),0)
  !Range(NearestMyGroupOfType([0.0.0.FIGHTER_ALL]),10)
  Range(NearestMyGroupOfType([0.0.0.FIGHTER_ALL]),30)
  OR(5)
    HasItem("BLAKBLAD",Myself) // Black Blade of Disaster
    HasItem("PHANBLAD",Myself) // Phantom Blade
    CheckStatLT(Myself,10,THAC0)
    CheckStatLT(Myself,0,ARMORCLASS)
    !HaveAnySpells()
THEN
  RESPONSE #100
    MoveToObject(NearestMyGroupOfType([0.0.0.FIGHTER_ALL]))
END

IF
  Range(LastSeenBy(Myself),5)
  !HasItem("BLAKBLAD",Myself) // Black Blade of Disaster
  !HasItem("PHANBLAD",Myself) // Phantom Blade
  !CheckStatLT(Myself,10,THAC0)
  !CheckStatLT(Myself,0,ARMORCLASS)
  HaveAnySpells()
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    RunAwayFrom(LastSeenBy(Myself),30)
    SetInterrupt(TRUE)
END

IF
  !Detect([GOODCUTOFF])
THEN
  RESPONSE #50
    MoveToObject(NearestEnemyOf(Myself))
  RESPONSE #50
    Continue()
END

IF
  !Range([PC],20)
  !AttackedBy([ANYONE],DEFAULT)
  !HaveAnySpells()
THEN
  RESPONSE #100
    MoveToObject([PC])
END

IF
  OR(2)
    AttackedBy([ANYONE],DEFAULT)
    HitBy([ANYONE],CRUSHING)
THEN
  RESPONSE #100
    RunAwayFrom(LastAttackerOf(Myself),15)
END

IF
  True()
THEN
  RESPONSE #100
    RandomWalkContinuous()
END
