// Create the character
IfSpawned
  IfStateIs0
    // It's an imported spell in hand
    tmpargument = 0
    SetState
    KeepAction
  Else
    // It's a falling sword
    MakeNameUnknown
    NotAnItem
    tmpargument = 0
    tmpdistance = SPAWNLAST
    SpawnAttachedParticle
    tmpargument = selfstate < 4 + 600     //Sword duration
    SetTime
    // Spawn another sword?
    IfStateIs1
      DoNothing
    Else
      tmpx = selfx
      tmpy = selfy
      tmpdistance = 55
      tmpturn = selfturn + 4192
      Compass
      tmpdistance = selfz + 100
      SpawnCharacterXYZ
        tmpargument = selfstate - 1	// Child will spawn more swords
        SetChildState

IfChanged
  // It's a spell in hand
  tmpargument = 0
  SetState
  KeepAction

// Sword AI
IfStateIs0
  DoNothing
Else
  IfTimeOut
    tmpargument = ACTIONKA
    DoAction
    tmpargument = 300
    SetTime
  IfHitGround
    tmpargument = 1
    PlaySound

// Spell AI
IfStateIs0
  // Remove the charge
  IfTakenOut
    tmpargument = 0
    SetContent
    SetTargetToWhoeverIsHolding
      IfTargetIsAPlayer
        tmpargument = 1
        IfNameIsKnown
          tmpargument = 2
        SendMessageNear
  // Allow it to be used
  IfUsed
    SetTargetToWhoeverIsHolding
    tmpargument = [WMAG]
    IfTargetHasSkillID
      tmpx = selfcontent
      tmpy = 256*6
      IfXIsLessThanY
        tmpy = targetmanaflow
        IfXIsLessThanY
          tmpx = 6
          tmpargument = tmpx
          CostTargetMana
            tmpargument = selfcontent + 6
            SetContent
            tmpx = targetx
            tmpy = targety
            tmpdistance = targetz
            tmpargument = 1
            SpawnExactParticle
  Else
    tmpx = selfcontent
    tmpy = 255
    IfXIsMoreThanY
      // Make the holder cast it
      SetTargetToWhoeverIsHolding
        tmpargument = ACTIONZA
        CorrectActionForHand
        TargetDoAction

        // Start dropping swords
        tmpx = targetx
        tmpy = targety
        tmpdistance = 130
        tmpargument = selfcontent > 8 + 1 < 12
        tmpturn = targetturn - tmpargument
        Compass
        tmpturn = tmpturn + 12192
        tmpdistance = targetz + 500
        SpawnCharacterXYZ
          // Set starting state
          tmpargument = selfcontent > 8 + 1	// Child will spawn more swords
          tmpargument = tmpargument < 1
          SetChildState

          // Identify stuff
          MakeNameKnown
          MakeUsageKnown

          // Cast sound
          tmpargument = 0
          PlaySound
        Else
          // Tried to cast in a wall?
          tmpargument = 0
          SendMessageNear
    Else
      tmpy = 0
      IfXIsMoreThanY
        // Didn't pump it enough
        tmpargument = 0
        SendMessageNear
    // Reset the charge counter
    tmpargument = 0
    SetContent
  // Return to spellbook, Do last!
  IfDropped
    tmpargument = 0
    SetContent
    BecomeSpellbook
    DisaffirmCharacter
    tmpargument = ACTIONJB
    DoAction
    KeepAction
End
