//METEOR SWARM AI
tmpx = selfstate		//number of meteors to spawn minus 1
tmpy = 1
IfXIsMoreThanY
  NotAnItem
  tmpargument = 1
  ChangeArmor			//invisible

  IfTimeOut
    tmpargument = rand % 15 + 35    //time between every meteor
    SetTime

    //Spawn one meteor
    tmpargument = 0
    SetTargetToNearbyEnemy
      tmpdistance = targetz
      tmpx = rand % 250 + targetx - 125
      tmpy = rand % 250 + targety - 125
    Else
      tmpdistance = selfz
      tmpx = rand % 250 + selfx - 125
      tmpy = rand % 250 + selfy - 125
    SpawnExactParticle

    tmpargument = selfstate - 1		//1 meteor used
    SetState

    tmpx = selfstate
    tmpy = 1
    IfXIsEqualToY
      GoPoof			//swarm is finished


//SPELL AI
Else
  
  //Clong
  IfHitGround
    tmpargument = 1
    PlaySound
	
  // Remove the charge
  IfTakenOut
    tmpargument = 0
    SetContent
    SetTargetToWhoeverIsHolding
      IfTargetIsAPlayer
        tmpargument = 0
        SendMessageNear


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

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

      //Aiming Cursor
      SetTargetToOwner
      GetContent
      tmpdistance = 500
      tmpturn = targetturn
      tmpx = targetx
      tmpy = targety
      Compass
      tmpdistance = targetz
      tmpargument = 7
      SpawnExactParticle

      //Charge it up!
      SetTargetToWhoeverIsHolding
      tmpx = selfcontent
      tmpy = 3840					//Max charge
      IfXIsLessThanY
        tmpy = targetmanaflow
        IfXIsLessThanY		//Enough power?
          tmpy = 10
          tmpx = targetmana
          IfXIsMoreThanY
            tmpargument = 9			//Mana cost
            CostTargetMana   
            tmpargument = selfcontent + 7		//Casting speed
            SetContent

  Else			//Player released the charge
    tmpx = selfcontent
    tmpy = 1024		//minimum needed charge
    IfXIsMoreThanY

      // Make the target shoot
      SetTargetToWhoeverIsHolding
        tmpargument = ACTIONZA
        CorrectActionForHand
        TargetDoAction

      //Spawn a meteor swarm spawner
      SetTargetToWhoeverIsHolding
      GetContent
      tmpdistance = 500			//How far away from caster
      tmpturn = targetturn
      tmpx = targetx
      tmpy = targety
      Compass

      tmpdistance = 0			//velocity
      SpawnCharacter
      GetContent
      tmpargument = tmpargument > 7
      tmpargument = tmpargument
      SetChildState			//Tell him how many to spawn

      tmpargument = 300
      SetReloadTime


    Else			//Not enough charged
      tmpx = selfcontent
      tmpy = 12
      IfXIsMoreThanY	//Only display message if charged
        tmpargument = 3
        SendMessageNear
    tmpargument = 0
    SetContent

// Put the little mana ball on the
// character's hand
IfStateIs0
  tmpx = selfcontent
  tmpy = 0
  IfXIsMoreThanY
    tmpturn = selfcontent * 5 + 5000
    tmpdistance = SPAWNLAST
    tmpargument = 7
    SpawnAttachedSizedParticle

// Finish up
End
