Beispiel #1
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);
             }
         }
     }
 }
Beispiel #2
0
        void ComplainMissing(Dictionary <IMySlimBlock, Dictionary <string, int> > MissingPerBlock)
        {
            var Player = MyAPIGateway.Session.Player;

            if (Player == null)
            {
                return;
            }
            if (Player.IdentityId != Tool.OwnerId)
            {
                return;
            }
            if (Player.GetPosition().DistanceTo(Tool.GetPosition()) > 200)
            {
                return;
            }

            StringBuilder Text = new StringBuilder();

            if (MissingPerBlock.Count == 1)
            {
                IMySlimBlock Block       = MissingPerBlock.Keys.First();
                var          Missing     = MissingPerBlock[Block];
                bool         IsProjected = Block.IsProjectable();
                if (Missing != null && Missing.Count > 0)
                {
                    Text.AppendLine($"{Tool.CustomName}: can't proceed to {(!IsProjected ? "build" : "place")} {Block.BlockDefinition.DisplayNameText}, missing:\n");
                    foreach (var ItemPair in Missing)
                    {
                        Text.AppendLine($"{ItemPair.Key}: {(!IsProjected ? 1 : ItemPair.Value)}");
                        if (IsProjected)
                        {
                            break;
                        }
                    }
                }
            }
            else if (UnbuiltBlocks.Count > 1 && MissingPerBlock.Values.Any(x => x.Count > 0))
            {
                Text.AppendLine($"{Tool.CustomName}: can't proceed to build {MissingPerBlock.Count} blocks:\n");
                foreach (IMySlimBlock Block in MissingPerBlock.Keys)
                {
                    var Missing = MissingPerBlock[Block];
                    if (Missing.Count == 0)
                    {
                        continue;
                    }
                    Text.AppendLine($"{Block.BlockDefinition.DisplayNameText}: missing:");
                    foreach (var ItemPair in Missing)
                    {
                        Text.AppendLine($"{ItemPair.Key}: {ItemPair.Value}");
                    }
                    Text.AppendLine();
                }
            }
            Text.RemoveTrailingNewlines();
            IMyHudNotification hud = MyAPIGateway.Utilities.CreateNotification(Text.ToString(), (int)Math.Ceiling(SessionCore.TickLengthMs * 101), "Red"); // Adding 1 excess tick is needed, otherwise notification can flicker

            hud.Show();
        }
Beispiel #3
0
        StringBuilder WriteMissing(Dictionary <IMySlimBlock, Dictionary <string, int> > MissingPerBlock)
        {
            StringBuilder Text = new StringBuilder();

            if (MissingPerBlock.Count == 1)
            {
                IMySlimBlock Block       = MissingPerBlock.Keys.First();
                var          Missing     = MissingPerBlock[Block];
                bool         IsProjected = Block.IsProjectable();
                if (Missing != null && Missing.Count > 0)
                {
                    Text.AppendLine($"{Tool.CustomName}: can't proceed to {(!IsProjected ? "build" : "place")} {Block.BlockDefinition.DisplayNameText}, missing:\n");
                    foreach (var ItemPair in Missing)
                    {
                        Text.AppendLine($"{ItemPair.Key}: {(!IsProjected ? 1 : ItemPair.Value)}");
                        if (IsProjected)
                        {
                            break;
                        }
                    }
                }
            }
            else if (MissingPerBlock.Count > 1 && MissingPerBlock.Values.Any(x => x.Count > 0))
            {
                Text.AppendLine($"{Tool.CustomName}: can't proceed to build {MissingPerBlock.Count} blocks:\n");
                foreach (IMySlimBlock Block in MissingPerBlock.Keys)
                {
                    var Missing = MissingPerBlock[Block];
                    if (Missing.Count == 0)
                    {
                        continue;
                    }
                    Text.AppendLine($"{Block.BlockDefinition.DisplayNameText}: missing:");
                    foreach (var ItemPair in Missing)
                    {
                        Text.AppendLine($"{ItemPair.Key}: {ItemPair.Value}");
                    }
                    Text.AppendLine();
                }
            }
            //SessionCore.DebugWrite(Tool.CustomName, $"WriteMissing() assembled StringBuilder - {Text.Length} chars");
            Text.RemoveTrailingNewlines();
            return(Text);
        }
Beispiel #4
0
        void Place(IMySlimBlock Block)
        {
            if (!Block.IsProjectable())
            {
                return;
            }
            var FirstItem = ((MyCubeBlockDefinition)Block.BlockDefinition).Components[0].Definition.Id;

            if (MyAPIGateway.Session.CreativeMode || ToolCargo.PullAny(OnboardInventoryOwners, FirstItem.SubtypeName, 1))
            {
                var Projector = ((Block.CubeGrid as MyCubeGrid).Projector as IMyProjector);
                Projector.Build(Block, 0, Tool.EntityId, false);
                ToolCargo.RemoveItemsOfType(1, FirstItem);
            }
            else
            {
                UnbuiltBlocks.Add(Block);
                SessionCore.DebugWrite($"{Tool.CustomName}.Place()", $"Tool can't pull the component {FirstItem.SubtypeName}!", IsExcessive: false);
            }
        }