IF
  HPPercentLT(Myself,25)
  !HasItem("potn52",Myself)
THEN
  RESPONSE #100
    RunAwayFrom(NearestEnemyOf(),30)
    Hide()
END

IF
  HPPercentLT(Myself,50)
  !GlobalTimerNotExpired("agu","LOCALS")
  HasItem("potn52",Myself)
THEN
  RESPONSE #100
    UseItem("potn52",Myself)
    SetGlobalTimer("agu","LOCALS",6)
END

IF
  StateCheck(Myself,STATE_POISONED)
  !GlobalTimerNotExpired("agu","LOCALS")
  HasItem("potn20",Myself)
THEN
  RESPONSE #100
    UseItem("potn20",Myself)
    SetGlobalTimer("agu","LOCALS",6)
END

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

IF
  !Allegiance(Myself,ENEMY)
THEN
  RESPONSE #100
    NoAction()
END

IF
  !See([GOODCUTOFF.0.0.MAGE_ALL])
  !See([GOODCUTOFF.0.0.CLERIC_ALL])
  !See([GOODCUTOFF.0.0.DRUID_ALL])
  !See([GOODCUTOFF.0.0.BARD_ALL])
  !See([GOODCUTOFF])
  False()
THEN
  RESPONSE #100
    Continue()
END

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

IF
  Global("agprep","LOCALS",0)
THEN
  RESPONSE #100
    ApplySpell(Myself,WIZARD_STONE_SKIN)
    ApplySpell(Myself,WIZARD_MINOR_SPELL_TURNING)
    Spell(Myself,WIZARD_MISLEAD)
    SetGlobal("agprep","LOCALS",1)
END

IF
  HaveSpell(WIZARD_STONE_SKIN)
  CheckStatLT(Myself,1,STONESKINS)
  Global("agprep","LOCALS",1)
THEN
  RESPONSE #100
    DisplayString(Myself,29736)
    SetGlobal("agprep","LOCALS",2)
    ApplySpell(Myself,WIZARD_STONE_SKIN)
END

