Exemple #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);
        }
Exemple #2
0
        public static IMyPlayer Player(this IMyIdentity identity)
        {
            var listPlayers = new List <IMyPlayer>();

            MyAPIGateway.Players.GetPlayers(listPlayers, p => p.IdentityId == identity.IdentityId);
            return(listPlayers.FirstOrDefault());
        }
Exemple #3
0
        private void ProjectorBlock_AppendingCustomInfo(IMyTerminalBlock arg1, StringBuilder stringBuilder)
        {
            if (SelectedOffer == null)
            {
                stringBuilder.AppendLine("_______•°•(Hangar Market)•°•_______");
                return;
            }



            if (SelectedOffer.SteamID != 0)
            {
                long ID = MyAPIGateway.Players.TryGetIdentityId(SelectedOffer.SteamID);

                if (ID != 0)
                {
                    List <IMyIdentity> Identities = new List <IMyIdentity>();
                    MyAPIGateway.Players.GetAllIdentites(Identities);

                    IMyIdentity Seller = Identities.FirstOrDefault(x => x.IdentityId == ID);

                    SelectedOffer.Seller = Seller.DisplayName;

                    var Fac = MyAPIGateway.Session.Factions.GetObjectBuilder().Factions.FirstOrDefault(x => x.Members.Any(c => c.PlayerId == Seller.IdentityId));


                    if (Fac != null)
                    {
                        SelectedOffer.SellerFaction = Fac.Tag;
                    }
                }
                else
                {
                    SelectedOffer.Seller = "Unknown";
                }
            }



            stringBuilder.AppendLine("______•°•(Hangar Market)•°•______");
            stringBuilder.AppendLine("Grid Name: " + SelectedOffer.Name);
            stringBuilder.AppendLine("Price: " + SelectedOffer.Price + " [sc]");
            stringBuilder.AppendLine("Market Value: " + SelectedOffer.MarketValue + " [sc]");
            stringBuilder.AppendLine("Seller: " + SelectedOffer.Seller);
            stringBuilder.AppendLine("Seller Faction: " + SelectedOffer.SellerFaction);


            stringBuilder.AppendLine("Seller Description: " + SelectedOffer.Description);
            stringBuilder.AppendLine();


            stringBuilder.AppendLine("_______•°•[ Ship Properties ]•°•_______");
            stringBuilder.AppendLine("GridMass: " + SelectedOffer.GridMass + "kg");
            stringBuilder.AppendLine("Num of Small Grids: " + SelectedOffer.SmallGrids);
            stringBuilder.AppendLine("Num of Large Grids: " + SelectedOffer.LargeGrids);
            stringBuilder.AppendLine("Max Power Output: " + SelectedOffer.MaxPowerOutput);
            stringBuilder.AppendLine("Build Percentage: " + Math.Round(SelectedOffer.GridBuiltPercent * 100, 2) + "%");
            stringBuilder.AppendLine("Max Jump Distance: " + SelectedOffer.JumpDistance);
            stringBuilder.AppendLine("Ship PCU: " + SelectedOffer.PCU);
        }
        public static IMyPlayer IdentityToPlayer(IMyIdentity identity)
        {
            List <IMyPlayer> players = new List <IMyPlayer>();

            MyAPIGateway.Players.GetPlayers(players, i => i.IdentityId == identity.IdentityId);
            return(players.FirstOrDefault());
        }
        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);
        }
Exemple #6
0
 /// <summary>
 ///     Called if local player identity changed (eg. died with permadeath on).
 ///     Used to remap CharacterChanged for the local player identity.
 /// </summary>
 /// <param name="player">The player which identity was changed.</param>
 /// <param name="identity">The new identity.</param>
 private void OnIdentityChanged(IMyPlayer player, IMyIdentity identity)
 {
     _identity.CharacterChanged -= OnCharacterChanged;
     _identity = identity;
     if (identity != null)
     {
         _identity.CharacterChanged += OnCharacterChanged;
     }
 }
