コード例 #1
0
 public static void ReadMissingComponentsSmart(this IMySlimBlock Block, Dictionary <string, int> addToDictionary)
 {
     if (Block.BuildIntegrity == Block.MaxIntegrity && Block.Integrity == Block.MaxIntegrity)
     {
         return;
     }
     Block.GetMissingComponents(addToDictionary);
     if (Block.StockpileAllocated)
     {
         Block.GetMissingComponents(addToDictionary);
     }
     else
     {
         foreach (var Component in (Block.BlockDefinition as Sandbox.Definitions.MyCubeBlockDefinition).Components)
         {
             string Name = Component.Definition.Id.SubtypeName;
             if (addToDictionary.ContainsKey(Name))
             {
                 addToDictionary[Name] += Component.Count;
             }
             else
             {
                 addToDictionary.Add(Name, Component.Count);
             }
         }
     }
 }
コード例 #2
0
        public static Dictionary <string, int> GetMissingComponents(this IMySlimBlock Block)
        {
            var Dict = new Dictionary <string, int>();

            Block.GetMissingComponents(Dict);
            return(Dict);
        }
コード例 #3
0
        private int GetMissingComponentCount(NaniteConstructionInventory inventoryManager, IMySlimBlock block)
        {
            Dictionary <string, int> missing = new Dictionary <string, int>();

            block.GetMissingComponents(missing);
            if (missing.Count == 0)
            {
                return(0);
            }

            Dictionary <string, int> available = new Dictionary <string, int>();

            inventoryManager.GetAvailableComponents(ref available);
            for (int r = missing.Count - 1; r >= 0; r--)
            {
                var item = missing.ElementAt(r);
                if (available.ContainsKey(item.Key))
                {
                    int amount = Math.Min(item.Value, available[item.Key]);
                    available[item.Key] -= amount;
                    missing[item.Key]   -= amount;
                }
            }

            return(missing.Sum(x => x.Value));
        }
コード例 #4
0
 public static void ReadMissingComponents(this IMySlimBlock Block, Dictionary <string, int> MissingList)
 {
     if (!Block.IsWeldable() && !Block.IsProjectable())
     {
         return;
     }
     if (Block.StockpileAllocated)
     {
         Block.GetMissingComponents(MissingList);
     }
     else
     {
         if (Block.IsFullIntegrity)
         {
             return;
         }
         foreach (var Component in (Block.BlockDefinition as MyCubeBlockDefinition).Components)
         {
             string Name = Component.Definition.Id.SubtypeName;
             if (MissingList.ContainsKey(Name))
             {
                 MissingList[Name] += Component.Count;
             }
             else
             {
                 MissingList.Add(Name, Component.Count);
             }
         }
     }
 }
