Пример #1
0
        public void Activate()
        {
            List <Type> ammoTypes = Utils.GetTypesWithAttribute <Ammo, SpawnableAttribute>();

            if (Category != null)
            {
                List <Type> filteredTypes = new();

                // Just spawn ammo that has spawnable weapons
                List <Type> wepTypes = Utils.GetTypesWithAttribute <Weapon, SpawnableAttribute>();

                foreach (Type ammoType in ammoTypes)
                {
                    foreach (Type wepType in wepTypes)
                    {
                        WeaponAttribute weaponAttribute = Utils.GetAttribute <WeaponAttribute>(wepType);

                        if (weaponAttribute != null && weaponAttribute.Category == Category && weaponAttribute.PrimaryAmmoName == Utils.GetLibraryName(ammoType))
                        {
                            if (!filteredTypes.Contains(ammoType))
                            {
                                filteredTypes.Add(ammoType);
                            }
                        }
                    }
                }

                ammoTypes = filteredTypes;
            }

            if (ammoTypes.Count <= 0)
            {
                return;
            }

            Type typeToSpawn = ammoTypes[Utils.RNG.Next(ammoTypes.Count)];

            Ammo ent = Utils.GetObjectByType <Ammo>(typeToSpawn);

            ent.Position = Position;
            ent.Rotation = Rotation;
            ent.Spawn();
        }
Пример #2
0
        public override void Simulate(Client owner)
        {
            if (TimeSinceDeployed < WeaponInfo.DeployTime)
            {
                return;
            }

            ResetBurstFireCount(CurrentClip, InputButton.Attack1);

            if (Input.Pressed(InputButton.Drop) && Input.Down(InputButton.Run) && ClipAmmo > 0 && !CurrentClip.UnlimitedAmmo)
            {
                if (CurrentClip.AmmoName != null && CurrentClip.CanDropAmmo)
                {
                    Type type = Utils.GetTypeByLibraryName <Ammo>(CurrentClip.AmmoName);

                    if (type != null)
                    {
                        if (IsServer)
                        {
                            Ammo ammoBox = Utils.GetObjectByType <Ammo>(type);
                            ammoBox.LastDropOwner     = Owner;
                            ammoBox.TimeSinceLastDrop = 0f;
                            ammoBox.Position          = Owner.EyePosition + Owner.EyeRotation.Forward * AMMO_DROP_POSITION_OFFSET;
                            ammoBox.Rotation          = Owner.EyeRotation;
                            ammoBox.Velocity          = Owner.EyeRotation.Forward * AMMO_DROP_VELOCITY;
                            ammoBox.SetCurrentAmmo(ClipAmmo);
                        }

                        TakeAmmo(CurrentClip, ClipAmmo);
                    }
                }
            }

            if (IsReloading && TimeSinceReload >= CurrentReloadTime)
            {
                OnReloadFinish(CurrentClip);
            }

            if (!IsReloading || CurrentClip.IsPartialReloading)
            {
                if (CanReload())
                {
                    Reload(CurrentClip);
                }

                if (!Owner.IsValid())
                {
                    return;
                }

                if (CanAttack(CurrentClip, InputButton.Attack1))
                {
                    using (LagCompensation())
                    {
                        Attack(CurrentClip);
                    }
                }
            }

            if (!Owner.IsValid())
            {
                return;
            }

            if (Secondary != null && (!IsReloading || CurrentClip.IsPartialReloading) && !CanZoom)
            {
                CurrentClip = Secondary;

                if (CanAttack(CurrentClip, InputButton.Attack2))
                {
                    using (LagCompensation())
                    {
                        Attack(CurrentClip);
                    }
                }

                CurrentClip = Primary;
            }

            // TODO Zoom
        }
Пример #3
0
        public virtual void Activate()
        {
            List <Type> wepTypes = Utils.GetTypesWithAttribute <Weapon, SpawnableAttribute>();

            if (Category != null)
            {
                List <Type> filteredTypes = new();

                foreach (Type type in wepTypes)
                {
                    WeaponAttribute weaponAttribute = Utils.GetAttribute <WeaponAttribute>(type);

                    if (weaponAttribute != null && weaponAttribute.Category == Category)
                    {
                        filteredTypes.Add(type);
                    }
                }

                wepTypes = filteredTypes;
            }

            if (wepTypes.Count <= 0)
            {
                return;
            }

            Type   weaponTypeToSpawn = Utils.RNG.FromList(wepTypes);
            Weapon weapon            = Utils.GetObjectByType <Weapon>(weaponTypeToSpawn);

            if (weapon == null || !weapon.IsValid)
            {
                Log.Debug($"Failed to initialize random weapon of type '{weaponTypeToSpawn}': {weapon}");

                return;
            }

            weapon.Position = Position;
            weapon.Rotation = Rotation;
            weapon.Spawn();

            string ammoName = weapon.Primary.AmmoName;

            if (ammoName == null)
            {
                return; // If the choosen weapon doesn't use ammo we don't need to spawn any
            }

            Type ammoType = Utils.GetTypeByLibraryName <Ammo>(ammoName);

            if (ammoType == null)
            {
                return; // If the choosen weapon doesn't use ammo we don't need to spawn any
            }

            if (!ammoType.IsSubclassOf(typeof(Ammo)))
            {
                Log.Error($"The defined ammo type {ammoType.Name} for the weapon {weapon.Info.LibraryName} is not a descendant of {typeof(Ammo).Name}.");

                return;
            }

            for (int i = 0; i < AmmoToSpawn; i++)
            {
                Ammo ammo = Utils.GetObjectByType <Ammo>(ammoType);
                ammo.Position = weapon.Position + Vector3.Up * AMMO_DISTANCE_UP;
                ammo.Spawn();
            }
        }