Exemple #7
0
        /// <summary>
        ///     Creates a new instance of <see cref="SuitComputer" />.
        /// </summary>
        /// <param name="player">The local player used to register required events.</param>
        private SuitComputer(IMyPlayer player)
        {
            Log = Mod.Static.Log.ForScope <SuitComputer>();

            _player = player;
            player.IdentityChanged += OnIdentityChanged;

            _identity = player.Identity;
            _identity.CharacterChanged += OnCharacterChanged;

            var character = player.Character;

            if (character != null)
            {
                RegisterEvents(character);
                _isFlying = character.CurrentMovementState == MyCharacterMovementEnum.Flying;
            }
        }
        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);
        }
Exemple #9
0
        private IMyPlayer GetPlayer(long playerId)
        {
            try
            {
                IMyIdentity playerIdentity = Player(playerId);
                if (playerIdentity == null)
                {
                    return(null);
                }

                var playerList = new List <IMyPlayer>();
                MyAPIGateway.Players.GetPlayers(playerList, p => p != null && p.IdentityId == playerIdentity.IdentityId);

                return(playerList.FirstOrDefault());
            }
            catch (Exception e)
            {
                return(null);
            }
        }
    private void PlayerSpawned(long playerId)
    {
        //logger.WriteLine("Request of Player "+ playerId);

        IMyIdentity playerIdentity = Player(playerId);

        //logger.WriteLine("Found Identity " + playerId);

        if (playerIdentity != null)
        {
            //logger.WriteLine("Player is " + playerIdentity.DisplayName);

            var playerList = new List <IMyPlayer>();
            MyAPIGateway.Players.GetPlayers(playerList, p => p != null && p.IdentityId == playerIdentity.IdentityId);

            var player = playerList.FirstOrDefault();
            if (player != null)
            {
                if (!MustBeExecuted(player))
                {
                    logger.WriteLine("Player " + playerIdentity.DisplayName + " did not spawn near special Medbay!");
                    return;
                }

                MyVisualScriptLogicProvider.SetPlayersHydrogenLevel(playerIdentity.IdentityId, 0);

                IMyCharacter character = player.Character;

                if (character == null)
                {
                    logger.WriteLine("Player " + playerIdentity.DisplayName + " has no Character yet!");
                }

                spawnToolsRemover.Remove(character);
            }
            else
            {
                logger.WriteLine("Player " + playerIdentity.DisplayName + " not Found!");
            }
        }
    }
Exemple #11
0
 public void Refresh()
 {
     blocks.Clear();
     PlayersOnToilet.Clear();
     Composts    = 0;
     OxygenFarms = 0;
     CropGrowers = 0;
     Grid.GetBlocks(blocks, b => b.FatBlock != null);
     LastScan = DateTime.Now;
     foreach (IMySlimBlock block in blocks)
     {
         if (block.FatBlock is Sandbox.ModAPI.IMyCargoContainer && block.FatBlock.BlockDefinition.SubtypeId.Equals("Compost"))
         {
             Composts++;
         }
         else if (block.FatBlock is IMyOxygenFarm && (block.FatBlock as IMyOxygenFarm).GetOutput() > 0)
         {
             OxygenFarms++;
         }
         else if (block.FatBlock is Sandbox.ModAPI.IMyAssembler && block.FatBlock.BlockDefinition.SubtypeId.Contains("Crop") && (block.FatBlock as Sandbox.ModAPI.IMyAssembler).IsWorking)
         {
             CropGrowers++;
         }
         else if (block.FatBlock is Sandbox.ModAPI.IMyCockpit &&
                  block.FatBlock.DefinitionDisplayNameText.ToLower().Contains("toilet"))
         {
             Sandbox.ModAPI.IMyCockpit cockpit = block.FatBlock as Sandbox.ModAPI.IMyCockpit;
             if (!cockpit.IsUnderControl)
             {
                 continue;
             }
             long        controller = cockpit.ControllerInfo.ControllingIdentityId;
             IMyIdentity identity   = Utilities.CubeBlockBuiltByToIdentity(controller);
             if (identity != null)
             {
                 PlayersOnToilet.Add(identity);
             }
         }
     }
 }
