//Died...
IfKilled
  tmpargument = 0
  IfTargetIsOnSameTeam
    tmpargument = 1
  SendMessage

  //Drop goodies
  tmpargument = selfmoney
  DropItems
  DropMoney
  DropKeys

  // Put out the eyes
  DisaffirmCharacter

  // Make the character body
  tmpargument = 45
  SetBumpHeight

SetTargetToNearestEnemy
  tmpx = 25*128				//Detect 25 tiles away
  tmpy = targetdistance
  IfYIsLessThanX
    SetTurnModeToWatchTarget

    IfTargetIsFlying
      tmpargument = 7
      tmpx = targetx
      tmpy = targety
      tmpdistance = targetz
      SpawnExactParticle
      GetContent
      tmpargument = tmpargument + 1
      SetContent
      tmpargument = 125
      SetTime				//Don't teleport away while charging

      tmpargument = 0
      IfContentIs
        tmpx = 2 < 7			//Keep at least 2 tiles away (if not casting)
        tmpy = targetdistance
        IfXIsMoreThanY
          tmpargument = 0
          SetTime

    Else
      IfFacingTarget
        tmpx = rand & 255
        tmpy = 5
        IfXIsLessThanY
          tmpargument = LATCHRIGHT
          PressLatchButton
          SetOldTarget			//remember our enemy
          SetTargetToSelf
          tmpargument = [WAND]
          RestockTargetAmmoIDFirst	//Never run out of charges
          SetTargetToOldTarget		//Return target to enemy
      tmpargument = 125			//Don't teleport away while charging
      SetTime			//Teleport away!
			//Enemy is waaay close!
Else
  SetTurnModeToSpin
  SetTargetToSelf
  tmpargument = 0
  SetContent

//Don't go running into the pit!
tmpx = selfx
tmpy = selfy
ClearWaypoints
AddWaypoint

//Check if casting is finished
tmpx = selfcontent
tmpy = 75
IfXIsMoreThanY
  tmpargument = [DISP]
  DispelTargetEnchantID
  tmpargument = 0
  SetContent
  tmpargument = 3
  PlayFullSound
  SendMessage

  tmpargument = 0
  SetTime			//Teleport away!

//Abort casting and escape!
IfBumped
  tmpargument = 0
  SetTime
  SetContent
IfAttacked
  tmpargument = 0
  SetTime
  SetContent

//Teleport around
IfTimeOut
  tmpargument = 25
  SetTime

  tmpargument = rand % 6		//Randomize next teleport point
  SetState

  IfStateIs0
    tmpx = 9025
    tmpy = 12795

  IfStateIs1
    tmpx = 9298
    tmpy = 11589

  IfStateIs2
    tmpx = 10333
    tmpy = 12090

  IfStateIs3
    tmpx = 11094
    tmpy = 13652

  IfStateIs4
    tmpx = 11610
    tmpy = 12780

  IfStateIs5
    tmpx = 10019
    tmpy = 13399

  SpawnPoof		  //Spawn spelly effects at last point
  tmpargument = 4
  PlaySound

  tmpargument = ACTIONMJ
  DoAction
  Teleport

  SpawnPoof		  //Spawn spelly effects at new point
  tmpargument = 4
  PlaySound

//------------------------------------------------------------------------------
// ZZ> Put on some eyes
IfSpawned
  tmpargument = 0
  tmpdistance = 9
  SpawnAttachedParticle
  tmpdistance = 10
  SpawnAttachedParticle
  DisableExport

//------------------------------------------------------------------------------
End
//------------------------------------------------------------------------------
