Beispiel #1
0
        public void TryFire(bool alt)
        {
            if (Trigger == null || Trigger.AllowFire())
            {
                if ((AmmoAmount > 0 || AmmoAmount == -1) && Holder != null)
                {
                    if (lastFireTime.HasValue && Time.CurrentTime.Now - lastFireTime < MinTimeBetweenShots)
                    {
                        return;
                    }
                    lastFireTime = Time.CurrentTime.Now;

                    OnFire.Fire(this);
                    OnFired.Fire();
                    FireInternal(alt);
                    if (AmmoAmount > 0)
                    {
                        AmmoAmount--;

                        if (AmmoAmount == 0)
                        {
                            var alternative = Holder.Inventory.Items
                                              .WhereAs <Weapon>()
                                              .Where(w => w.Style == this.Style && w.AmmoAmount > 0)
                                              .OrderByDescending(w => w.PowerRanking)
                                              .FirstOrDefault();

                            if (alternative != null)
                            {
                                if (alternative.Style == WeaponStyle.Primary)
                                {
                                    Holder.Inventory.PrimaryWeapon = alternative;
                                }
                                else
                                {
                                    Holder.Inventory.ExplosiveWeapon = alternative;
                                }
                            }
                        }
                    }
                }
                else
                {
                    OnFireEmpty.Fire(this);
                }
            }
        }