Ejemplo n.º 1
0
        private void WeldTarget()
        {
            if (m_targetBlock.HasDeformation)
            {
                m_targetBlock.FixBones(0f, 1f);
            }

            float        damage    = (MyAPIGateway.Session.WelderSpeedMultiplier * MyShipGrinderConstants.GRINDER_AMOUNT_PER_SECOND) * 8f * NaniteConstructionManager.Settings.ConstructionEfficiency;
            IMyInventory inventory = ((MyEntity)m_constructionBlock.ConstructionBlock).GetInventory();

            if (m_targetBlock.CanContinueBuild(inventory) || MyAPIGateway.Session.CreativeMode)
            {
                var functional = m_targetBlock as IMyFunctionalBlock;
                if (functional != null)
                {
                    Logging.Instance.WriteLine(string.Format("Functional block '{0}': {1}", functional.CustomName, functional.Enabled));
                    //if (functional.IsFunctional && !functional.Enabled)
                    if (!functional.Enabled)
                    {
                        Logging.Instance.WriteLine(string.Format("Requesting Enable: {0}", functional.CustomName));
                        functional.Enabled = true;
                    }
                }

                m_targetBlock.MoveItemsToConstructionStockpile(inventory);
                m_targetBlock.IncreaseMountLevel(damage, m_constructionBlock.ConstructionBlock.OwnerId, inventory, maxAllowedBoneMovement: 1.0f);
            }
        }
Ejemplo n.º 2
0
        private void WeldTarget()
        {
            try
            {
                if (m_targetBlock == null)
                {
                    return;
                }

                if (m_targetBlock.HasDeformation)
                {
                    m_targetBlock.FixBones(0f, 1f);
                }

                float        damage    = (MyAPIGateway.Session.WelderSpeedMultiplier * MyShipGrinderConstants.GRINDER_AMOUNT_PER_SECOND) * 8f * NaniteConstructionManager.Settings.ConstructionEfficiency;
                IMyInventory inventory = ((MyEntity)m_constructionBlock.ConstructionBlock).GetInventory();
                if (m_targetBlock.CanContinueBuild(inventory) || MyAPIGateway.Session.CreativeMode)
                {
                    var functional = m_targetBlock as IMyFunctionalBlock;
                    if (functional != null && !functional.Enabled)
                    {
                        functional.Enabled = true;
                    }

                    m_targetBlock.MoveItemsToConstructionStockpile(inventory);
                    m_targetBlock.IncreaseMountLevel(damage, m_constructionBlock.ConstructionBlock.OwnerId, inventory, maxAllowedBoneMovement: 1.0f);
                }
            }
            catch (Exception e)
            { Logging.Instance.WriteLine($"{e}"); }
        }
Ejemplo n.º 3
0
 bool Weld(IMySlimBlock Block, float SpeedRatio, float BoneFixSpeed)
 {
     //if (Block.IsFullIntegrity && !Block.HasDeformation) return;
     if (Block.CanContinueBuild(ToolCargo) || MyAPIGateway.Session.CreativeMode)
     {
         Block.IncreaseMountLevel(SpeedRatio, Welder.OwnerId, ToolCargo, BoneFixSpeed, false);
         Block.MoveItemsToConstructionStockpile(ToolCargo);
         return(true);
     }
     else if (Block.HasDeformation)
     {
         Block.IncreaseMountLevel(SpeedRatio, Welder.OwnerId, ToolCargo, BoneFixSpeed, false);
         return(true);
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 4
0
 /*void WeldDistanceMode(ICollection<IMySlimBlock> Blocks, int ticks = 1)
  * {
  *  UnbuiltBlocks.Clear();
  *  if (Blocks.Count == 0) return;
  *  Blocks = Blocks.OrderByDescending(x => Vector3D.DistanceSquared(x.GetPosition(), Tool.GetPosition())).ToList();
  *  float SpeedRatio = VanillaToolConstants.WelderSpeed * ticks * TermModule.SpeedMultiplier;
  *  float BoneFixSpeed = VanillaToolConstants.WelderBoneRepairSpeed * ticks;
  *
  *  IMySlimBlock Block = Blocks.First();
  *  bool welded = Weld(Block, SpeedRatio, BoneFixSpeed);
  *  if (!welded)
  *  {
  *      var missing = Block.ReadMissingComponents();
  *      bool pull = false;
  *      lock (GridInventoryModule.InventoryLock)
  *      {
  *          pull = Welder.UseConveyorSystem && ToolCargo.PullAny(OnboardInventoryOwners, missing);
  *      }
  *      if (!Welder.UseConveyorSystem || !pull)
  *          UnbuiltBlocks.Add(Block);
  *  }
  *  ComplainUnbuilt();
  * }
  */
 bool Weld(IMySlimBlock Block, float SpeedRatio, float BoneFixSpeed)
 {
     //if (Block.IsFullIntegrity && !Block.HasDeformation) return;
     if (Block.CanContinueBuild(ToolCargo)) // || MyAPIGateway.Session.CreativeMode)
     {                                      // Block should be welded in this order, or it won't work
         //SessionCore.DebugWrite(Tool.CustomName, $"Welding block...");
         Block.MoveItemsToConstructionStockpile(ToolCargo);
         Block.IncreaseMountLevel(SpeedRatio, Welder.OwnerId, ToolCargo, BoneFixSpeed, false);
         return(true);
     }
     else if (Block.HasDeformation)
     {
         //SessionCore.DebugWrite(Tool.CustomName, $"Undeforming block...");
         Block.IncreaseMountLevel(SpeedRatio, Welder.OwnerId, ToolCargo, BoneFixSpeed, false);
         return(true);
     }
     else
     {
         //SessionCore.DebugWrite(Tool.CustomName, $"Cannot continue building block");
         return(false);
     }
 }
 void Weld(IMySlimBlock Block, float SpeedRatio, float BoneFixRatio)
 {
     if (Block == null)
     {
         return;
     }
     try
     {
         Block.MoveItemsToConstructionStockpile(ToolCargo);
         Block.IncreaseMountLevel(SpeedRatio, MyKernel.Tool.OwnerId, ToolCargo, BoneFixRatio, MyKernel.Tool.HelpOthers);
     }
     catch (Exception Scrap)
     {
         LogError(nameof(Weld), $"Welding of the block {Extensions.GeneralExtensions.GetTypeName(Block)} failed", Scrap);
     }
 }
Ejemplo n.º 6
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);
        }