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);
                }
            }
        }
    }
Exemple #2
0
    public void ReloadCurrBullets()
    {
        soundEffectSource        = soundEffectSound.GetComponent <AudioSource>();
        soundEffectSource.volume = PlayerPrefs.GetFloat("sfxVol", 1);

        BulletInventory bullets = GetComponent <BulletInventory>();
        PlayerWeapons   weapons = GetComponent <PlayerWeapons>();

        if (Time.timeScale == 0.0f) // if  paused, return
        {
            return;
        }

        if (weapons.GetCurrWeaponType() == "Primary")
        {
            // Check if need to reload
            if (bullets.GetPriCurrBullets() < bullets.GetPriMaxBullets())
            {
                // How many bullets to load
                int BulletsToLoad = bullets.GetPriMaxBullets() - bullets.GetPriCurrBullets();

                if (bullets.GetPriTotalBullets() > 0)
                {
                    if (BulletsToLoad <= bullets.GetPriTotalBullets())
                    {
                        soundEffectSource.Play();

                        bullets.SetPriCurrBullets(bullets.GetPriMaxBullets());
                        bullets.AddPriTotalBullets(-BulletsToLoad);
                    }
                    else
                    {
                        soundEffectSource.Play();

                        bullets.SetPriCurrBullets(bullets.GetPriCurrBullets() + bullets.GetPriTotalBullets());
                        bullets.AddPriTotalBullets(-(bullets.GetPriTotalBullets()));
                    }
                }
                else
                {
                    //play another sound
                }
            }
        }
        else if (weapons.GetCurrWeaponType() == "Secondary")
        {
            // Check if need to reload
            if (bullets.GetSecCurrBullets() < bullets.GetSecMaxBullets())
            {
                // How many bullets to load
                int BulletsToLoad = bullets.GetSecMaxBullets() - bullets.GetSecCurrBullets();

                if (bullets.GetSecTotalBullets() > 0)
                {
                    if (BulletsToLoad <= bullets.GetSecTotalBullets())
                    {
                        soundEffectSource.Play();

                        bullets.SetSecCurrBullets(bullets.GetSecMaxBullets());
                        bullets.AddSecTotalBullets(-BulletsToLoad);
                    }
                    else
                    {
                        soundEffectSource.Play();

                        bullets.SetSecCurrBullets(bullets.GetSecCurrBullets() + bullets.GetSecTotalBullets());
                        bullets.AddSecTotalBullets(-(bullets.GetSecTotalBullets()));
                    }
                }
                else
                {
                    // Do not play sound / Play another sound
                }
            }
        }
    }