IF
	See(NearestEnemyOf(Myself))
	!GlobalTimerNotExpired("Prep","LOCALS")
THEN
	RESPONSE #100
                DisplayStringHead(Myself,@80)
                ApplySpell(Myself,DRAGON_STONE_SKIN)
                ReallyForceSpell(Myself,BEHOLDER_SPELL_TURNING)
		ApplySpell(Myself,WIZARD_SPELL_TRAP)
                ApplySpell(Myself,WIZARD_SPELL_SHIELD)
		SetGlobalTimer("Prep","LOCALS",60)
END

IF
        HPPercentLT(Myself,20)
        Global("HEALONCE","LOCALS",0)
THEN
	RESPONSE #100
                ForceSpell(Myself,CLERIC_HEAL)
                SetGlobal("HEALONCE","LOCALS",1)
END

IF
        See(NearestEnemyOf(Myself))
        GlobalLT("WPMW","LOCALS",5)
        CheckStat(Myself,0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
THEN
	RESPONSE #100
                IncrementGlobal("WPMW","LOCALS",1)
                ForceSpell(Myself,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
END

IF
        See(NearestEnemyOf(Myself))
	!CheckStatGT(Myself,0,STONESKINS)
        GlobalLT("DSS","LOCALS",5)
THEN
	RESPONSE #100
                IncrementGlobal("DSS","LOCALS",1)
		ForceSpell(Myself,DRAGON_STONE_SKIN)
END

IF
	See(NearestEnemyOf(Myself))
	OR(3)
		See(NearestEnemyOfType([PC.0.0.BARD_ALL]))
		See(NearestEnemyOfType([PC.0.0.LONG_BOW]))
		See(NearestEnemyOfType([PC.0.0.SORCERER]))
	!StateCheck(LastSeenBy(Myself),STATE_SILENCED)
	!GlobalTimerNotExpired("SpellTurn","LOCALS")
	!InMyGroup(LastSeenBy(Myself))
        !Allegiance(LastSeenBy(Myself),EVILCUTOFF)
THEN
	RESPONSE #100
		SetGlobalTimer("SpellTurn","LOCALS",15)
		ForceSpell(Myself,BEHOLDER_SPELL_TURNING)
END

IF
	OR(6)
		Class(LastSeenBy(Myself),PALADIN_ALL)
		Class(LastSeenBy(Myself),DRUID_ALL)
		Class(LastSeenBy(Myself),CLERIC_ALL)
		Class(LastSeenBy(Myself),BARD_ALL)
		Class(LastSeenBy(Myself),LONG_BOW)
		Class(LastSeenBy(Myself),SORCERER)
	!StateCheck(LastSeenBy(Myself),STATE_SILENCED)
	!HasBounceEffects(LastSeenBy(Myself))
	!GlobalTimerNotExpired("dbSilence","LOCALS")
	!InMyGroup(LastSeenBy(Myself))
        !Allegiance(LastSeenBy(Myself),EVILCUTOFF)
THEN
	RESPONSE #100
		SetGlobalTimer("dbSilence","LOCALS",15)
		ForceSpell(LastSeenBy(Myself),DRAGON_SILENCE)
END

IF
        See(NearestEnemyOf(Myself))
        CheckStat(Myself,0,WIZARD_SPELL_TRAP)
        GlobalLT("WSPT","LOCALS",4)
THEN
	RESPONSE #100
                IncrementGlobal("WSPT","LOCALS",1)
                ForceSpell(Myself,WIZARD_SPELL_TRAP)
END

IF
        See(NearestEnemyOf(Myself))
        GlobalLT("WFS","LOCALS",3)
        !GlobalTimerNotExpired("FIRESHIELD","LOCALS")
THEN
	RESPONSE #100
                IncrementGlobal("WFS","LOCALS",1)
                SetGlobalTimer("FIRESHIELD","LOCALS",60)
                ForceSpellRES("SPPR730",Myself)
END

IF
        See(NearestEnemyOf(Myself))
        GlobalLT("WSS","LOCALS",6)
        !CheckStat(Myself,1,WIZARD_SPELL_SHIELD)
THEN
	RESPONSE #100
                IncrementGlobal("WSS","LOCALS",1)
                ForceSpell(Myself,WIZARD_SPELL_SHIELD)
END

IF
	OR(6)
		Gender(LastSeenBy(Myself),ILLUSIONARY)
		SpellCast(LastSeenBy(Myself),WIZARD_PROJECT_IMAGE)
		SpellCast(LastSeenBy(Myself),WIZARD_SIMULACRUM)
		SpellCast(LastSeenBy(Myself),WIZARD_MISLEAD)
		StateCheck(LastSeenBy(Myself),STATE_BLUR)
		StateCheck(LastSeenBy(Myself),STATE_MIRRORIMAGE)
	!GlobalTimerNotExpired("TrueSight","LOCALS")
	!InMyGroup(LastSeenBy(Myself))
        !Allegiance(LastSeenBy(Myself),EVILCUTOFF)
THEN
	RESPONSE #100
		SetGlobalTimer("TrueSight","LOCALS",30)
		ForceSpell(Myself,WIZARD_TRUE_SIGHT)
END

IF
        Allegiance(LastSeenBy(Myself),PC)
        OR(13)
          StateCheck(LastSeenBy(Myself), STATE_INVISIBLE)
          StateCheck(LastSeenBy(Myself), STATE_IMPROVEDINVISIBILITY)
          StateCheck(LastSeenBy(Myself), STATE_MIRRORIMAGE)
          StateCheck(LastSeenBy(Myself), STATE_HASTED)
	  HasBounceEffects(LastSeenBy(Myself))
	  HasImmunityEffects(LastSeenBy(Myself))
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_MAGIC_ENERGY)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_MISLEAD)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_TENSERS_TRANSFORMATION)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_ENERGY)
          CheckStatGT(LastSeenBy(Myself),0,STONESKINS)
          CheckStatGT(LastSeenBy(Myself),0,IMPROVEDHASTE)
        GlobalLT("PENE","LOCALS",20)
