IF
        Global("RU_STAGE_OVER","GLOBAL",1)
THEN
	RESPONSE #100
                ReallyForceSpellRES("ru_disap",Myself)
                Wait(2)
                DestroySelf()
END

IF
        OR(8)
         StateCheck(NearestEnemyOf(Myself),STATE_INVISIBLE)
         StateCheck(NearestEnemyOf(Myself),STATE_IMPROVEDINVISIBILITY)
         StateCheck(SecondNearestEnemyOf(Myself),STATE_INVISIBLE)
         StateCheck(SecondNearestEnemyOf(Myself),STATE_IMPROVEDINVISIBILITY)
         StateCheck(ThirdNearestEnemyOf(Myself),STATE_INVISIBLE)
         StateCheck(ThirdNearestEnemyOf(Myself),STATE_IMPROVEDINVISIBILITY)
         StateCheck(FourthNearestEnemyOf(Myself),STATE_INVISIBLE)
         StateCheck(FourthNearestEnemyOf(Myself),STATE_IMPROVEDINVISIBILITY)
        Global("TrueSight","LOCALS",0)
        CheckStat(Myself,0,TRUE_SIGHT)
THEN
	RESPONSE #100
                SetGlobal("TrueSight","LOCALS",1)
                DisplayString(Myself,@272)
                ReallyForceSpell(Myself,WIZARD_TRUE_SIGHT)
END

IF
        OR(8)
         StateCheck(NearestEnemyOf(Myself),STATE_INVISIBLE)
         StateCheck(NearestEnemyOf(Myself),STATE_IMPROVEDINVISIBILITY)
         StateCheck(SecondNearestEnemyOf(Myself),STATE_INVISIBLE)
         StateCheck(SecondNearestEnemyOf(Myself),STATE_IMPROVEDINVISIBILITY)
         StateCheck(ThirdNearestEnemyOf(Myself),STATE_INVISIBLE)
         StateCheck(ThirdNearestEnemyOf(Myself),STATE_IMPROVEDINVISIBILITY)
         StateCheck(FourthNearestEnemyOf(Myself),STATE_INVISIBLE)
         StateCheck(FourthNearestEnemyOf(Myself),STATE_IMPROVEDINVISIBILITY)
        CheckStat(Myself,0,TRUE_SIGHT)
        Global("DetectInvisibility","LOCALS",0)
THEN
	RESPONSE #100
                SetGlobal("DetectInvisibility","LOCALS",1)
                DisplayString(Myself,@273)
                ReallyForceSpell(Myself,WIZARD_DETECT_INVISIBILITY)
END

IF
        Global("Type","LOCALS",1)
THEN
	RESPONSE #100
                SetGlobal("Type","LOCALS",0)
END

