Esempio n. 1
0
        internal static WeaponMelee OnDeserialize(NetworkReader reader)
        {
            string      weaponId = reader.ReadString();
            WeaponMelee weapon   = WeaponsResourceManager.GetWeapon(weaponId) as WeaponMelee;

            return(weapon);
        }
Esempio n. 2
0
        /// <summary>
        ///     Gets a weapon from the list
        /// </summary>
        /// <param name="weapon"></param>
        /// <returns></returns>
        internal TCWeapon GetWeapon(string weapon)
        {
            IEnumerable <NetworkedWeapon> result = from a in weapons
                                                   where a.Weapon == weapon
                                                   select a;

            return(WeaponsResourceManager.GetWeapon(result.FirstOrDefault()?.Weapon));
        }
        public static WeaponProjectile OnDeserialize(NetworkReader reader)
        {
            string           weaponId = reader.ReadString();
            WeaponProjectile weapon   = WeaponsResourceManager.GetWeapon(weaponId) as WeaponProjectile;

            weapon.currentProjectileCount = reader.ReadInt();
            weapon.isReloading            = reader.ReadBool();
            return(weapon);
        }
Esempio n. 4
0
        private void Start()
        {
            //Create all existing weapons on start
            for (int i = 0; i < weapons.Count; i++)
            {
                GameObject newWeapon =
                    Instantiate(WeaponsResourceManager.GetWeapon(weapons[i].Weapon).baseWeaponPrefab,
                                weaponsHolderSpot);

                newWeapon.SetActive(SelectedWeaponIndex == i);
            }
        }
Esempio n. 5
0
        private void RpcInstantiateWeaponOnClients(string weaponName)
        {
            if (weaponName == null)
            {
                return;
            }

            GameObject newWeapon = Instantiate(WeaponsResourceManager.GetWeapon(weaponName).baseWeaponPrefab,
                                               weaponsHolderSpot);

            if (isLocalPlayer)
            {
                LayersHelper.SetLayerRecursively(newWeapon, LayerMask.NameToLayer(weaponLayerName));
            }
        }
Esempio n. 6
0
        private void Start()
        {
            //Create all existing weapons on start
            for (int i = 0; i < weapons.Count; i++)
            {
                GameObject newWeapon =
                    Instantiate(WeaponsResourceManager.GetWeapon(weapons[i].Weapon).baseWeaponPrefab,
                                weaponsHolderSpot);

                if (isLocalPlayer)
                {
                    LayersHelper.SetLayerRecursively(newWeapon, LayerMask.NameToLayer(weaponLayerName));
                }

                newWeapon.SetActive(SelectedWeaponIndex == i);
            }
        }
        /// <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);
        }
    }
Esempio n. 8
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);
            }
        }