예제 #1
0
        public override bool Invoke(ulong steamId, long playerId, string messageText)
        {
            var match = Regex.Match(messageText, @"/invclear\s{1,}(?<Key>.+)", RegexOptions.IgnoreCase);

            if (match.Success)
            {
                var playerName = match.Groups["Key"].Value;
                var players    = new List <IMyPlayer>();
                MyAPIGateway.Players.GetPlayers(players, p => p != null);

                var identities = new List <IMyIdentity>();
                MyAPIGateway.Players.GetAllIdentites(identities, i => i.DisplayName.Equals(playerName, StringComparison.InvariantCultureIgnoreCase));
                IMyIdentity selectedPlayer = identities.FirstOrDefault();

                int index;
                List <IMyIdentity> cacheList = CommandPlayerStatus.GetIdentityCache(steamId);
                if (playerName.Substring(0, 1) == "#" && int.TryParse(playerName.Substring(1), out index) && index > 0 && index <= cacheList.Count)
                {
                    selectedPlayer = cacheList[index - 1];
                }

                if (selectedPlayer == null)
                {
                    return(false);
                }

                ClearInventory(steamId, selectedPlayer.IdentityId);
                return(true);
            }

            return(false);
        }
        public override bool Invoke(ulong steamId, long playerId, string messageText)
        {
            var match = Regex.Match(messageText, @"/fk\s{1,}(?<Key>.+)", RegexOptions.IgnoreCase);

            if (match.Success)
            {
                var playerName = match.Groups["Key"].Value;
                var players    = new List <IMyPlayer>();
                MyAPIGateway.Players.GetPlayers(players, p => p != null);
                IMyIdentity selectedPlayer = null;

                var identities = new List <IMyIdentity>();
                MyAPIGateway.Players.GetAllIdentites(identities, delegate(IMyIdentity i) { return(i.DisplayName.Equals(playerName, StringComparison.InvariantCultureIgnoreCase)); });
                selectedPlayer = identities.FirstOrDefault();

                int index;
                List <IMyIdentity> cacheList = CommandPlayerStatus.GetIdentityCache(steamId);
                if (playerName.Substring(0, 1) == "#" && Int32.TryParse(playerName.Substring(1), out index) && index > 0 && index <= cacheList.Count)
                {
                    selectedPlayer = cacheList[index - 1];
                }

                List <IMyIdentity> botCacheList = CommandListBots.GetIdentityCache(steamId);
                if (playerName.Substring(0, 1).Equals("B", StringComparison.InvariantCultureIgnoreCase) && Int32.TryParse(playerName.Substring(1), out index) && index > 0 && index <= botCacheList.Count)
                {
                    selectedPlayer = botCacheList[index - 1];
                }

                if (selectedPlayer == null)
                {
                    return(false);
                }

                var fc = MyAPIGateway.Session.Factions.GetObjectBuilder();

                var request = fc.Factions.FirstOrDefault(f => f.JoinRequests.Any(r => r.PlayerId == selectedPlayer.IdentityId));
                if (request != null)
                {
                    MessageSyncFaction.CancelJoinFaction(request.FactionId, selectedPlayer.IdentityId);
                    //MyAPIGateway.Session.Factions.CancelJoinRequest(request.FactionId, selectedPlayer.IdentityId);
                    MyAPIGateway.Utilities.SendMessage(steamId, "kick", "{0} has had join request cancelled.", selectedPlayer.DisplayName);
                    return(true);
                }

                var factionBuilder = fc.Factions.FirstOrDefault(f => f.Members.Any(m => m.PlayerId == selectedPlayer.IdentityId));

                if (factionBuilder == null)
                {
                    MyAPIGateway.Utilities.SendMessage(steamId, "kick", "{0} is not in faction.", selectedPlayer.DisplayName);
                    return(true);
                }

                MessageSyncFaction.KickFaction(factionBuilder.FactionId, selectedPlayer.IdentityId);
                MyAPIGateway.Utilities.SendMessage(steamId, "kick", "{0} has been removed from faction.", selectedPlayer.DisplayName);
                return(true);
            }

            return(false);
        }
        public override bool Invoke(ulong steamId, long playerId, string messageText)
        {
            var match = Regex.Match(messageText, @"/forceban\s+(?<Key>.+)", RegexOptions.IgnoreCase);

            if (match.Success)
            {
                var playerName = match.Groups["Key"].Value;
                var players    = new List <IMyPlayer>();
                MyAPIGateway.Players.GetPlayers(players, p => p != null);
                IMyPlayer selectedPlayer = null;

                var findPlayer = players.FirstOrDefault(p => p.DisplayName.Equals(playerName, StringComparison.InvariantCultureIgnoreCase));
                if (findPlayer != null)
                {
                    selectedPlayer = findPlayer;
                }

                int index;
                List <IMyIdentity> cacheList = CommandPlayerStatus.GetIdentityCache(steamId);
                if (playerName.Substring(0, 1) == "#" && Int32.TryParse(playerName.Substring(1), out index) && index > 0 && index <= cacheList.Count)
                {
                    var listplayers = new List <IMyPlayer>();
                    MyAPIGateway.Players.GetPlayers(listplayers, p => p.IdentityId == cacheList[index - 1].IdentityId);
                    selectedPlayer = listplayers.FirstOrDefault();
                }

                if (selectedPlayer == null)
                {
                    MyAPIGateway.Utilities.SendMessage(steamId, "ForceBan", "No player named {0} found.", playerName);
                    return(true);
                }

                ChatCommandLogic.Instance.ServerCfg.Config.ForceBannedPlayers.Add(new Player()
                {
                    SteamId    = selectedPlayer.SteamUserId,
                    PlayerName = selectedPlayer.DisplayName
                });

                ConnectionHelper.SendMessageToPlayer(selectedPlayer.SteamUserId, new MessageForceDisconnect {
                    SteamId = selectedPlayer.SteamUserId, Ban = true
                });
                MyAPIGateway.Utilities.SendMessage(steamId, "Server", "{0} player Forcebanned", selectedPlayer.DisplayName);

                return(true);
            }

            return(false);
        }
        public override bool Invoke(ulong steamId, long playerId, string messageText)
        {
            var match = Regex.Match(messageText, @"/invclear\s{1,}(?<Key>.+)", RegexOptions.IgnoreCase);

            if (match.Success)
            {
                var playerName = match.Groups["Key"].Value;
                var players    = new List <IMyPlayer>();
                MyAPIGateway.Players.GetPlayers(players, p => p != null);
                IMyIdentity selectedPlayer = null;

                var identities = new List <IMyIdentity>();
                MyAPIGateway.Players.GetAllIdentites(identities, delegate(IMyIdentity i) { return(i.DisplayName.Equals(playerName, StringComparison.InvariantCultureIgnoreCase)); });
                selectedPlayer = identities.FirstOrDefault();

                int index;
                List <IMyIdentity> cacheList = CommandPlayerStatus.GetIdentityCache(steamId);
                if (playerName.Substring(0, 1) == "#" && Int32.TryParse(playerName.Substring(1), out index) && index > 0 && index <= cacheList.Count)
                {
                    selectedPlayer = cacheList[index - 1];
                }

                if (selectedPlayer == null)
                {
                    return(false);
                }

                if (!MyAPIGateway.Multiplayer.MultiplayerActive)
                {
                    ClearInventory(0, selectedPlayer.PlayerId);
                }
                else
                {
                    ConnectionHelper.SendMessageToServer(new MessageSyncCreateObject()
                    {
                        EntityId = selectedPlayer.PlayerId,
                        Type     = SyncCreateObjectType.Clear,
                    });
                }
                return(true);
            }

            return(false);
        }
        public override bool Invoke(ulong steamId, long playerId, string messageText)
        {
            var match = Regex.Match(messageText, @"/smite\s+(?:(?:""(?<name>[^""]|.*?)"")|(?<name>.*))", RegexOptions.IgnoreCase);

            if (match.Success)
            {
                var playerName = match.Groups["name"].Value;
                var players    = new List <IMyPlayer>();
                MyAPIGateway.Players.GetPlayers(players, p => p != null);
                IMyPlayer selectedPlayer = null;

                var findPlayer = players.FirstOrDefault(p => p.DisplayName.Equals(playerName, StringComparison.InvariantCultureIgnoreCase));
                if (findPlayer != null)
                {
                    selectedPlayer = findPlayer;
                }

                int index;
                List <IMyIdentity> cacheList = CommandPlayerStatus.GetIdentityCache(steamId);
                if (playerName.Substring(0, 1) == "#" && Int32.TryParse(playerName.Substring(1), out index) && index > 0 && index <= cacheList.Count)
                {
                    var listplayers = new List <IMyPlayer>();
                    MyAPIGateway.Players.GetPlayers(listplayers, p => p.IdentityId == cacheList[index - 1].IdentityId);
                    selectedPlayer = listplayers.FirstOrDefault();
                }

                if (selectedPlayer == null)
                {
                    MyAPIGateway.Utilities.SendMessage(steamId, "Smite", "No player named '{0}' found.", playerName);
                    return(true);
                }

                MyAPIGateway.Utilities.SendMessage(steamId, "smiting", selectedPlayer.DisplayName);
                MessageSyncAres.Smite(selectedPlayer.SteamUserId, _defaultOreName);
                return(true);
            }

            return(false);
        }