IF
        Global("Contingency","LOCALS",0)
        !CheckStat(Myself,4,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
        HitBy(Myself,0) 
THEN
	RESPONSE #100
                SetGlobal("Contingency","LOCALS",1)
                DisplayString(Myself,@274)
                ApplySpell(Myself,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
END

IF
        HPPercentLT(Myself,50)
        Global("ChainContingency","LOCALS",0)
THEN
	RESPONSE #100
                SetGlobal("ChainContingency","LOCALS",1)
                DisplayString(Myself,@275)
                ApplySpell(Myself,WIZARD_SPELL_IMMUNITY_CONJURATION)
                ApplySpell(Myself,WIZARD_SPELL_IMMUNITY_INVOCATION)
                ApplySpell(Myself,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
                Continue()
END

IF
        Global("SilverFire","LOCALS",0)
        HPPercentLT(Myself,50)
        See(TenthNearestEnemyOf(Myself))
THEN
	RESPONSE #100
                SetGlobal("SilverFire","LOCALS",1)
                DisplayString(Myself,@276)
                ReallyForceSpellRES("ru_silve",TenthNearestEnemyOf(Myself)) // 실버파이어
END

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

IF
        See([ENEMY])
THEN
	RESPONSE #100
                Continue()
END

IF
        Global("Type","LOCALS",0)
        LevelGT(LastSeenBy(Myself),15)
THEN
	RESPONSE #100
                SetGlobal("Type","LOCALS",1)
                Continue()
END

IF
        HaveSpell(WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
        OR(2)
         !CheckStatGT(Myself,0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
         Global("Type","LOCALS",1)
        See(NearestEnemyOf(Myself))
        CheckStat(Myself,0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
THEN
	RESPONSE #100
                Spell(Myself,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
END

IF
        HaveSpell(WIZARD_SPELL_SHIELD)
        See(NearestEnemyOf(Myself))
        CheckStat(Myself,0,WIZARD_SPELL_SHIELD)
THEN
	RESPONSE #100
                Spell(Myself,WIZARD_SPELL_SHIELD)
END

IF
        HaveSpell(WIZARD_IMPROVED_INVISIBILITY)
        See(NearestEnemyOf(Myself))
        !StateCheck(Myself,STATE_IMPROVEDINVISIBILITY)
THEN
	RESPONSE #100
                Spell(Myself,WIZARD_IMPROVED_INVISIBILITY)
END

IF
        GlobalLT("SID","LOCALS",1)
        See(NearestEnemyOf(Myself))
        OR(2)
         StateCheck(Myself,STATE_IMPROVEDINVISIBILITY)
         CheckStatGT(Myself,0,WIZARD_MISLEAD)
THEN
	RESPONSE #100
                IncrementGlobal("SID","LOCALS",1)
                Spell(Myself,WIZARD_SPELL_IMMUNITY_DIVINATION)
END

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

IF
        HaveSpell(WIZARD_PROTECTION_FROM_THE_ELEMENTS)
        See(NearestEnemyOf(Myself))
        OR(2)
         CheckStatLT(Myself,75,14)
         CheckStatLT(Myself,75,15)
THEN
	RESPONSE #100
                Spell(Myself,WIZARD_PROTECTION_FROM_THE_ELEMENTS)
END

IF
        HaveSpell(WIZARD_PROTECTION_FROM_ENERGY)
        See(NearestEnemyOf(Myself))
        OR(2)
         CheckStatLT(Myself,75,14)
         CheckStatLT(Myself,75,15)
THEN
	RESPONSE #100
                Spell(Myself,WIZARD_PROTECTION_FROM_ENERGY)
END

IF
        HaveSpellRES("SPPR210")
        See(NearestEnemyOf(Myself))
        OR(2)
         CheckStatLT(Myself,100,14)
         CheckStatLT(Myself,100,15)
THEN
	RESPONSE #100
                SpellRES("SPPR210",Myself)
END

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

IF
        HaveSpell(WIZARD_PROTECTION_FROM_MAGIC_ENERGY)
        See(NearestEnemyOf(Myself))
        CheckStatLT(Myself,100,73)
THEN
	RESPONSE #100
                Spell(Myself,WIZARD_PROTECTION_FROM_MAGIC_ENERGY)
END


IF
        HaveSpell(WIZARD_STONE_SKIN)
        See(NearestEnemyOf(Myself))
        CheckStat(Myself,0,STONESKINS)
THEN
	RESPONSE #100
                Spell(Myself,WIZARD_STONE_SKIN)
END

IF
        HaveSpell(WIZARD_SPELL_TURNING)
        OR(2)
         See([ENEMY.0.0.MAGE_ALL])
         See([ENEMY.0.0.CLERIC_ALL])
        CheckStat(Myself,0,WIZARD_SPELL_TURNING)
THEN
	RESPONSE #100
                Spell(Myself,WIZARD_SPELL_TURNING)
END

IF
        HaveSpell(WIZARD_MIRROR_IMAGE)
        See(NearestEnemyOf(Myself))
        OR(2)
         CheckStat(Myself,0,STONESKINS)
         Global("Type","LOCALS",1)
        !StateCheck(Myself,STATE_MIRRORIMAGE)
THEN
	RESPONSE #100
                Spell(Myself,WIZARD_MIRROR_IMAGE)
END

IF
        HaveSpell(WIZARD_SPIRIT_ARMOR)
        See(NearestEnemyOf(Myself))
        OR(3)
         CheckStat(Myself,0,STONESKINS)
         !StateCheck(Myself,STATE_MIRRORIMAGE)
         Global("Type","LOCALS",1)
THEN
	RESPONSE #100
                Spell(Myself,WIZARD_SPIRIT_ARMOR)
END

IF
        HaveSpell(CLERIC_PROTECT_FROM_EVIL)
        See(NearestEnemyOf(Myself))
        CheckStat(Myself,0,PROTECTION_FROM_EVIL)
        Global("Type","LOCALS",1)
THEN
	RESPONSE #100
                Spell(Myself,CLERIC_PROTECT_FROM_EVIL)
END

IF
        HaveSpell(WIZARD_BLUR)
        See(NearestEnemyOf(Myself))
        Global("Type","LOCALS",1)
        !StateCheck(Myself,STATE_BLUR)
THEN
	RESPONSE #100
                Spell(Myself,WIZARD_BLUR)
END

IF
        See([ENEMY.0.0.0.0.SUMMONED])
THEN
	RESPONSE #100
		Continue()
END

IF
        HaveSpell(WIZARD_DEATH_SPELL)
        NumCreatureGT(LastSeenBy(Myself),2)
	Gender(LastSeenBy(Myself),SUMMONED)
        NumCreature([ALLY.0.0.0.0.SUMMONED],0)
THEN
	RESPONSE #100
                Spell(LastSeenBy(Myself),WIZARD_DEATH_SPELL)
END

IF
	!See(NearestEnemyOf(Myself))
THEN
	RESPONSE #100
		NoAction()
END

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

IF
	NumCreatureGT([ENEMY],1)
	See(SecondNearestEnemyOf(Myself))
        RandomNum(2,1)
THEN
	RESPONSE #100
		Continue()
END

IF
	NumCreatureGT([ENEMY],2)
	See(ThirdNearestEnemyOf(Myself))
        RandomNum(2,1)
THEN
	RESPONSE #100
		Continue()
END

IF
	NumCreatureGT([ENEMY],3)
	See(FourthNearestEnemyOf(Myself))
        RandomNum(2,1)
THEN
	RESPONSE #100
		Continue()
END

IF
	NumCreatureGT([ENEMY],4)
	See(FifthNearestEnemyOf(Myself))
        RandomNum(2,1)
THEN
	RESPONSE #100
		Continue()
END

IF
	NumCreatureGT([ENEMY],5)
	See(SixthNearestEnemyOf(Myself))
        RandomNum(2,1)
THEN
	RESPONSE #100
		Continue()
END

IF
        Global("Type","LOCALS",0)
        LevelGT(LastSeenBy(Myself),15)
THEN
	RESPONSE #100
                SetGlobal("Type","LOCALS",1)
                Continue()
END

IF
        GlobalLT("DB","LOCALS",2)
        LevelGT(LastSeenBy(Myself),15)
        CheckStatLT(LastSeenBy(Myself),50,RESISTPOISON)
THEN
	RESPONSE #100
                IncrementGlobal("DB","LOCALS",1)
                ForceSpellRES("ru_dragp",LastSeenBy(Myself))
                DisplayString(Myself,@277)
                Continue()
END

IF
        GlobalLT("DB","LOCALS",2)
        LevelGT(LastSeenBy(Myself),15)
        CheckStatLT(LastSeenBy(Myself),50,RESISTACID)
THEN
	RESPONSE #100
                IncrementGlobal("DB","LOCALS",1)
                ForceSpellRES("ru_draga",LastSeenBy(Myself))
                DisplayString(Myself,@277)
                Continue()
END

IF
        GlobalLT("DB","LOCALS",2)
        LevelGT(LastSeenBy(Myself),15)
        CheckStatLT(LastSeenBy(Myself),50,MAGICDAMAGERESISTANCE)
THEN
	RESPONSE #100
                IncrementGlobal("DB","LOCALS",1)
                ForceSpellRES("ru_dragm",LastSeenBy(Myself))
                DisplayString(Myself,@277)
                Continue()
END

IF
        GlobalLT("DB","LOCALS",2)
        LevelGT(LastSeenBy(Myself),15)
        CheckStatLT(LastSeenBy(Myself),50,RESISTELECTRICITY)
THEN
	RESPONSE #100
                IncrementGlobal("DB","LOCALS",1)
                ForceSpellRES("ru_drage",LastSeenBy(Myself))
                DisplayString(Myself,@277)
                Continue()
END

IF
        GlobalLT("DB","LOCALS",2)
        LevelGT(LastSeenBy(Myself),15)
        CheckStatLT(LastSeenBy(Myself),50,RESISTCOLD)
THEN
	RESPONSE #100
                IncrementGlobal("DB","LOCALS",1)
                ForceSpellRES("ru_dragc",LastSeenBy(Myself))
                DisplayString(Myself,@277)
                Continue()
END

IF
        GlobalLT("DB","LOCALS",2)
        LevelGT(LastSeenBy(Myself),15)
        CheckStatLT(LastSeenBy(Myself),50,RESISTFIRE)
THEN
	RESPONSE #100
                IncrementGlobal("DB","LOCALS",1)
                ForceSpell(LastSeenBy(Myself),WIZARD_DRAGONS_BREATH)
                Continue()
END

IF
        GlobalLT("DB","LOCALS",2)
        LevelGT(LastSeenBy(Myself),15)
        CheckStatLT(LastSeenBy(Myself),100,RESISTPOISON)
THEN
	RESPONSE #100
                IncrementGlobal("DB","LOCALS",1)
                ForceSpellRES("ru_dragp",LastSeenBy(Myself))
                DisplayString(Myself,@277)
                Continue()
END

IF
        GlobalLT("DB","LOCALS",2)
        LevelGT(LastSeenBy(Myself),15)
        CheckStatLT(LastSeenBy(Myself),100,RESISTACID)
THEN
	RESPONSE #100
                IncrementGlobal("DB","LOCALS",1)
                ForceSpellRES("ru_draga",LastSeenBy(Myself))
                DisplayString(Myself,@277)
                Continue()
END

IF
        GlobalLT("DB","LOCALS",2)
        LevelGT(LastSeenBy(Myself),15)
        CheckStatLT(LastSeenBy(Myself),100,MAGICDAMAGERESISTANCE)
THEN
	RESPONSE #100
                IncrementGlobal("DB","LOCALS",1)
                ForceSpellRES("ru_dragm",LastSeenBy(Myself))
                DisplayString(Myself,@277)
                Continue()
END

IF
        GlobalLT("DB","LOCALS",2)
        LevelGT(LastSeenBy(Myself),15)
        CheckStatLT(LastSeenBy(Myself),100,RESISTELECTRICITY)
THEN
	RESPONSE #100
                IncrementGlobal("DB","LOCALS",1)
                ForceSpellRES("ru_drage",LastSeenBy(Myself))
                DisplayString(Myself,@277)
                Continue()
END

IF
        GlobalLT("DB","LOCALS",2)
        LevelGT(LastSeenBy(Myself),15)
        CheckStatLT(LastSeenBy(Myself),100,RESISTCOLD)
THEN
	RESPONSE #100
                IncrementGlobal("DB","LOCALS",1)
                ForceSpellRES("ru_dragc",LastSeenBy(Myself))
                DisplayString(Myself,@277)
                Continue()
END

IF
        GlobalLT("DB","LOCALS",2)
        LevelGT(LastSeenBy(Myself),15)
        CheckStatLT(LastSeenBy(Myself),100,RESISTFIRE)
THEN
	RESPONSE #100
                IncrementGlobal("DB","LOCALS",1)
                ForceSpell(LastSeenBy(Myself),WIZARD_DRAGONS_BREATH)
                Continue()
END

IF
        HaveSpell(WIZARD_WARDING_WHIP)
        OR(6)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_SPELL_DEFLECTION)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_SPELL_TURNING)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_SPELL_IMMUNITY)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_SPELL_SHIELD)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_SPELL_TRAP)
          CheckStatGT(LastSeenBy(Myself),0,CLERIC_SHIELD_OF_THE_ARCHONS)
        !GlobalTimerNotExpired("PIERCE_DELAY","LOCALS")
THEN
	RESPONSE #100
                SetGlobalTimer("PIERCE_DELAY","LOCALS",6)
                Spell(LastSeenBy(Myself),WIZARD_WARDING_WHIP)
END

IF
        GlobalLT("MODEN","LOCALS",2)
        OR(21)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_SPELL_DEFLECTION)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_SPELL_TURNING)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_SPELL_IMMUNITY)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_SPELL_SHIELD)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_SPELL_TRAP)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_IMPROVED_ALACRITY)
	  CheckStatGT(LastSeenBy(Myself),0,TRUE_SIGHT)
	  CheckStatGT(LastSeenBy(Myself),0,CLERIC_CHAOTIC_COMMANDS)
	  CheckStatGT(LastSeenBy(Myself),0,CLERIC_BLADE_BARRIER)
	  CheckStatGT(LastSeenBy(Myself),0,CLERIC_PHYSICAL_MIRROR)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_NORMAL_WEAPONS)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_TENSERS_TRANSFORMATION)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_MAGIC_ENERGY)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_MISLEAD)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_THE_ELEMENTS)
          CheckStatGT(LastSeenBy(Myself),0,STONESKINS)
          StateCheck(LastSeenBy(Myself),STATE_MIRRORIMAGE)
          StateCheck(LastSeenBy(Myself),STATE_DRAWUPONHOLYMIGHT)
          StateCheck(LastSeenBy(Myself),STATE_BLUR)
        !GlobalTimerNotExpired("PIERCE_DELAY","LOCALS")
