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}"); }
        }
 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.º 4
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.º 5
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);
        }
Ejemplo n.º 6
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);
     }
 }
        private void ProcessConstructionItem(IMySlimBlock target)
        {
            try {
                if (Sync.IsServer)
                {
                    if (!((m_constructionBlock.FactoryState == NaniteConstructionBlock.FactoryStates.Active || m_constructionBlock.FactoryState == NaniteConstructionBlock.FactoryStates.MissingParts) && (TargetList.Count > 0 || PotentialTargetList.Count > 0)))
                    {
                        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);
                        MyAPIGateway.Utilities.InvokeOnGameThread(() =>
                        {
                            if (target == null)
                            {
                                return;
                            }

                            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)
                    {
                        MyAPIGateway.Utilities.InvokeOnGameThread(() =>
                        {
                            if (target != null)
                            {
                                CompleteTarget(target);
                            }
                        });
                        return;
                    }

                    if (m_areaTargetBlocks.ContainsKey(target))
                    {
                        BoundingBoxD bb;
                        target.GetWorldBoundingBox(out bb, true);
                        if (!m_areaTargetBlocks[target].IsInsideBox(bb))
                        {
                            MyAPIGateway.Utilities.InvokeOnGameThread(() =>
                            {
                                if (target != null)
                                {
                                    CancelTarget(target);
                                }
                            });
                            return;
                        }
                    }

                    if (target.IsDestroyed || target.IsFullyDismounted || (target.FatBlock != null && target.FatBlock.Closed))
                    {
                        Logging.Instance.WriteLine("[Construction] Cancelling Construction/Repair Target due to target being destroyed", 1);
                        MyAPIGateway.Utilities.InvokeOnGameThread(() =>
                        {
                            if (target != null)
                            {
                                CancelTarget(target);
                            }
                        });
                        return;
                    }

                    if (welder != null && MyAPIGateway.Session.ElapsedPlayTime.TotalMilliseconds - welder.StartTime >= welder.WaitTime)
                    {
                        MyAPIGateway.Utilities.InvokeOnGameThread(() =>
                        {
                            if (target == null)
                            {
                                return;
                            }

                            var blockDefinition = target.BlockDefinition as MyCubeBlockDefinition;
                            var localShipWelder = m_constructionBlock.ConstructionBlock as IMyShipWelder;

                            m_constructionBlock.UpdateOverLimit = false;

                            if (NaniteConstructionManager.ProjectorBlocks != null)
                            {
                                foreach (var item in NaniteConstructionManager.ProjectorBlocks)
                                {
                                    var projector = item.Value as IMyProjector;
                                    if (projector == null)
                                    {
                                        continue;
                                    }

                                    int subgridIndex;
                                    if (!ProjectorIntegration.TryGetSubgridIndex(projector, target, out subgridIndex))
                                    {
                                        return;
                                    }

                                    if (localShipWelder != null && blockDefinition != null)
                                    {
                                        var validator = localShipWelder.IsWithinWorldLimits(projector, blockDefinition.BlockPairName, blockDefinition.PCU);
                                        if (!validator)
                                        {
                                            m_constructionBlock.UpdateOverLimit = true;
                                            break;
                                        }
                                    }
                                }
                            }

                            if (m_constructionBlock.UpdateOverLimit)
                            {
                                CancelTarget(target);
                                return;
                            }

                            target.MoveItemsToConstructionStockpile(((MyEntity)m_constructionBlock.ConstructionBlock).GetInventory());

                            if (!target.HasDeformation && !target.CanContinueBuild(((MyEntity)m_constructionBlock.ConstructionBlock).GetInventory()) && !MyAPIGateway.Session.CreativeMode)
                            {
                                Logging.Instance.WriteLine("[Construction] Cancelling Construction/Repair Target due to missing components", 1);

                                CancelTarget(target);
                            }
                        });

                        return;
                    }
                    // NEW 12-1-2018 To save on performance, once a target is started, use SyncDistance only so we dont have to check each slave factory
                    if (m_remoteTargets.Contains(target) &&
                        !IsInRange(target, m_maxDistance))
                    {
                        Logging.Instance.WriteLine("[Construction] Cancelling Repair Target due to being out of range", 1);
                        MyAPIGateway.Utilities.InvokeOnGameThread(() =>
                                                                  { CancelTarget(target); });
                        return;
                    }
                }

                CreateConstructionParticle(target);
            } catch (Exception exc) {
                MyLog.Default.WriteLineAndConsole($"##MOD: nanites, ERROR: {exc}");
            }
        }
        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);
        }
        private void ProcessConstructionItem(IMySlimBlock target)
        {
            if (Sync.IsServer)
            {
                if (!((m_constructionBlock.FactoryState == NaniteConstructionBlock.FactoryStates.Active || m_constructionBlock.FactoryState == NaniteConstructionBlock.FactoryStates.MissingParts) && (TargetList.Count > 0 || PotentialTargetList.Count > 0)))
                {
                    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);
                    MyAPIGateway.Utilities.InvokeOnGameThread(() =>
                    {
                        if (target == null)
                        {
                            return;
                        }

                        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)
                {
                    MyAPIGateway.Utilities.InvokeOnGameThread(() =>
                    {
                        if (target != null)
                        {
                            CompleteTarget(target);
                        }
                    });
                    return;
                }

                if (m_areaTargetBlocks.ContainsKey(target))
                {
                    BoundingBoxD bb;
                    target.GetWorldBoundingBox(out bb, true);
                    if (!m_areaTargetBlocks[target].IsInsideBox(bb))
                    {
                        MyAPIGateway.Utilities.InvokeOnGameThread(() =>
                        {
                            if (target != null)
                            {
                                CancelTarget(target);
                            }
                        });
                        return;
                    }
                }

                if (target.IsDestroyed || target.IsFullyDismounted || (target.FatBlock != null && target.FatBlock.Closed))
                {
                    Logging.Instance.WriteLine("[Construction] Cancelling Construction/Repair Target due to target being destroyed", 1);
                    MyAPIGateway.Utilities.InvokeOnGameThread(() =>
                    {
                        if (target != null)
                        {
                            CancelTarget(target);
                        }
                    });
                    return;
                }

                if (welder != null && MyAPIGateway.Session.ElapsedPlayTime.TotalMilliseconds - welder.StartTime >= welder.WaitTime)
                {
                    MyAPIGateway.Utilities.InvokeOnGameThread(() =>
                    {
                        if (target == null)
                        {
                            return;
                        }

                        target.MoveItemsToConstructionStockpile(((MyEntity)m_constructionBlock.ConstructionBlock).GetInventory());

                        if (!target.HasDeformation && !target.CanContinueBuild(((MyEntity)m_constructionBlock.ConstructionBlock).GetInventory()) && !MyAPIGateway.Session.CreativeMode)
                        {
                            Logging.Instance.WriteLine("[Construction] Cancelling Construction/Repair Target due to missing components", 1);

                            CancelTarget(target);
                        }
                    });

                    return;
                }
                // NEW 12-1-2018 To save on performance, once a target is started, use SyncDistance only so we dont have to check each slave factory
                if (m_remoteTargets.Contains(target) &&
                    !IsInRange(target, m_maxDistance))
                {
                    Logging.Instance.WriteLine("[Construction] Cancelling Repair Target due to being out of range", 1);
                    MyAPIGateway.Utilities.InvokeOnGameThread(() =>
                                                              { CancelTarget(target); });
                    return;
                }
            }

            CreateConstructionParticle(target);
        }