IF
  HPPercentLT(Myself,20)
  HasItem("POTN52",Myself)
THEN
  RESPONSE #100
    UseItem("POTN52",Myself)
END

IF
  See([0.0.0.0.230])
  !Specifics(Myself,230)
  Range([0.0.0.0.230],20)
  HasItem("POTN52",Myself)
THEN
  RESPONSE #100
    GiveItem("POTN52",[0.0.0.0.230])
    ChangeSpecifics([0.0.0.0.230],0)
END

IF
  !HasItem("POTN52",Myself)
  HPPercentLT(Myself,20)
THEN
  RESPONSE #100
    ChangeSpecifics(Myself,230)
END

IF
  See(NearestEnemyOf(Myself))
  Global("Prep","LOCALS",0)
THEN
  RESPONSE #100
    ApplySpell(Myself,COM_DAERRAGHS_AURA_OF_CLEANSING)
    ApplySpell(Myself,COM_AURA_OF_FOCUS)
    ApplySpell(Myself,WIZARD_STONE_SKIN)
    ReallyForceSpell(Myself,WIZARD_HASTE)
    ApplySpell(Myself,WIZARD_ABSOLUTE_IMMUNITY)
    ApplySpell(Myself,WIZARD_SPELL_TURNING)
    SetGlobal("Prep","LOCALS",1)
END

IF
  See(NearestEnemyOf(Myself))
  OR(7)
    StateCheck(LastSeenBy(Myself),STATE_HASTED)
    StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
    StateCheck(LastSeenBy(Myself),STATE_BLESS)
    StateCheck(LastSeenBy(Myself),STATE_CHANT)
    StateCheck(LastSeenBy(Myself),STATE_MIRRORIMAGE)
    StateCheck(LastSeenBy(Myself),STATE_BLUR)
    StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  Global("PrepDef","LOCALS",0)
  HPGT(Myself,0)
THEN
  RESPONSE #70
    ReallyForceSpell(LastSeenBy(Myself),2326)//WIZARD_DISPEL_MAGIC)
    SetGlobal("PrepDef","LOCALS",1)
  RESPONSE #30
    ApplySpell(Myself,WIZARD_MIRROR_IMAGE)
    SetGlobal("PrepDef","LOCALS",1)
END

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

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

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

IF
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_STONE_SKIN)
  CheckStatLT(Myself,1,STONESKINS)
  TookDamage()
  Global("Prep2","LOCALS",0)
  HPGT(Myself,0)
THEN
  RESPONSE #100
    DisplayString(Myself,40199)
    ApplySpell(Myself,WIZARD_MIRROR_IMAGE)
    DisplayString(Myself,3302)
    ApplySpell(Myself,WIZARD_SPELL_TURNING)
    DisplayString(Myself,40240)
    ApplySpell(Myself,WIZARD_MISLEAD)
    DisplayString(Myself,29736)
    ApplySpell(Myself,WIZARD_STONE_SKIN)
    SetGlobal("Prep2","LOCALS",1)
END

IF
  Allegiance(Myself,ENEMY)
  !HasBounceEffects(Myself)
  HaveSpell(WIZARD_SPELL_TURNING)
THEN
  RESPONSE #100
    Spell(Myself,WIZARD_SPELL_TURNING)
END

IF
  See(NearestEnemyOf(Myself))
  Summoned(NearestEnemyOf(Myself))
  HaveSpell(2326)//WIZARD_DISPEL_MAGIC)
THEN
  RESPONSE #100
    Spell(NearestEnemyOf(Myself),2326)//WIZARD_DISPEL_MAGIC)
END

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

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

IF
  !AreaCheck("DD0119")
  !AreaCheck("DD0118")
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_ABI_DALZIMS_HORRID_WILTING)
THEN
  RESPONSE #100
    Spell(NearestEnemyOf(Myself),WIZARD_ABI_DALZIMS_HORRID_WILTING)
END

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

IF
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_POWER_WORD_KILL)
  HPLT(LastSeenBy(Myself),60)
THEN
  RESPONSE #100
    Spell(NearestEnemyOf(Myself),WIZARD_POWER_WORD_KILL)
END

IF
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_ABI_DALZIMS_HORRID_WILTING)
  HPGT(Myself,0)
THEN
  RESPONSE #100
    DisplayString(Myself,39968)
    DisplayString(Myself,40244)
    ApplySpell(Myself,WIZARD_STONE_SKIN)
    DisplayString(Myself,40245)
    ApplySpell(Myself,WIZARD_GLOBE_OF_INVULNERABILITY)
    DisplayString(Myself,40246)
    ApplySpell(Myself,WIZARD_MINOR_SPELL_TURNING)
    Spell(NearestEnemyOf(Myself),WIZARD_ABI_DALZIMS_HORRID_WILTING)
END

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

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

IF
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_FLESH_TO_STONE)
THEN
  RESPONSE #100
    DisplayString(Myself,39969)
    DisplayString(Myself,40241)
    ApplySpell(Myself,WIZARD_STONE_SKIN)
    DisplayString(Myself,40242)
    ApplySpell(Myself,WIZARD_IMPROVED_INVISIBILITY)
    DisplayString(Myself,40243)
    ApplySpell(Myself,WIZARD_FIRE_SHIELD_RED)
    Spell(NearestEnemyOf(Myself),WIZARD_FLESH_TO_STONE)
END

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

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

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

IF
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_WYVERN_CALL)
  AreaType(OUTDOOR)
THEN
  RESPONSE #100
    Spell(Myself,WIZARD_WYVERN_CALL)
END

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

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

IF
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_MAGIC_MISSILE)
  Global("PrepM","LOCALS",0)
THEN
  RESPONSE #100
    Spell(NearestEnemyOf(Myself),WIZARD_MAGIC_MISSILE)
    SetGlobal("PrepM","LOCALS",1)
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_GREATER_MALISON)
THEN
  RESPONSE #50
    Spell([GOODCUTOFF],WIZARD_GREATER_MALISON)
END

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

IF
  See(NearestEnemyOf(Myself))
  OR(2)
    Range(NearestEnemyOf(Myself),7)
    OutOfAmmo()
THEN
  RESPONSE #100
    EquipMostDamagingMelee()
    AttackReevaluate(NearestEnemyOf(Myself),15)
END

IF
  See(NearestEnemyOf(Myself))
  !Range(NearestEnemyOf(Myself),6)
  !OutOfAmmo()
THEN
  RESPONSE #100
    EquipRanged()
    AttackReevaluate(NearestEnemyOf(Myself),15)
END

