IF
  Global("pkmessrun","GLOBAL",7)
THEN
  RESPONSE #100
    SetGlobal("pkmessrun","GLOBAL",8)
    EscapeArea()
END

IF
  Heard([ANYONE],111)
THEN
  RESPONSE #100
    MoveToObject(NearestEnemyOf(Myself))
END

IF
  AttackedBy([GOODCUTOFF],DEFAULT)
  !Allegiance(Myself,ENEMY)
THEN
  RESPONSE #100
    Enemy()
END

IF
  See(NearestEnemyOf(Myself))
  Global("Prep","LOCALS",0)
THEN
  RESPONSE #100
    ApplySpell(Myself,WIZARD_STONE_SKIN)
    DisplayString(Myself,39968)
    ApplySpell(Myself,WIZARD_GLOBE_OF_INVULNERABILITY)
    ApplySpell(Myself,WIZARD_SPELL_TURNING)
    ApplySpell(Myself,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
    ApplySpell(Myself,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    ApplySpell(Myself,WIZARD_PROTECTION_FROM_ELECTRICITY)
    SetGlobal("Prep","LOCALS",1)
END

IF
  See(NearestEnemyOf(Myself))
  StateCheck(Myself,STATE_SILENCED)
  HaveSpell(WIZARD_VOCALIZE)
THEN
  RESPONSE #100
    Spell(Myself,WIZARD_VOCALIZE)
END

IF
  Detect([PC])
  !See(LastSeenBy(Myself))
  HaveSpell(WIZARD_TRUE_SIGHT)
THEN
  RESPONSE #100
    Spell(Myself,WIZARD_TRUE_SIGHT)
END

IF
  !HasBounceEffects(Myself)
  !HasImmunityEffects(Myself)
  HaveSpell(WIZARD_SPELL_TURNING)
  See(NearestEnemyOf(Myself))
THEN
  RESPONSE #100
    Spell(Myself,WIZARD_SPELL_TURNING)
END

IF
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_STONE_SKIN)
  CheckStatLT(Myself,1,STONESKINS)
  Global("Prep1","LOCALS",0)
  HPGT(Myself,0)
THEN
  RESPONSE #100
    DisplayString(Myself,29736)
    ForceSpell(Myself,WIZARD_STONE_SKIN)
    SetGlobal("Prep1","LOCALS",1)
END

IF
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_NPC_SYMBOL_STUN)
THEN
  RESPONSE #100
    Spell(NearestEnemyOf(Myself),WIZARD_NPC_SYMBOL_STUN)
END

IF
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_SIMULACRUM)
  Global("Sim","LOCALS",0)
  HPGT(Myself,0)
THEN
  RESPONSE #100
    ForceSpell(Myself,DO_NOTHING)
    DisplayString(Myself,40600)
    CreateCreatureObjectCopy("mage8a",Myself,0,0,0)
    SetGlobal("Sim","LOCALS",1)
END

IF
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_SHADOW_DOOR)
THEN
  RESPONSE #100
    Spell(Myself,WIZARD_SHADOW_DOOR)
END

IF
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_CHAIN_LIGHTNING)
  GlobalLT("chain","LOCALS",2)
THEN
  RESPONSE #100
    Spell(NearestEnemyOf(Myself),WIZARD_CHAIN_LIGHTNING)
    IncrementGlobal("chain","LOCALS",1)
END

IF
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_MAZE)
THEN
  RESPONSE #100
    Spell(NearestEnemyOf(Myself),WIZARD_MAZE)
END

IF
  See(NearestEnemyOfType([0.0.0.MAGE_ALL]))
  HaveSpell(WIZARD_RUBY_RAY_OF_REVERSAL)
THEN
  RESPONSE #100
    Spell(LastSeenBy(Myself),WIZARD_RUBY_RAY_OF_REVERSAL)
END

IF
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_NPC_SYMBOL_FEAR)
THEN
  RESPONSE #100
    Spell(NearestEnemyOf(Myself),WIZARD_NPC_SYMBOL_FEAR)
END

IF
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_MIRROR_IMAGE)
  Global("Prep","LOCALS",1)
  HPGT(Myself,0)
THEN
  RESPONSE #100
    DisplayString(Myself,39969)
    ApplySpell(Myself,WIZARD_STONE_SKIN)
    ApplySpell(Myself,WIZARD_MIRROR_IMAGE)
    ApplySpell(Myself,WIZARD_FIRE_SHIELD_RED)
    SetGlobal("Prep","LOCALS",2)
END

IF
  See(NearestEnemyOf(Myself))
  !StateCheck(LastSeenBy(Myself),STATE_STUNNED)
  HaveSpell(WIZARD_POWER_WORD_STUN)
THEN
  RESPONSE #100
    Spell(NearestEnemyOf(Myself),WIZARD_POWER_WORD_STUN)
END

IF
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_SUN_FIRE)
THEN
  RESPONSE #100
    Spell(Myself,WIZARD_SUN_FIRE)
END

IF
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_MISLEAD)
THEN
  RESPONSE #100
    Spell(Myself,WIZARD_MISLEAD)
END

IF
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_TRUE_SIGHT)
THEN
  RESPONSE #100
    Spell(NearestEnemyOf(Myself),WIZARD_TRUE_SIGHT)
END

IF
  See(NearestEnemyOfType([0.0.0.MAGE_ALL]))
  HaveSpell(WIZARD_RUBY_RAY_OF_REVERSAL)
  OR(2)
    HasBounceEffects(LastSeenBy(Myself))
    HasImmunityEffects(LastSeenBy(Myself))
THEN
  RESPONSE #100
    Spell(LastSeenBy(Myself),WIZARD_RUBY_RAY_OF_REVERSAL)
END

IF
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_DISINTEGRATE)
THEN
  RESPONSE #100
    Spell(NearestEnemyOf(Myself),WIZARD_DISINTEGRATE)
END

IF
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_CHAIN_LIGHTNING)
THEN
  RESPONSE #100
    Spell(NearestEnemyOf(Myself),WIZARD_CHAIN_LIGHTNING)
END

IF
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_CHAOS)
THEN
  RESPONSE #100
    Spell(NearestEnemyOf(Myself),WIZARD_CHAOS)
END

IF
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_DOMINATION)
THEN
  RESPONSE #100
    Spell(NearestEnemyOf(Myself),WIZARD_DOMINATION)
END

IF
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_FLAME_ARROW)
THEN
  RESPONSE #100
    Spell(NearestEnemyOf(Myself),WIZARD_FLAME_ARROW)
END

IF
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_MELF_ACID_ARROW)
THEN
  RESPONSE #100
    Spell(NearestEnemyOf(Myself),WIZARD_MELF_ACID_ARROW)
END

IF
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_MAGIC_MISSILE)
THEN
  RESPONSE #100
    Spell(NearestEnemyOf(Myself),WIZARD_MAGIC_MISSILE)
END

IF
  See(NearestEnemyOf(Myself))
THEN
  RESPONSE #100
    AttackReevaluate(NearestEnemyOf(Myself),15)
END

