Esempio n. 1
0
    public void BuyPriAmmo()
    {
        PlayerWeapons   weapon  = playerWeapon.GetComponent <PlayerWeapons>();
        BulletInventory bullets = playerWeapon.GetComponent <BulletInventory>();

        if (bullets.GetPriTotalBullets() < bullets.GetPriMaxTotalBullets())
        {
            int BulletsToBuy = bullets.GetPriMaxTotalBullets() - bullets.GetPriTotalBullets();
            int CashNeeded   = 20 * BulletsToBuy;

            // if hvae enough money to fill up to max total bullets
            if (weapon.GetCash() >= CashNeeded)
            {
                weapon.AddCash(-CashNeeded);
                bullets.SetPriTotalBullets(bullets.GetPriMaxTotalBullets());
            }
            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() / 20;

                weapon.AddCash(-(BulletsICanBuy * 20));
                bullets.SetPriTotalBullets(bullets.GetPriTotalBullets() + BulletsICanBuy);
            }
        }
    }
Esempio n. 2
0
    public void SetPriWeapon(string PriWeapon)
    {
        if (primaryWeapon != "None" && primaryWeapon == PriWeapon)
        {
            return;
        }
        else
        {
            primaryWeapon = PriWeapon;
            BulletInventory bullets = GetComponent <BulletInventory>();
            bullets.SetPriCurrBullets(30);
            bullets.SetPriTotalBullets(0);
            bullets.SetPriMaxBullets(30);
            bullets.SetPriMaxTotalBullets(90);

            if (currWepType == "Primary")
            {
                if (primaryWeapon == "AK-47")
                {
                    weaponImage.sprite = AKImage;
                }
                else if (primaryWeapon == "M4A1")
                {
                    weaponImage.sprite = M4Image;
                }
            }
        }
    }
Esempio n. 3
0
    private void Awake()
    {
        ps = GetComponentInChildren <ParticleSystem>();
        if (ps == null)
        {
            throw new System.Exception("Gun - Need Particle System");
        }

        //asGunShot = GetComponent<AudioSource>();

        var audioSources = GetComponents <AudioSource>();

        if (audioSources.Length == 0)
        {
            throw new System.Exception("Gun - Need Audio Source");
        }

        foreach (var audio in audioSources)
        {
            if (audio.clip.name.Contains("Shot"))
            {
                asGunShot = audio;
            }
            else if (audio.clip.name.Contains("Reload"))
            {
                asGunReload = audio;
            }
        }

        // can be null
        bulletInventory = GetComponent <BulletInventory>();
    }
Esempio n. 4
0
    public void Fire()
    {
        BulletInventory bullets = GetComponent <BulletInventory>();
        PlayerWeapons   weapons = GetComponent <PlayerWeapons>();

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

        if (weapons.GetCurrWeaponType() == "Primary")
        {
            if (bullets.ShootPrimary(1))
            {
                SpawnBullet();
            }
        }
        else if (weapons.GetCurrWeaponType() == "Secondary")
        {
            if (bullets.ShootSecondary(1))
            {
                SpawnBullet();
            }
        }
    }
Esempio n. 5
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);
                }
            }
        }
    }
Esempio n. 6
0
 public void SetSecWeapon(string SecWeapon)
 {
     if (secondaryWeapon == SecWeapon)
     {
         return;
     }
     else
     {
         secondaryWeapon = SecWeapon;
         BulletInventory bullets = GetComponent <BulletInventory>();
         if (secondaryWeapon == "228 Compact")
         {
             bullets.SetSecCurrBullets(13);
             bullets.SetSecMaxBullets(13);
             bullets.SetSecTotalBullets(13);
             bullets.SetSecMaxTotalBullets(52);
         }
         else if (secondaryWeapon == "Desert Eagle")
         {
             bullets.SetSecCurrBullets(7);
             bullets.SetSecMaxBullets(7);
             bullets.SetSecTotalBullets(14);
             bullets.SetSecMaxTotalBullets(35);
         }
         if (currWepType == "Secondary")
         {
             if (secondaryWeapon == "228 Compact")
             {
                 weaponImage.sprite = CompactImage;
             }
             else if (secondaryWeapon == "Desert Eagle")
             {
                 weaponImage.sprite = DesertImage;
             }
         }
     }
 }
Esempio n. 7
0
	public void Remove(Bullet.Type type, int numBullet = 1) {
		int count = listBullet.Count;
		for (int i = 0; i < count; i++) {
			tmpBulletInventory = listBullet[i];
			if (tmpBulletInventory.type == type) {
				tmpBulletInventory.total -= numBullet;
			}
		}
	}
Esempio n. 8
0
	// Add bullet to eventory, numBullet is the number bullet player can shot
	public void Add(Bullet.Type type, int numBullet = 1) {
		int count = listBullet.Count;
		for (int i = 0; i < count; i++) {
			tmpBulletInventory = listBullet[i];
			if (tmpBulletInventory.type == type) {
				tmpBulletInventory.total += numBullet;
				
				return;
			}
		}
		
		listBullet.Add(new BulletInventory(type, numBullet));
	}
Esempio n. 9
0
	public bool IsBulletInStock(Bullet.Type type) {
		int count = listBullet.Count;
		
		for (int i = 0; i < count; i++) {
			tmpBulletInventory = listBullet[i];
			if (tmpBulletInventory.type == type && tmpBulletInventory.total > 0) {
				return true;
			}
		}
		
		return false;
	}
Esempio n. 10
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
                }
            }
        }
    }