THEN
	RESPONSE #100
                IncrementGlobal("MODEN","LOCALS",1)
                SetGlobalTimer("PIERCE_DELAY","LOCALS",6)
                ForceSpellRES("ru_disju",LastSeenBy(Myself)) // 모덴카이넨의 디스정션
END

IF
        HaveSpell(WIZARD_TRUE_DISPEL_MAGIC)
        OR(21)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_SPELL_DEFLECTION)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_SPELL_TURNING)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_SPELL_IMMUNITY)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_SPELL_SHIELD)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_SPELL_TRAP)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_IMPROVED_ALACRITY)
	  CheckStatGT(LastSeenBy(Myself),0,TRUE_SIGHT)
	  CheckStatGT(LastSeenBy(Myself),0,CLERIC_CHAOTIC_COMMANDS)
	  CheckStatGT(LastSeenBy(Myself),0,CLERIC_BLADE_BARRIER)
	  CheckStatGT(LastSeenBy(Myself),0,CLERIC_PHYSICAL_MIRROR)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_NORMAL_WEAPONS)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_TENSERS_TRANSFORMATION)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_MAGIC_ENERGY)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_MISLEAD)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_THE_ELEMENTS)
          CheckStatGT(LastSeenBy(Myself),0,STONESKINS)
          StateCheck(LastSeenBy(Myself),STATE_MIRRORIMAGE)
          StateCheck(LastSeenBy(Myself),STATE_DRAWUPONHOLYMIGHT)
          StateCheck(LastSeenBy(Myself),STATE_BLUR)
        !GlobalTimerNotExpired("PIERCE_DELAY","LOCALS")
