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

IF
   AttackedBy([GOODCUTOFF],DEFAULT)
   !Allegiance(Myself,ENEMY)
THEN
   RESPONSE #100
      Enemy()
      SetGlobal("DeDeanoUnderAttack","GLOBAL",1)
END

IF
   TookDamage()
   Global("CosmoMantle","LOCALS",0)
THEN
   RESPONSE #100
      ReallyForceSpell(Myself,WIZARD_IMPROVED_MANTLE)
      SetGlobal("CosmoMantle","LOCALS",1)
END

IF
   See(NearestEnemyOfType([GOODCUTOFF]))
   False()
THEN
   RESPONSE #100
END

IF
   Global("DeDeanoUnderAttack","GLOBAL",1)
   Global("CosmoProtect","LOCALS",0)
THEN
   RESPONSE #100
      SetGlobal("CosmoProtect","LOCALS",1)
      SetGlobalTimer("CosmoCastAttack","LOCALS",6)
      ReallyForceSpell(Myself,WIZARD_MIRROR_IMAGE)
      ReallyForceSpell(Myself,WIZARD_STONE_SKIN)
END

IF
   AttackedBy(LastSeenBy(Myself),DEFAULT)
   !GlobalTimerNotExpired("CosmoCastAttack","LOCALS")
   Global("CosmoEfreeti","LOCALS",0)
THEN
   RESPONSE #100
      SetGlobal("CosmoEfreeti","LOCALS",1)
      SetGlobalTimer("CosmoCastAttack","LOCALS",6)
      ForceSpell(LastSeenBy(Myself),WIZARD_SUMMON_EFREET)
END

IF
   See(LastSeenBy(Myself))
   !GlobalTimerNotExpired("CosmoCastAttack","LOCALS")
   Global("CosmoCloudKill","LOCALS",0)
   Range(LastSeenBy(Myself),35)
THEN
   RESPONSE #100
      SetGlobalTimer("CosmoCastAttack","LOCALS",6)
      SetGlobal("CosmoCloudKill","LOCALS",1)
      ForceSpell(LastSeenBy(Myself),WIZARD_CLOUDKILL)
END

IF
   See(LastSeenBy(Myself))
   !GlobalTimerNotExpired("CosmoCastAttack","LOCALS")
   CheckStatGT(LastSeenBy(Myself),0,RESISTMAGICCOLD)
THEN
   RESPONSE #100
      SetGlobalTimer("CosmoCastAttack","LOCALS",6)
      ForceSpell(LastSeenBy(Myself),WIZARD_LOWER_RESISTANCE)
END

IF
   See(LastSeenBy(Myself))
   !GlobalTimerNotExpired("CosmoCastAttack","LOCALS")
   HPPercentLT(LastSeenBy(Myself),50)
   CheckStatLT(LastSeenBy(Myself),0,ACPIERCINGMOD)
THEN
   RESPONSE #100
      SetGlobalTimer("CosmoCastAttack","LOCALS",6)
      ForceSpell(LastSeenBy(Myself),WIZARD_CHROMATIC_ORB)
END

IF
   See(LastSeenBy(Myself))
   !GlobalTimerNotExpired("CosmoCastAttack","LOCALS")
   CheckStatLT(LastSeenBy(Myself),0,ACPIERCINGMOD)
THEN
   RESPONSE #100
      SetGlobalTimer("CosmoCastAttack","LOCALS",6)
      ForceSpell(LastSeenBy(Myself),WIZARD_MAGIC_MISSILE)
END

IF
   See(LastSeenBy(Myself))
   Range(LastSeenBy(Myself),4)
THEN
   RESPONSE #100
      EquipMostDamagingMelee()
      AttackReevaluate(LastSeenBy(Myself),8)
END