예제 #6
0
        public override bool Invoke(ulong steamId, long playerId, string messageText)
        {
            var match = Regex.Match(messageText, @"/fj\s+(?<Faction>.+)\s+(?<Key>.+)", RegexOptions.IgnoreCase);

            if (match.Success)
            {
                var factionName = match.Groups["Faction"].Value;
                var playerName  = match.Groups["Key"].Value;
                var players     = new List <IMyPlayer>();
                MyAPIGateway.Players.GetPlayers(players, p => p != null);

                var identities = new List <IMyIdentity>();
                MyAPIGateway.Players.GetAllIdentites(identities, delegate(IMyIdentity i) { return(i.DisplayName.Equals(playerName, StringComparison.InvariantCultureIgnoreCase)); });
                IMyIdentity selectedPlayer = identities.FirstOrDefault();

                int index;
                List <IMyIdentity> cacheList = CommandPlayerStatus.GetIdentityCache(steamId);
                if (playerName.Substring(0, 1) == "#" && Int32.TryParse(playerName.Substring(1), out index) && index > 0 && index <= cacheList.Count)
                {
                    selectedPlayer = cacheList[index - 1];
                }

                List <IMyIdentity> botCacheList = CommandListBots.GetIdentityCache(steamId);
                if (playerName.Substring(0, 1).Equals("B", StringComparison.InvariantCultureIgnoreCase) && Int32.TryParse(playerName.Substring(1), out index) && index > 0 && index <= botCacheList.Count)
                {
                    selectedPlayer = botCacheList[index - 1];
                }

                if (selectedPlayer == null)
                {
                    MyAPIGateway.Utilities.SendMessage(steamId, "fj", "specified player could not be found.");
                    return(true);
                }

                if (!MyAPIGateway.Session.Factions.FactionTagExists(factionName) &&
                    !MyAPIGateway.Session.Factions.FactionNameExists(factionName))
                {
                    MyAPIGateway.Utilities.SendMessage(steamId, "faction", "{0} does not exist.", factionName);
                    return(true);
                }

                var fc = MyAPIGateway.Session.Factions.GetObjectBuilder();

                var factionBuilder = fc.Factions.FirstOrDefault(f => f.Members.Any(m => m.PlayerId == selectedPlayer.IdentityId));
                if (factionBuilder != null)
                {
                    MyAPIGateway.Utilities.SendMessage(steamId, "player", "{0} is already in faction {1}.{2}", selectedPlayer.DisplayName, factionBuilder.Tag, factionBuilder.Name);
                    return(true);
                }

                var factionCollectionBuilder = fc.Factions.FirstOrDefault(f => f.Name.Equals(factionName, StringComparison.InvariantCultureIgnoreCase) ||
                                                                          f.Tag.Equals(factionName, StringComparison.InvariantCultureIgnoreCase));

                if (factionCollectionBuilder != null)
                {
                    MessageSyncFaction.JoinFaction(factionCollectionBuilder.FactionId, selectedPlayer.IdentityId);
                    MyAPIGateway.Utilities.SendMessage(steamId, "join", $"{selectedPlayer.DisplayName} has been addded to faction.");
                }

                return(true);
            }

            return(false);
        }
