Putting the 'role' back in role-playing games since 2002.
Donate to Codex
Good Old Games
  • Welcome to rpgcodex.net, a site dedicated to discussing computer based role-playing games in a free and open fashion. We're less strict than other forums, but please refer to the rules.

    "This message is awaiting moderator approval": All new users must pass through our moderation queue before they will be able to post normally. Until your account has "passed" your posts will only be visible to yourself (and moderators) until they are approved. Give us a week to get around to approving / deleting / ignoring your mundane opinion on crap before hassling us about it. Once you have passed the moderation period (think of it as a test), you will be able to post normally, just like all the other retards.

Baldur's Gate The Baldur's Gate Series Thread

Joined
Jan 14, 2018
Messages
50,754
Codex Year of the Donut
What do the numbers in the parentheses mean? Effective saving throw?
Googled it and found nothing.
CEvCpIB.png
 

Yosharian

Arcane
Joined
May 28, 2018
Messages
9,492
Location
Grand Chien
Viccy looks pretty good, but she looks more like a paladin/blackguard than a cleric. RE: mods, SCS is a must for BG2, even on a first playthrough, I played it first without it and I regret it. With BG1 it depends whether you want to go for the original engine or not, if not, go for SCS too.
Are you joking? SCS is insanely hard...
 

Chippy

Arcane
Patron
Joined
May 5, 2018
Messages
6,066
Steve gets a Kidney but I don't even get a tag.

Funny how art has changed over the years. Anyone remember Saturday morning art from the 90s? Gritty, grown-up characters with personality on their faces. Now everyone looks like an underage, vacuous, innocent but-knows-how-to-do-a-blowjob sex doll.
 
Joined
Jan 14, 2018
Messages
50,754
Codex Year of the Donut
Comparison of the AI script for the BG1 Act 4 boss(Davaeorn) in vanilla vs Sword Coast Stratagems. For a quick rundown, scripts are executed in a hierarchy, just assume the first script is executed then falls through to the second one for simplification.

Vanilla:
Code:
IF
   Detect([PC])
   NumberOfTimesTalkedTo(0)
THEN
   RESPONSE #100
       VerbalConstant(Myself,INITIAL_MEETING)
       StartDialogue("davaeo",LastSeenBy(Myself))
END

IF
   Global("DavaeornBehavior","AR1803",0)
   See(NearestEnemyOf(Myself))
THEN
   RESPONSE #100
       ForceSpellPoint([787.445],WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
       VerbalConstant(Myself,12)
       Wait(2)
       SpellNoDec(NearestEnemyOf(Myself),WIZARD_LIGHTNING_BOLT)  // SPWI308.SPL (Lightning Bolt)
       SetGlobal("DavaeornBehavior","AR1803",1)
END

IF
   Global("DavaeornBehavior","AR1803",1)
   See(NearestEnemyOf(Myself))
THEN
   RESPONSE #100
       ForceSpellPoint([290.790],WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
       VerbalConstant(Myself,13)
       Wait(2)
       SpellNoDec(NearestEnemyOf(Myself),WIZARD_FIREBALL)  // SPWI304.SPL (Fireball)
       SetGlobal("DavaeornBehavior","AR1803",2)
END

IF
   Global("DavaeornBehavior","AR1803",1)
THEN
   RESPONSE #100
       VerbalConstant(Myself,11)
       MoveToPoint([1060.640])
       MoveToPoint([870.800])
       MoveToPoint([580.820])
       MoveToPoint([710.440])
       SetGlobal("DavaeornBehavior","AR1803",2)
END

IF
   Global("DavaeornBehavior","AR1803",2)
   See(NearestEnemyOf(Myself))
THEN
   RESPONSE #100
       SpellNoDec(NearestEnemyOf(Myself),WIZARD_DIRE_CHARM)  // SPWI316.SPL (Dire Charm)
       VerbalConstant(Myself,12)
       ForceSpellPoint([787.445],WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
       SpellNoDec(Myself,WIZARD_MIRROR_IMAGE)  // SPWI212.SPL (Mirror Image)
       VerbalConstant(Myself,13)
       SetGlobal("DavaeornBehavior","AR1803",3)
END

IF
   Global("DavaeornBehavior","AR1803",2)
THEN
   RESPONSE #100
       VerbalConstant(Myself,BATTLE_CRY)
       MoveToPoint([560.1028])
       MoveToPoint([1060.650])
       MoveToPoint([787.445])
       MoveToPoint([510.640])
       VerbalConstant(Myself,10)
       MoveToPoint([670.920])
       MoveToPoint([560.1028])
       MoveToPoint([290.790])
       SetGlobal("DavaeornBehavior","AR1803",3)
END

IF
   Global("DavaeornBehavior","AR1803",3)
   See(NearestEnemyOf(Myself))
THEN
   RESPONSE #100
       SpellNoDec(NearestEnemyOf(Myself),WIZARD_HOLD_PERSON)  // SPWI306.SPL (Hold Person)
       VerbalConstant(Myself,10)
       SpellNoDec(NearestEnemyOf(Myself),WIZARD_MONSTER_SUMMONING_3)  // SPWI504.SPL (Monster Summoning III)
       SetGlobal("DavaeornBehavior","AR1803",4)
END

IF
   Global("DavaeornBehavior","AR1803",3)
THEN
   RESPONSE #100
       MoveToPoint([1075.640])
       VerbalConstant(Myself,10)
       MoveToPoint([555.1030])
       MoveToPoint([290.790])
       MoveToPoint([555.1030])
       MoveToPoint([1075.640])
       VerbalConstant(Myself,BATTLE_CRY)
       MoveToPoint([1280.870])
       SetGlobal("DavaeornBehavior","AR1803",4)
END

IF
   See(NearestEnemyOf(Myself))
   Global("DavaeornBehavior","AR1803",4)
   HaveSpell(WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
   HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
   HaveSpell(WIZARD_LIGHTNING_BOLT)  // SPWI308.SPL (Lightning Bolt)
THEN
   RESPONSE #30
       ForceSpellPoint([290.790],WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
       VerbalConstant(Myself,10)
       Wait(1)
       Spell(NearestEnemyOf(Myself),WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
       SetGlobal("DavaeornBehavior","AR1803",5)
   RESPONSE #30
       ForceSpellPoint([1280.870],WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
       VerbalConstant(Myself,13)
       Wait(1)
       Spell(NearestEnemyOf(Myself),WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
       SetGlobal("DavaeornBehavior","AR1803",5)
   RESPONSE #30
       ForceSpellPoint([787.445],WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
       VerbalConstant(Myself,12)
       Wait(2)
       Spell(NearestEnemyOf(Myself),WIZARD_LIGHTNING_BOLT)  // SPWI308.SPL (Lightning Bolt)
       SetGlobal("DavaeornBehavior","AR1803",5)
END

IF
   See(NearestEnemyOf(Myself))
   Global("DavaeornBehavior","AR1803",5)
   HaveSpell(WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
   HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
THEN
   RESPONSE #30
       ForceSpellPoint([290.790],WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
       VerbalConstant(Myself,10)
       Wait(1)
       Spell(NearestEnemyOf(Myself),WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
       SetGlobal("DavaeornBehavior","AR1803",6)
   RESPONSE #30
       ForceSpellPoint([1280.870],WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
       VerbalConstant(Myself,11)
       Wait(1)
       Spell(NearestEnemyOf(Myself),WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
       SetGlobal("DavaeornBehavior","AR1803",6)
END

IF
   See(NearestEnemyOf(Myself))
   Global("DavaeornBehavior","AR1803",5)
   HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
   HaveSpell(WIZARD_LIGHTNING_BOLT)  // SPWI308.SPL (Lightning Bolt)
THEN
   RESPONSE #30
       ForceSpellPoint([1280.870],WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
       VerbalConstant(Myself,12)
       Wait(1)
       Spell(NearestEnemyOf(Myself),WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
       SetGlobal("DavaeornBehavior","AR1803",6)
   RESPONSE #30
       ForceSpellPoint([787.445],WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
       VerbalConstant(Myself,13)
       Wait(2)
       Spell(NearestEnemyOf(Myself),WIZARD_LIGHTNING_BOLT)  // SPWI308.SPL (Lightning Bolt)
       SetGlobal("DavaeornBehavior","AR1803",6)
END

IF
   See(NearestEnemyOf(Myself))
   Global("DavaeornBehavior","AR1803",5)
   HaveSpell(WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
   HaveSpell(WIZARD_LIGHTNING_BOLT)  // SPWI308.SPL (Lightning Bolt)
THEN
   RESPONSE #30
       ForceSpellPoint([290.790],WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
       VerbalConstant(Myself,10)
       Wait(1)
       Spell(NearestEnemyOf(Myself),WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
       SetGlobal("DavaeornBehavior","AR1803",6)
   RESPONSE #30
       ForceSpellPoint([787.445],WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
       VerbalConstant(Myself,11)
       Wait(2)
       Spell(NearestEnemyOf(Myself),WIZARD_LIGHTNING_BOLT)  // SPWI308.SPL (Lightning Bolt)
       SetGlobal("DavaeornBehavior","AR1803",6)
END

IF
   See(NearestEnemyOf(Myself))
THEN
   RESPONSE #100
       AttackReevaluate(NearestEnemyOf(Myself),15)
END
Code:
IF
   StateCheck(Myself,STATE_PANIC)
THEN
   RESPONSE #100
       RandomWalkContinuous()
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))
   InWeaponRange(LastSeenBy(Myself))
THEN
   RESPONSE #100
       AttackReevaluate(NearestEnemyOf(Myself),30)
END

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

IF
   See(NearestEnemyOf(Myself))
THEN
   RESPONSE #100
       MoveToObject(LastSeenBy(Myself))
END

Sword Coast Stratagems:
Code:
IF
   Detect([PC])
   NumberOfTimesTalkedTo(0)
THEN
   RESPONSE #100
       VerbalConstant(Myself,INITIAL_MEETING)
       SetGlobal("Davaeorn_Activate_Horrors","AR1803",1)
       SetGlobalTimer("DMWWFlunkyTimer","AR1803",FOUR_ROUNDS)
       StartDialog("davaeo",LastSeenBy(Myself))
END

IF
   !GlobalTimerNotExpired("castspell","LOCALS")
   !GlobalTimerNotExpired("daveorn_jump","LOCALS")
   Range(NearestEnemyOf(Myself),5)
   !StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
   Global("DavaeornTelTrack","LOCALS",0)
   HaveSpell(WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
THEN
   RESPONSE #100
       SetGlobal("DavaeornTelTrack","LOCALS",1)
       SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
       SetGlobalTimer("davaeorn_jump","LOCALS",TWO_ROUNDS)
       VerbalConstant(Myself,BATTLE_CRY4)
       ReallyForceSpellPoint([788.460],WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
       RemoveSpell(WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
       Wait(3)
   RESPONSE #100
       SetGlobal("DavaeornTelTrack","LOCALS",2)
       SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
       SetGlobalTimer("davaeorn_jump","LOCALS",TWO_ROUNDS)
       VerbalConstant(Myself,BATTLE_CRY3)
       ReallyForceSpellPoint([1275.825],WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
       RemoveSpell(WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
       Wait(3)
   RESPONSE #100
       SetGlobal("DavaeornTelTrack","LOCALS",3)
       SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
       SetGlobalTimer("davaeorn_jump","LOCALS",TWO_ROUNDS)
       VerbalConstant(Myself,BATTLE_CRY5)
       ReallyForceSpellPoint([1360.425],WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
       RemoveSpell(WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
       Wait(3)
END

IF
   !GlobalTimerNotExpired("castspell","LOCALS")
   !GlobalTimerNotExpired("daveorn_jump","LOCALS")
   Range(NearestEnemyOf(Myself),5)
   !StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
   Global("DavaeornTelTrack","LOCALS",1)
   HaveSpell(WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
THEN
   RESPONSE #100
       SetGlobal("DavaeornTelTrack","LOCALS",0)
       SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
       SetGlobalTimer("davaeorn_jump","LOCALS",TWO_ROUNDS)
       VerbalConstant(Myself,BATTLE_CRY4)
       ReallyForceSpellPoint([714.888],WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
       RemoveSpell(WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
       Wait(3)
   RESPONSE #100
       SetGlobal("DavaeornTelTrack","LOCALS",2)
       SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
       SetGlobalTimer("davaeorn_jump","LOCALS",TWO_ROUNDS)
       VerbalConstant(Myself,BATTLE_CRY5)
       ReallyForceSpellPoint([1275.825],WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
       RemoveSpell(WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
       Wait(3)
   RESPONSE #100
       SetGlobal("DavaeornTelTrack","LOCALS",3)
       SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
       SetGlobalTimer("davaeorn_jump","LOCALS",TWO_ROUNDS)
       VerbalConstant(Myself,BATTLE_CRY3)
       ReallyForceSpellPoint([1360.425],WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
       RemoveSpell(WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
       Wait(3)
END

IF
   !GlobalTimerNotExpired("castspell","LOCALS")
   !GlobalTimerNotExpired("daveorn_jump","LOCALS")
   Range(NearestEnemyOf(Myself),5)
   !StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
   Global("DavaeornTelTrack","LOCALS",2)
   HaveSpell(WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
THEN
   RESPONSE #100
       SetGlobal("DavaeornTelTrack","LOCALS",1)
       SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
       SetGlobalTimer("davaeorn_jump","LOCALS",TWO_ROUNDS)
       VerbalConstant(Myself,BATTLE_CRY5)
       ReallyForceSpellPoint([788.460],WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
       RemoveSpell(WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
       Wait(3)
   RESPONSE #100
       SetGlobal("DavaeornTelTrack","LOCALS",0)
       SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
       SetGlobalTimer("davaeorn_jump","LOCALS",TWO_ROUNDS)
       VerbalConstant(Myself,BATTLE_CRY3)
       ReallyForceSpellPoint([714.888],WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
       RemoveSpell(WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
       Wait(3)
   RESPONSE #100
       SetGlobal("DavaeornTelTrack","LOCALS",3)
       SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
       SetGlobalTimer("davaeorn_jump","LOCALS",TWO_ROUNDS)
       VerbalConstant(Myself,BATTLE_CRY4)
       ReallyForceSpellPoint([1360.425],WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
       RemoveSpell(WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
       Wait(3)
END

IF
   !GlobalTimerNotExpired("castspell","LOCALS")
   !GlobalTimerNotExpired("daveorn_jump","LOCALS")
   Range(NearestEnemyOf(Myself),5)
   !StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
   Global("DavaeornTelTrack","LOCALS",3)
   HaveSpell(WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
THEN
   RESPONSE #100
       SetGlobal("DavaeornTelTrack","LOCALS",1)
       SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
       SetGlobalTimer("davaeorn_jump","LOCALS",TWO_ROUNDS)
       VerbalConstant(Myself,BATTLE_CRY5)
       ReallyForceSpellPoint([788.460],WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
       RemoveSpell(WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
       Wait(3)
   RESPONSE #100
       SetGlobal("DavaeornTelTrack","LOCALS",2)
       SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
       SetGlobalTimer("davaeorn_jump","LOCALS",TWO_ROUNDS)
       VerbalConstant(Myself,BATTLE_CRY4)
       ReallyForceSpellPoint([1275.825],WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
       RemoveSpell(WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
       Wait(3)
   RESPONSE #100
       SetGlobal("DavaeornTelTrack","LOCALS",0)
       SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
       SetGlobalTimer("davaeorn_jump","LOCALS",TWO_ROUNDS)
       VerbalConstant(Myself,BATTLE_CRY3)
       ReallyForceSpellPoint([714.888],WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
       RemoveSpell(WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
       Wait(3)
END

Code:
IF
    Global("caster_label_ini","LOCALS",0)
THEN
    RESPONSE #100
        SetGlobal("caster_label_ini","LOCALS",1)
        ApplySpellRES("dw#calab",Myself)  // No such index
        Continue()
END

IF
    Global("invis_anim","LOCALS",0)
    StateCheck(Myself,STATE_INVISIBLE)
THEN
    RESPONSE #100
        SetGlobal("invis_anim","LOCALS",1)
        ApplySpellRES("dw#hdani",Myself)  // No such index
        Continue()
END

IF
    Global("invis_anim","LOCALS",1)
    !StateCheck(Myself,STATE_INVISIBLE)
THEN
    RESPONSE #100
        SetGlobal("invis_anim","LOCALS",0)
        ApplySpellRES("dw#blhda",Myself)  // No such index
        Continue()
END

IF
    Allegiance(Myself,ENEMY)
    Range(Player1,30)
    !GlobalTimerNotExpired("thief_detection","LOCALS")
    CheckStatGT(Player1,65,DETECTILLUSIONS)
    ModalStateObject(Player1,DETECTTRAPS)
THEN
    RESPONSE #100
        SetGlobalTimer("thief_detection","LOCALS",ONE_MINUTE)
        Continue()
END

IF
    Allegiance(Myself,ENEMY)
    Range(Player2,30)
    !GlobalTimerNotExpired("thief_detection","LOCALS")
    CheckStatGT(Player2,65,DETECTILLUSIONS)
    ModalStateObject(Player2,DETECTTRAPS)
THEN
    RESPONSE #100
        SetGlobalTimer("thief_detection","LOCALS",ONE_MINUTE)
        Continue()
END

IF
    Allegiance(Myself,ENEMY)
    Range(Player3,30)
    !GlobalTimerNotExpired("thief_detection","LOCALS")
    CheckStatGT(Player3,65,DETECTILLUSIONS)
    ModalStateObject(Player3,DETECTTRAPS)
THEN
    RESPONSE #100
        SetGlobalTimer("thief_detection","LOCALS",ONE_MINUTE)
        Continue()
END

IF
    Allegiance(Myself,ENEMY)
    Range(Player4,30)
    !GlobalTimerNotExpired("thief_detection","LOCALS")
    CheckStatGT(Player4,65,DETECTILLUSIONS)
    ModalStateObject(Player4,DETECTTRAPS)
THEN
    RESPONSE #100
        SetGlobalTimer("thief_detection","LOCALS",ONE_MINUTE)
        Continue()
END

IF
    Allegiance(Myself,ENEMY)
    Range(Player5,30)
    !GlobalTimerNotExpired("thief_detection","LOCALS")
    CheckStatGT(Player5,65,DETECTILLUSIONS)
    ModalStateObject(Player5,DETECTTRAPS)
THEN
    RESPONSE #100
        SetGlobalTimer("thief_detection","LOCALS",ONE_MINUTE)
        Continue()
END

IF
    Allegiance(Myself,ENEMY)
    Range(Player6,30)
    !GlobalTimerNotExpired("thief_detection","LOCALS")
    CheckStatGT(Player6,65,DETECTILLUSIONS)
    ModalStateObject(Player6,DETECTTRAPS)
THEN
    RESPONSE #100
        SetGlobalTimer("thief_detection","LOCALS",ONE_MINUTE)
        Continue()
END

IF
    AttackedBy([ENEMY.UNDEAD],DEFAULT)
    Allegiance(LastAttackerOf(Myself),ENEMY)
    General(LastAttackerOf(Myself),UNDEAD)
    Allegiance(Myself,ENEMY)
THEN
    RESPONSE #100
        ClearActions(LastAttackerOf(Myself))
        Continue()
END

IF
    StateCheck(Myself,STATE_PANIC)
THEN
    RESPONSE #100
        RandomWalkContinuous()
END

IF
    See(NearestEnemyOf(Myself))
    Global("rest","LOCALS",0)
THEN
    RESPONSE #100
        SetGlobalTimer("rtime","LOCALS",2000)
        SetGlobal("rest","LOCALS",1)
        Continue()
END

IF
    Global("rest","LOCALS",1)
    !GlobalTimerNotExpired("rtime","LOCALS")
    !Detect(NearestEnemyOf(Myself))
THEN
    RESPONSE #100
        SetGlobal("instantprep","LOCALS",0)
        SetGlobal("chaincontingencyfired","LOCALS",0)
        SetGlobal("contingencyfired","LOCALS",0)
        SetGlobal("teleportpursue","LOCALS",0)
        SetGlobalTimer("redefend","LOCALS",2000)
        ApplySpell(Myself,RESTORE_FULL_HEALTH)  // SPIN746.SPL (No such index)
        Rest()
END

IF
    OR(2)
        Global("DMWW_mage_difficulty","GLOBAL",0)
        GlobalGT("DMWW_mage_difficulty","GLOBAL",2)
    OR(2)
        DifficultyGT(EASY)
        GlobalGT("DMWW_mage_difficulty","GLOBAL",2)
    Detect([PC])
    !See([PC])
    Allegiance(Myself,ENEMY)
    !StateCheck(Myself,STATE_INVISIBLE)
    !GlobalTimerNotExpired("detect","LOCALS")
THEN
    RESPONSE #50
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        SetGlobalTimer("detect","LOCALS",1000)
        DisplayString(Myself,49139)  // Hmmm... what was that?
        SpellNoDec(Myself,WIZARD_DETECT_INVISIBILITY)  // SPWI203.SPL (Detect Invisibility)
    RESPONSE #50
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        SetGlobalTimer("detect","LOCALS",1000)
        DisplayString(Myself,49140)  // Strange... let's see what a little divination will show.
        SpellNoDec(Myself,WIZARD_DETECT_INVISIBILITY)  // SPWI203.SPL (Detect Invisibility)
    RESPONSE #50
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        SetGlobalTimer("detect","LOCALS",1000)
        DisplayString(Myself,49141)  // Show yourself! You cannot hide from a mage!
        SpellNoDec(Myself,WIZARD_DETECT_INVISIBILITY)  // SPWI203.SPL (Detect Invisibility)
    RESPONSE #50
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        SetGlobalTimer("detect","LOCALS",1000)
        DisplayString(Myself,49142)  // Come out, spy... I can sense your presence
        SpellNoDec(Myself,WIZARD_DETECT_INVISIBILITY)  // SPWI203.SPL (Detect Invisibility)
    RESPONSE #800
        SetGlobalTimer("detect","LOCALS",FIVE_ROUNDS)
        Continue()
END

IF
    See(NearestEnemyOf(Myself))
    !Global("chasing","LOCALS",0)
THEN
    RESPONSE #100
        SetGlobal("chasing","LOCALS",0)
        ClearActions(Myself)
END

IF
    !GlobalTimerNotExpired("chasetarget","LOCALS")
    Allegiance(Myself,ENEMY)
    See(Player1)
THEN
    RESPONSE #100
        SetGlobalTimer("chasetarget","LOCALS",ONE_HOUR)
        SetGlobal("chasePC","LOCALS",1)
        Continue()
END

IF
    !GlobalTimerNotExpired("chasetarget","LOCALS")
    Allegiance(Myself,ENEMY)
    See(Player2)
THEN
    RESPONSE #100
        SetGlobalTimer("chasetarget","LOCALS",ONE_HOUR)
        SetGlobal("chasePC","LOCALS",2)
        Continue()
END

IF
    !GlobalTimerNotExpired("chasetarget","LOCALS")
    Allegiance(Myself,ENEMY)
    See(Player3)
THEN
    RESPONSE #100
        SetGlobalTimer("chasetarget","LOCALS",ONE_HOUR)
        SetGlobal("chasePC","LOCALS",3)
        Continue()
END

IF
    !GlobalTimerNotExpired("chasetarget","LOCALS")
    Allegiance(Myself,ENEMY)
    See(Player4)
THEN
    RESPONSE #100
        SetGlobalTimer("chasetarget","LOCALS",ONE_HOUR)
        SetGlobal("chasePC","LOCALS",4)
        Continue()
END

IF
    !GlobalTimerNotExpired("chasetarget","LOCALS")
    Allegiance(Myself,ENEMY)
    See(Player5)
THEN
    RESPONSE #100
        SetGlobalTimer("chasetarget","LOCALS",ONE_HOUR)
        SetGlobal("chasePC","LOCALS",5)
        Continue()
END

IF
    !GlobalTimerNotExpired("chasetarget","LOCALS")
    Allegiance(Myself,ENEMY)
    See(Player6)
THEN
    RESPONSE #100
        SetGlobalTimer("chasetarget","LOCALS",ONE_HOUR)
        SetGlobal("chasePC","LOCALS",6)
        Continue()
END

IF
    Global("chasePC","LOCALS",1)
    StateCheck(Player1,STATE_REALLY_DEAD)
THEN
    RESPONSE #100
        SetGlobal("chasePC","LOCALS",0)
        Continue()
END

IF
    Global("chasePC","LOCALS",2)
    StateCheck(Player2,STATE_REALLY_DEAD)
THEN
    RESPONSE #100
        SetGlobal("chasePC","LOCALS",0)
        Continue()
END

IF
    Global("chasePC","LOCALS",3)
    StateCheck(Player3,STATE_REALLY_DEAD)
THEN
    RESPONSE #100
        SetGlobal("chasePC","LOCALS",0)
        Continue()
END

IF
    Global("chasePC","LOCALS",4)
    StateCheck(Player4,STATE_REALLY_DEAD)
THEN
    RESPONSE #100
        SetGlobal("chasePC","LOCALS",0)
        Continue()
END

IF
    Global("chasePC","LOCALS",5)
    StateCheck(Player5,STATE_REALLY_DEAD)
THEN
    RESPONSE #100
        SetGlobal("chasePC","LOCALS",0)
        Continue()
END

IF
    Global("chasePC","LOCALS",6)
    StateCheck(Player6,STATE_REALLY_DEAD)
THEN
    RESPONSE #100
        SetGlobal("chasePC","LOCALS",0)
        Continue()
END

IF
    Global("created_out_of_sight","LOCALS",0)
    OR(2)
        !Allegiance(Myself,ENEMY)
        !See(NearestEnemyOf(Myself))
THEN
    RESPONSE #100
        SetGlobal("created_out_of_sight","LOCALS",1)
        Continue()
END

IF
    !Allegiance(Myself,ENEMY)
    OR(14)
        AttackedBy([GOODCUTOFF.0.0.0.0.SUMMONED],DEFAULT)
        AttackedBy([PC],DEFAULT)
        AttackedBy([FAMILIAR],DEFAULT)
        AttackedBy([ALLY],DEFAULT)
        AttackedBy([CONTROLLED],DEFAULT)
        AttackedBy([CHARMED],DEFAULT)
        SpellCastOnMeRES("",[GOODCUTOFF.0.0.0.0.SUMMONED])
        SpellCastOnMe([GOODCUTOFF],WIZARD_BLINDNESS)  // SPWI106.SPL (Blindness)
        SpellCastOnMe([GOODCUTOFF],WIZARD_FEEBLEMIND)  // SPWI509.SPL (Feeblemind)
        SpellCastOnMe([GOODCUTOFF],WIZARD_CHARM_PERSON)  // SPWI104.SPL (Charm Person)
        SpellCastOnMe([GOODCUTOFF],WIZARD_DIRE_CHARM)  // SPWI316.SPL (Dire Charm)
        SpellCastOnMe([GOODCUTOFF],CLERIC_CHARM_PERSON)  // SPPR204.SPL (Charm Person or Mammal)
        SpellCastOnMe([GOODCUTOFF],CLERIC_MENTAL_DOMINATION)  // SPPR405.SPL (Mental Domination)
        SpellCastOnMe([GOODCUTOFF],WIZARD_RAY_OF_ENFEEBLEMENT)  // SPWI221.SPL (Ray of Enfeeblement)
THEN
    RESPONSE #100
        Enemy()
        Continue()
END

IF
    Heard([ANYONE],404)
    !General(Myself,UNDEAD)
    !Race(Myself,RAKSHASA)
    !Race(Myself,DEMONIC)
    !See([PC])
    Range(LastHeardBy(Myself),20)
THEN
    RESPONSE #100
        SetInterrupt(FALSE)
        RunAwayFromNoLeaveArea(LastHeardBy(Myself),45)
        SetInterrupt(TRUE)
END

IF
    !Allegiance(Myself,ENEMY)
    !Global("DMWWNeutralPrebuff","GLOBAL",1)
THEN
    RESPONSE #100
        NoAction()
END

IF
    Global("invnc","LOCALS",0)
    !Allegiance(Myself,ENEMY)
THEN
    RESPONSE #100
        SetGlobal("invnc","LOCALS",1)
END

IF
    HaveSpell(WIZARD_MIRROR_IMAGE)  // SPWI212.SPL (Mirror Image)
    Global("instantprep","LOCALS",0)
    OR(2)
        See(NearestEnemyOf(Myself))
        Global("offscreenprep","LOCALS",1)
    HPPercentGT(Myself,0)
    OR(3)
        Global("DMWW_mage_prep_difficulty","GLOBAL",0)
        Global("DMWW_mage_prep_difficulty","GLOBAL",4)
        Global("DMWW_mage_prep_difficulty","GLOBAL",5)
    OR(3)
        !Global("DMWW_mage_prep_difficulty","GLOBAL",0)
        Difficulty(HARD)
        Difficulty(HARDEST)
    OR(3)
        Global("created_out_of_sight","LOCALS",0)
        Global("DMWW_mage_prep_difficulty","GLOBAL",0)
        Global("DMWW_mage_prep_difficulty","GLOBAL",5)
    OR(3)
        Global("created_out_of_sight","LOCALS",0)
        Difficulty(HARDEST)
        Global("DMWW_mage_prep_difficulty","GLOBAL",5)
THEN
    RESPONSE #100
        ReallyForceSpellRES("dwsw212",Myself)  // Mirror Image (cast previously)
        RemoveSpell(WIZARD_MIRROR_IMAGE)  // SPWI212.SPL (Mirror Image)
        Continue()
END

IF
    HaveSpell(WIZARD_MINOR_GLOBE_OF_INVULNERABILITY)  // SPWI406.SPL (Minor Globe of Invulnerability)
    Global("instantprep","LOCALS",0)
    OR(2)
        See(NearestEnemyOf(Myself))
        Global("offscreenprep","LOCALS",1)
    HPPercentGT(Myself,0)
    OR(3)
        Global("DMWW_mage_prep_difficulty","GLOBAL",0)
        Global("DMWW_mage_prep_difficulty","GLOBAL",4)
        Global("DMWW_mage_prep_difficulty","GLOBAL",5)
    OR(3)
        !Global("DMWW_mage_prep_difficulty","GLOBAL",0)
        Difficulty(HARD)
        Difficulty(HARDEST)
    OR(3)
        Global("created_out_of_sight","LOCALS",0)
        Global("DMWW_mage_prep_difficulty","GLOBAL",0)
        Global("DMWW_mage_prep_difficulty","GLOBAL",5)
    OR(3)
        Global("created_out_of_sight","LOCALS",0)
        Difficulty(HARDEST)
        Global("DMWW_mage_prep_difficulty","GLOBAL",5)
THEN
    RESPONSE #100
        ReallyForceSpellRES("dwsw406",Myself)  // Minor Globe of Invulnerability (cast previously)
        RemoveSpell(WIZARD_MINOR_GLOBE_OF_INVULNERABILITY)  // SPWI406.SPL (Minor Globe of Invulnerability)
        Continue()
END

IF
    HaveSpell(WIZARD_MINOR_SPELL_TURNING)  // SPWI522.SPL (Minor Spell Turning)
    Global("instantprep","LOCALS",0)
    OR(2)
        See(NearestEnemyOf(Myself))
        Global("offscreenprep","LOCALS",1)
    HPPercentGT(Myself,0)
    OR(3)
        Global("DMWW_mage_prep_difficulty","GLOBAL",0)
        Global("DMWW_mage_prep_difficulty","GLOBAL",3)
        Global("DMWW_mage_prep_difficulty","GLOBAL",4)
    OR(3)
        !Global("DMWW_mage_prep_difficulty","GLOBAL",0)
        Difficulty(NORMAL)
        Difficulty(HARD)
    OR(3)
        Global("created_out_of_sight","LOCALS",0)
        Global("DMWW_mage_prep_difficulty","GLOBAL",0)
        Global("DMWW_mage_prep_difficulty","GLOBAL",4)
    OR(3)
        Global("created_out_of_sight","LOCALS",0)
        Difficulty(HARD)
        Global("DMWW_mage_prep_difficulty","GLOBAL",4)
    OR(3)
        !Global("created_out_of_sight","LOCALS",0)
        Global("DMWW_mage_prep_difficulty","GLOBAL",0)
        Global("DMWW_mage_prep_difficulty","GLOBAL",3)
    OR(3)
        !Global("created_out_of_sight","LOCALS",0)
        Difficulty(NORMAL)
        Global("DMWW_mage_prep_difficulty","GLOBAL",3)
THEN
    RESPONSE #100
        ReallyForceSpellRES("dwsw522",Myself)  // Minor Spell Turning (cast previously)
        RemoveSpell(WIZARD_MINOR_SPELL_TURNING)  // SPWI522.SPL (Minor Spell Turning)
        Continue()
END

IF
    HaveSpell(WIZARD_MINOR_SPELL_TURNING)  // SPWI522.SPL (Minor Spell Turning)
    Global("instantprep","LOCALS",0)
    OR(2)
        See(NearestEnemyOf(Myself))
        Global("offscreenprep","LOCALS",1)
    HPPercentGT(Myself,0)
    OR(3)
        Global("DMWW_mage_prep_difficulty","GLOBAL",0)
        Global("DMWW_mage_prep_difficulty","GLOBAL",4)
        Global("DMWW_mage_prep_difficulty","GLOBAL",5)
    OR(3)
        !Global("DMWW_mage_prep_difficulty","GLOBAL",0)
        Difficulty(HARD)
        Difficulty(HARDEST)
    OR(3)
        Global("created_out_of_sight","LOCALS",0)
        Global("DMWW_mage_prep_difficulty","GLOBAL",0)
        Global("DMWW_mage_prep_difficulty","GLOBAL",5)
    OR(3)
        Global("created_out_of_sight","LOCALS",0)
        Difficulty(HARDEST)
        Global("DMWW_mage_prep_difficulty","GLOBAL",5)
THEN
    RESPONSE #100
        ReallyForceSpellRES("dwsw522",Myself)  // Minor Spell Turning (cast previously)
        RemoveSpell(WIZARD_MINOR_SPELL_TURNING)  // SPWI522.SPL (Minor Spell Turning)
        Continue()
END

IF
    HaveSpell(WIZARD_PROTECTION_FROM_NORMAL_MISSILES)  // SPWI311.SPL (Protection From Normal Missiles)
    Global("instantprep","LOCALS",0)
    OR(2)
        See(NearestEnemyOf(Myself))
        Global("offscreenprep","LOCALS",1)
    HPPercentGT(Myself,0)
    OR(2)
        Global("DMWW_mage_prep_difficulty","GLOBAL",0)
        GlobalGT("DMWW_mage_prep_difficulty","GLOBAL",2)
    OR(2)
        DifficultyGT(EASY)
        GlobalGT("DMWW_mage_prep_difficulty","GLOBAL",2)
THEN
    RESPONSE #100
        ReallyForceSpellRES("dwsw311",Myself)  // Protection From Normal Missiles (cast previously)
        RemoveSpell(WIZARD_PROTECTION_FROM_NORMAL_MISSILES)  // SPWI311.SPL (Protection From Normal Missiles)
        Continue()
END

IF
    !Global("DMWW_mage_prep_difficulty","GLOBAL",1)
    OR(2)
        !Global("DMWW_mage_prep_difficulty","GLOBAL",0)
        !Difficulty(EASIEST)
    Global("instantprep","LOCALS",0)
    See(NearestEnemyOf(Myself))
    HPPercentGT(Myself,0)
THEN
    RESPONSE #100
        ReallyForceSpellRES("dwsw408",Myself)  // Stoneskin (cast previously)
        Continue()
END

IF
    GlobalTimerNotExpired("invimp","LOCALS")
THEN
    RESPONSE #100
        RandomWalk()
END

IF
    Global("inafight","LOCALS",0)
    See(NearestEnemyOf(Myself))
THEN
    RESPONSE #100
        SetGlobal("inafight","LOCALS",1)
        Continue()
END

IF
    Global("instantprep","LOCALS",0)
    !GlobalTimerNotExpired("davaeorn_sequencer","LOCALS")
    See(NearestEnemyOf(Myself))
    !GlobalTimerNotExpired("castspell","LOCALS")
THEN
    RESPONSE #100
        SetGlobalTimer("davaeorn_sequencer","LOCALS",1000)
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ReallyForceSpellPointRES("dw#ms12B",[1072.653])  // Minor Sequencer
        ReallyForceSpellPoint([1072.653],WIZARD_WEB)  // SPWI215.SPL (Web)
        SmallWait(1)
        ReallyForceSpellPoint([1072.653],WIZARD_STINKING_CLOUD)  // SPWI213.SPL (Stinking Cloud)
END

IF
    !GlobalGT("DMWW_mage_prep_difficulty","GLOBAL",2)
    OR(2)
        !Global("DMWW_mage_prep_difficulty","GLOBAL",0)
        !DifficultyGT(EASY)
    Global("instantprep","LOCALS",0)
    See(NearestEnemyOf(Myself))
THEN
    RESPONSE #100
        SetGlobalTimer("redefend","LOCALS",0)
        SetGlobal("instantprep","LOCALS",1)
END

IF
    OR(2)
        Global("DMWW_mage_prep_difficulty","GLOBAL",0)
        GlobalGT("DMWW_mage_prep_difficulty","GLOBAL",2)
    OR(2)
        DifficultyGT(EASY)
        GlobalGT("DMWW_mage_prep_difficulty","GLOBAL",2)
    Global("instantprep","LOCALS",0)
    See(NearestEnemyOf(Myself))
THEN
    RESPONSE #100
        SetGlobalTimer("redefend","LOCALS",ONE_MINUTE)
        SetGlobal("instantprep","LOCALS",1)
        Continue()
END

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

IF
    !Detect(NearestEnemyOf(Myself))
    !HPPercentLT(Myself,100)
    !Global("inafight","LOCALS",1)
THEN
    RESPONSE #100
        NoAction()
END

IF
    OR(2)
        ActionListEmpty()
        !GlobalTimerExpired("castspell","LOCALS")
    !Global("DMWW_mage_difficulty","GLOBAL",1)
    OR(2)
        DifficultyGT(EASIEST)
        GlobalGT("DMWW_mage_difficulty","GLOBAL",0)
    Heard([ANYONE],407)
    Range(LastHeardBy(Myself),20)
    OR(3)
        !CheckStatGT(Myself,99,RESISTACID)
        !CheckStatGT(Myself,99,RESISTFIRE)
        !CheckStatGT(Myself,99,RESISTELECTRICITY)
    OR(2)
        !CheckStatGT(Myself,80,RESISTMAGIC)
        !See(NearestEnemyOf(Myself))
THEN
    RESPONSE #100
        SetGlobalTimer("seencloud","LOCALS",FOUR_MINUTES)
        RunAwayFromNoLeaveArea(LastHeardBy(Myself),30)
END

IF
    OR(2)
        ActionListEmpty()
        !GlobalTimerExpired("castspell","LOCALS")
    !Global("DMWW_mage_difficulty","GLOBAL",1)
    OR(2)
        DifficultyGT(EASIEST)
        GlobalGT("DMWW_mage_difficulty","GLOBAL",0)
    OR(2)
        Heard([ANYONE],405)
        Heard([ANYONE],409)
    Range(LastHeardBy(Myself),20)
    !CheckStatGT(Myself,99,RESISTFIRE)
    OR(2)
        !CheckStatGT(Myself,79,RESISTMAGIC)
        !See(NearestEnemyOf(Myself))
    OR(2)
        !CheckStatGT(Myself,59,RESISTFIRE)
        !See(NearestEnemyOf(Myself))
THEN
    RESPONSE #100
        SetGlobalTimer("seencloud","LOCALS",FOUR_MINUTES)
        RunAwayFromNoLeaveArea(LastHeardBy(Myself),30)
END

IF
    OR(2)
        ActionListEmpty()
        !GlobalTimerExpired("castspell","LOCALS")
    !Global("DMWW_mage_difficulty","GLOBAL",1)
    OR(2)
        DifficultyGT(EASIEST)
        GlobalGT("DMWW_mage_difficulty","GLOBAL",0)
    Heard([ANYONE],408)
    Range(LastHeardBy(Myself),20)
    !CheckStatGT(Myself,99,RESISTACID)
    OR(2)
        !CheckStatGT(Myself,80,RESISTMAGIC)
        !See(NearestEnemyOf(Myself))
    OR(2)
        !CheckStatGT(Myself,59,RESISTACID)
        !See(NearestEnemyOf(Myself))
THEN
    RESPONSE #100
        SetGlobalTimer("seencloud","LOCALS",FOUR_MINUTES)
        RunAwayFromNoLeaveArea(LastHeardBy(Myself),30)
END

IF
    OR(2)
        ActionListEmpty()
        !GlobalTimerExpired("castspell","LOCALS")
    !Global("DMWW_mage_difficulty","GLOBAL",1)
    OR(2)
        DifficultyGT(EASIEST)
        GlobalGT("DMWW_mage_difficulty","GLOBAL",0)
    Heard([ANYONE],404)
    Range(LastHeardBy(Myself),20)
    !General(Myself,UNDEAD)
    !Race(Myself,DEMONIC)
    OR(2)
        !CheckStatGT(Myself,80,RESISTMAGIC)
        !See(NearestEnemyOf(Myself))
THEN
    RESPONSE #100
        SetGlobalTimer("seencloud","LOCALS",FOUR_MINUTES)
        RunAwayFromNoLeaveArea(LastHeardBy(Myself),30)
END

IF
    OR(2)
        ActionListEmpty()
        !GlobalTimerExpired("castspell","LOCALS")
    !Global("DMWW_mage_difficulty","GLOBAL",1)
    OR(2)
        DifficultyGT(EASIEST)
        GlobalGT("DMWW_mage_difficulty","GLOBAL",0)
    Heard([ANYONE],411)
    Range(LastHeardBy(Myself),15)
    !CheckStatGT(Myself,0,MINORGLOBE)
    !General(Myself,UNDEAD)
    !Race(Myself,DEMONIC)
    OR(2)
        !CheckStatGT(Myself,80,RESISTMAGIC)
        !See(NearestEnemyOf(Myself))
THEN
    RESPONSE #100
        SetGlobalTimer("seencloud","LOCALS",FOUR_MINUTES)
        RunAwayFromNoLeaveArea(LastHeardBy(Myself),30)
END

IF
    OR(2)
        ActionListEmpty()
        !GlobalTimerExpired("castspell","LOCALS")
    See(Myself)
    !Kit(Myself,UNDEADHUNTER)
    !Kit(Myself,INQUISITOR)
    !CheckStatGT(Myself,0,CLERIC_FREE_ACTION)
    !CheckSpellState(Myself,STATE_ENRAGED)
    OR(2)
        !CheckSpellState(Myself,ITEM_HOLD_SEEN)
        !CheckSpellState(Myself,ITEM_HOLD)
    OR(2)
        !CheckSpellState(Myself,ITEM_HOLD_SEEN)
        !CheckSpellState(Myself,ITEM_HOLD)
    OR(2)
        !CheckSpellState(Myself,ITEM_HOLD_SEEN)
        !CheckSpellState(Myself,ITEM_HOLD)
    OR(2)
        !CheckSpellState(Myself,ITEM_ANTIWEB_SEEN)
        !CheckSpellState(Myself,ITEM_ANTIWEB)
    !Global("DMWW_mage_difficulty","GLOBAL",1)
    OR(2)
        DifficultyGT(EASIEST)
        GlobalGT("DMWW_mage_difficulty","GLOBAL",0)
    !CheckStatGT(Myself,0,MINORGLOBE)
    Heard([ANYONE],410)
    Range(LastHeardBy(Myself),15)
    OR(2)
        !CheckStatGT(Myself,80,RESISTMAGIC)
        !See(NearestEnemyOf(Myself))
THEN
    RESPONSE #100
        SetGlobalTimer("seencloud","LOCALS",FOUR_MINUTES)
        RunAwayFromNoLeaveArea(LastHeardBy(Myself),30)
END

IF
    OR(2)
        ActionListEmpty()
        !GlobalTimerExpired("castspell","LOCALS")
    See(Myself)
    !Global("DMWW_mage_difficulty","GLOBAL",1)
    OR(2)
        DifficultyGT(EASIEST)
        GlobalGT("DMWW_mage_difficulty","GLOBAL",0)
    Heard([ANYONE],412)
    Range(LastHeardBy(Myself),20)
    OR(2)
        !CheckStatGT(Myself,80,RESISTMAGIC)
        !See(NearestEnemyOf(Myself))
    OR(2)
        !CheckStatGT(Myself,59,RESISTCOLD)
        !See(NearestEnemyOf(Myself))
THEN
    RESPONSE #100
        SetGlobalTimer("seencloud","LOCALS",FOUR_MINUTES)
        RunAwayFromNoLeaveArea(LastHeardBy(Myself),30)
END

IF
    GlobalTimerNotExpired("melfinit","LOCALS")
    !HasItem("dw#missl",Myself)  // Mirror
THEN
    RESPONSE #100
        SetGlobal("melfnum","LOCALS",0)
        SetGlobal("eneblade","LOCALS",0)
        Continue()
END

IF
    !GlobalTimerNotExpired("melfinit","LOCALS")
    OR(2)
        Global("DMWW_mage_difficulty","GLOBAL",0)
        GlobalGT("DMWW_mage_difficulty","GLOBAL",3)
    OR(2)
        DifficultyGT(NORMAL)
        GlobalGT("DMWW_mage_difficulty","GLOBAL",3)
THEN
    RESPONSE #100
        SetGlobalTimer("melfinit","LOCALS",1000)
        SetGlobal("melfnum","LOCALS",5)
        GiveItemCreate("dw#missl",Myself,0,0,0)  // Mirror
        Continue()
END

IF
    GlobalGT("eneblade","LOCALS",0)
    !HasItem("dw#eneb",Myself)  // Energy Blade
    HasItem("dw#missl",Myself)  // Mirror
    OR(2)
        Global("DMWW_mage_difficulty","GLOBAL",0)
        GlobalGT("DMWW_mage_difficulty","GLOBAL",3)
    OR(2)
        DifficultyGT(NORMAL)
        GlobalGT("DMWW_mage_difficulty","GLOBAL",3)
THEN
    RESPONSE #100
        IncrementGlobal("eneblade","LOCALS",-1)
        ApplySpellRES("dw#eneb",Myself)  // Tazok found it comical and ordered me beaten in front of Deheriana, and pretended that her pleas might touch his heart. If only she tried a little harder...
        Continue()
END

IF
    GlobalGT("melfnum","LOCALS",0)
    !HasItem("dw#melf",Myself)  // Melf's Minute Meteor
    HasItem("dw#missl",Myself)  // Mirror
    OR(2)
        Global("DMWW_mage_difficulty","GLOBAL",0)
        GlobalGT("DMWW_mage_difficulty","GLOBAL",3)
    OR(2)
        DifficultyGT(NORMAL)
        GlobalGT("DMWW_mage_difficulty","GLOBAL",3)
THEN
    RESPONSE #100
        IncrementGlobal("melfnum","LOCALS",-1)
        ApplySpellRES("dw#melf",Myself)  // Tazok found it comical and ordered me beaten in front of Deheriana, and pretended that her pleas might touch his heart. If only she tried a little harder...
        Continue()
END

IF
    GlobalTimerNotExpired("castspell","LOCALS")
    GlobalLT("DMWW_mage_difficulty","GLOBAL",2)
    OR(2)
        Difficulty(EASIEST)
        !Global("DMWW_mage_difficulty","GLOBAL",0)
THEN
    RESPONSE #100
        Wait(1)
END

IF
    GlobalTimerNotExpired("castspell","LOCALS")
    Allegiance(Myself,ENEMY)
    OR(12)
        AttackedBy([GOODCUTOFF.0.0.0.0.SUMMONED],DEFAULT)
        AttackedBy([PC],DEFAULT)
        AttackedBy([FAMILIAR],DEFAULT)
        AttackedBy([ALLY],DEFAULT)
        AttackedBy([CONTROLLED],DEFAULT)
        AttackedBy([CHARMED],DEFAULT)
        SpellCastOnMeRES("",[GOODCUTOFF.0.0.0.0.SUMMONED])
        SpellCastOnMeRES("",[PC])
        SpellCastOnMeRES("",[FAMILIAR])
        SpellCastOnMeRES("",[ALLY])
        SpellCastOnMeRES("",[CONTROLLED])
        SpellCastOnMeRES("",[CHARMED])
    !GlobalTimerNotExpired("whatthe","LOCALS")
    !See(NearestEnemyOf(Myself))
THEN
    RESPONSE #100
        SetGlobalTimer("whatthe","LOCALS",TWO_ROUNDS)
        Continue()
END

IF
    GlobalTimerNotExpired("castspell","LOCALS")
    !See(NearestEnemyOf(Myself))
    !Heard([ANYONE],404)
    GlobalTimerNotExpired("whatthe","LOCALS")
THEN
    RESPONSE #100
        RandomWalkContinuous()
END

IF
    GlobalTimerNotExpired("castspell","LOCALS")
    See(NearestEnemyOf(Myself))
    OR(4)
        !Heard([ANYONE],404)
        General(Myself,UNDEAD)
        Race(Myself,DEMONIC)
        Race(Myself,RAKSHASA)
    Range(NearestEnemyOf(Myself),8)
    !GlobalTimerNotExpired("teleportfield","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(NearestEnemyOf(Myself),ENEMY)
    !StateCheck(NearestEnemyOf(Myself),STATE_IMMOBILE)
    !StateCheck(NearestEnemyOf(Myself),STATE_FEEBLEMINDED)
    !CheckStatGT(NearestEnemyOf(Myself),0,HELD)
    OR(11)
        HaveSpell(WIZARD_CHARM_PERSON)  // SPWI104.SPL (Charm Person)
        HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
        HaveSpell(WIZARD_FLAME_ARROW)  // SPWI303.SPL (Flame Arrow)
        HaveSpell(WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
        HaveSpell(WIZARD_BLINDNESS)  // SPWI106.SPL (Blindness)
        HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
        HasItem("wand04",Myself)  // Wand of Paralyzation
        HasItem("wand05",Myself)  // Wand of Fire
        HasItem("wand06",Myself)  // Wand of Frost
        HasItem("wand07",Myself)  // Wand of Lightning
        HasItem("wand08",Myself)  // Wand of Sleep
    !HasItem("dw#move0",Myself)  // Mirror
    !HasItem("ghoult",Myself)  // Ghoul Touch
    !HasItem("msword",Myself)
    OR(2)
        Gender(Myself,ILLUSIONARY)
        !HasItem("dw#melf",Myself)  // Melf's Minute Meteor
    OR(2)
        Gender(Myself,ILLUSIONARY)
        !HasItem("dw#eneb",Myself)  // Energy Blade
THEN
    RESPONSE #100
        RunAwayFromNoLeaveArea(NearestEnemyOf(Myself),60)
END

IF
    GlobalTimerNotExpired("castspell","LOCALS")
    See(SecondNearestEnemyOf(Myself))
    OR(4)
        !Heard([ANYONE],404)
        General(Myself,UNDEAD)
        Race(Myself,DEMONIC)
        Race(Myself,RAKSHASA)
    Range(SecondNearestEnemyOf(Myself),8)
    !GlobalTimerNotExpired("teleportfield","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondNearestEnemyOf(Myself),ENEMY)
    !StateCheck(SecondNearestEnemyOf(Myself),STATE_IMMOBILE)
    !StateCheck(SecondNearestEnemyOf(Myself),STATE_FEEBLEMINDED)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,HELD)
    OR(11)
        HaveSpell(WIZARD_CHARM_PERSON)  // SPWI104.SPL (Charm Person)
        HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
        HaveSpell(WIZARD_FLAME_ARROW)  // SPWI303.SPL (Flame Arrow)
        HaveSpell(WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
        HaveSpell(WIZARD_BLINDNESS)  // SPWI106.SPL (Blindness)
        HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
        HasItem("wand04",Myself)  // Wand of Paralyzation
        HasItem("wand05",Myself)  // Wand of Fire
        HasItem("wand06",Myself)  // Wand of Frost
        HasItem("wand07",Myself)  // Wand of Lightning
        HasItem("wand08",Myself)  // Wand of Sleep
    !HasItem("dw#move0",Myself)  // Mirror
    !HasItem("ghoult",Myself)  // Ghoul Touch
    !HasItem("msword",Myself)
    OR(2)
        Gender(Myself,ILLUSIONARY)
        !HasItem("dw#melf",Myself)  // Melf's Minute Meteor
    OR(2)
        Gender(Myself,ILLUSIONARY)
        !HasItem("dw#eneb",Myself)  // Energy Blade
THEN
    RESPONSE #100
        RunAwayFromNoLeaveArea(SecondNearestEnemyOf(Myself),60)
END

IF
    GlobalTimerNotExpired("castspell","LOCALS")
    See(ThirdNearestEnemyOf(Myself))
    OR(4)
        !Heard([ANYONE],404)
        General(Myself,UNDEAD)
        Race(Myself,DEMONIC)
        Race(Myself,RAKSHASA)
    Range(ThirdNearestEnemyOf(Myself),8)
    !GlobalTimerNotExpired("teleportfield","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdNearestEnemyOf(Myself),ENEMY)
    !StateCheck(ThirdNearestEnemyOf(Myself),STATE_IMMOBILE)
    !StateCheck(ThirdNearestEnemyOf(Myself),STATE_FEEBLEMINDED)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,HELD)
    OR(11)
        HaveSpell(WIZARD_CHARM_PERSON)  // SPWI104.SPL (Charm Person)
        HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
        HaveSpell(WIZARD_FLAME_ARROW)  // SPWI303.SPL (Flame Arrow)
        HaveSpell(WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
        HaveSpell(WIZARD_BLINDNESS)  // SPWI106.SPL (Blindness)
        HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
        HasItem("wand04",Myself)  // Wand of Paralyzation
        HasItem("wand05",Myself)  // Wand of Fire
        HasItem("wand06",Myself)  // Wand of Frost
        HasItem("wand07",Myself)  // Wand of Lightning
        HasItem("wand08",Myself)  // Wand of Sleep
    !HasItem("dw#move0",Myself)  // Mirror
    !HasItem("ghoult",Myself)  // Ghoul Touch
    !HasItem("msword",Myself)
    OR(2)
        Gender(Myself,ILLUSIONARY)
        !HasItem("dw#melf",Myself)  // Melf's Minute Meteor
    OR(2)
        Gender(Myself,ILLUSIONARY)
        !HasItem("dw#eneb",Myself)  // Energy Blade
THEN
    RESPONSE #100
        RunAwayFromNoLeaveArea(ThirdNearestEnemyOf(Myself),60)
END

IF
    GlobalTimerNotExpired("castspell","LOCALS")
    See(NearestEnemyOf(Myself))
    Range(NearestEnemyOf(Myself),15)
    !Global("DMWW_mage_difficulty","GLOBAL",1)
    OR(2)
        DifficultyGT(EASIEST)
        GlobalGT("DMWW_mage_difficulty","GLOBAL",0)
    OR(11)
        HaveSpell(WIZARD_CHARM_PERSON)  // SPWI104.SPL (Charm Person)
        HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
        HaveSpell(WIZARD_FLAME_ARROW)  // SPWI303.SPL (Flame Arrow)
        HaveSpell(WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
        HaveSpell(WIZARD_BLINDNESS)  // SPWI106.SPL (Blindness)
        HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
        HasItem("wand04",Myself)  // Wand of Paralyzation
        HasItem("wand05",Myself)  // Wand of Fire
        HasItem("wand06",Myself)  // Wand of Frost
        HasItem("wand07",Myself)  // Wand of Lightning
        HasItem("wand08",Myself)  // Wand of Sleep
    !GlobalTimerNotExpired("teleportfield","LOCALS")
    !CheckSpellState(Myself,TIME_STOP)
    !HasItem("dw#move0",Myself)  // Mirror
    !HasItem("ghoult",Myself)  // Ghoul Touch
    !HasItem("msword",Myself)
    OR(3)
        Gender(Myself,ILLUSIONARY)
        !HasItem("dw#melf",Myself)  // Melf's Minute Meteor
        StateCheck(Myself,STATE_INVISIBLE)
    OR(3)
        Gender(Myself,ILLUSIONARY)
        !HasItem("dw#eneb",Myself)  // Energy Blade
        StateCheck(Myself,STATE_INVISIBLE)
THEN
    RESPONSE #100
        RandomWalk()
END

IF
    GlobalTimerNotExpired("castspell","LOCALS")
    See(NearestEnemyOf(Myself))
    See(NearestEnemyOf(Myself))
    !Range(NearestEnemyOf(Myself),15)
    Allegiance(Myself,ENEMY)
    !Allegiance(NearestEnemyOf(Myself),ENEMY)
    !StateCheck(NearestEnemyOf(Myself),STATE_IMMOBILE)
    !StateCheck(NearestEnemyOf(Myself),STATE_FEEBLEMINDED)
    !CheckStatGT(NearestEnemyOf(Myself),0,HELD)
    OR(11)
        HaveSpell(WIZARD_CHARM_PERSON)  // SPWI104.SPL (Charm Person)
        HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
        HaveSpell(WIZARD_FLAME_ARROW)  // SPWI303.SPL (Flame Arrow)
        HaveSpell(WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
        HaveSpell(WIZARD_BLINDNESS)  // SPWI106.SPL (Blindness)
        HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
        HasItem("wand04",Myself)  // Wand of Paralyzation
        HasItem("wand05",Myself)  // Wand of Fire
        HasItem("wand06",Myself)  // Wand of Frost
        HasItem("wand07",Myself)  // Wand of Lightning
        HasItem("wand08",Myself)  // Wand of Sleep
    GlobalTimerNotExpired("teleportfield","LOCALS")
    OR(3)
        Gender(Myself,ILLUSIONARY)
        !HasItem("dw#melf",Myself)  // Melf's Minute Meteor
        StateCheck(Myself,STATE_INVISIBLE)
    OR(3)
        Gender(Myself,ILLUSIONARY)
        !HasItem("dw#eneb",Myself)  // Energy Blade
        StateCheck(Myself,STATE_INVISIBLE)
THEN
    RESPONSE #100
        Wait(1)
END

IF
    GlobalTimerNotExpired("castspell","LOCALS")
    See(SecondNearestEnemyOf(Myself))
    See(NearestEnemyOf(Myself))
    !Range(SecondNearestEnemyOf(Myself),15)
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondNearestEnemyOf(Myself),ENEMY)
    !StateCheck(SecondNearestEnemyOf(Myself),STATE_IMMOBILE)
    !StateCheck(SecondNearestEnemyOf(Myself),STATE_FEEBLEMINDED)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,HELD)
    OR(11)
        HaveSpell(WIZARD_CHARM_PERSON)  // SPWI104.SPL (Charm Person)
        HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
        HaveSpell(WIZARD_FLAME_ARROW)  // SPWI303.SPL (Flame Arrow)
        HaveSpell(WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
        HaveSpell(WIZARD_BLINDNESS)  // SPWI106.SPL (Blindness)
        HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
        HasItem("wand04",Myself)  // Wand of Paralyzation
        HasItem("wand05",Myself)  // Wand of Fire
        HasItem("wand06",Myself)  // Wand of Frost
        HasItem("wand07",Myself)  // Wand of Lightning
        HasItem("wand08",Myself)  // Wand of Sleep
    GlobalTimerNotExpired("teleportfield","LOCALS")
    OR(3)
        Gender(Myself,ILLUSIONARY)
        !HasItem("dw#melf",Myself)  // Melf's Minute Meteor
        StateCheck(Myself,STATE_INVISIBLE)
    OR(3)
        Gender(Myself,ILLUSIONARY)
        !HasItem("dw#eneb",Myself)  // Energy Blade
        StateCheck(Myself,STATE_INVISIBLE)
THEN
    RESPONSE #100
        Wait(1)
END

IF
    GlobalTimerNotExpired("castspell","LOCALS")
    See(ThirdNearestEnemyOf(Myself))
    See(NearestEnemyOf(Myself))
    !Range(ThirdNearestEnemyOf(Myself),15)
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdNearestEnemyOf(Myself),ENEMY)
    !StateCheck(ThirdNearestEnemyOf(Myself),STATE_IMMOBILE)
    !StateCheck(ThirdNearestEnemyOf(Myself),STATE_FEEBLEMINDED)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,HELD)
    OR(11)
        HaveSpell(WIZARD_CHARM_PERSON)  // SPWI104.SPL (Charm Person)
        HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
        HaveSpell(WIZARD_FLAME_ARROW)  // SPWI303.SPL (Flame Arrow)
        HaveSpell(WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
        HaveSpell(WIZARD_BLINDNESS)  // SPWI106.SPL (Blindness)
        HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
        HasItem("wand04",Myself)  // Wand of Paralyzation
        HasItem("wand05",Myself)  // Wand of Fire
        HasItem("wand06",Myself)  // Wand of Frost
        HasItem("wand07",Myself)  // Wand of Lightning
        HasItem("wand08",Myself)  // Wand of Sleep
    GlobalTimerNotExpired("teleportfield","LOCALS")
    OR(3)
        Gender(Myself,ILLUSIONARY)
        !HasItem("dw#melf",Myself)  // Melf's Minute Meteor
        StateCheck(Myself,STATE_INVISIBLE)
    OR(3)
        Gender(Myself,ILLUSIONARY)
        !HasItem("dw#eneb",Myself)  // Energy Blade
        StateCheck(Myself,STATE_INVISIBLE)
THEN
    RESPONSE #100
        Wait(1)
END

IF
    GlobalTimerNotExpired("castspell","LOCALS")
    See(NearestEnemyOf(Myself))
    OR(2)
        GlobalTimerNotExpired("DMWWTimeStopRunning","LOCALS")
        CheckSpellState(Myself,TIME_STOP)
THEN
    RESPONSE #100
        Wait(1)
END

IF
    !StateCheck(Myself,STATE_INVISIBLE)
    GlobalTimerNotExpired("castspell","LOCALS")
    See(NearestEnemyOf(Myself))
    OR(13)
        CheckStat(Player1,1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        CheckStat(Player1,1,CLERIC_PHYSICAL_MIRROR)
        CheckStat(Player2,1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        CheckStat(Player2,1,CLERIC_PHYSICAL_MIRROR)
        CheckStat(Player3,1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        CheckStat(Player3,1,CLERIC_PHYSICAL_MIRROR)
        CheckStat(Player4,1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        CheckStat(Player4,1,CLERIC_PHYSICAL_MIRROR)
        CheckStat(Player5,1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        CheckStat(Player5,1,CLERIC_PHYSICAL_MIRROR)
        CheckStat(Player6,1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        CheckStat(Player6,1,CLERIC_PHYSICAL_MIRROR)
        PartyHasItem("shld24")
    !Global("DMWWinitialiseseePNM","LOCALS",1)
THEN
    RESPONSE #100
        SetGlobal("DMWWinitialiseseePNM","LOCALS",1)
        SetGlobalTimer("DMWWseePNM","LOCALS",ONE_ROUND)
    RESPONSE #100
        SetGlobal("DMWWinitialiseseePNM","LOCALS",1)
        SetGlobalTimer("DMWWseePNM","LOCALS",3)
END

IF
    !StateCheck(Myself,STATE_INVISIBLE)
    GlobalTimerNotExpired("castspell","LOCALS")
    !CheckStatGT(Myself,0,WIZARD_IMPROVED_ALACRITY)
    !CheckStat(Myself,1,SANCTUARY)
    ActionListEmpty()
    !StateCheck([PC],STATE_INVISIBLE)
    !CheckStatGT([PC],0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    !HasItem("morsword",[PC])  // Mordenkainen's Sword
    See([PC])
    Allegiance(Myself,ENEMY)
    !Allegiance([PC],ENEMY)
    !StateCheck([PC],STATE_IMMOBILE)
    !StateCheck([PC],STATE_FEEBLEMINDED)
    !CheckStatGT([PC],0,HELD)
    OR(2)
        !CheckStat([PC],1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT([PC],0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",[PC])
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    CheckStatLT([PC],100,RESISTMISSILE)
    OR(2)
        CheckStatLT([PC],75,RESISTMISSILE)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    HPPercentLT([PC],40)
THEN
    RESPONSE #100
        EquipRanged()
        AttackReevaluate([PC],30)
    RESPONSE #50
        Continue()
END

IF
    !StateCheck(Myself,STATE_INVISIBLE)
    GlobalTimerNotExpired("castspell","LOCALS")
    !CheckStatGT(Myself,0,WIZARD_IMPROVED_ALACRITY)
    !CheckStat(Myself,1,SANCTUARY)
    ActionListEmpty()
    !StateCheck(SecondNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(SecondNearest([PC]),0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    !HasItem("morsword",SecondNearest([PC]))  // Mordenkainen's Sword
    See(SecondNearest([PC]))
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondNearest([PC]),ENEMY)
    !StateCheck(SecondNearest([PC]),STATE_IMMOBILE)
    !StateCheck(SecondNearest([PC]),STATE_FEEBLEMINDED)
    !CheckStatGT(SecondNearest([PC]),0,HELD)
    OR(2)
        !CheckStat(SecondNearest([PC]),1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT(SecondNearest([PC]),0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",SecondNearest([PC]))
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    CheckStatLT(SecondNearest([PC]),100,RESISTMISSILE)
    OR(2)
        CheckStatLT(SecondNearest([PC]),75,RESISTMISSILE)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    HPPercentLT(SecondNearest([PC]),40)
THEN
    RESPONSE #100
        EquipRanged()
        AttackReevaluate(SecondNearest([PC]),30)
    RESPONSE #50
        Continue()
END

IF
    !StateCheck(Myself,STATE_INVISIBLE)
    GlobalTimerNotExpired("castspell","LOCALS")
    !CheckStatGT(Myself,0,WIZARD_IMPROVED_ALACRITY)
    !CheckStat(Myself,1,SANCTUARY)
    ActionListEmpty()
    !StateCheck(ThirdNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(ThirdNearest([PC]),0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    !HasItem("morsword",ThirdNearest([PC]))  // Mordenkainen's Sword
    See(ThirdNearest([PC]))
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdNearest([PC]),ENEMY)
    !StateCheck(ThirdNearest([PC]),STATE_IMMOBILE)
    !StateCheck(ThirdNearest([PC]),STATE_FEEBLEMINDED)
    !CheckStatGT(ThirdNearest([PC]),0,HELD)
    OR(2)
        !CheckStat(ThirdNearest([PC]),1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT(ThirdNearest([PC]),0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",ThirdNearest([PC]))
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    CheckStatLT(ThirdNearest([PC]),100,RESISTMISSILE)
    OR(2)
        CheckStatLT(ThirdNearest([PC]),75,RESISTMISSILE)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    HPPercentLT(ThirdNearest([PC]),40)
THEN
    RESPONSE #100
        EquipRanged()
        AttackReevaluate(ThirdNearest([PC]),30)
    RESPONSE #50
        Continue()
END

IF
    !StateCheck(Myself,STATE_INVISIBLE)
    GlobalTimerNotExpired("castspell","LOCALS")
    !CheckStatGT(Myself,0,WIZARD_IMPROVED_ALACRITY)
    !CheckStat(Myself,1,SANCTUARY)
    ActionListEmpty()
    !StateCheck(FourthNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(FourthNearest([PC]),0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    !HasItem("morsword",FourthNearest([PC]))  // Mordenkainen's Sword
    See(FourthNearest([PC]))
    Allegiance(Myself,ENEMY)
    !Allegiance(FourthNearest([PC]),ENEMY)
    !StateCheck(FourthNearest([PC]),STATE_IMMOBILE)
    !StateCheck(FourthNearest([PC]),STATE_FEEBLEMINDED)
    !CheckStatGT(FourthNearest([PC]),0,HELD)
    OR(2)
        !CheckStat(FourthNearest([PC]),1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT(FourthNearest([PC]),0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",FourthNearest([PC]))
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    CheckStatLT(FourthNearest([PC]),100,RESISTMISSILE)
    OR(2)
        CheckStatLT(FourthNearest([PC]),75,RESISTMISSILE)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    HPPercentLT(FourthNearest([PC]),40)
THEN
    RESPONSE #100
        EquipRanged()
        AttackReevaluate(FourthNearest([PC]),30)
    RESPONSE #50
        Continue()
END

IF
    !StateCheck(Myself,STATE_INVISIBLE)
    GlobalTimerNotExpired("castspell","LOCALS")
    !CheckStatGT(Myself,0,WIZARD_IMPROVED_ALACRITY)
    !CheckStat(Myself,1,SANCTUARY)
    ActionListEmpty()
    !StateCheck(FifthNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(FifthNearest([PC]),0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    !HasItem("morsword",FifthNearest([PC]))  // Mordenkainen's Sword
    See(FifthNearest([PC]))
    Allegiance(Myself,ENEMY)
    !Allegiance(FifthNearest([PC]),ENEMY)
    !StateCheck(FifthNearest([PC]),STATE_IMMOBILE)
    !StateCheck(FifthNearest([PC]),STATE_FEEBLEMINDED)
    !CheckStatGT(FifthNearest([PC]),0,HELD)
    OR(2)
        !CheckStat(FifthNearest([PC]),1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT(FifthNearest([PC]),0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",FifthNearest([PC]))
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    CheckStatLT(FifthNearest([PC]),100,RESISTMISSILE)
    OR(2)
        CheckStatLT(FifthNearest([PC]),75,RESISTMISSILE)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    HPPercentLT(FifthNearest([PC]),40)
THEN
    RESPONSE #100
        EquipRanged()
        AttackReevaluate(FifthNearest([PC]),30)
    RESPONSE #50
        Continue()
END

IF
    !StateCheck(Myself,STATE_INVISIBLE)
    GlobalTimerNotExpired("castspell","LOCALS")
    !CheckStatGT(Myself,0,WIZARD_IMPROVED_ALACRITY)
    !CheckStat(Myself,1,SANCTUARY)
    ActionListEmpty()
    !StateCheck(SixthNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(SixthNearest([PC]),0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    !HasItem("morsword",SixthNearest([PC]))  // Mordenkainen's Sword
    See(SixthNearest([PC]))
    Allegiance(Myself,ENEMY)
    !Allegiance(SixthNearest([PC]),ENEMY)
    !StateCheck(SixthNearest([PC]),STATE_IMMOBILE)
    !StateCheck(SixthNearest([PC]),STATE_FEEBLEMINDED)
    !CheckStatGT(SixthNearest([PC]),0,HELD)
    OR(2)
        !CheckStat(SixthNearest([PC]),1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT(SixthNearest([PC]),0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",SixthNearest([PC]))
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    CheckStatLT(SixthNearest([PC]),100,RESISTMISSILE)
    OR(2)
        CheckStatLT(SixthNearest([PC]),75,RESISTMISSILE)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    HPPercentLT(SixthNearest([PC]),40)
THEN
    RESPONSE #100
        EquipRanged()
        AttackReevaluate(SixthNearest([PC]),30)
    RESPONSE #50
        Continue()
END

IF
    !StateCheck(Myself,STATE_INVISIBLE)
    GlobalTimerNotExpired("castspell","LOCALS")
    !CheckStatGT(Myself,0,WIZARD_IMPROVED_ALACRITY)
    !CheckStat(Myself,1,SANCTUARY)
    ActionListEmpty()
    !StateCheck([PC.0.0.MAGE_ALL],STATE_INVISIBLE)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    !HasItem("morsword",[PC.0.0.MAGE_ALL])  // Mordenkainen's Sword
    See([PC.0.0.MAGE_ALL])
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.MAGE_ALL],ENEMY)
    !StateCheck([PC.0.0.MAGE_ALL],STATE_IMMOBILE)
    !StateCheck([PC.0.0.MAGE_ALL],STATE_FEEBLEMINDED)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,HELD)
    OR(2)
        !CheckStat([PC.0.0.MAGE_ALL],1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT([PC.0.0.MAGE_ALL],0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",[PC.0.0.MAGE_ALL])
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    CheckStatLT([PC.0.0.MAGE_ALL],100,RESISTMISSILE)
    OR(2)
        CheckStatLT([PC.0.0.MAGE_ALL],75,RESISTMISSILE)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
THEN
    RESPONSE #100
        EquipRanged()
        AttackReevaluate([PC.0.0.MAGE_ALL],30)
    RESPONSE #50
        Continue()
END

IF
    !StateCheck(Myself,STATE_INVISIBLE)
    GlobalTimerNotExpired("castspell","LOCALS")
    !CheckStatGT(Myself,0,WIZARD_IMPROVED_ALACRITY)
    !CheckStat(Myself,1,SANCTUARY)
    ActionListEmpty()
    !StateCheck([PC.0.0.CLERIC_ALL],STATE_INVISIBLE)
    !CheckStatGT([PC.0.0.CLERIC_ALL],0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    !HasItem("morsword",[PC.0.0.CLERIC_ALL])  // Mordenkainen's Sword
    See([PC.0.0.CLERIC_ALL])
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.CLERIC_ALL],ENEMY)
    !StateCheck([PC.0.0.CLERIC_ALL],STATE_IMMOBILE)
    !StateCheck([PC.0.0.CLERIC_ALL],STATE_FEEBLEMINDED)
    !CheckStatGT([PC.0.0.CLERIC_ALL],0,HELD)
    OR(2)
        !CheckStat([PC.0.0.CLERIC_ALL],1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT([PC.0.0.CLERIC_ALL],0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",[PC.0.0.CLERIC_ALL])
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    CheckStatLT([PC.0.0.CLERIC_ALL],100,RESISTMISSILE)
    OR(2)
        CheckStatLT([PC.0.0.CLERIC_ALL],75,RESISTMISSILE)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
THEN
    RESPONSE #100
        EquipRanged()
        AttackReevaluate([PC.0.0.CLERIC_ALL],30)
    RESPONSE #50
        Continue()
END

IF
    !StateCheck(Myself,STATE_INVISIBLE)
    GlobalTimerNotExpired("castspell","LOCALS")
    !CheckStatGT(Myself,0,WIZARD_IMPROVED_ALACRITY)
    !CheckStat(Myself,1,SANCTUARY)
    ActionListEmpty()
    !StateCheck([PC.0.0.DRUID_ALL],STATE_INVISIBLE)
    !CheckStatGT([PC.0.0.DRUID_ALL],0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    !HasItem("morsword",[PC.0.0.DRUID_ALL])  // Mordenkainen's Sword
    See([PC.0.0.DRUID_ALL])
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.DRUID_ALL],ENEMY)
    !StateCheck([PC.0.0.DRUID_ALL],STATE_IMMOBILE)
    !StateCheck([PC.0.0.DRUID_ALL],STATE_FEEBLEMINDED)
    !CheckStatGT([PC.0.0.DRUID_ALL],0,HELD)
    OR(2)
        !CheckStat([PC.0.0.DRUID_ALL],1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT([PC.0.0.DRUID_ALL],0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",[PC.0.0.DRUID_ALL])
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    CheckStatLT([PC.0.0.DRUID_ALL],100,RESISTMISSILE)
    OR(2)
        CheckStatLT([PC.0.0.DRUID_ALL],75,RESISTMISSILE)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
THEN
    RESPONSE #100
        EquipRanged()
        AttackReevaluate([PC.0.0.DRUID_ALL],30)
    RESPONSE #50
        Continue()
END

IF
    !StateCheck(Myself,STATE_INVISIBLE)
    GlobalTimerNotExpired("castspell","LOCALS")
    !CheckStatGT(Myself,0,WIZARD_IMPROVED_ALACRITY)
    !CheckStat(Myself,1,SANCTUARY)
    ActionListEmpty()
    !StateCheck([PC.0.0.BARD],STATE_INVISIBLE)
    !CheckStatGT([PC.0.0.BARD],0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    !HasItem("morsword",[PC.0.0.BARD])  // Mordenkainen's Sword
    See([PC.0.0.BARD])
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.BARD],ENEMY)
    !StateCheck([PC.0.0.BARD],STATE_IMMOBILE)
    !StateCheck([PC.0.0.BARD],STATE_FEEBLEMINDED)
    !CheckStatGT([PC.0.0.BARD],0,HELD)
    OR(2)
        !CheckStat([PC.0.0.BARD],1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT([PC.0.0.BARD],0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",[PC.0.0.BARD])
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    CheckStatLT([PC.0.0.BARD],100,RESISTMISSILE)
    OR(2)
        CheckStatLT([PC.0.0.BARD],75,RESISTMISSILE)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
THEN
    RESPONSE #100
        EquipRanged()
        AttackReevaluate([PC.0.0.BARD],30)
    RESPONSE #50
        Continue()
END

IF
    !StateCheck(Myself,STATE_INVISIBLE)
    GlobalTimerNotExpired("castspell","LOCALS")
    !CheckStatGT(Myself,0,WIZARD_IMPROVED_ALACRITY)
    !CheckStat(Myself,1,SANCTUARY)
    ActionListEmpty()
    !StateCheck([PC],STATE_INVISIBLE)
    !CheckStatGT([PC],0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    !HasItem("morsword",[PC])  // Mordenkainen's Sword
    See([PC])
    !HasItem("morsword",[PC])  // Mordenkainen's Sword
    Allegiance(Myself,ENEMY)
    !Allegiance([PC],ENEMY)
    !StateCheck([PC],STATE_IMMOBILE)
    !StateCheck([PC],STATE_FEEBLEMINDED)
    !CheckStatGT([PC],0,HELD)
    OR(2)
        !CheckStat([PC],1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT([PC],0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",[PC])
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    CheckStatLT([PC],100,RESISTMISSILE)
    OR(2)
        CheckStatLT([PC],75,RESISTMISSILE)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
THEN
    RESPONSE #100
        EquipRanged()
        AttackReevaluate([PC],30)
END

IF
    !StateCheck(Myself,STATE_INVISIBLE)
    GlobalTimerNotExpired("castspell","LOCALS")
    !CheckStatGT(Myself,0,WIZARD_IMPROVED_ALACRITY)
    !CheckStat(Myself,1,SANCTUARY)
    ActionListEmpty()
    !StateCheck(SecondNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(SecondNearest([PC]),0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    !HasItem("morsword",SecondNearest([PC]))  // Mordenkainen's Sword
    See(SecondNearest([PC]))
    !HasItem("morsword",SecondNearest([PC]))  // Mordenkainen's Sword
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondNearest([PC]),ENEMY)
    !StateCheck(SecondNearest([PC]),STATE_IMMOBILE)
    !StateCheck(SecondNearest([PC]),STATE_FEEBLEMINDED)
    !CheckStatGT(SecondNearest([PC]),0,HELD)
    OR(2)
        !CheckStat(SecondNearest([PC]),1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT(SecondNearest([PC]),0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",SecondNearest([PC]))
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    CheckStatLT(SecondNearest([PC]),100,RESISTMISSILE)
    OR(2)
        CheckStatLT(SecondNearest([PC]),75,RESISTMISSILE)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
THEN
    RESPONSE #100
        EquipRanged()
        AttackReevaluate(SecondNearest([PC]),30)
END

IF
    !StateCheck(Myself,STATE_INVISIBLE)
    GlobalTimerNotExpired("castspell","LOCALS")
    !CheckStatGT(Myself,0,WIZARD_IMPROVED_ALACRITY)
    !CheckStat(Myself,1,SANCTUARY)
    ActionListEmpty()
    !StateCheck(ThirdNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(ThirdNearest([PC]),0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    !HasItem("morsword",ThirdNearest([PC]))  // Mordenkainen's Sword
    See(ThirdNearest([PC]))
    !HasItem("morsword",ThirdNearest([PC]))  // Mordenkainen's Sword
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdNearest([PC]),ENEMY)
    !StateCheck(ThirdNearest([PC]),STATE_IMMOBILE)
    !StateCheck(ThirdNearest([PC]),STATE_FEEBLEMINDED)
    !CheckStatGT(ThirdNearest([PC]),0,HELD)
    OR(2)
        !CheckStat(ThirdNearest([PC]),1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT(ThirdNearest([PC]),0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",ThirdNearest([PC]))
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    CheckStatLT(ThirdNearest([PC]),100,RESISTMISSILE)
    OR(2)
        CheckStatLT(ThirdNearest([PC]),75,RESISTMISSILE)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
THEN
    RESPONSE #100
        EquipRanged()
        AttackReevaluate(ThirdNearest([PC]),30)
END

IF
    !StateCheck(Myself,STATE_INVISIBLE)
    GlobalTimerNotExpired("castspell","LOCALS")
    !CheckStatGT(Myself,0,WIZARD_IMPROVED_ALACRITY)
    !CheckStat(Myself,1,SANCTUARY)
    ActionListEmpty()
    !StateCheck(FourthNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(FourthNearest([PC]),0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    !HasItem("morsword",FourthNearest([PC]))  // Mordenkainen's Sword
    See(FourthNearest([PC]))
    !HasItem("morsword",FourthNearest([PC]))  // Mordenkainen's Sword
    Allegiance(Myself,ENEMY)
    !Allegiance(FourthNearest([PC]),ENEMY)
    !StateCheck(FourthNearest([PC]),STATE_IMMOBILE)
    !StateCheck(FourthNearest([PC]),STATE_FEEBLEMINDED)
    !CheckStatGT(FourthNearest([PC]),0,HELD)
    OR(2)
        !CheckStat(FourthNearest([PC]),1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT(FourthNearest([PC]),0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",FourthNearest([PC]))
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    CheckStatLT(FourthNearest([PC]),100,RESISTMISSILE)
    OR(2)
        CheckStatLT(FourthNearest([PC]),75,RESISTMISSILE)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
THEN
    RESPONSE #100
        EquipRanged()
        AttackReevaluate(FourthNearest([PC]),30)
END

IF
    !StateCheck(Myself,STATE_INVISIBLE)
    GlobalTimerNotExpired("castspell","LOCALS")
    !CheckStatGT(Myself,0,WIZARD_IMPROVED_ALACRITY)
    !CheckStat(Myself,1,SANCTUARY)
    ActionListEmpty()
    !StateCheck(FifthNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(FifthNearest([PC]),0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    !HasItem("morsword",FifthNearest([PC]))  // Mordenkainen's Sword
    See(FifthNearest([PC]))
    !HasItem("morsword",FifthNearest([PC]))  // Mordenkainen's Sword
    Allegiance(Myself,ENEMY)
    !Allegiance(FifthNearest([PC]),ENEMY)
    !StateCheck(FifthNearest([PC]),STATE_IMMOBILE)
    !StateCheck(FifthNearest([PC]),STATE_FEEBLEMINDED)
    !CheckStatGT(FifthNearest([PC]),0,HELD)
    OR(2)
        !CheckStat(FifthNearest([PC]),1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT(FifthNearest([PC]),0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",FifthNearest([PC]))
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    CheckStatLT(FifthNearest([PC]),100,RESISTMISSILE)
    OR(2)
        CheckStatLT(FifthNearest([PC]),75,RESISTMISSILE)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
THEN
    RESPONSE #100
        EquipRanged()
        AttackReevaluate(FifthNearest([PC]),30)
END

IF
    !StateCheck(Myself,STATE_INVISIBLE)
    GlobalTimerNotExpired("castspell","LOCALS")
    !CheckStatGT(Myself,0,WIZARD_IMPROVED_ALACRITY)
    !CheckStat(Myself,1,SANCTUARY)
    ActionListEmpty()
    !StateCheck(SixthNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(SixthNearest([PC]),0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    !HasItem("morsword",SixthNearest([PC]))  // Mordenkainen's Sword
    See(SixthNearest([PC]))
    !HasItem("morsword",SixthNearest([PC]))  // Mordenkainen's Sword
    Allegiance(Myself,ENEMY)
    !Allegiance(SixthNearest([PC]),ENEMY)
    !StateCheck(SixthNearest([PC]),STATE_IMMOBILE)
    !StateCheck(SixthNearest([PC]),STATE_FEEBLEMINDED)
    !CheckStatGT(SixthNearest([PC]),0,HELD)
    OR(2)
        !CheckStat(SixthNearest([PC]),1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT(SixthNearest([PC]),0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",SixthNearest([PC]))
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    CheckStatLT(SixthNearest([PC]),100,RESISTMISSILE)
    OR(2)
        CheckStatLT(SixthNearest([PC]),75,RESISTMISSILE)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
THEN
    RESPONSE #100
        EquipRanged()
        AttackReevaluate(SixthNearest([PC]),30)
END

IF
    !StateCheck(Myself,STATE_INVISIBLE)
    GlobalTimerNotExpired("castspell","LOCALS")
    !CheckStatGT(Myself,0,WIZARD_IMPROVED_ALACRITY)
    !CheckStat(Myself,1,SANCTUARY)
    ActionListEmpty()
    !StateCheck(NearestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(NearestEnemyOf(Myself),0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    !HasItem("morsword",NearestEnemyOf(Myself))  // Mordenkainen's Sword
    See(NearestEnemyOf(Myself))
    !HasItem("morsword",NearestEnemyOf(Myself))  // Mordenkainen's Sword
    Allegiance(Myself,ENEMY)
    !Allegiance(NearestEnemyOf(Myself),ENEMY)
    !StateCheck(NearestEnemyOf(Myself),STATE_IMMOBILE)
    !StateCheck(NearestEnemyOf(Myself),STATE_FEEBLEMINDED)
    !CheckStatGT(NearestEnemyOf(Myself),0,HELD)
    OR(2)
        !CheckStat(NearestEnemyOf(Myself),1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT(NearestEnemyOf(Myself),0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",NearestEnemyOf(Myself))
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    CheckStatLT(NearestEnemyOf(Myself),100,RESISTMISSILE)
    OR(2)
        CheckStatLT(NearestEnemyOf(Myself),75,RESISTMISSILE)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
THEN
    RESPONSE #100
        EquipRanged()
        AttackReevaluate(NearestEnemyOf(Myself),30)
END

IF
    !StateCheck(Myself,STATE_INVISIBLE)
    GlobalTimerNotExpired("castspell","LOCALS")
    !CheckStatGT(Myself,0,WIZARD_IMPROVED_ALACRITY)
    !CheckStat(Myself,1,SANCTUARY)
    ActionListEmpty()
    !StateCheck(SecondNearestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    !HasItem("morsword",SecondNearestEnemyOf(Myself))  // Mordenkainen's Sword
    See(SecondNearestEnemyOf(Myself))
    !HasItem("morsword",SecondNearestEnemyOf(Myself))  // Mordenkainen's Sword
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondNearestEnemyOf(Myself),ENEMY)
    !StateCheck(SecondNearestEnemyOf(Myself),STATE_IMMOBILE)
    !StateCheck(SecondNearestEnemyOf(Myself),STATE_FEEBLEMINDED)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,HELD)
    OR(2)
        !CheckStat(SecondNearestEnemyOf(Myself),1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT(SecondNearestEnemyOf(Myself),0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",SecondNearestEnemyOf(Myself))
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    CheckStatLT(SecondNearestEnemyOf(Myself),100,RESISTMISSILE)
    OR(2)
        CheckStatLT(SecondNearestEnemyOf(Myself),75,RESISTMISSILE)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
THEN
    RESPONSE #100
        EquipRanged()
        AttackReevaluate(SecondNearestEnemyOf(Myself),30)
END

IF
    !StateCheck(Myself,STATE_INVISIBLE)
    GlobalTimerNotExpired("castspell","LOCALS")
    !CheckStatGT(Myself,0,WIZARD_IMPROVED_ALACRITY)
    !CheckStat(Myself,1,SANCTUARY)
    ActionListEmpty()
    !StateCheck(ThirdNearestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    !HasItem("morsword",ThirdNearestEnemyOf(Myself))  // Mordenkainen's Sword
    See(ThirdNearestEnemyOf(Myself))
    !HasItem("morsword",ThirdNearestEnemyOf(Myself))  // Mordenkainen's Sword
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdNearestEnemyOf(Myself),ENEMY)
    !StateCheck(ThirdNearestEnemyOf(Myself),STATE_IMMOBILE)
    !StateCheck(ThirdNearestEnemyOf(Myself),STATE_FEEBLEMINDED)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,HELD)
    OR(2)
        !CheckStat(ThirdNearestEnemyOf(Myself),1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT(ThirdNearestEnemyOf(Myself),0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",ThirdNearestEnemyOf(Myself))
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    CheckStatLT(ThirdNearestEnemyOf(Myself),100,RESISTMISSILE)
    OR(2)
        CheckStatLT(ThirdNearestEnemyOf(Myself),75,RESISTMISSILE)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
THEN
    RESPONSE #100
        EquipRanged()
        AttackReevaluate(ThirdNearestEnemyOf(Myself),30)
END

IF
    !StateCheck(Myself,STATE_INVISIBLE)
    GlobalTimerNotExpired("castspell","LOCALS")
    !CheckStatGT(Myself,0,WIZARD_IMPROVED_ALACRITY)
    !CheckStat(Myself,1,SANCTUARY)
    ActionListEmpty()
    !StateCheck(FourthNearestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(FourthNearestEnemyOf(Myself),0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    !HasItem("morsword",FourthNearestEnemyOf(Myself))  // Mordenkainen's Sword
    See(FourthNearestEnemyOf(Myself))
    !HasItem("morsword",FourthNearestEnemyOf(Myself))  // Mordenkainen's Sword
    Allegiance(Myself,ENEMY)
    !Allegiance(FourthNearestEnemyOf(Myself),ENEMY)
    !StateCheck(FourthNearestEnemyOf(Myself),STATE_IMMOBILE)
    !StateCheck(FourthNearestEnemyOf(Myself),STATE_FEEBLEMINDED)
    !CheckStatGT(FourthNearestEnemyOf(Myself),0,HELD)
    OR(2)
        !CheckStat(FourthNearestEnemyOf(Myself),1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT(FourthNearestEnemyOf(Myself),0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",FourthNearestEnemyOf(Myself))
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    CheckStatLT(FourthNearestEnemyOf(Myself),100,RESISTMISSILE)
    OR(2)
        CheckStatLT(FourthNearestEnemyOf(Myself),75,RESISTMISSILE)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
THEN
    RESPONSE #100
        EquipRanged()
        AttackReevaluate(FourthNearestEnemyOf(Myself),30)
END

IF
    !StateCheck(Myself,STATE_INVISIBLE)
    GlobalTimerNotExpired("castspell","LOCALS")
    !CheckStatGT(Myself,0,WIZARD_IMPROVED_ALACRITY)
    !CheckStat(Myself,1,SANCTUARY)
    ActionListEmpty()
    !StateCheck(FifthNearestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(FifthNearestEnemyOf(Myself),0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    !HasItem("morsword",FifthNearestEnemyOf(Myself))  // Mordenkainen's Sword
    See(FifthNearestEnemyOf(Myself))
    !HasItem("morsword",FifthNearestEnemyOf(Myself))  // Mordenkainen's Sword
    Allegiance(Myself,ENEMY)
    !Allegiance(FifthNearestEnemyOf(Myself),ENEMY)
    !StateCheck(FifthNearestEnemyOf(Myself),STATE_IMMOBILE)
    !StateCheck(FifthNearestEnemyOf(Myself),STATE_FEEBLEMINDED)
    !CheckStatGT(FifthNearestEnemyOf(Myself),0,HELD)
    OR(2)
        !CheckStat(FifthNearestEnemyOf(Myself),1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT(FifthNearestEnemyOf(Myself),0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",FifthNearestEnemyOf(Myself))
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    CheckStatLT(FifthNearestEnemyOf(Myself),100,RESISTMISSILE)
    OR(2)
        CheckStatLT(FifthNearestEnemyOf(Myself),75,RESISTMISSILE)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
THEN
    RESPONSE #100
        EquipRanged()
        AttackReevaluate(FifthNearestEnemyOf(Myself),30)
END

IF
    !StateCheck(Myself,STATE_INVISIBLE)
    GlobalTimerNotExpired("castspell","LOCALS")
    !CheckStatGT(Myself,0,WIZARD_IMPROVED_ALACRITY)
    !CheckStat(Myself,1,SANCTUARY)
    ActionListEmpty()
    !StateCheck(SixthNearestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(SixthNearestEnemyOf(Myself),0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    !HasItem("morsword",SixthNearestEnemyOf(Myself))  // Mordenkainen's Sword
    See(SixthNearestEnemyOf(Myself))
    !HasItem("morsword",SixthNearestEnemyOf(Myself))  // Mordenkainen's Sword
    Allegiance(Myself,ENEMY)
    !Allegiance(SixthNearestEnemyOf(Myself),ENEMY)
    !StateCheck(SixthNearestEnemyOf(Myself),STATE_IMMOBILE)
    !StateCheck(SixthNearestEnemyOf(Myself),STATE_FEEBLEMINDED)
    !CheckStatGT(SixthNearestEnemyOf(Myself),0,HELD)
    OR(2)
        !CheckStat(SixthNearestEnemyOf(Myself),1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT(SixthNearestEnemyOf(Myself),0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",SixthNearestEnemyOf(Myself))
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    CheckStatLT(SixthNearestEnemyOf(Myself),100,RESISTMISSILE)
    OR(2)
        CheckStatLT(SixthNearestEnemyOf(Myself),75,RESISTMISSILE)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
THEN
    RESPONSE #100
        EquipRanged()
        AttackReevaluate(SixthNearestEnemyOf(Myself),30)
END

IF
    !StateCheck(Myself,STATE_INVISIBLE)
    GlobalTimerNotExpired("castspell","LOCALS")
    !CheckStatGT(Myself,0,WIZARD_IMPROVED_ALACRITY)
    !CheckStat(Myself,1,SANCTUARY)
    ActionListEmpty()
    !StateCheck([PC],STATE_INVISIBLE)
    !CheckStatGT([PC],0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    !HasItem("morsword",[PC])  // Mordenkainen's Sword
    See([PC])
    !HasItem("morsword",[PC])  // Mordenkainen's Sword
    Allegiance(Myself,ENEMY)
    !Allegiance([PC],ENEMY)
    OR(2)
        !CheckStat([PC],1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT([PC],0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",[PC])
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    CheckStatLT([PC],100,RESISTMISSILE)
    OR(2)
        CheckStatLT([PC],75,RESISTMISSILE)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
THEN
    RESPONSE #100
        EquipRanged()
        AttackReevaluate([PC],30)
END

IF
    !StateCheck(Myself,STATE_INVISIBLE)
    GlobalTimerNotExpired("castspell","LOCALS")
    !CheckStatGT(Myself,0,WIZARD_IMPROVED_ALACRITY)
    !CheckStat(Myself,1,SANCTUARY)
    ActionListEmpty()
    !StateCheck(SecondNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(SecondNearest([PC]),0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    !HasItem("morsword",SecondNearest([PC]))  // Mordenkainen's Sword
    See(SecondNearest([PC]))
    !HasItem("morsword",SecondNearest([PC]))  // Mordenkainen's Sword
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondNearest([PC]),ENEMY)
    OR(2)
        !CheckStat(SecondNearest([PC]),1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT(SecondNearest([PC]),0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",SecondNearest([PC]))
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    CheckStatLT(SecondNearest([PC]),100,RESISTMISSILE)
    OR(2)
        CheckStatLT(SecondNearest([PC]),75,RESISTMISSILE)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
THEN
    RESPONSE #100
        EquipRanged()
        AttackReevaluate(SecondNearest([PC]),30)
END

IF
    !StateCheck(Myself,STATE_INVISIBLE)
    GlobalTimerNotExpired("castspell","LOCALS")
    !CheckStatGT(Myself,0,WIZARD_IMPROVED_ALACRITY)
    !CheckStat(Myself,1,SANCTUARY)
    ActionListEmpty()
    !StateCheck(ThirdNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(ThirdNearest([PC]),0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    !HasItem("morsword",ThirdNearest([PC]))  // Mordenkainen's Sword
    See(ThirdNearest([PC]))
    !HasItem("morsword",ThirdNearest([PC]))  // Mordenkainen's Sword
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdNearest([PC]),ENEMY)
    OR(2)
        !CheckStat(ThirdNearest([PC]),1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT(ThirdNearest([PC]),0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",ThirdNearest([PC]))
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    CheckStatLT(ThirdNearest([PC]),100,RESISTMISSILE)
    OR(2)
        CheckStatLT(ThirdNearest([PC]),75,RESISTMISSILE)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
THEN
    RESPONSE #100
        EquipRanged()
        AttackReevaluate(ThirdNearest([PC]),30)
END

IF
    !StateCheck(Myself,STATE_INVISIBLE)
    GlobalTimerNotExpired("castspell","LOCALS")
    !CheckStatGT(Myself,0,WIZARD_IMPROVED_ALACRITY)
    !CheckStat(Myself,1,SANCTUARY)
    ActionListEmpty()
    !StateCheck(FourthNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(FourthNearest([PC]),0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    !HasItem("morsword",FourthNearest([PC]))  // Mordenkainen's Sword
    See(FourthNearest([PC]))
    !HasItem("morsword",FourthNearest([PC]))  // Mordenkainen's Sword
    Allegiance(Myself,ENEMY)
    !Allegiance(FourthNearest([PC]),ENEMY)
    OR(2)
        !CheckStat(FourthNearest([PC]),1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT(FourthNearest([PC]),0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",FourthNearest([PC]))
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    CheckStatLT(FourthNearest([PC]),100,RESISTMISSILE)
    OR(2)
        CheckStatLT(FourthNearest([PC]),75,RESISTMISSILE)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
THEN
    RESPONSE #100
        EquipRanged()
        AttackReevaluate(FourthNearest([PC]),30)
END

IF
    !StateCheck(Myself,STATE_INVISIBLE)
    GlobalTimerNotExpired("castspell","LOCALS")
    !CheckStatGT(Myself,0,WIZARD_IMPROVED_ALACRITY)
    !CheckStat(Myself,1,SANCTUARY)
    ActionListEmpty()
    !StateCheck(FifthNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(FifthNearest([PC]),0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    !HasItem("morsword",FifthNearest([PC]))  // Mordenkainen's Sword
    See(FifthNearest([PC]))
    !HasItem("morsword",FifthNearest([PC]))  // Mordenkainen's Sword
    Allegiance(Myself,ENEMY)
    !Allegiance(FifthNearest([PC]),ENEMY)
    OR(2)
        !CheckStat(FifthNearest([PC]),1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT(FifthNearest([PC]),0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",FifthNearest([PC]))
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    CheckStatLT(FifthNearest([PC]),100,RESISTMISSILE)
    OR(2)
        CheckStatLT(FifthNearest([PC]),75,RESISTMISSILE)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
THEN
    RESPONSE #100
        EquipRanged()
        AttackReevaluate(FifthNearest([PC]),30)
END

IF
    !StateCheck(Myself,STATE_INVISIBLE)
    GlobalTimerNotExpired("castspell","LOCALS")
    !CheckStatGT(Myself,0,WIZARD_IMPROVED_ALACRITY)
    !CheckStat(Myself,1,SANCTUARY)
    ActionListEmpty()
    !StateCheck(SixthNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(SixthNearest([PC]),0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    !HasItem("morsword",SixthNearest([PC]))  // Mordenkainen's Sword
    See(SixthNearest([PC]))
    !HasItem("morsword",SixthNearest([PC]))  // Mordenkainen's Sword
    Allegiance(Myself,ENEMY)
    !Allegiance(SixthNearest([PC]),ENEMY)
    OR(2)
        !CheckStat(SixthNearest([PC]),1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT(SixthNearest([PC]),0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",SixthNearest([PC]))
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    CheckStatLT(SixthNearest([PC]),100,RESISTMISSILE)
    OR(2)
        CheckStatLT(SixthNearest([PC]),75,RESISTMISSILE)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
THEN
    RESPONSE #100
        EquipRanged()
        AttackReevaluate(SixthNearest([PC]),30)
END

IF
    !StateCheck(Myself,STATE_INVISIBLE)
    GlobalTimerNotExpired("castspell","LOCALS")
    !CheckStatGT(Myself,0,WIZARD_IMPROVED_ALACRITY)
    !CheckStat(Myself,1,SANCTUARY)
    ActionListEmpty()
    !StateCheck(NearestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(NearestEnemyOf(Myself),0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    !HasItem("morsword",NearestEnemyOf(Myself))  // Mordenkainen's Sword
    See(NearestEnemyOf(Myself))
    !HasItem("morsword",NearestEnemyOf(Myself))  // Mordenkainen's Sword
    Allegiance(Myself,ENEMY)
    !Allegiance(NearestEnemyOf(Myself),ENEMY)
    OR(2)
        !CheckStat(NearestEnemyOf(Myself),1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT(NearestEnemyOf(Myself),0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",NearestEnemyOf(Myself))
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    CheckStatLT(NearestEnemyOf(Myself),100,RESISTMISSILE)
    OR(2)
        CheckStatLT(NearestEnemyOf(Myself),75,RESISTMISSILE)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
THEN
    RESPONSE #100
        EquipRanged()
        AttackReevaluate(NearestEnemyOf(Myself),30)
END

IF
    !StateCheck(Myself,STATE_INVISIBLE)
    GlobalTimerNotExpired("castspell","LOCALS")
    !CheckStatGT(Myself,0,WIZARD_IMPROVED_ALACRITY)
    !CheckStat(Myself,1,SANCTUARY)
    ActionListEmpty()
    !StateCheck(SecondNearestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    !HasItem("morsword",SecondNearestEnemyOf(Myself))  // Mordenkainen's Sword
    See(SecondNearestEnemyOf(Myself))
    !HasItem("morsword",SecondNearestEnemyOf(Myself))  // Mordenkainen's Sword
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondNearestEnemyOf(Myself),ENEMY)
    OR(2)
        !CheckStat(SecondNearestEnemyOf(Myself),1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT(SecondNearestEnemyOf(Myself),0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",SecondNearestEnemyOf(Myself))
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    CheckStatLT(SecondNearestEnemyOf(Myself),100,RESISTMISSILE)
    OR(2)
        CheckStatLT(SecondNearestEnemyOf(Myself),75,RESISTMISSILE)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
THEN
    RESPONSE #100
        EquipRanged()
        AttackReevaluate(SecondNearestEnemyOf(Myself),30)
END

IF
    !StateCheck(Myself,STATE_INVISIBLE)
    GlobalTimerNotExpired("castspell","LOCALS")
    !CheckStatGT(Myself,0,WIZARD_IMPROVED_ALACRITY)
    !CheckStat(Myself,1,SANCTUARY)
    ActionListEmpty()
    !StateCheck(ThirdNearestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    !HasItem("morsword",ThirdNearestEnemyOf(Myself))  // Mordenkainen's Sword
    See(ThirdNearestEnemyOf(Myself))
    !HasItem("morsword",ThirdNearestEnemyOf(Myself))  // Mordenkainen's Sword
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdNearestEnemyOf(Myself),ENEMY)
    OR(2)
        !CheckStat(ThirdNearestEnemyOf(Myself),1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT(ThirdNearestEnemyOf(Myself),0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",ThirdNearestEnemyOf(Myself))
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    CheckStatLT(ThirdNearestEnemyOf(Myself),100,RESISTMISSILE)
    OR(2)
        CheckStatLT(ThirdNearestEnemyOf(Myself),75,RESISTMISSILE)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
THEN
    RESPONSE #100
        EquipRanged()
        AttackReevaluate(ThirdNearestEnemyOf(Myself),30)
END

IF
    !StateCheck(Myself,STATE_INVISIBLE)
    GlobalTimerNotExpired("castspell","LOCALS")
    !CheckStatGT(Myself,0,WIZARD_IMPROVED_ALACRITY)
    !CheckStat(Myself,1,SANCTUARY)
    ActionListEmpty()
    !StateCheck(FourthNearestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(FourthNearestEnemyOf(Myself),0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    !HasItem("morsword",FourthNearestEnemyOf(Myself))  // Mordenkainen's Sword
    See(FourthNearestEnemyOf(Myself))
    !HasItem("morsword",FourthNearestEnemyOf(Myself))  // Mordenkainen's Sword
    Allegiance(Myself,ENEMY)
    !Allegiance(FourthNearestEnemyOf(Myself),ENEMY)
    OR(2)
        !CheckStat(FourthNearestEnemyOf(Myself),1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT(FourthNearestEnemyOf(Myself),0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",FourthNearestEnemyOf(Myself))
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    CheckStatLT(FourthNearestEnemyOf(Myself),100,RESISTMISSILE)
    OR(2)
        CheckStatLT(FourthNearestEnemyOf(Myself),75,RESISTMISSILE)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
THEN
    RESPONSE #100
        EquipRanged()
        AttackReevaluate(FourthNearestEnemyOf(Myself),30)
END

IF
    !StateCheck(Myself,STATE_INVISIBLE)
    GlobalTimerNotExpired("castspell","LOCALS")
    !CheckStatGT(Myself,0,WIZARD_IMPROVED_ALACRITY)
    !CheckStat(Myself,1,SANCTUARY)
    ActionListEmpty()
    !StateCheck(FifthNearestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(FifthNearestEnemyOf(Myself),0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    !HasItem("morsword",FifthNearestEnemyOf(Myself))  // Mordenkainen's Sword
    See(FifthNearestEnemyOf(Myself))
    !HasItem("morsword",FifthNearestEnemyOf(Myself))  // Mordenkainen's Sword
    Allegiance(Myself,ENEMY)
    !Allegiance(FifthNearestEnemyOf(Myself),ENEMY)
    OR(2)
        !CheckStat(FifthNearestEnemyOf(Myself),1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT(FifthNearestEnemyOf(Myself),0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",FifthNearestEnemyOf(Myself))
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    CheckStatLT(FifthNearestEnemyOf(Myself),100,RESISTMISSILE)
    OR(2)
        CheckStatLT(FifthNearestEnemyOf(Myself),75,RESISTMISSILE)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
THEN
    RESPONSE #100
        EquipRanged()
        AttackReevaluate(FifthNearestEnemyOf(Myself),30)
END

IF
    !StateCheck(Myself,STATE_INVISIBLE)
    GlobalTimerNotExpired("castspell","LOCALS")
    !CheckStatGT(Myself,0,WIZARD_IMPROVED_ALACRITY)
    !CheckStat(Myself,1,SANCTUARY)
    ActionListEmpty()
    !StateCheck(SixthNearestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(SixthNearestEnemyOf(Myself),0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    !HasItem("morsword",SixthNearestEnemyOf(Myself))  // Mordenkainen's Sword
    See(SixthNearestEnemyOf(Myself))
    !HasItem("morsword",SixthNearestEnemyOf(Myself))  // Mordenkainen's Sword
    Allegiance(Myself,ENEMY)
    !Allegiance(SixthNearestEnemyOf(Myself),ENEMY)
    OR(2)
        !CheckStat(SixthNearestEnemyOf(Myself),1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT(SixthNearestEnemyOf(Myself),0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",SixthNearestEnemyOf(Myself))
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    CheckStatLT(SixthNearestEnemyOf(Myself),100,RESISTMISSILE)
    OR(2)
        CheckStatLT(SixthNearestEnemyOf(Myself),75,RESISTMISSILE)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
THEN
    RESPONSE #100
        EquipRanged()
        AttackReevaluate(SixthNearestEnemyOf(Myself),30)
END

IF
    !StateCheck(Myself,STATE_INVISIBLE)
    GlobalTimerNotExpired("castspell","LOCALS")
    !CheckStatGT(Myself,0,WIZARD_IMPROVED_ALACRITY)
    !CheckStat(Myself,1,SANCTUARY)
    ActionListEmpty()
    !StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
    !CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    !HasItem("morsword",LastSeenBy(Myself))  // Mordenkainen's Sword
    Allegiance(Myself,ENEMY)
    OR(6)
        See(Player1)
        See(Player2)
        See(Player3)
        See(Player4)
        See(Player5)
        See(Player6)
THEN
    RESPONSE #100
        EquipRanged()
        AttackReevaluate(LastSeenBy(Myself),30)
END

IF
    GlobalTimerNotExpired("castspell","LOCALS")
    See(NearestEnemyOf(Myself))
    !HaveSpell(WIZARD_CHARM_PERSON)  // SPWI104.SPL (Charm Person)
    !HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !HaveSpell(WIZARD_FLAME_ARROW)  // SPWI303.SPL (Flame Arrow)
    !HaveSpell(WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    !HaveSpell(WIZARD_BLINDNESS)  // SPWI106.SPL (Blindness)
    !HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !HasItem("wand04",Myself)  // Wand of Paralyzation
    !HasItem("wand05",Myself)  // Wand of Fire
    !HasItem("wand06",Myself)  // Wand of Frost
    !HasItem("wand07",Myself)  // Wand of Lightning
    !HasItem("wand08",Myself)  // Wand of Sleep
    OR(2)
        Range(NearestEnemyOf(Myself),5)
        !HasItem("dw#move0",Myself)  // Mirror
THEN
    RESPONSE #100
        AttackReevaluate(NearestEnemyOf(Myself),30)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MIRROR_IMAGE)  // SPWI212.SPL (Mirror Image)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    See(NearestEnemyOf(Myself))
    !CheckStatGT(Myself,0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    CheckStatLT(Myself,2,STONESKINS)
    !StateCheck(Myself,STATE_MIRRORIMAGE)
    Global("instantprep","LOCALS",1)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(Myself,WIZARD_MIRROR_IMAGE)  // SPWI212.SPL (Mirror Image)
        SetGlobalTimer("redefend","LOCALS",7)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HasItem("potn10",Myself)  // Potion of Invisibility
    OR(2)
        Global("DMWW_mage_difficulty","GLOBAL",0)
        GlobalGT("DMWW_mage_difficulty","GLOBAL",2)
    OR(2)
        DifficultyGT(EASY)
        GlobalGT("DMWW_mage_difficulty","GLOBAL",2)
    HPPercentLT(Myself,75)
    !StateCheck(Myself,STATE_INVISIBLE)
    !CheckSpellState(Myself,CANNOT_TURN_INVISIBLE)
    !GlobalTimerNotExpired("thief_detection","LOCALS")
    GlobalTimerExpired("redefend","LOCALS")
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        DisplayStringHead(Myself,49135)  // Quaffs potion of invisibility
        UseItem("potn10",Myself)  // Potion of Invisibility
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HasItem("potn11",Myself)  // Potion of Invulnerability
    CheckStatGT(Myself,0,ARMORCLASS)
    Class(Myself,FIGHTER_MAGE)
    See(NearestEnemyOf(Myself))
    OR(2)
        Global("DMWW_mage_difficulty","GLOBAL",0)
        GlobalGT("DMWW_mage_difficulty","GLOBAL",2)
    OR(2)
        DifficultyGT(EASY)
        GlobalGT("DMWW_mage_difficulty","GLOBAL",2)
    Range(LastSeenBy(Myself),5)
    !StateCheck(Myself,STATE_INVISIBLE)
    GlobalTimerExpired("redefend","LOCALS")
    Global("magedrinks","LOCALS",0)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        DisplayStringHead(Myself,49136)  // Quaffs potion of invulnerability
        UseItem("potn11",Myself)  // Potion of Invulnerability
        SetGlobal("magedrinks","LOCALS",1)
        SetGlobalTimer("redefend","LOCALS",7)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HasItem("potn24",Myself)  // Potion of Defense
    CheckStatGT(Myself,0,ARMORCLASS)
    See(NearestEnemyOf(Myself))
    OR(2)
        Global("DMWW_mage_difficulty","GLOBAL",0)
        GlobalGT("DMWW_mage_difficulty","GLOBAL",2)
    OR(2)
        DifficultyGT(EASY)
        GlobalGT("DMWW_mage_difficulty","GLOBAL",2)
    Range(LastSeenBy(Myself),5)
    !StateCheck(Myself,STATE_INVISIBLE)
    GlobalTimerExpired("redefend","LOCALS")
    Global("magedrinks","LOCALS",0)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        DisplayStringHead(Myself,49131)  // Quaffs potion of defense
        UseItem("potn24",Myself)  // Potion of Defense
        SetGlobal("magedrinks","LOCALS",1)
        SetGlobalTimer("redefend","LOCALS",7)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HasItem("dw#ptn11",Myself)  // Potion of Invulnerability
    CheckStatGT(Myself,0,ARMORCLASS)
    Class(Myself,FIGHTER_MAGE)
    See(NearestEnemyOf(Myself))
    OR(2)
        Global("DMWW_mage_difficulty","GLOBAL",0)
        GlobalGT("DMWW_mage_difficulty","GLOBAL",2)
    OR(2)
        DifficultyGT(EASY)
        GlobalGT("DMWW_mage_difficulty","GLOBAL",2)
    Range(LastSeenBy(Myself),5)
    !StateCheck(Myself,STATE_INVISIBLE)
    GlobalTimerExpired("redefend","LOCALS")
    Global("magedrinks","LOCALS",0)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        DisplayStringHead(Myself,49136)  // Quaffs potion of invulnerability
        UseItem("dw#ptn11",Myself)  // Potion of Invulnerability
        SetGlobal("magedrinks","LOCALS",1)
        SetGlobalTimer("redefend","LOCALS",7)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HasItem("dw#ptn24",Myself)  // Potion of Defense
    CheckStatGT(Myself,0,ARMORCLASS)
    See(NearestEnemyOf(Myself))
    OR(2)
        Global("DMWW_mage_difficulty","GLOBAL",0)
        GlobalGT("DMWW_mage_difficulty","GLOBAL",2)
    OR(2)
        DifficultyGT(EASY)
        GlobalGT("DMWW_mage_difficulty","GLOBAL",2)
    Range(LastSeenBy(Myself),5)
    !StateCheck(Myself,STATE_INVISIBLE)
    GlobalTimerExpired("redefend","LOCALS")
    Global("magedrinks","LOCALS",0)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        DisplayStringHead(Myself,49131)  // Quaffs potion of defense
        UseItem("dw#ptn24",Myself)  // Potion of Defense
        SetGlobal("magedrinks","LOCALS",1)
        SetGlobalTimer("redefend","LOCALS",7)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HasItem("potn55",Myself)
    OR(2)
        Global("DMWW_mage_difficulty","GLOBAL",0)
        GlobalGT("DMWW_mage_difficulty","GLOBAL",2)
    OR(2)
        DifficultyGT(EASY)
        GlobalGT("DMWW_mage_difficulty","GLOBAL",2)
    HPPercentLT(Myself,100)
    OR(2)
        StateCheck(Myself,STATE_INVISIBLE)
        !See(NearestEnemyOf(Myself))
    OR(2)
        HPPercentLT(Myself,75)
        !See(NearestEnemyOf(Myself))
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        DisplayStringHead(Myself,49137)  // Quaffs superior healing potion
        UseItem("potn55",Myself)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HasItem("potn52",Myself)  // Potion of Extra Healing
    OR(2)
        Global("DMWW_mage_difficulty","GLOBAL",0)
        GlobalGT("DMWW_mage_difficulty","GLOBAL",2)
    OR(2)
        DifficultyGT(EASY)
        GlobalGT("DMWW_mage_difficulty","GLOBAL",2)
    HPPercentLT(Myself,100)
    OR(2)
        StateCheck(Myself,STATE_INVISIBLE)
        !See(NearestEnemyOf(Myself))
    OR(2)
        HPPercentLT(Myself,75)
        !See(NearestEnemyOf(Myself))
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        DisplayStringHead(Myself,49138)  // Quaffs extra-healing potion
        UseItem("potn52",Myself)  // Potion of Extra Healing
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HasItem("extheal",Myself)
    OR(2)
        Global("DMWW_mage_difficulty","GLOBAL",0)
        GlobalGT("DMWW_mage_difficulty","GLOBAL",2)
    OR(2)
        DifficultyGT(EASY)
        GlobalGT("DMWW_mage_difficulty","GLOBAL",2)
    HPPercentLT(Myself,100)
    OR(2)
        StateCheck(Myself,STATE_INVISIBLE)
        !See(NearestEnemyOf(Myself))
    OR(2)
        HPPercentLT(Myself,75)
        !See(NearestEnemyOf(Myself))
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        DisplayStringHead(Myself,49138)  // Quaffs extra-healing potion
        UseItem("extheal",Myself)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HasItem("potn08",Myself)  // Potion of Healing
    OR(2)
        !See(NearestEnemyOf(Myself))
        CheckStatLT(Myself,11,LEVEL)
    OR(2)
        Global("DMWW_mage_difficulty","GLOBAL",0)
        GlobalGT("DMWW_mage_difficulty","GLOBAL",2)
    OR(2)
        DifficultyGT(EASY)
        GlobalGT("DMWW_mage_difficulty","GLOBAL",2)
    HPPercentLT(Myself,100)
    OR(2)
        StateCheck(Myself,STATE_INVISIBLE)
        !See(NearestEnemyOf(Myself))
    OR(2)
        HPPercentLT(Myself,75)
        !See(NearestEnemyOf(Myself))
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        DisplayStringHead(Myself,49134)  // Quaffs healing potion
        UseItem("potn08",Myself)  // Potion of Healing
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MINOR_SPELL_TURNING)  // SPWI522.SPL (Minor Spell Turning)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    See(NearestEnemyOf(Myself))
    OR(5)
        See(NearestEnemyOfType([0.0.0.MAGE_ALL]))
        See(NearestEnemyOfType([0.0.0.BARD]))
        See(NearestEnemyOfType([0.0.0.CLERIC_ALL]))
        See(NearestEnemyOfType([0.0.0.DRUID_ALL]))
        See(NearestEnemyOfType([0.0.0.SORCERER]))
    GlobalTimerExpired("redefend","LOCALS")
    !GlobalTimerNotExpired("impinv","LOCALS")
    !CheckSpellState(Myself,SPELL_PROTECTION)
THEN
    RESPONSE #200
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(Myself,WIZARD_MINOR_SPELL_TURNING)  // SPWI522.SPL (Minor Spell Turning)
        SetGlobalTimer("redefend","LOCALS",7)
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MINOR_GLOBE_OF_INVULNERABILITY)  // SPWI406.SPL (Minor Globe of Invulnerability)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    See(NearestEnemyOf(Myself))
    GlobalTimerExpired("redefend","LOCALS")
    CheckStat(Myself,0,MINORGLOBE)
    OR(8)
        See(NearestEnemyOfType([0.0.0.MAGE_ALL]))
        See(NearestEnemyOfType([0.0.0.BARD]))
        See(NearestEnemyOfType([0.0.0.CLERIC_ALL]))
        See(NearestEnemyOfType([0.0.0.DRUID_ALL]))
        See(NearestEnemyOfType([0.0.0.SORCERER]))
        HaveSpell(WIZARD_FIREBALL)  // SPWI304.SPL (Fireball)
        HaveSpell(WIZARD_SKULL_TRAP)  // SPWI313.SPL (Skull Trap)
        HaveSpell(WIZARD_LIGHTNING_BOLT)  // SPWI308.SPL (Lightning Bolt)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(Myself,WIZARD_MINOR_GLOBE_OF_INVULNERABILITY)  // SPWI406.SPL (Minor Globe of Invulnerability)
        SetGlobalTimer("redefend","LOCALS",7)
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_DISPEL_MAGIC)  // SPWI302.SPL (Remove Magic)
    !StateCheck(ThirdNearestEnemyOf(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(ThirdNearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    GlobalLT("DMWW_mage_difficulty","GLOBAL",2)
    OR(2)
        Difficulty(EASIEST)
        !Global("DMWW_mage_difficulty","GLOBAL",0)
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdNearestEnemyOf(Myself),ENEMY)
    OR(3)
        CheckSpellState(ThirdNearestEnemyOf(Myself),BUFF_PRO_DAMAGE)
        CheckSpellState(ThirdNearestEnemyOf(Myself),BUFF_PRO_SPELLS)
        CheckSpellState(ThirdNearestEnemyOf(Myself),BUFF_ENHANCEMENT)
    !GlobalTimerNotExpired("easy_dispel","LOCALS")
    See(ThirdNearestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_DISPEL_MAGIC)  // SPWI302.SPL (Remove Magic)
    !StateCheck(SecondNearestEnemyOf(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(SecondNearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    GlobalLT("DMWW_mage_difficulty","GLOBAL",2)
    OR(2)
        Difficulty(EASIEST)
        !Global("DMWW_mage_difficulty","GLOBAL",0)
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondNearestEnemyOf(Myself),ENEMY)
    OR(3)
        CheckSpellState(SecondNearestEnemyOf(Myself),BUFF_PRO_DAMAGE)
        CheckSpellState(SecondNearestEnemyOf(Myself),BUFF_PRO_SPELLS)
        CheckSpellState(SecondNearestEnemyOf(Myself),BUFF_ENHANCEMENT)
    !GlobalTimerNotExpired("easy_dispel","LOCALS")
    See(SecondNearestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_DISPEL_MAGIC)  // SPWI302.SPL (Remove Magic)
    !StateCheck(NearestEnemyOf(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(NearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(NearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    GlobalLT("DMWW_mage_difficulty","GLOBAL",2)
    OR(2)
        Difficulty(EASIEST)
        !Global("DMWW_mage_difficulty","GLOBAL",0)
    Allegiance(Myself,ENEMY)
    !Allegiance(NearestEnemyOf(Myself),ENEMY)
    OR(3)
        CheckSpellState(NearestEnemyOf(Myself),BUFF_PRO_DAMAGE)
        CheckSpellState(NearestEnemyOf(Myself),BUFF_PRO_SPELLS)
        CheckSpellState(NearestEnemyOf(Myself),BUFF_ENHANCEMENT)
    !GlobalTimerNotExpired("easy_dispel","LOCALS")
    See(NearestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_DISPEL_MAGIC)  // SPWI302.SPL (Remove Magic)
    !StateCheck(LastSeenBy(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(LastSeenBy(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(LastSeenBy(Myself),DO_NOT_TARGET_SPELLS)
    GlobalLT("DMWW_mage_difficulty","GLOBAL",2)
    OR(2)
        Difficulty(EASIEST)
        !Global("DMWW_mage_difficulty","GLOBAL",0)
    Allegiance(Myself,ENEMY)
    !Allegiance(LastSeenBy(Myself),ENEMY)
    OR(3)
        CheckSpellState(LastSeenBy(Myself),BUFF_PRO_DAMAGE)
        CheckSpellState(LastSeenBy(Myself),BUFF_PRO_SPELLS)
        CheckSpellState(LastSeenBy(Myself),BUFF_ENHANCEMENT)
    !GlobalTimerNotExpired("easy_dispel","LOCALS")
    See(LastSeenBy(Myself))
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(LastSeenBy(Myself),WIZARD_DISPEL_MAGIC)  // SPWI302.SPL (Remove Magic)
        SetGlobalTimer("easy_dispel","LOCALS",FOUR_MINUTES)
        SetGlobalTimer("easy_antimagic","LOCALS",TWO_MINUTES)
    RESPONSE #50
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CONE_OF_COLD)  // SPWI503.SPL (Cone of Cold)
    !StateCheck(NearestEnemyOf(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(NearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(NearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    See(NearestEnemyOf(Myself))
    Range(NearestEnemyOf(Myself),6)
    GlobalLT("DMWW_mage_difficulty","GLOBAL",2)
    OR(2)
        Difficulty(EASIEST)
        !Global("DMWW_mage_difficulty","GLOBAL",0)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(NearestEnemyOf(Myself),WIZARD_CONE_OF_COLD)  // SPWI503.SPL (Cone of Cold)
    RESPONSE #50
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    !StateCheck(ThirdNearestEnemyOf(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(ThirdNearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    GlobalLT("DMWW_mage_difficulty","GLOBAL",2)
    OR(2)
        Difficulty(EASIEST)
        !Global("DMWW_mage_difficulty","GLOBAL",0)
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdNearestEnemyOf(Myself),ENEMY)
    See(ThirdNearestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    !StateCheck(SecondNearestEnemyOf(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(SecondNearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    GlobalLT("DMWW_mage_difficulty","GLOBAL",2)
    OR(2)
        Difficulty(EASIEST)
        !Global("DMWW_mage_difficulty","GLOBAL",0)
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondNearestEnemyOf(Myself),ENEMY)
    See(SecondNearestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    !StateCheck(NearestEnemyOf(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(NearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(NearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    GlobalLT("DMWW_mage_difficulty","GLOBAL",2)
    OR(2)
        Difficulty(EASIEST)
        !Global("DMWW_mage_difficulty","GLOBAL",0)
    Allegiance(Myself,ENEMY)
    !Allegiance(NearestEnemyOf(Myself),ENEMY)
    See(NearestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_SUN_FIRE)  // SPWI523.SPL (Sunfire)
    !StateCheck(LastSeenBy(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(LastSeenBy(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(LastSeenBy(Myself),DO_NOT_TARGET_SPELLS)
    GlobalLT("DMWW_mage_difficulty","GLOBAL",2)
    OR(2)
        Difficulty(EASIEST)
        !Global("DMWW_mage_difficulty","GLOBAL",0)
    Allegiance(Myself,ENEMY)
    !Allegiance(LastSeenBy(Myself),ENEMY)
    See(LastSeenBy(Myself))
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(LastSeenBy(Myself),WIZARD_SUN_FIRE)  // SPWI523.SPL (Sunfire)
    RESPONSE #50
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    !StateCheck(ThirdFarthestEnemyOf(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(ThirdFarthestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(ThirdFarthestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    GlobalLT("DMWW_mage_difficulty","GLOBAL",2)
    OR(2)
        Difficulty(EASIEST)
        !Global("DMWW_mage_difficulty","GLOBAL",0)
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdFarthestEnemyOf(Myself),ENEMY)
    OR(2)
        !Range(ThirdFarthestEnemyOf(Myself),20)
        CheckStatGT(Myself,0,MINORGLOBE)
    See(ThirdFarthestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    !StateCheck(SecondFarthestEnemyOf(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(SecondFarthestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(SecondFarthestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    GlobalLT("DMWW_mage_difficulty","GLOBAL",2)
    OR(2)
        Difficulty(EASIEST)
        !Global("DMWW_mage_difficulty","GLOBAL",0)
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondFarthestEnemyOf(Myself),ENEMY)
    OR(2)
        !Range(SecondFarthestEnemyOf(Myself),20)
        CheckStatGT(Myself,0,MINORGLOBE)
    See(SecondFarthestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    !StateCheck(FarthestEnemyOf(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(FarthestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(FarthestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    GlobalLT("DMWW_mage_difficulty","GLOBAL",2)
    OR(2)
        Difficulty(EASIEST)
        !Global("DMWW_mage_difficulty","GLOBAL",0)
    Allegiance(Myself,ENEMY)
    !Allegiance(FarthestEnemyOf(Myself),ENEMY)
    OR(2)
        !Range(FarthestEnemyOf(Myself),20)
        CheckStatGT(Myself,0,MINORGLOBE)
    See(FarthestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_FIREBALL)  // SPWI304.SPL (Fireball)
    !StateCheck(LastSeenBy(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(LastSeenBy(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(LastSeenBy(Myself),DO_NOT_TARGET_SPELLS)
    GlobalLT("DMWW_mage_difficulty","GLOBAL",2)
    OR(2)
        Difficulty(EASIEST)
        !Global("DMWW_mage_difficulty","GLOBAL",0)
    Allegiance(Myself,ENEMY)
    !Allegiance(LastSeenBy(Myself),ENEMY)
    OR(2)
        !Range(LastSeenBy(Myself),20)
        CheckStatGT(Myself,0,MINORGLOBE)
    See(LastSeenBy(Myself))
THEN
    RESPONSE #80
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(LastSeenBy(Myself),WIZARD_FIREBALL)  // SPWI304.SPL (Fireball)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_LIGHTNING_BOLT)  // SPWI308.SPL (Lightning Bolt)
    !StateCheck(LastSeenBy(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(LastSeenBy(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(LastSeenBy(Myself),DO_NOT_TARGET_SPELLS)
    GlobalLT("DMWW_mage_difficulty","GLOBAL",2)
    OR(2)
        Difficulty(EASIEST)
        !Global("DMWW_mage_difficulty","GLOBAL",0)
    Allegiance(Myself,ENEMY)
    !Allegiance(LastSeenBy(Myself),ENEMY)
    OR(2)
        !Range(LastSeenBy(Myself),20)
        CheckStatGT(Myself,0,MINORGLOBE)
    See(LastSeenBy(Myself))
THEN
    RESPONSE #80
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(LastSeenBy(Myself),WIZARD_LIGHTNING_BOLT)  // SPWI308.SPL (Lightning Bolt)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    !StateCheck(ThirdNearestEnemyOf(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(ThirdNearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    GlobalLT("DMWW_mage_difficulty","GLOBAL",2)
    OR(2)
        Difficulty(EASIEST)
        !Global("DMWW_mage_difficulty","GLOBAL",0)
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdNearestEnemyOf(Myself),ENEMY)
    See(ThirdNearestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    !StateCheck(SecondNearestEnemyOf(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(SecondNearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    GlobalLT("DMWW_mage_difficulty","GLOBAL",2)
    OR(2)
        Difficulty(EASIEST)
        !Global("DMWW_mage_difficulty","GLOBAL",0)
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondNearestEnemyOf(Myself),ENEMY)
    See(SecondNearestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    !StateCheck(NearestEnemyOf(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(NearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(NearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    GlobalLT("DMWW_mage_difficulty","GLOBAL",2)
    OR(2)
        Difficulty(EASIEST)
        !Global("DMWW_mage_difficulty","GLOBAL",0)
    Allegiance(Myself,ENEMY)
    !Allegiance(NearestEnemyOf(Myself),ENEMY)
    See(NearestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_HORROR)  // SPWI205.SPL (Horror)
    !StateCheck(LastSeenBy(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(LastSeenBy(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(LastSeenBy(Myself),DO_NOT_TARGET_SPELLS)
    GlobalLT("DMWW_mage_difficulty","GLOBAL",2)
    OR(2)
        Difficulty(EASIEST)
        !Global("DMWW_mage_difficulty","GLOBAL",0)
    Allegiance(Myself,ENEMY)
    !Allegiance(LastSeenBy(Myself),ENEMY)
    See(LastSeenBy(Myself))
THEN
    RESPONSE #80
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(LastSeenBy(Myself),WIZARD_HORROR)  // SPWI205.SPL (Horror)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    !StateCheck(LastSeenBy(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(LastSeenBy(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(LastSeenBy(Myself),DO_NOT_TARGET_SPELLS)
    GlobalLT("DMWW_mage_difficulty","GLOBAL",2)
    OR(2)
        Difficulty(EASIEST)
        !Global("DMWW_mage_difficulty","GLOBAL",0)
    Allegiance(Myself,ENEMY)
    !Allegiance(LastSeenBy(Myself),ENEMY)
    See(LastSeenBy(Myself))
THEN
    RESPONSE #80
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(LastSeenBy(Myself),WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck(LastSeenBy(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(LastSeenBy(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(LastSeenBy(Myself),DO_NOT_TARGET_SPELLS)
    GlobalLT("DMWW_mage_difficulty","GLOBAL",2)
    OR(2)
        Difficulty(EASIEST)
        !Global("DMWW_mage_difficulty","GLOBAL",0)
    Allegiance(Myself,ENEMY)
    !Allegiance(LastSeenBy(Myself),ENEMY)
    See(LastSeenBy(Myself))
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(LastSeenBy(Myself),WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck(LastSeenBy(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(LastSeenBy(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(LastSeenBy(Myself),DO_NOT_TARGET_SPELLS)
    GlobalLT("DMWW_mage_difficulty","GLOBAL",2)
    OR(2)
        Difficulty(EASIEST)
        !Global("DMWW_mage_difficulty","GLOBAL",0)
    Allegiance(Myself,ENEMY)
    !Allegiance(LastSeenBy(Myself),ENEMY)
    See(LastSeenBy(Myself))
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(LastSeenBy(Myself),WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    GlobalTimerNotExpired("castspell","LOCALS")
    See(NearestEnemyOf(Myself))
    StateCheck(Myself,STATE_INVISIBLE)
    GlobalLT("DMWW_mage_difficulty","GLOBAL",2)
    OR(2)
        Difficulty(EASIEST)
        !Global("DMWW_mage_difficulty","GLOBAL",0)
THEN
    RESPONSE #100
        RandomWalk()
END

IF
    See(NearestEnemyOf(Myself))
    !GlobalTimerNotExpired("castspell","LOCALS")
    GlobalLT("DMWW_mage_difficulty","GLOBAL",2)
    OR(2)
        Difficulty(EASIEST)
        !Global("DMWW_mage_difficulty","GLOBAL",0)
THEN
    RESPONSE #100
        Attack(NearestEnemyOf(Myself))
END

IF
    !Global("chasing","LOCALS",0)
    See(NearestEnemyOf(Myself))
THEN
    RESPONSE #100
        SetGlobal("chasing","LOCALS",0)
        Continue()
END

IF
    ActionListEmpty()
    Global("inafight","LOCALS",1)
    Allegiance(Myself,ENEMY)
    !See(NearestEnemyOf(Myself))
    Global("chasing","LOCALS",0)
    !Global("chasePC","LOCALS",0)
THEN
    RESPONSE #100
        SetGlobalTimer("chasetimer","LOCALS",8)
        SetGlobal("chasing","LOCALS",1)
END

IF
    !See(NearestEnemyOf(Myself))
    GlobalTimerExpired("chasetimer","LOCALS")
    !Global("inafight","LOCALS",0)
    !Global("chasePC","LOCALS",0)
THEN
    RESPONSE #100
        SetGlobal("inafight","LOCALS",0)
        SetGlobal("chasePC","LOCALS",0)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    !GlobalTimerNotExpired("teleportpursuetimer","LOCALS")
    GlobalTimerExpired("chasetimer","LOCALS")
    Global("chasePC","LOCALS",1)
    !Detect([PC])
    HaveSpell(WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
    !Range(Player1,30)
    !StateCheck(Myself,STATE_INVISIBLE)
    !HasItem("dw#nodor",Myself)  // Mirror
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ReallyForceSpell(Player1,WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
        RemoveSpell(WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
        SetGlobalTimer("teleportpursuetimer","LOCALS",THREE_ROUNDS)
        SetGlobal("chasePC","LOCALS",0)
END

IF
    !See(NearestEnemyOf(Myself))
    !Detect(Player1)
    !StateCheck(Player1,STATE_INVISIBLE)
    !CheckStatGT(Player1,0,SANCTUARY)
    ActionListEmpty()
    !See(NearestEnemyOf(Myself))
    !GlobalTimerNotExpired("castspell","LOCALS")
    GlobalTimerNotExpired("chasetimer","LOCALS")
    Global("chasePC","LOCALS",1)
    OR(5)
        !HaveSpell(WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
        Range(Player1,30)
        StateCheck(Myself,STATE_INVISIBLE)
        HasItem("dw#nodor",Myself)  // Mirror
        GlobalTimerNotExpired("teleportpursuetimer","LOCALS")
THEN
    RESPONSE #100
        MoveToObject(Player1)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    !GlobalTimerNotExpired("teleportpursuetimer","LOCALS")
    GlobalTimerExpired("chasetimer","LOCALS")
    Global("chasePC","LOCALS",2)
    !Detect([PC])
    HaveSpell(WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
    !Range(Player2,30)
    !StateCheck(Myself,STATE_INVISIBLE)
    !HasItem("dw#nodor",Myself)  // Mirror
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ReallyForceSpell(Player2,WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
        RemoveSpell(WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
        SetGlobalTimer("teleportpursuetimer","LOCALS",THREE_ROUNDS)
        SetGlobal("chasePC","LOCALS",0)
END

IF
    !See(NearestEnemyOf(Myself))
    !Detect(Player2)
    !StateCheck(Player2,STATE_INVISIBLE)
    !CheckStatGT(Player2,0,SANCTUARY)
    ActionListEmpty()
    !See(NearestEnemyOf(Myself))
    !GlobalTimerNotExpired("castspell","LOCALS")
    GlobalTimerNotExpired("chasetimer","LOCALS")
    Global("chasePC","LOCALS",2)
    OR(5)
        !HaveSpell(WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
        Range(Player2,30)
        StateCheck(Myself,STATE_INVISIBLE)
        HasItem("dw#nodor",Myself)  // Mirror
        GlobalTimerNotExpired("teleportpursuetimer","LOCALS")
THEN
    RESPONSE #100
        MoveToObject(Player2)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    !GlobalTimerNotExpired("teleportpursuetimer","LOCALS")
    GlobalTimerExpired("chasetimer","LOCALS")
    Global("chasePC","LOCALS",3)
    !Detect([PC])
    HaveSpell(WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
    !Range(Player3,30)
    !StateCheck(Myself,STATE_INVISIBLE)
    !HasItem("dw#nodor",Myself)  // Mirror
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ReallyForceSpell(Player3,WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
        RemoveSpell(WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
        SetGlobalTimer("teleportpursuetimer","LOCALS",THREE_ROUNDS)
        SetGlobal("chasePC","LOCALS",0)
END

IF
    !See(NearestEnemyOf(Myself))
    !Detect(Player3)
    !StateCheck(Player3,STATE_INVISIBLE)
    !CheckStatGT(Player3,0,SANCTUARY)
    ActionListEmpty()
    !See(NearestEnemyOf(Myself))
    !GlobalTimerNotExpired("castspell","LOCALS")
    GlobalTimerNotExpired("chasetimer","LOCALS")
    Global("chasePC","LOCALS",3)
    OR(5)
        !HaveSpell(WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
        Range(Player3,30)
        StateCheck(Myself,STATE_INVISIBLE)
        HasItem("dw#nodor",Myself)  // Mirror
        GlobalTimerNotExpired("teleportpursuetimer","LOCALS")
THEN
    RESPONSE #100
        MoveToObject(Player3)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    !GlobalTimerNotExpired("teleportpursuetimer","LOCALS")
    GlobalTimerExpired("chasetimer","LOCALS")
    Global("chasePC","LOCALS",4)
    !Detect([PC])
    HaveSpell(WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
    !Range(Player4,30)
    !StateCheck(Myself,STATE_INVISIBLE)
    !HasItem("dw#nodor",Myself)  // Mirror
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ReallyForceSpell(Player4,WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
        RemoveSpell(WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
        SetGlobalTimer("teleportpursuetimer","LOCALS",THREE_ROUNDS)
        SetGlobal("chasePC","LOCALS",0)
END

IF
    !See(NearestEnemyOf(Myself))
    !Detect(Player4)
    !StateCheck(Player4,STATE_INVISIBLE)
    !CheckStatGT(Player4,0,SANCTUARY)
    ActionListEmpty()
    !See(NearestEnemyOf(Myself))
    !GlobalTimerNotExpired("castspell","LOCALS")
    GlobalTimerNotExpired("chasetimer","LOCALS")
    Global("chasePC","LOCALS",4)
    OR(5)
        !HaveSpell(WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
        Range(Player4,30)
        StateCheck(Myself,STATE_INVISIBLE)
        HasItem("dw#nodor",Myself)  // Mirror
        GlobalTimerNotExpired("teleportpursuetimer","LOCALS")
THEN
    RESPONSE #100
        MoveToObject(Player4)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    !GlobalTimerNotExpired("teleportpursuetimer","LOCALS")
    GlobalTimerExpired("chasetimer","LOCALS")
    Global("chasePC","LOCALS",5)
    !Detect([PC])
    HaveSpell(WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
    !Range(Player5,30)
    !StateCheck(Myself,STATE_INVISIBLE)
    !HasItem("dw#nodor",Myself)  // Mirror
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ReallyForceSpell(Player5,WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
        RemoveSpell(WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
        SetGlobalTimer("teleportpursuetimer","LOCALS",THREE_ROUNDS)
        SetGlobal("chasePC","LOCALS",0)
END

IF
    !See(NearestEnemyOf(Myself))
    !Detect(Player5)
    !StateCheck(Player5,STATE_INVISIBLE)
    !CheckStatGT(Player5,0,SANCTUARY)
    ActionListEmpty()
    !See(NearestEnemyOf(Myself))
    !GlobalTimerNotExpired("castspell","LOCALS")
    GlobalTimerNotExpired("chasetimer","LOCALS")
    Global("chasePC","LOCALS",5)
    OR(5)
        !HaveSpell(WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
        Range(Player5,30)
        StateCheck(Myself,STATE_INVISIBLE)
        HasItem("dw#nodor",Myself)  // Mirror
        GlobalTimerNotExpired("teleportpursuetimer","LOCALS")
THEN
    RESPONSE #100
        MoveToObject(Player5)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    !GlobalTimerNotExpired("teleportpursuetimer","LOCALS")
    GlobalTimerExpired("chasetimer","LOCALS")
    Global("chasePC","LOCALS",6)
    !Detect([PC])
    HaveSpell(WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
    !Range(Player6,30)
    !StateCheck(Myself,STATE_INVISIBLE)
    !HasItem("dw#nodor",Myself)  // Mirror
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ReallyForceSpell(Player6,WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
        RemoveSpell(WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
        SetGlobalTimer("teleportpursuetimer","LOCALS",THREE_ROUNDS)
        SetGlobal("chasePC","LOCALS",0)
END

IF
    !See(NearestEnemyOf(Myself))
    !Detect(Player6)
    !StateCheck(Player6,STATE_INVISIBLE)
    !CheckStatGT(Player6,0,SANCTUARY)
    ActionListEmpty()
    !See(NearestEnemyOf(Myself))
    !GlobalTimerNotExpired("castspell","LOCALS")
    GlobalTimerNotExpired("chasetimer","LOCALS")
    Global("chasePC","LOCALS",6)
    OR(5)
        !HaveSpell(WIZARD_DIMENSION_DOOR)  // SPWI402.SPL (Dimension Door)
        Range(Player6,30)
        StateCheck(Myself,STATE_INVISIBLE)
        HasItem("dw#nodor",Myself)  // Mirror
        GlobalTimerNotExpired("teleportpursuetimer","LOCALS")
THEN
    RESPONSE #100
        MoveToObject(Player6)
END

IF
    GlobalLT("DMWW_mage_difficulty","GLOBAL",2)
    OR(2)
        Difficulty(EASIEST)
        !Global("DMWW_mage_difficulty","GLOBAL",0)
THEN
    RESPONSE #100
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MINOR_SPELL_TURNING)  // SPWI522.SPL (Minor Spell Turning)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    GlobalTimerExpired("redefend","LOCALS")
    See(NearestEnemyOf(Myself))
    !CheckStatGT(Myself,0,WIZARD_SPELL_TURNING)
    !CheckStatGT(Myself,0,WIZARD_SPELL_TRAP)
    !CheckStatGT(Myself,0,WIZARD_SPELL_DEFLECTION)
    OR(2)
        !Range(NearestEnemyOf(Myself),10)
        CheckStatGT(Myself,0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    OR(2)
        !Range(NearestEnemyOf(Myself),10)
        CheckStatGT(Myself,0,STONESKINS)
THEN
    RESPONSE #500
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(Myself,WIZARD_MINOR_SPELL_TURNING)  // SPWI522.SPL (Minor Spell Turning)
    RESPONSE #500
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MINOR_GLOBE_OF_INVULNERABILITY)  // SPWI406.SPL (Minor Globe of Invulnerability)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    GlobalTimerExpired("redefend","LOCALS")
    See(NearestEnemyOf(Myself))
    CheckStat(Myself,0,MINORGLOBE)
    OR(2)
        !Range(NearestEnemyOf(Myself),10)
        CheckStatGT(Myself,0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    OR(2)
        !Range(NearestEnemyOf(Myself),10)
        CheckStatGT(Myself,0,STONESKINS)
THEN
    RESPONSE #500
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(Myself,WIZARD_MINOR_GLOBE_OF_INVULNERABILITY)  // SPWI406.SPL (Minor Globe of Invulnerability)
    RESPONSE #500
        Continue()
END

IF
    See(Myself)
    False()
THEN
    RESPONSE #100
        NoAction()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_DISPEL_MAGIC)  // SPWI302.SPL (Remove Magic)
    !StateCheck([PC],STATE_INVISIBLE)
    !CheckStatGT([PC],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC],DO_NOT_TARGET_SPELLS)
    See([PC])
    OR(2)
        !GlobalTimerNotExpired("DMWW_dispel","LOCALS")
        HasItem("dw#dispe",Myself)  // Mirror
    CheckSpellState([PC],PRIORITY_DISPEL)
    !StateCheck(Player1,STATE_DISABLED)
    !CheckStatGT(Player1,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player1,ENEMY)
    !StateCheck(Player2,STATE_DISABLED)
    !CheckStatGT(Player2,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player2,ENEMY)
    !StateCheck(Player3,STATE_DISABLED)
    !CheckStatGT(Player3,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player3,ENEMY)
    !StateCheck(Player4,STATE_DISABLED)
    !CheckStatGT(Player4,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player4,ENEMY)
    !StateCheck(Player5,STATE_DISABLED)
    !CheckStatGT(Player5,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player5,ENEMY)
    !StateCheck(Player6,STATE_DISABLED)
    !CheckStatGT(Player6,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player6,ENEMY)
    !GlobalTimerNotExpired("delay_dispel","LOCALS")
    !CheckStat([PC],1,WIZARD_SPELL_IMMUNITY)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC],ENEMY)
    !CheckSpellState(Myself,TIME_STOP)
THEN
    RESPONSE #100
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC],WIZARD_DISPEL_MAGIC)  // SPWI302.SPL (Remove Magic)
        SetGlobalTimer("DMWW_dispel","LOCALS",THREE_ROUNDS)
        SetGlobalTimer("DMWW_antimagic","LOCALS",THREE_ROUNDS)
    RESPONSE #150
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_DISPEL_MAGIC)  // SPWI302.SPL (Remove Magic)
    !StateCheck(SecondNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(SecondNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(SecondNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(SecondNearest([PC]))
    OR(2)
        !GlobalTimerNotExpired("DMWW_dispel","LOCALS")
        HasItem("dw#dispe",Myself)  // Mirror
    CheckSpellState(SecondNearest([PC]),PRIORITY_DISPEL)
    !StateCheck(Player1,STATE_DISABLED)
    !CheckStatGT(Player1,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player1,ENEMY)
    !StateCheck(Player2,STATE_DISABLED)
    !CheckStatGT(Player2,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player2,ENEMY)
    !StateCheck(Player3,STATE_DISABLED)
    !CheckStatGT(Player3,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player3,ENEMY)
    !StateCheck(Player4,STATE_DISABLED)
    !CheckStatGT(Player4,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player4,ENEMY)
    !StateCheck(Player5,STATE_DISABLED)
    !CheckStatGT(Player5,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player5,ENEMY)
    !StateCheck(Player6,STATE_DISABLED)
    !CheckStatGT(Player6,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player6,ENEMY)
    !GlobalTimerNotExpired("delay_dispel","LOCALS")
    !CheckStat(SecondNearest([PC]),1,WIZARD_SPELL_IMMUNITY)
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondNearest([PC]),ENEMY)
    !CheckSpellState(Myself,TIME_STOP)
THEN
    RESPONSE #100
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(SecondNearest([PC]),WIZARD_DISPEL_MAGIC)  // SPWI302.SPL (Remove Magic)
        SetGlobalTimer("DMWW_dispel","LOCALS",THREE_ROUNDS)
        SetGlobalTimer("DMWW_antimagic","LOCALS",THREE_ROUNDS)
    RESPONSE #150
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_DISPEL_MAGIC)  // SPWI302.SPL (Remove Magic)
    !StateCheck(ThirdNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(ThirdNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(ThirdNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(ThirdNearest([PC]))
    OR(2)
        !GlobalTimerNotExpired("DMWW_dispel","LOCALS")
        HasItem("dw#dispe",Myself)  // Mirror
    CheckSpellState(ThirdNearest([PC]),PRIORITY_DISPEL)
    !StateCheck(Player1,STATE_DISABLED)
    !CheckStatGT(Player1,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player1,ENEMY)
    !StateCheck(Player2,STATE_DISABLED)
    !CheckStatGT(Player2,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player2,ENEMY)
    !StateCheck(Player3,STATE_DISABLED)
    !CheckStatGT(Player3,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player3,ENEMY)
    !StateCheck(Player4,STATE_DISABLED)
    !CheckStatGT(Player4,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player4,ENEMY)
    !StateCheck(Player5,STATE_DISABLED)
    !CheckStatGT(Player5,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player5,ENEMY)
    !StateCheck(Player6,STATE_DISABLED)
    !CheckStatGT(Player6,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player6,ENEMY)
    !GlobalTimerNotExpired("delay_dispel","LOCALS")
    !CheckStat(ThirdNearest([PC]),1,WIZARD_SPELL_IMMUNITY)
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdNearest([PC]),ENEMY)
    !CheckSpellState(Myself,TIME_STOP)
THEN
    RESPONSE #100
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(ThirdNearest([PC]),WIZARD_DISPEL_MAGIC)  // SPWI302.SPL (Remove Magic)
        SetGlobalTimer("DMWW_dispel","LOCALS",THREE_ROUNDS)
        SetGlobalTimer("DMWW_antimagic","LOCALS",THREE_ROUNDS)
    RESPONSE #150
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_DISPEL_MAGIC)  // SPWI302.SPL (Remove Magic)
    !StateCheck(FourthNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(FourthNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(FourthNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(FourthNearest([PC]))
    OR(2)
        !GlobalTimerNotExpired("DMWW_dispel","LOCALS")
        HasItem("dw#dispe",Myself)  // Mirror
    CheckSpellState(FourthNearest([PC]),PRIORITY_DISPEL)
    !StateCheck(Player1,STATE_DISABLED)
    !CheckStatGT(Player1,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player1,ENEMY)
    !StateCheck(Player2,STATE_DISABLED)
    !CheckStatGT(Player2,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player2,ENEMY)
    !StateCheck(Player3,STATE_DISABLED)
    !CheckStatGT(Player3,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player3,ENEMY)
    !StateCheck(Player4,STATE_DISABLED)
    !CheckStatGT(Player4,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player4,ENEMY)
    !StateCheck(Player5,STATE_DISABLED)
    !CheckStatGT(Player5,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player5,ENEMY)
    !StateCheck(Player6,STATE_DISABLED)
    !CheckStatGT(Player6,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player6,ENEMY)
    !GlobalTimerNotExpired("delay_dispel","LOCALS")
    !CheckStat(FourthNearest([PC]),1,WIZARD_SPELL_IMMUNITY)
    Allegiance(Myself,ENEMY)
    !Allegiance(FourthNearest([PC]),ENEMY)
    !CheckSpellState(Myself,TIME_STOP)
THEN
    RESPONSE #100
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(FourthNearest([PC]),WIZARD_DISPEL_MAGIC)  // SPWI302.SPL (Remove Magic)
        SetGlobalTimer("DMWW_dispel","LOCALS",THREE_ROUNDS)
        SetGlobalTimer("DMWW_antimagic","LOCALS",THREE_ROUNDS)
    RESPONSE #150
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_DISPEL_MAGIC)  // SPWI302.SPL (Remove Magic)
    !StateCheck(FifthNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(FifthNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(FifthNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(FifthNearest([PC]))
    OR(2)
        !GlobalTimerNotExpired("DMWW_dispel","LOCALS")
        HasItem("dw#dispe",Myself)  // Mirror
    CheckSpellState(FifthNearest([PC]),PRIORITY_DISPEL)
    !StateCheck(Player1,STATE_DISABLED)
    !CheckStatGT(Player1,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player1,ENEMY)
    !StateCheck(Player2,STATE_DISABLED)
    !CheckStatGT(Player2,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player2,ENEMY)
    !StateCheck(Player3,STATE_DISABLED)
    !CheckStatGT(Player3,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player3,ENEMY)
    !StateCheck(Player4,STATE_DISABLED)
    !CheckStatGT(Player4,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player4,ENEMY)
    !StateCheck(Player5,STATE_DISABLED)
    !CheckStatGT(Player5,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player5,ENEMY)
    !StateCheck(Player6,STATE_DISABLED)
    !CheckStatGT(Player6,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player6,ENEMY)
    !GlobalTimerNotExpired("delay_dispel","LOCALS")
    !CheckStat(FifthNearest([PC]),1,WIZARD_SPELL_IMMUNITY)
    Allegiance(Myself,ENEMY)
    !Allegiance(FifthNearest([PC]),ENEMY)
    !CheckSpellState(Myself,TIME_STOP)
THEN
    RESPONSE #100
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(FifthNearest([PC]),WIZARD_DISPEL_MAGIC)  // SPWI302.SPL (Remove Magic)
        SetGlobalTimer("DMWW_dispel","LOCALS",THREE_ROUNDS)
        SetGlobalTimer("DMWW_antimagic","LOCALS",THREE_ROUNDS)
    RESPONSE #150
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_DISPEL_MAGIC)  // SPWI302.SPL (Remove Magic)
    !StateCheck(SixthNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(SixthNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(SixthNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(SixthNearest([PC]))
    OR(2)
        !GlobalTimerNotExpired("DMWW_dispel","LOCALS")
        HasItem("dw#dispe",Myself)  // Mirror
    CheckSpellState(SixthNearest([PC]),PRIORITY_DISPEL)
    !StateCheck(Player1,STATE_DISABLED)
    !CheckStatGT(Player1,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player1,ENEMY)
    !StateCheck(Player2,STATE_DISABLED)
    !CheckStatGT(Player2,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player2,ENEMY)
    !StateCheck(Player3,STATE_DISABLED)
    !CheckStatGT(Player3,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player3,ENEMY)
    !StateCheck(Player4,STATE_DISABLED)
    !CheckStatGT(Player4,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player4,ENEMY)
    !StateCheck(Player5,STATE_DISABLED)
    !CheckStatGT(Player5,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player5,ENEMY)
    !StateCheck(Player6,STATE_DISABLED)
    !CheckStatGT(Player6,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player6,ENEMY)
    !GlobalTimerNotExpired("delay_dispel","LOCALS")
    !CheckStat(SixthNearest([PC]),1,WIZARD_SPELL_IMMUNITY)
    Allegiance(Myself,ENEMY)
    !Allegiance(SixthNearest([PC]),ENEMY)
    !CheckSpellState(Myself,TIME_STOP)
THEN
    RESPONSE #100
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(SixthNearest([PC]),WIZARD_DISPEL_MAGIC)  // SPWI302.SPL (Remove Magic)
        SetGlobalTimer("DMWW_dispel","LOCALS",THREE_ROUNDS)
        SetGlobalTimer("DMWW_antimagic","LOCALS",THREE_ROUNDS)
    RESPONSE #150
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    !CheckSpellState(SixthNearest([PC]),DO_NOT_TARGET_SPELLS)
    OR(2)
        !GlobalTimerNotExpired("DMWW_dispel","LOCALS")
        HasItem("dw#dispe",Myself)  // Mirror
    OR(6)
        CheckSpellState(SixthNearest([PC]),BUFF_PRO_WEAPONS)
        CheckSpellState(SixthNearest([PC]),BUFF_PRO_DAMAGE)
        CheckSpellState(SixthNearest([PC]),BUFF_PRO_SPELLS)
        CheckSpellState(SixthNearest([PC]),BUFF_PRO_EFFECTS)
        CheckSpellState(SixthNearest([PC]),BUFF_ENHANCEMENT)
        CheckStatGT(SixthNearest([PC]),0,STONESKINS)
    !StateCheck(Player1,STATE_DISABLED)
    !CheckStatGT(Player1,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player1,ENEMY)
    !StateCheck(Player2,STATE_DISABLED)
    !CheckStatGT(Player2,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player2,ENEMY)
    !StateCheck(Player3,STATE_DISABLED)
    !CheckStatGT(Player3,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player3,ENEMY)
    !StateCheck(Player4,STATE_DISABLED)
    !CheckStatGT(Player4,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player4,ENEMY)
    !StateCheck(Player5,STATE_DISABLED)
    !CheckStatGT(Player5,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player5,ENEMY)
    !StateCheck(Player6,STATE_DISABLED)
    !CheckStatGT(Player6,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player6,ENEMY)
    !GlobalTimerNotExpired("delay_dispel","LOCALS")
    !CheckStat(SixthNearest([PC]),1,WIZARD_SPELL_IMMUNITY)
    Allegiance(Myself,ENEMY)
    !Allegiance(SixthNearest([PC]),ENEMY)
    !CheckSpellState(Myself,TIME_STOP)
    See(SixthNearest([PC]))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    !CheckSpellState(FifthNearest([PC]),DO_NOT_TARGET_SPELLS)
    OR(2)
        !GlobalTimerNotExpired("DMWW_dispel","LOCALS")
        HasItem("dw#dispe",Myself)  // Mirror
    OR(6)
        CheckSpellState(FifthNearest([PC]),BUFF_PRO_WEAPONS)
        CheckSpellState(FifthNearest([PC]),BUFF_PRO_DAMAGE)
        CheckSpellState(FifthNearest([PC]),BUFF_PRO_SPELLS)
        CheckSpellState(FifthNearest([PC]),BUFF_PRO_EFFECTS)
        CheckSpellState(FifthNearest([PC]),BUFF_ENHANCEMENT)
        CheckStatGT(FifthNearest([PC]),0,STONESKINS)
    !StateCheck(Player1,STATE_DISABLED)
    !CheckStatGT(Player1,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player1,ENEMY)
    !StateCheck(Player2,STATE_DISABLED)
    !CheckStatGT(Player2,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player2,ENEMY)
    !StateCheck(Player3,STATE_DISABLED)
    !CheckStatGT(Player3,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player3,ENEMY)
    !StateCheck(Player4,STATE_DISABLED)
    !CheckStatGT(Player4,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player4,ENEMY)
    !StateCheck(Player5,STATE_DISABLED)
    !CheckStatGT(Player5,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player5,ENEMY)
    !StateCheck(Player6,STATE_DISABLED)
    !CheckStatGT(Player6,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player6,ENEMY)
    !GlobalTimerNotExpired("delay_dispel","LOCALS")
    !CheckStat(FifthNearest([PC]),1,WIZARD_SPELL_IMMUNITY)
    Allegiance(Myself,ENEMY)
    !Allegiance(FifthNearest([PC]),ENEMY)
    !CheckSpellState(Myself,TIME_STOP)
    See(FifthNearest([PC]))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    !CheckSpellState(FourthNearest([PC]),DO_NOT_TARGET_SPELLS)
    OR(2)
        !GlobalTimerNotExpired("DMWW_dispel","LOCALS")
        HasItem("dw#dispe",Myself)  // Mirror
    OR(6)
        CheckSpellState(FourthNearest([PC]),BUFF_PRO_WEAPONS)
        CheckSpellState(FourthNearest([PC]),BUFF_PRO_DAMAGE)
        CheckSpellState(FourthNearest([PC]),BUFF_PRO_SPELLS)
        CheckSpellState(FourthNearest([PC]),BUFF_PRO_EFFECTS)
        CheckSpellState(FourthNearest([PC]),BUFF_ENHANCEMENT)
        CheckStatGT(FourthNearest([PC]),0,STONESKINS)
    !StateCheck(Player1,STATE_DISABLED)
    !CheckStatGT(Player1,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player1,ENEMY)
    !StateCheck(Player2,STATE_DISABLED)
    !CheckStatGT(Player2,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player2,ENEMY)
    !StateCheck(Player3,STATE_DISABLED)
    !CheckStatGT(Player3,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player3,ENEMY)
    !StateCheck(Player4,STATE_DISABLED)
    !CheckStatGT(Player4,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player4,ENEMY)
    !StateCheck(Player5,STATE_DISABLED)
    !CheckStatGT(Player5,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player5,ENEMY)
    !StateCheck(Player6,STATE_DISABLED)
    !CheckStatGT(Player6,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player6,ENEMY)
    !GlobalTimerNotExpired("delay_dispel","LOCALS")
    !CheckStat(FourthNearest([PC]),1,WIZARD_SPELL_IMMUNITY)
    Allegiance(Myself,ENEMY)
    !Allegiance(FourthNearest([PC]),ENEMY)
    !CheckSpellState(Myself,TIME_STOP)
    See(FourthNearest([PC]))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    !CheckSpellState(ThirdNearest([PC]),DO_NOT_TARGET_SPELLS)
    OR(2)
        !GlobalTimerNotExpired("DMWW_dispel","LOCALS")
        HasItem("dw#dispe",Myself)  // Mirror
    OR(6)
        CheckSpellState(ThirdNearest([PC]),BUFF_PRO_WEAPONS)
        CheckSpellState(ThirdNearest([PC]),BUFF_PRO_DAMAGE)
        CheckSpellState(ThirdNearest([PC]),BUFF_PRO_SPELLS)
        CheckSpellState(ThirdNearest([PC]),BUFF_PRO_EFFECTS)
        CheckSpellState(ThirdNearest([PC]),BUFF_ENHANCEMENT)
        CheckStatGT(ThirdNearest([PC]),0,STONESKINS)
    !StateCheck(Player1,STATE_DISABLED)
    !CheckStatGT(Player1,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player1,ENEMY)
    !StateCheck(Player2,STATE_DISABLED)
    !CheckStatGT(Player2,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player2,ENEMY)
    !StateCheck(Player3,STATE_DISABLED)
    !CheckStatGT(Player3,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player3,ENEMY)
    !StateCheck(Player4,STATE_DISABLED)
    !CheckStatGT(Player4,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player4,ENEMY)
    !StateCheck(Player5,STATE_DISABLED)
    !CheckStatGT(Player5,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player5,ENEMY)
    !StateCheck(Player6,STATE_DISABLED)
    !CheckStatGT(Player6,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player6,ENEMY)
    !GlobalTimerNotExpired("delay_dispel","LOCALS")
    !CheckStat(ThirdNearest([PC]),1,WIZARD_SPELL_IMMUNITY)
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdNearest([PC]),ENEMY)
    !CheckSpellState(Myself,TIME_STOP)
    See(ThirdNearest([PC]))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    !CheckSpellState(SecondNearest([PC]),DO_NOT_TARGET_SPELLS)
    OR(2)
        !GlobalTimerNotExpired("DMWW_dispel","LOCALS")
        HasItem("dw#dispe",Myself)  // Mirror
    OR(6)
        CheckSpellState(SecondNearest([PC]),BUFF_PRO_WEAPONS)
        CheckSpellState(SecondNearest([PC]),BUFF_PRO_DAMAGE)
        CheckSpellState(SecondNearest([PC]),BUFF_PRO_SPELLS)
        CheckSpellState(SecondNearest([PC]),BUFF_PRO_EFFECTS)
        CheckSpellState(SecondNearest([PC]),BUFF_ENHANCEMENT)
        CheckStatGT(SecondNearest([PC]),0,STONESKINS)
    !StateCheck(Player1,STATE_DISABLED)
    !CheckStatGT(Player1,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player1,ENEMY)
    !StateCheck(Player2,STATE_DISABLED)
    !CheckStatGT(Player2,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player2,ENEMY)
    !StateCheck(Player3,STATE_DISABLED)
    !CheckStatGT(Player3,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player3,ENEMY)
    !StateCheck(Player4,STATE_DISABLED)
    !CheckStatGT(Player4,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player4,ENEMY)
    !StateCheck(Player5,STATE_DISABLED)
    !CheckStatGT(Player5,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player5,ENEMY)
    !StateCheck(Player6,STATE_DISABLED)
    !CheckStatGT(Player6,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player6,ENEMY)
    !GlobalTimerNotExpired("delay_dispel","LOCALS")
    !CheckStat(SecondNearest([PC]),1,WIZARD_SPELL_IMMUNITY)
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondNearest([PC]),ENEMY)
    !CheckSpellState(Myself,TIME_STOP)
    See(SecondNearest([PC]))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    !CheckSpellState([PC],DO_NOT_TARGET_SPELLS)
    OR(2)
        !GlobalTimerNotExpired("DMWW_dispel","LOCALS")
        HasItem("dw#dispe",Myself)  // Mirror
    OR(6)
        CheckSpellState([PC],BUFF_PRO_WEAPONS)
        CheckSpellState([PC],BUFF_PRO_DAMAGE)
        CheckSpellState([PC],BUFF_PRO_SPELLS)
        CheckSpellState([PC],BUFF_PRO_EFFECTS)
        CheckSpellState([PC],BUFF_ENHANCEMENT)
        CheckStatGT([PC],0,STONESKINS)
    !StateCheck(Player1,STATE_DISABLED)
    !CheckStatGT(Player1,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player1,ENEMY)
    !StateCheck(Player2,STATE_DISABLED)
    !CheckStatGT(Player2,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player2,ENEMY)
    !StateCheck(Player3,STATE_DISABLED)
    !CheckStatGT(Player3,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player3,ENEMY)
    !StateCheck(Player4,STATE_DISABLED)
    !CheckStatGT(Player4,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player4,ENEMY)
    !StateCheck(Player5,STATE_DISABLED)
    !CheckStatGT(Player5,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player5,ENEMY)
    !StateCheck(Player6,STATE_DISABLED)
    !CheckStatGT(Player6,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player6,ENEMY)
    !GlobalTimerNotExpired("delay_dispel","LOCALS")
    !CheckStat([PC],1,WIZARD_SPELL_IMMUNITY)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC],ENEMY)
    !CheckSpellState(Myself,TIME_STOP)
    See([PC])
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_DISPEL_MAGIC)  // SPWI302.SPL (Remove Magic)
    !StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
    !CheckStatGT(LastSeenBy(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(LastSeenBy(Myself),DO_NOT_TARGET_SPELLS)
    OR(2)
        !GlobalTimerNotExpired("DMWW_dispel","LOCALS")
        HasItem("dw#dispe",Myself)  // Mirror
    OR(6)
        CheckSpellState(LastSeenBy(Myself),BUFF_PRO_WEAPONS)
        CheckSpellState(LastSeenBy(Myself),BUFF_PRO_DAMAGE)
        CheckSpellState(LastSeenBy(Myself),BUFF_PRO_SPELLS)
        CheckSpellState(LastSeenBy(Myself),BUFF_PRO_EFFECTS)
        CheckSpellState(LastSeenBy(Myself),BUFF_ENHANCEMENT)
        CheckStatGT(LastSeenBy(Myself),0,STONESKINS)
    !StateCheck(Player1,STATE_DISABLED)
    !CheckStatGT(Player1,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player1,ENEMY)
    !StateCheck(Player2,STATE_DISABLED)
    !CheckStatGT(Player2,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player2,ENEMY)
    !StateCheck(Player3,STATE_DISABLED)
    !CheckStatGT(Player3,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player3,ENEMY)
    !StateCheck(Player4,STATE_DISABLED)
    !CheckStatGT(Player4,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player4,ENEMY)
    !StateCheck(Player5,STATE_DISABLED)
    !CheckStatGT(Player5,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player5,ENEMY)
    !StateCheck(Player6,STATE_DISABLED)
    !CheckStatGT(Player6,0,CLERIC_INSECT_PLAGUE)
    !Allegiance(Player6,ENEMY)
    !GlobalTimerNotExpired("delay_dispel","LOCALS")
    !CheckStat(LastSeenBy(Myself),1,WIZARD_SPELL_IMMUNITY)
    Allegiance(Myself,ENEMY)
    !Allegiance(LastSeenBy(Myself),ENEMY)
    !CheckSpellState(Myself,TIME_STOP)
    See(LastSeenBy(Myself))
THEN
    RESPONSE #100
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(LastSeenBy(Myself),WIZARD_DISPEL_MAGIC)  // SPWI302.SPL (Remove Magic)
        SetGlobalTimer("DMWW_dispel","LOCALS",THREE_ROUNDS)
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_SUN_FIRE)  // SPWI523.SPL (Sunfire)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    Allegiance(Myself,ENEMY)
    !Allegiance(SixthNearestEnemyOf(Myself),ENEMY)
    OR(2)
        !CheckStatGT(SixthNearestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    !CheckStatGT(SixthNearestEnemyOf(Myself),50,RESISTFIRE)
    !CheckStat(SixthNearestEnemyOf(Myself),6,WIZARD_SPELL_IMMUNITY)
    Range(SixthNearestEnemyOf(Myself),10)
    OR(2)
        Range(SecondNearestEnemyOfType([0.HUMANOID]),10)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(4)
        !Range(NearestAllyOf(Myself),10)
        CheckStatGT(NearestAllyOf(Myself),59,RESISTFIRE)
        Race(NearestAllyOf(Myself),LICH)
        Race(NearestAllyOf(Myself),RAKSHASA)
    See(SixthNearestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_SUN_FIRE)  // SPWI523.SPL (Sunfire)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    Allegiance(Myself,ENEMY)
    !Allegiance(FifthNearestEnemyOf(Myself),ENEMY)
    OR(2)
        !CheckStatGT(FifthNearestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    !CheckStatGT(FifthNearestEnemyOf(Myself),50,RESISTFIRE)
    !CheckStat(FifthNearestEnemyOf(Myself),6,WIZARD_SPELL_IMMUNITY)
    Range(FifthNearestEnemyOf(Myself),10)
    OR(2)
        Range(SecondNearestEnemyOfType([0.HUMANOID]),10)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(4)
        !Range(NearestAllyOf(Myself),10)
        CheckStatGT(NearestAllyOf(Myself),59,RESISTFIRE)
        Race(NearestAllyOf(Myself),LICH)
        Race(NearestAllyOf(Myself),RAKSHASA)
    See(FifthNearestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_SUN_FIRE)  // SPWI523.SPL (Sunfire)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    Allegiance(Myself,ENEMY)
    !Allegiance(FourthNearestEnemyOf(Myself),ENEMY)
    OR(2)
        !CheckStatGT(FourthNearestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    !CheckStatGT(FourthNearestEnemyOf(Myself),50,RESISTFIRE)
    !CheckStat(FourthNearestEnemyOf(Myself),6,WIZARD_SPELL_IMMUNITY)
    Range(FourthNearestEnemyOf(Myself),10)
    OR(2)
        Range(SecondNearestEnemyOfType([0.HUMANOID]),10)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(4)
        !Range(NearestAllyOf(Myself),10)
        CheckStatGT(NearestAllyOf(Myself),59,RESISTFIRE)
        Race(NearestAllyOf(Myself),LICH)
        Race(NearestAllyOf(Myself),RAKSHASA)
    See(FourthNearestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_SUN_FIRE)  // SPWI523.SPL (Sunfire)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdNearestEnemyOf(Myself),ENEMY)
    OR(2)
        !CheckStatGT(ThirdNearestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    !CheckStatGT(ThirdNearestEnemyOf(Myself),50,RESISTFIRE)
    !CheckStat(ThirdNearestEnemyOf(Myself),6,WIZARD_SPELL_IMMUNITY)
    Range(ThirdNearestEnemyOf(Myself),10)
    OR(2)
        Range(SecondNearestEnemyOfType([0.HUMANOID]),10)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(4)
        !Range(NearestAllyOf(Myself),10)
        CheckStatGT(NearestAllyOf(Myself),59,RESISTFIRE)
        Race(NearestAllyOf(Myself),LICH)
        Race(NearestAllyOf(Myself),RAKSHASA)
    See(ThirdNearestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_SUN_FIRE)  // SPWI523.SPL (Sunfire)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondNearestEnemyOf(Myself),ENEMY)
    OR(2)
        !CheckStatGT(SecondNearestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    !CheckStatGT(SecondNearestEnemyOf(Myself),50,RESISTFIRE)
    !CheckStat(SecondNearestEnemyOf(Myself),6,WIZARD_SPELL_IMMUNITY)
    Range(SecondNearestEnemyOf(Myself),10)
    OR(2)
        Range(SecondNearestEnemyOfType([0.HUMANOID]),10)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(4)
        !Range(NearestAllyOf(Myself),10)
        CheckStatGT(NearestAllyOf(Myself),59,RESISTFIRE)
        Race(NearestAllyOf(Myself),LICH)
        Race(NearestAllyOf(Myself),RAKSHASA)
    See(SecondNearestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_SUN_FIRE)  // SPWI523.SPL (Sunfire)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    Allegiance(Myself,ENEMY)
    !Allegiance(NearestEnemyOf(Myself),ENEMY)
    OR(2)
        !CheckStatGT(NearestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    !CheckStatGT(NearestEnemyOf(Myself),50,RESISTFIRE)
    !CheckStat(NearestEnemyOf(Myself),6,WIZARD_SPELL_IMMUNITY)
    Range(NearestEnemyOf(Myself),10)
    OR(2)
        Range(SecondNearestEnemyOfType([0.HUMANOID]),10)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(4)
        !Range(NearestAllyOf(Myself),10)
        CheckStatGT(NearestAllyOf(Myself),59,RESISTFIRE)
        Race(NearestAllyOf(Myself),LICH)
        Race(NearestAllyOf(Myself),RAKSHASA)
    See(NearestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_SUN_FIRE)  // SPWI523.SPL (Sunfire)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    Allegiance(Myself,ENEMY)
    !Allegiance(LastSeenBy(Myself),ENEMY)
    OR(2)
        !CheckStatGT(LastSeenBy(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    !CheckStatGT(LastSeenBy(Myself),50,RESISTFIRE)
    !CheckStat(LastSeenBy(Myself),6,WIZARD_SPELL_IMMUNITY)
    Range(LastSeenBy(Myself),10)
    OR(2)
        Range(SecondNearestEnemyOfType([0.HUMANOID]),10)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(4)
        !Range(NearestAllyOf(Myself),10)
        CheckStatGT(NearestAllyOf(Myself),59,RESISTFIRE)
        Race(NearestAllyOf(Myself),LICH)
        Race(NearestAllyOf(Myself),RAKSHASA)
    See(LastSeenBy(Myself))
THEN
    RESPONSE #150
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(Myself,WIZARD_SUN_FIRE)  // SPWI523.SPL (Sunfire)
    RESPONSE #50
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CONE_OF_COLD)  // SPWI503.SPL (Cone of Cold)
    !StateCheck([PC],STATE_INVISIBLE)
    !CheckStatGT([PC],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC],DO_NOT_TARGET_SPELLS)
    See([PC])
    OR(2)
        !CheckStatGT([PC],50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance([PC],ENEMY)
    !CheckStat([PC],6,WIZARD_SPELL_IMMUNITY)
    Range([PC],10)
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC],WIZARD_CONE_OF_COLD)  // SPWI503.SPL (Cone of Cold)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CONE_OF_COLD)  // SPWI503.SPL (Cone of Cold)
    !StateCheck(SecondNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(SecondNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(SecondNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(SecondNearest([PC]))
    OR(2)
        !CheckStatGT(SecondNearest([PC]),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondNearest([PC]),ENEMY)
    !CheckStat(SecondNearest([PC]),6,WIZARD_SPELL_IMMUNITY)
    Range(SecondNearest([PC]),10)
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(SecondNearest([PC]),WIZARD_CONE_OF_COLD)  // SPWI503.SPL (Cone of Cold)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CONE_OF_COLD)  // SPWI503.SPL (Cone of Cold)
    !StateCheck(ThirdNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(ThirdNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(ThirdNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(ThirdNearest([PC]))
    OR(2)
        !CheckStatGT(ThirdNearest([PC]),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdNearest([PC]),ENEMY)
    !CheckStat(ThirdNearest([PC]),6,WIZARD_SPELL_IMMUNITY)
    Range(ThirdNearest([PC]),10)
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(ThirdNearest([PC]),WIZARD_CONE_OF_COLD)  // SPWI503.SPL (Cone of Cold)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CONE_OF_COLD)  // SPWI503.SPL (Cone of Cold)
    !StateCheck(FourthNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(FourthNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(FourthNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(FourthNearest([PC]))
    OR(2)
        !CheckStatGT(FourthNearest([PC]),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(FourthNearest([PC]),ENEMY)
    !CheckStat(FourthNearest([PC]),6,WIZARD_SPELL_IMMUNITY)
    Range(FourthNearest([PC]),10)
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(FourthNearest([PC]),WIZARD_CONE_OF_COLD)  // SPWI503.SPL (Cone of Cold)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CONE_OF_COLD)  // SPWI503.SPL (Cone of Cold)
    !StateCheck(FifthNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(FifthNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(FifthNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(FifthNearest([PC]))
    OR(2)
        !CheckStatGT(FifthNearest([PC]),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(FifthNearest([PC]),ENEMY)
    !CheckStat(FifthNearest([PC]),6,WIZARD_SPELL_IMMUNITY)
    Range(FifthNearest([PC]),10)
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(FifthNearest([PC]),WIZARD_CONE_OF_COLD)  // SPWI503.SPL (Cone of Cold)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CONE_OF_COLD)  // SPWI503.SPL (Cone of Cold)
    !StateCheck(SixthNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(SixthNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(SixthNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(SixthNearest([PC]))
    OR(2)
        !CheckStatGT(SixthNearest([PC]),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(SixthNearest([PC]),ENEMY)
    !CheckStat(SixthNearest([PC]),6,WIZARD_SPELL_IMMUNITY)
    Range(SixthNearest([PC]),10)
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(SixthNearest([PC]),WIZARD_CONE_OF_COLD)  // SPWI503.SPL (Cone of Cold)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CONE_OF_COLD)  // SPWI503.SPL (Cone of Cold)
    !StateCheck(NearestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(NearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(NearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    See(NearestEnemyOf(Myself))
    OR(2)
        !CheckStatGT(NearestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(NearestEnemyOf(Myself),ENEMY)
    !CheckStat(NearestEnemyOf(Myself),6,WIZARD_SPELL_IMMUNITY)
    Range(NearestEnemyOf(Myself),10)
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(NearestEnemyOf(Myself),WIZARD_CONE_OF_COLD)  // SPWI503.SPL (Cone of Cold)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CONE_OF_COLD)  // SPWI503.SPL (Cone of Cold)
    !StateCheck(SecondNearestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(SecondNearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    See(SecondNearestEnemyOf(Myself))
    OR(2)
        !CheckStatGT(SecondNearestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondNearestEnemyOf(Myself),ENEMY)
    !CheckStat(SecondNearestEnemyOf(Myself),6,WIZARD_SPELL_IMMUNITY)
    Range(SecondNearestEnemyOf(Myself),10)
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(SecondNearestEnemyOf(Myself),WIZARD_CONE_OF_COLD)  // SPWI503.SPL (Cone of Cold)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CONE_OF_COLD)  // SPWI503.SPL (Cone of Cold)
    !StateCheck(ThirdNearestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(ThirdNearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    See(ThirdNearestEnemyOf(Myself))
    OR(2)
        !CheckStatGT(ThirdNearestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdNearestEnemyOf(Myself),ENEMY)
    !CheckStat(ThirdNearestEnemyOf(Myself),6,WIZARD_SPELL_IMMUNITY)
    Range(ThirdNearestEnemyOf(Myself),10)
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(ThirdNearestEnemyOf(Myself),WIZARD_CONE_OF_COLD)  // SPWI503.SPL (Cone of Cold)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_LIGHTNING_BOLT)  // SPWI308.SPL (Lightning Bolt)
    !StateCheck(SixthNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(SixthNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(SixthNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(SixthNearest([PC]))
    CheckStat(Myself,1,MINORGLOBE)
    OR(2)
        !CheckStatGT(SixthNearest([PC]),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(SixthNearest([PC]),ENEMY)
    !CheckStat(SixthNearest([PC]),6,WIZARD_SPELL_IMMUNITY)
    !CheckStatGT(SixthNearest([PC]),0,MINORGLOBE)
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(SixthNearest([PC]),WIZARD_LIGHTNING_BOLT)  // SPWI308.SPL (Lightning Bolt)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_LIGHTNING_BOLT)  // SPWI308.SPL (Lightning Bolt)
    !StateCheck(FifthNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(FifthNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(FifthNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(FifthNearest([PC]))
    CheckStat(Myself,1,MINORGLOBE)
    OR(2)
        !CheckStatGT(FifthNearest([PC]),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(FifthNearest([PC]),ENEMY)
    !CheckStat(FifthNearest([PC]),6,WIZARD_SPELL_IMMUNITY)
    !CheckStatGT(FifthNearest([PC]),0,MINORGLOBE)
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(FifthNearest([PC]),WIZARD_LIGHTNING_BOLT)  // SPWI308.SPL (Lightning Bolt)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_LIGHTNING_BOLT)  // SPWI308.SPL (Lightning Bolt)
    !StateCheck(FourthNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(FourthNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(FourthNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(FourthNearest([PC]))
    CheckStat(Myself,1,MINORGLOBE)
    OR(2)
        !CheckStatGT(FourthNearest([PC]),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(FourthNearest([PC]),ENEMY)
    !CheckStat(FourthNearest([PC]),6,WIZARD_SPELL_IMMUNITY)
    !CheckStatGT(FourthNearest([PC]),0,MINORGLOBE)
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(FourthNearest([PC]),WIZARD_LIGHTNING_BOLT)  // SPWI308.SPL (Lightning Bolt)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_LIGHTNING_BOLT)  // SPWI308.SPL (Lightning Bolt)
    !StateCheck(ThirdNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(ThirdNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(ThirdNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(ThirdNearest([PC]))
    CheckStat(Myself,1,MINORGLOBE)
    OR(2)
        !CheckStatGT(ThirdNearest([PC]),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdNearest([PC]),ENEMY)
    !CheckStat(ThirdNearest([PC]),6,WIZARD_SPELL_IMMUNITY)
    !CheckStatGT(ThirdNearest([PC]),0,MINORGLOBE)
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(ThirdNearest([PC]),WIZARD_LIGHTNING_BOLT)  // SPWI308.SPL (Lightning Bolt)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_LIGHTNING_BOLT)  // SPWI308.SPL (Lightning Bolt)
    !StateCheck(SecondNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(SecondNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(SecondNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(SecondNearest([PC]))
    CheckStat(Myself,1,MINORGLOBE)
    OR(2)
        !CheckStatGT(SecondNearest([PC]),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondNearest([PC]),ENEMY)
    !CheckStat(SecondNearest([PC]),6,WIZARD_SPELL_IMMUNITY)
    !CheckStatGT(SecondNearest([PC]),0,MINORGLOBE)
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(SecondNearest([PC]),WIZARD_LIGHTNING_BOLT)  // SPWI308.SPL (Lightning Bolt)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_LIGHTNING_BOLT)  // SPWI308.SPL (Lightning Bolt)
    !StateCheck([PC],STATE_INVISIBLE)
    !CheckStatGT([PC],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC],DO_NOT_TARGET_SPELLS)
    See([PC])
    CheckStat(Myself,1,MINORGLOBE)
    OR(2)
        !CheckStatGT([PC],50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance([PC],ENEMY)
    !CheckStat([PC],6,WIZARD_SPELL_IMMUNITY)
    !CheckStatGT([PC],0,MINORGLOBE)
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC],WIZARD_LIGHTNING_BOLT)  // SPWI308.SPL (Lightning Bolt)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_LIGHTNING_BOLT)  // SPWI308.SPL (Lightning Bolt)
    !StateCheck(FarthestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(FarthestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(FarthestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    See(FarthestEnemyOf(Myself))
    CheckStat(Myself,1,MINORGLOBE)
    OR(2)
        !CheckStatGT(FarthestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(FarthestEnemyOf(Myself),ENEMY)
    !CheckStat(FarthestEnemyOf(Myself),6,WIZARD_SPELL_IMMUNITY)
    !CheckStatGT(FarthestEnemyOf(Myself),0,MINORGLOBE)
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(FarthestEnemyOf(Myself),WIZARD_LIGHTNING_BOLT)  // SPWI308.SPL (Lightning Bolt)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_LIGHTNING_BOLT)  // SPWI308.SPL (Lightning Bolt)
    !StateCheck(SecondFarthestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(SecondFarthestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(SecondFarthestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    See(SecondFarthestEnemyOf(Myself))
    CheckStat(Myself,1,MINORGLOBE)
    OR(2)
        !CheckStatGT(SecondFarthestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondFarthestEnemyOf(Myself),ENEMY)
    !CheckStat(SecondFarthestEnemyOf(Myself),6,WIZARD_SPELL_IMMUNITY)
    !CheckStatGT(SecondFarthestEnemyOf(Myself),0,MINORGLOBE)
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(SecondFarthestEnemyOf(Myself),WIZARD_LIGHTNING_BOLT)  // SPWI308.SPL (Lightning Bolt)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_LIGHTNING_BOLT)  // SPWI308.SPL (Lightning Bolt)
    !StateCheck(ThirdFarthestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(ThirdFarthestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(ThirdFarthestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    See(ThirdFarthestEnemyOf(Myself))
    CheckStat(Myself,1,MINORGLOBE)
    OR(2)
        !CheckStatGT(ThirdFarthestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdFarthestEnemyOf(Myself),ENEMY)
    !CheckStat(ThirdFarthestEnemyOf(Myself),6,WIZARD_SPELL_IMMUNITY)
    !CheckStatGT(ThirdFarthestEnemyOf(Myself),0,MINORGLOBE)
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(ThirdFarthestEnemyOf(Myself),WIZARD_LIGHTNING_BOLT)  // SPWI308.SPL (Lightning Bolt)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_FIREBALL)  // SPWI304.SPL (Fireball)
    !StateCheck(SixthNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(SixthNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(SixthNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(SixthNearest([PC]))
    OR(2)
        !CheckStatGT(SixthNearest([PC]),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(SixthNearest([PC]),ENEMY)
    !CheckStatGT(SixthNearest([PC]),0,MINORGLOBE)
    !CheckStat(SixthNearest([PC]),6,WIZARD_SPELL_IMMUNITY)
    OR(3)
        TriggerOverride(SixthNearest([PC]),Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(6)
        !TriggerOverride(SixthNearest([PC]),Range(NearestEnemyOfType([0.HUMANOID]),22))
        TriggerOverride(SixthNearest([PC]),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),59,RESISTFIRE))
        TriggerOverride(SixthNearest([PC]),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),59,RESISTMAGIC))
        TriggerOverride(SixthNearest([PC]),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),0,MINORGLOBE))
        TriggerOverride(SixthNearest([PC]),Race(NearestEnemyOfType([0.HUMANOID]),RAKSHASA))
        TriggerOverride(SixthNearest([PC]),Race(NearestEnemyOfType([0.HUMANOID]),LICH))
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(SixthNearest([PC]),WIZARD_FIREBALL)  // SPWI304.SPL (Fireball)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_FIREBALL)  // SPWI304.SPL (Fireball)
    !StateCheck(FifthNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(FifthNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(FifthNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(FifthNearest([PC]))
    OR(2)
        !CheckStatGT(FifthNearest([PC]),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(FifthNearest([PC]),ENEMY)
    !CheckStatGT(FifthNearest([PC]),0,MINORGLOBE)
    !CheckStat(FifthNearest([PC]),6,WIZARD_SPELL_IMMUNITY)
    OR(3)
        TriggerOverride(FifthNearest([PC]),Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(6)
        !TriggerOverride(FifthNearest([PC]),Range(NearestEnemyOfType([0.HUMANOID]),22))
        TriggerOverride(FifthNearest([PC]),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),59,RESISTFIRE))
        TriggerOverride(FifthNearest([PC]),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),59,RESISTMAGIC))
        TriggerOverride(FifthNearest([PC]),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),0,MINORGLOBE))
        TriggerOverride(FifthNearest([PC]),Race(NearestEnemyOfType([0.HUMANOID]),RAKSHASA))
        TriggerOverride(FifthNearest([PC]),Race(NearestEnemyOfType([0.HUMANOID]),LICH))
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(FifthNearest([PC]),WIZARD_FIREBALL)  // SPWI304.SPL (Fireball)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_FIREBALL)  // SPWI304.SPL (Fireball)
    !StateCheck(FourthNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(FourthNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(FourthNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(FourthNearest([PC]))
    OR(2)
        !CheckStatGT(FourthNearest([PC]),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(FourthNearest([PC]),ENEMY)
    !CheckStatGT(FourthNearest([PC]),0,MINORGLOBE)
    !CheckStat(FourthNearest([PC]),6,WIZARD_SPELL_IMMUNITY)
    OR(3)
        TriggerOverride(FourthNearest([PC]),Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(6)
        !TriggerOverride(FourthNearest([PC]),Range(NearestEnemyOfType([0.HUMANOID]),22))
        TriggerOverride(FourthNearest([PC]),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),59,RESISTFIRE))
        TriggerOverride(FourthNearest([PC]),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),59,RESISTMAGIC))
        TriggerOverride(FourthNearest([PC]),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),0,MINORGLOBE))
        TriggerOverride(FourthNearest([PC]),Race(NearestEnemyOfType([0.HUMANOID]),RAKSHASA))
        TriggerOverride(FourthNearest([PC]),Race(NearestEnemyOfType([0.HUMANOID]),LICH))
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(FourthNearest([PC]),WIZARD_FIREBALL)  // SPWI304.SPL (Fireball)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_FIREBALL)  // SPWI304.SPL (Fireball)
    !StateCheck(ThirdNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(ThirdNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(ThirdNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(ThirdNearest([PC]))
    OR(2)
        !CheckStatGT(ThirdNearest([PC]),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdNearest([PC]),ENEMY)
    !CheckStatGT(ThirdNearest([PC]),0,MINORGLOBE)
    !CheckStat(ThirdNearest([PC]),6,WIZARD_SPELL_IMMUNITY)
    OR(3)
        TriggerOverride(ThirdNearest([PC]),Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(6)
        !TriggerOverride(ThirdNearest([PC]),Range(NearestEnemyOfType([0.HUMANOID]),22))
        TriggerOverride(ThirdNearest([PC]),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),59,RESISTFIRE))
        TriggerOverride(ThirdNearest([PC]),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),59,RESISTMAGIC))
        TriggerOverride(ThirdNearest([PC]),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),0,MINORGLOBE))
        TriggerOverride(ThirdNearest([PC]),Race(NearestEnemyOfType([0.HUMANOID]),RAKSHASA))
        TriggerOverride(ThirdNearest([PC]),Race(NearestEnemyOfType([0.HUMANOID]),LICH))
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(ThirdNearest([PC]),WIZARD_FIREBALL)  // SPWI304.SPL (Fireball)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_FIREBALL)  // SPWI304.SPL (Fireball)
    !StateCheck(SecondNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(SecondNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(SecondNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(SecondNearest([PC]))
    OR(2)
        !CheckStatGT(SecondNearest([PC]),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondNearest([PC]),ENEMY)
    !CheckStatGT(SecondNearest([PC]),0,MINORGLOBE)
    !CheckStat(SecondNearest([PC]),6,WIZARD_SPELL_IMMUNITY)
    OR(3)
        TriggerOverride(SecondNearest([PC]),Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(6)
        !TriggerOverride(SecondNearest([PC]),Range(NearestEnemyOfType([0.HUMANOID]),22))
        TriggerOverride(SecondNearest([PC]),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),59,RESISTFIRE))
        TriggerOverride(SecondNearest([PC]),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),59,RESISTMAGIC))
        TriggerOverride(SecondNearest([PC]),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),0,MINORGLOBE))
        TriggerOverride(SecondNearest([PC]),Race(NearestEnemyOfType([0.HUMANOID]),RAKSHASA))
        TriggerOverride(SecondNearest([PC]),Race(NearestEnemyOfType([0.HUMANOID]),LICH))
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(SecondNearest([PC]),WIZARD_FIREBALL)  // SPWI304.SPL (Fireball)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_FIREBALL)  // SPWI304.SPL (Fireball)
    !StateCheck([PC],STATE_INVISIBLE)
    !CheckStatGT([PC],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC],DO_NOT_TARGET_SPELLS)
    See([PC])
    OR(2)
        !CheckStatGT([PC],50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance([PC],ENEMY)
    !CheckStatGT([PC],0,MINORGLOBE)
    !CheckStat([PC],6,WIZARD_SPELL_IMMUNITY)
    OR(3)
        TriggerOverride([PC],Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(6)
        !TriggerOverride([PC],Range(NearestEnemyOfType([0.HUMANOID]),22))
        TriggerOverride([PC],CheckStatGT(NearestEnemyOfType([0.HUMANOID]),59,RESISTFIRE))
        TriggerOverride([PC],CheckStatGT(NearestEnemyOfType([0.HUMANOID]),59,RESISTMAGIC))
        TriggerOverride([PC],CheckStatGT(NearestEnemyOfType([0.HUMANOID]),0,MINORGLOBE))
        TriggerOverride([PC],Race(NearestEnemyOfType([0.HUMANOID]),RAKSHASA))
        TriggerOverride([PC],Race(NearestEnemyOfType([0.HUMANOID]),LICH))
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC],WIZARD_FIREBALL)  // SPWI304.SPL (Fireball)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_FIREBALL)  // SPWI304.SPL (Fireball)
    !StateCheck(FarthestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(FarthestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(FarthestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    See(FarthestEnemyOf(Myself))
    OR(2)
        !CheckStatGT(FarthestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(FarthestEnemyOf(Myself),ENEMY)
    !CheckStatGT(FarthestEnemyOf(Myself),0,MINORGLOBE)
    !CheckStat(FarthestEnemyOf(Myself),6,WIZARD_SPELL_IMMUNITY)
    OR(3)
        TriggerOverride(FarthestEnemyOf(Myself),Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(6)
        !TriggerOverride(FarthestEnemyOf(Myself),Range(NearestEnemyOfType([0.HUMANOID]),22))
        TriggerOverride(FarthestEnemyOf(Myself),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),59,RESISTFIRE))
        TriggerOverride(FarthestEnemyOf(Myself),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),59,RESISTMAGIC))
        TriggerOverride(FarthestEnemyOf(Myself),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),0,MINORGLOBE))
        TriggerOverride(FarthestEnemyOf(Myself),Race(NearestEnemyOfType([0.HUMANOID]),RAKSHASA))
        TriggerOverride(FarthestEnemyOf(Myself),Race(NearestEnemyOfType([0.HUMANOID]),LICH))
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(FarthestEnemyOf(Myself),WIZARD_FIREBALL)  // SPWI304.SPL (Fireball)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_FIREBALL)  // SPWI304.SPL (Fireball)
    !StateCheck(SecondFarthestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(SecondFarthestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(SecondFarthestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    See(SecondFarthestEnemyOf(Myself))
    OR(2)
        !CheckStatGT(SecondFarthestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondFarthestEnemyOf(Myself),ENEMY)
    !CheckStatGT(SecondFarthestEnemyOf(Myself),0,MINORGLOBE)
    !CheckStat(SecondFarthestEnemyOf(Myself),6,WIZARD_SPELL_IMMUNITY)
    OR(3)
        TriggerOverride(SecondFarthestEnemyOf(Myself),Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(6)
        !TriggerOverride(SecondFarthestEnemyOf(Myself),Range(NearestEnemyOfType([0.HUMANOID]),22))
        TriggerOverride(SecondFarthestEnemyOf(Myself),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),59,RESISTFIRE))
        TriggerOverride(SecondFarthestEnemyOf(Myself),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),59,RESISTMAGIC))
        TriggerOverride(SecondFarthestEnemyOf(Myself),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),0,MINORGLOBE))
        TriggerOverride(SecondFarthestEnemyOf(Myself),Race(NearestEnemyOfType([0.HUMANOID]),RAKSHASA))
        TriggerOverride(SecondFarthestEnemyOf(Myself),Race(NearestEnemyOfType([0.HUMANOID]),LICH))
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(SecondFarthestEnemyOf(Myself),WIZARD_FIREBALL)  // SPWI304.SPL (Fireball)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_FIREBALL)  // SPWI304.SPL (Fireball)
    !StateCheck(ThirdFarthestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(ThirdFarthestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(ThirdFarthestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    See(ThirdFarthestEnemyOf(Myself))
    OR(2)
        !CheckStatGT(ThirdFarthestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdFarthestEnemyOf(Myself),ENEMY)
    !CheckStatGT(ThirdFarthestEnemyOf(Myself),0,MINORGLOBE)
    !CheckStat(ThirdFarthestEnemyOf(Myself),6,WIZARD_SPELL_IMMUNITY)
    OR(3)
        TriggerOverride(ThirdFarthestEnemyOf(Myself),Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(6)
        !TriggerOverride(ThirdFarthestEnemyOf(Myself),Range(NearestEnemyOfType([0.HUMANOID]),22))
        TriggerOverride(ThirdFarthestEnemyOf(Myself),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),59,RESISTFIRE))
        TriggerOverride(ThirdFarthestEnemyOf(Myself),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),59,RESISTMAGIC))
        TriggerOverride(ThirdFarthestEnemyOf(Myself),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),0,MINORGLOBE))
        TriggerOverride(ThirdFarthestEnemyOf(Myself),Race(NearestEnemyOfType([0.HUMANOID]),RAKSHASA))
        TriggerOverride(ThirdFarthestEnemyOf(Myself),Race(NearestEnemyOfType([0.HUMANOID]),LICH))
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(ThirdFarthestEnemyOf(Myself),WIZARD_FIREBALL)  // SPWI304.SPL (Fireball)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_HORROR)  // SPWI205.SPL (Horror)
    !StateCheck(NearestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(NearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(NearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    !StateCheck(NearestEnemyOf(Myself),STATE_DISABLED)
    !CheckStatGT(NearestEnemyOf(Myself),0,HELD)
    !Kit(NearestEnemyOf(Myself),CAVALIER)
    !CheckStatGT(NearestEnemyOf(Myself),0,WIZARD_RESIST_FEAR)
    !CheckSpellState(NearestEnemyOf(Myself),RESIST_FEAR)
    !General(NearestEnemyOf(Myself),UNDEAD)
    !CheckSpellState(NearestEnemyOf(Myself),STATE_ENRAGED)
    !Kit(NearestEnemyOf(Myself),Blackguard)
    OR(2)
        !CheckSpellState(NearestEnemyOf(Myself),ITEM_PANIC_SEEN)
        !CheckSpellState(NearestEnemyOf(Myself),ITEM_PANIC)
    !CheckStatGT(NearestEnemyOf(Myself),0,MINORGLOBE)
    OR(2)
        !CheckStatGT(NearestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(NearestEnemyOf(Myself),ENEMY)
    OR(3)
        TriggerOverride(NearestEnemyOf(Myself),Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(2)
        !TriggerOverride(NearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        !TriggerOverride(NearestEnemyOf(Myself),StateCheck(SecondNearestAllyOf(Myself),STATE_DISABLED))
    OR(2)
        !TriggerOverride(NearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        TriggerOverride(NearestEnemyOf(Myself),Range(SecondNearestAllyOf(Myself),15))
    CheckStatGT(NearestEnemyOf(Myself),0,SAVEVSSPELL)
    CheckStatLT(Player1,5,LEVEL)
    See(NearestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_HORROR)  // SPWI205.SPL (Horror)
    !StateCheck(SecondNearestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(SecondNearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    !StateCheck(SecondNearestEnemyOf(Myself),STATE_DISABLED)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,HELD)
    !Kit(SecondNearestEnemyOf(Myself),CAVALIER)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,WIZARD_RESIST_FEAR)
    !CheckSpellState(SecondNearestEnemyOf(Myself),RESIST_FEAR)
    !General(SecondNearestEnemyOf(Myself),UNDEAD)
    !CheckSpellState(SecondNearestEnemyOf(Myself),STATE_ENRAGED)
    !Kit(SecondNearestEnemyOf(Myself),Blackguard)
    OR(2)
        !CheckSpellState(SecondNearestEnemyOf(Myself),ITEM_PANIC_SEEN)
        !CheckSpellState(SecondNearestEnemyOf(Myself),ITEM_PANIC)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,MINORGLOBE)
    OR(2)
        !CheckStatGT(SecondNearestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondNearestEnemyOf(Myself),ENEMY)
    OR(3)
        TriggerOverride(SecondNearestEnemyOf(Myself),Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(2)
        !TriggerOverride(SecondNearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        !TriggerOverride(SecondNearestEnemyOf(Myself),StateCheck(SecondNearestAllyOf(Myself),STATE_DISABLED))
    OR(2)
        !TriggerOverride(SecondNearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        TriggerOverride(SecondNearestEnemyOf(Myself),Range(SecondNearestAllyOf(Myself),15))
    CheckStatGT(SecondNearestEnemyOf(Myself),0,SAVEVSSPELL)
    CheckStatLT(Player1,5,LEVEL)
    See(SecondNearestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_HORROR)  // SPWI205.SPL (Horror)
    !StateCheck(ThirdNearestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(ThirdNearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    !StateCheck(ThirdNearestEnemyOf(Myself),STATE_DISABLED)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,HELD)
    !Kit(ThirdNearestEnemyOf(Myself),CAVALIER)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,WIZARD_RESIST_FEAR)
    !CheckSpellState(ThirdNearestEnemyOf(Myself),RESIST_FEAR)
    !General(ThirdNearestEnemyOf(Myself),UNDEAD)
    !CheckSpellState(ThirdNearestEnemyOf(Myself),STATE_ENRAGED)
    !Kit(ThirdNearestEnemyOf(Myself),Blackguard)
    OR(2)
        !CheckSpellState(ThirdNearestEnemyOf(Myself),ITEM_PANIC_SEEN)
        !CheckSpellState(ThirdNearestEnemyOf(Myself),ITEM_PANIC)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,MINORGLOBE)
    OR(2)
        !CheckStatGT(ThirdNearestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdNearestEnemyOf(Myself),ENEMY)
    OR(3)
        TriggerOverride(ThirdNearestEnemyOf(Myself),Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(2)
        !TriggerOverride(ThirdNearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        !TriggerOverride(ThirdNearestEnemyOf(Myself),StateCheck(SecondNearestAllyOf(Myself),STATE_DISABLED))
    OR(2)
        !TriggerOverride(ThirdNearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        TriggerOverride(ThirdNearestEnemyOf(Myself),Range(SecondNearestAllyOf(Myself),15))
    CheckStatGT(ThirdNearestEnemyOf(Myself),0,SAVEVSSPELL)
    CheckStatLT(Player1,5,LEVEL)
    See(ThirdNearestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_HORROR)  // SPWI205.SPL (Horror)
    !StateCheck(FourthNearestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(FourthNearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(FourthNearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    !StateCheck(FourthNearestEnemyOf(Myself),STATE_DISABLED)
    !CheckStatGT(FourthNearestEnemyOf(Myself),0,HELD)
    !Kit(FourthNearestEnemyOf(Myself),CAVALIER)
    !CheckStatGT(FourthNearestEnemyOf(Myself),0,WIZARD_RESIST_FEAR)
    !CheckSpellState(FourthNearestEnemyOf(Myself),RESIST_FEAR)
    !General(FourthNearestEnemyOf(Myself),UNDEAD)
    !CheckSpellState(FourthNearestEnemyOf(Myself),STATE_ENRAGED)
    !Kit(FourthNearestEnemyOf(Myself),Blackguard)
    OR(2)
        !CheckSpellState(FourthNearestEnemyOf(Myself),ITEM_PANIC_SEEN)
        !CheckSpellState(FourthNearestEnemyOf(Myself),ITEM_PANIC)
    !CheckStatGT(FourthNearestEnemyOf(Myself),0,MINORGLOBE)
    OR(2)
        !CheckStatGT(FourthNearestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(FourthNearestEnemyOf(Myself),ENEMY)
    OR(3)
        TriggerOverride(FourthNearestEnemyOf(Myself),Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(2)
        !TriggerOverride(FourthNearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        !TriggerOverride(FourthNearestEnemyOf(Myself),StateCheck(SecondNearestAllyOf(Myself),STATE_DISABLED))
    OR(2)
        !TriggerOverride(FourthNearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        TriggerOverride(FourthNearestEnemyOf(Myself),Range(SecondNearestAllyOf(Myself),15))
    CheckStatGT(FourthNearestEnemyOf(Myself),0,SAVEVSSPELL)
    CheckStatLT(Player1,5,LEVEL)
    See(FourthNearestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_HORROR)  // SPWI205.SPL (Horror)
    !StateCheck(FifthNearestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(FifthNearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(FifthNearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    !StateCheck(FifthNearestEnemyOf(Myself),STATE_DISABLED)
    !CheckStatGT(FifthNearestEnemyOf(Myself),0,HELD)
    !Kit(FifthNearestEnemyOf(Myself),CAVALIER)
    !CheckStatGT(FifthNearestEnemyOf(Myself),0,WIZARD_RESIST_FEAR)
    !CheckSpellState(FifthNearestEnemyOf(Myself),RESIST_FEAR)
    !General(FifthNearestEnemyOf(Myself),UNDEAD)
    !CheckSpellState(FifthNearestEnemyOf(Myself),STATE_ENRAGED)
    !Kit(FifthNearestEnemyOf(Myself),Blackguard)
    OR(2)
        !CheckSpellState(FifthNearestEnemyOf(Myself),ITEM_PANIC_SEEN)
        !CheckSpellState(FifthNearestEnemyOf(Myself),ITEM_PANIC)
    !CheckStatGT(FifthNearestEnemyOf(Myself),0,MINORGLOBE)
    OR(2)
        !CheckStatGT(FifthNearestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(FifthNearestEnemyOf(Myself),ENEMY)
    OR(3)
        TriggerOverride(FifthNearestEnemyOf(Myself),Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(2)
        !TriggerOverride(FifthNearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        !TriggerOverride(FifthNearestEnemyOf(Myself),StateCheck(SecondNearestAllyOf(Myself),STATE_DISABLED))
    OR(2)
        !TriggerOverride(FifthNearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        TriggerOverride(FifthNearestEnemyOf(Myself),Range(SecondNearestAllyOf(Myself),15))
    CheckStatGT(FifthNearestEnemyOf(Myself),0,SAVEVSSPELL)
    CheckStatLT(Player1,5,LEVEL)
    See(FifthNearestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_HORROR)  // SPWI205.SPL (Horror)
    !StateCheck(SixthNearestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(SixthNearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(SixthNearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    !StateCheck(SixthNearestEnemyOf(Myself),STATE_DISABLED)
    !CheckStatGT(SixthNearestEnemyOf(Myself),0,HELD)
    !Kit(SixthNearestEnemyOf(Myself),CAVALIER)
    !CheckStatGT(SixthNearestEnemyOf(Myself),0,WIZARD_RESIST_FEAR)
    !CheckSpellState(SixthNearestEnemyOf(Myself),RESIST_FEAR)
    !General(SixthNearestEnemyOf(Myself),UNDEAD)
    !CheckSpellState(SixthNearestEnemyOf(Myself),STATE_ENRAGED)
    !Kit(SixthNearestEnemyOf(Myself),Blackguard)
    OR(2)
        !CheckSpellState(SixthNearestEnemyOf(Myself),ITEM_PANIC_SEEN)
        !CheckSpellState(SixthNearestEnemyOf(Myself),ITEM_PANIC)
    !CheckStatGT(SixthNearestEnemyOf(Myself),0,MINORGLOBE)
    OR(2)
        !CheckStatGT(SixthNearestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(SixthNearestEnemyOf(Myself),ENEMY)
    OR(3)
        TriggerOverride(SixthNearestEnemyOf(Myself),Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(2)
        !TriggerOverride(SixthNearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        !TriggerOverride(SixthNearestEnemyOf(Myself),StateCheck(SecondNearestAllyOf(Myself),STATE_DISABLED))
    OR(2)
        !TriggerOverride(SixthNearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        TriggerOverride(SixthNearestEnemyOf(Myself),Range(SecondNearestAllyOf(Myself),15))
    CheckStatGT(SixthNearestEnemyOf(Myself),0,SAVEVSSPELL)
    CheckStatLT(Player1,5,LEVEL)
    See(SixthNearestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_HORROR)  // SPWI205.SPL (Horror)
    !StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
    !CheckStatGT(LastSeenBy(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(LastSeenBy(Myself),DO_NOT_TARGET_SPELLS)
    !StateCheck(LastSeenBy(Myself),STATE_DISABLED)
    !CheckStatGT(LastSeenBy(Myself),0,HELD)
    !Kit(LastSeenBy(Myself),CAVALIER)
    !CheckStatGT(LastSeenBy(Myself),0,WIZARD_RESIST_FEAR)
    !CheckSpellState(LastSeenBy(Myself),RESIST_FEAR)
    !General(LastSeenBy(Myself),UNDEAD)
    !CheckSpellState(LastSeenBy(Myself),STATE_ENRAGED)
    !Kit(LastSeenBy(Myself),Blackguard)
    OR(2)
        !CheckSpellState(LastSeenBy(Myself),ITEM_PANIC_SEEN)
        !CheckSpellState(LastSeenBy(Myself),ITEM_PANIC)
    !CheckStatGT(LastSeenBy(Myself),0,MINORGLOBE)
    OR(2)
        !CheckStatGT(LastSeenBy(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(LastSeenBy(Myself),ENEMY)
    OR(3)
        TriggerOverride(LastSeenBy(Myself),Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(2)
        !TriggerOverride(LastSeenBy(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        !TriggerOverride(LastSeenBy(Myself),StateCheck(SecondNearestAllyOf(Myself),STATE_DISABLED))
    OR(2)
        !TriggerOverride(LastSeenBy(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        TriggerOverride(LastSeenBy(Myself),Range(SecondNearestAllyOf(Myself),15))
    CheckStatGT(LastSeenBy(Myself),0,SAVEVSSPELL)
    CheckStatLT(Player1,5,LEVEL)
    See(LastSeenBy(Myself))
THEN
    RESPONSE #100
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(LastSeenBy(Myself),WIZARD_HORROR)  // SPWI205.SPL (Horror)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    !StateCheck(NearestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(NearestEnemyOf(Myself),0,SANCTUARY)
    !StateCheck(NearestEnemyOf(Myself),STATE_DISABLED)
    !CheckStatGT(NearestEnemyOf(Myself),0,HELD)
    !Kit(NearestEnemyOf(Myself),CAVALIER)
    !CheckStatGT(NearestEnemyOf(Myself),0,WIZARD_RESIST_FEAR)
    !CheckSpellState(NearestEnemyOf(Myself),RESIST_FEAR)
    !General(NearestEnemyOf(Myself),UNDEAD)
    !CheckSpellState(NearestEnemyOf(Myself),STATE_ENRAGED)
    !Kit(NearestEnemyOf(Myself),Blackguard)
    OR(2)
        !CheckSpellState(NearestEnemyOf(Myself),ITEM_PANIC_SEEN)
        !CheckSpellState(NearestEnemyOf(Myself),ITEM_PANIC)
    !CheckStatGT(NearestEnemyOf(Myself),0,MINORGLOBE)
    OR(2)
        !CheckStatGT(NearestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(NearestEnemyOf(Myself),ENEMY)
    OR(3)
        TriggerOverride(NearestEnemyOf(Myself),Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(2)
        !TriggerOverride(NearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        !TriggerOverride(NearestEnemyOf(Myself),StateCheck(SecondNearestAllyOf(Myself),STATE_DISABLED))
    OR(2)
        !TriggerOverride(NearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        TriggerOverride(NearestEnemyOf(Myself),Range(SecondNearestAllyOf(Myself),15))
    CheckStatGT(NearestEnemyOf(Myself),0,SAVEVSSPELL)
    See(NearestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    !StateCheck(SecondNearestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,SANCTUARY)
    !StateCheck(SecondNearestEnemyOf(Myself),STATE_DISABLED)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,HELD)
    !Kit(SecondNearestEnemyOf(Myself),CAVALIER)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,WIZARD_RESIST_FEAR)
    !CheckSpellState(SecondNearestEnemyOf(Myself),RESIST_FEAR)
    !General(SecondNearestEnemyOf(Myself),UNDEAD)
    !CheckSpellState(SecondNearestEnemyOf(Myself),STATE_ENRAGED)
    !Kit(SecondNearestEnemyOf(Myself),Blackguard)
    OR(2)
        !CheckSpellState(SecondNearestEnemyOf(Myself),ITEM_PANIC_SEEN)
        !CheckSpellState(SecondNearestEnemyOf(Myself),ITEM_PANIC)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,MINORGLOBE)
    OR(2)
        !CheckStatGT(SecondNearestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondNearestEnemyOf(Myself),ENEMY)
    OR(3)
        TriggerOverride(SecondNearestEnemyOf(Myself),Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(2)
        !TriggerOverride(SecondNearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        !TriggerOverride(SecondNearestEnemyOf(Myself),StateCheck(SecondNearestAllyOf(Myself),STATE_DISABLED))
    OR(2)
        !TriggerOverride(SecondNearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        TriggerOverride(SecondNearestEnemyOf(Myself),Range(SecondNearestAllyOf(Myself),15))
    CheckStatGT(SecondNearestEnemyOf(Myself),0,SAVEVSSPELL)
    See(SecondNearestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    !StateCheck(ThirdNearestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,SANCTUARY)
    !StateCheck(ThirdNearestEnemyOf(Myself),STATE_DISABLED)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,HELD)
    !Kit(ThirdNearestEnemyOf(Myself),CAVALIER)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,WIZARD_RESIST_FEAR)
    !CheckSpellState(ThirdNearestEnemyOf(Myself),RESIST_FEAR)
    !General(ThirdNearestEnemyOf(Myself),UNDEAD)
    !CheckSpellState(ThirdNearestEnemyOf(Myself),STATE_ENRAGED)
    !Kit(ThirdNearestEnemyOf(Myself),Blackguard)
    OR(2)
        !CheckSpellState(ThirdNearestEnemyOf(Myself),ITEM_PANIC_SEEN)
        !CheckSpellState(ThirdNearestEnemyOf(Myself),ITEM_PANIC)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,MINORGLOBE)
    OR(2)
        !CheckStatGT(ThirdNearestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdNearestEnemyOf(Myself),ENEMY)
    OR(3)
        TriggerOverride(ThirdNearestEnemyOf(Myself),Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(2)
        !TriggerOverride(ThirdNearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        !TriggerOverride(ThirdNearestEnemyOf(Myself),StateCheck(SecondNearestAllyOf(Myself),STATE_DISABLED))
    OR(2)
        !TriggerOverride(ThirdNearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        TriggerOverride(ThirdNearestEnemyOf(Myself),Range(SecondNearestAllyOf(Myself),15))
    CheckStatGT(ThirdNearestEnemyOf(Myself),0,SAVEVSSPELL)
    See(ThirdNearestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    !StateCheck(FourthNearestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(FourthNearestEnemyOf(Myself),0,SANCTUARY)
    !StateCheck(FourthNearestEnemyOf(Myself),STATE_DISABLED)
    !CheckStatGT(FourthNearestEnemyOf(Myself),0,HELD)
    !Kit(FourthNearestEnemyOf(Myself),CAVALIER)
    !CheckStatGT(FourthNearestEnemyOf(Myself),0,WIZARD_RESIST_FEAR)
    !CheckSpellState(FourthNearestEnemyOf(Myself),RESIST_FEAR)
    !General(FourthNearestEnemyOf(Myself),UNDEAD)
    !CheckSpellState(FourthNearestEnemyOf(Myself),STATE_ENRAGED)
    !Kit(FourthNearestEnemyOf(Myself),Blackguard)
    OR(2)
        !CheckSpellState(FourthNearestEnemyOf(Myself),ITEM_PANIC_SEEN)
        !CheckSpellState(FourthNearestEnemyOf(Myself),ITEM_PANIC)
    !CheckStatGT(FourthNearestEnemyOf(Myself),0,MINORGLOBE)
    OR(2)
        !CheckStatGT(FourthNearestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(FourthNearestEnemyOf(Myself),ENEMY)
    OR(3)
        TriggerOverride(FourthNearestEnemyOf(Myself),Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(2)
        !TriggerOverride(FourthNearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        !TriggerOverride(FourthNearestEnemyOf(Myself),StateCheck(SecondNearestAllyOf(Myself),STATE_DISABLED))
    OR(2)
        !TriggerOverride(FourthNearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        TriggerOverride(FourthNearestEnemyOf(Myself),Range(SecondNearestAllyOf(Myself),15))
    CheckStatGT(FourthNearestEnemyOf(Myself),0,SAVEVSSPELL)
    See(FourthNearestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    !StateCheck(FifthNearestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(FifthNearestEnemyOf(Myself),0,SANCTUARY)
    !StateCheck(FifthNearestEnemyOf(Myself),STATE_DISABLED)
    !CheckStatGT(FifthNearestEnemyOf(Myself),0,HELD)
    !Kit(FifthNearestEnemyOf(Myself),CAVALIER)
    !CheckStatGT(FifthNearestEnemyOf(Myself),0,WIZARD_RESIST_FEAR)
    !CheckSpellState(FifthNearestEnemyOf(Myself),RESIST_FEAR)
    !General(FifthNearestEnemyOf(Myself),UNDEAD)
    !CheckSpellState(FifthNearestEnemyOf(Myself),STATE_ENRAGED)
    !Kit(FifthNearestEnemyOf(Myself),Blackguard)
    OR(2)
        !CheckSpellState(FifthNearestEnemyOf(Myself),ITEM_PANIC_SEEN)
        !CheckSpellState(FifthNearestEnemyOf(Myself),ITEM_PANIC)
    !CheckStatGT(FifthNearestEnemyOf(Myself),0,MINORGLOBE)
    OR(2)
        !CheckStatGT(FifthNearestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(FifthNearestEnemyOf(Myself),ENEMY)
    OR(3)
        TriggerOverride(FifthNearestEnemyOf(Myself),Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(2)
        !TriggerOverride(FifthNearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        !TriggerOverride(FifthNearestEnemyOf(Myself),StateCheck(SecondNearestAllyOf(Myself),STATE_DISABLED))
    OR(2)
        !TriggerOverride(FifthNearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        TriggerOverride(FifthNearestEnemyOf(Myself),Range(SecondNearestAllyOf(Myself),15))
    CheckStatGT(FifthNearestEnemyOf(Myself),0,SAVEVSSPELL)
    See(FifthNearestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    !StateCheck(SixthNearestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(SixthNearestEnemyOf(Myself),0,SANCTUARY)
    !StateCheck(SixthNearestEnemyOf(Myself),STATE_DISABLED)
    !CheckStatGT(SixthNearestEnemyOf(Myself),0,HELD)
    !Kit(SixthNearestEnemyOf(Myself),CAVALIER)
    !CheckStatGT(SixthNearestEnemyOf(Myself),0,WIZARD_RESIST_FEAR)
    !CheckSpellState(SixthNearestEnemyOf(Myself),RESIST_FEAR)
    !General(SixthNearestEnemyOf(Myself),UNDEAD)
    !CheckSpellState(SixthNearestEnemyOf(Myself),STATE_ENRAGED)
    !Kit(SixthNearestEnemyOf(Myself),Blackguard)
    OR(2)
        !CheckSpellState(SixthNearestEnemyOf(Myself),ITEM_PANIC_SEEN)
        !CheckSpellState(SixthNearestEnemyOf(Myself),ITEM_PANIC)
    !CheckStatGT(SixthNearestEnemyOf(Myself),0,MINORGLOBE)
    OR(2)
        !CheckStatGT(SixthNearestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(SixthNearestEnemyOf(Myself),ENEMY)
    OR(3)
        TriggerOverride(SixthNearestEnemyOf(Myself),Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(2)
        !TriggerOverride(SixthNearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        !TriggerOverride(SixthNearestEnemyOf(Myself),StateCheck(SecondNearestAllyOf(Myself),STATE_DISABLED))
    OR(2)
        !TriggerOverride(SixthNearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        TriggerOverride(SixthNearestEnemyOf(Myself),Range(SecondNearestAllyOf(Myself),15))
    CheckStatGT(SixthNearestEnemyOf(Myself),0,SAVEVSSPELL)
    See(SixthNearestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_HORROR)  // SPWI205.SPL (Horror)
    !StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
    !CheckStatGT(LastSeenBy(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(LastSeenBy(Myself),DO_NOT_TARGET_SPELLS)
    !StateCheck(LastSeenBy(Myself),STATE_DISABLED)
    !CheckStatGT(LastSeenBy(Myself),0,HELD)
    !Kit(LastSeenBy(Myself),CAVALIER)
    !CheckStatGT(LastSeenBy(Myself),0,WIZARD_RESIST_FEAR)
    !CheckSpellState(LastSeenBy(Myself),RESIST_FEAR)
    !General(LastSeenBy(Myself),UNDEAD)
    !CheckSpellState(LastSeenBy(Myself),STATE_ENRAGED)
    !Kit(LastSeenBy(Myself),Blackguard)
    OR(2)
        !CheckSpellState(LastSeenBy(Myself),ITEM_PANIC_SEEN)
        !CheckSpellState(LastSeenBy(Myself),ITEM_PANIC)
    !CheckStatGT(LastSeenBy(Myself),0,MINORGLOBE)
    OR(2)
        !CheckStatGT(LastSeenBy(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(LastSeenBy(Myself),ENEMY)
    OR(3)
        TriggerOverride(LastSeenBy(Myself),Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(2)
        !TriggerOverride(LastSeenBy(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        !TriggerOverride(LastSeenBy(Myself),StateCheck(SecondNearestAllyOf(Myself),STATE_DISABLED))
    OR(2)
        !TriggerOverride(LastSeenBy(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        TriggerOverride(LastSeenBy(Myself),Range(SecondNearestAllyOf(Myself),15))
    CheckStatGT(LastSeenBy(Myself),0,SAVEVSSPELL)
    See(LastSeenBy(Myself))
THEN
    RESPONSE #100
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(LastSeenBy(Myself),WIZARD_HORROR)  // SPWI205.SPL (Horror)
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    !StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
    HasItem("wand02",Myself)  // Wand of Fear
    !CheckStatGT(LastSeenBy(Myself),0,SANCTUARY)
    !StateCheck(LastSeenBy(Myself),STATE_DISABLED)
    !CheckStatGT(LastSeenBy(Myself),0,HELD)
    !Kit(LastSeenBy(Myself),CAVALIER)
    !CheckStatGT(LastSeenBy(Myself),0,WIZARD_RESIST_FEAR)
    !CheckSpellState(LastSeenBy(Myself),RESIST_FEAR)
    !General(LastSeenBy(Myself),UNDEAD)
    !CheckSpellState(LastSeenBy(Myself),STATE_ENRAGED)
    !Kit(LastSeenBy(Myself),Blackguard)
    OR(2)
        !CheckSpellState(LastSeenBy(Myself),ITEM_PANIC_SEEN)
        !CheckSpellState(LastSeenBy(Myself),ITEM_PANIC)
    !CheckStatGT(LastSeenBy(Myself),0,MINORGLOBE)
    OR(2)
        !CheckStatGT(LastSeenBy(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(LastSeenBy(Myself),ENEMY)
    OR(3)
        TriggerOverride(LastSeenBy(Myself),Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(2)
        !TriggerOverride(LastSeenBy(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        !TriggerOverride(LastSeenBy(Myself),StateCheck(SecondNearestAllyOf(Myself),STATE_DISABLED))
    OR(2)
        !TriggerOverride(LastSeenBy(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        TriggerOverride(LastSeenBy(Myself),Range(SecondNearestAllyOf(Myself),15))
    CheckStatGT(LastSeenBy(Myself),0,SAVEVSSPELL)
    See(LastSeenBy(Myself))
THEN
    RESPONSE #100
        SetInterrupt(FALSE)
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        DisplayStringHead(Myself,49146)  // Uses a wand
        UseItem("wand02",LastSeenBy(Myself))  // Wand of Fear
        SetInterrupt(TRUE)
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck([PC.0.0.MAGE_ALL],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.MAGE_ALL],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.MAGE_ALL])
    !CheckStatGT([PC.0.0.MAGE_ALL],99,RESISTMAGIC)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.MAGE_ALL],ENEMY)
    !CheckSpellState([PC.0.0.MAGE_ALL],WIZARD_SHIELD)
    OR(2)
        !CheckSpellState([PC.0.0.MAGE_ALL],ITEM_MM_SEEN)
        !CheckSpellState([PC.0.0.MAGE_ALL],ITEM_MM)
    StateCheck([PC.0.0.MAGE_ALL],STATE_MIRRORIMAGE)
    Allegiance(Myself,ENEMY)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",[PC.0.0.MAGE_ALL])  // No such index
        Spell([PC.0.0.MAGE_ALL],WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck([PC.0.0.CLERIC_ALL],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.CLERIC_ALL],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.CLERIC_ALL],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.CLERIC_ALL])
    !CheckStatGT([PC.0.0.CLERIC_ALL],99,RESISTMAGIC)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.CLERIC_ALL],ENEMY)
    !CheckSpellState([PC.0.0.CLERIC_ALL],WIZARD_SHIELD)
    OR(2)
        !CheckSpellState([PC.0.0.CLERIC_ALL],ITEM_MM_SEEN)
        !CheckSpellState([PC.0.0.CLERIC_ALL],ITEM_MM)
    StateCheck([PC.0.0.CLERIC_ALL],STATE_MIRRORIMAGE)
    Allegiance(Myself,ENEMY)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",[PC.0.0.CLERIC_ALL])  // No such index
        Spell([PC.0.0.CLERIC_ALL],WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck([PC.0.0.DRUID_ALL],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.DRUID_ALL],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.DRUID_ALL],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.DRUID_ALL])
    !CheckStatGT([PC.0.0.DRUID_ALL],99,RESISTMAGIC)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.DRUID_ALL],ENEMY)
    !CheckSpellState([PC.0.0.DRUID_ALL],WIZARD_SHIELD)
    OR(2)
        !CheckSpellState([PC.0.0.DRUID_ALL],ITEM_MM_SEEN)
        !CheckSpellState([PC.0.0.DRUID_ALL],ITEM_MM)
    StateCheck([PC.0.0.DRUID_ALL],STATE_MIRRORIMAGE)
    Allegiance(Myself,ENEMY)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",[PC.0.0.DRUID_ALL])  // No such index
        Spell([PC.0.0.DRUID_ALL],WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck([PC.0.0.BARD],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.BARD],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.BARD],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.BARD])
    !CheckStatGT([PC.0.0.BARD],99,RESISTMAGIC)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.BARD],ENEMY)
    !CheckSpellState([PC.0.0.BARD],WIZARD_SHIELD)
    OR(2)
        !CheckSpellState([PC.0.0.BARD],ITEM_MM_SEEN)
        !CheckSpellState([PC.0.0.BARD],ITEM_MM)
    StateCheck([PC.0.0.BARD],STATE_MIRRORIMAGE)
    Allegiance(Myself,ENEMY)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",[PC.0.0.BARD])  // No such index
        Spell([PC.0.0.BARD],WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    !StateCheck([PC.0.0.MAGE_ALL],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.MAGE_ALL],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.MAGE_ALL])
    Allegiance(Myself,ENEMY)
    !CheckStatGT([PC.0.0.MAGE_ALL],99,RESISTMAGIC)
    !StateCheck([PC.0.0.MAGE_ALL],STATE_MIRRORIMAGE)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,MINORGLOBE)
    OR(2)
        !CheckStat([PC.0.0.MAGE_ALL],1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT([PC.0.0.MAGE_ALL],0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",[PC.0.0.MAGE_ALL])
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    !CheckStatGT([PC.0.0.MAGE_ALL],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,WIZARD_SPELL_TRAP)
    !Allegiance([PC.0.0.MAGE_ALL],ENEMY)
    !CheckStatGT([PC.0.0.MAGE_ALL],50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC.0.0.MAGE_ALL],WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    RESPONSE #50
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    !StateCheck([PC.0.0.CLERIC_ALL],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.CLERIC_ALL],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.CLERIC_ALL],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.CLERIC_ALL])
    Allegiance(Myself,ENEMY)
    !CheckStatGT([PC.0.0.CLERIC_ALL],99,RESISTMAGIC)
    !StateCheck([PC.0.0.CLERIC_ALL],STATE_MIRRORIMAGE)
    !CheckStatGT([PC.0.0.CLERIC_ALL],0,MINORGLOBE)
    OR(2)
        !CheckStat([PC.0.0.CLERIC_ALL],1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT([PC.0.0.CLERIC_ALL],0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",[PC.0.0.CLERIC_ALL])
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    !CheckStatGT([PC.0.0.CLERIC_ALL],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.CLERIC_ALL],0,WIZARD_SPELL_TRAP)
    !Allegiance([PC.0.0.CLERIC_ALL],ENEMY)
    !CheckStatGT([PC.0.0.CLERIC_ALL],50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC.0.0.CLERIC_ALL],WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    RESPONSE #50
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    !StateCheck([PC.0.0.DRUID_ALL],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.DRUID_ALL],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.DRUID_ALL],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.DRUID_ALL])
    Allegiance(Myself,ENEMY)
    !CheckStatGT([PC.0.0.DRUID_ALL],99,RESISTMAGIC)
    !StateCheck([PC.0.0.DRUID_ALL],STATE_MIRRORIMAGE)
    !CheckStatGT([PC.0.0.DRUID_ALL],0,MINORGLOBE)
    OR(2)
        !CheckStat([PC.0.0.DRUID_ALL],1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT([PC.0.0.DRUID_ALL],0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",[PC.0.0.DRUID_ALL])
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    !CheckStatGT([PC.0.0.DRUID_ALL],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.DRUID_ALL],0,WIZARD_SPELL_TRAP)
    !Allegiance([PC.0.0.DRUID_ALL],ENEMY)
    !CheckStatGT([PC.0.0.DRUID_ALL],50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC.0.0.DRUID_ALL],WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    RESPONSE #50
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    !StateCheck([PC.0.0.BARD],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.BARD],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.BARD],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.BARD])
    Allegiance(Myself,ENEMY)
    !CheckStatGT([PC.0.0.BARD],99,RESISTMAGIC)
    !StateCheck([PC.0.0.BARD],STATE_MIRRORIMAGE)
    !CheckStatGT([PC.0.0.BARD],0,MINORGLOBE)
    OR(2)
        !CheckStat([PC.0.0.BARD],1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT([PC.0.0.BARD],0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",[PC.0.0.BARD])
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    !CheckStatGT([PC.0.0.BARD],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.BARD],0,WIZARD_SPELL_TRAP)
    !Allegiance([PC.0.0.BARD],ENEMY)
    !CheckStatGT([PC.0.0.BARD],50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC.0.0.BARD],WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    RESPONSE #50
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    !StateCheck([PC.0.0.MAGE_ALL],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.MAGE_ALL],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.MAGE_ALL])
    Allegiance(Myself,ENEMY)
    !CheckStatGT([PC.0.0.MAGE_ALL],99,RESISTMAGIC)
    !StateCheck([PC.0.0.MAGE_ALL],STATE_MIRRORIMAGE)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,MINORGLOBE)
    OR(2)
        !CheckStat([PC.0.0.MAGE_ALL],1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT([PC.0.0.MAGE_ALL],0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",[PC.0.0.MAGE_ALL])
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    !CheckStatGT([PC.0.0.MAGE_ALL],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,WIZARD_SPELL_TRAP)
    !Allegiance([PC.0.0.MAGE_ALL],ENEMY)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC.0.0.MAGE_ALL],WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    RESPONSE #50
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    !StateCheck([PC.0.0.CLERIC_ALL],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.CLERIC_ALL],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.CLERIC_ALL],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.CLERIC_ALL])
    Allegiance(Myself,ENEMY)
    !CheckStatGT([PC.0.0.CLERIC_ALL],99,RESISTMAGIC)
    !StateCheck([PC.0.0.CLERIC_ALL],STATE_MIRRORIMAGE)
    !CheckStatGT([PC.0.0.CLERIC_ALL],0,MINORGLOBE)
    OR(2)
        !CheckStat([PC.0.0.CLERIC_ALL],1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT([PC.0.0.CLERIC_ALL],0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",[PC.0.0.CLERIC_ALL])
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    !CheckStatGT([PC.0.0.CLERIC_ALL],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.CLERIC_ALL],0,WIZARD_SPELL_TRAP)
    !Allegiance([PC.0.0.CLERIC_ALL],ENEMY)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC.0.0.CLERIC_ALL],WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    RESPONSE #50
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    !StateCheck([PC.0.0.DRUID_ALL],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.DRUID_ALL],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.DRUID_ALL],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.DRUID_ALL])
    Allegiance(Myself,ENEMY)
    !CheckStatGT([PC.0.0.DRUID_ALL],99,RESISTMAGIC)
    !StateCheck([PC.0.0.DRUID_ALL],STATE_MIRRORIMAGE)
    !CheckStatGT([PC.0.0.DRUID_ALL],0,MINORGLOBE)
    OR(2)
        !CheckStat([PC.0.0.DRUID_ALL],1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT([PC.0.0.DRUID_ALL],0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",[PC.0.0.DRUID_ALL])
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    !CheckStatGT([PC.0.0.DRUID_ALL],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.DRUID_ALL],0,WIZARD_SPELL_TRAP)
    !Allegiance([PC.0.0.DRUID_ALL],ENEMY)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC.0.0.DRUID_ALL],WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    RESPONSE #50
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    !StateCheck([PC.0.0.BARD],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.BARD],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.BARD],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.BARD])
    Allegiance(Myself,ENEMY)
    !CheckStatGT([PC.0.0.BARD],99,RESISTMAGIC)
    !StateCheck([PC.0.0.BARD],STATE_MIRRORIMAGE)
    !CheckStatGT([PC.0.0.BARD],0,MINORGLOBE)
    OR(2)
        !CheckStat([PC.0.0.BARD],1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT([PC.0.0.BARD],0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",[PC.0.0.BARD])
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    !CheckStatGT([PC.0.0.BARD],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.BARD],0,WIZARD_SPELL_TRAP)
    !Allegiance([PC.0.0.BARD],ENEMY)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC.0.0.BARD],WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    RESPONSE #50
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck([PC.0.0.MAGE],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.MAGE],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.MAGE],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.MAGE])
    !CheckStatGT([PC.0.0.MAGE],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.MAGE],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.MAGE],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.MAGE],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.MAGE],ENEMY)
    !CheckStatGT([PC.0.0.MAGE],50,RESISTMAGIC)
    HPPercentLT([PC.0.0.MAGE],40)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC.0.0.MAGE],WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck([PC.0.0.MAGE_THIEF],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.MAGE_THIEF],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.MAGE_THIEF],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.MAGE_THIEF])
    !CheckStatGT([PC.0.0.MAGE_THIEF],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.MAGE_THIEF],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.MAGE_THIEF],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.MAGE_THIEF],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.MAGE_THIEF],ENEMY)
    !CheckStatGT([PC.0.0.MAGE_THIEF],50,RESISTMAGIC)
    HPPercentLT([PC.0.0.MAGE_THIEF],40)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC.0.0.MAGE_THIEF],WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck([PC.0.0.MAGE_ALL],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.MAGE_ALL],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.MAGE_ALL])
    !CheckStatGT([PC.0.0.MAGE_ALL],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.MAGE_ALL],ENEMY)
    !CheckStatGT([PC.0.0.MAGE_ALL],50,RESISTMAGIC)
    HPPercentLT([PC.0.0.MAGE_ALL],40)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC.0.0.MAGE_ALL],WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck([PC.0.0.THIEF],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.THIEF],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.THIEF],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.THIEF])
    !CheckStatGT([PC.0.0.THIEF],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.THIEF],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.THIEF],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.THIEF],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.THIEF],ENEMY)
    !CheckStatGT([PC.0.0.THIEF],50,RESISTMAGIC)
    HPPercentLT([PC.0.0.THIEF],40)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC.0.0.THIEF],WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck([PC.0.0.BARD],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.BARD],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.BARD],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.BARD])
    !CheckStatGT([PC.0.0.BARD],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.BARD],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.BARD],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.BARD],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.BARD],ENEMY)
    !CheckStatGT([PC.0.0.BARD],50,RESISTMAGIC)
    HPPercentLT([PC.0.0.BARD],40)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC.0.0.BARD],WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck([PC.0.0.THIEF_ALL],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.THIEF_ALL],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.THIEF_ALL],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.THIEF_ALL])
    !CheckStatGT([PC.0.0.THIEF_ALL],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.THIEF_ALL],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.THIEF_ALL],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.THIEF_ALL],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.THIEF_ALL],ENEMY)
    !CheckStatGT([PC.0.0.THIEF_ALL],50,RESISTMAGIC)
    HPPercentLT([PC.0.0.THIEF_ALL],40)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC.0.0.THIEF_ALL],WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck([PC.0.0.CLERIC],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.CLERIC],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.CLERIC],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.CLERIC])
    !CheckStatGT([PC.0.0.CLERIC],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.CLERIC],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.CLERIC],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.CLERIC],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.CLERIC],ENEMY)
    !CheckStatGT([PC.0.0.CLERIC],50,RESISTMAGIC)
    HPPercentLT([PC.0.0.CLERIC],40)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC.0.0.CLERIC],WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck([PC],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC],DO_NOT_TARGET_SPELLS)
    See([PC])
    !CheckStatGT([PC],99,RESISTMAGIC)
    !CheckStatGT([PC],0,MINORGLOBE)
    !CheckStatGT([PC],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC],ENEMY)
    !CheckStatGT([PC],50,RESISTMAGIC)
    HPPercentLT([PC],40)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC],WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck(SecondNearest([PC]),STATE_NOT_TARGETABLE)
    !CheckStatGT(SecondNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(SecondNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(SecondNearest([PC]))
    !CheckStatGT(SecondNearest([PC]),99,RESISTMAGIC)
    !CheckStatGT(SecondNearest([PC]),0,MINORGLOBE)
    !CheckStatGT(SecondNearest([PC]),0,WIZARD_SPELL_TURNING)
    !CheckStatGT(SecondNearest([PC]),0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondNearest([PC]),ENEMY)
    !CheckStatGT(SecondNearest([PC]),50,RESISTMAGIC)
    HPPercentLT(SecondNearest([PC]),40)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(SecondNearest([PC]),WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck(ThirdNearest([PC]),STATE_NOT_TARGETABLE)
    !CheckStatGT(ThirdNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(ThirdNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(ThirdNearest([PC]))
    !CheckStatGT(ThirdNearest([PC]),99,RESISTMAGIC)
    !CheckStatGT(ThirdNearest([PC]),0,MINORGLOBE)
    !CheckStatGT(ThirdNearest([PC]),0,WIZARD_SPELL_TURNING)
    !CheckStatGT(ThirdNearest([PC]),0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdNearest([PC]),ENEMY)
    !CheckStatGT(ThirdNearest([PC]),50,RESISTMAGIC)
    HPPercentLT(ThirdNearest([PC]),40)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(ThirdNearest([PC]),WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck([PC.0.0.MAGE],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.MAGE],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.MAGE],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.MAGE])
    !CheckStatGT([PC.0.0.MAGE],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.MAGE],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.MAGE],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.MAGE],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.MAGE],ENEMY)
    !CheckStatGT([PC.0.0.MAGE],50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC.0.0.MAGE],WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck([PC.0.0.MAGE_THIEF],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.MAGE_THIEF],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.MAGE_THIEF],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.MAGE_THIEF])
    !CheckStatGT([PC.0.0.MAGE_THIEF],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.MAGE_THIEF],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.MAGE_THIEF],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.MAGE_THIEF],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.MAGE_THIEF],ENEMY)
    !CheckStatGT([PC.0.0.MAGE_THIEF],50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC.0.0.MAGE_THIEF],WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck([PC.0.0.MAGE_ALL],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.MAGE_ALL],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.MAGE_ALL])
    !CheckStatGT([PC.0.0.MAGE_ALL],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.MAGE_ALL],ENEMY)
    !CheckStatGT([PC.0.0.MAGE_ALL],50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC.0.0.MAGE_ALL],WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck([PC.0.0.THIEF],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.THIEF],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.THIEF],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.THIEF])
    !CheckStatGT([PC.0.0.THIEF],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.THIEF],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.THIEF],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.THIEF],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.THIEF],ENEMY)
    !CheckStatGT([PC.0.0.THIEF],50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC.0.0.THIEF],WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck([PC.0.0.BARD],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.BARD],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.BARD],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.BARD])
    !CheckStatGT([PC.0.0.BARD],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.BARD],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.BARD],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.BARD],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.BARD],ENEMY)
    !CheckStatGT([PC.0.0.BARD],50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC.0.0.BARD],WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck([PC.0.0.THIEF_ALL],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.THIEF_ALL],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.THIEF_ALL],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.THIEF_ALL])
    !CheckStatGT([PC.0.0.THIEF_ALL],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.THIEF_ALL],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.THIEF_ALL],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.THIEF_ALL],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.THIEF_ALL],ENEMY)
    !CheckStatGT([PC.0.0.THIEF_ALL],50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC.0.0.THIEF_ALL],WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck([PC.0.0.CLERIC],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.CLERIC],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.CLERIC],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.CLERIC])
    !CheckStatGT([PC.0.0.CLERIC],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.CLERIC],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.CLERIC],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.CLERIC],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.CLERIC],ENEMY)
    !CheckStatGT([PC.0.0.CLERIC],50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC.0.0.CLERIC],WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck([PC],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC],DO_NOT_TARGET_SPELLS)
    See([PC])
    !CheckStatGT([PC],99,RESISTMAGIC)
    !CheckStatGT([PC],0,MINORGLOBE)
    !CheckStatGT([PC],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC],ENEMY)
    !CheckStatGT([PC],50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC],WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck(SecondNearest([PC]),STATE_NOT_TARGETABLE)
    !CheckStatGT(SecondNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(SecondNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(SecondNearest([PC]))
    !CheckStatGT(SecondNearest([PC]),99,RESISTMAGIC)
    !CheckStatGT(SecondNearest([PC]),0,MINORGLOBE)
    !CheckStatGT(SecondNearest([PC]),0,WIZARD_SPELL_TURNING)
    !CheckStatGT(SecondNearest([PC]),0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondNearest([PC]),ENEMY)
    !CheckStatGT(SecondNearest([PC]),50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(SecondNearest([PC]),WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck(ThirdNearest([PC]),STATE_NOT_TARGETABLE)
    !CheckStatGT(ThirdNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(ThirdNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(ThirdNearest([PC]))
    !CheckStatGT(ThirdNearest([PC]),99,RESISTMAGIC)
    !CheckStatGT(ThirdNearest([PC]),0,MINORGLOBE)
    !CheckStatGT(ThirdNearest([PC]),0,WIZARD_SPELL_TURNING)
    !CheckStatGT(ThirdNearest([PC]),0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdNearest([PC]),ENEMY)
    !CheckStatGT(ThirdNearest([PC]),50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(ThirdNearest([PC]),WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck(NearestEnemyOf(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(NearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(NearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    See(NearestEnemyOf(Myself))
    !CheckStatGT(NearestEnemyOf(Myself),99,RESISTMAGIC)
    !CheckStatGT(NearestEnemyOf(Myself),0,MINORGLOBE)
    !CheckStatGT(NearestEnemyOf(Myself),0,WIZARD_SPELL_TURNING)
    !CheckStatGT(NearestEnemyOf(Myself),0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance(NearestEnemyOf(Myself),ENEMY)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(NearestEnemyOf(Myself),WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck(SecondNearestEnemyOf(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(SecondNearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    See(SecondNearestEnemyOf(Myself))
    !CheckStatGT(SecondNearestEnemyOf(Myself),99,RESISTMAGIC)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,MINORGLOBE)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,WIZARD_SPELL_TURNING)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondNearestEnemyOf(Myself),ENEMY)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(SecondNearestEnemyOf(Myself),WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck(ThirdNearestEnemyOf(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(ThirdNearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    See(ThirdNearestEnemyOf(Myself))
    !CheckStatGT(ThirdNearestEnemyOf(Myself),99,RESISTMAGIC)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,MINORGLOBE)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,WIZARD_SPELL_TURNING)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdNearestEnemyOf(Myself),ENEMY)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(ThirdNearestEnemyOf(Myself),WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck([PC.0.0.MAGE],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.MAGE],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.MAGE],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.MAGE])
    !CheckStatGT([PC.0.0.MAGE],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.MAGE],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.MAGE],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.MAGE],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.MAGE],ENEMY)
    !CheckSpellState([PC.0.0.MAGE],WIZARD_SHIELD)
    OR(2)
        !CheckSpellState([PC.0.0.MAGE],ITEM_MM_SEEN)
        !CheckSpellState([PC.0.0.MAGE],ITEM_MM)
    !CheckStatGT([PC.0.0.MAGE],50,RESISTMAGIC)
    HPPercentLT([PC.0.0.MAGE],40)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",[PC.0.0.MAGE])  // No such index
        Spell([PC.0.0.MAGE],WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck([PC.0.0.MAGE_THIEF],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.MAGE_THIEF],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.MAGE_THIEF],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.MAGE_THIEF])
    !CheckStatGT([PC.0.0.MAGE_THIEF],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.MAGE_THIEF],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.MAGE_THIEF],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.MAGE_THIEF],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.MAGE_THIEF],ENEMY)
    !CheckSpellState([PC.0.0.MAGE_THIEF],WIZARD_SHIELD)
    OR(2)
        !CheckSpellState([PC.0.0.MAGE_THIEF],ITEM_MM_SEEN)
        !CheckSpellState([PC.0.0.MAGE_THIEF],ITEM_MM)
    !CheckStatGT([PC.0.0.MAGE_THIEF],50,RESISTMAGIC)
    HPPercentLT([PC.0.0.MAGE_THIEF],40)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",[PC.0.0.MAGE_THIEF])  // No such index
        Spell([PC.0.0.MAGE_THIEF],WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck([PC.0.0.MAGE_ALL],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.MAGE_ALL],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.MAGE_ALL])
    !CheckStatGT([PC.0.0.MAGE_ALL],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.MAGE_ALL],ENEMY)
    !CheckSpellState([PC.0.0.MAGE_ALL],WIZARD_SHIELD)
    OR(2)
        !CheckSpellState([PC.0.0.MAGE_ALL],ITEM_MM_SEEN)
        !CheckSpellState([PC.0.0.MAGE_ALL],ITEM_MM)
    !CheckStatGT([PC.0.0.MAGE_ALL],50,RESISTMAGIC)
    HPPercentLT([PC.0.0.MAGE_ALL],40)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",[PC.0.0.MAGE_ALL])  // No such index
        Spell([PC.0.0.MAGE_ALL],WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck([PC.0.0.THIEF],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.THIEF],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.THIEF],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.THIEF])
    !CheckStatGT([PC.0.0.THIEF],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.THIEF],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.THIEF],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.THIEF],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.THIEF],ENEMY)
    !CheckSpellState([PC.0.0.THIEF],WIZARD_SHIELD)
    OR(2)
        !CheckSpellState([PC.0.0.THIEF],ITEM_MM_SEEN)
        !CheckSpellState([PC.0.0.THIEF],ITEM_MM)
    !CheckStatGT([PC.0.0.THIEF],50,RESISTMAGIC)
    HPPercentLT([PC.0.0.THIEF],40)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",[PC.0.0.THIEF])  // No such index
        Spell([PC.0.0.THIEF],WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck([PC.0.0.BARD],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.BARD],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.BARD],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.BARD])
    !CheckStatGT([PC.0.0.BARD],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.BARD],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.BARD],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.BARD],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.BARD],ENEMY)
    !CheckSpellState([PC.0.0.BARD],WIZARD_SHIELD)
    OR(2)
        !CheckSpellState([PC.0.0.BARD],ITEM_MM_SEEN)
        !CheckSpellState([PC.0.0.BARD],ITEM_MM)
    !CheckStatGT([PC.0.0.BARD],50,RESISTMAGIC)
    HPPercentLT([PC.0.0.BARD],40)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",[PC.0.0.BARD])  // No such index
        Spell([PC.0.0.BARD],WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck([PC.0.0.THIEF_ALL],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.THIEF_ALL],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.THIEF_ALL],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.THIEF_ALL])
    !CheckStatGT([PC.0.0.THIEF_ALL],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.THIEF_ALL],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.THIEF_ALL],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.THIEF_ALL],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.THIEF_ALL],ENEMY)
    !CheckSpellState([PC.0.0.THIEF_ALL],WIZARD_SHIELD)
    OR(2)
        !CheckSpellState([PC.0.0.THIEF_ALL],ITEM_MM_SEEN)
        !CheckSpellState([PC.0.0.THIEF_ALL],ITEM_MM)
    !CheckStatGT([PC.0.0.THIEF_ALL],50,RESISTMAGIC)
    HPPercentLT([PC.0.0.THIEF_ALL],40)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",[PC.0.0.THIEF_ALL])  // No such index
        Spell([PC.0.0.THIEF_ALL],WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck([PC.0.0.CLERIC],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.CLERIC],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.CLERIC],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.CLERIC])
    !CheckStatGT([PC.0.0.CLERIC],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.CLERIC],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.CLERIC],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.CLERIC],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.CLERIC],ENEMY)
    !CheckSpellState([PC.0.0.CLERIC],WIZARD_SHIELD)
    OR(2)
        !CheckSpellState([PC.0.0.CLERIC],ITEM_MM_SEEN)
        !CheckSpellState([PC.0.0.CLERIC],ITEM_MM)
    !CheckStatGT([PC.0.0.CLERIC],50,RESISTMAGIC)
    HPPercentLT([PC.0.0.CLERIC],40)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",[PC.0.0.CLERIC])  // No such index
        Spell([PC.0.0.CLERIC],WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck([PC],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC],DO_NOT_TARGET_SPELLS)
    See([PC])
    !CheckStatGT([PC],99,RESISTMAGIC)
    !CheckStatGT([PC],0,MINORGLOBE)
    !CheckStatGT([PC],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC],ENEMY)
    !CheckSpellState([PC],WIZARD_SHIELD)
    OR(2)
        !CheckSpellState([PC],ITEM_MM_SEEN)
        !CheckSpellState([PC],ITEM_MM)
    !CheckStatGT([PC],50,RESISTMAGIC)
    HPPercentLT([PC],40)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",[PC])  // No such index
        Spell([PC],WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck(SecondNearest([PC]),STATE_NOT_TARGETABLE)
    !CheckStatGT(SecondNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(SecondNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(SecondNearest([PC]))
    !CheckStatGT(SecondNearest([PC]),99,RESISTMAGIC)
    !CheckStatGT(SecondNearest([PC]),0,MINORGLOBE)
    !CheckStatGT(SecondNearest([PC]),0,WIZARD_SPELL_TURNING)
    !CheckStatGT(SecondNearest([PC]),0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondNearest([PC]),ENEMY)
    !CheckSpellState(SecondNearest([PC]),WIZARD_SHIELD)
    OR(2)
        !CheckSpellState(SecondNearest([PC]),ITEM_MM_SEEN)
        !CheckSpellState(SecondNearest([PC]),ITEM_MM)
    !CheckStatGT(SecondNearest([PC]),50,RESISTMAGIC)
    HPPercentLT(SecondNearest([PC]),40)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",SecondNearest([PC]))  // No such index
        Spell(SecondNearest([PC]),WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck(ThirdNearest([PC]),STATE_NOT_TARGETABLE)
    !CheckStatGT(ThirdNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(ThirdNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(ThirdNearest([PC]))
    !CheckStatGT(ThirdNearest([PC]),99,RESISTMAGIC)
    !CheckStatGT(ThirdNearest([PC]),0,MINORGLOBE)
    !CheckStatGT(ThirdNearest([PC]),0,WIZARD_SPELL_TURNING)
    !CheckStatGT(ThirdNearest([PC]),0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdNearest([PC]),ENEMY)
    !CheckSpellState(ThirdNearest([PC]),WIZARD_SHIELD)
    OR(2)
        !CheckSpellState(ThirdNearest([PC]),ITEM_MM_SEEN)
        !CheckSpellState(ThirdNearest([PC]),ITEM_MM)
    !CheckStatGT(ThirdNearest([PC]),50,RESISTMAGIC)
    HPPercentLT(ThirdNearest([PC]),40)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",ThirdNearest([PC]))  // No such index
        Spell(ThirdNearest([PC]),WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck([PC.0.0.MAGE],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.MAGE],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.MAGE],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.MAGE])
    !CheckStatGT([PC.0.0.MAGE],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.MAGE],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.MAGE],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.MAGE],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.MAGE],ENEMY)
    !CheckSpellState([PC.0.0.MAGE],WIZARD_SHIELD)
    OR(2)
        !CheckSpellState([PC.0.0.MAGE],ITEM_MM_SEEN)
        !CheckSpellState([PC.0.0.MAGE],ITEM_MM)
    !CheckStatGT([PC.0.0.MAGE],50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",[PC.0.0.MAGE])  // No such index
        Spell([PC.0.0.MAGE],WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck([PC.0.0.MAGE_THIEF],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.MAGE_THIEF],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.MAGE_THIEF],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.MAGE_THIEF])
    !CheckStatGT([PC.0.0.MAGE_THIEF],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.MAGE_THIEF],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.MAGE_THIEF],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.MAGE_THIEF],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.MAGE_THIEF],ENEMY)
    !CheckSpellState([PC.0.0.MAGE_THIEF],WIZARD_SHIELD)
    OR(2)
        !CheckSpellState([PC.0.0.MAGE_THIEF],ITEM_MM_SEEN)
        !CheckSpellState([PC.0.0.MAGE_THIEF],ITEM_MM)
    !CheckStatGT([PC.0.0.MAGE_THIEF],50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",[PC.0.0.MAGE_THIEF])  // No such index
        Spell([PC.0.0.MAGE_THIEF],WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck([PC.0.0.MAGE_ALL],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.MAGE_ALL],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.MAGE_ALL])
    !CheckStatGT([PC.0.0.MAGE_ALL],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.MAGE_ALL],ENEMY)
    !CheckSpellState([PC.0.0.MAGE_ALL],WIZARD_SHIELD)
    OR(2)
        !CheckSpellState([PC.0.0.MAGE_ALL],ITEM_MM_SEEN)
        !CheckSpellState([PC.0.0.MAGE_ALL],ITEM_MM)
    !CheckStatGT([PC.0.0.MAGE_ALL],50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",[PC.0.0.MAGE_ALL])  // No such index
        Spell([PC.0.0.MAGE_ALL],WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck([PC.0.0.THIEF],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.THIEF],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.THIEF],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.THIEF])
    !CheckStatGT([PC.0.0.THIEF],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.THIEF],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.THIEF],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.THIEF],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.THIEF],ENEMY)
    !CheckSpellState([PC.0.0.THIEF],WIZARD_SHIELD)
    OR(2)
        !CheckSpellState([PC.0.0.THIEF],ITEM_MM_SEEN)
        !CheckSpellState([PC.0.0.THIEF],ITEM_MM)
    !CheckStatGT([PC.0.0.THIEF],50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",[PC.0.0.THIEF])  // No such index
        Spell([PC.0.0.THIEF],WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck([PC.0.0.BARD],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.BARD],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.BARD],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.BARD])
    !CheckStatGT([PC.0.0.BARD],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.BARD],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.BARD],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.BARD],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.BARD],ENEMY)
    !CheckSpellState([PC.0.0.BARD],WIZARD_SHIELD)
    OR(2)
        !CheckSpellState([PC.0.0.BARD],ITEM_MM_SEEN)
        !CheckSpellState([PC.0.0.BARD],ITEM_MM)
    !CheckStatGT([PC.0.0.BARD],50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",[PC.0.0.BARD])  // No such index
        Spell([PC.0.0.BARD],WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck([PC.0.0.THIEF_ALL],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.THIEF_ALL],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.THIEF_ALL],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.THIEF_ALL])
    !CheckStatGT([PC.0.0.THIEF_ALL],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.THIEF_ALL],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.THIEF_ALL],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.THIEF_ALL],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.THIEF_ALL],ENEMY)
    !CheckSpellState([PC.0.0.THIEF_ALL],WIZARD_SHIELD)
    OR(2)
        !CheckSpellState([PC.0.0.THIEF_ALL],ITEM_MM_SEEN)
        !CheckSpellState([PC.0.0.THIEF_ALL],ITEM_MM)
    !CheckStatGT([PC.0.0.THIEF_ALL],50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",[PC.0.0.THIEF_ALL])  // No such index
        Spell([PC.0.0.THIEF_ALL],WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck([PC.0.0.CLERIC],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.CLERIC],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.CLERIC],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.CLERIC])
    !CheckStatGT([PC.0.0.CLERIC],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.CLERIC],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.CLERIC],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.CLERIC],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.CLERIC],ENEMY)
    !CheckSpellState([PC.0.0.CLERIC],WIZARD_SHIELD)
    OR(2)
        !CheckSpellState([PC.0.0.CLERIC],ITEM_MM_SEEN)
        !CheckSpellState([PC.0.0.CLERIC],ITEM_MM)
    !CheckStatGT([PC.0.0.CLERIC],50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",[PC.0.0.CLERIC])  // No such index
        Spell([PC.0.0.CLERIC],WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck([PC],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC],DO_NOT_TARGET_SPELLS)
    See([PC])
    !CheckStatGT([PC],99,RESISTMAGIC)
    !CheckStatGT([PC],0,MINORGLOBE)
    !CheckStatGT([PC],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC],ENEMY)
    !CheckSpellState([PC],WIZARD_SHIELD)
    OR(2)
        !CheckSpellState([PC],ITEM_MM_SEEN)
        !CheckSpellState([PC],ITEM_MM)
    !CheckStatGT([PC],50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",[PC])  // No such index
        Spell([PC],WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck(SecondNearest([PC]),STATE_NOT_TARGETABLE)
    !CheckStatGT(SecondNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(SecondNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(SecondNearest([PC]))
    !CheckStatGT(SecondNearest([PC]),99,RESISTMAGIC)
    !CheckStatGT(SecondNearest([PC]),0,MINORGLOBE)
    !CheckStatGT(SecondNearest([PC]),0,WIZARD_SPELL_TURNING)
    !CheckStatGT(SecondNearest([PC]),0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondNearest([PC]),ENEMY)
    !CheckSpellState(SecondNearest([PC]),WIZARD_SHIELD)
    OR(2)
        !CheckSpellState(SecondNearest([PC]),ITEM_MM_SEEN)
        !CheckSpellState(SecondNearest([PC]),ITEM_MM)
    !CheckStatGT(SecondNearest([PC]),50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",SecondNearest([PC]))  // No such index
        Spell(SecondNearest([PC]),WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck(ThirdNearest([PC]),STATE_NOT_TARGETABLE)
    !CheckStatGT(ThirdNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(ThirdNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(ThirdNearest([PC]))
    !CheckStatGT(ThirdNearest([PC]),99,RESISTMAGIC)
    !CheckStatGT(ThirdNearest([PC]),0,MINORGLOBE)
    !CheckStatGT(ThirdNearest([PC]),0,WIZARD_SPELL_TURNING)
    !CheckStatGT(ThirdNearest([PC]),0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdNearest([PC]),ENEMY)
    !CheckSpellState(ThirdNearest([PC]),WIZARD_SHIELD)
    OR(2)
        !CheckSpellState(ThirdNearest([PC]),ITEM_MM_SEEN)
        !CheckSpellState(ThirdNearest([PC]),ITEM_MM)
    !CheckStatGT(ThirdNearest([PC]),50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",ThirdNearest([PC]))  // No such index
        Spell(ThirdNearest([PC]),WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck(NearestEnemyOf(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(NearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(NearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    See(NearestEnemyOf(Myself))
    !CheckStatGT(NearestEnemyOf(Myself),99,RESISTMAGIC)
    !CheckStatGT(NearestEnemyOf(Myself),0,MINORGLOBE)
    !CheckStatGT(NearestEnemyOf(Myself),0,WIZARD_SPELL_TURNING)
    !CheckStatGT(NearestEnemyOf(Myself),0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance(NearestEnemyOf(Myself),ENEMY)
    !CheckSpellState(NearestEnemyOf(Myself),WIZARD_SHIELD)
    OR(2)
        !CheckSpellState(NearestEnemyOf(Myself),ITEM_MM_SEEN)
        !CheckSpellState(NearestEnemyOf(Myself),ITEM_MM)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",NearestEnemyOf(Myself))  // No such index
        Spell(NearestEnemyOf(Myself),WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck(SecondNearestEnemyOf(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(SecondNearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    See(SecondNearestEnemyOf(Myself))
    !CheckStatGT(SecondNearestEnemyOf(Myself),99,RESISTMAGIC)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,MINORGLOBE)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,WIZARD_SPELL_TURNING)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondNearestEnemyOf(Myself),ENEMY)
    !CheckSpellState(SecondNearestEnemyOf(Myself),WIZARD_SHIELD)
    OR(2)
        !CheckSpellState(SecondNearestEnemyOf(Myself),ITEM_MM_SEEN)
        !CheckSpellState(SecondNearestEnemyOf(Myself),ITEM_MM)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",SecondNearestEnemyOf(Myself))  // No such index
        Spell(SecondNearestEnemyOf(Myself),WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck(ThirdNearestEnemyOf(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(ThirdNearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    See(ThirdNearestEnemyOf(Myself))
    !CheckStatGT(ThirdNearestEnemyOf(Myself),99,RESISTMAGIC)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,MINORGLOBE)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,WIZARD_SPELL_TURNING)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdNearestEnemyOf(Myself),ENEMY)
    !CheckSpellState(ThirdNearestEnemyOf(Myself),WIZARD_SHIELD)
    OR(2)
        !CheckSpellState(ThirdNearestEnemyOf(Myself),ITEM_MM_SEEN)
        !CheckSpellState(ThirdNearestEnemyOf(Myself),ITEM_MM)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",ThirdNearestEnemyOf(Myself))  // No such index
        Spell(ThirdNearestEnemyOf(Myself),WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    !StateCheck(NearestEnemyOf(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(NearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(NearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    See(NearestEnemyOf(Myself))
    Allegiance(Myself,ENEMY)
    !Allegiance(NearestEnemyOf(Myself),ENEMY)
    !CheckStatGT(NearestEnemyOf(Myself),99,RESISTMAGIC)
    !StateCheck(NearestEnemyOf(Myself),STATE_MIRRORIMAGE)
    !CheckStatGT(NearestEnemyOf(Myself),0,MINORGLOBE)
    OR(2)
        !CheckStat(NearestEnemyOf(Myself),1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT(NearestEnemyOf(Myself),0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",NearestEnemyOf(Myself))
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    !CheckStatGT(NearestEnemyOf(Myself),0,WIZARD_SPELL_TURNING)
    !CheckStatGT(NearestEnemyOf(Myself),0,WIZARD_SPELL_TRAP)
    !CheckStatGT(NearestEnemyOf(Myself),50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(NearestEnemyOf(Myself),WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    !StateCheck(SecondNearestEnemyOf(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(SecondNearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    See(SecondNearestEnemyOf(Myself))
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondNearestEnemyOf(Myself),ENEMY)
    !CheckStatGT(SecondNearestEnemyOf(Myself),99,RESISTMAGIC)
    !StateCheck(SecondNearestEnemyOf(Myself),STATE_MIRRORIMAGE)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,MINORGLOBE)
    OR(2)
        !CheckStat(SecondNearestEnemyOf(Myself),1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT(SecondNearestEnemyOf(Myself),0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",SecondNearestEnemyOf(Myself))
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,WIZARD_SPELL_TURNING)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,WIZARD_SPELL_TRAP)
    !CheckStatGT(SecondNearestEnemyOf(Myself),50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(SecondNearestEnemyOf(Myself),WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    !StateCheck(ThirdNearestEnemyOf(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(ThirdNearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    See(ThirdNearestEnemyOf(Myself))
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdNearestEnemyOf(Myself),ENEMY)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),99,RESISTMAGIC)
    !StateCheck(ThirdNearestEnemyOf(Myself),STATE_MIRRORIMAGE)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,MINORGLOBE)
    OR(2)
        !CheckStat(ThirdNearestEnemyOf(Myself),1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT(ThirdNearestEnemyOf(Myself),0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",ThirdNearestEnemyOf(Myself))
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,WIZARD_SPELL_TURNING)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,WIZARD_SPELL_TRAP)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(ThirdNearestEnemyOf(Myself),WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    !StateCheck(NearestEnemyOf(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(NearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(NearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    See(NearestEnemyOf(Myself))
    Allegiance(Myself,ENEMY)
    !Allegiance(NearestEnemyOf(Myself),ENEMY)
    !CheckStatGT(NearestEnemyOf(Myself),99,RESISTMAGIC)
    !StateCheck(NearestEnemyOf(Myself),STATE_MIRRORIMAGE)
    !CheckStatGT(NearestEnemyOf(Myself),0,MINORGLOBE)
    OR(2)
        !CheckStat(NearestEnemyOf(Myself),1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT(NearestEnemyOf(Myself),0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",NearestEnemyOf(Myself))
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    !CheckStatGT(NearestEnemyOf(Myself),0,WIZARD_SPELL_TURNING)
    !CheckStatGT(NearestEnemyOf(Myself),0,WIZARD_SPELL_TRAP)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(NearestEnemyOf(Myself),WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    !StateCheck(SecondNearestEnemyOf(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(SecondNearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    See(SecondNearestEnemyOf(Myself))
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondNearestEnemyOf(Myself),ENEMY)
    !CheckStatGT(SecondNearestEnemyOf(Myself),99,RESISTMAGIC)
    !StateCheck(SecondNearestEnemyOf(Myself),STATE_MIRRORIMAGE)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,MINORGLOBE)
    OR(2)
        !CheckStat(SecondNearestEnemyOf(Myself),1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT(SecondNearestEnemyOf(Myself),0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",SecondNearestEnemyOf(Myself))
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,WIZARD_SPELL_TURNING)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,WIZARD_SPELL_TRAP)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(SecondNearestEnemyOf(Myself),WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    !StateCheck(ThirdNearestEnemyOf(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(ThirdNearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    See(ThirdNearestEnemyOf(Myself))
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdNearestEnemyOf(Myself),ENEMY)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),99,RESISTMAGIC)
    !StateCheck(ThirdNearestEnemyOf(Myself),STATE_MIRRORIMAGE)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,MINORGLOBE)
    OR(2)
        !CheckStat(ThirdNearestEnemyOf(Myself),1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT(ThirdNearestEnemyOf(Myself),0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",ThirdNearestEnemyOf(Myself))
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,WIZARD_SPELL_TURNING)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,WIZARD_SPELL_TRAP)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(ThirdNearestEnemyOf(Myself),WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_SUN_FIRE)  // SPWI523.SPL (Sunfire)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    Allegiance(Myself,ENEMY)
    !Allegiance(SixthNearestEnemyOf(Myself),ENEMY)
    OR(2)
        !CheckStatGT(SixthNearestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    !CheckStatGT(SixthNearestEnemyOf(Myself),50,RESISTFIRE)
    !CheckStat(SixthNearestEnemyOf(Myself),6,WIZARD_SPELL_IMMUNITY)
    Range(SixthNearestEnemyOf(Myself),10)
    OR(2)
        Range(SecondNearestEnemyOfType([0.HUMANOID]),10)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(4)
        !Range(NearestAllyOf(Myself),10)
        CheckStatGT(NearestAllyOf(Myself),59,RESISTFIRE)
        Race(NearestAllyOf(Myself),LICH)
        Race(NearestAllyOf(Myself),RAKSHASA)
    See(SixthNearestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_SUN_FIRE)  // SPWI523.SPL (Sunfire)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    Allegiance(Myself,ENEMY)
    !Allegiance(FifthNearestEnemyOf(Myself),ENEMY)
    OR(2)
        !CheckStatGT(FifthNearestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    !CheckStatGT(FifthNearestEnemyOf(Myself),50,RESISTFIRE)
    !CheckStat(FifthNearestEnemyOf(Myself),6,WIZARD_SPELL_IMMUNITY)
    Range(FifthNearestEnemyOf(Myself),10)
    OR(2)
        Range(SecondNearestEnemyOfType([0.HUMANOID]),10)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(4)
        !Range(NearestAllyOf(Myself),10)
        CheckStatGT(NearestAllyOf(Myself),59,RESISTFIRE)
        Race(NearestAllyOf(Myself),LICH)
        Race(NearestAllyOf(Myself),RAKSHASA)
    See(FifthNearestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_SUN_FIRE)  // SPWI523.SPL (Sunfire)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    Allegiance(Myself,ENEMY)
    !Allegiance(FourthNearestEnemyOf(Myself),ENEMY)
    OR(2)
        !CheckStatGT(FourthNearestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    !CheckStatGT(FourthNearestEnemyOf(Myself),50,RESISTFIRE)
    !CheckStat(FourthNearestEnemyOf(Myself),6,WIZARD_SPELL_IMMUNITY)
    Range(FourthNearestEnemyOf(Myself),10)
    OR(2)
        Range(SecondNearestEnemyOfType([0.HUMANOID]),10)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(4)
        !Range(NearestAllyOf(Myself),10)
        CheckStatGT(NearestAllyOf(Myself),59,RESISTFIRE)
        Race(NearestAllyOf(Myself),LICH)
        Race(NearestAllyOf(Myself),RAKSHASA)
    See(FourthNearestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_SUN_FIRE)  // SPWI523.SPL (Sunfire)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdNearestEnemyOf(Myself),ENEMY)
    OR(2)
        !CheckStatGT(ThirdNearestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    !CheckStatGT(ThirdNearestEnemyOf(Myself),50,RESISTFIRE)
    !CheckStat(ThirdNearestEnemyOf(Myself),6,WIZARD_SPELL_IMMUNITY)
    Range(ThirdNearestEnemyOf(Myself),10)
    OR(2)
        Range(SecondNearestEnemyOfType([0.HUMANOID]),10)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(4)
        !Range(NearestAllyOf(Myself),10)
        CheckStatGT(NearestAllyOf(Myself),59,RESISTFIRE)
        Race(NearestAllyOf(Myself),LICH)
        Race(NearestAllyOf(Myself),RAKSHASA)
    See(ThirdNearestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_SUN_FIRE)  // SPWI523.SPL (Sunfire)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondNearestEnemyOf(Myself),ENEMY)
    OR(2)
        !CheckStatGT(SecondNearestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    !CheckStatGT(SecondNearestEnemyOf(Myself),50,RESISTFIRE)
    !CheckStat(SecondNearestEnemyOf(Myself),6,WIZARD_SPELL_IMMUNITY)
    Range(SecondNearestEnemyOf(Myself),10)
    OR(2)
        Range(SecondNearestEnemyOfType([0.HUMANOID]),10)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(4)
        !Range(NearestAllyOf(Myself),10)
        CheckStatGT(NearestAllyOf(Myself),59,RESISTFIRE)
        Race(NearestAllyOf(Myself),LICH)
        Race(NearestAllyOf(Myself),RAKSHASA)
    See(SecondNearestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_SUN_FIRE)  // SPWI523.SPL (Sunfire)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    Allegiance(Myself,ENEMY)
    !Allegiance(NearestEnemyOf(Myself),ENEMY)
    OR(2)
        !CheckStatGT(NearestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    !CheckStatGT(NearestEnemyOf(Myself),50,RESISTFIRE)
    !CheckStat(NearestEnemyOf(Myself),6,WIZARD_SPELL_IMMUNITY)
    Range(NearestEnemyOf(Myself),10)
    OR(2)
        Range(SecondNearestEnemyOfType([0.HUMANOID]),10)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(4)
        !Range(NearestAllyOf(Myself),10)
        CheckStatGT(NearestAllyOf(Myself),59,RESISTFIRE)
        Race(NearestAllyOf(Myself),LICH)
        Race(NearestAllyOf(Myself),RAKSHASA)
    See(NearestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_SUN_FIRE)  // SPWI523.SPL (Sunfire)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    Allegiance(Myself,ENEMY)
    !Allegiance(LastSeenBy(Myself),ENEMY)
    OR(2)
        !CheckStatGT(LastSeenBy(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    !CheckStatGT(LastSeenBy(Myself),50,RESISTFIRE)
    !CheckStat(LastSeenBy(Myself),6,WIZARD_SPELL_IMMUNITY)
    Range(LastSeenBy(Myself),10)
    OR(2)
        Range(SecondNearestEnemyOfType([0.HUMANOID]),10)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(4)
        !Range(NearestAllyOf(Myself),10)
        CheckStatGT(NearestAllyOf(Myself),59,RESISTFIRE)
        Race(NearestAllyOf(Myself),LICH)
        Race(NearestAllyOf(Myself),RAKSHASA)
    See(LastSeenBy(Myself))
THEN
    RESPONSE #150
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(Myself,WIZARD_SUN_FIRE)  // SPWI523.SPL (Sunfire)
    RESPONSE #50
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CONE_OF_COLD)  // SPWI503.SPL (Cone of Cold)
    !StateCheck([PC],STATE_INVISIBLE)
    !CheckStatGT([PC],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC],DO_NOT_TARGET_SPELLS)
    See([PC])
    OR(2)
        !CheckStatGT([PC],50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance([PC],ENEMY)
    !CheckStat([PC],6,WIZARD_SPELL_IMMUNITY)
    Range([PC],10)
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC],WIZARD_CONE_OF_COLD)  // SPWI503.SPL (Cone of Cold)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CONE_OF_COLD)  // SPWI503.SPL (Cone of Cold)
    !StateCheck(SecondNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(SecondNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(SecondNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(SecondNearest([PC]))
    OR(2)
        !CheckStatGT(SecondNearest([PC]),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondNearest([PC]),ENEMY)
    !CheckStat(SecondNearest([PC]),6,WIZARD_SPELL_IMMUNITY)
    Range(SecondNearest([PC]),10)
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(SecondNearest([PC]),WIZARD_CONE_OF_COLD)  // SPWI503.SPL (Cone of Cold)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CONE_OF_COLD)  // SPWI503.SPL (Cone of Cold)
    !StateCheck(ThirdNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(ThirdNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(ThirdNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(ThirdNearest([PC]))
    OR(2)
        !CheckStatGT(ThirdNearest([PC]),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdNearest([PC]),ENEMY)
    !CheckStat(ThirdNearest([PC]),6,WIZARD_SPELL_IMMUNITY)
    Range(ThirdNearest([PC]),10)
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(ThirdNearest([PC]),WIZARD_CONE_OF_COLD)  // SPWI503.SPL (Cone of Cold)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CONE_OF_COLD)  // SPWI503.SPL (Cone of Cold)
    !StateCheck(FourthNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(FourthNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(FourthNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(FourthNearest([PC]))
    OR(2)
        !CheckStatGT(FourthNearest([PC]),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(FourthNearest([PC]),ENEMY)
    !CheckStat(FourthNearest([PC]),6,WIZARD_SPELL_IMMUNITY)
    Range(FourthNearest([PC]),10)
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(FourthNearest([PC]),WIZARD_CONE_OF_COLD)  // SPWI503.SPL (Cone of Cold)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CONE_OF_COLD)  // SPWI503.SPL (Cone of Cold)
    !StateCheck(FifthNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(FifthNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(FifthNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(FifthNearest([PC]))
    OR(2)
        !CheckStatGT(FifthNearest([PC]),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(FifthNearest([PC]),ENEMY)
    !CheckStat(FifthNearest([PC]),6,WIZARD_SPELL_IMMUNITY)
    Range(FifthNearest([PC]),10)
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(FifthNearest([PC]),WIZARD_CONE_OF_COLD)  // SPWI503.SPL (Cone of Cold)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CONE_OF_COLD)  // SPWI503.SPL (Cone of Cold)
    !StateCheck(SixthNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(SixthNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(SixthNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(SixthNearest([PC]))
    OR(2)
        !CheckStatGT(SixthNearest([PC]),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(SixthNearest([PC]),ENEMY)
    !CheckStat(SixthNearest([PC]),6,WIZARD_SPELL_IMMUNITY)
    Range(SixthNearest([PC]),10)
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(SixthNearest([PC]),WIZARD_CONE_OF_COLD)  // SPWI503.SPL (Cone of Cold)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CONE_OF_COLD)  // SPWI503.SPL (Cone of Cold)
    !StateCheck(NearestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(NearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(NearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    See(NearestEnemyOf(Myself))
    OR(2)
        !CheckStatGT(NearestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(NearestEnemyOf(Myself),ENEMY)
    !CheckStat(NearestEnemyOf(Myself),6,WIZARD_SPELL_IMMUNITY)
    Range(NearestEnemyOf(Myself),10)
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(NearestEnemyOf(Myself),WIZARD_CONE_OF_COLD)  // SPWI503.SPL (Cone of Cold)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CONE_OF_COLD)  // SPWI503.SPL (Cone of Cold)
    !StateCheck(SecondNearestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(SecondNearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    See(SecondNearestEnemyOf(Myself))
    OR(2)
        !CheckStatGT(SecondNearestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondNearestEnemyOf(Myself),ENEMY)
    !CheckStat(SecondNearestEnemyOf(Myself),6,WIZARD_SPELL_IMMUNITY)
    Range(SecondNearestEnemyOf(Myself),10)
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(SecondNearestEnemyOf(Myself),WIZARD_CONE_OF_COLD)  // SPWI503.SPL (Cone of Cold)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CONE_OF_COLD)  // SPWI503.SPL (Cone of Cold)
    !StateCheck(ThirdNearestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(ThirdNearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    See(ThirdNearestEnemyOf(Myself))
    OR(2)
        !CheckStatGT(ThirdNearestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdNearestEnemyOf(Myself),ENEMY)
    !CheckStat(ThirdNearestEnemyOf(Myself),6,WIZARD_SPELL_IMMUNITY)
    Range(ThirdNearestEnemyOf(Myself),10)
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(ThirdNearestEnemyOf(Myself),WIZARD_CONE_OF_COLD)  // SPWI503.SPL (Cone of Cold)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_LIGHTNING_BOLT)  // SPWI308.SPL (Lightning Bolt)
    !StateCheck(SixthNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(SixthNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(SixthNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(SixthNearest([PC]))
    CheckStat(Myself,1,MINORGLOBE)
    OR(2)
        !CheckStatGT(SixthNearest([PC]),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(SixthNearest([PC]),ENEMY)
    !CheckStat(SixthNearest([PC]),6,WIZARD_SPELL_IMMUNITY)
    !CheckStatGT(SixthNearest([PC]),0,MINORGLOBE)
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(SixthNearest([PC]),WIZARD_LIGHTNING_BOLT)  // SPWI308.SPL (Lightning Bolt)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_LIGHTNING_BOLT)  // SPWI308.SPL (Lightning Bolt)
    !StateCheck(FifthNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(FifthNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(FifthNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(FifthNearest([PC]))
    CheckStat(Myself,1,MINORGLOBE)
    OR(2)
        !CheckStatGT(FifthNearest([PC]),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(FifthNearest([PC]),ENEMY)
    !CheckStat(FifthNearest([PC]),6,WIZARD_SPELL_IMMUNITY)
    !CheckStatGT(FifthNearest([PC]),0,MINORGLOBE)
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(FifthNearest([PC]),WIZARD_LIGHTNING_BOLT)  // SPWI308.SPL (Lightning Bolt)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_LIGHTNING_BOLT)  // SPWI308.SPL (Lightning Bolt)
    !StateCheck(FourthNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(FourthNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(FourthNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(FourthNearest([PC]))
    CheckStat(Myself,1,MINORGLOBE)
    OR(2)
        !CheckStatGT(FourthNearest([PC]),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(FourthNearest([PC]),ENEMY)
    !CheckStat(FourthNearest([PC]),6,WIZARD_SPELL_IMMUNITY)
    !CheckStatGT(FourthNearest([PC]),0,MINORGLOBE)
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(FourthNearest([PC]),WIZARD_LIGHTNING_BOLT)  // SPWI308.SPL (Lightning Bolt)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_LIGHTNING_BOLT)  // SPWI308.SPL (Lightning Bolt)
    !StateCheck(ThirdNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(ThirdNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(ThirdNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(ThirdNearest([PC]))
    CheckStat(Myself,1,MINORGLOBE)
    OR(2)
        !CheckStatGT(ThirdNearest([PC]),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdNearest([PC]),ENEMY)
    !CheckStat(ThirdNearest([PC]),6,WIZARD_SPELL_IMMUNITY)
    !CheckStatGT(ThirdNearest([PC]),0,MINORGLOBE)
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(ThirdNearest([PC]),WIZARD_LIGHTNING_BOLT)  // SPWI308.SPL (Lightning Bolt)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_LIGHTNING_BOLT)  // SPWI308.SPL (Lightning Bolt)
    !StateCheck(SecondNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(SecondNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(SecondNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(SecondNearest([PC]))
    CheckStat(Myself,1,MINORGLOBE)
    OR(2)
        !CheckStatGT(SecondNearest([PC]),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondNearest([PC]),ENEMY)
    !CheckStat(SecondNearest([PC]),6,WIZARD_SPELL_IMMUNITY)
    !CheckStatGT(SecondNearest([PC]),0,MINORGLOBE)
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(SecondNearest([PC]),WIZARD_LIGHTNING_BOLT)  // SPWI308.SPL (Lightning Bolt)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_LIGHTNING_BOLT)  // SPWI308.SPL (Lightning Bolt)
    !StateCheck([PC],STATE_INVISIBLE)
    !CheckStatGT([PC],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC],DO_NOT_TARGET_SPELLS)
    See([PC])
    CheckStat(Myself,1,MINORGLOBE)
    OR(2)
        !CheckStatGT([PC],50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance([PC],ENEMY)
    !CheckStat([PC],6,WIZARD_SPELL_IMMUNITY)
    !CheckStatGT([PC],0,MINORGLOBE)
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC],WIZARD_LIGHTNING_BOLT)  // SPWI308.SPL (Lightning Bolt)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_LIGHTNING_BOLT)  // SPWI308.SPL (Lightning Bolt)
    !StateCheck(FarthestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(FarthestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(FarthestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    See(FarthestEnemyOf(Myself))
    CheckStat(Myself,1,MINORGLOBE)
    OR(2)
        !CheckStatGT(FarthestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(FarthestEnemyOf(Myself),ENEMY)
    !CheckStat(FarthestEnemyOf(Myself),6,WIZARD_SPELL_IMMUNITY)
    !CheckStatGT(FarthestEnemyOf(Myself),0,MINORGLOBE)
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(FarthestEnemyOf(Myself),WIZARD_LIGHTNING_BOLT)  // SPWI308.SPL (Lightning Bolt)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_LIGHTNING_BOLT)  // SPWI308.SPL (Lightning Bolt)
    !StateCheck(SecondFarthestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(SecondFarthestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(SecondFarthestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    See(SecondFarthestEnemyOf(Myself))
    CheckStat(Myself,1,MINORGLOBE)
    OR(2)
        !CheckStatGT(SecondFarthestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondFarthestEnemyOf(Myself),ENEMY)
    !CheckStat(SecondFarthestEnemyOf(Myself),6,WIZARD_SPELL_IMMUNITY)
    !CheckStatGT(SecondFarthestEnemyOf(Myself),0,MINORGLOBE)
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(SecondFarthestEnemyOf(Myself),WIZARD_LIGHTNING_BOLT)  // SPWI308.SPL (Lightning Bolt)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_LIGHTNING_BOLT)  // SPWI308.SPL (Lightning Bolt)
    !StateCheck(ThirdFarthestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(ThirdFarthestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(ThirdFarthestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    See(ThirdFarthestEnemyOf(Myself))
    CheckStat(Myself,1,MINORGLOBE)
    OR(2)
        !CheckStatGT(ThirdFarthestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdFarthestEnemyOf(Myself),ENEMY)
    !CheckStat(ThirdFarthestEnemyOf(Myself),6,WIZARD_SPELL_IMMUNITY)
    !CheckStatGT(ThirdFarthestEnemyOf(Myself),0,MINORGLOBE)
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(ThirdFarthestEnemyOf(Myself),WIZARD_LIGHTNING_BOLT)  // SPWI308.SPL (Lightning Bolt)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_FIREBALL)  // SPWI304.SPL (Fireball)
    !StateCheck(SixthNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(SixthNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(SixthNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(SixthNearest([PC]))
    OR(2)
        !CheckStatGT(SixthNearest([PC]),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(SixthNearest([PC]),ENEMY)
    !CheckStatGT(SixthNearest([PC]),0,MINORGLOBE)
    !CheckStat(SixthNearest([PC]),6,WIZARD_SPELL_IMMUNITY)
    OR(3)
        TriggerOverride(SixthNearest([PC]),Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(6)
        !TriggerOverride(SixthNearest([PC]),Range(NearestEnemyOfType([0.HUMANOID]),22))
        TriggerOverride(SixthNearest([PC]),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),59,RESISTFIRE))
        TriggerOverride(SixthNearest([PC]),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),59,RESISTMAGIC))
        TriggerOverride(SixthNearest([PC]),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),0,MINORGLOBE))
        TriggerOverride(SixthNearest([PC]),Race(NearestEnemyOfType([0.HUMANOID]),RAKSHASA))
        TriggerOverride(SixthNearest([PC]),Race(NearestEnemyOfType([0.HUMANOID]),LICH))
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(SixthNearest([PC]),WIZARD_FIREBALL)  // SPWI304.SPL (Fireball)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_FIREBALL)  // SPWI304.SPL (Fireball)
    !StateCheck(FifthNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(FifthNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(FifthNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(FifthNearest([PC]))
    OR(2)
        !CheckStatGT(FifthNearest([PC]),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(FifthNearest([PC]),ENEMY)
    !CheckStatGT(FifthNearest([PC]),0,MINORGLOBE)
    !CheckStat(FifthNearest([PC]),6,WIZARD_SPELL_IMMUNITY)
    OR(3)
        TriggerOverride(FifthNearest([PC]),Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(6)
        !TriggerOverride(FifthNearest([PC]),Range(NearestEnemyOfType([0.HUMANOID]),22))
        TriggerOverride(FifthNearest([PC]),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),59,RESISTFIRE))
        TriggerOverride(FifthNearest([PC]),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),59,RESISTMAGIC))
        TriggerOverride(FifthNearest([PC]),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),0,MINORGLOBE))
        TriggerOverride(FifthNearest([PC]),Race(NearestEnemyOfType([0.HUMANOID]),RAKSHASA))
        TriggerOverride(FifthNearest([PC]),Race(NearestEnemyOfType([0.HUMANOID]),LICH))
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(FifthNearest([PC]),WIZARD_FIREBALL)  // SPWI304.SPL (Fireball)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_FIREBALL)  // SPWI304.SPL (Fireball)
    !StateCheck(FourthNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(FourthNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(FourthNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(FourthNearest([PC]))
    OR(2)
        !CheckStatGT(FourthNearest([PC]),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(FourthNearest([PC]),ENEMY)
    !CheckStatGT(FourthNearest([PC]),0,MINORGLOBE)
    !CheckStat(FourthNearest([PC]),6,WIZARD_SPELL_IMMUNITY)
    OR(3)
        TriggerOverride(FourthNearest([PC]),Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(6)
        !TriggerOverride(FourthNearest([PC]),Range(NearestEnemyOfType([0.HUMANOID]),22))
        TriggerOverride(FourthNearest([PC]),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),59,RESISTFIRE))
        TriggerOverride(FourthNearest([PC]),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),59,RESISTMAGIC))
        TriggerOverride(FourthNearest([PC]),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),0,MINORGLOBE))
        TriggerOverride(FourthNearest([PC]),Race(NearestEnemyOfType([0.HUMANOID]),RAKSHASA))
        TriggerOverride(FourthNearest([PC]),Race(NearestEnemyOfType([0.HUMANOID]),LICH))
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(FourthNearest([PC]),WIZARD_FIREBALL)  // SPWI304.SPL (Fireball)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_FIREBALL)  // SPWI304.SPL (Fireball)
    !StateCheck(ThirdNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(ThirdNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(ThirdNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(ThirdNearest([PC]))
    OR(2)
        !CheckStatGT(ThirdNearest([PC]),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdNearest([PC]),ENEMY)
    !CheckStatGT(ThirdNearest([PC]),0,MINORGLOBE)
    !CheckStat(ThirdNearest([PC]),6,WIZARD_SPELL_IMMUNITY)
    OR(3)
        TriggerOverride(ThirdNearest([PC]),Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(6)
        !TriggerOverride(ThirdNearest([PC]),Range(NearestEnemyOfType([0.HUMANOID]),22))
        TriggerOverride(ThirdNearest([PC]),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),59,RESISTFIRE))
        TriggerOverride(ThirdNearest([PC]),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),59,RESISTMAGIC))
        TriggerOverride(ThirdNearest([PC]),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),0,MINORGLOBE))
        TriggerOverride(ThirdNearest([PC]),Race(NearestEnemyOfType([0.HUMANOID]),RAKSHASA))
        TriggerOverride(ThirdNearest([PC]),Race(NearestEnemyOfType([0.HUMANOID]),LICH))
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(ThirdNearest([PC]),WIZARD_FIREBALL)  // SPWI304.SPL (Fireball)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_FIREBALL)  // SPWI304.SPL (Fireball)
    !StateCheck(SecondNearest([PC]),STATE_INVISIBLE)
    !CheckStatGT(SecondNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(SecondNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(SecondNearest([PC]))
    OR(2)
        !CheckStatGT(SecondNearest([PC]),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondNearest([PC]),ENEMY)
    !CheckStatGT(SecondNearest([PC]),0,MINORGLOBE)
    !CheckStat(SecondNearest([PC]),6,WIZARD_SPELL_IMMUNITY)
    OR(3)
        TriggerOverride(SecondNearest([PC]),Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(6)
        !TriggerOverride(SecondNearest([PC]),Range(NearestEnemyOfType([0.HUMANOID]),22))
        TriggerOverride(SecondNearest([PC]),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),59,RESISTFIRE))
        TriggerOverride(SecondNearest([PC]),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),59,RESISTMAGIC))
        TriggerOverride(SecondNearest([PC]),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),0,MINORGLOBE))
        TriggerOverride(SecondNearest([PC]),Race(NearestEnemyOfType([0.HUMANOID]),RAKSHASA))
        TriggerOverride(SecondNearest([PC]),Race(NearestEnemyOfType([0.HUMANOID]),LICH))
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(SecondNearest([PC]),WIZARD_FIREBALL)  // SPWI304.SPL (Fireball)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_FIREBALL)  // SPWI304.SPL (Fireball)
    !StateCheck([PC],STATE_INVISIBLE)
    !CheckStatGT([PC],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC],DO_NOT_TARGET_SPELLS)
    See([PC])
    OR(2)
        !CheckStatGT([PC],50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance([PC],ENEMY)
    !CheckStatGT([PC],0,MINORGLOBE)
    !CheckStat([PC],6,WIZARD_SPELL_IMMUNITY)
    OR(3)
        TriggerOverride([PC],Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(6)
        !TriggerOverride([PC],Range(NearestEnemyOfType([0.HUMANOID]),22))
        TriggerOverride([PC],CheckStatGT(NearestEnemyOfType([0.HUMANOID]),59,RESISTFIRE))
        TriggerOverride([PC],CheckStatGT(NearestEnemyOfType([0.HUMANOID]),59,RESISTMAGIC))
        TriggerOverride([PC],CheckStatGT(NearestEnemyOfType([0.HUMANOID]),0,MINORGLOBE))
        TriggerOverride([PC],Race(NearestEnemyOfType([0.HUMANOID]),RAKSHASA))
        TriggerOverride([PC],Race(NearestEnemyOfType([0.HUMANOID]),LICH))
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC],WIZARD_FIREBALL)  // SPWI304.SPL (Fireball)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_FIREBALL)  // SPWI304.SPL (Fireball)
    !StateCheck(FarthestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(FarthestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(FarthestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    See(FarthestEnemyOf(Myself))
    OR(2)
        !CheckStatGT(FarthestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(FarthestEnemyOf(Myself),ENEMY)
    !CheckStatGT(FarthestEnemyOf(Myself),0,MINORGLOBE)
    !CheckStat(FarthestEnemyOf(Myself),6,WIZARD_SPELL_IMMUNITY)
    OR(3)
        TriggerOverride(FarthestEnemyOf(Myself),Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(6)
        !TriggerOverride(FarthestEnemyOf(Myself),Range(NearestEnemyOfType([0.HUMANOID]),22))
        TriggerOverride(FarthestEnemyOf(Myself),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),59,RESISTFIRE))
        TriggerOverride(FarthestEnemyOf(Myself),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),59,RESISTMAGIC))
        TriggerOverride(FarthestEnemyOf(Myself),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),0,MINORGLOBE))
        TriggerOverride(FarthestEnemyOf(Myself),Race(NearestEnemyOfType([0.HUMANOID]),RAKSHASA))
        TriggerOverride(FarthestEnemyOf(Myself),Race(NearestEnemyOfType([0.HUMANOID]),LICH))
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(FarthestEnemyOf(Myself),WIZARD_FIREBALL)  // SPWI304.SPL (Fireball)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_FIREBALL)  // SPWI304.SPL (Fireball)
    !StateCheck(SecondFarthestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(SecondFarthestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(SecondFarthestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    See(SecondFarthestEnemyOf(Myself))
    OR(2)
        !CheckStatGT(SecondFarthestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondFarthestEnemyOf(Myself),ENEMY)
    !CheckStatGT(SecondFarthestEnemyOf(Myself),0,MINORGLOBE)
    !CheckStat(SecondFarthestEnemyOf(Myself),6,WIZARD_SPELL_IMMUNITY)
    OR(3)
        TriggerOverride(SecondFarthestEnemyOf(Myself),Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(6)
        !TriggerOverride(SecondFarthestEnemyOf(Myself),Range(NearestEnemyOfType([0.HUMANOID]),22))
        TriggerOverride(SecondFarthestEnemyOf(Myself),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),59,RESISTFIRE))
        TriggerOverride(SecondFarthestEnemyOf(Myself),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),59,RESISTMAGIC))
        TriggerOverride(SecondFarthestEnemyOf(Myself),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),0,MINORGLOBE))
        TriggerOverride(SecondFarthestEnemyOf(Myself),Race(NearestEnemyOfType([0.HUMANOID]),RAKSHASA))
        TriggerOverride(SecondFarthestEnemyOf(Myself),Race(NearestEnemyOfType([0.HUMANOID]),LICH))
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(SecondFarthestEnemyOf(Myself),WIZARD_FIREBALL)  // SPWI304.SPL (Fireball)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_FIREBALL)  // SPWI304.SPL (Fireball)
    !StateCheck(ThirdFarthestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(ThirdFarthestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(ThirdFarthestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    See(ThirdFarthestEnemyOf(Myself))
    OR(2)
        !CheckStatGT(ThirdFarthestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdFarthestEnemyOf(Myself),ENEMY)
    !CheckStatGT(ThirdFarthestEnemyOf(Myself),0,MINORGLOBE)
    !CheckStat(ThirdFarthestEnemyOf(Myself),6,WIZARD_SPELL_IMMUNITY)
    OR(3)
        TriggerOverride(ThirdFarthestEnemyOf(Myself),Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(6)
        !TriggerOverride(ThirdFarthestEnemyOf(Myself),Range(NearestEnemyOfType([0.HUMANOID]),22))
        TriggerOverride(ThirdFarthestEnemyOf(Myself),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),59,RESISTFIRE))
        TriggerOverride(ThirdFarthestEnemyOf(Myself),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),59,RESISTMAGIC))
        TriggerOverride(ThirdFarthestEnemyOf(Myself),CheckStatGT(NearestEnemyOfType([0.HUMANOID]),0,MINORGLOBE))
        TriggerOverride(ThirdFarthestEnemyOf(Myself),Race(NearestEnemyOfType([0.HUMANOID]),RAKSHASA))
        TriggerOverride(ThirdFarthestEnemyOf(Myself),Race(NearestEnemyOfType([0.HUMANOID]),LICH))
THEN
    RESPONSE #80
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(ThirdFarthestEnemyOf(Myself),WIZARD_FIREBALL)  // SPWI304.SPL (Fireball)
    RESPONSE #20
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_HORROR)  // SPWI205.SPL (Horror)
    !StateCheck(NearestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(NearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(NearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    !StateCheck(NearestEnemyOf(Myself),STATE_DISABLED)
    !CheckStatGT(NearestEnemyOf(Myself),0,HELD)
    !Kit(NearestEnemyOf(Myself),CAVALIER)
    !CheckStatGT(NearestEnemyOf(Myself),0,WIZARD_RESIST_FEAR)
    !CheckSpellState(NearestEnemyOf(Myself),RESIST_FEAR)
    !General(NearestEnemyOf(Myself),UNDEAD)
    !CheckSpellState(NearestEnemyOf(Myself),STATE_ENRAGED)
    !Kit(NearestEnemyOf(Myself),Blackguard)
    OR(2)
        !CheckSpellState(NearestEnemyOf(Myself),ITEM_PANIC_SEEN)
        !CheckSpellState(NearestEnemyOf(Myself),ITEM_PANIC)
    !CheckStatGT(NearestEnemyOf(Myself),0,MINORGLOBE)
    OR(2)
        !CheckStatGT(NearestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(NearestEnemyOf(Myself),ENEMY)
    OR(3)
        TriggerOverride(NearestEnemyOf(Myself),Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(2)
        !TriggerOverride(NearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        !TriggerOverride(NearestEnemyOf(Myself),StateCheck(SecondNearestAllyOf(Myself),STATE_DISABLED))
    OR(2)
        !TriggerOverride(NearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        TriggerOverride(NearestEnemyOf(Myself),Range(SecondNearestAllyOf(Myself),15))
    CheckStatGT(NearestEnemyOf(Myself),0,SAVEVSSPELL)
    CheckStatLT(Player1,5,LEVEL)
    See(NearestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_HORROR)  // SPWI205.SPL (Horror)
    !StateCheck(SecondNearestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(SecondNearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    !StateCheck(SecondNearestEnemyOf(Myself),STATE_DISABLED)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,HELD)
    !Kit(SecondNearestEnemyOf(Myself),CAVALIER)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,WIZARD_RESIST_FEAR)
    !CheckSpellState(SecondNearestEnemyOf(Myself),RESIST_FEAR)
    !General(SecondNearestEnemyOf(Myself),UNDEAD)
    !CheckSpellState(SecondNearestEnemyOf(Myself),STATE_ENRAGED)
    !Kit(SecondNearestEnemyOf(Myself),Blackguard)
    OR(2)
        !CheckSpellState(SecondNearestEnemyOf(Myself),ITEM_PANIC_SEEN)
        !CheckSpellState(SecondNearestEnemyOf(Myself),ITEM_PANIC)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,MINORGLOBE)
    OR(2)
        !CheckStatGT(SecondNearestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondNearestEnemyOf(Myself),ENEMY)
    OR(3)
        TriggerOverride(SecondNearestEnemyOf(Myself),Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(2)
        !TriggerOverride(SecondNearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        !TriggerOverride(SecondNearestEnemyOf(Myself),StateCheck(SecondNearestAllyOf(Myself),STATE_DISABLED))
    OR(2)
        !TriggerOverride(SecondNearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        TriggerOverride(SecondNearestEnemyOf(Myself),Range(SecondNearestAllyOf(Myself),15))
    CheckStatGT(SecondNearestEnemyOf(Myself),0,SAVEVSSPELL)
    CheckStatLT(Player1,5,LEVEL)
    See(SecondNearestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_HORROR)  // SPWI205.SPL (Horror)
    !StateCheck(ThirdNearestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(ThirdNearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    !StateCheck(ThirdNearestEnemyOf(Myself),STATE_DISABLED)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,HELD)
    !Kit(ThirdNearestEnemyOf(Myself),CAVALIER)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,WIZARD_RESIST_FEAR)
    !CheckSpellState(ThirdNearestEnemyOf(Myself),RESIST_FEAR)
    !General(ThirdNearestEnemyOf(Myself),UNDEAD)
    !CheckSpellState(ThirdNearestEnemyOf(Myself),STATE_ENRAGED)
    !Kit(ThirdNearestEnemyOf(Myself),Blackguard)
    OR(2)
        !CheckSpellState(ThirdNearestEnemyOf(Myself),ITEM_PANIC_SEEN)
        !CheckSpellState(ThirdNearestEnemyOf(Myself),ITEM_PANIC)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,MINORGLOBE)
    OR(2)
        !CheckStatGT(ThirdNearestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdNearestEnemyOf(Myself),ENEMY)
    OR(3)
        TriggerOverride(ThirdNearestEnemyOf(Myself),Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(2)
        !TriggerOverride(ThirdNearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        !TriggerOverride(ThirdNearestEnemyOf(Myself),StateCheck(SecondNearestAllyOf(Myself),STATE_DISABLED))
    OR(2)
        !TriggerOverride(ThirdNearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        TriggerOverride(ThirdNearestEnemyOf(Myself),Range(SecondNearestAllyOf(Myself),15))
    CheckStatGT(ThirdNearestEnemyOf(Myself),0,SAVEVSSPELL)
    CheckStatLT(Player1,5,LEVEL)
    See(ThirdNearestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_HORROR)  // SPWI205.SPL (Horror)
    !StateCheck(FourthNearestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(FourthNearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(FourthNearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    !StateCheck(FourthNearestEnemyOf(Myself),STATE_DISABLED)
    !CheckStatGT(FourthNearestEnemyOf(Myself),0,HELD)
    !Kit(FourthNearestEnemyOf(Myself),CAVALIER)
    !CheckStatGT(FourthNearestEnemyOf(Myself),0,WIZARD_RESIST_FEAR)
    !CheckSpellState(FourthNearestEnemyOf(Myself),RESIST_FEAR)
    !General(FourthNearestEnemyOf(Myself),UNDEAD)
    !CheckSpellState(FourthNearestEnemyOf(Myself),STATE_ENRAGED)
    !Kit(FourthNearestEnemyOf(Myself),Blackguard)
    OR(2)
        !CheckSpellState(FourthNearestEnemyOf(Myself),ITEM_PANIC_SEEN)
        !CheckSpellState(FourthNearestEnemyOf(Myself),ITEM_PANIC)
    !CheckStatGT(FourthNearestEnemyOf(Myself),0,MINORGLOBE)
    OR(2)
        !CheckStatGT(FourthNearestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(FourthNearestEnemyOf(Myself),ENEMY)
    OR(3)
        TriggerOverride(FourthNearestEnemyOf(Myself),Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(2)
        !TriggerOverride(FourthNearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        !TriggerOverride(FourthNearestEnemyOf(Myself),StateCheck(SecondNearestAllyOf(Myself),STATE_DISABLED))
    OR(2)
        !TriggerOverride(FourthNearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        TriggerOverride(FourthNearestEnemyOf(Myself),Range(SecondNearestAllyOf(Myself),15))
    CheckStatGT(FourthNearestEnemyOf(Myself),0,SAVEVSSPELL)
    CheckStatLT(Player1,5,LEVEL)
    See(FourthNearestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_HORROR)  // SPWI205.SPL (Horror)
    !StateCheck(FifthNearestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(FifthNearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(FifthNearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    !StateCheck(FifthNearestEnemyOf(Myself),STATE_DISABLED)
    !CheckStatGT(FifthNearestEnemyOf(Myself),0,HELD)
    !Kit(FifthNearestEnemyOf(Myself),CAVALIER)
    !CheckStatGT(FifthNearestEnemyOf(Myself),0,WIZARD_RESIST_FEAR)
    !CheckSpellState(FifthNearestEnemyOf(Myself),RESIST_FEAR)
    !General(FifthNearestEnemyOf(Myself),UNDEAD)
    !CheckSpellState(FifthNearestEnemyOf(Myself),STATE_ENRAGED)
    !Kit(FifthNearestEnemyOf(Myself),Blackguard)
    OR(2)
        !CheckSpellState(FifthNearestEnemyOf(Myself),ITEM_PANIC_SEEN)
        !CheckSpellState(FifthNearestEnemyOf(Myself),ITEM_PANIC)
    !CheckStatGT(FifthNearestEnemyOf(Myself),0,MINORGLOBE)
    OR(2)
        !CheckStatGT(FifthNearestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(FifthNearestEnemyOf(Myself),ENEMY)
    OR(3)
        TriggerOverride(FifthNearestEnemyOf(Myself),Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(2)
        !TriggerOverride(FifthNearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        !TriggerOverride(FifthNearestEnemyOf(Myself),StateCheck(SecondNearestAllyOf(Myself),STATE_DISABLED))
    OR(2)
        !TriggerOverride(FifthNearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        TriggerOverride(FifthNearestEnemyOf(Myself),Range(SecondNearestAllyOf(Myself),15))
    CheckStatGT(FifthNearestEnemyOf(Myself),0,SAVEVSSPELL)
    CheckStatLT(Player1,5,LEVEL)
    See(FifthNearestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_HORROR)  // SPWI205.SPL (Horror)
    !StateCheck(SixthNearestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(SixthNearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(SixthNearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    !StateCheck(SixthNearestEnemyOf(Myself),STATE_DISABLED)
    !CheckStatGT(SixthNearestEnemyOf(Myself),0,HELD)
    !Kit(SixthNearestEnemyOf(Myself),CAVALIER)
    !CheckStatGT(SixthNearestEnemyOf(Myself),0,WIZARD_RESIST_FEAR)
    !CheckSpellState(SixthNearestEnemyOf(Myself),RESIST_FEAR)
    !General(SixthNearestEnemyOf(Myself),UNDEAD)
    !CheckSpellState(SixthNearestEnemyOf(Myself),STATE_ENRAGED)
    !Kit(SixthNearestEnemyOf(Myself),Blackguard)
    OR(2)
        !CheckSpellState(SixthNearestEnemyOf(Myself),ITEM_PANIC_SEEN)
        !CheckSpellState(SixthNearestEnemyOf(Myself),ITEM_PANIC)
    !CheckStatGT(SixthNearestEnemyOf(Myself),0,MINORGLOBE)
    OR(2)
        !CheckStatGT(SixthNearestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(SixthNearestEnemyOf(Myself),ENEMY)
    OR(3)
        TriggerOverride(SixthNearestEnemyOf(Myself),Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(2)
        !TriggerOverride(SixthNearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        !TriggerOverride(SixthNearestEnemyOf(Myself),StateCheck(SecondNearestAllyOf(Myself),STATE_DISABLED))
    OR(2)
        !TriggerOverride(SixthNearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        TriggerOverride(SixthNearestEnemyOf(Myself),Range(SecondNearestAllyOf(Myself),15))
    CheckStatGT(SixthNearestEnemyOf(Myself),0,SAVEVSSPELL)
    CheckStatLT(Player1,5,LEVEL)
    See(SixthNearestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_HORROR)  // SPWI205.SPL (Horror)
    !StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
    !CheckStatGT(LastSeenBy(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(LastSeenBy(Myself),DO_NOT_TARGET_SPELLS)
    !StateCheck(LastSeenBy(Myself),STATE_DISABLED)
    !CheckStatGT(LastSeenBy(Myself),0,HELD)
    !Kit(LastSeenBy(Myself),CAVALIER)
    !CheckStatGT(LastSeenBy(Myself),0,WIZARD_RESIST_FEAR)
    !CheckSpellState(LastSeenBy(Myself),RESIST_FEAR)
    !General(LastSeenBy(Myself),UNDEAD)
    !CheckSpellState(LastSeenBy(Myself),STATE_ENRAGED)
    !Kit(LastSeenBy(Myself),Blackguard)
    OR(2)
        !CheckSpellState(LastSeenBy(Myself),ITEM_PANIC_SEEN)
        !CheckSpellState(LastSeenBy(Myself),ITEM_PANIC)
    !CheckStatGT(LastSeenBy(Myself),0,MINORGLOBE)
    OR(2)
        !CheckStatGT(LastSeenBy(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(LastSeenBy(Myself),ENEMY)
    OR(3)
        TriggerOverride(LastSeenBy(Myself),Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(2)
        !TriggerOverride(LastSeenBy(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        !TriggerOverride(LastSeenBy(Myself),StateCheck(SecondNearestAllyOf(Myself),STATE_DISABLED))
    OR(2)
        !TriggerOverride(LastSeenBy(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        TriggerOverride(LastSeenBy(Myself),Range(SecondNearestAllyOf(Myself),15))
    CheckStatGT(LastSeenBy(Myself),0,SAVEVSSPELL)
    CheckStatLT(Player1,5,LEVEL)
    See(LastSeenBy(Myself))
THEN
    RESPONSE #100
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(LastSeenBy(Myself),WIZARD_HORROR)  // SPWI205.SPL (Horror)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    !StateCheck(NearestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(NearestEnemyOf(Myself),0,SANCTUARY)
    !StateCheck(NearestEnemyOf(Myself),STATE_DISABLED)
    !CheckStatGT(NearestEnemyOf(Myself),0,HELD)
    !Kit(NearestEnemyOf(Myself),CAVALIER)
    !CheckStatGT(NearestEnemyOf(Myself),0,WIZARD_RESIST_FEAR)
    !CheckSpellState(NearestEnemyOf(Myself),RESIST_FEAR)
    !General(NearestEnemyOf(Myself),UNDEAD)
    !CheckSpellState(NearestEnemyOf(Myself),STATE_ENRAGED)
    !Kit(NearestEnemyOf(Myself),Blackguard)
    OR(2)
        !CheckSpellState(NearestEnemyOf(Myself),ITEM_PANIC_SEEN)
        !CheckSpellState(NearestEnemyOf(Myself),ITEM_PANIC)
    !CheckStatGT(NearestEnemyOf(Myself),0,MINORGLOBE)
    OR(2)
        !CheckStatGT(NearestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(NearestEnemyOf(Myself),ENEMY)
    OR(3)
        TriggerOverride(NearestEnemyOf(Myself),Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(2)
        !TriggerOverride(NearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        !TriggerOverride(NearestEnemyOf(Myself),StateCheck(SecondNearestAllyOf(Myself),STATE_DISABLED))
    OR(2)
        !TriggerOverride(NearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        TriggerOverride(NearestEnemyOf(Myself),Range(SecondNearestAllyOf(Myself),15))
    CheckStatGT(NearestEnemyOf(Myself),0,SAVEVSSPELL)
    See(NearestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    !StateCheck(SecondNearestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,SANCTUARY)
    !StateCheck(SecondNearestEnemyOf(Myself),STATE_DISABLED)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,HELD)
    !Kit(SecondNearestEnemyOf(Myself),CAVALIER)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,WIZARD_RESIST_FEAR)
    !CheckSpellState(SecondNearestEnemyOf(Myself),RESIST_FEAR)
    !General(SecondNearestEnemyOf(Myself),UNDEAD)
    !CheckSpellState(SecondNearestEnemyOf(Myself),STATE_ENRAGED)
    !Kit(SecondNearestEnemyOf(Myself),Blackguard)
    OR(2)
        !CheckSpellState(SecondNearestEnemyOf(Myself),ITEM_PANIC_SEEN)
        !CheckSpellState(SecondNearestEnemyOf(Myself),ITEM_PANIC)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,MINORGLOBE)
    OR(2)
        !CheckStatGT(SecondNearestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondNearestEnemyOf(Myself),ENEMY)
    OR(3)
        TriggerOverride(SecondNearestEnemyOf(Myself),Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(2)
        !TriggerOverride(SecondNearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        !TriggerOverride(SecondNearestEnemyOf(Myself),StateCheck(SecondNearestAllyOf(Myself),STATE_DISABLED))
    OR(2)
        !TriggerOverride(SecondNearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        TriggerOverride(SecondNearestEnemyOf(Myself),Range(SecondNearestAllyOf(Myself),15))
    CheckStatGT(SecondNearestEnemyOf(Myself),0,SAVEVSSPELL)
    See(SecondNearestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    !StateCheck(ThirdNearestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,SANCTUARY)
    !StateCheck(ThirdNearestEnemyOf(Myself),STATE_DISABLED)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,HELD)
    !Kit(ThirdNearestEnemyOf(Myself),CAVALIER)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,WIZARD_RESIST_FEAR)
    !CheckSpellState(ThirdNearestEnemyOf(Myself),RESIST_FEAR)
    !General(ThirdNearestEnemyOf(Myself),UNDEAD)
    !CheckSpellState(ThirdNearestEnemyOf(Myself),STATE_ENRAGED)
    !Kit(ThirdNearestEnemyOf(Myself),Blackguard)
    OR(2)
        !CheckSpellState(ThirdNearestEnemyOf(Myself),ITEM_PANIC_SEEN)
        !CheckSpellState(ThirdNearestEnemyOf(Myself),ITEM_PANIC)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,MINORGLOBE)
    OR(2)
        !CheckStatGT(ThirdNearestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdNearestEnemyOf(Myself),ENEMY)
    OR(3)
        TriggerOverride(ThirdNearestEnemyOf(Myself),Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(2)
        !TriggerOverride(ThirdNearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        !TriggerOverride(ThirdNearestEnemyOf(Myself),StateCheck(SecondNearestAllyOf(Myself),STATE_DISABLED))
    OR(2)
        !TriggerOverride(ThirdNearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        TriggerOverride(ThirdNearestEnemyOf(Myself),Range(SecondNearestAllyOf(Myself),15))
    CheckStatGT(ThirdNearestEnemyOf(Myself),0,SAVEVSSPELL)
    See(ThirdNearestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    !StateCheck(FourthNearestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(FourthNearestEnemyOf(Myself),0,SANCTUARY)
    !StateCheck(FourthNearestEnemyOf(Myself),STATE_DISABLED)
    !CheckStatGT(FourthNearestEnemyOf(Myself),0,HELD)
    !Kit(FourthNearestEnemyOf(Myself),CAVALIER)
    !CheckStatGT(FourthNearestEnemyOf(Myself),0,WIZARD_RESIST_FEAR)
    !CheckSpellState(FourthNearestEnemyOf(Myself),RESIST_FEAR)
    !General(FourthNearestEnemyOf(Myself),UNDEAD)
    !CheckSpellState(FourthNearestEnemyOf(Myself),STATE_ENRAGED)
    !Kit(FourthNearestEnemyOf(Myself),Blackguard)
    OR(2)
        !CheckSpellState(FourthNearestEnemyOf(Myself),ITEM_PANIC_SEEN)
        !CheckSpellState(FourthNearestEnemyOf(Myself),ITEM_PANIC)
    !CheckStatGT(FourthNearestEnemyOf(Myself),0,MINORGLOBE)
    OR(2)
        !CheckStatGT(FourthNearestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(FourthNearestEnemyOf(Myself),ENEMY)
    OR(3)
        TriggerOverride(FourthNearestEnemyOf(Myself),Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(2)
        !TriggerOverride(FourthNearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        !TriggerOverride(FourthNearestEnemyOf(Myself),StateCheck(SecondNearestAllyOf(Myself),STATE_DISABLED))
    OR(2)
        !TriggerOverride(FourthNearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        TriggerOverride(FourthNearestEnemyOf(Myself),Range(SecondNearestAllyOf(Myself),15))
    CheckStatGT(FourthNearestEnemyOf(Myself),0,SAVEVSSPELL)
    See(FourthNearestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    !StateCheck(FifthNearestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(FifthNearestEnemyOf(Myself),0,SANCTUARY)
    !StateCheck(FifthNearestEnemyOf(Myself),STATE_DISABLED)
    !CheckStatGT(FifthNearestEnemyOf(Myself),0,HELD)
    !Kit(FifthNearestEnemyOf(Myself),CAVALIER)
    !CheckStatGT(FifthNearestEnemyOf(Myself),0,WIZARD_RESIST_FEAR)
    !CheckSpellState(FifthNearestEnemyOf(Myself),RESIST_FEAR)
    !General(FifthNearestEnemyOf(Myself),UNDEAD)
    !CheckSpellState(FifthNearestEnemyOf(Myself),STATE_ENRAGED)
    !Kit(FifthNearestEnemyOf(Myself),Blackguard)
    OR(2)
        !CheckSpellState(FifthNearestEnemyOf(Myself),ITEM_PANIC_SEEN)
        !CheckSpellState(FifthNearestEnemyOf(Myself),ITEM_PANIC)
    !CheckStatGT(FifthNearestEnemyOf(Myself),0,MINORGLOBE)
    OR(2)
        !CheckStatGT(FifthNearestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(FifthNearestEnemyOf(Myself),ENEMY)
    OR(3)
        TriggerOverride(FifthNearestEnemyOf(Myself),Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(2)
        !TriggerOverride(FifthNearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        !TriggerOverride(FifthNearestEnemyOf(Myself),StateCheck(SecondNearestAllyOf(Myself),STATE_DISABLED))
    OR(2)
        !TriggerOverride(FifthNearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        TriggerOverride(FifthNearestEnemyOf(Myself),Range(SecondNearestAllyOf(Myself),15))
    CheckStatGT(FifthNearestEnemyOf(Myself),0,SAVEVSSPELL)
    See(FifthNearestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    !StateCheck(SixthNearestEnemyOf(Myself),STATE_INVISIBLE)
    !CheckStatGT(SixthNearestEnemyOf(Myself),0,SANCTUARY)
    !StateCheck(SixthNearestEnemyOf(Myself),STATE_DISABLED)
    !CheckStatGT(SixthNearestEnemyOf(Myself),0,HELD)
    !Kit(SixthNearestEnemyOf(Myself),CAVALIER)
    !CheckStatGT(SixthNearestEnemyOf(Myself),0,WIZARD_RESIST_FEAR)
    !CheckSpellState(SixthNearestEnemyOf(Myself),RESIST_FEAR)
    !General(SixthNearestEnemyOf(Myself),UNDEAD)
    !CheckSpellState(SixthNearestEnemyOf(Myself),STATE_ENRAGED)
    !Kit(SixthNearestEnemyOf(Myself),Blackguard)
    OR(2)
        !CheckSpellState(SixthNearestEnemyOf(Myself),ITEM_PANIC_SEEN)
        !CheckSpellState(SixthNearestEnemyOf(Myself),ITEM_PANIC)
    !CheckStatGT(SixthNearestEnemyOf(Myself),0,MINORGLOBE)
    OR(2)
        !CheckStatGT(SixthNearestEnemyOf(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(SixthNearestEnemyOf(Myself),ENEMY)
    OR(3)
        TriggerOverride(SixthNearestEnemyOf(Myself),Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(2)
        !TriggerOverride(SixthNearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        !TriggerOverride(SixthNearestEnemyOf(Myself),StateCheck(SecondNearestAllyOf(Myself),STATE_DISABLED))
    OR(2)
        !TriggerOverride(SixthNearestEnemyOf(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        TriggerOverride(SixthNearestEnemyOf(Myself),Range(SecondNearestAllyOf(Myself),15))
    CheckStatGT(SixthNearestEnemyOf(Myself),0,SAVEVSSPELL)
    See(SixthNearestEnemyOf(Myself))
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_HORROR)  // SPWI205.SPL (Horror)
    !StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
    !CheckStatGT(LastSeenBy(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(LastSeenBy(Myself),DO_NOT_TARGET_SPELLS)
    !StateCheck(LastSeenBy(Myself),STATE_DISABLED)
    !CheckStatGT(LastSeenBy(Myself),0,HELD)
    !Kit(LastSeenBy(Myself),CAVALIER)
    !CheckStatGT(LastSeenBy(Myself),0,WIZARD_RESIST_FEAR)
    !CheckSpellState(LastSeenBy(Myself),RESIST_FEAR)
    !General(LastSeenBy(Myself),UNDEAD)
    !CheckSpellState(LastSeenBy(Myself),STATE_ENRAGED)
    !Kit(LastSeenBy(Myself),Blackguard)
    OR(2)
        !CheckSpellState(LastSeenBy(Myself),ITEM_PANIC_SEEN)
        !CheckSpellState(LastSeenBy(Myself),ITEM_PANIC)
    !CheckStatGT(LastSeenBy(Myself),0,MINORGLOBE)
    OR(2)
        !CheckStatGT(LastSeenBy(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(LastSeenBy(Myself),ENEMY)
    OR(3)
        TriggerOverride(LastSeenBy(Myself),Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(2)
        !TriggerOverride(LastSeenBy(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        !TriggerOverride(LastSeenBy(Myself),StateCheck(SecondNearestAllyOf(Myself),STATE_DISABLED))
    OR(2)
        !TriggerOverride(LastSeenBy(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        TriggerOverride(LastSeenBy(Myself),Range(SecondNearestAllyOf(Myself),15))
    CheckStatGT(LastSeenBy(Myself),0,SAVEVSSPELL)
    See(LastSeenBy(Myself))
THEN
    RESPONSE #100
        ApplySpellRES("dw#mgsee",Myself)  // Armor
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(LastSeenBy(Myself),WIZARD_HORROR)  // SPWI205.SPL (Horror)
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    !StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
    HasItem("wand02",Myself)  // Wand of Fear
    !CheckStatGT(LastSeenBy(Myself),0,SANCTUARY)
    !StateCheck(LastSeenBy(Myself),STATE_DISABLED)
    !CheckStatGT(LastSeenBy(Myself),0,HELD)
    !Kit(LastSeenBy(Myself),CAVALIER)
    !CheckStatGT(LastSeenBy(Myself),0,WIZARD_RESIST_FEAR)
    !CheckSpellState(LastSeenBy(Myself),RESIST_FEAR)
    !General(LastSeenBy(Myself),UNDEAD)
    !CheckSpellState(LastSeenBy(Myself),STATE_ENRAGED)
    !Kit(LastSeenBy(Myself),Blackguard)
    OR(2)
        !CheckSpellState(LastSeenBy(Myself),ITEM_PANIC_SEEN)
        !CheckSpellState(LastSeenBy(Myself),ITEM_PANIC)
    !CheckStatGT(LastSeenBy(Myself),0,MINORGLOBE)
    OR(2)
        !CheckStatGT(LastSeenBy(Myself),50,RESISTMAGIC)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    Allegiance(Myself,ENEMY)
    !Allegiance(LastSeenBy(Myself),ENEMY)
    OR(3)
        TriggerOverride(LastSeenBy(Myself),Range(NearestAllyOf(Myself),15))
        NumInParty(1)
        GlobalTimerNotExpired("targetcompromise","LOCALS")
    OR(2)
        !TriggerOverride(LastSeenBy(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        !TriggerOverride(LastSeenBy(Myself),StateCheck(SecondNearestAllyOf(Myself),STATE_DISABLED))
    OR(2)
        !TriggerOverride(LastSeenBy(Myself),StateCheck(NearestAllyOf(Myself),STATE_DISABLED))
        TriggerOverride(LastSeenBy(Myself),Range(SecondNearestAllyOf(Myself),15))
    CheckStatGT(LastSeenBy(Myself),0,SAVEVSSPELL)
    See(LastSeenBy(Myself))
THEN
    RESPONSE #100
        SetInterrupt(FALSE)
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        DisplayStringHead(Myself,49146)  // Uses a wand
        UseItem("wand02",LastSeenBy(Myself))  // Wand of Fear
        SetInterrupt(TRUE)
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck([PC.0.0.MAGE_ALL],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.MAGE_ALL],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.MAGE_ALL])
    !CheckStatGT([PC.0.0.MAGE_ALL],99,RESISTMAGIC)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.MAGE_ALL],ENEMY)
    !CheckSpellState([PC.0.0.MAGE_ALL],WIZARD_SHIELD)
    OR(2)
        !CheckSpellState([PC.0.0.MAGE_ALL],ITEM_MM_SEEN)
        !CheckSpellState([PC.0.0.MAGE_ALL],ITEM_MM)
    StateCheck([PC.0.0.MAGE_ALL],STATE_MIRRORIMAGE)
    Allegiance(Myself,ENEMY)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",[PC.0.0.MAGE_ALL])  // No such index
        Spell([PC.0.0.MAGE_ALL],WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck([PC.0.0.CLERIC_ALL],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.CLERIC_ALL],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.CLERIC_ALL],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.CLERIC_ALL])
    !CheckStatGT([PC.0.0.CLERIC_ALL],99,RESISTMAGIC)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.CLERIC_ALL],ENEMY)
    !CheckSpellState([PC.0.0.CLERIC_ALL],WIZARD_SHIELD)
    OR(2)
        !CheckSpellState([PC.0.0.CLERIC_ALL],ITEM_MM_SEEN)
        !CheckSpellState([PC.0.0.CLERIC_ALL],ITEM_MM)
    StateCheck([PC.0.0.CLERIC_ALL],STATE_MIRRORIMAGE)
    Allegiance(Myself,ENEMY)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",[PC.0.0.CLERIC_ALL])  // No such index
        Spell([PC.0.0.CLERIC_ALL],WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck([PC.0.0.DRUID_ALL],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.DRUID_ALL],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.DRUID_ALL],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.DRUID_ALL])
    !CheckStatGT([PC.0.0.DRUID_ALL],99,RESISTMAGIC)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.DRUID_ALL],ENEMY)
    !CheckSpellState([PC.0.0.DRUID_ALL],WIZARD_SHIELD)
    OR(2)
        !CheckSpellState([PC.0.0.DRUID_ALL],ITEM_MM_SEEN)
        !CheckSpellState([PC.0.0.DRUID_ALL],ITEM_MM)
    StateCheck([PC.0.0.DRUID_ALL],STATE_MIRRORIMAGE)
    Allegiance(Myself,ENEMY)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",[PC.0.0.DRUID_ALL])  // No such index
        Spell([PC.0.0.DRUID_ALL],WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck([PC.0.0.BARD],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.BARD],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.BARD],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.BARD])
    !CheckStatGT([PC.0.0.BARD],99,RESISTMAGIC)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.BARD],ENEMY)
    !CheckSpellState([PC.0.0.BARD],WIZARD_SHIELD)
    OR(2)
        !CheckSpellState([PC.0.0.BARD],ITEM_MM_SEEN)
        !CheckSpellState([PC.0.0.BARD],ITEM_MM)
    StateCheck([PC.0.0.BARD],STATE_MIRRORIMAGE)
    Allegiance(Myself,ENEMY)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",[PC.0.0.BARD])  // No such index
        Spell([PC.0.0.BARD],WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    !StateCheck([PC.0.0.MAGE_ALL],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.MAGE_ALL],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.MAGE_ALL])
    Allegiance(Myself,ENEMY)
    !CheckStatGT([PC.0.0.MAGE_ALL],99,RESISTMAGIC)
    !StateCheck([PC.0.0.MAGE_ALL],STATE_MIRRORIMAGE)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,MINORGLOBE)
    OR(2)
        !CheckStat([PC.0.0.MAGE_ALL],1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT([PC.0.0.MAGE_ALL],0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",[PC.0.0.MAGE_ALL])
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    !CheckStatGT([PC.0.0.MAGE_ALL],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,WIZARD_SPELL_TRAP)
    !Allegiance([PC.0.0.MAGE_ALL],ENEMY)
    !CheckStatGT([PC.0.0.MAGE_ALL],50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC.0.0.MAGE_ALL],WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    RESPONSE #50
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    !StateCheck([PC.0.0.CLERIC_ALL],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.CLERIC_ALL],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.CLERIC_ALL],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.CLERIC_ALL])
    Allegiance(Myself,ENEMY)
    !CheckStatGT([PC.0.0.CLERIC_ALL],99,RESISTMAGIC)
    !StateCheck([PC.0.0.CLERIC_ALL],STATE_MIRRORIMAGE)
    !CheckStatGT([PC.0.0.CLERIC_ALL],0,MINORGLOBE)
    OR(2)
        !CheckStat([PC.0.0.CLERIC_ALL],1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT([PC.0.0.CLERIC_ALL],0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",[PC.0.0.CLERIC_ALL])
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    !CheckStatGT([PC.0.0.CLERIC_ALL],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.CLERIC_ALL],0,WIZARD_SPELL_TRAP)
    !Allegiance([PC.0.0.CLERIC_ALL],ENEMY)
    !CheckStatGT([PC.0.0.CLERIC_ALL],50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC.0.0.CLERIC_ALL],WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    RESPONSE #50
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    !StateCheck([PC.0.0.DRUID_ALL],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.DRUID_ALL],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.DRUID_ALL],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.DRUID_ALL])
    Allegiance(Myself,ENEMY)
    !CheckStatGT([PC.0.0.DRUID_ALL],99,RESISTMAGIC)
    !StateCheck([PC.0.0.DRUID_ALL],STATE_MIRRORIMAGE)
    !CheckStatGT([PC.0.0.DRUID_ALL],0,MINORGLOBE)
    OR(2)
        !CheckStat([PC.0.0.DRUID_ALL],1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT([PC.0.0.DRUID_ALL],0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",[PC.0.0.DRUID_ALL])
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    !CheckStatGT([PC.0.0.DRUID_ALL],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.DRUID_ALL],0,WIZARD_SPELL_TRAP)
    !Allegiance([PC.0.0.DRUID_ALL],ENEMY)
    !CheckStatGT([PC.0.0.DRUID_ALL],50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC.0.0.DRUID_ALL],WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    RESPONSE #50
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    !StateCheck([PC.0.0.BARD],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.BARD],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.BARD],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.BARD])
    Allegiance(Myself,ENEMY)
    !CheckStatGT([PC.0.0.BARD],99,RESISTMAGIC)
    !StateCheck([PC.0.0.BARD],STATE_MIRRORIMAGE)
    !CheckStatGT([PC.0.0.BARD],0,MINORGLOBE)
    OR(2)
        !CheckStat([PC.0.0.BARD],1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT([PC.0.0.BARD],0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",[PC.0.0.BARD])
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    !CheckStatGT([PC.0.0.BARD],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.BARD],0,WIZARD_SPELL_TRAP)
    !Allegiance([PC.0.0.BARD],ENEMY)
    !CheckStatGT([PC.0.0.BARD],50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC.0.0.BARD],WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    RESPONSE #50
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    !StateCheck([PC.0.0.MAGE_ALL],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.MAGE_ALL],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.MAGE_ALL])
    Allegiance(Myself,ENEMY)
    !CheckStatGT([PC.0.0.MAGE_ALL],99,RESISTMAGIC)
    !StateCheck([PC.0.0.MAGE_ALL],STATE_MIRRORIMAGE)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,MINORGLOBE)
    OR(2)
        !CheckStat([PC.0.0.MAGE_ALL],1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT([PC.0.0.MAGE_ALL],0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",[PC.0.0.MAGE_ALL])
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    !CheckStatGT([PC.0.0.MAGE_ALL],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,WIZARD_SPELL_TRAP)
    !Allegiance([PC.0.0.MAGE_ALL],ENEMY)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC.0.0.MAGE_ALL],WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    RESPONSE #50
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    !StateCheck([PC.0.0.CLERIC_ALL],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.CLERIC_ALL],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.CLERIC_ALL],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.CLERIC_ALL])
    Allegiance(Myself,ENEMY)
    !CheckStatGT([PC.0.0.CLERIC_ALL],99,RESISTMAGIC)
    !StateCheck([PC.0.0.CLERIC_ALL],STATE_MIRRORIMAGE)
    !CheckStatGT([PC.0.0.CLERIC_ALL],0,MINORGLOBE)
    OR(2)
        !CheckStat([PC.0.0.CLERIC_ALL],1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT([PC.0.0.CLERIC_ALL],0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",[PC.0.0.CLERIC_ALL])
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    !CheckStatGT([PC.0.0.CLERIC_ALL],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.CLERIC_ALL],0,WIZARD_SPELL_TRAP)
    !Allegiance([PC.0.0.CLERIC_ALL],ENEMY)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC.0.0.CLERIC_ALL],WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    RESPONSE #50
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    !StateCheck([PC.0.0.DRUID_ALL],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.DRUID_ALL],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.DRUID_ALL],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.DRUID_ALL])
    Allegiance(Myself,ENEMY)
    !CheckStatGT([PC.0.0.DRUID_ALL],99,RESISTMAGIC)
    !StateCheck([PC.0.0.DRUID_ALL],STATE_MIRRORIMAGE)
    !CheckStatGT([PC.0.0.DRUID_ALL],0,MINORGLOBE)
    OR(2)
        !CheckStat([PC.0.0.DRUID_ALL],1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT([PC.0.0.DRUID_ALL],0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",[PC.0.0.DRUID_ALL])
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    !CheckStatGT([PC.0.0.DRUID_ALL],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.DRUID_ALL],0,WIZARD_SPELL_TRAP)
    !Allegiance([PC.0.0.DRUID_ALL],ENEMY)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC.0.0.DRUID_ALL],WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    RESPONSE #50
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    !StateCheck([PC.0.0.BARD],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.BARD],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.BARD],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.BARD])
    Allegiance(Myself,ENEMY)
    !CheckStatGT([PC.0.0.BARD],99,RESISTMAGIC)
    !StateCheck([PC.0.0.BARD],STATE_MIRRORIMAGE)
    !CheckStatGT([PC.0.0.BARD],0,MINORGLOBE)
    OR(2)
        !CheckStat([PC.0.0.BARD],1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT([PC.0.0.BARD],0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",[PC.0.0.BARD])
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    !CheckStatGT([PC.0.0.BARD],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.BARD],0,WIZARD_SPELL_TRAP)
    !Allegiance([PC.0.0.BARD],ENEMY)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC.0.0.BARD],WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    RESPONSE #50
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck([PC.0.0.MAGE],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.MAGE],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.MAGE],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.MAGE])
    !CheckStatGT([PC.0.0.MAGE],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.MAGE],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.MAGE],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.MAGE],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.MAGE],ENEMY)
    !CheckStatGT([PC.0.0.MAGE],50,RESISTMAGIC)
    HPPercentLT([PC.0.0.MAGE],40)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC.0.0.MAGE],WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck([PC.0.0.MAGE_THIEF],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.MAGE_THIEF],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.MAGE_THIEF],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.MAGE_THIEF])
    !CheckStatGT([PC.0.0.MAGE_THIEF],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.MAGE_THIEF],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.MAGE_THIEF],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.MAGE_THIEF],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.MAGE_THIEF],ENEMY)
    !CheckStatGT([PC.0.0.MAGE_THIEF],50,RESISTMAGIC)
    HPPercentLT([PC.0.0.MAGE_THIEF],40)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC.0.0.MAGE_THIEF],WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck([PC.0.0.MAGE_ALL],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.MAGE_ALL],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.MAGE_ALL])
    !CheckStatGT([PC.0.0.MAGE_ALL],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.MAGE_ALL],ENEMY)
    !CheckStatGT([PC.0.0.MAGE_ALL],50,RESISTMAGIC)
    HPPercentLT([PC.0.0.MAGE_ALL],40)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC.0.0.MAGE_ALL],WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck([PC.0.0.THIEF],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.THIEF],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.THIEF],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.THIEF])
    !CheckStatGT([PC.0.0.THIEF],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.THIEF],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.THIEF],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.THIEF],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.THIEF],ENEMY)
    !CheckStatGT([PC.0.0.THIEF],50,RESISTMAGIC)
    HPPercentLT([PC.0.0.THIEF],40)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC.0.0.THIEF],WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck([PC.0.0.BARD],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.BARD],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.BARD],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.BARD])
    !CheckStatGT([PC.0.0.BARD],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.BARD],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.BARD],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.BARD],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.BARD],ENEMY)
    !CheckStatGT([PC.0.0.BARD],50,RESISTMAGIC)
    HPPercentLT([PC.0.0.BARD],40)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC.0.0.BARD],WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck([PC.0.0.THIEF_ALL],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.THIEF_ALL],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.THIEF_ALL],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.THIEF_ALL])
    !CheckStatGT([PC.0.0.THIEF_ALL],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.THIEF_ALL],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.THIEF_ALL],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.THIEF_ALL],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.THIEF_ALL],ENEMY)
    !CheckStatGT([PC.0.0.THIEF_ALL],50,RESISTMAGIC)
    HPPercentLT([PC.0.0.THIEF_ALL],40)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC.0.0.THIEF_ALL],WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck([PC.0.0.CLERIC],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.CLERIC],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.CLERIC],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.CLERIC])
    !CheckStatGT([PC.0.0.CLERIC],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.CLERIC],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.CLERIC],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.CLERIC],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.CLERIC],ENEMY)
    !CheckStatGT([PC.0.0.CLERIC],50,RESISTMAGIC)
    HPPercentLT([PC.0.0.CLERIC],40)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC.0.0.CLERIC],WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck([PC],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC],DO_NOT_TARGET_SPELLS)
    See([PC])
    !CheckStatGT([PC],99,RESISTMAGIC)
    !CheckStatGT([PC],0,MINORGLOBE)
    !CheckStatGT([PC],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC],ENEMY)
    !CheckStatGT([PC],50,RESISTMAGIC)
    HPPercentLT([PC],40)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC],WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck(SecondNearest([PC]),STATE_NOT_TARGETABLE)
    !CheckStatGT(SecondNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(SecondNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(SecondNearest([PC]))
    !CheckStatGT(SecondNearest([PC]),99,RESISTMAGIC)
    !CheckStatGT(SecondNearest([PC]),0,MINORGLOBE)
    !CheckStatGT(SecondNearest([PC]),0,WIZARD_SPELL_TURNING)
    !CheckStatGT(SecondNearest([PC]),0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondNearest([PC]),ENEMY)
    !CheckStatGT(SecondNearest([PC]),50,RESISTMAGIC)
    HPPercentLT(SecondNearest([PC]),40)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(SecondNearest([PC]),WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck(ThirdNearest([PC]),STATE_NOT_TARGETABLE)
    !CheckStatGT(ThirdNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(ThirdNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(ThirdNearest([PC]))
    !CheckStatGT(ThirdNearest([PC]),99,RESISTMAGIC)
    !CheckStatGT(ThirdNearest([PC]),0,MINORGLOBE)
    !CheckStatGT(ThirdNearest([PC]),0,WIZARD_SPELL_TURNING)
    !CheckStatGT(ThirdNearest([PC]),0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdNearest([PC]),ENEMY)
    !CheckStatGT(ThirdNearest([PC]),50,RESISTMAGIC)
    HPPercentLT(ThirdNearest([PC]),40)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(ThirdNearest([PC]),WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck([PC.0.0.MAGE],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.MAGE],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.MAGE],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.MAGE])
    !CheckStatGT([PC.0.0.MAGE],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.MAGE],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.MAGE],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.MAGE],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.MAGE],ENEMY)
    !CheckStatGT([PC.0.0.MAGE],50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC.0.0.MAGE],WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck([PC.0.0.MAGE_THIEF],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.MAGE_THIEF],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.MAGE_THIEF],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.MAGE_THIEF])
    !CheckStatGT([PC.0.0.MAGE_THIEF],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.MAGE_THIEF],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.MAGE_THIEF],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.MAGE_THIEF],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.MAGE_THIEF],ENEMY)
    !CheckStatGT([PC.0.0.MAGE_THIEF],50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC.0.0.MAGE_THIEF],WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck([PC.0.0.MAGE_ALL],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.MAGE_ALL],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.MAGE_ALL])
    !CheckStatGT([PC.0.0.MAGE_ALL],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.MAGE_ALL],ENEMY)
    !CheckStatGT([PC.0.0.MAGE_ALL],50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC.0.0.MAGE_ALL],WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck([PC.0.0.THIEF],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.THIEF],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.THIEF],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.THIEF])
    !CheckStatGT([PC.0.0.THIEF],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.THIEF],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.THIEF],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.THIEF],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.THIEF],ENEMY)
    !CheckStatGT([PC.0.0.THIEF],50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC.0.0.THIEF],WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck([PC.0.0.BARD],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.BARD],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.BARD],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.BARD])
    !CheckStatGT([PC.0.0.BARD],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.BARD],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.BARD],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.BARD],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.BARD],ENEMY)
    !CheckStatGT([PC.0.0.BARD],50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC.0.0.BARD],WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck([PC.0.0.THIEF_ALL],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.THIEF_ALL],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.THIEF_ALL],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.THIEF_ALL])
    !CheckStatGT([PC.0.0.THIEF_ALL],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.THIEF_ALL],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.THIEF_ALL],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.THIEF_ALL],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.THIEF_ALL],ENEMY)
    !CheckStatGT([PC.0.0.THIEF_ALL],50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC.0.0.THIEF_ALL],WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck([PC.0.0.CLERIC],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.CLERIC],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.CLERIC],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.CLERIC])
    !CheckStatGT([PC.0.0.CLERIC],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.CLERIC],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.CLERIC],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.CLERIC],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.CLERIC],ENEMY)
    !CheckStatGT([PC.0.0.CLERIC],50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC.0.0.CLERIC],WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck([PC],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC],DO_NOT_TARGET_SPELLS)
    See([PC])
    !CheckStatGT([PC],99,RESISTMAGIC)
    !CheckStatGT([PC],0,MINORGLOBE)
    !CheckStatGT([PC],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC],ENEMY)
    !CheckStatGT([PC],50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell([PC],WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck(SecondNearest([PC]),STATE_NOT_TARGETABLE)
    !CheckStatGT(SecondNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(SecondNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(SecondNearest([PC]))
    !CheckStatGT(SecondNearest([PC]),99,RESISTMAGIC)
    !CheckStatGT(SecondNearest([PC]),0,MINORGLOBE)
    !CheckStatGT(SecondNearest([PC]),0,WIZARD_SPELL_TURNING)
    !CheckStatGT(SecondNearest([PC]),0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondNearest([PC]),ENEMY)
    !CheckStatGT(SecondNearest([PC]),50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(SecondNearest([PC]),WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck(ThirdNearest([PC]),STATE_NOT_TARGETABLE)
    !CheckStatGT(ThirdNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(ThirdNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(ThirdNearest([PC]))
    !CheckStatGT(ThirdNearest([PC]),99,RESISTMAGIC)
    !CheckStatGT(ThirdNearest([PC]),0,MINORGLOBE)
    !CheckStatGT(ThirdNearest([PC]),0,WIZARD_SPELL_TURNING)
    !CheckStatGT(ThirdNearest([PC]),0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdNearest([PC]),ENEMY)
    !CheckStatGT(ThirdNearest([PC]),50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(ThirdNearest([PC]),WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck(NearestEnemyOf(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(NearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(NearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    See(NearestEnemyOf(Myself))
    !CheckStatGT(NearestEnemyOf(Myself),99,RESISTMAGIC)
    !CheckStatGT(NearestEnemyOf(Myself),0,MINORGLOBE)
    !CheckStatGT(NearestEnemyOf(Myself),0,WIZARD_SPELL_TURNING)
    !CheckStatGT(NearestEnemyOf(Myself),0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance(NearestEnemyOf(Myself),ENEMY)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(NearestEnemyOf(Myself),WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck(SecondNearestEnemyOf(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(SecondNearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    See(SecondNearestEnemyOf(Myself))
    !CheckStatGT(SecondNearestEnemyOf(Myself),99,RESISTMAGIC)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,MINORGLOBE)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,WIZARD_SPELL_TURNING)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondNearestEnemyOf(Myself),ENEMY)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(SecondNearestEnemyOf(Myself),WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck(ThirdNearestEnemyOf(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(ThirdNearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    See(ThirdNearestEnemyOf(Myself))
    !CheckStatGT(ThirdNearestEnemyOf(Myself),99,RESISTMAGIC)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,MINORGLOBE)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,WIZARD_SPELL_TURNING)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdNearestEnemyOf(Myself),ENEMY)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(ThirdNearestEnemyOf(Myself),WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck([PC.0.0.MAGE],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.MAGE],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.MAGE],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.MAGE])
    !CheckStatGT([PC.0.0.MAGE],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.MAGE],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.MAGE],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.MAGE],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.MAGE],ENEMY)
    !CheckSpellState([PC.0.0.MAGE],WIZARD_SHIELD)
    OR(2)
        !CheckSpellState([PC.0.0.MAGE],ITEM_MM_SEEN)
        !CheckSpellState([PC.0.0.MAGE],ITEM_MM)
    !CheckStatGT([PC.0.0.MAGE],50,RESISTMAGIC)
    HPPercentLT([PC.0.0.MAGE],40)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",[PC.0.0.MAGE])  // No such index
        Spell([PC.0.0.MAGE],WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck([PC.0.0.MAGE_THIEF],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.MAGE_THIEF],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.MAGE_THIEF],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.MAGE_THIEF])
    !CheckStatGT([PC.0.0.MAGE_THIEF],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.MAGE_THIEF],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.MAGE_THIEF],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.MAGE_THIEF],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.MAGE_THIEF],ENEMY)
    !CheckSpellState([PC.0.0.MAGE_THIEF],WIZARD_SHIELD)
    OR(2)
        !CheckSpellState([PC.0.0.MAGE_THIEF],ITEM_MM_SEEN)
        !CheckSpellState([PC.0.0.MAGE_THIEF],ITEM_MM)
    !CheckStatGT([PC.0.0.MAGE_THIEF],50,RESISTMAGIC)
    HPPercentLT([PC.0.0.MAGE_THIEF],40)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",[PC.0.0.MAGE_THIEF])  // No such index
        Spell([PC.0.0.MAGE_THIEF],WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck([PC.0.0.MAGE_ALL],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.MAGE_ALL],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.MAGE_ALL])
    !CheckStatGT([PC.0.0.MAGE_ALL],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.MAGE_ALL],ENEMY)
    !CheckSpellState([PC.0.0.MAGE_ALL],WIZARD_SHIELD)
    OR(2)
        !CheckSpellState([PC.0.0.MAGE_ALL],ITEM_MM_SEEN)
        !CheckSpellState([PC.0.0.MAGE_ALL],ITEM_MM)
    !CheckStatGT([PC.0.0.MAGE_ALL],50,RESISTMAGIC)
    HPPercentLT([PC.0.0.MAGE_ALL],40)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",[PC.0.0.MAGE_ALL])  // No such index
        Spell([PC.0.0.MAGE_ALL],WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck([PC.0.0.THIEF],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.THIEF],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.THIEF],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.THIEF])
    !CheckStatGT([PC.0.0.THIEF],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.THIEF],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.THIEF],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.THIEF],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.THIEF],ENEMY)
    !CheckSpellState([PC.0.0.THIEF],WIZARD_SHIELD)
    OR(2)
        !CheckSpellState([PC.0.0.THIEF],ITEM_MM_SEEN)
        !CheckSpellState([PC.0.0.THIEF],ITEM_MM)
    !CheckStatGT([PC.0.0.THIEF],50,RESISTMAGIC)
    HPPercentLT([PC.0.0.THIEF],40)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",[PC.0.0.THIEF])  // No such index
        Spell([PC.0.0.THIEF],WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck([PC.0.0.BARD],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.BARD],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.BARD],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.BARD])
    !CheckStatGT([PC.0.0.BARD],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.BARD],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.BARD],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.BARD],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.BARD],ENEMY)
    !CheckSpellState([PC.0.0.BARD],WIZARD_SHIELD)
    OR(2)
        !CheckSpellState([PC.0.0.BARD],ITEM_MM_SEEN)
        !CheckSpellState([PC.0.0.BARD],ITEM_MM)
    !CheckStatGT([PC.0.0.BARD],50,RESISTMAGIC)
    HPPercentLT([PC.0.0.BARD],40)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",[PC.0.0.BARD])  // No such index
        Spell([PC.0.0.BARD],WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck([PC.0.0.THIEF_ALL],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.THIEF_ALL],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.THIEF_ALL],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.THIEF_ALL])
    !CheckStatGT([PC.0.0.THIEF_ALL],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.THIEF_ALL],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.THIEF_ALL],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.THIEF_ALL],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.THIEF_ALL],ENEMY)
    !CheckSpellState([PC.0.0.THIEF_ALL],WIZARD_SHIELD)
    OR(2)
        !CheckSpellState([PC.0.0.THIEF_ALL],ITEM_MM_SEEN)
        !CheckSpellState([PC.0.0.THIEF_ALL],ITEM_MM)
    !CheckStatGT([PC.0.0.THIEF_ALL],50,RESISTMAGIC)
    HPPercentLT([PC.0.0.THIEF_ALL],40)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",[PC.0.0.THIEF_ALL])  // No such index
        Spell([PC.0.0.THIEF_ALL],WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck([PC.0.0.CLERIC],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.CLERIC],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.CLERIC],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.CLERIC])
    !CheckStatGT([PC.0.0.CLERIC],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.CLERIC],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.CLERIC],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.CLERIC],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.CLERIC],ENEMY)
    !CheckSpellState([PC.0.0.CLERIC],WIZARD_SHIELD)
    OR(2)
        !CheckSpellState([PC.0.0.CLERIC],ITEM_MM_SEEN)
        !CheckSpellState([PC.0.0.CLERIC],ITEM_MM)
    !CheckStatGT([PC.0.0.CLERIC],50,RESISTMAGIC)
    HPPercentLT([PC.0.0.CLERIC],40)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",[PC.0.0.CLERIC])  // No such index
        Spell([PC.0.0.CLERIC],WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck([PC],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC],DO_NOT_TARGET_SPELLS)
    See([PC])
    !CheckStatGT([PC],99,RESISTMAGIC)
    !CheckStatGT([PC],0,MINORGLOBE)
    !CheckStatGT([PC],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC],ENEMY)
    !CheckSpellState([PC],WIZARD_SHIELD)
    OR(2)
        !CheckSpellState([PC],ITEM_MM_SEEN)
        !CheckSpellState([PC],ITEM_MM)
    !CheckStatGT([PC],50,RESISTMAGIC)
    HPPercentLT([PC],40)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",[PC])  // No such index
        Spell([PC],WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck(SecondNearest([PC]),STATE_NOT_TARGETABLE)
    !CheckStatGT(SecondNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(SecondNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(SecondNearest([PC]))
    !CheckStatGT(SecondNearest([PC]),99,RESISTMAGIC)
    !CheckStatGT(SecondNearest([PC]),0,MINORGLOBE)
    !CheckStatGT(SecondNearest([PC]),0,WIZARD_SPELL_TURNING)
    !CheckStatGT(SecondNearest([PC]),0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondNearest([PC]),ENEMY)
    !CheckSpellState(SecondNearest([PC]),WIZARD_SHIELD)
    OR(2)
        !CheckSpellState(SecondNearest([PC]),ITEM_MM_SEEN)
        !CheckSpellState(SecondNearest([PC]),ITEM_MM)
    !CheckStatGT(SecondNearest([PC]),50,RESISTMAGIC)
    HPPercentLT(SecondNearest([PC]),40)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",SecondNearest([PC]))  // No such index
        Spell(SecondNearest([PC]),WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck(ThirdNearest([PC]),STATE_NOT_TARGETABLE)
    !CheckStatGT(ThirdNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(ThirdNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(ThirdNearest([PC]))
    !CheckStatGT(ThirdNearest([PC]),99,RESISTMAGIC)
    !CheckStatGT(ThirdNearest([PC]),0,MINORGLOBE)
    !CheckStatGT(ThirdNearest([PC]),0,WIZARD_SPELL_TURNING)
    !CheckStatGT(ThirdNearest([PC]),0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdNearest([PC]),ENEMY)
    !CheckSpellState(ThirdNearest([PC]),WIZARD_SHIELD)
    OR(2)
        !CheckSpellState(ThirdNearest([PC]),ITEM_MM_SEEN)
        !CheckSpellState(ThirdNearest([PC]),ITEM_MM)
    !CheckStatGT(ThirdNearest([PC]),50,RESISTMAGIC)
    HPPercentLT(ThirdNearest([PC]),40)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",ThirdNearest([PC]))  // No such index
        Spell(ThirdNearest([PC]),WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck([PC.0.0.MAGE],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.MAGE],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.MAGE],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.MAGE])
    !CheckStatGT([PC.0.0.MAGE],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.MAGE],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.MAGE],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.MAGE],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.MAGE],ENEMY)
    !CheckSpellState([PC.0.0.MAGE],WIZARD_SHIELD)
    OR(2)
        !CheckSpellState([PC.0.0.MAGE],ITEM_MM_SEEN)
        !CheckSpellState([PC.0.0.MAGE],ITEM_MM)
    !CheckStatGT([PC.0.0.MAGE],50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",[PC.0.0.MAGE])  // No such index
        Spell([PC.0.0.MAGE],WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck([PC.0.0.MAGE_THIEF],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.MAGE_THIEF],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.MAGE_THIEF],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.MAGE_THIEF])
    !CheckStatGT([PC.0.0.MAGE_THIEF],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.MAGE_THIEF],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.MAGE_THIEF],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.MAGE_THIEF],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.MAGE_THIEF],ENEMY)
    !CheckSpellState([PC.0.0.MAGE_THIEF],WIZARD_SHIELD)
    OR(2)
        !CheckSpellState([PC.0.0.MAGE_THIEF],ITEM_MM_SEEN)
        !CheckSpellState([PC.0.0.MAGE_THIEF],ITEM_MM)
    !CheckStatGT([PC.0.0.MAGE_THIEF],50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",[PC.0.0.MAGE_THIEF])  // No such index
        Spell([PC.0.0.MAGE_THIEF],WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck([PC.0.0.MAGE_ALL],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.MAGE_ALL],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.MAGE_ALL])
    !CheckStatGT([PC.0.0.MAGE_ALL],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.MAGE_ALL],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.MAGE_ALL],ENEMY)
    !CheckSpellState([PC.0.0.MAGE_ALL],WIZARD_SHIELD)
    OR(2)
        !CheckSpellState([PC.0.0.MAGE_ALL],ITEM_MM_SEEN)
        !CheckSpellState([PC.0.0.MAGE_ALL],ITEM_MM)
    !CheckStatGT([PC.0.0.MAGE_ALL],50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",[PC.0.0.MAGE_ALL])  // No such index
        Spell([PC.0.0.MAGE_ALL],WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck([PC.0.0.THIEF],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.THIEF],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.THIEF],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.THIEF])
    !CheckStatGT([PC.0.0.THIEF],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.THIEF],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.THIEF],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.THIEF],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.THIEF],ENEMY)
    !CheckSpellState([PC.0.0.THIEF],WIZARD_SHIELD)
    OR(2)
        !CheckSpellState([PC.0.0.THIEF],ITEM_MM_SEEN)
        !CheckSpellState([PC.0.0.THIEF],ITEM_MM)
    !CheckStatGT([PC.0.0.THIEF],50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",[PC.0.0.THIEF])  // No such index
        Spell([PC.0.0.THIEF],WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck([PC.0.0.BARD],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.BARD],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.BARD],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.BARD])
    !CheckStatGT([PC.0.0.BARD],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.BARD],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.BARD],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.BARD],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.BARD],ENEMY)
    !CheckSpellState([PC.0.0.BARD],WIZARD_SHIELD)
    OR(2)
        !CheckSpellState([PC.0.0.BARD],ITEM_MM_SEEN)
        !CheckSpellState([PC.0.0.BARD],ITEM_MM)
    !CheckStatGT([PC.0.0.BARD],50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",[PC.0.0.BARD])  // No such index
        Spell([PC.0.0.BARD],WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck([PC.0.0.THIEF_ALL],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.THIEF_ALL],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.THIEF_ALL],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.THIEF_ALL])
    !CheckStatGT([PC.0.0.THIEF_ALL],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.THIEF_ALL],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.THIEF_ALL],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.THIEF_ALL],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.THIEF_ALL],ENEMY)
    !CheckSpellState([PC.0.0.THIEF_ALL],WIZARD_SHIELD)
    OR(2)
        !CheckSpellState([PC.0.0.THIEF_ALL],ITEM_MM_SEEN)
        !CheckSpellState([PC.0.0.THIEF_ALL],ITEM_MM)
    !CheckStatGT([PC.0.0.THIEF_ALL],50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",[PC.0.0.THIEF_ALL])  // No such index
        Spell([PC.0.0.THIEF_ALL],WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck([PC.0.0.CLERIC],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC.0.0.CLERIC],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC.0.0.CLERIC],DO_NOT_TARGET_SPELLS)
    See([PC.0.0.CLERIC])
    !CheckStatGT([PC.0.0.CLERIC],99,RESISTMAGIC)
    !CheckStatGT([PC.0.0.CLERIC],0,MINORGLOBE)
    !CheckStatGT([PC.0.0.CLERIC],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC.0.0.CLERIC],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC.0.0.CLERIC],ENEMY)
    !CheckSpellState([PC.0.0.CLERIC],WIZARD_SHIELD)
    OR(2)
        !CheckSpellState([PC.0.0.CLERIC],ITEM_MM_SEEN)
        !CheckSpellState([PC.0.0.CLERIC],ITEM_MM)
    !CheckStatGT([PC.0.0.CLERIC],50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",[PC.0.0.CLERIC])  // No such index
        Spell([PC.0.0.CLERIC],WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck([PC],STATE_NOT_TARGETABLE)
    !CheckStatGT([PC],0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState([PC],DO_NOT_TARGET_SPELLS)
    See([PC])
    !CheckStatGT([PC],99,RESISTMAGIC)
    !CheckStatGT([PC],0,MINORGLOBE)
    !CheckStatGT([PC],0,WIZARD_SPELL_TURNING)
    !CheckStatGT([PC],0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance([PC],ENEMY)
    !CheckSpellState([PC],WIZARD_SHIELD)
    OR(2)
        !CheckSpellState([PC],ITEM_MM_SEEN)
        !CheckSpellState([PC],ITEM_MM)
    !CheckStatGT([PC],50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",[PC])  // No such index
        Spell([PC],WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck(SecondNearest([PC]),STATE_NOT_TARGETABLE)
    !CheckStatGT(SecondNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(SecondNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(SecondNearest([PC]))
    !CheckStatGT(SecondNearest([PC]),99,RESISTMAGIC)
    !CheckStatGT(SecondNearest([PC]),0,MINORGLOBE)
    !CheckStatGT(SecondNearest([PC]),0,WIZARD_SPELL_TURNING)
    !CheckStatGT(SecondNearest([PC]),0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondNearest([PC]),ENEMY)
    !CheckSpellState(SecondNearest([PC]),WIZARD_SHIELD)
    OR(2)
        !CheckSpellState(SecondNearest([PC]),ITEM_MM_SEEN)
        !CheckSpellState(SecondNearest([PC]),ITEM_MM)
    !CheckStatGT(SecondNearest([PC]),50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",SecondNearest([PC]))  // No such index
        Spell(SecondNearest([PC]),WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck(ThirdNearest([PC]),STATE_NOT_TARGETABLE)
    !CheckStatGT(ThirdNearest([PC]),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(ThirdNearest([PC]),DO_NOT_TARGET_SPELLS)
    See(ThirdNearest([PC]))
    !CheckStatGT(ThirdNearest([PC]),99,RESISTMAGIC)
    !CheckStatGT(ThirdNearest([PC]),0,MINORGLOBE)
    !CheckStatGT(ThirdNearest([PC]),0,WIZARD_SPELL_TURNING)
    !CheckStatGT(ThirdNearest([PC]),0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdNearest([PC]),ENEMY)
    !CheckSpellState(ThirdNearest([PC]),WIZARD_SHIELD)
    OR(2)
        !CheckSpellState(ThirdNearest([PC]),ITEM_MM_SEEN)
        !CheckSpellState(ThirdNearest([PC]),ITEM_MM)
    !CheckStatGT(ThirdNearest([PC]),50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",ThirdNearest([PC]))  // No such index
        Spell(ThirdNearest([PC]),WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck(NearestEnemyOf(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(NearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(NearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    See(NearestEnemyOf(Myself))
    !CheckStatGT(NearestEnemyOf(Myself),99,RESISTMAGIC)
    !CheckStatGT(NearestEnemyOf(Myself),0,MINORGLOBE)
    !CheckStatGT(NearestEnemyOf(Myself),0,WIZARD_SPELL_TURNING)
    !CheckStatGT(NearestEnemyOf(Myself),0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance(NearestEnemyOf(Myself),ENEMY)
    !CheckSpellState(NearestEnemyOf(Myself),WIZARD_SHIELD)
    OR(2)
        !CheckSpellState(NearestEnemyOf(Myself),ITEM_MM_SEEN)
        !CheckSpellState(NearestEnemyOf(Myself),ITEM_MM)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",NearestEnemyOf(Myself))  // No such index
        Spell(NearestEnemyOf(Myself),WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck(SecondNearestEnemyOf(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(SecondNearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    See(SecondNearestEnemyOf(Myself))
    !CheckStatGT(SecondNearestEnemyOf(Myself),99,RESISTMAGIC)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,MINORGLOBE)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,WIZARD_SPELL_TURNING)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondNearestEnemyOf(Myself),ENEMY)
    !CheckSpellState(SecondNearestEnemyOf(Myself),WIZARD_SHIELD)
    OR(2)
        !CheckSpellState(SecondNearestEnemyOf(Myself),ITEM_MM_SEEN)
        !CheckSpellState(SecondNearestEnemyOf(Myself),ITEM_MM)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",SecondNearestEnemyOf(Myself))  // No such index
        Spell(SecondNearestEnemyOf(Myself),WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck(ThirdNearestEnemyOf(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(ThirdNearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    See(ThirdNearestEnemyOf(Myself))
    !CheckStatGT(ThirdNearestEnemyOf(Myself),99,RESISTMAGIC)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,MINORGLOBE)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,WIZARD_SPELL_TURNING)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,WIZARD_SPELL_TRAP)
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdNearestEnemyOf(Myself),ENEMY)
    !CheckSpellState(ThirdNearestEnemyOf(Myself),WIZARD_SHIELD)
    OR(2)
        !CheckSpellState(ThirdNearestEnemyOf(Myself),ITEM_MM_SEEN)
        !CheckSpellState(ThirdNearestEnemyOf(Myself),ITEM_MM)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",ThirdNearestEnemyOf(Myself))  // No such index
        Spell(ThirdNearestEnemyOf(Myself),WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    !StateCheck(NearestEnemyOf(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(NearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(NearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    See(NearestEnemyOf(Myself))
    Allegiance(Myself,ENEMY)
    !Allegiance(NearestEnemyOf(Myself),ENEMY)
    !CheckStatGT(NearestEnemyOf(Myself),99,RESISTMAGIC)
    !StateCheck(NearestEnemyOf(Myself),STATE_MIRRORIMAGE)
    !CheckStatGT(NearestEnemyOf(Myself),0,MINORGLOBE)
    OR(2)
        !CheckStat(NearestEnemyOf(Myself),1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT(NearestEnemyOf(Myself),0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",NearestEnemyOf(Myself))
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    !CheckStatGT(NearestEnemyOf(Myself),0,WIZARD_SPELL_TURNING)
    !CheckStatGT(NearestEnemyOf(Myself),0,WIZARD_SPELL_TRAP)
    !CheckStatGT(NearestEnemyOf(Myself),50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(NearestEnemyOf(Myself),WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    !StateCheck(SecondNearestEnemyOf(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(SecondNearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    See(SecondNearestEnemyOf(Myself))
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondNearestEnemyOf(Myself),ENEMY)
    !CheckStatGT(SecondNearestEnemyOf(Myself),99,RESISTMAGIC)
    !StateCheck(SecondNearestEnemyOf(Myself),STATE_MIRRORIMAGE)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,MINORGLOBE)
    OR(2)
        !CheckStat(SecondNearestEnemyOf(Myself),1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT(SecondNearestEnemyOf(Myself),0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",SecondNearestEnemyOf(Myself))
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,WIZARD_SPELL_TURNING)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,WIZARD_SPELL_TRAP)
    !CheckStatGT(SecondNearestEnemyOf(Myself),50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(SecondNearestEnemyOf(Myself),WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    !StateCheck(ThirdNearestEnemyOf(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(ThirdNearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    See(ThirdNearestEnemyOf(Myself))
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdNearestEnemyOf(Myself),ENEMY)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),99,RESISTMAGIC)
    !StateCheck(ThirdNearestEnemyOf(Myself),STATE_MIRRORIMAGE)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,MINORGLOBE)
    OR(2)
        !CheckStat(ThirdNearestEnemyOf(Myself),1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT(ThirdNearestEnemyOf(Myself),0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",ThirdNearestEnemyOf(Myself))
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,WIZARD_SPELL_TURNING)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,WIZARD_SPELL_TRAP)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),50,RESISTMAGIC)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(ThirdNearestEnemyOf(Myself),WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    !StateCheck(NearestEnemyOf(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(NearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(NearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    See(NearestEnemyOf(Myself))
    Allegiance(Myself,ENEMY)
    !Allegiance(NearestEnemyOf(Myself),ENEMY)
    !CheckStatGT(NearestEnemyOf(Myself),99,RESISTMAGIC)
    !StateCheck(NearestEnemyOf(Myself),STATE_MIRRORIMAGE)
    !CheckStatGT(NearestEnemyOf(Myself),0,MINORGLOBE)
    OR(2)
        !CheckStat(NearestEnemyOf(Myself),1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT(NearestEnemyOf(Myself),0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",NearestEnemyOf(Myself))
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    !CheckStatGT(NearestEnemyOf(Myself),0,WIZARD_SPELL_TURNING)
    !CheckStatGT(NearestEnemyOf(Myself),0,WIZARD_SPELL_TRAP)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(NearestEnemyOf(Myself),WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    !StateCheck(SecondNearestEnemyOf(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(SecondNearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    See(SecondNearestEnemyOf(Myself))
    Allegiance(Myself,ENEMY)
    !Allegiance(SecondNearestEnemyOf(Myself),ENEMY)
    !CheckStatGT(SecondNearestEnemyOf(Myself),99,RESISTMAGIC)
    !StateCheck(SecondNearestEnemyOf(Myself),STATE_MIRRORIMAGE)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,MINORGLOBE)
    OR(2)
        !CheckStat(SecondNearestEnemyOf(Myself),1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT(SecondNearestEnemyOf(Myself),0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",SecondNearestEnemyOf(Myself))
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,WIZARD_SPELL_TURNING)
    !CheckStatGT(SecondNearestEnemyOf(Myself),0,WIZARD_SPELL_TRAP)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(SecondNearestEnemyOf(Myself),WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    !StateCheck(ThirdNearestEnemyOf(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(ThirdNearestEnemyOf(Myself),DO_NOT_TARGET_SPELLS)
    See(ThirdNearestEnemyOf(Myself))
    Allegiance(Myself,ENEMY)
    !Allegiance(ThirdNearestEnemyOf(Myself),ENEMY)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),99,RESISTMAGIC)
    !StateCheck(ThirdNearestEnemyOf(Myself),STATE_MIRRORIMAGE)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,MINORGLOBE)
    OR(2)
        !CheckStat(ThirdNearestEnemyOf(Myself),1,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !CheckStatGT(ThirdNearestEnemyOf(Myself),0,CLERIC_PHYSICAL_MIRROR)
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    OR(2)
        !HasItemEquiped("shld24",ThirdNearestEnemyOf(Myself))
        GlobalTimerNotExpired("DMWWseePNM","LOCALS")
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,WIZARD_SPELL_TURNING)
    !CheckStatGT(ThirdNearestEnemyOf(Myself),0,WIZARD_SPELL_TRAP)
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(ThirdNearestEnemyOf(Myself),WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    !StateCheck(Player6,STATE_NOT_TARGETABLE)
    !CheckStatGT(Player6,0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(Player6,DO_NOT_TARGET_SPELLS)
    Allegiance(Myself,ENEMY)
    !CheckStatGT(Player6,99,RESISTMAGIC)
    !CheckStatGT(Player6,0,MINORGLOBE)
    OR(2)
        !Allegiance(Player6,ENEMY)
        StateCheck(Player6,STATE_CHARMED)
    See(Player6)
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    !StateCheck(Player5,STATE_NOT_TARGETABLE)
    !CheckStatGT(Player5,0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(Player5,DO_NOT_TARGET_SPELLS)
    Allegiance(Myself,ENEMY)
    !CheckStatGT(Player5,99,RESISTMAGIC)
    !CheckStatGT(Player5,0,MINORGLOBE)
    OR(2)
        !Allegiance(Player5,ENEMY)
        StateCheck(Player5,STATE_CHARMED)
    See(Player5)
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    !StateCheck(Player4,STATE_NOT_TARGETABLE)
    !CheckStatGT(Player4,0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(Player4,DO_NOT_TARGET_SPELLS)
    Allegiance(Myself,ENEMY)
    !CheckStatGT(Player4,99,RESISTMAGIC)
    !CheckStatGT(Player4,0,MINORGLOBE)
    OR(2)
        !Allegiance(Player4,ENEMY)
        StateCheck(Player4,STATE_CHARMED)
    See(Player4)
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    !StateCheck(Player3,STATE_NOT_TARGETABLE)
    !CheckStatGT(Player3,0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(Player3,DO_NOT_TARGET_SPELLS)
    Allegiance(Myself,ENEMY)
    !CheckStatGT(Player3,99,RESISTMAGIC)
    !CheckStatGT(Player3,0,MINORGLOBE)
    OR(2)
        !Allegiance(Player3,ENEMY)
        StateCheck(Player3,STATE_CHARMED)
    See(Player3)
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    !StateCheck(Player2,STATE_NOT_TARGETABLE)
    !CheckStatGT(Player2,0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(Player2,DO_NOT_TARGET_SPELLS)
    Allegiance(Myself,ENEMY)
    !CheckStatGT(Player2,99,RESISTMAGIC)
    !CheckStatGT(Player2,0,MINORGLOBE)
    OR(2)
        !Allegiance(Player2,ENEMY)
        StateCheck(Player2,STATE_CHARMED)
    See(Player2)
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    !StateCheck(Player1,STATE_NOT_TARGETABLE)
    !CheckStatGT(Player1,0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(Player1,DO_NOT_TARGET_SPELLS)
    Allegiance(Myself,ENEMY)
    !CheckStatGT(Player1,99,RESISTMAGIC)
    !CheckStatGT(Player1,0,MINORGLOBE)
    OR(2)
        !Allegiance(Player1,ENEMY)
        StateCheck(Player1,STATE_CHARMED)
    See(Player1)
    False()
THEN
    RESPONSE #100
        Continue()
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
    !StateCheck(LastSeenBy(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(LastSeenBy(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(LastSeenBy(Myself),DO_NOT_TARGET_SPELLS)
    Allegiance(Myself,ENEMY)
    !CheckStatGT(LastSeenBy(Myself),99,RESISTMAGIC)
    !CheckStatGT(LastSeenBy(Myself),0,MINORGLOBE)
    OR(2)
        !Allegiance(LastSeenBy(Myself),ENEMY)
        StateCheck(LastSeenBy(Myself),STATE_CHARMED)
    See(LastSeenBy(Myself))
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(LastSeenBy(Myself),WIZARD_MELF_ACID_ARROW)  // SPWI211.SPL (Melf's Acid Arrow)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
    !StateCheck(LastSeenBy(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(LastSeenBy(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(LastSeenBy(Myself),DO_NOT_TARGET_SPELLS)
    Allegiance(Myself,ENEMY)
    !CheckStatGT(LastSeenBy(Myself),99,RESISTMAGIC)
    !CheckStatGT(LastSeenBy(Myself),0,MINORGLOBE)
    OR(2)
        !Allegiance(LastSeenBy(Myself),ENEMY)
        StateCheck(LastSeenBy(Myself),STATE_CHARMED)
    See(LastSeenBy(Myself))
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        Spell(LastSeenBy(Myself),WIZARD_CHROMATIC_ORB)  // SPWI118.SPL (Chromatic Orb)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    HaveSpell(WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
    !StateCheck(LastSeenBy(Myself),STATE_NOT_TARGETABLE)
    !CheckStatGT(LastSeenBy(Myself),0,SANCTUARY)
    CheckStatLT(Myself,60,SPELLFAILUREMAGE)
    !CheckSpellState(LastSeenBy(Myself),DO_NOT_TARGET_SPELLS)
    Allegiance(Myself,ENEMY)
    !CheckStatGT(LastSeenBy(Myself),99,RESISTMAGIC)
    !CheckStatGT(LastSeenBy(Myself),0,MINORGLOBE)
    OR(2)
        !Allegiance(LastSeenBy(Myself),ENEMY)
        StateCheck(LastSeenBy(Myself),STATE_CHARMED)
    See(LastSeenBy(Myself))
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
        ApplySpellRES("dw#mmsee",LastSeenBy(Myself))  // No such index
        Spell(LastSeenBy(Myself),WIZARD_MAGIC_MISSILE)  // SPWI112.SPL (Magic Missile)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    !GlobalTimerNotExpired("targetcompromise","LOCALS")
    See(NearestEnemyOf(Myself))
THEN
    RESPONSE #100
        SetGlobalTimer("targetcompromise","LOCALS",ONE_ROUND)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    See(NearestEnemyOf(Myself))
    OR(2)
        Class(Myself,MAGE)
        Class(Myself,MAGE_THIEF)
    OR(3)
        !See(Player1)
        StateCheck(Player1,STATE_IMMOBILE)
        CheckStatGT(Player1,0,HELD)
    OR(3)
        !See(Player2)
        StateCheck(Player2,STATE_IMMOBILE)
        CheckStatGT(Player2,0,HELD)
    OR(3)
        !See(Player3)
        StateCheck(Player3,STATE_IMMOBILE)
        CheckStatGT(Player3,0,HELD)
    OR(3)
        !See(Player4)
        StateCheck(Player4,STATE_IMMOBILE)
        CheckStatGT(Player4,0,HELD)
    OR(3)
        !See(Player5)
        StateCheck(Player5,STATE_IMMOBILE)
        CheckStatGT(Player5,0,HELD)
    OR(3)
        !See(Player6)
        StateCheck(Player6,STATE_IMMOBILE)
        CheckStatGT(Player6,0,HELD)
THEN
    RESPONSE #100
        AttackReevaluate(NearestEnemyOf(Myself),15)
END

IF
    !GlobalTimerNotExpired("castspell","LOCALS")
    See(NearestEnemyOf(Myself))
THEN
    RESPONSE #100
        SetGlobalTimer("castspell","LOCALS",ONE_ROUND)
END

IF
    ActionListEmpty()
THEN
    RESPONSE #100
        NoAction()
END
 
Joined
May 4, 2017
Messages
631
I came back after a long hiatus and I don't know if people have actually turned retarded in this board all together or something weird is in the air that actually makes you not think straight.


+++++++++++++++
First of all, SCS shouldn't be recommended for a first timer. I plaud (it's irony if you didn't catch it) over the fact that you people say

'HEY MEIT PLIS ITZ DE WEI IT IS MENT TU BI PLEIED END IF YIU DISAGRI YU SAC'

It's a mod where you have to powerplay. Forget about RP with a mod such as this one - for example, if you roleplay, how would you justify a good <charname> entering houses uninvited, after lockpicking their doors? So no helm of balduran for you mate. And there are a tons of example.

You want another? Open Baldur's gate 2, start a new campaign. You see what happened to Imoen ? Ow yes if you are good you are going to go to spellhold as fast as possible, and no, you don't need much time to get 15k given that all you have to do is

> Do Kalah's quest (free the circus)
> Survive the first ambush (the one with the short sword with free action)
> Free only hendak and get the money from the body of Lehtinan.

Well you got your 15k, without even having to do one single 10k quest.

So.... What about an evil charname? Maybe an evil charname is justified in waiting because he simply doesn't give a fuck about Imoen, but that's up to you.
++++++++++++++

Good you are now in spellhold. You see what you got? Ah you got level 9 characters facing so many different and hard creatures that you will regret coming there so early. Oh what are you saying? You got a class for that? Ah that's good, hopefully you didn't pick it just for this reason... because SCS removes all your equipment when you go to Spellhold


++++++++++++++++

So you're telling me you like SCS? Ah, I get that every mage you face always cast the same contingencies, the same spells, and you read every time always the same spells, provided that the guy you are currently facing is the same level of the other guys you will be facing?
Funny, isn't it?

+++++++++++++

Wait, so you're telling me that it is cool that SCS makes the enemy actually detect your resistance? So for example, you've got a barbarian and don't worry, no thieves in your next 100 hours of gaming will actually try to backstab you. Because you know, SCS gives him prescience and he knows he can't backstab you because you are immune. They won't even try once, you know, for "immersion" reason.

oh and you are not immune to backstab but you still have a fighter with High DR? Don't you know that SCS makes the enemies read your resistances so they won't aim for you? Forget about warriors focusing your barbarian. They know he has DR, they won't aim for him.


Do I have to add other things? Because I've got a list of 100 different things more that could be added.
 
Last edited:

Lacrymas

Arcane
Joined
Sep 23, 2015
Messages
18,001
Pathfinder: Wrath
You don't need to minmax to beat SCS. People are doing it even solo (with a minmaxed char, but that's different, if you can do it solo, you can do with a non-optimal party). It's kinda weird you won't go for the Helm of Balduran on any character just because of how powerful it is, but trust me, you don't NEED it for SCS. If you HAD to minmax, only evil parties would be viable in BG1, but that's just not the case.
 

Chippy

Arcane
Patron
Joined
May 5, 2018
Messages
6,066
Steve gets a Kidney but I don't even get a tag.
I came back after a long hiatus and I don't know if people have actually turned retarded in this board all together or something weird is in the air that actually makes you not think straight.


+++++++++++++++
First of all, SCS shouldn't be recommended for a first timer. I plaud (it's irony if you didn't catch it) over the fact that you people say

'HEY MEIT PLIS ITZ DE WEI IT IS MENT TU BI PLEIED END IF YIU DISAGRI YU SAC'

It's a mod where you have to powerplay. Forget about RP with a mod such as this one - for example, if you roleplay, how would you justify a good <charname> entering houses uninvited, after lockpicking their doors? So no helm of balduran for you mate. And there are a tons of example.

You want another? Open Baldur's gate 2, start a new campaign. You see what happened to Imoen ? Ow yes if you are good you are going to go to spellhold as fast as possible, and no, you don't need much time to get 15k given that all you have to do is

> Do Kalah's quest (free the circus)
> Survive the first ambush (the one with the short sword with free action)
> Free only hendak and get the money from the body of Lehtinan.

Well you got your 15k, without even having to do one single 10k quest.

So.... What about an evil charname? Maybe an evil charname is justified in waiting because he simply doesn't give a fuck about Imoen, but that's up to you.
++++++++++++++

Good you are now in spellhold. You see what you got? Ah you got level 9 characters facing so many different and hard creatures that you will regret coming there so early. Oh what are you saying? You got a class for that? Ah that's good, hopefully you didn't pick it just for this reason... because SCS removes all your equipment when you go to Spellhold


++++++++++++++++

So you're telling me you like SCS? Ah, I get that every mage you face always cast the same contingencies, the same spells, and you read every time always the same spells, provided that the guy you are currently facing is the same level of the other guys you will be facing?
Funny, isn't it?

+++++++++++++

Wait, so you're telling me that it is cool that SCS makes the enemy actually detect your resistance? So for example, you've got a barbarian and don't worry, no thieves in your next 100 hours of gaming will actually try to backstab you. Because you know, SCS gives him prescience and he knows he can't backstab you because you are immune. They won't even try once, you know, for "immersion" reason.

oh and you are not immune to backstab but you still have a fighter with High DR? Don't you know that SCS makes the enemies read your resistances so they won't aim for you? Forget about warriors focusing your barbarian. They know he has DR, they won't aim for him.


Do I have to add other things? Because I've got a list of 100 different things more that could be added.

Not that I want to be a dick, but I always hated mods (only played the Drizzt ones recently because of Lilura) but the SCS readme specifically states that it doesn't cheat. And I always planned on installing it one day (maybe in another 20 or so years) yet reading your post, it seems to me that it does cheat. It seems to me that it just introduces rock-paper-scissors...not tactics.
 
Joined
May 4, 2017
Messages
631
Lacrymas I'm sorry, but I'm not sure I agree with you.
I won't go for helm of balduran because I've got a good charname and I don't go inside houses uninvited. There are maybe a couple of quests I do in baldur's gate city (most content of Baldur's gate city is behind closed doors that I won't lockpick). Boogey man quest is an example.

Anyway you see, you say "helm of balduran is too good". You guess where this is going?

Your example with solo is not a good example. I played Solo no reload baldur's gate (finished successfully) with a barbarian, and it is way way easier than having a party. You have to think about a single character, give him the best equipment he can get (bonus points if you don't roleplay), and generally be ready (in the sense that you have to know what you're going to face next, usually with potions, either the amulet of kazgaroth and the amulet of shield you buy in Nashkel's carnival).

Get an ambush from any of the Assassins when you are low level and you've got Xzar in your team. They will all use bows and aim automatically for him, ignoring your warrior. And there are no contingencies. Maybe there is the possibility to use a potion of invisibility, but is that the definition of "fun"? Having characters that will always adopt the best decision based on data that are not available to the player because the player can't simply know that the person he is facing is a barbarian (immune to backstab and high DR), etc etc.

Another note (unrelated)
What about BG2? Things get harder in BG2 initially, but in underdark if you keep going solo you'll be level 40. And this is without you actually "giving" yourself the experience you deserve. What am I referring to? If you play with a party after finishing a quest every member of the party gets his share of xp. When going solo, I actually recommend people to give themselves the 6*xp. They deserve it.

Solo will start to turn shitty in the endgame, provided that you don't have a dual class or why not, a multi-class with level uncapper.

And playing high level baldur's gate doesn't necessarily mean that it is fun for the player. Especially because it doesn't help immersion (at least for me) seeing these mages starting with contingencies every time I face one.

Chippy The ai in vanilla baldur's gate is pretty bad, that's for sure. My suggestion is, if you wish to play Baldur's gate with improved AI to go for questpack's ai. http://mods.pocketplane.net/d0questpack_v3readme.htm
 
Last edited:

Cael

Arcane
Joined
Nov 1, 2017
Messages
20,522
Another note (unrelated)
What about BG2? Things get harder in BG2 initially, but in underdark if you keep going solo you'll be level 40. And this is without you actually "giving" yourself the experience you deserve. What am I referring to? If you play with a party after finishing a quest every member of the party gets his share of xp. When going solo, I actually recommend people to give themselves the 6*xp. They deserve it.

Solo will start to turn shitty in the endgame, provided that you don't have a dual class or why not, a multi-class with level uncapper.

And playing high level baldur's gate doesn't necessarily mean that it is fun for the player. Especially because it doesn't help immersion (at least for me) seeing these mages starting with contingencies every time I face one.
You do get 6*XP if you play solo when compared to a full party. That is basic BG...
 

Bester

⚰️☠️⚱️
Patron
Vatnik
Joined
Sep 28, 2014
Messages
11,101
Location
USSR
Comparison of the AI script for the BG1 Act 4 boss(Davaeorn) in vanilla vs Sword Coast Stratagems.
That long script looks extremely bug prone. It's most likely broken in more than one place.

That's why they use behavior trees, hfsm and other modern patterns for AI now. Can't make any elaborate AI just using a bunch of if-elses.

I played with SCS a couple of years ago and a lot of boss fights were just outright broken. They most likely still are.
 
Joined
Jan 14, 2018
Messages
50,754
Codex Year of the Donut
Comparison of the AI script for the BG1 Act 4 boss(Davaeorn) in vanilla vs Sword Coast Stratagems.
That long script looks extremely bug prone. It's most likely broken in more than one place.
:lol:
It looks like that because the author writes it in a separate language and compiles it to the IE scripting language. That's like complaining the assembly output of a modern C compiler is nigh unreadable — because it's not meant for you to read.

That's why they use behavior trees, hfsm and other modern patterns for AI now. Can't make any elaborate AI just using a bunch of if-elses.
A behavior tree is a model of computation, there's thing stopping someone from implementing behavior trees as a massive amount of conditionals. That's like saying you can't implement a finite state machine with a bunch of conditional statements -- after all, behavior trees are just a variation(& generalization) of a specific kind of FSM(HFSM.)
 

Lacrymas

Arcane
Joined
Sep 23, 2015
Messages
18,001
Pathfinder: Wrath
Anomander Rake, I didn't say it's too good, I said it isn't mandatory. The whole idea is that you CAN complete SCS with a good party, which is quite suboptimal with the exception of Coran. And the helm isn't in a private house either way, it was stolen and kept in a secret safe in the inn, it's very easy to justify breaking into the safe if you are into that sort of thing.
 
Joined
Jan 14, 2018
Messages
50,754
Codex Year of the Donut
oh and you are not immune to backstab but you still have a fighter with High DR? Don't you know that SCS makes the enemies read your resistances so they won't aim for you? Forget about warriors focusing your barbarian. They know he has DR, they won't aim for him.
I'm just imagining an enemy looking at a massive barbarian and then at a mage wearing a dress and thinking "wow, I should definitely stop and go toe to toe with the barbarian!"
Are you mentally challenged?
 

Yosharian

Arcane
Joined
May 28, 2018
Messages
9,492
Location
Grand Chien
You don't need to minmax to beat SCS. People are doing it even solo (with a minmaxed char, but that's different, if you can do it solo, you can do with a non-optimal party). It's kinda weird you won't go for the Helm of Balduran on any character just because of how powerful it is, but trust me, you don't NEED it for SCS. If you HAD to minmax, only evil parties would be viable in BG1, but that's just not the case.
You're off your ladder mate. People playing BG2 for the first time need all the help they can get. AD&D is crazy complicated for someone who's new to it.
 
Joined
Jan 14, 2018
Messages
50,754
Codex Year of the Donut
You don't need to minmax to beat SCS. People are doing it even solo (with a minmaxed char, but that's different, if you can do it solo, you can do with a non-optimal party). It's kinda weird you won't go for the Helm of Balduran on any character just because of how powerful it is, but trust me, you don't NEED it for SCS. If you HAD to minmax, only evil parties would be viable in BG1, but that's just not the case.
You're off your ladder mate. People playing BG2 for the first time need all the help they can get. AD&D is crazy complicated for someone who's new to it.
Nobody is suggesting to install SCS for first time players, but if you do you can just turn the difficulty down.
https://www.gibberlings3.net/forums/topic/29759-scs-v32-and-the-difficulty-slider/
SCS relabels the five difficulty modes as BASIC, IMPROVED, TACTICAL, HARDCORE and INSANE. They have in-game descriptions, but roughly speaking:



- BASIC is roughly equal to the original game's AI, with a few rough corners smoothed off.

- IMPROVED is SCS-lite: most of SCS's intelligence, but a lot of restraint as to what powers and spells get used

- TACTICAL is SCS v30 towards the lower end of its difficulty settings: some but not too much prebuffing, no extra hit points for dragons, etc

- HARDCORE is around what a full install of SCS v30 looks like (and is roughly my own preferred difficulty)

- INSANE is pretty much a full-on no-holds-barred install of SCSv30, including options that I don't really use myself
 
Joined
Jan 14, 2018
Messages
50,754
Codex Year of the Donut
Ah ok, so that's what call for help means. They don't actually call in more enemies, they just move as a mob.

(1) Any creature shouts when it sees you. Any creature of the same faction that hears that shout will move towards the party.

(2) For intelligent creatures (e.g., gnolls, hobgoblins - but not spiders or skeletons) any creature that hears a shout will give a differently coded shout. Any same-faction creature that hears the differently-coded shout will move towards the party, but won't shout in turn.

There are also some range subtleties. The idea is that if you run into unintelligent creatures, the whole group will attack you; if you run into intelligent creatures, the whole group and any other groups in earshot will attack you; but you won't have the whole map descend on you. (In very rare cases - notably the bandit camp - 'the whole map descends on you' is intended behavior: in those cases, anyone who sees you will call for help, anyone hearing that call will call in the same way, and so on.)
 

Yosharian

Arcane
Joined
May 28, 2018
Messages
9,492
Location
Grand Chien
You don't need to minmax to beat SCS. People are doing it even solo (with a minmaxed char, but that's different, if you can do it solo, you can do with a non-optimal party). It's kinda weird you won't go for the Helm of Balduran on any character just because of how powerful it is, but trust me, you don't NEED it for SCS. If you HAD to minmax, only evil parties would be viable in BG1, but that's just not the case.
You're off your ladder mate. People playing BG2 for the first time need all the help they can get. AD&D is crazy complicated for someone who's new to it.
Nobody is suggesting to install SCS for first time players, but if you do you can just turn the difficulty down.
Really? Nobody is suggesting it? I must have imagined it when I saw Lacrymas say this, then:

RE: mods, SCS is a must for BG2, even on a first playthrough, I played it first without it and I regret it.
This comment is the entire fucking reason that we're discussing SCS in the first place!
 

Lacrymas

Arcane
Joined
Sep 23, 2015
Messages
18,001
Pathfinder: Wrath
If you've never played RPGs before, obviously don't go for SCS, but you wouldn't be on this site and reading that comment either.
 

smaug

Secular Koranism with Israeli Characteristics
Patron
Dumbfuck
Joined
Feb 20, 2019
Messages
6,518
Location
Texas
Insert Title Here
I’m playing Vanilla BG I kind of want to play with SCS. Should I download BGT, along with it?
 

As an Amazon Associate, rpgcodex.net earns from qualifying purchases.
Back
Top Bottom