IF
  HaveSpell(WIZARD_MONSTER_SUMMONING_3)
  !GlobalTimerNotExpired("agu","LOCALS")
  !StateCheck(Myself,STATE_SILENCED)
  !CheckStatGT(Myself,75,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("agu","LOCALS",6)
    Spell(LastSeenBy(),WIZARD_MONSTER_SUMMONING_3)
END

IF
  HaveSpell(WIZARD_MIRROR_IMAGE)
  !GlobalTimerNotExpired("agu","LOCALS")
  !StateCheck(Myself,STATE_MIRRORIMAGE)
  !StateCheck(Myself,STATE_SILENCED)
  !CheckStatGT(Myself,75,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("agu","LOCALS",6)
    Spell(Myself,WIZARD_MIRROR_IMAGE)
END

IF
  HaveSpell(WIZARD_HASTE)
  !GlobalTimerNotExpired("agu","LOCALS")
  !StateCheck(Myself,STATE_HASTED)
  !StateCheck(Myself,STATE_SILENCED)
  !CheckStatGT(Myself,75,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("agu","LOCALS",6)
    Spell(Myself,WIZARD_HASTE)
END

IF
  HaveSpell(WIZARD_SECRET_WORD)
  !GlobalTimerNotExpired("agu","LOCALS")
  !StateCheck(Myself,STATE_SILENCED)
  !CheckStatGT(Myself,75,SPELLFAILUREMAGE)
  CheckStatLT(LastSeenBy(),50,RESISTCOLD)
THEN
  RESPONSE #100
    SetGlobalTimer("agu","LOCALS",6)
    Spell(LastSeenBy(),WIZARD_SECRET_WORD)
END

IF
  HaveSpell(WIZARD_SPIDER_SPAWN)
  !GlobalTimerNotExpired("agu","LOCALS")
  !StateCheck(Myself,STATE_SILENCED)
  !CheckStatGT(Myself,75,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("agu","LOCALS",6)
    Spell(LastSeenBy(),WIZARD_SPIDER_SPAWN)
END

IF
  HaveSpell(WIZARD_CHAIN_LIGHTNING)
  !GlobalTimerNotExpired("agu","LOCALS")
  !StateCheck(Myself,STATE_SILENCED)
  !CheckStatGT(Myself,75,SPELLFAILUREMAGE)
  !HasBounceEffects(LastSeenBy())
  CheckStatLT(LastSeenBy(),50,RESISTELECTRICITY)
THEN
  RESPONSE #100
    SetGlobalTimer("agu","LOCALS",6)
    Spell(LastSeenBy(),WIZARD_CHAIN_LIGHTNING)
END

IF
  HaveSpell(WIZARD_DISPEL_MAGIC)
  !GlobalTimerNotExpired("agu","LOCALS")
  !StateCheck(Myself,STATE_SILENCED)
  !CheckStatGT(Myself,75,SPELLFAILUREMAGE)
  CheckStatLT(LastSeenBy(),50,RESISTCOLD)
THEN
  RESPONSE #100
    SetGlobalTimer("agu","LOCALS",6)
    Spell(LastSeenBy(),WIZARD_DISPEL_MAGIC)
END

IF
  HaveSpell(WIZARD_CHAOS)
  !GlobalTimerNotExpired("agu","LOCALS")
  !StateCheck(LastSeenBy(),STATE_SLEEPING)
  !StateCheck(LastSeenBy(),STATE_HELPLESS)
  !StateCheck(LastSeenBy(),STATE_CHARMED)
  !StateCheck(LastSeenBy(),STATE_CONFUSED)
  !StateCheck(LastSeenBy(),STATE_PANIC)
  !HasBounceEffects(LastSeenBy())
  !StateCheck(Myself,STATE_SILENCED)
  !CheckStatGT(Myself,75,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("agu","LOCALS",6)
    Spell(LastSeenBy(),WIZARD_CHAOS)
END

IF
  HaveSpell(WIZARD_TRUE_SIGHT)
  !GlobalTimerNotExpired("agu","LOCALS")
  !StateCheck(Myself,STATE_SILENCED)
  !CheckStatGT(Myself,75,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("agu","LOCALS",6)
    Spell(Myself,WIZARD_TRUE_SIGHT)
END

IF
  HaveSpell(WIZARD_SHADOW_DOOR)
  !GlobalTimerNotExpired("agu","LOCALS")
  !StateCheck(Myself,STATE_SILENCED)
  !StateCheck(Myself,STATE_INVISIBLE)
  !StateCheck(Myself,STATE_IMPROVEDINVISIBILITY)
  !CheckStatGT(Myself,75,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("agu","LOCALS",6)
    Spell(Myself,WIZARD_SHADOW_DOOR)
END

IF
  HaveSpell(WIZARD_DOMINATION)
  !GlobalTimerNotExpired("agu","LOCALS")
  !StateCheck(LastSeenBy(),STATE_SLEEPING)
  !StateCheck(LastSeenBy(),STATE_HELPLESS)
  !StateCheck(LastSeenBy(),STATE_CHARMED)
  !StateCheck(LastSeenBy(),STATE_CONFUSED)
  !StateCheck(LastSeenBy(),STATE_PANIC)
  !HasBounceEffects(LastSeenBy())
  !StateCheck(Myself,STATE_SILENCED)
  !CheckStatGT(Myself,75,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("agu","LOCALS",6)
    Spell(LastSeenBy(),WIZARD_DOMINATION)
END

IF
  HaveSpell(WIZARD_CONFUSION)
  !GlobalTimerNotExpired("agu","LOCALS")
  !StateCheck(LastSeenBy(),STATE_SLEEPING)
  !StateCheck(LastSeenBy(),STATE_HELPLESS)
  !StateCheck(LastSeenBy(),STATE_CHARMED)
  !StateCheck(LastSeenBy(),STATE_CONFUSED)
  !StateCheck(LastSeenBy(),STATE_PANIC)
  !HasBounceEffects(LastSeenBy())
  !StateCheck(Myself,STATE_SILENCED)
  !CheckStatGT(Myself,75,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("agu","LOCALS",6)
    Spell(LastSeenBy(),WIZARD_CONFUSION)
END

IF
  HaveSpell(WIZARD_SLOW)
  !GlobalTimerNotExpired("agu","LOCALS")
  !StateCheck(LastSeenBy(),STATE_SLOWED)
  !HasBounceEffects(LastSeenBy())
  !StateCheck(Myself,STATE_SILENCED)
  !CheckStatGT(Myself,75,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("agu","LOCALS",6)
    Spell(LastSeenBy(),WIZARD_SLOW)
END

IF
  HaveSpell(WIZARD_MELF_METEOR)
  !GlobalTimerNotExpired("agu","LOCALS")
  !HasItem("melfmet",Myself)
  !StateCheck(Myself,STATE_SILENCED)
  !CheckStatGT(Myself,75,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("agu","LOCALS",6)
    Spell(Myself(),WIZARD_MELF_METEOR)
END

IF
  HaveSpell(WIZARD_HOLD_PERSON)
  !GlobalTimerNotExpired("agu","LOCALS")
  !StateCheck(LastSeenBy(),STATE_SLEEPING)
  !StateCheck(LastSeenBy(),STATE_HELPLESS)
  !StateCheck(LastSeenBy(),STATE_STUNNED)
  !StateCheck(LastSeenBy(),STATE_CHARMED)
  !StateCheck(LastSeenBy(),STATE_CONFUSED)
  !StateCheck(LastSeenBy(),STATE_PANIC)
  !HasBounceEffects(LastSeenBy())
  !StateCheck(Myself,STATE_SILENCED)
  !CheckStatGT(Myself,75,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("agu","LOCALS",6)
    Spell(LastSeenBy(),WIZARD_HOLD_PERSON)
END

IF
  HaveSpell(WIZARD_LIGHTNING_BOLT)
  !GlobalTimerNotExpired("agu","LOCALS")
  !StateCheck(Myself,STATE_SILENCED)
  !CheckStatGT(Myself,75,SPELLFAILUREMAGE)
  !HasBounceEffects(LastSeenBy())
  CheckStatLT(LastSeenBy(),50,RESISTELECTRICITY)
THEN
  RESPONSE #100
    SetGlobalTimer("agu","LOCALS",6)
    Spell(LastSeenBy(),WIZARD_LIGHTNING_BOLT)
END

IF
  HaveSpell(WIZARD_MELF_ACID_ARROW)
  !GlobalTimerNotExpired("agu","LOCALS")
  !StateCheck(Myself,STATE_SILENCED)
  !CheckStatGT(Myself,75,SPELLFAILUREMAGE)
  !HasBounceEffects(LastSeenBy())
  CheckStatLT(LastSeenBy(),50,RESISTACID)
THEN
  RESPONSE #100
    SetGlobalTimer("agu","LOCALS",6)
    Spell(LastSeenBy(),WIZARD_MELF_ACID_ARROW)
END

IF
  HaveSpell(WIZARD_AGANNAZAR_SCORCHER)
  !GlobalTimerNotExpired("agu","LOCALS")
  !StateCheck(Myself,STATE_SILENCED)
  !CheckStatGT(Myself,75,SPELLFAILUREMAGE)
  !HasBounceEffects(LastSeenBy())
  CheckStatLT(LastSeenBy(),50,RESISTFIRE)
THEN
  RESPONSE #100
    SetGlobalTimer("agu","LOCALS",6)
    Spell(LastSeenBy(),WIZARD_AGANNAZAR_SCORCHER)
END

IF
  HaveSpell(WIZARD_CHROMATIC_ORB)
  !GlobalTimerNotExpired("agu","LOCALS")
  !StateCheck(Myself,STATE_SILENCED)
  !CheckStatGT(Myself,75,SPELLFAILUREMAGE)
  !HasBounceEffects(LastSeenBy())
  CheckStatLT(LastSeenBy(),50,RESISTMAGIC)
THEN
  RESPONSE #100
    SetGlobalTimer("agu","LOCALS",6)
    Spell(LastSeenBy(),WIZARD_CHROMATIC_ORB)
END

IF
  HaveSpell(WIZARD_MAGIC_MISSILE)
  !GlobalTimerNotExpired("agu","LOCALS")
  !StateCheck(Myself,STATE_SILENCED)
  !CheckStatGT(Myself,75,SPELLFAILUREMAGE)
  !HasBounceEffects(LastSeenBy())
THEN
  RESPONSE #100
    SetGlobalTimer("agu","LOCALS",6)
    Spell(LastSeenBy(),WIZARD_MAGIC_MISSILE)
END

IF
  GlobalTimerNotExpired("agu","LOCALS")
THEN
  RESPONSE #100
    AttackOneRound(LastSeenBy())
END