THEN
	RESPONSE #100
                SetGlobalTimer("PIERCE_DELAY","LOCALS",6)
                Spell(LastSeenBy(Myself),WIZARD_TRUE_DISPEL_MAGIC)
END

IF
        HaveSpell(WIZARD_PIERCE_SHIELD)
        OR(7)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_SPELL_DEFLECTION)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_SPELL_TURNING)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_SPELL_IMMUNITY)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_SPELL_SHIELD)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_SPELL_TRAP)
	  CheckStatGT(LastSeenBy(Myself),50,RESISTMAGIC)
          CheckStatGT(LastSeenBy(Myself),0,CLERIC_SHIELD_OF_THE_ARCHONS)
        !GlobalTimerNotExpired("PIERCE_DELAY","LOCALS")
THEN
	RESPONSE #100
                SetGlobalTimer("PIERCE_DELAY","LOCALS",6)
                Spell(LastSeenBy(Myself),WIZARD_PIERCE_SHIELD)
END

IF
        HaveSpell(WIZARD_PIERCE_MAGIC)
        OR(6)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_SPELL_DEFLECTION)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_SPELL_TURNING)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_SPELL_IMMUNITY)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_SPELL_SHIELD)
	  CheckStatGT(LastSeenBy(Myself),50,RESISTMAGIC)
          CheckStatGT(LastSeenBy(Myself),0,CLERIC_SHIELD_OF_THE_ARCHONS)
        !GlobalTimerNotExpired("PIERCE_DELAY","LOCALS")
THEN
	RESPONSE #100
                SetGlobalTimer("PIERCE_DELAY","LOCALS",6)
                Spell(LastSeenBy(Myself),WIZARD_PIERCE_MAGIC)
END

IF
        HaveSpell(WIZARD_BREACH)
        OR(15)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_IMPROVED_ALACRITY)
	  CheckStatGT(LastSeenBy(Myself),0,TRUE_SIGHT)
	  CheckStatGT(LastSeenBy(Myself),0,CLERIC_CHAOTIC_COMMANDS)
	  CheckStatGT(LastSeenBy(Myself),0,CLERIC_BLADE_BARRIER)
	  CheckStatGT(LastSeenBy(Myself),0,CLERIC_PHYSICAL_MIRROR)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_NORMAL_WEAPONS)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_TENSERS_TRANSFORMATION)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_MAGIC_ENERGY)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_THE_ELEMENTS)
          CheckStatGT(LastSeenBy(Myself),0,STONESKINS)
          StateCheck(LastSeenBy(Myself),STATE_MIRRORIMAGE)
          StateCheck(LastSeenBy(Myself),STATE_DRAWUPONHOLYMIGHT)
          StateCheck(LastSeenBy(Myself),STATE_BLUR)
        !GlobalTimerNotExpired("PIERCE_DELAY","LOCALS")
