public override bool Invoke(ulong steamId, long playerId, string messageText)
        {
            if (messageText.Equals("/id", StringComparison.InvariantCultureIgnoreCase))
            {
                IMyEntity entity;
                double    distance;
                Vector3D  hitPoint;
                Support.FindLookAtEntity(MyAPIGateway.Session.ControlledObject, true, false, out entity, out distance, out hitPoint, true, true, true, true, true, true);
                if (entity != null)
                {
                    MessageTaggedEntityStore.RegisterIdentity(playerId, entity.EntityId);
                    string        displayType;
                    string        displayName;
                    StringBuilder description = new StringBuilder();
                    if (entity is IMyVoxelMap)
                    {
                        var voxelMap = (IMyVoxelMap)entity;
                        displayType = "asteroid";
                        displayName = voxelMap.StorageName;
                        var aabb = new BoundingBoxD(voxelMap.PositionLeftBottomCorner, voxelMap.PositionLeftBottomCorner + voxelMap.Storage.Size);
                        description.AppendFormat("Distance: {0:N} m\r\nSize: {1}\r\nBoundingBox Center: [X:{2:N} Y:{3:N} Z:{4:N}]\r\n\r\nUse /detail for more information on asteroid content.",
                                                 distance, voxelMap.Storage.Size,
                                                 aabb.Center.X, aabb.Center.Y, aabb.Center.Z);

                        MyAPIGateway.Utilities.ShowMissionScreen(string.Format("ID {0}:", displayType), string.Format("'{0}'", displayName), " ", description.ToString(), null, "OK");
                    }
                    else if (entity is Sandbox.Game.Entities.MyPlanet)
                    {
                        var planet = (Sandbox.Game.Entities.MyPlanet)entity;
                        displayType = "planet";
                        displayName = planet.StorageName;
                        description.AppendFormat("Distance: {0:N} m\r\nCenter: [X:{1:N} Y:{2:N} Z:{3:N}]\r\nMinimum Radius: {4:N} m\r\nMaximum Radius: {5:N} m\r\nAverage Radius: {6:N} m\r\nAtmosphere Radius: {7:N} m\r\nHas Atmosphere: {8}\r\nBreathable Atmosphere: {9}",
                                                 distance,
                                                 planet.WorldMatrix.Translation.X, planet.WorldMatrix.Translation.Y, planet.WorldMatrix.Translation.Z,
                                                 planet.MinimumRadius,
                                                 planet.MaximumRadius,
                                                 planet.AverageRadius,
                                                 planet.AtmosphereRadius,
                                                 planet.HasAtmosphere,
                                                 planet.Generator.Atmosphere.Breathable);

                        MySphericalNaturalGravityComponent naturalGravity = planet.Components.Get <MyGravityProviderComponent>() as MySphericalNaturalGravityComponent;
                        if (naturalGravity != null)
                        {
                            description.AppendLine();
                            description.AppendLine("Gravity Limit: {0:N} m",
                                                   naturalGravity.GravityLimit);
                        }

                        MyAPIGateway.Utilities.ShowMissionScreen(string.Format("ID {0}:", displayType), string.Format("'{0}'", displayName), " ", description.ToString(), null, "OK");
                    }
                    else if (entity is IMyCubeBlock || entity is IMyCubeGrid)
                    {
                        IMyCubeGrid  gridCube;
                        IMyCubeBlock cubeBlock = null;

                        if (entity is IMyCubeGrid)
                        {
                            gridCube = (IMyCubeGrid)entity;
                        }
                        else
                        {
                            cubeBlock = (IMyCubeBlock)entity;
                            gridCube  = (IMyCubeGrid)cubeBlock.GetTopMostParent();
                        }

                        var attachedGrids = gridCube.GetAttachedGrids(AttachedGrids.Static);
                        var blocks        = new List <IMySlimBlock>();
                        gridCube.GetBlocks(blocks);
                        //var cockpits = entity.FindWorkingCockpits(); // TODO: determine if any cockpits are occupied.


                        var identities = new List <IMyIdentity>();
                        MyAPIGateway.Players.GetAllIdentites(identities);
                        var ownerCounts = new Dictionary <long, long>();

                        foreach (var block in blocks.Where(f => f.FatBlock != null && f.FatBlock.OwnerId != 0))
                        {
                            if (ownerCounts.ContainsKey(block.FatBlock.OwnerId))
                            {
                                ownerCounts[block.FatBlock.OwnerId]++;
                            }
                            else
                            {
                                ownerCounts.Add(block.FatBlock.OwnerId, 1);
                            }
                        }

                        var ownerList = new List <string>();
                        foreach (var ownerKvp in ownerCounts)
                        {
                            var owner = identities.FirstOrDefault(p => p.IdentityId == ownerKvp.Key);
                            if (owner == null)
                            {
                                continue;
                            }
                            ownerList.Add(string.Format("{0} [{1}]", owner.DisplayName, ownerKvp.Value));
                        }

                        // TODO: BuiltBy needs to be made available in IMySlimBlock.
                        //var builtByCounts = new Dictionary<long, long>();
                        //foreach (var block in blocks.Where(f => f.FatBlock != null && ((MyCubeBlock)f).BuiltBy != 0))
                        //{
                        //    if (ownerCounts.ContainsKey(block.FatBlock.OwnerId))
                        //        ownerCounts[block.FatBlock.OwnerId]++;
                        //    else
                        //        ownerCounts.Add(block.FatBlock.OwnerId, 1);
                        //}


                        //var damage = new StringBuilder();
                        //var buildComplete = new StringBuilder();
                        var incompleteBlocks = 0;

                        foreach (var block in blocks)
                        {
                            //damage.    cube.IntegrityPercent <= cube.BuildPercent;
                            //complete.    cube.BuildPercent;

                            // This information does not appear to work.
                            // Unsure if the API is broken, incomplete , or a temporary bug under 01.070.
                            //damage.AppendFormat("D={0:N} ", block.DamageRatio);
                            //damage.AppendFormat("A={0:N} ", block.AccumulatedDamage);

                            if (!block.IsFullIntegrity)
                            {
                                incompleteBlocks++;
                                //buildComplete.AppendFormat("B={0:N} ", block.BuildLevelRatio);
                                //buildComplete.AppendFormat("I={0:N} ", block.BuildIntegrity);
                                //buildComplete.AppendFormat("M={0:N} ", block.MaxIntegrity);
                            }
                        }

                        displayType = gridCube.IsStatic ? "Station" : gridCube.GridSizeEnum.ToString() + " Ship";
                        displayName = gridCube.DisplayName;

                        description.AppendFormat("Distance: {0:N} m\r\n",
                                                 distance);

                        if (gridCube.Physics == null)
                        {
                            description.AppendFormat("Projection has no physics characteristics.\r\n");
                        }
                        else
                        {
                            description.AppendFormat("Mass: {0:N} kg\r\nVector: {1}\r\nVelocity: {2:N} m/s\r\nMass Center: {3}\r\n",
                                                     gridCube.Physics.Mass,
                                                     gridCube.Physics.LinearVelocity,
                                                     gridCube.Physics.LinearVelocity.Length(),
                                                     gridCube.Physics.CenterOfMassWorld);
                        }

                        description.AppendFormat("Size : {0}\r\nNumber of Blocks : {1:#,##0}\r\nAttached Grids : {2:#,##0} (including this one).\r\nOwners : {3}\r\nBuild : {4} blocks incomplete.",
                                                 gridCube.LocalAABB.Size,
                                                 blocks.Count,
                                                 attachedGrids.Count,
                                                 string.Join(", ", ownerList),
                                                 incompleteBlocks);

                        if (cubeBlock != null)
                        {
                            string ownerName = "";
                            var    owner     = identities.FirstOrDefault(p => p.IdentityId == cubeBlock.OwnerId);
                            if (owner != null)
                            {
                                ownerName = owner.DisplayName;
                            }

                            string builtByName = "";
                            var    builtBy     = identities.FirstOrDefault(p => p.IdentityId == ((MyCubeBlock)cubeBlock).BuiltBy);
                            if (builtBy != null)
                            {
                                builtByName = builtBy.DisplayName;
                            }
                            description.AppendFormat("\r\n\r\nCube;\r\n  Type : {1}\r\n  SubType : {0}\r\n  Name : {2}\r\n  Owner : {3}\r\n  BuiltBy : {4}", cubeBlock.BlockDefinition.SubtypeName, cubeBlock.DefinitionDisplayNameText, cubeBlock.DisplayNameText, ownerName, builtByName);
                        }

                        MyAPIGateway.Utilities.ShowMissionScreen(string.Format("ID {0}:", displayType), string.Format("'{0}'", displayName), " ", description.ToString(), null, "OK");
                    }
                    else if (entity is IMyCharacter)
                    {
                        displayType = "player";
                        displayName = entity.DisplayName;
                        description.AppendFormat("Distance: {0:N} m", distance);
                        MyAPIGateway.Utilities.ShowMissionScreen(string.Format("ID {0}:", displayType), string.Format("'{0}'", displayName), " ", description.ToString(), null, "OK");
                    }
                    else if (entity is MyInventoryBagEntity)
                    {
                        displayType = "Unknown";

                        var replicable = (MyInventoryBagEntity)entity;
                        if (replicable.DefinitionId.HasValue)
                        {
                            MyDefinitionBase definition;
                            if (MyDefinitionManager.Static.TryGetDefinition(replicable.DefinitionId.Value, out definition))
                            {
                                displayType = definition.Id.SubtypeName;
                            }
                        }

                        displayName = entity.DisplayName;
                        description.AppendFormat("Distance: {0:N} m", distance);
                        MyAPIGateway.Utilities.ShowMissionScreen(string.Format("ID {0}:", displayType), string.Format("'{0}'", displayName), " ", description.ToString(), null, "OK");
                    }
                    else
                    {
                        displayType = "unknown";
                        displayName = entity.DisplayName;
                        description.AppendFormat("Distance: {0:N} m", distance);
                        MyAPIGateway.Utilities.ShowMissionScreen(string.Format("ID {0}:", displayType), string.Format("'{0}'", displayName), " ", description.ToString(), null, "OK");
                    }

                    return(true);
                }

                MyAPIGateway.Utilities.ShowMessage("ID", "Could not find object.");
                return(true);
            }

            return(false);
        }