Exemple #12
0
    private void PlayerSpawned(long playerId)
    {
        //logger.WriteLine("Request of Player "+ playerId);

        IMyIdentity playerIdentity = Player(playerId);

        //logger.WriteLine("Found Identity " + playerId);

        if (playerIdentity != null)
        {
            //logger.WriteLine("Player is " + playerIdentity.DisplayName);

            var playerList = new List <IMyPlayer>();
            MyAPIGateway.Players.GetPlayers(playerList, p => p != null && p.IdentityId == playerIdentity.IdentityId);

            var player = playerList.FirstOrDefault();
            if (player != null)
            {
                MyVisualScriptLogicProvider.SetPlayersHydrogenLevel(playerIdentity.IdentityId, 0);
            }
        }
    }
Exemple #13
0
        public IdentityController(
            ILogger <IdentityController> logger,
            IMyIdentity myIdentity,
            IHttpContextAccessor httpContextAccessor,
            IEmail emailService,
            IQueue queue
            )
        {
            _logger              = logger;
            _myIdentity          = myIdentity;
            _httpContextAccessor = httpContextAccessor;
            _email = emailService;
            _queue = queue;

            if (_httpContextAccessor.HttpContext.User.Identity.IsAuthenticated)
            {
                string id = (from c in _httpContextAccessor.HttpContext.User.Claims
                             where c.Type == "UserID"
                             select c.Value).FirstOrDefault()
                ;

                string name = (from c in _httpContextAccessor.HttpContext.User.Claims
                               where c.Type == ClaimTypes.Name
                               select c.Value).FirstOrDefault()
                ;

                string email = (from c in _httpContextAccessor.HttpContext.User.Claims
                                where c.Type == ClaimTypes.Email
                                select c.Value).FirstOrDefault()
                ;

                _user = new User(id, name, email);
            }
            else
            {
                _user = new User();
            }
        }