THEN
	RESPONSE #100
                SetGlobalTimer("PIERCE_DELAY","LOCALS",6)
                Spell(LastSeenBy(Myself),WIZARD_BREACH)
END

IF
        HaveSpell(WIZARD_LOWER_RESISTANCE)
        CheckStatGT(LastSeenBy(Myself),50,RESISTMAGIC)
THEN
	RESPONSE #100
                Spell(LastSeenBy(Myself),WIZARD_LOWER_RESISTANCE)
END

IF
        Global("SpellSequence","LOCALS",0)
        CheckStatLT(LastSeenBy(Myself),12,SAVEVSSPELL)
THEN
	RESPONSE #100
                SetGlobal("SpellSequence","LOCALS",1)
                DisplayString(Myself,@278)
                ReallyForceSpell(LastSeenBy(Myself),WIZARD_GREATER_MALISON)
                ReallyForceSpell(LastSeenBy(Myself),WIZARD_GREATER_MALISON)
                ReallyForceSpell(LastSeenBy(Myself),WIZARD_GREATER_MALISON)
                Continue()
END

IF
        HaveSpell(WIZARD_GREATER_MALISON)
        CheckStatLT(LastSeenBy(Myself),12,SAVEVSSPELL)
THEN
	RESPONSE #100
                Spell(LastSeenBy(Myself),WIZARD_GREATER_MALISON)
END

IF
        ActionListEmpty()
        GlobalLT("MAMI","LOCALS",7)
        CheckStatLT(LastSeenBy(Myself),50,MAGICDAMAGERESISTANCE)
THEN
	RESPONSE #100
                IncrementGlobal("MAMI","LOCALS",1)
                ForceSpellRES("ru_arcma",LastSeenBy(Myself))
                DisplayString(Myself,@279)
                Continue()
END

IF
        ActionListEmpty()
        GlobalLT("DB","LOCALS",2)
        CheckStatLT(LastSeenBy(Myself),50,RESISTPOISON)
THEN
	RESPONSE #100
                IncrementGlobal("DB","LOCALS",1)
                ForceSpellRES("ru_dragp",LastSeenBy(Myself))
                DisplayString(Myself,@277)
                Continue()
END

IF
        ActionListEmpty()
        GlobalLT("DB","LOCALS",2)
        CheckStatLT(LastSeenBy(Myself),50,RESISTACID)
THEN
	RESPONSE #100
                IncrementGlobal("DB","LOCALS",1)
                ForceSpellRES("ru_draga",LastSeenBy(Myself))
                DisplayString(Myself,@277)
                Continue()
END

IF
        ActionListEmpty()
        GlobalLT("DB","LOCALS",2)
        CheckStatLT(LastSeenBy(Myself),50,MAGICDAMAGERESISTANCE)
THEN
	RESPONSE #100
                IncrementGlobal("DB","LOCALS",1)
                ForceSpellRES("ru_dragm",LastSeenBy(Myself))
                DisplayString(Myself,@277)
                Continue()
END

IF
        ActionListEmpty()
        GlobalLT("DB","LOCALS",2)
        CheckStatLT(LastSeenBy(Myself),50,RESISTELECTRICITY)
THEN
	RESPONSE #100
                IncrementGlobal("DB","LOCALS",1)
                ForceSpellRES("ru_drage",LastSeenBy(Myself))
                DisplayString(Myself,@277)
                Continue()
END

IF
        ActionListEmpty()
        GlobalLT("DB","LOCALS",2)
        CheckStatLT(LastSeenBy(Myself),50,RESISTCOLD)
THEN
	RESPONSE #100
                IncrementGlobal("DB","LOCALS",1)
                ForceSpellRES("ru_dragc",LastSeenBy(Myself))
                DisplayString(Myself,@277)
                Continue()
END

IF
        ActionListEmpty()
        GlobalLT("DB","LOCALS",2)
        CheckStatLT(LastSeenBy(Myself),50,RESISTFIRE)
THEN
	RESPONSE #100
                IncrementGlobal("DB","LOCALS",1)
                ForceSpell(LastSeenBy(Myself),WIZARD_DRAGONS_BREATH)
                Continue()
END

IF
        ActionListEmpty()
        GlobalLT("DB","LOCALS",2)
        CheckStatLT(LastSeenBy(Myself),100,RESISTPOISON)
THEN
	RESPONSE #100
                IncrementGlobal("DB","LOCALS",1)
                ForceSpellRES("ru_dragp",LastSeenBy(Myself))
                DisplayString(Myself,@277)
                Continue()
END

IF
        ActionListEmpty()
        GlobalLT("DB","LOCALS",2)
        CheckStatLT(LastSeenBy(Myself),100,RESISTACID)
THEN
	RESPONSE #100
                IncrementGlobal("DB","LOCALS",1)
                ForceSpellRES("ru_draga",LastSeenBy(Myself))
                DisplayString(Myself,@277)
                Continue()
END

IF
        ActionListEmpty()
        GlobalLT("DB","LOCALS",2)
        CheckStatLT(LastSeenBy(Myself),100,MAGICDAMAGERESISTANCE)
THEN
	RESPONSE #100
                IncrementGlobal("DB","LOCALS",1)
                ForceSpellRES("ru_dragm",LastSeenBy(Myself))
                DisplayString(Myself,@277)
                Continue()
END

IF
        ActionListEmpty()
        GlobalLT("DB","LOCALS",2)
        CheckStatLT(LastSeenBy(Myself),100,RESISTELECTRICITY)
