/// <summary>
        /// Close all weapons
        /// </summary>
        public void Close()
        {
            //foreach (MySmallShipGunBase gun in GetMountedWeaponstWithHarvesterAndDrill())
            //{
            //    gun.Close();
            //}
            foreach (MyWeaponSlot weaponSlot in WeaponSlots)
            {
                if (weaponSlot != null)
                {
                    weaponSlot.OnWeaponDismouting -= m_weaponDismounting;
                    weaponSlot.OnWeaponMounting   -= m_weaponMounting;
                    weaponSlot.Close();
                }
            }
            WeaponSlots.Clear();
            WeaponSlots = null;

            DrillSlot.OnWeaponDismouting -= m_weaponDismounting;
            DrillSlot.OnWeaponMounting   -= m_weaponMounting;
            DrillSlot.Close();
            DrillSlot = null;

            HarvestingDeviceSlot.OnWeaponDismouting -= m_weaponDismounting;
            HarvestingDeviceSlot.OnWeaponMounting   -= m_weaponMounting;
            HarvestingDeviceSlot.Close();
            HarvestingDeviceSlot = null;

            m_allMountedWeapons.Clear();
            m_allMountedWeapons = null;

            AmmoAssignments.Close();
            AmmoAssignments = null;

            AmmoInventoryItems.Close();
            AmmoAssignments = null;

            Ship.Inventory.OnInventoryContentChange -= OnInventoryContentChange;
            Ship = null;

            m_helperInventoryItems.Clear();
            m_helperInventoryItems = null;

            m_isClosed = true;
        }
        /// <summary>
        /// Returns amount of ammo which is bind at fire key
        /// </summary>
        /// <param name="key">Fire key</param>
        /// <returns></returns>
        public int GetAmountOfAmmo(MyMwcObjectBuilder_FireKeyEnum key)
        {
            if (AmmoInventoryItems.Count() == 0 || AmmoAssignments.Count() == 0)
            {
                return(0);
            }

            //Get ammo type
            MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum ammoType = AmmoAssignments.GetAmmoType(key);

            if (ammoType == 0)
            {
                return(0);
            }

            //Get amount
            int result = 0;

            foreach (MyInventoryItem ammoInventoryItem in AmmoInventoryItems.GetAmmoInventoryItems(ammoType))
            {
                result += (int)ammoInventoryItem.Amount;
            }
            return(result);
        }
        /// <summary>
        /// Shot from weapon which is bind at fire key
        /// </summary>
        /// <param name="key">Fire key</param>
        void FirePrivate(MyMwcObjectBuilder_FireKeyEnum key)
        {
            //Do nothing if there are no ammo or weapons or assignments


            this.m_ship.InitGroupMaskIfNeeded();

            var drill = GetMountedDrill();

            if ((!MySession.Is25DSector && (drill != null && (drill.CurrentState == MyDrillStateEnum.Activated || drill.CurrentState == MyDrillStateEnum.Drilling))) ||
                (MySession.Is25DSector && drill != null && key == MyMwcObjectBuilder_FireKeyEnum.Secondary))
            {
                drill.Shot(null);
                return;
            }

            List <MySmallShipGunBase> mountedGuns = GetMountedWeaponsWithHarvesterAndDrill();

            /*if (AmmoInventoryItems.Count() == 0 || AmmoAssignments.Count() == 0 || mountedGuns.Count == 0)
             *  return;*/

            MyAmmoAssignment ammoAssignment = AmmoAssignments.GetAmmoAssignment(key);

            //If type or group is not found in object builders, do nothing
            if (ammoAssignment == null)
            {
                return;
            }

            //If type and group is bad combination, do nothing
            if (!MyGuiSmallShipHelpers.GetWeaponType(ammoAssignment.AmmoType, ammoAssignment.AmmoGroup).HasValue)
            {
                return;
            }

            MyInventoryItem usedAmmoInventoryItem = null;

            foreach (MyInventoryItem ammoItem in AmmoInventoryItems.GetAmmoInventoryItems(ammoAssignment.AmmoType))
            {
                if (ammoItem.Amount > 0)
                {
                    usedAmmoInventoryItem = ammoItem;
                    break;
                }
            }

            bool thereWasShot         = false;
            bool wasCountedMuzzleTime = false;

            //  Shot from gun
            foreach (MySmallShipGunBase gun in mountedGuns)
            {
                if (MyGuiSmallShipHelpers.GetWeaponType(ammoAssignment.AmmoType, ammoAssignment.AmmoGroup).Value == gun.WeaponType)
                {
                    bool shot = false;
                    if (usedAmmoInventoryItem != null && usedAmmoInventoryItem.Amount > 0)
                    {
                        shot = gun.Shot((MyMwcObjectBuilder_SmallShip_Ammo)usedAmmoInventoryItem.GetInventoryItemObjectBuilder(false));
                        if (shot && MyMultiplayerGameplay.IsRunning && !m_ship.IsDummy)
                        {
                            var ammo = ((MyMwcObjectBuilder_SmallShip_Ammo)usedAmmoInventoryItem.GetInventoryItemObjectBuilder(false)).AmmoType;
                            MyMultiplayerGameplay.Static.Shoot(this.m_ship, this.m_ship.WorldMatrix, gun.WeaponType, ammo, this.Ship.TargetEntity, gun.LastShotId);
                        }
                    }
                    else
                    {
                        if (m_noAmmoSoundDelay + 175 < MyMinerGame.TotalGamePlayTimeInMilliseconds)
                        {
                            Audio.MyAudio.AddCue2dOr3d(Ship, Audio.MySoundCuesEnum.WepNoAmmo, Ship.GetPosition(), Ship.WorldMatrix.Forward, Ship.WorldMatrix.Up, Ship.Physics.LinearVelocity);
                            m_noAmmoSoundDelay = MyMinerGame.TotalGamePlayTimeInMilliseconds;
                        }
                    }

                    if (shot)
                    {
                        Ship.Inventory.RemoveInventoryItemAmount(ref usedAmmoInventoryItem, 1f);
                        thereWasShot = true;
                        Ship.WeaponShot(gun, ammoAssignment);
                    }

                    //  If we shot from gun that uses projectiles, we need to remember it as last time of muzzle flash
                    if ((shot == true) &&
                        MyGuiSmallShipHelpers.IsAmmoInGroup(ammoAssignment.AmmoType, MyMwcObjectBuilder_AmmoGroupEnum.Bullet) &&
                        !wasCountedMuzzleTime)
                    {
                        MuzzleFlashLastTime  = MyMinerGame.TotalGamePlayTimeInMilliseconds;
                        wasCountedMuzzleTime = true;
                    }
                }
            }

            if (thereWasShot == true)
            {
                Ship.IncreaseHeadShake(MyHeadShakeConstants.HEAD_SHAKE_AMOUNT_AFTER_GUN_SHOT);
            }
        }
 /// <summary>
 /// Fills ammo inventory items from ship inventory
 /// </summary>
 private void FillAmmoInventoryItemsFromInventory()
 {
     m_helperInventoryItems.Clear();
     Ship.Inventory.GetInventoryItems(ref m_helperInventoryItems, MyMwcObjectBuilderTypeEnum.SmallShip_Ammo, null);
     AmmoInventoryItems.Init(m_helperInventoryItems);
 }