THEN
	RESPONSE #25
                IncrementGlobal("PENE","LOCALS",1)
                ForceSpell(LastSeenBy(Myself),WIZARD_WARDING_WHIP)
                Continue()
	RESPONSE #25
                IncrementGlobal("PENE","LOCALS",1)
                ForceSpell(LastSeenBy(Myself),WIZARD_BREACH)
                Continue()
	RESPONSE #25
                IncrementGlobal("PENE","LOCALS",1)
                ForceSpell(LastSeenBy(Myself),WIZARD_SECRET_WORD)
                Continue()
	RESPONSE #25
                IncrementGlobal("PENE","LOCALS",1)
                ForceSpell(LastSeenBy(Myself),WIZARD_DISPEL_MAGIC)
                Continue()
END

IF
	See(NearestEnemyOf(Myself))
	CheckStatLT(Myself,50,RESISTMAGIC)
	!GlobalTimerNotExpired("RegainMagic","LOCALS")
THEN
	RESPONSE #100
		SetGlobalTimer("RegainMagic","LOCALS",15)
		ApplySpellRES("SPCL904",Myself)
END

IF
        See([ENEMY])
        CheckStatGT(LastSeenBy(Myself), 0, RESISTMAGIC)
        GlobalLT("WLR","LOCALS",4)
	!InMyGroup(LastSeenBy(Myself))
        !Allegiance(LastSeenBy(Myself),EVILCUTOFF)
THEN
	RESPONSE #100
                IncrementGlobal("WLR","LOCALS",1)
                ReallyForceSpell(LastSeenBy(Myself),WIZARD_LOWER_RESISTANCE)
END

IF
        See([ENEMY])
        CheckStatLT(LastSeenBy(Myself), 10, SAVEVSDEATH)
        GlobalLT("WGM","LOCALS",4)
	!InMyGroup(LastSeenBy(Myself))
        !Allegiance(LastSeenBy(Myself),EVILCUTOFF)