THEN
	RESPONSE #100
                IncrementGlobal("DB","LOCALS",1)
                ForceSpellRES("ru_drage",LastSeenBy(Myself))
                DisplayString(Myself,@277)
                Continue()
END

IF
        ActionListEmpty()
        GlobalLT("DB","LOCALS",2)
        CheckStatLT(LastSeenBy(Myself),100,RESISTCOLD)
THEN
	RESPONSE #100
                IncrementGlobal("DB","LOCALS",1)
                ForceSpellRES("ru_dragc",LastSeenBy(Myself))
                DisplayString(Myself,@277)
                Continue()
END

IF
        ActionListEmpty()
        GlobalLT("ABI","LOCALS",3)
        CheckStatLT(LastSeenBy(Myself),50,RESISTPOISON)
        CheckStatLT(LastSeenBy(Myself),100,RESISTMAGIC)
THEN
	RESPONSE #100
                IncrementGlobal("ABI","LOCALS",1)
                ForceSpellRES("ru_abidp",LastSeenBy(Myself))
                DisplayString(Myself,@280)
                Continue()
END

IF
        ActionListEmpty()
        GlobalLT("ABI","LOCALS",3)
        CheckStatLT(LastSeenBy(Myself),50,RESISTACID)
        CheckStatLT(LastSeenBy(Myself),100,RESISTMAGIC)
THEN
	RESPONSE #100
                IncrementGlobal("ABI","LOCALS",1)
                ForceSpellRES("ru_abida",LastSeenBy(Myself))
                DisplayString(Myself,@280)
                Continue()
END

IF
        ActionListEmpty()
        GlobalLT("ABI","LOCALS",3)
        CheckStatLT(LastSeenBy(Myself),50,MAGICDAMAGERESISTANCE)
        CheckStatLT(LastSeenBy(Myself),100,RESISTMAGIC)
THEN
	RESPONSE #100
                IncrementGlobal("ABI","LOCALS",1)
                ForceSpell(LastSeenBy(Myself),WIZARD_ABI_DALZIMS_HORRID_WILTING)
                Continue()
END

IF
        ActionListEmpty()
        GlobalLT("ABI","LOCALS",3)
        CheckStatLT(LastSeenBy(Myself),50,RESISTELECTRICITY)
        CheckStatLT(LastSeenBy(Myself),100,RESISTMAGIC)
THEN
	RESPONSE #100
                IncrementGlobal("ABI","LOCALS",1)
                ForceSpellRES("ru_abide",LastSeenBy(Myself))
                DisplayString(Myself,@280)
                Continue()
END

IF
        ActionListEmpty()
        GlobalLT("ABI","LOCALS",3)
        CheckStatLT(LastSeenBy(Myself),50,RESISTCOLD)
        CheckStatLT(LastSeenBy(Myself),100,RESISTMAGIC)
THEN
	RESPONSE #100
                IncrementGlobal("ABI","LOCALS",1)
                ForceSpellRES("ru_abidc",LastSeenBy(Myself))
                DisplayString(Myself,@280)
                Continue()
END

IF
        ActionListEmpty()
        GlobalLT("ABI","LOCALS",3)
        CheckStatLT(LastSeenBy(Myself),50,RESISTFIRE)
        CheckStatLT(LastSeenBy(Myself),100,RESISTMAGIC)
THEN
	RESPONSE #100
                IncrementGlobal("ABI","LOCALS",1)
                ForceSpellRES("ru_abidf",LastSeenBy(Myself))
                DisplayString(Myself,@280)
                Continue()
END

IF
        ActionListEmpty()
        GlobalLT("ABI","LOCALS",3)
        CheckStatLT(LastSeenBy(Myself),100,RESISTPOISON)
        CheckStatLT(LastSeenBy(Myself),100,RESISTMAGIC)
THEN
	RESPONSE #100
                IncrementGlobal("ABI","LOCALS",1)
                ForceSpellRES("ru_abidp",LastSeenBy(Myself))
                DisplayString(Myself,@280)
                Continue()
END

IF
        ActionListEmpty()
        GlobalLT("ABI","LOCALS",3)
        CheckStatLT(LastSeenBy(Myself),100,RESISTACID)
        CheckStatLT(LastSeenBy(Myself),100,RESISTMAGIC)
THEN
	RESPONSE #100
                IncrementGlobal("ABI","LOCALS",1)
                ForceSpellRES("ru_abida",LastSeenBy(Myself))
                DisplayString(Myself,@280)
                Continue()
END

IF
        ActionListEmpty()
        GlobalLT("ABI","LOCALS",3)
        CheckStatLT(LastSeenBy(Myself),100,MAGICDAMAGERESISTANCE)
        CheckStatLT(LastSeenBy(Myself),100,RESISTMAGIC)
THEN
	RESPONSE #100
                IncrementGlobal("ABI","LOCALS",1)
                ForceSpell(LastSeenBy(Myself),WIZARD_ABI_DALZIMS_HORRID_WILTING)
                Continue()
END

IF
        ActionListEmpty()
        GlobalLT("ABI","LOCALS",3)
        CheckStatLT(LastSeenBy(Myself),100,RESISTELECTRICITY)
        CheckStatLT(LastSeenBy(Myself),100,RESISTMAGIC)
THEN
	RESPONSE #100
                IncrementGlobal("ABI","LOCALS",1)
                ForceSpellRES("ru_abide",LastSeenBy(Myself))
                DisplayString(Myself,@280)
                Continue()
END

IF
        ActionListEmpty()
        GlobalLT("ABI","LOCALS",3)
        CheckStatLT(LastSeenBy(Myself),100,RESISTCOLD)
        CheckStatLT(LastSeenBy(Myself),100,RESISTMAGIC)