Exemple #14
0
        public static IMyIdentity GetIdentity_Safe(this IMyCharacter character)
        {
            string      DisplayName = (character as IMyEntity).DisplayName;
            IMyIdentity living      = null;
            IMyIdentity dead        = null;

            UsingShared(() => {
                MyAPIGateway.Players.GetAllIdentites(null, id => {
                    if (living == null && id.DisplayName == DisplayName)
                    {
                        if (id.IsDead)
                        {
                            dead = id;
                        }
                        else
                        {
                            living = id;
                        }
                    }
                    return(false);
                });
            });
            return(living ?? dead);
        }
        public static string TagPlayerName(IMyIdentity identity)
        {
            IMyFaction faction = MyAPIGateway.Session.Factions.TryGetPlayerFaction(identity.IdentityId);

            return((faction != null) ? (faction.Tag + "." + identity.DisplayName) : identity.DisplayName);
        }
        private void CommonProcess(ulong steamId, SyncGridChangeType syncType, long entityId, string searchEntity, long playerId, bool switchOn)
        {
            List <IMyCubeGrid> selectedShips = new List <IMyCubeGrid>();
            bool allSelectedShips            = false;

            if (entityId != 0)
            {
                var selectedShip = MyAPIGateway.Entities.GetEntityById(entityId) as IMyCubeGrid;
                if (selectedShip != null)
                {
                    selectedShips.Add(selectedShip);
                }
            }
            else if (searchEntity == "**")  // All ships in the players hot list.
            {
                List <IMyEntity> shipCache = CommandListShips.GetShipCache(steamId);
                foreach (IMyEntity ship in shipCache)
                {
                    selectedShips.Add((IMyCubeGrid)ship);
                }
                allSelectedShips = true;
            }
            else if (!string.IsNullOrEmpty(searchEntity))
            {
                // exact name search.
                var currentShipList = new HashSet <IMyEntity>();
                MyAPIGateway.Entities.GetEntities(currentShipList, e => e is IMyCubeGrid && e.DisplayName.Equals(searchEntity, StringComparison.InvariantCultureIgnoreCase));
                selectedShips.AddRange(currentShipList.Cast <IMyCubeGrid>());

                if (currentShipList.Count == 0)
                {
                    // hotlist search.
                    int index;
                    List <IMyEntity> shipCache = CommandListShips.GetShipCache(steamId);
                    if (searchEntity.Substring(0, 1) == "#" && int.TryParse(searchEntity.Substring(1), out index) && index > 0 && index <= shipCache.Count)
                    {
                        selectedShips.Add((IMyCubeGrid)shipCache[index - 1]);
                    }
                }
            }

            if (selectedShips.Count == 0)
            {
                MyAPIGateway.Utilities.SendMessage(steamId, "Server", "No ships selected or found.");
                return;
            }

            switch (syncType)
            {
            case SyncGridChangeType.OwnerClaim:
            {
                var players = new List <IMyPlayer>();
                MyAPIGateway.Players.GetPlayers(players, p => p != null && p.IdentityId == playerId);
                IMyPlayer player = players.FirstOrDefault();

                if (player == null)
                {
                    return;
                }

                foreach (var selectedShip in selectedShips)
                {
                    var grids = selectedShip.GetAttachedGrids(AttachedGrids.Static);
                    foreach (var grid in grids)
                    {
                        grid.ChangeGridOwnership(player.IdentityId, MyOwnershipShareModeEnum.All);
                    }

                    MyAPIGateway.Utilities.SendMessage(steamId, "Server", string.Format("Grid {0} Claimed by player {1}.", selectedShip.DisplayName, player.DisplayName));
                }
            }
            break;

            case SyncGridChangeType.OwnerRevoke:
            {
                foreach (var selectedShip in selectedShips)
                {
                    var grids = selectedShip.GetAttachedGrids(AttachedGrids.Static);
                    foreach (var grid in grids)
                    {
                        grid.ChangeGridOwnership(0, MyOwnershipShareModeEnum.All);
                    }
                    MyAPIGateway.Utilities.SendMessage(steamId, "Server", string.Format("Grid {0} Revoked of all ownership.", selectedShip.DisplayName));
                }
            }
            break;

            case SyncGridChangeType.OwnerShareAll:
            {
                foreach (var selectedShip in selectedShips)
                {
                    var grids = selectedShip.GetAttachedGrids(AttachedGrids.Static);
                    foreach (var grid in grids)
                    {
                        var blocks = new List <IMySlimBlock>();
                        grid.GetBlocks(blocks, f => f.FatBlock != null && f.FatBlock.OwnerId != 0);

                        foreach (var block in blocks)
                        {
                            block.FatBlock.ChangeOwner(block.FatBlock.OwnerId, MyOwnershipShareModeEnum.All);
                        }
                    }
                    MyAPIGateway.Utilities.SendMessage(steamId, "Server", string.Format("Grid {0} Shared.", selectedShip.DisplayName));
                }
            }
            break;

            case SyncGridChangeType.OwnerShareNone:
            {
                foreach (var selectedShip in selectedShips)
                {
                    var grids = selectedShip.GetAttachedGrids(AttachedGrids.Static);
                    foreach (var grid in grids)
                    {
                        var blocks = new List <IMySlimBlock>();
                        grid.GetBlocks(blocks, f => f.FatBlock != null && f.FatBlock.OwnerId != 0);

                        foreach (var block in blocks)
                        {
                            block.FatBlock.ChangeOwner(block.FatBlock.OwnerId, MyOwnershipShareModeEnum.None);
                        }
                    }
                    MyAPIGateway.Utilities.SendMessage(steamId, "Server", string.Format("Grid {0} Shared.", selectedShip.DisplayName));
                }
            }
            break;

            case SyncGridChangeType.SwitchOnPower:
            {
                int reactors;
                int batteries;
                TurnOnShips(steamId, selectedShips, out reactors, out batteries);
            }
            break;

            case SyncGridChangeType.SwitchOffPower:
            {
                int reactors;
                int batteries;
                TurnOffShips(steamId, selectedShips, out reactors, out batteries);
            }
            break;

            case SyncGridChangeType.DeleteShip:
            {
                if (allSelectedShips)
                {
                    foreach (var selectedShip in selectedShips)
                    {
                        DeleteShip(steamId, selectedShip);
                    }
                }
                else if (selectedShips.Count == 1)
                {
                    DeleteShip(steamId, selectedShips.First());
                }
                else if (selectedShips.Count > 1)
                {
                    MyAPIGateway.Utilities.SendMessage(steamId, "deleteship", "{0} Ships match that name.", selectedShips.Count);
                }
            }
            break;

            case SyncGridChangeType.Destructible:
            {
                if (selectedShips.Count == 1)
                {
                    SetDestructible(selectedShips.First(), switchOn, steamId);
                }
            }
            break;

            case SyncGridChangeType.Stop:
            {
                foreach (var selectedShip in selectedShips)
                {
                    MessageSyncEntity.Process(selectedShip, SyncEntityType.Stop);
                    MyAPIGateway.Utilities.SendMessage(steamId, selectedShip.DisplayName, "Is stopping.");
                }
            }
            break;

            case SyncGridChangeType.ScaleDown:
            {
                ScaleShip(steamId, selectedShips.First(), MyCubeSize.Small);
            }
            break;

            case SyncGridChangeType.ScaleUp:
            {
                ScaleShip(steamId, selectedShips.First(), MyCubeSize.Large);
            }
            break;

            case SyncGridChangeType.BuiltBy:
            {
                string playerName = SearchEntity;

                var players = new List <IMyPlayer>();
                MyAPIGateway.Players.GetPlayers(players, p => p != null);
                IMyIdentity selectedPlayer = null;

                var identities = new List <IMyIdentity>();
                MyAPIGateway.Players.GetAllIdentites(identities, i => i.DisplayName.Equals(playerName, StringComparison.InvariantCultureIgnoreCase));
                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];
                }

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

                if (selectedPlayer == null)
                {
                    MyAPIGateway.Utilities.SendMessage(steamId, "Server", string.Format("Player or Bot '{0}' could not be found.", playerName));
                    return;
                }

                // Using the identity list is a crap way, but since we don't have access to BuiltBy for non-functional blocks, this has to do.
                var listIdentites = new List <IMyIdentity>();
                MyAPIGateway.Players.GetAllIdentites(listIdentites);
                foreach (var selectedShip in selectedShips)
                {
                    var grids = selectedShip.GetAttachedGrids(AttachedGrids.Static);
                    foreach (var grid in grids)
                    {
                        foreach (IMyIdentity identity in listIdentites)
                        {
                            if (identity.IdentityId != selectedPlayer.IdentityId)
                            {
                                // The current API doesn't allow the setting of the BuiltBy to anything but an existing Identity (player or NPC).
                                ((MyCubeGrid)grid).TransferBlocksBuiltByID(identity.IdentityId, selectedPlayer.IdentityId);
                            }
                        }
                    }
                    MyAPIGateway.Utilities.SendMessage(steamId, "Server", string.Format("Grid '{0}' Changed of all built to '{1}'.", selectedShip.DisplayName, selectedPlayer.DisplayName));
                }
            }
            break;

            case SyncGridChangeType.Repair:
            {
                var players = new List <IMyPlayer>();
                MyAPIGateway.Players.GetPlayers(players, p => p != null && p.IdentityId == playerId);
                IMyPlayer player = players.FirstOrDefault();

                if (player == null)
                {
                    return;
                }

                foreach (var selectedShip in selectedShips)
                {
                    var grids = selectedShip.GetAttachedGrids(AttachedGrids.Static);
                    foreach (var grid in grids)
                    {
                        RepairShip(steamId, grid);
                    }

                    MyAPIGateway.Utilities.SendMessage(steamId, "Server", string.Format("Grid {0} Repaired.", selectedShip.DisplayName));
                }
            }
            break;
            }
        }