THEN
	RESPONSE #100
                IncrementGlobal("WGM","LOCALS",1)
                ReallyForceSpell(LastSeenBy(Myself),WIZARD_GREATER_MALISON)
END

IF
	See([ENEMY])
        CheckStatLT(LastSeenBy(Myself), 30, RESISTMAGIC)
        CheckStatGT(LastSeenBy(Myself), 10, SAVEVSDEATH)
        GlobalLT("WWB","LOCALS",4)
	!InMyGroup(LastSeenBy(Myself))
        !Allegiance(LastSeenBy(Myself),EVILCUTOFF)
THEN
	RESPONSE #100
                IncrementGlobal("WWB","LOCALS",1)
                ForceSpell(LastSeenBy(Myself),WIZARD_WAIL_OF_THE_BANSHEE)
END

IF
        See([ENEMY])
        HPLT(LastSeenBy(Myself), 90)
        CheckStatLT(LastSeenBy(Myself), 100, RESISTMAGIC)
	!StateCheck(LastSeenBy(Myself),STATE_STUNNED)
	!InMyGroup(LastSeenBy(Myself))
        !Allegiance(LastSeenBy(Myself),EVILCUTOFF)
        GlobalLT("WPS","LOCALS",5)
THEN
	RESPONSE #100
                IncrementGlobal("WPS","LOCALS",1)
                ForceSpell(LastSeenBy(Myself),WIZARD_POWER_WORD_STUN)
END

IF
	See([ENEMY])
        CheckStatLT(LastSeenBy(Myself), 100, RESISTMAGIC)
        HPLT(LastSeenBy(Myself), 60)
	!InMyGroup(LastSeenBy(Myself))
        !Allegiance(LastSeenBy(Myself),EVILCUTOFF)
        GlobalLT("WPK","LOCALS",5)
THEN
	RESPONSE #100
                IncrementGlobal("WPK","LOCALS",1)
                ForceSpell(LastSeenBy(Myself),WIZARD_POWER_WORD_KILL)
END

IF
	See(NearestEnemyOf(Myself))
	!GlobalTimerNotExpired("DRAGONFEAR","LOCALS")
THEN
	RESPONSE #100
		SetGlobalTimer("DRAGONFEAR","LOCALS",20)
		ReallyForceSpell(NearestEnemyOf(Myself),DRAGON_FEAR)
		ReallyForceSpell(NearestEnemyOf(Myself),DRAGON_LOWER_ELECTRICAL)
                ReallyForceSpell(NearestEnemyOf(Myself),DRAGON_LOWER_FIRE)
		ForceSpell(NearestEnemyOf(Myself),DRAGON_WING_BUFFET)
END

IF
	OR(3)
		SpellCast([GOODCUTOFF],WIZARD_CLOUDKILL)
		SpellCast([GOODCUTOFF],WIZARD_INCENDIARY_CLOUD)
		SpellCast([GOODCUTOFF],WIZARD_DEATH_FOG)
	!GlobalTimerNotExpired("WINGBUFFET","LOCALS")
THEN
	RESPONSE #100
		SetGlobalTimer("WINGBUFFET","LOCALS",8)
		ForceSpell(NearestEnemyOf(Myself),DRAGON_WING_BUFFET)
		Wait(1)
		ApplySpell(Myself,CLERIC_ZONE_OF_SWEET_AIR)
END

IF
	See(NearestEnemyOf(Myself))
        !GlobalTimerNotExpired("ProtectionOfDeath","LOCALS")
THEN
	RESPONSE #100
                SetGlobalTimer("ProtectionOfDeath","LOCALS",30)
                ForceSpellRES("SPCL917",Myself)
END

IF
	See(NearestEnemyOf(Myself))
        !GlobalTimerNotExpired("GreaterEvasion","LOCALS")
THEN
	RESPONSE #100
                SetGlobalTimer("GreaterEvasion","LOCALS",30)
                ForceSpellRES("SPCL914",Myself)
END

