Esempio n. 1
0
 public static bool AreOwnersOnline( GridGroup group )
 {
     foreach ( MyPlayer player in MySession.Static.Players.GetOnlinePlayers(  ) )
     {
         if ( group.SmallOwners.Contains(player.Identity.IdentityId) )
             return true;
     }
     return false;
 }
Esempio n. 2
0
        public static HashSet <GridGroup> GetGroups(HashSet <MyEntity> entities, GridLinkTypeEnum linkType = GridLinkTypeEnum.Logical)
        {
            HashSet <GridGroup> result = new HashSet <GridGroup>();

            //Create a copy of the entities list;
            //group processing can take so long that the internal list of entities can change
            //which is Bad.
            MyEntity[] entitiesCopy = new MyEntity[entities.Count];
            entities.CopyTo(entitiesCopy);

            //on large servers this can run into the tens of seconds, so parallelize it
            Parallel.ForEach(entitiesCopy, (entity) =>
            {
                MyCubeGrid grid = entity as MyCubeGrid;

                if (grid?.Physics == null || grid.Closed)
                {
                    return;
                }

                lock (result)
                    foreach (var item in result)
                    {
                        if (item._grids.Contains(grid))
                        {
                            return;
                        }
                    }

                var newGroup = new GridGroup(grid, linkType);

                lock (result)
                    result.Add(newGroup);
            });

            return(result);
        }
Esempio n. 3
0
        public static HashSet<GridGroup> GetGroups( HashSet<MyEntity> entities, GridLinkTypeEnum linkType = GridLinkTypeEnum.Logical )
        {
            HashSet<GridGroup> result = new HashSet<GridGroup>();

            //Create a copy of the entities list;
            //group processing can take so long that the internal list of entities can change
            //which is Bad.
            MyEntity[] entitiesCopy = new MyEntity[entities.Count];
            entities.CopyTo( entitiesCopy );

                //on large servers this can run into the tens of seconds, so parallelize it
            Parallel.ForEach( entitiesCopy, ( entity ) =>
                                            {
                                                MyCubeGrid grid = entity as MyCubeGrid;

                                                if (grid?.Physics == null || grid.Closed)
                                                    return;

                                                lock (result)
                                                    foreach(var item in result)
                                                        if ( item._grids.Contains( grid ) )
                                                            return;

                                                var newGroup = new GridGroup( grid, linkType );

                                                lock (result)
                                                    result.Add( newGroup );
                                            } );

            return result;
        }
Esempio n. 4
0
 public static bool IsGroupGridSize( GridGroup group, MyCubeSize size, bool isStatic = false )
 {
     if( isStatic )
         return group.Grids.Any( x => x?.Physics !=null && x.Physics.IsStatic );
     else
         return group.Grids.All( x => x.GridSizeEnum == size );
 }
Esempio n. 5
0
 public static bool IsGroupFunctional( GridGroup group )
 {
     foreach ( MyCubeBlock fatBlock in group.GetFatBlocks() )
     {
         MyFunctionalBlock block = fatBlock as MyFunctionalBlock;
         if ( block == null )
             continue;
         if ( block.IsFunctional )
             return true;
     }
     return false;
 }
Esempio n. 6
0
 public static bool DoesGroupHaveTerminal( GridGroup group )
 {
     return group.CubeBlocks.Any( x => (x?.FatBlock as MyTerminalBlock) != null );
 }
Esempio n. 7
0
 public static bool DoesGroupHavePowerSupply(GridGroup group )
 {
     return group.GetFatBlocks().Any( DoesBlockSupplyPower );
 }
Esempio n. 8
0
        public static bool DoesGroupHaveDisplayName( GridGroup group, string displayName, bool exact = false, bool grouped = false )
        {
            if ( !grouped && group.Grids.Count > 1 )
                return false;

            if ( !exact )
                return group.Grids.Any( x => x?.DisplayName != null && x.DisplayName.Contains( displayName, StringComparison.CurrentCultureIgnoreCase ) );
            else
                return group.Grids.Any( x => x?.DisplayName != null && x.DisplayName.Equals( displayName,StringComparison.CurrentCultureIgnoreCase ));
        }
Esempio n. 9
0
 public static bool DoesGroupHaveCustomName( GridGroup group, string customName, bool exact = false )
 {
     if ( !exact )
         return group.CubeBlocks.Any( x => x?.FatBlock?.DisplayNameText != null && x.FatBlock.DisplayNameText.Contains( customName, StringComparison.CurrentCultureIgnoreCase));
     else
         return group.CubeBlocks.Any( x => x?.FatBlock?.DisplayNameText != null && x.FatBlock.DisplayNameText.Equals( customName,StringComparison.CurrentCultureIgnoreCase ));
 }
Esempio n. 10
0
        public static bool DoesGroupHaveBlockType(GridGroup group, string type, int count)
        {
            int result = 0;

            foreach (MyCubeBlock block in group.GetFatBlocks())
            {
                if (block.BlockDefinition.Id.TypeId.ToString(  ).ToLower().Contains( type, StringComparison.CurrentCultureIgnoreCase ))
                    result++;

                if (result >= count)
                    return true;
            }
            return false;
        }