コード例 #1
0
ファイル: LaserGrinder.cs プロジェクト: Gauge/LaserWelders
        void Grind(IMySlimBlock Block, float SpeedRatio)
        {
            Block.DecreaseMountLevel(SpeedRatio, ToolCargo, useDefaultDeconstructEfficiency: true);
            Block.MoveItemsFromConstructionStockpile(ToolCargo);
            Block.DoDamage(0, VRage.Utils.MyStringHash.GetOrCompute("Grind"), true, null, Tool.EntityId);

            if (Block.FatBlock?.IsFunctional == false && Block.FatBlock?.HasInventory == true)
            {
                foreach (var Inventory in Block.FatBlock.GetInventories())
                {
                    if (Inventory.CurrentVolume == VRage.MyFixedPoint.Zero)
                    {
                        continue;
                    }
                    foreach (var Item in Inventory.GetItems())
                    {
                        var Amount = Inventory.ComputeAmountThatFits(Item);
                        ToolCargo.TransferItemFrom(Inventory, (int)Item.ItemId, null, null, Amount, false);
                    }
                }
            }
            if (Block.IsFullyDismounted)
            {
                Block.CubeGrid.RazeBlock(Block.Position);
            }
        }
コード例 #2
0
        private void GrindTarget()
        {
            float        damage    = (MyAPIGateway.Session.GrinderSpeedMultiplier * MyShipGrinderConstants.GRINDER_AMOUNT_PER_SECOND) * 4f * NaniteConstructionManager.Settings.DeconstructionEfficiency;
            IMyInventory inventory = ((MyEntity)m_constructionBlock.ConstructionBlock).GetInventory();

            m_targetBlock.DecreaseMountLevel(damage, inventory);
            m_targetBlock.MoveItemsFromConstructionStockpile(inventory);

            if (m_targetBlock.IsFullyDismounted)
            {
                m_targetBlock.CubeGrid.RazeBlock(m_targetBlock.Position);
            }
        }
コード例 #3
0
        void Grind(IMySlimBlock Block, float SpeedRatio, bool Raze = true)
        {
            if (Block == null)
            {
                return;
            }
            try
            {
                Stopwatch watch = Stopwatch.StartNew();
                Block.DecreaseMountLevel(SpeedRatio, ToolCargo);
                watch.Stop();
                //WriteToLog($"GrindBlocks[{MyKernel.Block.CustomName}]", $"Decreasing mount level took {Math.Round(watch.Elapsed.TotalMilliseconds, 3)}ms", EemRdx.SessionModules.LoggingLevelEnum.ProfilingLog);
                watch.Restart();
                Block.MoveItemsFromConstructionStockpile(ToolCargo);
                watch.Stop();
                //WriteToLog($"GrindBlocks[{MyKernel.Block.CustomName}]", $"Moving items took {Math.Round(watch.Elapsed.TotalMilliseconds, 3)}ms", EemRdx.SessionModules.LoggingLevelEnum.ProfilingLog);
                watch.Restart();
                // This is necessary for compatibility with EEM and other mods which react to damage to their grids
                Block.DoDamage(0, MyStringHash.GetOrCompute("Grind"), true, null, MyKernel.Block.EntityId);
                watch.Stop();
                //WriteToLog($"GrindBlocks[{MyKernel.Block.CustomName}]", $"Doing damage took {Math.Round(watch.Elapsed.TotalMilliseconds, 3)}ms", EemRdx.SessionModules.LoggingLevelEnum.ProfilingLog);
                watch.Restart();

                if (Block.FatBlock?.IsFunctional == false && Block.FatBlock?.HasInventory == true)
                {
                    foreach (IMyInventory Inventory in Block.FatBlock.GetInventories())
                    {
                        if (Inventory.CurrentVolume == VRage.MyFixedPoint.Zero)
                        {
                            continue;
                        }
                        List <MyInventoryItem> Items = new List <MyInventoryItem>();
                        Inventory.GetItems(Items);

                        foreach (MyInventoryItem Item in Items)
                        {
                            VRage.MyFixedPoint Amount = (VRage.MyFixedPoint)Math.Min((float)(Inventory as Sandbox.Game.MyInventory).ComputeAmountThatFits(Item.Type), (float)Item.Amount);
                            if ((float)Amount > 0)
                            {
                                ToolCargo.TransferItemFrom(Inventory, (int)Item.ItemId, null, null, Amount, false);
                            }
                        }
                    }
                    watch.Stop();
                    //WriteToLog($"GrindBlocks[{MyKernel.Block.CustomName}]", $"Block has an inventory; cleaning took {Math.Round(watch.Elapsed.TotalMilliseconds, 3)}ms", EemRdx.SessionModules.LoggingLevelEnum.ProfilingLog);
                    watch.Reset();
                }

                if (Raze && Block.IsFullyDismounted)
                {
                    watch.Restart();
                    Block.CubeGrid.RazeBlock(Block.Position);
                    watch.Stop();
                    //WriteToLog($"GrindBlocks[{MyKernel.Block.CustomName}]", $"Razing the block took {Math.Round(watch.Elapsed.TotalMilliseconds, 3)}ms", EemRdx.SessionModules.LoggingLevelEnum.ProfilingLog);
                }
            }
            catch (Exception Scrap)
            {
                LogError($"GrindBlocks[{MyKernel.Block.CustomName}]", $"Grinding of the block {Extensions.GeneralExtensions.GetTypeName(Block)} failed", Scrap);
            }
        }