IF
  HPLT(Myself,50)
  Global("GB_Killed","LOCALS",0)
THEN
  RESPONSE #100
    ActionOverride(Myself,SetGlobal("GB_Killed","LOCALS",1))
END

IF
  Global("GB_Killed","LOCALS",1)
  Global("GB_Final","LOCALS",0)
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    DisplayStringHead(Myself,47318)  // ~uses a ring of invisibility~
    ApplySpell(Myself,WIZARD_IMPROVED_INVISIBILITY)
    DisplayStringHead(Myself,46153)  // ~uses a scroll~
    ForceSpell(Myself,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    SetGlobalTimer("GB_WpnIm","LOCALS",24)
    Wait(2)
    DisplayStringHead(Myself,46153)  // ~uses a scroll~
    ForceSpell(Myself,WIZARD_TIME_STOP)
    Wait(2)
    ForceSpell(Myself,WIZARD_IMPROVED_HASTE)
    Wait(2)
    DestroyItem("MELFMET")  // ~Melf's Minute Meteor~
    ForceSpell(Myself,WIZARD_BLACK_BLADE_OF_DISASTER)
    Wait(2)
    ForceSpell(Myself,WIZARD_TENSERS_TRANSFORMATION)
    Wait(2)
    SetGlobal("GB_Final","LOCALS",1)
    SetInterrupt(TRUE)
END

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

IF
  RandomNum(8,1)
  See(Player1)
  See(Player2)
  See(Player3)
  See(Player4)
  See(Player5)
  See(Player6)
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  RandomNum(8,2)
  See(Player4)
  See(Player1)
  See(Player6)
  See(Player3)
  See(Player2)
  See(Player5)
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  RandomNum(8,3)
  See(Player6)
  See(Player3)
  See(Player5)
  See(Player1)
  See(Player2)
  See(Player4)
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  RandomNum(8,4)
  See(Player4)
  See(Player2)
  See(Player6)
  See(Player1)
  See(Player5)
  See(Player3)
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  RandomNum(8,5)
  See(Player3)
  See(Player6)
  See(Player4)
  See(Player1)
  See(Player5)
  See(Player2)
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  RandomNum(8,6)
  See(Player6)
  See(Player5)
  See(Player4)
  See(Player3)
  See(Player2)
  See(Player1)
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  RandomNum(8,7)
  See(Player6)
  See(Player5)
  See(Player4)
  See(Player3)
  See(Player2)
  See(Player1)
  See(WeakestOf(Myself))
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  RandomNum(8,8)
  See(Player6)
  See(Player5)
  See(Player4)
  See(Player3)
  See(Player2)
  See(Player1)
  See(MostDamagedOf(Myself))
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  !GlobalTimerNotExpired("GB_Fear","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("GB_Fear","LOCALS",24)
    ReallyForceSpell(LastSeenBy(Myself),DRAGON_FEAR)
    Continue()
END

IF
  !GlobalTimerNotExpired("GB_CastAttack","LOCALS")
  Global("GB_CastAttacking","LOCALS",1)
THEN
  RESPONSE #100
    SetGlobal("GB_CastAttacking","LOCALS",0)
END

IF
  GlobalTimerNotExpired("GB_CastAttack","LOCALS")
  HasItem("melfmet",Myself)  // ~Melf's Minute Meteor~
THEN
  RESPONSE #100
    SetGlobal("GB_CastAttacking","LOCALS",1)
    AttackOneRound(LastSeenBy(Myself))
END

IF
  !GlobalTimerNotExpired("GB_WpnIm","LOCALS")
  HaveSpell(WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_CastAttack","LOCALS",4)
    Spell(Myself,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    SetGlobalTimer("GB_WpnIm","LOCALS",24)
END

IF
  CheckStatGT(LastSeenBy(Myself),25,RESISTMAGIC)
  HaveSpell(WIZARD_LOWER_RESISTANCE)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_CastAttack","LOCALS",4)
    Spell(LastSeenBy(Myself),WIZARD_LOWER_RESISTANCE)
END

IF
  !HasItem("melfmet",Myself)  // ~Melf's Minute Meteor~
  !HasItem("blakblad",Myself)  // ~Black Blade of Disaster~
  HaveSpell(WIZARD_MELF_METEOR)
THEN
  RESPONSE #300
    Continue()
  RESPONSE #100
    SetGlobalTimer("GB_CastAttack","LOCALS",4)
    Spell(Myself,WIZARD_MELF_METEOR)
END

IF
  HitBy([GOODCUTOFF.0.0.0.0.SUMMONED],CRUSHING)
  TookDamage()
  HaveSpell(WIZARD_DEATH_SPELL)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_CastAttack","LOCALS",4)
    Spell(LastHitter,WIZARD_DEATH_SPELL)
END

IF
  HaveSpell(WIZARD_GREATER_MALISON)
  RandomNumLT(4,2)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_CastAttack","LOCALS",4)
    Spell(LastSeenBy(Myself),WIZARD_GREATER_MALISON)
END

IF
  HaveSpell(WIZARD_SPHERE_OF_CHAOS)
  RandomNumLT(8,3)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_CastAttack","LOCALS",4)
    Spell(Myself,WIZARD_SPHERE_OF_CHAOS)
END

IF
  HaveSpell(WIZARD_TELEPORT_FIELD)
  RandomNumLT(12,4)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_CastAttack","LOCALS",4)
    Spell(Myself,WIZARD_TELEPORT_FIELD)
END

IF
  Class(LastSeenBy(Myself),LONG_BOW)
  HaveSpell(WIZARD_WARDING_WHIP)
  RandomNumLT(16,5)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_CastAttack","LOCALS",4)
    Spell(LastSeenBy(Myself),WIZARD_WARDING_WHIP)
END

IF
  Class(LastSeenBy(Myself),CLERIC_ALL)
  HaveSpell(WIZARD_SPOOK)
  RandomNumLT(20,6)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_CastAttack","LOCALS",4)
    Spell(LastSeenBy(Myself),WIZARD_SPOOK)
END

IF
  !StateCheck(Myself,STATE_IMPROVEDINVISIBILITY)
  HaveSpell(WIZARD_IMPROVED_INVISIBILITY)
  RandomNumLT(24,7)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_CastAttack","LOCALS",4)
    Spell(Myself,WIZARD_IMPROVED_INVISIBILITY)
END

IF
  !StateCheck(Myself,STATE_MIRRORIMAGE)
  HaveSpell(WIZARD_MIRROR_IMAGE)
  RandomNumLT(28,8)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_CastAttack","LOCALS",4)
    Spell(Myself,WIZARD_MIRROR_IMAGE)
END

IF
  !Range(TenthNearestEnemyOf(Myself),12)
  HaveSpell(WIZARD_METEOR_SWARM)
  RandomNumLT(32,9)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_CastAttack","LOCALS",4)
    Spell(TenthNearestEnemyOf(Myself),WIZARD_METEOR_SWARM)
END

IF
  HPLT(LastSeenBy(Myself),61)
  HaveSpell(WIZARD_POWER_WORD_KILL)
  !CheckStatGT(LastSeenBy(Myself),25,RESISTMAGIC)
  RandomNumLT(36,10)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_CastAttack","LOCALS",4)
    Spell(LastSeenBy(Myself),WIZARD_POWER_WORD_KILL)
END

IF
  Range(LastSeenBy(Myself),4)
  HaveSpell(WIZARD_IMPRISONMENT)
  !Kit(LastSeenBy(Myself),BERSERKER)
  !Kit(LastSeenBy(Myself),BARBARIAN)
  RandomNumLT(40,11)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_CastAttack","LOCALS",4)
    Spell(LastSeenBy(Myself),WIZARD_IMPRISONMENT)
END

IF
  HaveSpell(WIZARD_WAIL_OF_THE_BANSHEE)
  RandomNumLT(44,12)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_CastAttack","LOCALS",4)
    Spell(LastSeenBy(Myself),WIZARD_WAIL_OF_THE_BANSHEE)
END

IF
  Range(LastSeenBy(Myself),4)
  HaveSpell(WIZARD_MAZE)
  !Kit(LastSeenBy(Myself),BERSERKER)
  !Kit(LastSeenBy(Myself),BARBARIAN)
  RandomNumLT(48,13)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_CastAttack","LOCALS",4)
    Spell(LastSeenBy(Myself),WIZARD_MAZE)
END

IF
  HaveSpell(WIZARD_SYMBOL_STUN)
  RandomNumLT(52,14)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_CastAttack","LOCALS",4)
    Spell(LastSeenBy(Myself),WIZARD_SYMBOL_STUN)
END

IF
  HaveSpell(WIZARD_SYMBOL_FEAR)
  RandomNumLT(56,15)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_CastAttack","LOCALS",4)
    Spell(LastSeenBy(Myself),WIZARD_SYMBOL_FEAR)
END

IF
  HPLT(LastSeenBy(Myself),90)
  HaveSpell(WIZARD_POWER_WORD_STUN)
  !CheckStatGT(LastSeenBy(Myself),25,RESISTMAGIC)
  RandomNumLT(60,16)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_CastAttack","LOCALS",4)
    Spell(LastSeenBy(Myself),WIZARD_POWER_WORD_STUN)
END

IF
  Range(LastSeenBy(Myself),4)
  HaveSpell(WIZARD_SUN_FIRE)
  !CheckStatGT(LastSeenBy(Myself),25,RESISTMAGIC)
  !CheckStatGT(LastSeenBy(Myself),25,RESISTFIRE)
  RandomNumLT(64,17)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_CastAttack","LOCALS",4)
    Spell(LastSeenBy(Myself),WIZARD_SUN_FIRE)
END

IF
  Range(LastSeenBy(Myself),4)
  HaveSpell(WIZARD_CONE_OF_COLD)
  !CheckStatGT(LastSeenBy(Myself),25,RESISTMAGIC)
  !CheckStatGT(LastSeenBy(Myself),25,RESISTCOLD)
  RandomNumLT(68,18)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_CastAttack","LOCALS",4)
    Spell(LastSeenBy(Myself),WIZARD_CONE_OF_COLD)
END

IF
  HaveSpell(WIZARD_EMOTION_HOPELESSNESS)
  !CheckStatGT(LastSeenBy(Myself),25,RESISTMAGIC)
  RandomNumLT(72,19)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_CastAttack","LOCALS",4)
    Spell(LastSeenBy(Myself),WIZARD_EMOTION_HOPELESSNESS)
END

IF
  HaveSpell(WIZARD_SKULL_TRAP)
  !CheckStatGT(LastSeenBy(Myself),25,RESISTMAGIC)
  RandomNumLT(76,20)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_CastAttack","LOCALS",4)
    Spell(LastSeenBy(Myself),WIZARD_SKULL_TRAP)
END

IF
  HaveSpell(WIZARD_SLOW)
  !CheckStatGT(LastSeenBy(Myself),25,RESISTMAGIC)
  RandomNumLT(80,21)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_CastAttack","LOCALS",4)
    Spell(LastSeenBy(Myself),WIZARD_SLOW)
END

IF
  HaveSpell(WIZARD_FLAME_ARROW)
  !CheckStatGT(LastSeenBy(Myself),25,RESISTMAGIC)
  RandomNumLT(84,22)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_CastAttack","LOCALS",4)
    Spell(LastSeenBy(Myself),WIZARD_FLAME_ARROW)
END

IF
  HaveSpell(WIZARD_WEB)
  !CheckStatGT(LastSeenBy(Myself),25,RESISTMAGIC)
  RandomNumLT(88,23)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_CastAttack","LOCALS",4)
    Spell(LastSeenBy(Myself),WIZARD_WEB)
END

IF
  HaveSpell(WIZARD_GLITTERDUST)
  !CheckStatGT(LastSeenBy(Myself),25,RESISTMAGIC)
  RandomNumLT(92,24)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_CastAttack","LOCALS",4)
    Spell(LastSeenBy(Myself),WIZARD_GLITTERDUST)
END

IF
  HaveSpell(WIZARD_STINKING_CLOUD)
  !CheckStatGT(LastSeenBy(Myself),25,RESISTMAGIC)
  RandomNumLT(96,25)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_CastAttack","LOCALS",4)
    Spell(LastSeenBy(Myself),WIZARD_STINKING_CLOUD)
END

IF
  HaveSpell(WIZARD_MAGIC_MISSILE)
  !CheckStatGT(LastSeenBy(Myself),25,RESISTMAGIC)
  RandomNumLT(100,26)
THEN
  RESPONSE #100
    SetGlobalTimer("GB_CastAttack","LOCALS",4)
    Spell(LastSeenBy(Myself),WIZARD_MAGIC_MISSILE)
END

IF
  True()
THEN
  RESPONSE #100
    AttackOneRound(MostDamagedOf(Myself))
  RESPONSE #100
    AttackOneRound(LastSeenBy(Myself))
  RESPONSE #100
    AttackOneRound(NearestEnemyOf(Myself))
END

