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

// Spell AI
IfUsed
  tmpx = selfcontent
  tmpy = 1024
  IfXIsLessThanY
    SetTargetToWhoeverIsHolding
    tmpargument = [WMAG]
    IfTargetHasSkillID
      tmpy = targetmanaflow
      IfXIsLessThanY
        tmpx = 8
        tmpargument = tmpx
        CostTargetMana
          GetContent
          tmpargument = tmpargument + tmpx
          SetContent
          tmpargument = tmpargument > 8
          SetState
Else
  tmpx = selfcontent
  tmpy = 256
  IfXIsMoreThanY
    // Make the target shoot
    SetTargetToWhoeverIsHolding
      tmpargument = ACTIONZA
      CorrectActionForHand
      TargetDoAction

    // Figured out what it was
    MakeNameKnown
    MakeUsageKnown
    
    // unleash the ring of fire
    SetTargetToWhoeverIsHolding
    tmpx = targetx
    tmpy = targety
    tmpdistance = targetz
    IfStateIs1
      tmpargument = 1
      SpawnExactParticle
      tmpargument = 100
      tmpdistance = DAMAGEFIRE
      DamageTarget
    IfStateIs2
      tmpargument = 2
      SpawnExactParticle
      tmpargument = 256
      tmpdistance = DAMAGEFIRE
      DamageTarget
    IfStateIs3
      tmpargument = 5
      SpawnExactParticle
      tmpargument = 600
      tmpdistance = DAMAGEFIRE
      DamageTarget
    IfStateIs4
      tmpargument = 6
      SpawnExactParticle
      tmpargument = 1000
      tmpdistance = DAMAGEFIRE
      DamageTarget
    tmpargument = 0
    PlaySound
    
  // Reset the charge counter
  tmpargument = 0
  SetContent

// Put the little mana ball on the
// character's hand
tmpx = selfcontent
tmpy = 0
IfXIsMoreThanY
  tmpturn = tmpargument < 4 + 500
  tmpdistance = SPAWNORIGIN
  tmpargument = 0
  SpawnAttachedSizedParticle

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

End
