// Remove the charge
IfTakenOut
  tmpargument = 0
  SetContent
  SetTargetToWhoeverIsHolding
    IfTargetIsAPlayer
      tmpargument = 2
      SendMessageNear


// Tell them what they've won...
IfGrabbed
  SetTargetToWhoeverIsHolding
  IfTargetIsAPlayer
    tmpargument = 0
    SendMessageNear

// What happens if it is used by a arcane spellcaster?
IfUsed
  SetTargetToWhoeverIsHolding
  tmpargument = [WMAG]
  IfTargetHasSkillID		//Can cast spell?

    //Aiming Cursor
    SetTargetToOwner
    GetContent
    tmpdistance = tmpargument > 8 + 4 < 6
    tmpturn = targetturn
    tmpx = targetx
    tmpy = targety
    Compass
    tmpdistance = targetz
    tmpargument = 4
    SpawnExactParticle

    //Charge it up!
    SetTargetToWhoeverIsHolding
    GetContent
    tmpx = tmpargument
    tmpy = 768
    IfXIsLessThanY
      tmpy = targetmanaflow / 2 + 512		//Need at least 4 mana flow
      IfXIsLessThanY		//Enough power?
        tmpy = 10
        tmpx = targetmana
        IfXIsMoreThanY
          tmpargument = 50
          CostTargetMana   
          GetContent
          tmpargument = tmpargument + 50
          SetContent

Else			//Player released the charge
  GetContent
  tmpx = tmpargument
  tmpy = 770
  IfXIsMoreThanY	//Finished Charging
    // Make the target shoot
    SetTargetToWhoeverIsHolding
      tmpargument = ACTIONZA
      CorrectActionForHand
      TargetDoAction

    // Figured out what it was
    MakeNameKnown
    MakeUsageKnown	

    //Spawn the magic effects
    SetTargetToWhoeverIsHolding
    GetContent
    tmpdistance = tmpargument > 8 + 4 < 6
    tmpturn = targetturn
    tmpx = targetx
    tmpy = targety
    Compass
    tmpdistance = targetz
    tmpargument = 0
    TeleportTarget
      tmpargument = 0
      SpawnExactParticle
      SpawnExactParticle
      SpawnExactParticle
    Else
      tmpargument = 3
      SendMessageNear
  

    //Play the spell effect sound
    tmpargument = 0
    tmpdistance = rand & 8000	+ 11000
    PlaySound

    IfNameIsKnown
      GetState
    Else
      MakeNameKnown
      MakeUsageKnown
      SetTargetToWhoeverIsHolding
      tmpargument = 30
      tmpdistance = EXPDARE
      GiveExperienceToTarget

  Else			//Not enough charged
    tmpy = 0
    GetContent
    tmpx = tmpargument
    IfXIsMoreThanY	//Only display message if charged
      tmpargument = 1
      SendMessageNear
  tmpargument = 0
  SetContent

// Put the little mana ball on the
// character's hand
GetContent
tmpx = tmpargument
tmpy = 0
IfXIsMoreThanY
  tmpturn = tmpargument * 20
  tmpdistance = SPAWNORIGIN
  tmpargument = 3
  SpawnAttachedSizedParticle

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

// Finish up
End