Exemple #17
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);
        }
Exemple #18
0
 public CR_Character(IMyCharacter character)
 {
     this.m_character = character;
     this.m_identity  = character.GetIdentity_Safe();
 }
Exemple #19
0
 internal static FatProfilerEntry PlayerEntry(IMyIdentity id)
 {
     return(FixedProfiler(ProfilerFixedEntry.Players)?.GetFat(id));
 }
Exemple #20
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 static bool TryGetIdentity(this IMyPlayerCollection collection, long identityId, out IMyIdentity identity)
        {
            var listIdentites = new List <IMyIdentity>();

            MyAPIGateway.Players.GetAllIdentites(listIdentites, p => p.IdentityId == identityId);
            identity = listIdentites.FirstOrDefault();
            return(identity != null);
        }
 private void MovePlayerPilotToPlayer(IMyPlayer sourcePlayer, IMyIdentity targetedPlayerIdentity, bool agressivePosition)
 {
     var listplayers = new List<IMyPlayer>();
     MyAPIGateway.Players.GetPlayers(listplayers, p => p.PlayerID == targetedPlayerIdentity.PlayerId);
     MovePlayerPilotToPlayer(sourcePlayer, listplayers.FirstOrDefault(), agressivePosition);
 }
Exemple #23
0
 public CR_Character(IMyCharacter character)
 {
     this.m_character = character;
     this.m_identity = character.GetIdentity_Safe();
 }
        private static bool DoesGridHaveTarget(IMyCubeGrid grid, IMySlimBlock block, bool disabling = false)
        {
            if (m_scanCache.Count < 1)
            {
                BoundingSphereD sphere = new BoundingSphereD(grid.GetPosition(), PluginSettings.Instance.DynamicTurretTargetDistance);
                m_scanCache = MyAPIGateway.Entities.GetEntitiesInSphere(ref sphere);
            }

            /*
             * HashSet<IMyEntity> testEntities = new HashSet<IMyEntity>();
             * try
             * {
             *      MyAPIGateway.Entities.GetEntities(testEntities);
             * }
             * catch
             * {
             *      return false;
             * }
             */
            //bool found = false;
            foreach (IMyEntity testEntity in m_scanCache)
            {
                if ((IMyEntity)grid == testEntity)
                {
                    continue;
                }

                if (!testEntity.InScene)
                {
                    continue;
                }

                if (testEntity is IMyCubeBlock)
                {
                    continue;

                    /*
                     * IMyCubeBlock cubeBlock = (IMyCubeBlock)testEntity;
                     * if (cubeBlock.OwnerId == 0)
                     *      continue;
                     *
                     * if (PluginSettings.Instance.DynamicTurretManagementType == DynamicTurretManagementTypes.AllButOwner)
                     * {
                     *      if (block.FatBlock.GetUserRelationToOwner(cubeBlock.OwnerId) != Sandbox.Common.MyRelationsBetweenPlayerAndBlock.Owner)
                     *      {
                     *              Console.WriteLine("Block: Not owner");
                     *              return true;
                     *      }
                     * }
                     *
                     * if (PluginSettings.Instance.DynamicTurretManagementType == DynamicTurretManagementTypes.NeutralAndEnemy)
                     * {
                     *      if (block.FatBlock.GetUserRelationToOwner(cubeBlock.OwnerId) == Sandbox.Common.MyRelationsBetweenPlayerAndBlock.Enemies ||
                     *              block.FatBlock.GetUserRelationToOwner(cubeBlock.OwnerId) == Sandbox.Common.MyRelationsBetweenPlayerAndBlock.Neutral)
                     *      {
                     *              Console.WriteLine("Block: Enemy or Neutral: {0} {1} {2}", cubeBlock.OwnerId, cubeBlock.Parent.DisplayName, cubeBlock.BlockDefinition);
                     *              return true;
                     *      }
                     * }
                     *
                     * if (PluginSettings.Instance.DynamicTurretManagementType == DynamicTurretManagementTypes.Enemy)
                     * {
                     *      if (block.FatBlock.GetUserRelationToOwner(cubeBlock.OwnerId) == Sandbox.Common.MyRelationsBetweenPlayerAndBlock.Enemies)
                     *      {
                     * //							Console.WriteLine("Block: Enemy: {0} {1} {2}", cubeBlock.OwnerId, cubeBlock.Parent.DisplayName, cubeBlock.BlockDefinition);
                     *              return true;
                     *      }
                     * }
                     */
                }

                if (testEntity is IMyCubeGrid)
                {
                    if (PluginSettings.Instance.DynamicTurretManagementType == DynamicTurretManagementTypes.All)
                    {
                        return(true);
                    }

                    IMyCubeGrid testGrid = (IMyCubeGrid)testEntity;
                    // Always enable if grid has no owner.  Seems suspect.  Might be a user trying to abuse a no ownership ship.

                    /*
                     * if (testGrid.BigOwners.Count < 1 && testGrid.SmallOwners.Count < 1)
                     * {
                     *      //if(!(testEntity is IMyControllableEntity))
                     *      //Console.WriteLine("Grid: No owner");
                     *      return true;
                     * }
                     */

                    foreach (long owner in testGrid.BigOwners)
                    {
                        if (PluginSettings.Instance.DynamicTurretManagementType == DynamicTurretManagementTypes.AllButOwner)
                        {
                            if (block.FatBlock.GetUserRelationToOwner(owner) != MyRelationsBetweenPlayerAndBlock.Owner)
                            {
                                //Console.WriteLine("Grid: Not owner");
                                return(true);
                            }
                        }

                        if (PluginSettings.Instance.DynamicTurretManagementType == DynamicTurretManagementTypes.NeutralAndEnemy)
                        {
                            if (block.FatBlock.GetUserRelationToOwner(owner) == MyRelationsBetweenPlayerAndBlock.Enemies ||
                                block.FatBlock.GetUserRelationToOwner(owner) == MyRelationsBetweenPlayerAndBlock.Neutral)
                            {
                                //Console.WriteLine("Grid: Enemy or Neutral: {0} {1}", owner, grid.DisplayName);
                                return(true);
                            }
                        }

                        if (PluginSettings.Instance.DynamicTurretManagementType == DynamicTurretManagementTypes.Enemy)
                        {
                            if (block.FatBlock.GetUserRelationToOwner(owner) == MyRelationsBetweenPlayerAndBlock.Enemies)
                            {
                                //Console.WriteLine("{3} Target: Grid - Enemy: {0} - {1} ({2})", block.FatBlock.OwnerId, owner, testEntity.DisplayName, ((IMyTerminalBlock)block.FatBlock).Parent.DisplayName);

                                //Console.WriteLine("Grid: Enemy: {0} {1}", owner, grid.DisplayName);
                                return(true);
                            }
                        }
                    }

                    foreach (long owner in testGrid.SmallOwners)
                    {
                        if (PluginSettings.Instance.DynamicTurretManagementType == DynamicTurretManagementTypes.AllButOwner)
                        {
                            if (block.FatBlock.GetUserRelationToOwner(owner) != MyRelationsBetweenPlayerAndBlock.Owner)
                            {
                                //Console.WriteLine("Grid: Not owner");
                                return(true);
                            }
                        }

                        if (PluginSettings.Instance.DynamicTurretManagementType == DynamicTurretManagementTypes.NeutralAndEnemy)
                        {
                            if (block.FatBlock.GetUserRelationToOwner(owner) == MyRelationsBetweenPlayerAndBlock.Enemies ||
                                block.FatBlock.GetUserRelationToOwner(owner) == MyRelationsBetweenPlayerAndBlock.Neutral)
                            {
                                //Console.WriteLine("Grid: Enemy or Neutral: {0} {1}", owner, grid.DisplayName);
                                return(true);
                            }
                        }

                        if (PluginSettings.Instance.DynamicTurretManagementType == DynamicTurretManagementTypes.Enemy)
                        {
                            if (block.FatBlock.GetUserRelationToOwner(owner) == MyRelationsBetweenPlayerAndBlock.Enemies)
                            {
                                //Console.WriteLine("Grid: Enemy: {0} {1}", owner, grid.DisplayName);
                                return(true);
                            }
                        }
                    }
                }
                else
                {
                    if (PluginSettings.Instance.DynamicTurretManagementType == DynamicTurretManagementTypes.All)
                    {
                        return(true);
                    }

                    if (testEntity is IMyCharacter)
//					var builderBase = testEntity.GetObjectBuilder();
//					if (builderBase is MyObjectBuilder_Character)
                    {
                        IMyPlayer   player   = null;
                        IMyIdentity identity = null;
                        long        playerId = 0;
                        try
                        {
                            identity = m_identityCache.FirstOrDefault(x => x.DisplayName == testEntity.DisplayName);
                            //List<IMyPlayer> players = new List<IMyPlayer>();
                            //MyAPIGateway.Players.GetPlayers(players);
                            //player = players.FirstOrDefault(x => x.DisplayName == testEntity.DisplayName);

                            if (player == null)
                            {
                                /*
                                 * //player = players.FirstOrDefault(x => x.Controller != null && x.Controller.ControlledEntity != null && x.Controller.ControlledEntity.Entity != null && x.Controller.ControlledEntity.Entity.EntityId == testEntity.EntityId);
                                 * if(testEntity is IMyControllableEntity)
                                 * {
                                 *      IMyControllableEntity control = (IMyControllableEntity)testEntity;
                                 *      List<PlayerMap.InternalPlayerItem> items = PlayerMap.Instance.GetPlayerItemsFromPlayerName(control.Entity.DisplayName);
                                 *      if (items != null)
                                 *              playerId = items.First().playerId;
                                 * }
                                 */
                            }
                        }
                        catch
                        {
                            //Console.WriteLine("{3} Target: Character - Unknown: {0} - {1} ({2})", block.FatBlock.OwnerId, testEntity.EntityId, testEntity.DisplayName, ((IMyTerminalBlock)block.FatBlock).Parent.DisplayName);
                            //Console.WriteLine("Unknown1: {0}", testEntity.DisplayName);
                            return(true);
                        }

                        if (identity == null)
                        {
                            //Console.WriteLine("{3} Target: Character - Unknown2: {0} - {1} ({2})", block.FatBlock.OwnerId, testEntity.EntityId, testEntity.DisplayName, ((IMyTerminalBlock)block.FatBlock).Parent.DisplayName);
                            //Console.WriteLine("Unknown2: {0} - {1}", testEntity.DisplayName, testEntity.GetFriendlyName());
                            return(true);
                            //continue;
                        }

                        if (identity != null)
                        {
                            playerId = identity.PlayerId;
                        }

                        if (player != null)
                        {
                            playerId = player.PlayerID;
                        }

                        if (PluginSettings.Instance.DynamicTurretManagementType == DynamicTurretManagementTypes.AllButOwner && block.FatBlock.GetUserRelationToOwner(playerId) != MyRelationsBetweenPlayerAndBlock.Owner)
                        {
                            //Console.WriteLine("Character: Not Owner: {0} - {1}", block.FatBlock.OwnerId, playerId);
                            return(true);
                        }

                        if (PluginSettings.Instance.DynamicTurretManagementType == DynamicTurretManagementTypes.NeutralAndEnemy)
                        {
                            if (block.FatBlock.GetUserRelationToOwner(playerId) == MyRelationsBetweenPlayerAndBlock.Enemies ||
                                block.FatBlock.GetUserRelationToOwner(playerId) == MyRelationsBetweenPlayerAndBlock.Neutral)
                            {
                                //Console.WriteLine("Character: Enemy or Neutral: {0} - {1}", block.FatBlock.OwnerId, playerId);
                                return(true);
                            }
                        }

                        if (PluginSettings.Instance.DynamicTurretManagementType == DynamicTurretManagementTypes.Enemy)
                        {
                            if (block.FatBlock.GetUserRelationToOwner(playerId) == MyRelationsBetweenPlayerAndBlock.Enemies)
                            {
                                //Console.WriteLine("{3} Target: Character - Enemy: {0} - {1} ({2})", block.FatBlock.OwnerId, playerId, testEntity.DisplayName, ((IMyTerminalBlock)block.FatBlock).Parent.DisplayName);
                                return(true);
                            }
                        }
                    }
                }
            }

            return(false);
        }
Exemple #25
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);
        }
Exemple #26
0
 private void Player_IdentityChanged(IMyPlayer arg1, IMyIdentity arg2)
 {
     $"{arg1.SteamUserId} => {arg2?.IdentityId ?? 0}".Log(true);
     //TODO: watch identities
 }