public void UpdateInventoryCache()
        {
            if (SessionCore.IsUnloading)
            {
                return;
            }
            lock (InventoryLock)
            {
                InventoriesStatus.Clear();
                OnboardInventoryOwners.Clear();
                if (!HasWatchers)
                {
                    return;
                }
                ShallShowDebug = true;
                System.Diagnostics.Stopwatch Watch = new System.Diagnostics.Stopwatch();
                Watch.Start();
                List <IMyTerminalBlock>       trash  = new List <IMyTerminalBlock>();
                Func <IMyTerminalBlock, bool> Puller = (Block) =>
                {
                    if (IsValidInventory(Block))
                    {
                        OnboardInventoryOwners.Add(Block);
                    }
                    return(false);
                };
                Term.GetBlocksOfType(trash, Puller);

                foreach (var Watcher in Watchers)
                {
                    InventoriesPerWatcher[Watcher] = RefreshAccessibleInventories(Watcher);
                }
                LastUpdate   = DateTime.Now;
                NeedsRefresh = false;

                Watch.Stop();
                Watch.Report(Grid.CustomName, "Grid inventories refresh", UseAsync: true);
            }
        }
Exemple #2
0
        /// <summary>
        /// Builds cache of accessible inventories on this ship.
        /// </summary>
        void BuildInventoryCache()
        {
            OnboardInventoryOwners.Clear();
            if (!(Tool.IsFunctional && Tool.UseConveyorSystem))
            {
                return;
            }
            //SessionCore.DebugWrite($"{Tool.CustomName}.BuildInventoryCache()", "Rebuilding cache...", IsExcessive: true);
            List <IMyTerminalBlock> trash = new List <IMyTerminalBlock>();

            OnboardInventoryOwners.Add(Tool);
            Func <IMyTerminalBlock, bool> Puller = (Block) =>
            {
                if (Block == null)
                {
                    return(false);
                }
                if (!Block.HasPlayerAccess(Tool.OwnerId) || !Block.HasInventory)
                {
                    return(false);
                }
                if (Block == Tool)
                {
                    return(false);
                }
                if (Block.IsOfType <IMyCargoContainer>() || Block.IsOfType <IMyAssembler>() || Block.IsOfType <IMyShipConnector>() || Block.IsOfType <IMyCollector>())
                {
                    IMyInventory Inventory = Block.GetInventories().First();
                    if (Inventory.IsConnectedTo(ToolCargo))
                    {
                        OnboardInventoryOwners.Add(Block);
                    }
                }
                return(false);
            };

            Term.GetBlocksOfType(trash, Puller);
        }