// Create the character
IfSpawned
  KeepAction
  tmpargument = 0
  SetContent


// Say they pour over a book...
IfTakenOut
  tmpargument = 0
  SetContent
  SetTargetToWhoeverIsHolding
    IfTargetIsAPlayer
      tmpargument = 0
      SendMessageNear

IfTimeOut
  tmpargument = 500
  SetTime
  tmpargument = 0
  SetContent


// Allow it to be used
IfUsed
  tmpargument = 50
  SetReloadTime
  SetTargetToWhoeverIsHolding
    tmpx = 512
    tmpy = targetmanaflow
    IfXIsLessThanY
      // Give experience...
      IfUsageIsKnown
        GetState // NOP
      Else
        MakeUsageKnown
        MakeNameKnown
        tmpargument = 30
        tmpdistance = EXPSECRET
        GiveExperienceToTarget
      // Do the effect
      tmpargument = tmpx + 50
      CostTargetMana
        tmpx = rand & 2047 + targetint
        tmpy = 5888     // 23 int is perfect, 15 is near impossible
        IfXIsMoreThanY
          tmpargument = 1
          SendMessageNear
          // Drop on an enemy
          SetTargetToNearestEnemy
            tmpx = targetdistance
            tmpy = 600
            IfXIsLessThanY
              tmpx = targetx
              tmpy = targety
            Else
              tmpx = targetx
              tmpy = targety
              tmpturn = rand
              tmpdistance = 456
              Compass
          Else
            tmpx = targetx
            tmpy = targety
            tmpturn = rand
            tmpdistance = 456
            Compass
        Else
          // Drop around the caster...
          tmpargument = 2
          SendMessageNear
          tmpturn = rand
          tmpdistance = rand & 455
          tmpx = targetx
          tmpy = targety
          Compass
        tmpdistance = 0
        tmpargument = 0
        SpawnExactParticle


        // Skybolts are loud, so wake up sleepers...
        tmpargument = [WAKE]
        tmpdistance = [WAKE]
        OrderSpecialID
      Else
        // Not enough mana to cast...  Make a storm
        tmpargument = 3
        SendMessageNear
        tmpargument = 255
        SetReloadTime
        tmpargument = 1
        SetContent
        tmpargument = 50
        SetTime
    Else
      // Not enough flow to cast...
      tmpargument = 256
      CostTargetMana
        // Make a storm
        tmpargument = 3
        SendMessageNear
        tmpargument = 255
        SetReloadTime
        tmpargument = 1
        SetContent
        tmpargument = 50
        SetTime
        // Give experience...
        IfUsageIsKnown
          GetState // NOP
        Else
          MakeUsageKnown
          MakeNameKnown
          tmpargument = 30
          tmpdistance = EXPSECRET
          GiveExperienceToTarget
      Else
        tmpargument = 3
        SendMessageNear



// Return to spellbook, Do last!
IfDropped
  GetContent
  tmpx = tmpargument
  tmpy = 1
  IfXIsEqualToY
    tmpdistance = 11025
    PlaySound
  tmpargument = 0
  SetContent
  BecomeSpellbook
  DisaffirmCharacter
  tmpargument = ACTIONJB
  DoAction
  KeepAction
End
