void Work(int ticks = 1)
        {
            if (!MyAPIGateway.Multiplayer.IsServer)
            {
                return;
            }
            LineD           WeldRay = new LineD(BeamStart, BeamEnd);
            List <IHitInfo> Hits    = new List <IHitInfo>();
            List <MyLineSegmentOverlapResult <MyEntity> > Overlaps = new List <MyLineSegmentOverlapResult <MyEntity> >();

            MyGamePruningStructure.GetTopmostEntitiesOverlappingRay(ref WeldRay, Overlaps);

            List <IMyCubeGrid>       Grids      = new List <IMyCubeGrid>();
            List <IMyCharacter>      Characters = new List <IMyCharacter>();
            List <IMyFloatingObject> Flobjes    = new List <IMyFloatingObject>();

            Overlaps.Select(x => x.Element as IMyEntity).SortByType(Grids, Characters, Flobjes);

            ClosestGrid = Grids.OrderBy(Grid => Vector3D.DistanceSquared(Tool.GetPosition(), Grid.GetPosition())).FirstOrDefault();
            foreach (IMyCharacter Char in Characters)
            {
                Char.DoDamage(GrinderSpeed, MyDamageType.Grind, true, null, Tool.EntityId);
            }

            foreach (IMyCubeGrid Grid in Grids)
            {
                if (Grid == Tool.CubeGrid)
                {
                    continue;
                }
                try
                {
                    List <IMySlimBlock> Blocks = Grid.GetBlocksOnRay(WeldRay.From, WeldRay.To);
                    //if (!SessionCore.Debug && Blocks.Count == 0) return;

                    if (IsWelder)
                    {
                        Weld(Blocks, ticks);
                    }
                    if (IsGrinder)
                    {
                        Grind(Blocks, ticks);
                    }
                }
                catch (Exception Scrap)
                {
                    SessionCore.LogError(Grid.DisplayName, Scrap);
                }
            }

            foreach (IMyFloatingObject Flobj in Flobjes)
            {
                ToolCargo.PickupItem(Flobj);
            }
        }
        void Work(int ticks = 1)
        {
            if (!MyAPIGateway.Multiplayer.IsServer)
            {
                return;
            }
            LineD           WeldRay = new LineD(BeamStart, BeamEnd);
            List <IHitInfo> Hits    = new List <IHitInfo>();
            List <MyLineSegmentOverlapResult <MyEntity> > Overlaps = new List <MyLineSegmentOverlapResult <MyEntity> >();

            MyGamePruningStructure.GetTopmostEntitiesOverlappingRay(ref WeldRay, Overlaps);

            var Entities = Overlaps.Select(x => x.Element);
            var Grids    = Entities.OfType <IMyCubeGrid>().Except(Tool.CubeGrid).OrderBy(x => Vector3D.DistanceSquared(BlockPosition, x.GetPosition())).ToList();

            ClosestGrid = Grids.FirstOrDefault();

            foreach (IMyCharacter Char in Entities.OfType <IMyCharacter>())
            {
                Char.DoDamage(GrinderSpeed, MyDamageType.Grind, true, null, Tool.EntityId);
            }

            foreach (IMyCubeGrid Grid in Entities.OfType <IMyCubeGrid>())
            {
                try
                {
                    List <IMySlimBlock> Blocks = Grid.GetBlocksOnRay(WeldRay.From, WeldRay.To);
                    //if (!SessionCore.Debug && Blocks.Count == 0) return;

                    if (IsWelder)
                    {
                        Weld(Blocks, ticks);
                    }
                    if (IsGrinder)
                    {
                        Grind(Blocks, ticks);
                    }
                }
                catch (Exception Scrap)
                {
                    SessionCore.LogError(Grid.DisplayName, Scrap);
                }
            }
        }
 protected override void ProcessCharacters(HashSet <IMyCharacter> Characters)
 {
     if (Characters.Count == 0)
     {
         return;
     }
     if (!MyAPIGateway.Session.IsServer)
     {
         return;
     }
     foreach (IMyCharacter Char in Characters)
     {
         LineD WorkingRay = new LineD(MyKernel.BeamDrawer.BeamStart, MyKernel.BeamDrawer.BeamEnd);
         if (Char.WorldAABB.Intersects(ref WorkingRay))
         {
             Char.DoDamage(VanillaToolConstants.GrinderSpeed * NominalWorkingFrequency / 2, MyDamageType.Grind, true, null, MyKernel.Block.EntityId);
         }
     }
     //WriteToLog("ProcessCharacters", $"Attempting to damage {Characters.Count} characters");
 }
        void Work(int ticks = 1)
        {
            if (IsDrill)
            {
                return;
            }

            LineD WeldRay = new LineD(BeamCtlModule.BeamStart, BeamCtlModule.BeamEnd);
            List <MyLineSegmentOverlapResult <MyEntity> > Overlaps = new List <MyLineSegmentOverlapResult <MyEntity> >();

            MyGamePruningStructure.GetTopmostEntitiesOverlappingRay(ref WeldRay, Overlaps);

            HashSet <IMyCubeGrid>       Grids      = new HashSet <IMyCubeGrid>();
            HashSet <IMyCharacter>      Characters = new HashSet <IMyCharacter>();
            HashSet <IMyFloatingObject> Flobjes    = new HashSet <IMyFloatingObject>();

            Overlaps.Select(x => x.Element as IMyEntity).SortByType(Grids, Characters, Flobjes);
            Grids.Remove(ToolGrid);

            if (SessionCore.Settings.Debug && Vector3D.Distance(Tool.GetPosition(), MyAPIGateway.Session.LocalHumanPlayer.GetPosition()) <= 200)
            {
                string GridNames = "";
                foreach (var grid in Grids)
                {
                    GridNames += $"{grid.DisplayName};";
                }
                DebugNote.Text = $"{Tool.CustomName}: processing {Grids.Count} entities: {GridNames}{(IsWelder ? $" sup.invs: {GridInventoryModule.GetAccessibleInventories(Tool).Count}; unbuilt: {(this as LaserWelder).UnbuiltBlocks.Count}" : "")}";
                GridNames      = null;
            }

            foreach (IMyCubeGrid Grid in Grids)
            {
                //if (Grid.EntityId == ToolGrid.EntityId) continue;
                try
                {
                    ProcessGrid(Grid, ticks);
                }
                catch (Exception Scrap)
                {
                    SessionCore.LogError(Grid.DisplayName, Scrap);
                }
            }

            if (MyAPIGateway.Session.IsServer)
            {
                foreach (IMyCharacter Char in Characters)
                {
                    if (Char.WorldAABB.Intersects(ref WeldRay))
                    {
                        Char.DoDamage(VanillaToolConstants.GrinderSpeed * ticks / 2, MyDamageType.Grind, true, null, Tool.EntityId);
                    }
                }

                foreach (IMyFloatingObject Flobj in Flobjes)
                {
                    if (CargoFillRatio < 0.75)
                    {
                        ToolCargo.PickupItem(Flobj);
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
Exemple #5
0
        void Work(int ticks = 1)
        {
            if (!MyAPIGateway.Multiplayer.IsServer)
            {
                return;
            }
            if (IsDrill)
            {
                return;
            }

            LineD WeldRay = new LineD(BeamStart, BeamEnd);
            List <MyLineSegmentOverlapResult <MyEntity> > Overlaps = new List <MyLineSegmentOverlapResult <MyEntity> >();

            MyGamePruningStructure.GetTopmostEntitiesOverlappingRay(ref WeldRay, Overlaps);

            HashSet <IMyCubeGrid>       Grids      = new HashSet <IMyCubeGrid>();
            HashSet <IMyCharacter>      Characters = new HashSet <IMyCharacter>();
            HashSet <IMyFloatingObject> Flobjes    = new HashSet <IMyFloatingObject>();

            Overlaps.Select(x => x.Element as IMyEntity).SortByType(Grids, Characters, Flobjes);
            Grids.Remove(ToolGrid);

            if (SessionCore.Debug && Vector3D.Distance(BlockPosition, MyAPIGateway.Session.LocalHumanPlayer.GetPosition()) <= 200)
            {
                string GridNames = "";
                foreach (var grid in Grids)
                {
                    GridNames += $"{grid.DisplayName};";
                }
                DebugNote.Text = $"{Tool.CustomName}: processing {Grids.Count} entities: {GridNames}";
                GridNames      = null;
            }

            foreach (IMyCubeGrid Grid in Grids)
            {
                //if (Grid.EntityId == ToolGrid.EntityId) continue;
                try
                {
                    ProcessGrid(Grid, ticks);
                }
                catch (Exception Scrap)
                {
                    SessionCore.LogError(Grid.DisplayName, Scrap);
                }
            }

            foreach (IMyCharacter Char in Characters)
            {
                if (Char.WorldAABB.Intersects(ref WeldRay))
                {
                    Char.DoDamage(GrinderSpeed * ticks / 2, MyDamageType.Grind, true, null, Tool.EntityId);
                }
            }

            foreach (IMyFloatingObject Flobj in Flobjes)
            {
                if ((double)ToolCargo.CurrentVolume / (double)ToolCargo.MaxVolume < 0.75)
                {
                    ToolCargo.PickupItem(Flobj);
                }
            }

            /*if (Tool is IMyShipDrill)
             * {
             *  List<MyLineSegmentOverlapResult<MyVoxelBase>> VoxelOverlaps = new List<MyLineSegmentOverlapResult<MyVoxelBase>>();
             *  MyGamePruningStructure.GetVoxelMapsOverlappingRay(ref WeldRay, VoxelOverlaps);
             *  MyVoxelBase Voxel = VoxelOverlaps.OrderBy(x => Vector3D.DistanceSquared(BlockPosition, x.Element.PositionComp.GetPosition())).First().Element;
             *  ProcessVoxel(Voxel, ticks);
             * }*/
        }