예제 #7
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);
        }
예제 #8
0
        public override bool Invoke(ulong steamId, long playerId, string messageText)
        {
            List <IMyIdentity> cacheList = CommandPlayerStatus.GetIdentityCache(steamId);

            //TODO: matching playernames
            var match = Regex.Match(messageText, @"@@@@@\s+(?<Key>.+)", RegexOptions.IgnoreCase);

            if (match.Success)
            {
                string    message     = match.Groups["Key"].Value;
                IMyPlayer lastWhisper = null;
                if (MyAPIGateway.Players.TryGetPlayer(LastWhisperId, out lastWhisper))
                {
                    SendPrivateMessage(steamId, lastWhisper, message);
                    return(true);
                }
                MyAPIGateway.Utilities.SendMessage(steamId, "PM System", "Could not find player. Either no one whispered to you or he is offline now.");
                return(true);
            }

            var match1 = Regex.Match(messageText, @"@@@@(\s+(?<Key>.+)|)", RegexOptions.IgnoreCase);

            if (match1.Success)
            {
                string    message     = match1.Groups["Key"].Value;
                IMyPlayer lastWhisper = null;
                if (MyAPIGateway.Players.TryGetPlayer(LastWhisperId, out lastWhisper))
                {
                    if (!string.IsNullOrEmpty(message))
                    {
                        SendPrivateMessage(steamId, lastWhisper, message);
                    }

                    WhisperPartner = lastWhisper;
                    MyAPIGateway.Utilities.SendMessage(steamId, "PM System", string.Format("Set whisperpartner to {0}", WhisperPartner.DisplayName));
                    return(true);
                }
                MyAPIGateway.Utilities.SendMessage(steamId, "PM System", "Could not find player. Either no one whispered to you or he is offline now.");
                return(true);
            }

            var match2 = Regex.Match(messageText, @"@@@\s+((?<Player>[^\s]+)\s+(?<Message>.*)|(?<Player>.+))", RegexOptions.IgnoreCase);

            if (match2.Success)
            {
                var       playerName = match2.Groups["Player"].Value;
                var       message    = match2.Groups["Message"].Value;
                IMyPlayer receiver;
                int       index;
                if (MyAPIGateway.Players.TryGetPlayer(playerName, out receiver))
                {
                    if (!string.IsNullOrEmpty(message))
                    {
                        SendPrivateMessage(steamId, receiver, message);
                    }

                    WhisperPartner = receiver;
                    MyAPIGateway.Utilities.SendMessage(steamId, "PM System", string.Format("Set whisperpartner to {0}", WhisperPartner.DisplayName));
                }
                else if (playerName.Substring(0, 1) == "#" && Int32.TryParse(playerName.Substring(1), out index) && index > 0 && index <= cacheList.Count)
                {
                    var listplayers = new List <IMyPlayer>();
                    MyAPIGateway.Players.GetPlayers(listplayers, p => p.PlayerID == cacheList[index - 1].PlayerId);
                    receiver = listplayers.FirstOrDefault();
                    if (!string.IsNullOrEmpty(message))
                    {
                        SendPrivateMessage(steamId, receiver, message);
                    }

                    WhisperPartner = receiver;
                    MyAPIGateway.Utilities.SendMessage(steamId, "PM System", string.Format("Set whisperpartner to {0}", WhisperPartner.DisplayName));
                }
                else
                {
                    MyAPIGateway.Utilities.SendMessage(steamId, "PM System", string.Format("Player {0} does not exist.", match2.Groups["KeyPlayer"].Value));
                }

                return(true);
            }

            var match3 = Regex.Match(messageText, @"@@\s+(?<Key>.+)", RegexOptions.IgnoreCase);

            if (match3.Success)
            {
                if (WhisperPartner == null)
                {
                    MyAPIGateway.Utilities.SendMessage(steamId, "PM System", "No whisperpartner set");
                    return(true);
                }
                //make sure player is online
                if (MyAPIGateway.Players.TryGetPlayer(WhisperPartner.SteamUserId, out WhisperPartner))
                {
                    SendPrivateMessage(steamId, WhisperPartner, match3.Groups["Key"].Value);
                    return(true);
                }

                MyAPIGateway.Utilities.SendMessage(steamId, "PM System", string.Format("Player {0} is offline.", WhisperPartner.DisplayName));
                return(true);
            }

            var match4 = Regex.Match(messageText, @"(@|/msg|/tell)\s+(?<Player>[^\s]+)\s+(?<Message>.+)", RegexOptions.IgnoreCase);

            if (match4.Success)
            {
                var       playerName = match4.Groups["Player"].Value;
                IMyPlayer receiver;
                int       index;

                if (MyAPIGateway.Players.TryGetPlayer(playerName, out receiver))
                {
                    SendPrivateMessage(steamId, receiver, match4.Groups["Message"].Value);
                }
                else if (playerName.Substring(0, 1) == "#" && Int32.TryParse(playerName.Substring(1), out index) && index > 0 && index <= cacheList.Count)
                {
                    var listplayers = new List <IMyPlayer>();
                    MyAPIGateway.Players.GetPlayers(listplayers, p => p.PlayerID == cacheList[index - 1].PlayerId);
                    receiver = listplayers.FirstOrDefault();
                    SendPrivateMessage(steamId, receiver, match4.Groups["Message"].Value);
                }
                else
                {
                    MyAPIGateway.Utilities.SendMessage(steamId, "PM System", string.Format("Player {0} does not exist.", match4.Groups["KeyPlayer"].Value));
                }
                return(true);
            }

            var match5 = Regex.Match(messageText, @"@\?", RegexOptions.IgnoreCase);

            if (match5.Success)
            {
                if (WhisperPartner != null)
                {
                    MyAPIGateway.Utilities.SendMessage(steamId, "PM System", string.Format("Your current whisperpartner is {0}.", WhisperPartner.DisplayName));
                }
                else
                {
                    MyAPIGateway.Utilities.SendMessage(steamId, "PM System", "No whisperpartner set.");
                }
                return(true);
            }


            return(false);
        }
