Esempio n. 1
0
        private List <MyGps> FindGrids(IGridDetectionStrategy gridDetectionStrategy, int min, int distance, bool ignoreOffline, bool ignoreNpcs, long seconds)
        {
            List <KeyValuePair <long, List <MyCubeGrid> > > grids         = gridDetectionStrategy.FindGrids(Plugin.Config, Plugin.UseConnectedGrids);
            List <KeyValuePair <long, List <MyCubeGrid> > > filteredGrids = gridDetectionStrategy.GetFilteredGrids(grids,
                                                                                                                   min, distance, Plugin.TopGrids, ignoreOffline, ignoreNpcs);

            List <MyGps> gpsList = new List <MyGps>();

            int i = 0;

            Color gpsColor = Plugin.GpsColor;

            foreach (KeyValuePair <long, List <MyCubeGrid> > pair in filteredGrids)
            {
                i++;

                MyCubeGrid grid = pair.Value[0]; /* Cannot be empty because where do the PCUs come from? */

                var position = grid.PositionComp.GetPosition();

                if (Plugin.LogBroadcastedGrids)
                {
                    LogGrid(grid);
                }

                MyGps gps = CreateGps(i, grid, gpsColor, seconds);

                gpsList.Add(gps);
            }

            return(gpsList);
        }
Esempio n. 2
0
        private void AddGridsToSb(IGridDetectionStrategy gridDetectionStrategy, int min, int distance, bool ignoreOffline, StringBuilder sb, long seconds)
        {
            int  top            = Plugin.TopGrids;
            int  playerdistance = distance;
            bool connected      = Plugin.UseConnectedGrids;
            bool filterOffline  = ignoreOffline;
            bool gps            = false;
            bool ignoreNpcs     = Plugin.IgnoreNPCs;

            List <string> args = Context.Args;

            foreach (string arg in args)
            {
                if (arg == "-phsical")
                {
                    connected = true;
                }

                if (arg == "-mechanical")
                {
                    connected = false;
                }

                if (arg == "-gps")
                {
                    gps = true;
                }

                if (arg == "-showOffline")
                {
                    filterOffline = false;
                }

                if (arg.StartsWith("-top="))
                {
                    string localArg = arg.Replace("-top=", "");
                    int.TryParse(localArg, out top);
                }

                if (arg.StartsWith("-min="))
                {
                    string localArg = arg.Replace("-min=", "");
                    int.TryParse(localArg, out min);
                }

                if (arg.StartsWith("-playerdistance="))
                {
                    string localArg = arg.Replace("-playerdistance=", "");
                    int.TryParse(localArg, out playerdistance);
                }

                if (arg.StartsWith("-ignoreNpcs="))
                {
                    string localArg = arg.Replace("-ignoreNpcs=", "");
                    bool.TryParse(localArg, out ignoreNpcs);
                }
            }

            var PluginConfig = Plugin.Config;

            List <KeyValuePair <long, List <MyCubeGrid> > > grids         = gridDetectionStrategy.FindGrids(PluginConfig, connected);
            List <KeyValuePair <long, List <MyCubeGrid> > > filteredGrids = gridDetectionStrategy.GetFilteredGrids(grids, min, playerdistance, top, filterOffline, ignoreNpcs);

            gridDetectionStrategy.WriteSettings(sb, top, playerdistance, min, filterOffline, ignoreNpcs, connected, PluginConfig);

            sb.AppendLine();

            sb.AppendLine("Result");
            sb.AppendLine("---------------------------------------");

            int i = 0;

            Color gpsColor = Plugin.GpsColor;

            if (gps && Context.Player != null)
            {
                Plugin.RemoveGpsFromPlayer(Context.Player.IdentityId);
            }

            if (filteredGrids.Count == 0)
            {
                sb.AppendLine("-");
            }

            foreach (KeyValuePair <long, List <MyCubeGrid> > pair in filteredGrids)
            {
                i++;

                MyCubeGrid biggestGrid = GridUtils.GetBiggestGridInGroup(pair.Value);

                var gridOwnerList = biggestGrid.BigOwners;
                var ownerCnt      = gridOwnerList.Count;
                var gridOwner     = 0L;

                if (ownerCnt > 0 && gridOwnerList[0] != 0)
                {
                    gridOwner = gridOwnerList[0];
                }
                else if (ownerCnt > 1)
                {
                    gridOwner = gridOwnerList[1];
                }

                IMyFaction faction = GetFactionForPlayer(gridOwner);

                string factionString = "";
                if (faction != null)
                {
                    factionString = "[" + faction.Tag + "]";
                }


                sb.AppendLine(i + ". " + pair.Key.ToString("#,##0") + " " + gridDetectionStrategy.GetUnitName() + " - " + biggestGrid.DisplayName);
                sb.AppendLine("   " + pair.Value.Count + " Grids.");
                sb.AppendLine("   Owned by: " + GetPlayerNameById(gridOwner) + " " + factionString);

                MyCubeGrid grid = pair.Value[0]; /* Cannot be empty because where do the PCUs come from? */

                var position = grid.PositionComp.GetPosition();

                sb.AppendLine($"   X: {position.X.ToString("#,##0.00")}, Y: {position.Y.ToString("#,##0.00")}, Z: {position.Z.ToString("#,##0.00")}");

                if (gps && Context.Player != null)
                {
                    MyGps gridGPS = CreateGps(i, grid, gpsColor, seconds);

                    MyAPIGateway.Session?.GPS.AddGps(Context.Player.IdentityId, gridGPS);
                }
            }

            sb.AppendLine();
            sb.AppendLine();
        }