Beispiel #2
0
        public override bool Invoke(ulong steamId, long playerId, string messageText)
        {
            Action <Vector3D> saveTeleportBack = delegate(Vector3D position)
            {
                //save teleport in history
                CommandTeleportBack.SaveTeleportInHistory(playerId, position);
            };

            Action emptySourceMsg = delegate()
            {
                MyAPIGateway.Utilities.SendMessage(steamId, "Teleport failed", "Source entity no longer exists.");
            };

            Action emptyTargetMsg = delegate()
            {
                MyAPIGateway.Utilities.SendMessage(steamId, "Teleport failed", "Target entity no longer exists.");
            };

            Action noSafeLocationMsg = delegate()
            {
                MyAPIGateway.Utilities.SendMessage(steamId, "Failed", "Could not find safe location to transport to.");
            };

            var match = Regex.Match(messageText, teleportPattern, RegexOptions.IgnoreCase);

            if (match.Success)
            {
                var safely     = match.Groups["command"].Value.Equals("/tp", StringComparison.InvariantCultureIgnoreCase);
                var ident1     = !string.IsNullOrEmpty(match.Groups["ID1"].Value);
                var ident2     = !string.IsNullOrEmpty(match.Groups["ID2"].Value);
                var ship1      = !string.IsNullOrEmpty(match.Groups["Ship1"].Value);
                var ship2      = !string.IsNullOrEmpty(match.Groups["Ship2"].Value);
                var character1 = !string.IsNullOrEmpty(match.Groups["Character1"].Value);
                var character2 = !string.IsNullOrEmpty(match.Groups["Character2"].Value);
                var asteroid1  = !string.IsNullOrEmpty(match.Groups["Asteroid1"].Value);
                var asteroid2  = !string.IsNullOrEmpty(match.Groups["Asteroid2"].Value);
                var planet1    = !string.IsNullOrEmpty(match.Groups["Planet1"].Value);
                var planet2    = !string.IsNullOrEmpty(match.Groups["Planet2"].Value);
                var pos1       = !string.IsNullOrEmpty(match.Groups["X1"].Value);
                var pos2       = !string.IsNullOrEmpty(match.Groups["X2"].Value);
                var word1      = !string.IsNullOrEmpty(match.Groups["Quote1"].Value) || !string.IsNullOrEmpty(match.Groups["Word1"].Value);
                var word2      = !string.IsNullOrEmpty(match.Groups["Quote2"].Value) || !string.IsNullOrEmpty(match.Groups["Word2"].Value);
                var gps1       = !string.IsNullOrEmpty(match.Groups["GX1"].Value);
                var gps2       = !string.IsNullOrEmpty(match.Groups["GX2"].Value);
                //var currentPosition = MyAPIGateway.Session.Player.Controller.ControlledEntity.Entity.GetPosition();
                int index;
                List <IMyIdentity> identityCache = CommandPlayerStatus.GetIdentityCache(steamId);
                List <IMyEntity>   shipCache     = CommandListShips.GetShipCache(steamId);

                List <IMyVoxelBase> planetCache   = CommandPlanetsList.GetPlanetCache(steamId);
                List <IMyVoxelBase> asteroidCache = CommandAsteroidsList.GetAsteroidCache(steamId);

                IMyEntity taggedEntity = MessageTaggedEntityStore.GetEntity(playerId);

                #region Teleport You to target.

                if (!ident2 && !ship2 && !character2 && !asteroid2 && !planet2 && !word2 && !pos2 && !gps2)
                {
                    // move this player or the ship this player is in.
                    IMyPlayer player = MyAPIGateway.Players.GetPlayer(steamId);

                    if (ident1)
                    {
                        if (taggedEntity == null)
                        {
                            MyAPIGateway.Utilities.SendMessage(steamId, "Teleport failed", "No item identified yet.");
                            return(true);
                        }

                        if (taggedEntity is IMyIdentity)
                        {
                            Support.MoveTo(player, ((IMyIdentity)taggedEntity).Player(), safely, true, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg, steamId);
                            return(true);
                        }

                        if (taggedEntity is IMyCubeGrid)
                        {
                            Support.MoveTo(player, taggedEntity, safely, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg);
                            return(true);
                        }

                        if (taggedEntity is IMyCubeBlock)
                        {
                            Support.MoveTo(player, taggedEntity.GetTopMostParent(), safely, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg);
                            return(true);
                        }

                        if (taggedEntity is IMyVoxelBase)
                        {
                            Support.MoveTo(player, taggedEntity, safely, saveTeleportBack, noSafeLocationMsg, emptyTargetMsg, noSafeLocationMsg);
                            return(true);
                        }

                        MyAPIGateway.Utilities.SendMessage(steamId, "Teleport failed", "Item not teleportable to currently.");
                        return(true);
                    }
                    if (pos1)
                    {
                        var position = new Vector3D(
                            double.Parse(match.Groups["X1"].Value, CultureInfo.InvariantCulture),
                            double.Parse(match.Groups["Y1"].Value, CultureInfo.InvariantCulture),
                            double.Parse(match.Groups["Z1"].Value, CultureInfo.InvariantCulture));

                        Support.MoveTo(player, position, safely, saveTeleportBack, noSafeLocationMsg);
                        return(true);
                    }
                    if (gps1)
                    {
                        var position = new Vector3D(
                            double.Parse(match.Groups["GX1"].Value, CultureInfo.InvariantCulture),
                            double.Parse(match.Groups["GY1"].Value, CultureInfo.InvariantCulture),
                            double.Parse(match.Groups["GZ1"].Value, CultureInfo.InvariantCulture));

                        Support.MoveTo(player, position, safely, saveTeleportBack, noSafeLocationMsg);
                        return(true);
                    }
                    if (character1)
                    {
                        if (Int32.TryParse(match.Groups["Character1"].Value.Substring(1), out index) && index > 0 && index <= identityCache.Count)
                        {
                            IMyIdentity selectedPlayer = identityCache[index - 1];
                            Support.MoveTo(player, selectedPlayer.Player(), safely, true, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg, steamId);
                            return(true);
                        }
                    }
                    if (ship1)
                    {
                        if (Int32.TryParse(match.Groups["Ship1"].Value.Substring(1), out index) && index > 0 && index <= shipCache.Count)
                        {
                            var currentShipList = new HashSet <IMyEntity> {
                                shipCache[index - 1]
                            };
                            var targetShip = currentShipList.FirstElement();
                            Support.MoveTo(player, targetShip, safely, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg);
                            return(true);
                        }
                    }
                    if (asteroid1)
                    {
                        if (Int32.TryParse(match.Groups["Asteroid1"].Value.Substring(1), out index) && index > 0 && index <= asteroidCache.Count)
                        {
                            var currentAsteroidList = new HashSet <IMyEntity> {
                                asteroidCache[index - 1]
                            };
                            var asteroid = (IMyVoxelBase)currentAsteroidList.FirstElement();
                            Support.MoveTo(player, asteroid, safely, saveTeleportBack, noSafeLocationMsg, emptyTargetMsg, noSafeLocationMsg);
                            return(true);
                        }
                    }
                    if (planet1)
                    {
                        if (Int32.TryParse(match.Groups["Planet1"].Value.Substring(1), out index) && index > 0 && index <= planetCache.Count)
                        {
                            var currentPlanetList = new HashSet <IMyEntity> {
                                planetCache[index - 1]
                            };
                            var planet = (IMyVoxelBase)currentPlanetList.FirstElement();
                            Support.MoveTo(player, planet, safely, saveTeleportBack, noSafeLocationMsg, emptyTargetMsg, noSafeLocationMsg);
                            return(true);
                        }
                    }
                    if (word1)
                    {
                        var entityName = string.IsNullOrEmpty(match.Groups["Quote1"].Value) ? match.Groups["Word1"].Value : match.Groups["Quote1"].Value;

                        IMyPlayer foundPlayer;
                        IMyEntity foundEntity;
                        IMyGps    foundGps;
                        if (Support.FindEntitiesNamed(steamId, playerId, entityName, true, true, true, true, true, out foundPlayer, out foundEntity, out foundGps))
                        {
                            if (foundPlayer != null)
                            {
                                Support.MoveTo(player, foundPlayer, safely, true, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg, steamId);
                            }
                            if (foundEntity != null)
                            {
                                Support.MoveTo(player, foundEntity, safely, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg);
                            }
                            if (foundGps != null)
                            {
                                Support.MoveTo(player, foundGps.Coords, safely, saveTeleportBack, noSafeLocationMsg);
                            }
                        }
                        return(true); // FindEntitiesNamed should have displayed a message.
                    }

                    MyAPIGateway.Utilities.SendMessage(steamId, "Error", "Could not find specified object");
                    return(true);
                }

                #endregion

                #region Teleport entity to position.

                if (pos2)
                {
                    var position2 = new Vector3D(
                        double.Parse(match.Groups["X2"].Value, CultureInfo.InvariantCulture),
                        double.Parse(match.Groups["Y2"].Value, CultureInfo.InvariantCulture),
                        double.Parse(match.Groups["Z2"].Value, CultureInfo.InvariantCulture));

                    if (character1)
                    {
                        if (Int32.TryParse(match.Groups["Character1"].Value.Substring(1), out index) && index > 0 && index <= identityCache.Count)
                        {
                            IMyIdentity selectedPlayer = identityCache[index - 1];
                            Support.MoveTo(selectedPlayer.Player(), position2, safely, saveTeleportBack, noSafeLocationMsg);
                            return(true);
                        }
                    }
                    if (ship1)
                    {
                        if (Int32.TryParse(match.Groups["Ship1"].Value.Substring(1), out index) && index > 0 && index <= shipCache.Count)
                        {
                            var currentShipList = new HashSet <IMyEntity> {
                                shipCache[index - 1]
                            };
                            var sourceShip = currentShipList.FirstElement();
                            Support.MoveTo(sourceShip, position2, safely, saveTeleportBack, emptySourceMsg, noSafeLocationMsg);
                            return(true);
                        }
                    }
                    if (word1)
                    {
                        var entityName1 = string.IsNullOrEmpty(match.Groups["Quote1"].Value) ? match.Groups["Word1"].Value : match.Groups["Quote1"].Value;

                        IMyPlayer foundPlayer;
                        IMyEntity foundEntity;
                        IMyGps    foundGps;
                        if (Support.FindEntitiesNamed(steamId, playerId, entityName1, true, true, false, false, false, out foundPlayer, out foundEntity, out foundGps))
                        {
                            if (foundPlayer != null)
                            {
                                Support.MoveTo(foundPlayer, position2, safely, saveTeleportBack, noSafeLocationMsg);
                            }
                            if (foundEntity != null)
                            {
                                Support.MoveTo(foundEntity, position2, safely, saveTeleportBack, emptySourceMsg, noSafeLocationMsg);
                            }
                        }
                        return(true); // FindEntitiesNamed should have displayed a message.
                    }
                }

                #endregion

                #region Teleport entity to gps

                if (gps2)
                {
                    var position2 = new Vector3D(
                        double.Parse(match.Groups["GX2"].Value, CultureInfo.InvariantCulture),
                        double.Parse(match.Groups["GY2"].Value, CultureInfo.InvariantCulture),
                        double.Parse(match.Groups["GZ2"].Value, CultureInfo.InvariantCulture));

                    if (character1)
                    {
                        if (Int32.TryParse(match.Groups["Character1"].Value.Substring(1), out index) && index > 0 && index <= identityCache.Count)
                        {
                            IMyIdentity selectedPlayer = identityCache[index - 1];
                            Support.MoveTo(selectedPlayer.Player(), position2, safely, saveTeleportBack, noSafeLocationMsg);
                            return(true);
                        }
                    }
                    if (ship1)
                    {
                        if (Int32.TryParse(match.Groups["Ship1"].Value.Substring(1), out index) && index > 0 && index <= shipCache.Count)
                        {
                            var currentShipList = new HashSet <IMyEntity> {
                                shipCache[index - 1]
                            };
                            var sourceShip = currentShipList.FirstElement();
                            Support.MoveTo(sourceShip, position2, safely, saveTeleportBack, emptySourceMsg, noSafeLocationMsg);
                            return(true);
                        }
                    }
                    if (word1)
                    {
                        var entityName1 = string.IsNullOrEmpty(match.Groups["Quote1"].Value) ? match.Groups["Word1"].Value : match.Groups["Quote1"].Value;

                        IMyPlayer foundPlayer;
                        IMyEntity foundEntity;
                        IMyGps    foundGps;
                        if (Support.FindEntitiesNamed(steamId, playerId, entityName1, true, true, false, false, false, out foundPlayer, out foundEntity, out foundGps))
                        {
                            if (foundPlayer != null)
                            {
                                Support.MoveTo(foundPlayer, position2, safely, saveTeleportBack, noSafeLocationMsg);
                            }
                            if (foundEntity != null)
                            {
                                Support.MoveTo(foundEntity, position2, safely, saveTeleportBack, emptySourceMsg, noSafeLocationMsg);
                            }
                        }
                        return(true); // FindEntitiesNamed should have displayed a message.
                    }
                }

                #endregion

                #region Teleport entity to shipgrid.

                if (ship2)
                {
                    IMyEntity targetShip = null;
                    if (Int32.TryParse(match.Groups["Ship2"].Value.Substring(1), out index) && index > 0 && index <= shipCache.Count)
                    {
                        var currentShipList = new HashSet <IMyEntity> {
                            shipCache[index - 1]
                        };
                        targetShip = currentShipList.FirstElement();
                    }
                    if (targetShip == null)
                    {
                        MyAPIGateway.Utilities.SendMessage(steamId, "Teleport failed", "Target ship not found.");
                        return(true);
                    }

                    if (character1)
                    {
                        if (Int32.TryParse(match.Groups["Character1"].Value.Substring(1), out index) && index > 0 && index <= identityCache.Count)
                        {
                            IMyIdentity selectedPlayer = identityCache[index - 1];
                            Support.MoveTo(selectedPlayer.Player(), targetShip, safely, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg);
                            return(true);
                        }
                    }
                    if (ship1)
                    {
                        if (Int32.TryParse(match.Groups["Ship1"].Value.Substring(1), out index) && index > 0 && index <= shipCache.Count)
                        {
                            var currentShipList = new HashSet <IMyEntity> {
                                shipCache[index - 1]
                            };
                            var sourceShip = currentShipList.FirstElement();
                            Support.MoveTo(sourceShip, targetShip, safely, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg);
                            return(true);
                        }
                    }
                    if (word1)
                    {
                        var entityName1 = string.IsNullOrEmpty(match.Groups["Quote1"].Value) ? match.Groups["Word1"].Value : match.Groups["Quote1"].Value;

                        IMyPlayer foundPlayer;
                        IMyEntity foundEntity;
                        IMyGps    foundGps;
                        if (Support.FindEntitiesNamed(steamId, playerId, entityName1, true, true, false, false, false, out foundPlayer, out foundEntity, out foundGps))
                        {
                            if (foundPlayer != null)
                            {
                                Support.MoveTo(foundPlayer, targetShip, safely, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg);
                            }
                            if (foundEntity != null)
                            {
                                Support.MoveTo(foundEntity, targetShip, safely, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg);
                            }
                        }
                        return(true); // FindEntitiesNamed should have displayed a message.
                    }
                }

                #endregion

                #region Teleport entity to player.

                if (character2)
                {
                    IMyIdentity targetPlayer = null;
                    if (Int32.TryParse(match.Groups["Character2"].Value.Substring(1), out index) && index > 0 && index <= identityCache.Count)
                    {
                        targetPlayer = identityCache[index - 1];
                    }
                    if (targetPlayer == null)
                    {
                        MyAPIGateway.Utilities.SendMessage(steamId, "Teleport failed", "Target player not found.");
                        return(true);
                    }

                    if (character1)
                    {
                        if (Int32.TryParse(match.Groups["Character1"].Value.Substring(1), out index) && index > 0 && index <= identityCache.Count)
                        {
                            IMyIdentity selectedPlayer = identityCache[index - 1];
                            Support.MoveTo(selectedPlayer.Player(), targetPlayer.Player(), safely, false, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg, steamId);
                            return(true);
                        }
                    }
                    if (ship1)
                    {
                        if (Int32.TryParse(match.Groups["Ship1"].Value.Substring(1), out index) && index > 0 && index <= shipCache.Count)
                        {
                            var currentShipList = new HashSet <IMyEntity> {
                                shipCache[index - 1]
                            };
                            var sourceShip = currentShipList.FirstElement();
                            Support.MoveTo(sourceShip, targetPlayer.Player(), safely, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg);
                            return(true);
                        }
                    }
                    if (word1)
                    {
                        var entityName1 = string.IsNullOrEmpty(match.Groups["Quote1"].Value) ? match.Groups["Word1"].Value : match.Groups["Quote1"].Value;

                        IMyPlayer foundPlayer;
                        IMyEntity foundEntity;
                        IMyGps    foundGps;
                        if (Support.FindEntitiesNamed(steamId, playerId, entityName1, true, true, false, false, false, out foundPlayer, out foundEntity, out foundGps))
                        {
                            if (foundPlayer != null)
                            {
                                Support.MoveTo(foundPlayer, targetPlayer.Player(), safely, false, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg, steamId);
                            }
                            if (foundEntity != null)
                            {
                                Support.MoveTo(foundEntity, targetPlayer.Player(), safely, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg);
                            }
                        }
                        return(true); // FindEntitiesNamed should have displayed a message.
                    }
                }

                #endregion

                #region Teleport entity to named entity.

                if (word2)
                {
                    var entityName2 = string.IsNullOrEmpty(match.Groups["Quote2"].Value) ? match.Groups["Word2"].Value : match.Groups["Quote2"].Value;

                    if (character1)
                    {
                        if (Int32.TryParse(match.Groups["Character1"].Value.Substring(1), out index) && index > 0 && index <= identityCache.Count)
                        {
                            IMyIdentity selectedPlayer = identityCache[index - 1];

                            IMyPlayer foundPlayer;
                            IMyEntity foundEntity;
                            IMyGps    foundGps;
                            if (Support.FindEntitiesNamed(steamId, playerId, entityName2, true, true, true, true, true, out foundPlayer, out foundEntity, out foundGps))
                            {
                                if (foundPlayer != null)
                                {
                                    Support.MoveTo(selectedPlayer.Player(), foundPlayer, safely, false, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg, steamId);
                                }
                                if (foundEntity != null)
                                {
                                    Support.MoveTo(selectedPlayer.Player(), foundEntity, safely, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg);
                                }
                                if (foundGps != null)
                                {
                                    Support.MoveTo(selectedPlayer.Player(), foundGps.Coords, safely, saveTeleportBack, noSafeLocationMsg);
                                }
                            }
                            return(true); // FindEntitiesNamed should have displayed a message.
                        }
                    }
                    if (ship1)
                    {
                        if (Int32.TryParse(match.Groups["Ship1"].Value.Substring(1), out index) && index > 0 && index <= shipCache.Count)
                        {
                            var currentShipList = new HashSet <IMyEntity> {
                                shipCache[index - 1]
                            };
                            var selectedShip = currentShipList.FirstElement();

                            IMyPlayer foundPlayer;
                            IMyEntity foundEntity;
                            IMyGps    foundGps;
                            if (Support.FindEntitiesNamed(steamId, playerId, entityName2, true, true, true, true, true, out foundPlayer, out foundEntity, out foundGps))
                            {
                                if (foundPlayer != null)
                                {
                                    Support.MoveTo(selectedShip, foundPlayer, safely, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg);
                                }
                                if (foundEntity != null)
                                {
                                    Support.MoveTo(selectedShip, foundEntity, safely, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg);
                                }
                                if (foundGps != null)
                                {
                                    Support.MoveTo(selectedShip, foundGps.Coords, safely, saveTeleportBack, emptySourceMsg, noSafeLocationMsg);
                                }
                            }
                            return(true); // FindEntitiesNamed should have displayed a message.
                        }
                    }
                    if (word1)
                    {
                        var entityName1 = string.IsNullOrEmpty(match.Groups["Quote1"].Value) ? match.Groups["Word1"].Value : match.Groups["Quote1"].Value;

                        IMyPlayer foundPlayer1;
                        IMyEntity foundEntity1;
                        IMyGps    foundGps1;
                        IMyPlayer foundPlayer2;
                        IMyEntity foundEntity2;
                        IMyGps    foundGps2;

                        var result1 = Support.FindEntitiesNamed(steamId, playerId, entityName1, true, true, false, false, false, out foundPlayer1, out foundEntity1, out foundGps1);
                        var result2 = Support.FindEntitiesNamed(steamId, playerId, entityName2, true, true, true, true, true, out foundPlayer2, out foundEntity2, out foundGps2);

                        if (result1 && result2)
                        {
                            if (foundPlayer1 != null && foundPlayer2 != null)
                            {
                                Support.MoveTo(foundPlayer1, foundPlayer2, safely, true, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg, steamId);
                            }
                            if (foundPlayer1 != null && foundEntity2 != null)
                            {
                                Support.MoveTo(foundPlayer1, foundEntity2, safely, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg);
                            }
                            if (foundPlayer1 != null && foundGps2 != null)
                            {
                                Support.MoveTo(foundPlayer1, foundGps2.Coords, safely, saveTeleportBack, noSafeLocationMsg);
                            }
                            if (foundEntity1 != null && foundPlayer2 != null)
                            {
                                Support.MoveTo(foundEntity1, foundPlayer2, safely, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg);
                            }
                            if (foundEntity1 != null && foundEntity2 != null)
                            {
                                Support.MoveTo(foundEntity1, foundEntity2, safely, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg);
                            }
                            if (foundEntity1 != null && foundGps2 != null)
                            {
                                Support.MoveTo(foundEntity1, foundGps2.Coords, safely, saveTeleportBack, emptySourceMsg, noSafeLocationMsg);
                            }
                        }
                        if (!result1)
                        {
                            MyAPIGateway.Utilities.SendMessage(steamId, "Failed", "Could not find '{0}'", entityName1);
                        }
                        if (!result2)
                        {
                            MyAPIGateway.Utilities.SendMessage(steamId, "Failed", "Could not find '{0}'", entityName2);
                        }
                        return(true); // FindEntitiesNamed should have displayed a message.
                    }
                }

                #endregion

                #region Teleport entity to ID

                if (ident1 && ident2)
                {
                    MyAPIGateway.Utilities.SendMessage(steamId, "Teleport failed", "cannot teleport item to itself.");
                    return(true);
                }

                if (ident2)
                {
                    if (taggedEntity == null)
                    {
                        MyAPIGateway.Utilities.SendMessage(steamId, "Teleport failed", "No item identified yet.");
                        return(true);
                    }

                    if (character1)
                    {
                        if (Int32.TryParse(match.Groups["Character1"].Value.Substring(1), out index) && index > 0 && index <= identityCache.Count)
                        {
                            IMyIdentity selectedPlayer = identityCache[index - 1];
                            if (taggedEntity is IMyIdentity)
                            {
                                Support.MoveTo(selectedPlayer.Player(), ((IMyIdentity)taggedEntity).Player(), safely, false, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg, steamId);
                            }
                            if (taggedEntity is IMyCubeGrid)
                            {
                                Support.MoveTo(selectedPlayer.Player(), taggedEntity, safely, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg);
                            }
                            if (taggedEntity is IMyCubeBlock)
                            {
                                Support.MoveTo(selectedPlayer.Player(), taggedEntity.GetTopMostParent(), safely, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg);
                            }
                            if (taggedEntity is IMyVoxelBase)
                            {
                                Support.MoveTo(selectedPlayer.Player(), taggedEntity, safely, saveTeleportBack, noSafeLocationMsg, emptyTargetMsg, noSafeLocationMsg);
                            }
                            return(true);
                        }
                    }
                    if (ship1)
                    {
                        if (Int32.TryParse(match.Groups["Ship1"].Value.Substring(1), out index) && index > 0 && index <= shipCache.Count)
                        {
                            var currentShipList = new HashSet <IMyEntity> {
                                shipCache[index - 1]
                            };
                            var sourceShip = currentShipList.FirstElement();
                            if (taggedEntity is IMyIdentity)
                            {
                                Support.MoveTo(sourceShip, ((IMyIdentity)taggedEntity).Player(), safely, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg);
                            }
                            if (taggedEntity is IMyCubeGrid)
                            {
                                Support.MoveTo(sourceShip, taggedEntity, safely, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg);
                            }
                            if (taggedEntity is IMyCubeBlock)
                            {
                                Support.MoveTo(sourceShip, taggedEntity.GetTopMostParent(), safely, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg);
                            }
                            if (taggedEntity is IMyVoxelBase)
                            {
                                Support.MoveTo(sourceShip, taggedEntity, safely, saveTeleportBack, noSafeLocationMsg, emptyTargetMsg, noSafeLocationMsg);
                            }
                            return(true);
                        }
                    }
                    if (word1)
                    {
                        var entityName1 = string.IsNullOrEmpty(match.Groups["Quote1"].Value) ? match.Groups["Word1"].Value : match.Groups["Quote1"].Value;

                        IMyPlayer foundPlayer;
                        IMyEntity foundEntity;
                        IMyGps    foundGps;
                        if (Support.FindEntitiesNamed(steamId, playerId, entityName1, true, true, false, false, false, out foundPlayer, out foundEntity, out foundGps))
                        {
                            if (foundPlayer != null && taggedEntity is IMyIdentity)
                            {
                                Support.MoveTo(foundPlayer, ((IMyIdentity)taggedEntity).Player(), safely, false, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg, steamId);
                            }
                            if (foundPlayer != null && taggedEntity is IMyCubeGrid)
                            {
                                Support.MoveTo(foundPlayer, taggedEntity, safely, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg);
                            }
                            if (foundPlayer != null && taggedEntity is IMyCubeBlock)
                            {
                                Support.MoveTo(foundPlayer, taggedEntity.GetTopMostParent(), safely, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg);
                            }
                            if (foundPlayer != null && taggedEntity is IMyVoxelBase)
                            {
                                Support.MoveTo(foundPlayer, taggedEntity, safely, saveTeleportBack, noSafeLocationMsg, emptyTargetMsg, noSafeLocationMsg);
                            }
                            if (foundEntity != null && taggedEntity is IMyIdentity)
                            {
                                Support.MoveTo(foundEntity, ((IMyIdentity)taggedEntity).Player(), safely, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg);
                            }
                            if (foundEntity != null && taggedEntity is IMyCubeGrid)
                            {
                                Support.MoveTo(foundEntity, taggedEntity, safely, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg);
                            }
                            if (foundEntity != null && taggedEntity is IMyCubeBlock)
                            {
                                Support.MoveTo(foundEntity, taggedEntity.GetTopMostParent(), safely, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg);
                            }
                            if (foundEntity != null && taggedEntity is IMyVoxelBase)
                            {
                                Support.MoveTo(foundEntity, taggedEntity, safely, saveTeleportBack, noSafeLocationMsg, emptyTargetMsg, noSafeLocationMsg);
                            }
                        }
                        return(true); // FindEntitiesNamed should have displayed a message.
                    }
                }

                #endregion

                #region Teleport entity to asteroid.

                if (asteroid2)
                {
                    IMyEntity targetAsteroid = null;
                    if (Int32.TryParse(match.Groups["Asteroid2"].Value.Substring(1), out index) && index > 0 && index <= asteroidCache.Count)
                    {
                        var currentAsteroidList = new HashSet <IMyEntity> {
                            asteroidCache[index - 1]
                        };
                        targetAsteroid = currentAsteroidList.FirstElement();
                    }
                    if (targetAsteroid == null)
                    {
                        MyAPIGateway.Utilities.SendMessage(steamId, "Teleport failed", "Target asteroid not found.");
                        return(true);
                    }

                    if (character1)
                    {
                        if (Int32.TryParse(match.Groups["Character1"].Value.Substring(1), out index) && index > 0 && index <= identityCache.Count)
                        {
                            IMyIdentity selectedPlayer = identityCache[index - 1];
                            Support.MoveTo(selectedPlayer.Player(), targetAsteroid, safely, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg);
                            return(true);
                        }
                    }
                    if (ship1)
                    {
                        if (Int32.TryParse(match.Groups["Ship1"].Value.Substring(1), out index) && index > 0 && index <= shipCache.Count)
                        {
                            var currentShipList = new HashSet <IMyEntity> {
                                shipCache[index - 1]
                            };
                            var sourceShip = currentShipList.FirstElement();
                            Support.MoveTo(sourceShip, targetAsteroid, safely, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg);
                            return(true);
                        }
                    }
                    if (word1)
                    {
                        var entityName1 = string.IsNullOrEmpty(match.Groups["Quote1"].Value) ? match.Groups["Word1"].Value : match.Groups["Quote1"].Value;

                        IMyPlayer foundPlayer;
                        IMyEntity foundEntity;
                        IMyGps    foundGps;
                        if (Support.FindEntitiesNamed(steamId, playerId, entityName1, true, true, false, false, false, out foundPlayer, out foundEntity, out foundGps))
                        {
                            if (foundPlayer != null)
                            {
                                Support.MoveTo(foundPlayer, targetAsteroid, safely, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg);
                            }
                            if (foundEntity != null)
                            {
                                Support.MoveTo(foundEntity, targetAsteroid, safely, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg);
                            }
                        }
                        return(true); // FindEntitiesNamed should have displayed a message.
                    }
                }

                #endregion

                #region Teleport entity to planet.

                if (planet2)
                {
                    IMyEntity targetPlanet = null;
                    if (Int32.TryParse(match.Groups["Planet2"].Value.Substring(1), out index) && index > 0 && index <= planetCache.Count)
                    {
                        var currentPlanetList = new HashSet <IMyEntity> {
                            planetCache[index - 1]
                        };
                        targetPlanet = currentPlanetList.FirstElement();
                    }
                    if (targetPlanet == null)
                    {
                        MyAPIGateway.Utilities.SendMessage(steamId, "Teleport failed", "Target planet not found.");
                        return(true);
                    }

                    if (character1)
                    {
                        if (Int32.TryParse(match.Groups["Character1"].Value.Substring(1), out index) && index > 0 && index <= identityCache.Count)
                        {
                            IMyIdentity selectedPlayer = identityCache[index - 1];
                            Support.MoveTo(selectedPlayer.Player(), targetPlanet, safely, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg);
                            return(true);
                        }
                    }
                    if (ship1)
                    {
                        if (Int32.TryParse(match.Groups["Ship1"].Value.Substring(1), out index) && index > 0 && index <= shipCache.Count)
                        {
                            var currentShipList = new HashSet <IMyEntity> {
                                shipCache[index - 1]
                            };
                            var sourceShip = currentShipList.FirstElement();
                            Support.MoveTo(sourceShip, targetPlanet, safely, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg);
                            return(true);
                        }
                    }
                    if (word1)
                    {
                        var entityName1 = string.IsNullOrEmpty(match.Groups["Quote1"].Value) ? match.Groups["Word1"].Value : match.Groups["Quote1"].Value;

                        IMyPlayer foundPlayer;
                        IMyEntity foundEntity;
                        IMyGps    foundGps;
                        if (Support.FindEntitiesNamed(steamId, playerId, entityName1, true, true, false, false, false, out foundPlayer, out foundEntity, out foundGps))
                        {
                            if (foundPlayer != null)
                            {
                                Support.MoveTo(foundPlayer, targetPlanet, safely, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg);
                            }
                            if (foundEntity != null)
                            {
                                Support.MoveTo(foundEntity, targetPlanet, safely, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg);
                            }
                        }
                        return(true); // FindEntitiesNamed should have displayed a message.
                    }
                }

                #endregion

                // more move logic goes here. If we can figure out if we need more. When we need it.

                MyAPIGateway.Utilities.SendMessage(steamId, "Incomplete", "This function of teleport is not complete.");
                return(true);
            }

            match = Regex.Match(messageText, teleportPattern2, RegexOptions.IgnoreCase);
            if (match.Success)
            {
                var safely     = match.Groups["command"].Value.Equals("/tp", StringComparison.InvariantCultureIgnoreCase);
                var entityName = match.Groups["Word1"].Value;

                IMyPlayer player = MyAPIGateway.Players.GetPlayer(steamId);
                IMyPlayer foundPlayer;
                IMyEntity foundEntity;
                IMyGps    foundGps;
                if (Support.FindEntitiesNamed(steamId, playerId, entityName, true, true, true, true, true, out foundPlayer, out foundEntity, out foundGps))
                {
                    if (foundPlayer != null)
                    {
                        Support.MoveTo(player, foundPlayer, safely, true, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg, steamId);
                    }
                    if (foundEntity != null)
                    {
                        Support.MoveTo(player, foundEntity, safely, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg);
                    }
                    if (foundGps != null)
                    {
                        Support.MoveTo(player, foundGps.Coords, safely, saveTeleportBack, noSafeLocationMsg);
                    }
                }
                return(true); // FindEntitiesNamed should have displayed a message.
            }

            return(false);
        }