THEN
	RESPONSE #100
                IncrementGlobal("ABI","LOCALS",1)
                ForceSpellRES("ru_abidc",LastSeenBy(Myself))
                DisplayString(Myself,@280)
                Continue()
END

IF
        ActionListEmpty()
        GlobalLT("ABI","LOCALS",3)
        CheckStatLT(LastSeenBy(Myself),100,RESISTFIRE)
        CheckStatLT(LastSeenBy(Myself),100,RESISTMAGIC)
THEN
	RESPONSE #100
                IncrementGlobal("ABI","LOCALS",1)
                ForceSpellRES("ru_abidf",LastSeenBy(Myself))
                DisplayString(Myself,@280)
                Continue()
END

IF
        ActionListEmpty()
        !See([ALLY])
        GlobalLT("FB","LOCALS",5)
        CheckStatLT(LastSeenBy(Myself),50,RESISTPOISON)
        CheckStatLT(LastSeenBy(Myself),100,RESISTMAGIC)
THEN
	RESPONSE #100
                IncrementGlobal("FB","LOCALS",1)
                ForceSpellRES("ru_firep",LastSeenBy(Myself))
                DisplayString(Myself,@281)
                Continue()
END

IF
        ActionListEmpty()
        !See([ALLY])
        GlobalLT("FB","LOCALS",5)
        CheckStatLT(LastSeenBy(Myself),50,RESISTACID)
        CheckStatLT(LastSeenBy(Myself),100,RESISTMAGIC)
THEN
	RESPONSE #100
                IncrementGlobal("FB","LOCALS",1)
                ForceSpellRES("ru_firea",LastSeenBy(Myself))
                DisplayString(Myself,@281)
                Continue()
END

IF
        ActionListEmpty()
        !See([ALLY])
        GlobalLT("FB","LOCALS",5)
        CheckStatLT(LastSeenBy(Myself),50,MAGICDAMAGERESISTANCE)
        CheckStatLT(LastSeenBy(Myself),100,RESISTMAGIC)
THEN
	RESPONSE #100
                IncrementGlobal("FB","LOCALS",1)
                ForceSpellRES("ru_firem",LastSeenBy(Myself))
                DisplayString(Myself,@281)
                Continue()
END

IF
        ActionListEmpty()
        !See([ALLY])
        GlobalLT("FB","LOCALS",5)
        CheckStatLT(LastSeenBy(Myself),50,RESISTELECTRICITY)
        CheckStatLT(LastSeenBy(Myself),100,RESISTMAGIC)
THEN
	RESPONSE #100
                IncrementGlobal("FB","LOCALS",1)
                ForceSpellRES("ru_firee",LastSeenBy(Myself))
                DisplayString(Myself,@281)
                Continue()
END

IF
        ActionListEmpty()
        !See([ALLY])
        GlobalLT("FB","LOCALS",5)
        CheckStatLT(LastSeenBy(Myself),50,RESISTCOLD)
        CheckStatLT(LastSeenBy(Myself),100,RESISTMAGIC)
THEN
	RESPONSE #100
                IncrementGlobal("FB","LOCALS",1)
                ForceSpellRES("ru_firec",LastSeenBy(Myself))
                DisplayString(Myself,@281)
                Continue()
END

IF
        ActionListEmpty()
        !See([ALLY])
        GlobalLT("FB","LOCALS",5)
        CheckStatLT(LastSeenBy(Myself),50,RESISTFIRE)
        CheckStatLT(LastSeenBy(Myself),100,RESISTMAGIC)
THEN
	RESPONSE #100
                IncrementGlobal("FB","LOCALS",1)
                ForceSpell(LastSeenBy(Myself),WIZARD_FIREBALL)
                Continue()
END

IF
        ActionListEmpty()
        !See([ALLY])
        GlobalLT("FB","LOCALS",5)
        CheckStatLT(LastSeenBy(Myself),100,RESISTPOISON)
        CheckStatLT(LastSeenBy(Myself),100,RESISTMAGIC)
THEN
	RESPONSE #100
                IncrementGlobal("FB","LOCALS",1)
                ForceSpellRES("ru_firep",LastSeenBy(Myself))
                DisplayString(Myself,@281)
                Continue()
END

IF
        ActionListEmpty()
        !See([ALLY])
        GlobalLT("FB","LOCALS",5)
        CheckStatLT(LastSeenBy(Myself),100,RESISTACID)
        CheckStatLT(LastSeenBy(Myself),100,RESISTMAGIC)
THEN
	RESPONSE #100
                IncrementGlobal("FB","LOCALS",1)
                ForceSpellRES("ru_firea",LastSeenBy(Myself))
                DisplayString(Myself,@281)
                Continue()
END

IF
        ActionListEmpty()
        !See([ALLY])
        GlobalLT("FB","LOCALS",5)
        CheckStatLT(LastSeenBy(Myself),100,MAGICDAMAGERESISTANCE)
        CheckStatLT(LastSeenBy(Myself),100,RESISTMAGIC)
THEN
	RESPONSE #100
                IncrementGlobal("FB","LOCALS",1)
                ForceSpellRES("ru_firem",LastSeenBy(Myself))
                DisplayString(Myself,@281)
                Continue()
END

IF
        ActionListEmpty()
        !See([ALLY])
        GlobalLT("FB","LOCALS",5)
        CheckStatLT(LastSeenBy(Myself),100,RESISTELECTRICITY)
        CheckStatLT(LastSeenBy(Myself),100,RESISTMAGIC)
