/////////////////////////
/// Magic Projectile ///////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/// D0: MP cost per use.                                          ///
/// D1: Speed that Subweapon Travels across screen; suggest 240.  ///
/// D2: Amount of Damage that Subweapon Deals to Enemies.         ///
/// D3: Sprite used by Subweapon; select from:                    ///
///            Quest->Graphics->Sprites->WeaponsMisc.             ///   
/// D4: Maximum number of projectiles allowed at once.            ///
/// D5: Error Sound Effects.                                      ///
/// D6: Item Sound Effects.  Select sounds from:                  ///
///            Quest->Audio->SFX Data                             ///   
/// D7: Delay before Link can use item again.                     ///     
/////////////////////////////////////////////////////////////////////


item script twoPart
{
    void run(int magicCost, int speed, int power, int spriteUsed, int maxProjectiles, int errorSFX, int SFX_ITEM, int nouse)
    {
    if (Game->Counter[CR_MAGIC] > magicCost && NumLWeaponsOf(LW_MAGIC) < maxProjectiles) //Fill in the numbers for magic consumption and number of projectiles allowed on screen
        {
        Game->Counter[CR_MAGIC] -= magicCost; //fill in the magic consumption here as well
        lweapon magic = Screen->CreateLWeapon(LW_MAGIC);
        magic->UseSprite(spriteUsed); // the number of the sprite used for the projectile. Use two tiles, the first for up/down, the second for left/right
        magic->X = Link->X; //Find Link's Position X
        magic->Y = Link->Y; //Find Link's Position Y
        magic->Dir = Link->Dir; //Find the Direction that Link is facing.
        magic->Step = speed; // the speed the projectile travels
        magic->Damage = 0; //the damage the projectile will do
        lweapon sonic = Screen->CreateLWeapon(LW_SCRIPT1);
        sonic->Dir = Link->Dir; //Find the Direction that Link is facing.
        sonic->UseSprite(spriteUsed);
        sonic->Step = speed; // the speed the projectile travels
        currentDamage = rollDie(power);;
        sonic->Damage = currentDamage; //the damage the projectile will do
        Game->PlaySound(SFX_ITEM); // the sound effect for the weapon
		Link->ItemJinx = (nouse * 1); //Set delay between firing. Change multiplier if desired, but set base in argument D7.
        if(Link->Dir == DIR_UP) {
            sonic->X = magic->X+0;
            sonic->Y = magic->Y-16;
            }
        
        if(Link->Dir == DIR_DOWN) //If Link is facing down...
            {
            sonic->X = magic->X+0;
            sonic->Y = magic->Y+16;
            magic->Flip = 2; //Change direction of spriteUsed to down.
            sonic->Flip = 2; //Change direction of spriteUsed to down.
            }
        if(Link->Dir == DIR_RIGHT) //If Link is facing right.
            {
            sonic->X = magic->X+16;
            sonic->Y = magic->Y+0;
            magic->Tile += 1; //Use next tile as well.
            sonic->Tile += 1; //Use next tile as well.
            }
        if(Link->Dir == DIR_LEFT)
            {
            sonic->X = magic->X-16;
            sonic->Y = magic->Y-0;
            magic->Tile += 1; //If Link is facing left.
            magic->Flip = 1; //Flip spriteUsed tile and use next tile as well.
            sonic->Tile += 1; //If Link is facing left.
            sonic->Flip = 1; //Flip spriteUsed tile and use next tile as well.
            }
		
        }
        
		else{
    Game->PlaySound(errorSFX); //If out of MP, play ERROR SOund Effects.
    }
    }
}