Beispiel #1
0
        internal IEnumerator ServerReloadPlayerWeapon()
        {
            Logger.Debug($"Reloading player `{transform.name}`'s active weapon");

            //Get our players weapon
            NetworkedWeapon networkedWeapon = GetActiveWeapon();

            networkedWeapon.IsReloading         = true;
            networkedWeapon.CurrentBulletAmount = 0;

            TargetSendWeaponStatus(GetClientConnection, networkedWeapon);

            int weaponIndex = SelectedWeaponIndex;

            TCWeapon weapon = networkedWeapon.GetTCWeapon();

            yield return(new WaitForSeconds(weapon.reloadTime));

            FinishReload(networkedWeapon, weaponIndex);
        }
        /// <summary>
        ///     Reads a <see cref="NetworkedWeapon" />
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        public static NetworkedWeapon ReadNetworkedWeapon(this NetworkReader reader)
        {
            //First, read the weapon
            TCWeapon weapon = WeaponsResourceManager.GetWeapon(reader.ReadString());

            //Return the NetworkedWeapon
            if (weapon != null)
            {
                return new NetworkedWeapon(weapon, false)
                       {
                           CurrentBulletAmount = reader.ReadInt32(),
                           IsReloading         = reader.ReadBoolean()
                       }
            }
            ;

            //Something went wrong
            Logger.Error("Sent networked weapon doesn't have a TCWeapon!");
            return(null);
        }
    }
Beispiel #3
0
        internal void AddWeapon(string weapon)
        {
            TCWeapon tcWeapon = WeaponsResourceManager.GetWeapon(weapon);

            if (tcWeapon == null)
            {
                return;
            }

            NetworkedWeapon netWeapon = new NetworkedWeapon(tcWeapon);

            weapons.Add(netWeapon);

            Logger.Debug($"Added weapon {weapon} for {transform.name} with {tcWeapon.maxBullets} bullets");

            //Setup the new added weapon, and stop any reloading going on with the current weapon
            TargetSendWeaponStatus(GetClientConnection, netWeapon);

            if (weapons.Count > 1)
            {
                SetClientWeaponIndex(weapons.Count - 1);
            }
        }