THEN
	RESPONSE #100
                IncrementGlobal("FB","LOCALS",1)
                ForceSpellRES("ru_firee",LastSeenBy(Myself))
                DisplayString(Myself,@281)
                Continue()
END

IF
        ActionListEmpty()
        !See([ALLY])
        GlobalLT("FB","LOCALS",5)
        CheckStatLT(LastSeenBy(Myself),100,RESISTCOLD)
        CheckStatLT(LastSeenBy(Myself),100,RESISTMAGIC)
THEN
	RESPONSE #100
                IncrementGlobal("FB","LOCALS",1)
                ForceSpellRES("ru_firec",LastSeenBy(Myself))
                DisplayString(Myself,@281)
                Continue()
END

IF
        ActionListEmpty()
        !See([ALLY])
        GlobalLT("FB","LOCALS",5)
        CheckStatLT(LastSeenBy(Myself),100,RESISTFIRE)
        CheckStatLT(LastSeenBy(Myself),100,RESISTMAGIC)
THEN
	RESPONSE #100
                IncrementGlobal("FB","LOCALS",1)
                ForceSpell(LastSeenBy(Myself),WIZARD_FIREBALL)
                Continue()
END

IF
        ActionListEmpty()
        GlobalLT("FB","LOCALS",5)
        CheckStatLT(LastSeenBy(Myself),100,MAGICDAMAGERESISTANCE)
THEN
	RESPONSE #100
                IncrementGlobal("FB","LOCALS",1)
                ForceSpellRES("ru_arcfb",LastSeenBy(Myself))
                DisplayString(Myself,@283)
END

IF
        ActionListEmpty()
        GlobalLT("MELF","LOCALS",4)
        CheckStatLT(LastSeenBy(Myself),100,MAGICDAMAGERESISTANCE)
THEN
	RESPONSE #100
                IncrementGlobal("MELF","LOCALS",1)
                ForceSpellRES("ru_arcme",LastSeenBy(Myself))
                DisplayString(Myself,@282)
                Continue()
END

IF
        ActionListEmpty()
        GlobalLT("MAMI","LOCALS",7)
        CheckStatLT(LastSeenBy(Myself),100,MAGICDAMAGERESISTANCE)
THEN
	RESPONSE #100
                IncrementGlobal("MAMI","LOCALS",1)
                ForceSpellRES("ru_arcma",LastSeenBy(Myself))
                DisplayString(Myself,@279)
                Continue()
END

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

IF
        Global("WISH","LOCALS",0)
        CheckStatLT(LastSeenBy(Myself),100,RESISTMAGIC)
        OR(5)
         CheckStatLT(LastSeenBy(Myself),100,RESISTFIRE)
         CheckStatLT(LastSeenBy(Myself),100,RESISTACID)
         CheckStatLT(LastSeenBy(Myself),100,RESISTCOLD)
         CheckStatLT(LastSeenBy(Myself),100,RESISTPOISON)
         CheckStatLT(LastSeenBy(Myself),100,MAGICDAMAGERESISTANCE)
THEN
	RESPONSE #100
                SetGlobal("WISH","LOCALS",1)
                DisplayString(Myself,@285)
                DisplayString(Myself,72548)
                Rest()
                SetGlobal("DB","LOCALS",0)
                SetGlobal("ABI","LOCALS",0)
                SetGlobal("MAMI","LOCALS",0)
                SetGlobal("SpellSequence","LOCALS",0)
                SetGlobal("SIM","LOCALS",0)
                SetGlobal("SID","LOCALS",0)
                SetGlobal("TrueSight","LOCALS",0)
                SetGlobal("DetectInvisibility","LOCALS",0)
                SetGlobal("Contingency","LOCALS",0)
                SetGlobal("ChainContingency","LOCALS",0)
                SetGlobal("SilverFire","LOCALS",0)
                SetGlobal("TS1","LOCALS",0)
                SetGlobal("TS2","LOCALS",0)
                SetGlobal("FB","LOCALS",0)
                SetGlobal("MODEN","LOCALS",0)
END

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

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

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

IF
        Global("BATTLE","LOCALS",0)
        See(NearestEnemyOf(Myself))
THEN
	RESPONSE #100
                SetGlobal("BATTLE","LOCALS",1)
                DisplayString(Myself,@284)
                ReallyForceSpellRES("ru_c400c",Myself)
END

IF
        HaveSpell(WIZARD_TIME_STOP)
        Global("TS2","LOCALS",0)
        !CombatCounter(0)
        ActionListEmpty()
THEN
	RESPONSE #100
                SetGlobal("TS2","LOCALS",1)
                Spell(Myself,WIZARD_TIME_STOP)
                Continue()
END

IF
        HaveSpell(CLERIC_AID)
        !CombatCounter(0)
        ActionListEmpty()
THEN
	RESPONSE #100
                Spell(Myself,CLERIC_AID)
                Continue()
END

IF
        HaveSpell(WIZARD_TENSERS_TRANSFORMATION)
        Global("COMBAT","LOCALS",0)
        !CombatCounter(0)
        ActionListEmpty()
THEN
	RESPONSE #100
                SetGlobal("COMBAT","LOCALS",1)
                Spell(Myself,WIZARD_TENSERS_TRANSFORMATION)
                Continue()
END

IF
        !CombatCounter(0)
        ActionListEmpty()
        Global("BATTLE","LOCALS",0)
THEN
	RESPONSE #100
                SetGlobal("BATTLE","LOCALS",1)
                DisplayString(Myself,@284)
                ReallyForceSpellRES("ru_c400c",Myself)
END