IF
	!GlobalTimerNotExpired("REDDRAGONBREATH","LOCALS")
	Range(LastSeenBy(Myself),30)
	CheckStatLT(LastSeenBy(Myself),100,RESISTFIRE)
	!InMyGroup(LastSeenBy(Myself))
        !Allegiance(LastSeenBy(Myself),EVILCUTOFF)
THEN
	RESPONSE #25
		SetGlobalTimer("REDDRAGONBREATH","LOCALS",6)
		ForceSpell(LastSeenBy(Myself),RED_DRAGON_BREATH)
		ReallyForceSpell(LastSeenBy(Myself),RED_DRAGON_HIT)
                ReallyForceSpell(LastSeenBy(Myself),YELLOW_DRAGON_BREATH)
	RESPONSE #25
		SetGlobalTimer("REDDRAGONBREATH","LOCALS",6)
		ForceSpell(LastSeenBy(Myself),RED_DRAGON_BREATH)
		ReallyForceSpell(LastSeenBy(Myself),RED_DRAGON_HIT)
                ReallyForceSpell(LastSeenBy(Myself),YELLOW_DRAGON_BREATH)
                Continue()
	RESPONSE #50
                Continue()
END

IF
	!GlobalTimerNotExpired("SILVERDRAGONBREATH","LOCALS")
	Range(LastSeenBy(Myself),30)
	CheckStatLT(LastSeenBy(Myself),100,RESISTCOLD)
	!InMyGroup(LastSeenBy(Myself))
        !Allegiance(LastSeenBy(Myself),EVILCUTOFF)
THEN
	RESPONSE #25
		SetGlobalTimer("SILVERDRAGONBREATH","LOCALS",6)
		ForceSpell(LastSeenBy(Myself),SILVER_DRAGON_BREATH_COLD)
		ReallyForceSpell(LastSeenBy(Myself),SILVER_DRAGON_BREATH_PARALIZATION)
		ReallyForceSpell(LastSeenBy(Myself),DRAGON_RAIN)
	RESPONSE #25
		SetGlobalTimer("SILVERDRAGONBREATH","LOCALS",6)
		ForceSpell(LastSeenBy(Myself),SILVER_DRAGON_BREATH_COLD)
		ReallyForceSpell(LastSeenBy(Myself),SILVER_DRAGON_BREATH_PARALIZATION)
		ReallyForceSpell(LastSeenBy(Myself),DRAGON_RAIN)
                Continue()
	RESPONSE #50
                Continue()
END

IF
	!GlobalTimerNotExpired("BLUEDRAGONBREATH","LOCALS")
	Range(LastSeenBy(Myself),30)
	CheckStatLT(LastSeenBy(Myself),100,RESISTELECTRICITY)
	!InMyGroup(LastSeenBy(Myself))
        !Allegiance(LastSeenBy(Myself),EVILCUTOFF)
THEN
	RESPONSE #25
		SetGlobalTimer("BLUEDRAGONBREATH","LOCALS",6)
		ForceSpell(LastSeenBy(Myself),BLUE_DRAGON_BREATH)
	RESPONSE #25
		SetGlobalTimer("BLUEDRAGONBREATH","LOCALS",6)
		ForceSpell(LastSeenBy(Myself),BLUE_DRAGON_BREATH)
                Continue()
	RESPONSE #50
                Continue()
END

IF
	!GlobalTimerNotExpired("GREENDRAGONBREATH","LOCALS")
	Range(LastSeenBy(Myself),30)
	CheckStatLT(LastSeenBy(Myself),100,RESISTPOISON)
	!InMyGroup(LastSeenBy(Myself))
        !Allegiance(LastSeenBy(Myself),EVILCUTOFF)
THEN
	RESPONSE #25
		SetGlobalTimer("GREENDRAGONBREATH","LOCALS",6)
		ForceSpellRES("ru_green",LastSeenBy(Myself))
	RESPONSE #25
		SetGlobalTimer("GREENDRAGONBREATH","LOCALS",6)
		ForceSpellRES("ru_green",LastSeenBy(Myself))
                Continue()
	RESPONSE #50
                Continue()
END

