//-----------------------------------------------------------------------
//AI was modified to have 50% to pick either hand
//Hand 1 = Charge a big spell very long and throw on long range
//Hand 2 = Cast a instant spell on medium range. Cooldown.

//Haha! Player was killed
IfTargetIsAPlayer
  tmpargument = 0
  GetXY
  IfXIsEqualToY
    tmpx = tmpx + 1
    SetXY
    tmpargument = 4
    PlayFullSound
    SendMessage
  IfTargetKilled
    tmpargument = 6
    PlayFullSound
    tmpargument = 3
    SendMessage
    SetTargetToSelf
    tmpargument = 0
    SetState

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

// Handle death by sending a message and other stuff
IfKilled
  tmpargument = 3
  PlayFullSound

  // Send messages
  IfTargetIsOnHatedTeam
    tmpargument = 0
  Else
    tmpargument = 1
  SendMessageNear

  // Drop goodies
  tmpargument = selfmoney
  DropMoney
  DropItems
  DropKeys

  // Award quest experience
  tmpargument = 100
  tmpdistance = EXPQUEST
  GiveExperienceToGoodTeam

  // Finish it up
  BeatModule
  EnableExport

  // Mark this module as beaten, hidden modules may open up
  tmpargument = [BEAT]
  AddIDSZ

  // Fix the end text
  ClearEndMessage
  tmpargument = 5
  AddEndMessage
  tmpargument = 6
  AddEndMessage
  tmpargument = 7
  AddEndMessage

  // Order team to die
  tmpdistance = [EVIL]
  tmpargument = [UNDO]
  OrderSpecialID

  // Put out the eyes
  DisaffirmCharacter
  SpawnPoof
  SpawnPoof
  SpawnPoof
  SpawnPoof

  // Make the character body
  tmpargument = 45
  SetBumpHeight

//------------------------------------------------------------------------------
// ZZ> Keep 'em guessin'
IfAttacked
  tmpargument = rand & 2
  PlaySound

  SetTargetToWhoeverAttacked
    IfTargetIsOnHatedTeam
      DoNothing
    Else
      SetTargetToOldTarget
      tmpargument = 1
      SetState
      tmpargument = 1
      SetTime

  tmpargument = 1
  IfStateIsNot
    tmpargument = 2
    IfStateIsNot
      // Teleport away...
      tmpargument = 1
      SetState
      tmpargument = 20
      SetTime

//------------------------------------------------------------------------------
// ZZ> For charging a spell...
IfStateIs10
  // Left hand
  IfTimeOut
    // Release the spell?
    tmpx = targetdistance - 128
    GetContent
    tmpy = 600
    IfXIsLessThanY
      // Distance is good...
      tmpx = selfmana
      tmpy = 256
      IfXIsMoreThanY
        tmpargument = 0
        SetState
      Else
        // Get more mana first
        tmpargument = LATCHLEFT
        PressLatchButton
    Else
      // Get closer first
      tmpargument = LATCHLEFT
      PressLatchButton
    tmpx = targetx - selfx > 1 + selfx
    tmpy = targety - selfy > 1 + selfy
    ClearWaypoints
    AddWaypoint
    tmpargument = 10
    SetTime
  Else
    // Keep charging
    tmpargument = LATCHLEFT
    PressLatchButton
    tmpx = targetx - selfx > 1 + selfx
    tmpy = targety - selfy > 1 + selfy
    ClearWaypoints
    AddWaypoint

//------------------------------------------------------------------------------
// ZZ> Find something to do...
IfTimeOut
  CleanUp     //Make ghouls ressurect

  IfStateIs15
    // Fall through to normal state
    tmpargument = 0
    SetState

  IfStateIs12
    IfTargetIsOnHatedTeam
      // Un-charged spell in left hand...
      tmpx = targetdistance - 128
      GetContent
      tmpy = tmpargument & 7 < 7
      IfXIsLessThanY
        // Distance is good...
        IfFacingTarget
          tmpargument = LATCHLEFT
          PressLatchButton
      tmpargument = 15
      SetState
      tmpargument = rand & 15 + 20
      SetTime
    Else
      tmpargument = 0
      SetState

  IfStateIs3
    // Pick a spell to use on the enemy...  Left or right
    IfTargetIsOnHatedTeam
      tmpx = rand & 1
      IfXIsEqualToY
        IfFacingTarget
          tmpx = targetdistance
          tmpy = 300
          IfXIsLessThanY
            tmpargument = LATCHRIGHT
            PressLatchButton
        tmpargument = 50
        SetTime
      Else
        tmpargument = 10
        SetState
        tmpargument = 40
        SetTime

  IfStateIs2
    // Halfway through a teleport
    tmpargument = rand & 15 + 35
    SetTime
    tmpargument = 7
    tmpdistance = selfz
    tmpx = selfx
    tmpy = selfy
    SpawnExactParticle
    tmpx = rand & 511 - 256 + selfx
    tmpy = rand & 511 - 256 + selfy
    Teleport
    tmpx = rand & 511 - 256 + selfx
    tmpy = rand & 511 - 256 + selfy
    Teleport
    SpawnExactParticle
    tmpargument = 15
    SetState

    // Face the target
    tmpx = targetx
    tmpy = targety
    ClearWaypoints
    AddWaypoint

  IfStateIs1
    // Want to start a teleport
    tmpargument = ACTIONMJ
    DoAction
      tmpargument = 2
      SetState
      tmpargument = 40  // Don't let 'em get hit out of it...
      SetDamageTime
      tmpargument = 16
      SetTime
    Else
      // Try again in a bit...
      tmpargument = 5
      SetTime

  IfStateIs0
    tmpargument = 20
    SetTime
    tmpx = rand & 255
    tmpy = 200
    IfXIsMoreThanY
      // Teleport...
      tmpargument = 1
      SetState
      SetTime
    Else
      // Go after enemies
      SetTargetToWideEnemy
        tmpargument = rand & 7 + 4
        SetTime
        tmpargument = 3
        SetState
        tmpx = targetx
        tmpy = targety
      Else
        // Wander around
        tmpargument = rand & 15 + 25
        SetTime
        tmpx = rand & 511 - 256 + selfspawnx
        tmpy = rand & 511 - 256 + selfspawny
      ClearWaypoints
      AddWaypoint

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