コード例 #5
0
        /// <summary>
        /// Retrieve the amount of components to build the block to the given index
        /// </summary>
        /// <param name="block"></param>
        /// <param name="componentList"></param>
        /// <param name="level">integrity level </param>
        public static void GetMissingComponents(this IMySlimBlock block, Dictionary <string, int> componentList, IntegrityLevel level)
        {
            var blockDefinition = block.BlockDefinition as MyCubeBlockDefinition;

            if (blockDefinition.Components == null || blockDefinition.Components.Length == 0)
            {
                return;
            }

            if (level == IntegrityLevel.Create)
            {
                var component = blockDefinition.Components[0];
                componentList.Add(component.Definition.Id.SubtypeName, 1);
            }
            else
            {
                if (block.IsProjected())
                {
                    int maxIdx = level == IntegrityLevel.Functional ? blockDefinition.CriticalGroup + 1 : blockDefinition.Components.Length;
                    for (var idx = 0; idx < maxIdx; idx++)
                    {
                        var component = blockDefinition.Components[idx];
                        if (componentList.ContainsKey(component.Definition.Id.SubtypeName))
                        {
                            componentList[component.Definition.Id.SubtypeName] += component.Count;
                        }
                        else
                        {
                            componentList.Add(component.Definition.Id.SubtypeName, component.Count);
                        }
                    }
                }
                else
                {
                    block.GetMissingComponents(componentList);
                    if (level == IntegrityLevel.Functional)
                    {
                        for (var idx = blockDefinition.CriticalGroup + 1; idx < blockDefinition.Components.Length; idx++)
                        {
                            var component = blockDefinition.Components[idx];
                            if (componentList.ContainsKey(component.Definition.Id.SubtypeName))
                            {
                                var amount = componentList[component.Definition.Id.SubtypeName];
                                if (amount <= component.Count)
                                {
                                    componentList.Remove(component.Definition.Id.SubtypeName);
                                }
                                else
                                {
                                    componentList[component.Definition.Id.SubtypeName] -= component.Count;
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #6
0
        private MyTuple <MyDefinitionId, Vector3I, Vector3D, float, IReadOnlyDictionary <string, int> > BlockDataToTuple(IMySlimBlock Block)
        {
            MyDefinitionId           id                = Block.BlockDefinition.Id;
            Vector3I                 gridPos           = Block.Position;
            Vector3D                 worldPos          = Block.CubeGrid.GridIntegerToWorld(Block.Position);
            float                    integrityRatio    = (Block.BuildIntegrity - Block.CurrentDamage) / Block.MaxIntegrity;
            Dictionary <string, int> missingComponents = new Dictionary <string, int>();

            if (integrityRatio < 1 && Block.StockpileAllocated)
            {
                Block.GetMissingComponents(missingComponents);
            }

            return(MyTuple.Create <MyDefinitionId, Vector3I, Vector3D, float, IReadOnlyDictionary <string, int> >(id, gridPos, worldPos, integrityRatio, missingComponents));
        }
コード例 #7
0
        public static bool FixUnfinishedBlock(IMyInventory inv, IMySlimBlock slimBlock, long owner)
        {
            bool success = true;

            Dictionary <string, int> missingParts = new Dictionary <string, int>();

            slimBlock.GetMissingComponents(missingParts);

            if (missingParts.Keys.Count == 0)
            {
                return(success);
            }

            foreach (var part in missingParts.Keys.ToList())
            {
                MyDefinitionId defId   = new MyDefinitionId(typeof(MyObjectBuilder_Component), part);
                var            content = (MyObjectBuilder_PhysicalObject)MyObjectBuilderSerializer.CreateNewObject(defId);
                MyObjectBuilder_InventoryItem inventoryItem = new MyObjectBuilder_InventoryItem {
                    Amount = 1, Content = content
                };

                while (missingParts[part] > 0)
                {
                    if (inv.CanItemsBeAdded(1, defId) == true)
                    {
                        inv.AddItems(1, inventoryItem.Content);
                        missingParts[part]--;
                    }
                    else
                    {
                        //Logger.AddMsg("Failed To Add Repair Component To Container", true);
                        success = false;
                        break;
                    }
                }

                slimBlock.MoveItemsToConstructionStockpile(inv);
                slimBlock.IncreaseMountLevel(10000, owner, inv);
            }

            return(success);
        }
コード例 #8
0
        public static void ReadMissingComponents(this IMySlimBlock Block, Dictionary <string, int> MissingList, bool ClearDictionary = false)
        {
            if (ClearDictionary)
            {
                MissingList.Clear();
            }
            if (Block.BuildIntegrity == Block.MaxIntegrity && Block.Integrity == Block.MaxIntegrity)
            {
                return;
            }
            Block.GetMissingComponents(MissingList);

            /*
             * if (Block.StockpileAllocated)
             * {
             *  if (SessionCore.Settings.Debug)
             *  {
             *      Dictionary<string, int> missing = new Dictionary<string, int>();
             *      Block.GetMissingComponents(missing);
             *      if (missing.Count == 0)
             *      {
             *          SessionCore.DebugAsync($"BlockHelpers.ReadMissing", $"NO MISSING ACQUIRED: {Math.Round(Block.BuildIntegrity / Block.MaxIntegrity, 3) * 100}% build integrity, {Math.Round(Block.Integrity / Block.MaxIntegrity, 3) * 100}% damage integrity");
             *      }
             *  }
             *  Block.GetMissingComponents(MissingList);
             * }
             * else
             * {
             *  foreach (var Component in (Block.BlockDefinition as MyCubeBlockDefinition).Components)
             *  {
             *      string Name = Component.Definition.Id.SubtypeName;
             *      if (MissingList.ContainsKey(Name)) MissingList[Name] += Component.Count;
             *      else MissingList.Add(Name, Component.Count);
             *  }
             * }*/
        }
コード例 #9
0
        private void Complete(bool replace = false)
        {
            if (replace)
            {
                /*
                 * VRage.Game.ModAPI.Interfaces.IMyDestroyableObject obj = (VRage.Game.ModAPI.Interfaces.IMyDestroyableObject)m_targetBlock;
                 * var dmg = m_targetBlock.MaxIntegrity - m_targetBlock.BuildIntegrity;
                 * obj.DoDamage(-dmg, VRage.Utils.MyStringHash.GetOrCompute("NaniteRepair"), true);
                 * m_targetBlock.ApplyAccumulatedDamage();
                 * MyCubeGrid grid = (MyCubeGrid)m_targetBlock.CubeGrid;
                 * grid.SendIntegrityChanged((Sandbox.Game.Entities.Cube.MySlimBlock)m_targetBlock, MyCubeGrid.MyIntegrityChangeEnum.Repair, 0);
                 * grid.OnIntegrityChanged((Sandbox.Game.Entities.Cube.MySlimBlock)m_targetBlock);
                 * m_targetBlock.UpdateVisual();
                 */
            }
            else
            {
                if (m_targetBlock.IsDestroyed || m_targetBlock.CubeGrid.GetCubeBlock(m_targetBlock.Position) == null || (m_targetBlock.FatBlock != null && m_targetBlock.FatBlock.Closed))
                {
                    return;
                }

                if (m_targetBlock.CubeGrid.Closed)
                {
                    return;
                }

                MyCubeGrid grid = (MyCubeGrid)m_targetBlock.CubeGrid;
                MyObjectBuilder_CubeBlock block;
                try
                {
                    if (m_targetBlock.FatBlock == null)
                    {
                        block = m_targetBlock.GetObjectBuilder();
                    }
                    else
                    {
                        block = m_targetBlock.FatBlock.GetObjectBuilderCubeBlock();
                    }
                }
                catch (Exception ex)
                {
                    Logging.Instance.WriteLine(string.Format("ERROR getting cubeblock object builder (3): {0} {1} - {2}", m_targetBlock.IsDestroyed, m_targetBlock.FatBlock != null ? m_targetBlock.FatBlock.GetType().Name : m_targetBlock.GetType().Name, ex.ToString()));
                }

                // Target block contains inventory, spawn it
                if (m_targetBlock.FatBlock != null && ((MyEntity)m_targetBlock.FatBlock).HasInventory)
                {
                    for (int r = 0; r < ((MyEntity)m_targetBlock.FatBlock).InventoryCount; r++)
                    {
                        var inventory = ((MyEntity)m_targetBlock.FatBlock).GetInventoryBase(r);
                        if (inventory == null)
                        {
                            continue;
                        }

                        foreach (var item in inventory.GetItems())
                        {
                            Logging.Instance.WriteLine(string.Format("INVENTORY found.  Target block contains inventory: {0} {1}", item.Amount, item.Content.SubtypeId));
                            if (!m_inventory.ContainsKey(item.Content.SubtypeName))
                            {
                                m_inventory.Add(item.Content.SubtypeName, new MyTuple <MyFixedPoint, MyObjectBuilder_PhysicalObject>(item.Amount, item.Content));
                            }
                            else
                            {
                                m_inventory[item.Content.SubtypeName] = new MyTuple <MyFixedPoint, MyObjectBuilder_PhysicalObject>(m_inventory[item.Content.SubtypeName].Item1 + item.Amount, m_inventory[item.Content.SubtypeName].Item2);
                            }
                        }
                    }
                }

                m_targetBlock.GetMissingComponents(m_missingComponents);
                //grid.RemoveBlock((Sandbox.Game.Entities.Cube.MySlimBlock)m_targetBlock, true);
                grid.RazeBlock(m_targetBlock.Position);
                m_removed = true;
            }
        }
コード例 #10
0
        private void ProcessConstructionItem(IMySlimBlock target)
        {
            if (Sync.IsServer)
            {
                if (!IsEnabled())
                {
                    Logging.Instance.WriteLine("CANCELLING Construction/Repair Target due to being disabled");
                    CancelTarget(target);
                    return;
                }

                if (!NaniteConstructionPower.HasRequiredPowerForCurrentTarget((IMyFunctionalBlock)m_constructionBlock.ConstructionBlock))
                {
                    Logging.Instance.WriteLine("CANCELLING Construction/Repair Target due to power shortage");
                    CancelTarget(target);
                    return;
                }

                if (m_constructionBlock.FactoryState != NaniteConstructionBlock.FactoryStates.Active)
                {
                    return;
                }

                if (!m_targetBlocks.ContainsKey(target))
                {
                    m_targetBlocks.Add(target, 0);
                }

                NaniteWelder welder = (NaniteWelder)m_constructionBlock.ToolManager.Tools.FirstOrDefault(x => x.TargetBlock == target && x is NaniteWelder);
                if (welder == null)
                {
                    double distance = EntityHelper.GetDistanceBetweenBlockAndSlimblock((IMyCubeBlock)m_constructionBlock.ConstructionBlock, target);
                    int    time     = (int)Math.Max(GetMinTravelTime() * 1000f, (distance / GetSpeed()) * 1000f);
                    welder = new NaniteWelder(m_constructionBlock, target, (int)(time / 2.5f), false);
                    m_constructionBlock.ToolManager.Tools.Add(welder);
                    m_constructionBlock.SendAddTarget(target, TargetTypes.Construction);
                }

                if (target.IsFullIntegrity && !target.HasDeformation)
                {
                    CompleteTarget(target);
                    return;
                }

                if (m_areaTargetBlocks.ContainsKey(target))
                {
                    BoundingBoxD bb;
                    target.GetWorldBoundingBox(out bb, true);
                    if (!m_areaTargetBlocks[target].IsInsideBox(bb))
                    {
                        CancelTarget(target);
                        return;
                    }
                }

                if (target.IsDestroyed || target.IsFullyDismounted || (target.FatBlock != null && target.FatBlock.Closed))
                {
                    Logging.Instance.WriteLine("CANCELLING Construction/Repair Target due to target being destroyed");
                    CancelTarget(target);
                    return;
                }

                if (welder != null && MyAPIGateway.Session.ElapsedPlayTime.TotalMilliseconds - welder.StartTime >= welder.WaitTime)
                {
                    target.MoveItemsToConstructionStockpile(((MyEntity)m_constructionBlock.ConstructionBlock).GetInventory());
                    Dictionary <string, int> missing = new Dictionary <string, int>();
                    target.GetMissingComponents(missing);

                    if (!target.HasDeformation && !target.CanContinueBuild(((MyEntity)m_constructionBlock.ConstructionBlock).GetInventory()))
                    {
                        if (!MyAPIGateway.Session.CreativeMode)
                        {
                            Logging.Instance.WriteLine("CANCELLING Construction/Repair Target due to missing components");
                            foreach (var item in missing)
                            {
                                Logging.Instance.WriteLine(string.Format("Missing component: {0} - {1}", item.Value, item.Key));
                            }
                            CancelTarget(target);
                        }
                    }

                    return;
                }

                bool isRemote = false;
                using (m_remoteLock.AcquireExclusiveUsing())
                {
                    isRemote = m_remoteTargets.Contains(target);
                }

                if (isRemote && EntityHelper.GetDistanceBetweenBlockAndSlimblock((IMyCubeBlock)m_constructionBlock.ConstructionBlock, target) > m_maxDistance)
                {
                    Logging.Instance.WriteLine("CANCELLING Repair Target due to target being out of range");
                    CancelTarget(target);
                    return;
                }
            }

            CreateConstructionParticle(target);
        }
コード例 #11
0
        internal bool ProcessMissingComponents(IMySlimBlock target)
        {
            if (MyAPIGateway.Session.CreativeMode)
            {
                return(true);
            }

            int pos = 0;

            try
            {
                IMyInventory inventory = GetConstructionInventory();
                if (inventory == null)
                {
                    Logging.Instance.WriteLine(string.Format("Inventory {0} is null.", inventory == null));
                    return(false);
                }

                Dictionary <string, int> missingComponents = new Dictionary <string, int>();
                // Target block is on a real grid
                if (target.CubeGrid.Physics != null)
                {
                    target.GetMissingComponents(missingComponents);
                    if (missingComponents.Count == 0)
                    {
                        return(true);
                    }
                }
                else // Target block is projection, let's just put 1 item in it
                {
                    try
                    {
                        MyCubeBlockDefinition blockDefinition = (MyCubeBlockDefinition)target.BlockDefinition;
                        missingComponents.Add(blockDefinition.Components[0].Definition.Id.SubtypeName, 1);
                    }
                    catch (Exception ex)
                    {
                        Logging.Instance.WriteLine(string.Format("Process Error: {0}", ex.ToString()));
                        return(false);
                    }
                }

                foreach (var item in inventory.GetItems().ToList())
                {
                    if (missingComponents.ContainsKey(item.Content.SubtypeName))
                    {
                        var amount = (float)missingComponents[item.Content.SubtypeName];
                        if (amount >= (float)item.Amount)
                        {
                            amount = (float)item.Amount;
                        }

                        missingComponents[item.Content.SubtypeName] -= (int)item.Amount;
                        if (missingComponents[item.Content.SubtypeName] <= 0)
                        {
                            missingComponents.Remove(item.Content.SubtypeName);
                        }

                        inventory.RemoveItemsOfType((int)amount, (MyObjectBuilder_PhysicalObject)item.Content);
                    }
                }

                if (missingComponents.Count == 0)
                {
                    return(true);
                }

                return(false);
            }
            catch (Exception ex)
            {
                Logging.Instance.WriteLine(string.Format("Exception {0} : {1}", pos, ex.ToString()));
                return(false);
            }
        }
コード例 #12
0
        private void Complete()
        {
            if (m_targetBlock.IsDestroyed || m_targetBlock.CubeGrid.GetCubeBlock(m_targetBlock.Position) == null || (m_targetBlock.FatBlock != null && m_targetBlock.FatBlock.Closed))
            {
                return;
            }

            if (m_targetBlock.CubeGrid.Closed)
            {
                return;
            }

            MyCubeGrid grid = (MyCubeGrid)m_targetBlock.CubeGrid;
            MyObjectBuilder_CubeBlock block;

            try
            {
                if (m_targetBlock.FatBlock == null)
                {
                    block = m_targetBlock.GetObjectBuilder();
                }
                else
                {
                    block = m_targetBlock.FatBlock.GetObjectBuilderCubeBlock();
                }
            }
            catch (Exception ex)
            {
                Logging.Instance.WriteLine(string.Format("ERROR getting cubeblock object builder (3): {0} {1} - {2}", m_targetBlock.IsDestroyed, m_targetBlock.FatBlock != null ? m_targetBlock.FatBlock.GetType().Name : m_targetBlock.GetType().Name, ex.ToString()));
            }

            // Target block contains inventory, spawn it
            if (m_targetBlock.FatBlock != null && ((MyEntity)m_targetBlock.FatBlock).HasInventory)
            {
                for (int r = 0; r < ((MyEntity)m_targetBlock.FatBlock).InventoryCount; r++)
                {
                    var inventory = ((MyEntity)m_targetBlock.FatBlock).GetInventoryBase(r);
                    if (inventory == null)
                    {
                        continue;
                    }

                    foreach (var item in inventory.GetItems())
                    {
                        Logging.Instance.WriteLine(string.Format("INVENTORY found.  Target block contains inventory: {0} {1}", item.Amount, item.Content.SubtypeId));
                        if (!m_inventory.ContainsKey(item.Content.SubtypeName))
                        {
                            m_inventory.Add(item.Content.SubtypeName, new MyTuple <MyFixedPoint, MyObjectBuilder_PhysicalObject>(item.Amount, item.Content));
                        }
                        else
                        {
                            m_inventory[item.Content.SubtypeName] = new MyTuple <MyFixedPoint, MyObjectBuilder_PhysicalObject>(m_inventory[item.Content.SubtypeName].Item1 + item.Amount, m_inventory[item.Content.SubtypeName].Item2);
                        }
                    }
                }
            }

            m_targetBlock.GetMissingComponents(m_missingComponents);
            //grid.RemoveBlock()
            //grid.RemoveBlock((Sandbox.Game.Entities.Cube.MySlimBlock)m_targetBlock, true);
            grid.RazeBlock(m_targetBlock.Position);
            m_removed = true;
        }
コード例 #13
0
ファイル: WeldGrid.cs プロジェクト: zrisher/ARMS
 private void GetMissingComponents(IMySlimBlock slim)
 {
     using (MainLock.AcquireSharedUsing())
         slim.GetMissingComponents(m_components_missing);
 }
コード例 #14
0
ファイル: WeldGrid.cs プロジェクト: Souper07/Autopilot
 private void GetMissingComponents(IMySlimBlock slim)
 {
     using (MainLock.AcquireSharedUsing())
         slim.GetMissingComponents(m_components_missing);
 }