IF
	!GlobalTimerNotExpired("BROWNRAGONBREATH","LOCALS")
	Range(LastSeenBy(Myself),30)
	CheckStatLT(LastSeenBy(Myself),100,RESISTACID)
	!InMyGroup(LastSeenBy(Myself))
        !Allegiance(LastSeenBy(Myself),EVILCUTOFF)
THEN
	RESPONSE #25
		SetGlobalTimer("BROWNDRAGONBREATH","LOCALS",6)
		ForceSpell(LastSeenBy(Myself),BROWN_DRAGON_BREATH)
	RESPONSE #25
		SetGlobalTimer("BROWNDRAGONBREATH","LOCALS",6)
		ForceSpell(LastSeenBy(Myself),BROWN_DRAGON_BREATH)
                Continue()
	RESPONSE #50
                Continue()
END

IF
	!GlobalTimerNotExpired("BLACKRAGONBREATH","LOCALS")
	Range(LastSeenBy(Myself),30)
	!InMyGroup(LastSeenBy(Myself))
        !Allegiance(LastSeenBy(Myself),EVILCUTOFF)
THEN
	RESPONSE #25
		SetGlobalTimer("BLACKDRAGONBREATH","LOCALS",6)
                ForceSpell(LastSeenBy(Myself),SHADOW_DRAGON_BREATH)
                ReallyForceSpell(Myself,BLACK_DRAGON_PLANT)
		ReallyForceSpell(LastSeenBy(Myself),BLACK_DRAGON_BREATH)
                ReallyForceSpell(LastSeenBy(Myself),BLACK_DRAGON_INSECT)
	RESPONSE #25
		SetGlobalTimer("BLACKDRAGONBREATH","LOCALS",6)
                ForceSpell(LastSeenBy(Myself),SHADOW_DRAGON_BREATH)
                ReallyForceSpell(Myself,BLACK_DRAGON_PLANT)
		ReallyForceSpell(LastSeenBy(Myself),BLACK_DRAGON_BREATH)
                ReallyForceSpell(LastSeenBy(Myself),BLACK_DRAGON_INSECT)
                Continue()
	RESPONSE #50
                Continue()
END

IF
	!GlobalTimerNotExpired("EXTREMRAGONBREATH","LOCALS")
	Range(LastSeenBy(Myself),30)
	!InMyGroup(LastSeenBy(Myself))
        !Allegiance(LastSeenBy(Myself),EVILCUTOFF)
THEN
	RESPONSE #100
		SetGlobalTimer("EXTREMDRAGONBREATH","LOCALS",6)
                ForceSpellRES("ru_monib",LastSeenBy(Myself))
                ReallyForceSpellRES("ru_mohit",LastSeenBy(Myself))
END

IF
	!InActiveArea(Myself)
        OR(12)
          GlobalGT("HEALONCE","LOCALS",0)
          GlobalGT("WWB","LOCALS",0)
          GlobalGT("WPK","LOCALS",0)
          GlobalGT("WPS","LOCALS",0)
          GlobalGT("WSS","LOCALS",0)
          GlobalGT("WFS","LOCALS",0)
          GlobalGT("DSS","LOCALS",0)
          GlobalGT("WPMW","LOCALS",0)
          GlobalGT("WGM","LOCALS",0)
          GlobalGT("WLR","LOCALS",0)
          GlobalGT("PENE","LOCALS",0)
          GlobalGT("WSPT","LOCALS",0)
THEN
	RESPONSE #100
          SetGlobal("HEALONCE","LOCALS",0)
          SetGlobal("WWB","LOCALS",0)
          SetGlobal("WPK","LOCALS",0)
          SetGlobal("WPS","LOCALS",0)
          SetGlobal("WSS","LOCALS",0)
          SetGlobal("WFS","LOCALS",0)
          SetGlobal("DSS","LOCALS",0)
          SetGlobal("WPMW","LOCALS",0)
          SetGlobal("WGM","LOCALS",0)
          SetGlobal("WLR","LOCALS",0)
          SetGlobal("PENE","LOCALS",0)
          SetGlobal("WSPT","LOCALS",0)
END