예제 #9
0
        public override bool Invoke(ulong steamId, long playerId, string messageText)
        {
            var match = Regex.Match(messageText, @"/tpp\s{1,}(?<Key>.+)", RegexOptions.IgnoreCase);

            if (match.Success)
            {
                var playerName = match.Groups["Key"].Value;
                var players    = new List <IMyPlayer>();
                MyAPIGateway.Players.GetPlayers(players, p => p != null);
                IMyIdentity selectedPlayer = null;

                var identities = new List <IMyIdentity>();
                MyAPIGateway.Players.GetAllIdentites(identities, delegate(IMyIdentity i) { return(i.DisplayName.Equals(playerName, StringComparison.InvariantCultureIgnoreCase)); });
                selectedPlayer = identities.FirstOrDefault();

                int index;
                List <IMyIdentity> cacheList = CommandPlayerStatus.GetIdentityCache(steamId);
                if (playerName.Substring(0, 1) == "#" && Int32.TryParse(playerName.Substring(1), out index) && index > 0 && index <= cacheList.Count)
                {
                    selectedPlayer = cacheList[index - 1];
                }

                if (selectedPlayer == null)
                {
                    MyAPIGateway.Utilities.SendMessage(steamId, "Player name", string.Format("'{0}' not found", playerName));
                    return(true);
                }

                var listplayers = new List <IMyPlayer>();
                MyAPIGateway.Players.GetPlayers(listplayers, p => p.PlayerID == selectedPlayer.PlayerId);
                var player = listplayers.FirstOrDefault();

                if (player == null)
                {
                    MyAPIGateway.Utilities.SendMessage(steamId, "Player", "no longer exists");
                    return(true);
                }

                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.");
                };

                IMyPlayer thisPlayer;
                if (!MyAPIGateway.Players.TryGetPlayer(steamId, out thisPlayer))
                {
                    MyAPIGateway.Utilities.SendMessage(steamId, "Teleport failed", "Source entity no longer exists.");
                    return(true);
                }

                var ret = Support.MoveTo(thisPlayer, player, true, true, saveTeleportBack, emptySourceMsg, emptyTargetMsg, noSafeLocationMsg, steamId);
                return(true);
            }

            return(false);
        }
        public override bool Invoke(ulong steamId, long playerId, string messageText)
        {
            var match = Regex.Match(messageText, @"/fd\s+(?<Key>.+)", RegexOptions.IgnoreCase);

            if (match.Success)
            {
                var playerName = match.Groups["Key"].Value;
                var players    = new List <IMyPlayer>();
                MyAPIGateway.Players.GetPlayers(players, p => p != null);
                IMyPlayer selectedPlayer = null;

                var findPlayer = players.FirstOrDefault(p => p.DisplayName.Equals(playerName, StringComparison.InvariantCultureIgnoreCase));
                if (findPlayer != null)
                {
                    selectedPlayer = findPlayer;
                }

                int index;
                List <IMyIdentity> cacheList = CommandPlayerStatus.GetIdentityCache(steamId);
                if (playerName.Substring(0, 1) == "#" && Int32.TryParse(playerName.Substring(1), out index) && index > 0 && index <= cacheList.Count)
                {
                    var listplayers = new List <IMyPlayer>();
                    MyAPIGateway.Players.GetPlayers(listplayers, p => p.PlayerID == cacheList[index - 1].PlayerId);
                    selectedPlayer = listplayers.FirstOrDefault();
                }

                if (selectedPlayer == null)
                {
                    return(false);
                }

                var fc             = MyAPIGateway.Session.Factions.GetObjectBuilder();
                var factionBuilder = fc.Factions.FirstOrDefault(f => f.Members.Any(m => m.PlayerId == selectedPlayer.PlayerID));

                if (factionBuilder == null)
                {
                    MyAPIGateway.Utilities.SendMessage(steamId, "demote", "{0} not in faction.", selectedPlayer.DisplayName);
                    return(true);
                }

                var fm = factionBuilder.Members.FirstOrDefault(m => m.PlayerId == selectedPlayer.PlayerID);

                if (fm.IsFounder)
                {
                    MyAPIGateway.Utilities.SendMessage(steamId, "demote", "{0} is Founder and cannot be demoted.", selectedPlayer.DisplayName);
                    return(true);
                }

                if (fm.IsLeader)
                {
                    MessageSyncFaction.DemotePlayer(factionBuilder.FactionId, selectedPlayer.PlayerID);
                    MyAPIGateway.Utilities.SendMessage(steamId, "demote", "{0} from Leader to Member.", selectedPlayer.DisplayName);
                    return(true);
                }

                MyAPIGateway.Utilities.SendMessage(steamId, "demote", "{0} cannot be demoted further.", selectedPlayer.DisplayName);
                return(true);
            }

            return(false);
        }
        public override bool Invoke(ulong steamId, long playerId, string messageText)
        {
            var match = Regex.Match(messageText, @"/eject\s+(?:(?:""(?<name>[^""]|.*?)"")|(?<name>.*))", RegexOptions.IgnoreCase);

            if (match.Success)
            {
                var playerName = match.Groups["name"].Value;
                var players    = new List <IMyPlayer>();
                MyAPIGateway.Players.GetPlayers(players, p => p != null);
                IMyPlayer selectedPlayer = null;

                var findPlayer = players.FirstOrDefault(p => p.DisplayName.Equals(playerName, StringComparison.InvariantCultureIgnoreCase));
                if (findPlayer != null)
                {
                    selectedPlayer = findPlayer;
                }

                int index;
                List <IMyIdentity> cacheList = CommandPlayerStatus.GetIdentityCache(steamId);
                if (playerName.Substring(0, 1) == "#" && int.TryParse(playerName.Substring(1), out index) && index > 0 && index <= cacheList.Count)
                {
                    var listplayers = new List <IMyPlayer>();
                    MyAPIGateway.Players.GetPlayers(listplayers, p => p.PlayerID == cacheList[index - 1].PlayerId);
                    selectedPlayer = listplayers.FirstOrDefault();
                }

                if (selectedPlayer == null)
                {
                    MyAPIGateway.Utilities.SendMessage(steamId, "Eject", "No player named '{0}' found.", playerName);
                    return(true);
                }

                MessageSyncAres.Eject(selectedPlayer.SteamUserId);
                return(true);

                // NPC's do not appears as Players, but Identities.
                // There could be multiple Identities with the same name, for active, inactive and dead.
                //if (playerName.Substring(0, 1) == "B" && Int32.TryParse(playerName.Substring(1), out index) && index > 0 && index <= CommandListBots.BotCache.Count)
                //{
                //    selectedPlayer = CommandListBots.BotCache[index - 1];
                //}

                // TODO: figure out how to eject Autopilot.

                //var entities = new HashSet<IMyEntity>();
                //MyAPIGateway.Entities.GetEntities(entities, e => e is IMyCubeGrid);

                //foreach (var entity in entities)
                //{
                //    var cockpits = entity.FindWorkingCockpits();

                //    foreach (var cockpit in cockpits)
                //    {
                //        var block = (IMyCubeBlock)cockpit;
                //        if (block.OwnerId == selectedPlayer.PlayerId)
                //        {
                //            MyAPIGateway.Utilities.SendMessage(steamId, "ejecting", selectedPlayer.DisplayName);
                //            // Does not appear to eject Autopilot.
                //            cockpit.Use();
                //        }
                //    }
                //}
            }

            return(false);
        }