Exemple #1
0
    public void BuySecAmmo()
    {
        PlayerWeapons   weapon  = playerWeapon.GetComponent <PlayerWeapons>();
        BulletInventory bullets = playerWeapon.GetComponent <BulletInventory>();

        if (weapon.GetSecWeapon() == "228 Compact")
        {
            if (bullets.GetSecTotalBullets() < bullets.GetSecMaxTotalBullets())
            {
                int BulletsToBuy = bullets.GetSecMaxTotalBullets() - bullets.GetSecTotalBullets();
                int CashNeeded   = 7 * BulletsToBuy;

                // if hvae enough money to fill up to max total bullets
                if (weapon.GetCash() >= CashNeeded)
                {
                    weapon.AddCash(-CashNeeded);
                    bullets.SetSecTotalBullets(bullets.GetSecMaxTotalBullets());
                }
                else
                {
                    // Not enough money to buy all of the "needed to fill up to max total bullets"
                    // So we buy until have no money
                    int BulletsICanBuy = weapon.GetCash() / 7;

                    weapon.AddCash(-(BulletsICanBuy * 7));
                    bullets.SetSecTotalBullets(bullets.GetSecTotalBullets() + BulletsICanBuy);
                }
            }
        }
        else if (weapon.GetSecWeapon() == "Desert Eagle")
        {
            if (bullets.GetSecTotalBullets() < bullets.GetSecMaxTotalBullets())
            {
                int BulletsToBuy = bullets.GetSecMaxTotalBullets() - bullets.GetSecTotalBullets();
                int CashNeeded   = 28 * BulletsToBuy;

                // if hvae enough money to fill up to max total bullets
                if (weapon.GetCash() >= CashNeeded)
                {
                    weapon.AddCash(-CashNeeded);
                    bullets.SetSecTotalBullets(bullets.GetSecMaxTotalBullets());
                }
                else
                {
                    // Not enough money to buy all of the "needed to fill up to max total bullets"
                    // So we buy until have no money
                    int BulletsICanBuy = weapon.GetCash() / 28;

                    weapon.AddCash(-(BulletsICanBuy * 28));
                    bullets.SetSecTotalBullets(bullets.GetSecTotalBullets() + BulletsICanBuy);
                }
            }
        }
    }