private void CmdShootWeapon()
        {
            //First, get our active weapon
            NetworkedWeapon activeWeapon = weaponManager.GetActiveWeapon();

            //Reset our nextTimeToFire if we aren't using the same weapon from last time
            if (lastWeapon != activeWeapon.Weapon)
            {
                nextTimeToFire = 0;
                lastWeapon     = activeWeapon.Weapon;
            }

            //If our player is dead, or reloading, then return
            if (activeWeapon.IsReloading || playerManager.IsDead || Time.time < nextTimeToFire)
            {
                return;
            }

            if (activeWeapon.CurrentBulletAmount <= 0)
            {
                //Reload
                StartCoroutine(weaponManager.ServerReloadPlayerWeapon());
                return;
            }

            ServerShootWeapon(activeWeapon);

            //Update weapon stats
            weaponManager.TargetSendWeaponStatus(netIdentity.connectionToClient, activeWeapon);
        }
        private void ServerShootWeapon(NetworkedWeapon networkedWeapon)
        {
            nextTimeToFire = Time.time + 1f / networkedWeapon.GetTCWeapon().fireRate;

            networkedWeapon.CurrentBulletAmount--;

            RpcWeaponMuzzleFlash();

            SimulationHelper.SimulateCommand(playerManager, () => WeaponRayCast());
        }
Exemple #3
0
        /// <summary>
        ///     Updates ammo text
        /// </summary>
        /// <param name="netWeapon"></param>
        public void UpdateAmmoUI(NetworkedWeapon netWeapon)
        {
            if (clientUI == null || clientUI.WeaponManager == null)
            {
                return;
            }

            TCWeapon weapon = netWeapon.GetTCWeapon();

            ammoText.text    = netWeapon.CurrentBulletAmount.ToString();
            maxAmmoText.text = weapon.maxBullets.ToString();
            reloadTextGameObject.SetActive(netWeapon.IsReloading);
        }
        internal void ShootWeapon(bool buttonDown)
        {
            if (ClientUI.IsPauseMenuOpen)
            {
                return;
            }

            //Cache our current weapon
            NetworkedWeapon networkedWeapon = weaponManager.GetActiveWeapon();

            //Looks like the weapon isn't setup yet
            if (networkedWeapon == null)
            {
                return;
            }

            if (networkedWeapon.IsReloading)
            {
                return;
            }

            TCWeapon weapon = networkedWeapon.GetTCWeapon();

            if (weapon == null)
            {
                return;
            }

            if (buttonDown && weapon.fireMode == TCWeapon.WeaponFireMode.Semi)
            {
                ClientCallServerShoot();
            }
            if (buttonDown && weapon.fireMode == TCWeapon.WeaponFireMode.Auto)
            {
                InvokeRepeating(nameof(ClientCallServerShoot), 0f, 1f / weapon.fireRate);
            }
            if (!buttonDown && weapon.fireMode == TCWeapon.WeaponFireMode.Auto)
            {
                CancelInvoke(nameof(ClientCallServerShoot));
            }
        }
 private void OnWeaponUpdated(NetworkedWeapon weapon)
 {
     ui.hud.UpdateAmmoUI(weapon);
 }