//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

IfTimeOut
  tmpargument = 25
  SetTime
  
  //Teleport around
  IfTargetIsOnHatedTeam
    tmpx = rand % 5
    tmpy = 1
    IfXIsEqualToY
      tmpx = 0            //20% chance to always teleport
    Else
      tmpx = targetdistance   //else only if very close
    tmpy = 300
    IfXIsLessThanY
      
      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
    
  tmpdistance = 128*25      //Detect 25 tiles away
  SetTargetToDistantEnemy
    SetTurnModeToWatchTarget
    
    //Begin charging disenchant?
    IfTargetIsFlying
      tmpargument = 7
      tmpx = targetx
      tmpy = targety
      tmpdistance = targetz
      SpawnExactParticle
      tmpargument = selfcontent + 1
      SetContent
      tmpargument = 125
      SetTime				//Don't teleport away while charging

      tmpargument = 0
      IfContentIs
        tmpx = 256			//Keep at least 2 tiles away (if not casting)
        tmpy = targetdistance
        IfXIsMoreThanY
          tmpargument = 0
          SetTime
    Else
      IfFacingTarget
        tmpx = targetdistance
        tmpy = 128*10
        IfXIsLessThanY
          tmpargument = LATCHRIGHT
          PressLatchButton
          SetOldTarget			//remember our enemy
          SetTargetToSelf
          tmpargument = [WAND]
          RestockTargetAmmoIDFirst	//Never run out of charges
          SetTargetToOldTarget		//Return target to enemy
          tmpargument = 50
          SetTime
  Else
    SetTurnModeToSpin
    SetTargetToSelf
    tmpargument = 0
    SetContent
  
  //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!
    
  //Don't go running into the pit!
  tmpx = selfx
  tmpy = selfy
  ClearWaypoints
  AddWaypoint
  
//Abort casting and escape!
IfBumped
  tmpargument = 0
  SetTime
  SetContent
IfAttacked
  tmpargument = 0
  SetTime
  SetContent

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

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