//-----------------------------------------------------------------------------------------------
// Create the character
IfSpawned
  KeepAction

//-----------------------------------------------------------------------------------------------
// Draw message
IfTakenOut
  SetTargetToWhoeverIsHolding
    IfTargetIsAPlayer
      tmpargument = 0
      SendMessageNear

//-----------------------------------------------------------------------------------------------
// Allow it to be cast
IfUsed
  SetTargetToWhoeverIsHolding
  tmpdistance = 11025
  tmpargument = 0
  PlaySound
  MakeNameKnown
  MakeUsageKnown
  tmpargument = ACTIONZA
  CorrectActionForHand
  TargetDoAction
  tmpargument = 1
  SetState
  tmpargument = 20
  SetContent
  tmpargument = 30
  SetReloadTime

  tmpargument = [WMAG]
  IfTargetHasSkillID 
    //Spawn damage particles. Higher intelligence, more damage...

    // Spawn at least the Level 1 damage particle
    tmpargument = 2

    // Spawn the Level 2 damage particle
    tmpx = targetint
    tmpy = 17
    IfXIsMoreThanY
      tmpargument = 4

    // Spawn the Level 3 damage particle
    tmpx = targetint
    tmpy = 21
    IfXIsMoreThanY
      tmpargument = 5

    // Spawn the Level 4 damage particle
    tmpx = targetint
    tmpy = 24
    IfXIsMoreThanY
      tmpargument = 6

    // Spawn the Level 5 damage particle
    tmpx = targetint
    tmpy = 27
    IfXIsMoreThanY
      tmpargument = 7
    
    tmpx = targetint
    tmpy = 14
    IfXIsMoreThanY
      //Activate the spell
      tmpx = selfx
      tmpy = selfy
      tmpdistance = selfz
      SpawnExactParticle 
    Else
      SetTargetToWhoeverIsHolding
      tmpargument = 2
      SendMessageNear           

//-----------------------------------------------------------------------------------------------
// Shoot for a while
IfStateIs1
  GetContent
  tmpargument = tmpargument - 1
  SetContent
  tmpx = tmpargument
  tmpy = 0
  IfXIsMoreThanY
    // Spawn particles
    tmpx = selfx
    tmpy = selfy
    tmpdistance = selfz
    tmpargument = 0
    SpawnExactParticle
  Else
    tmpargument = 0
    SetState

//-----------------------------------------------------------------------------------------------
// Return to spellbook, Do last!
IfDropped
  tmpargument = 0
  SetContent
  BecomeSpellbook
  DisaffirmCharacter
  tmpargument = ACTIONJB
  DoAction
  KeepAction

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