public bool GetGrids(Chat Response, MyCharacter character, string GridNameOREntityID = null) { if (!GridUtilities.FindGridList(GridNameOREntityID, character, out Grids)) { Response.Respond("No grids found. Check your viewing angle or make sure you spelled right!"); return(false); } if (!GridUtilities.BiggestGrid(Grids, out BiggestGrid)) { Response.Respond("Grid incompatible!"); return(false); } if (!IsAdmin && !BiggestGrid.BigOwners.Contains(character.GetPlayerIdentityId())) { Response.Respond("You are not the owner of the biggest grid!"); return(false); } if (BiggestGrid.BigOwners.Count == 0) { BiggestOwner = 0; } else { BiggestOwner = BiggestGrid.BigOwners[0]; } if (!GetOwner(BiggestOwner, out OwnerSteamID)) { Response.Respond("Unable to get owners SteamID"); return(false); } GridName = BiggestGrid.DisplayName; return(true); }
private static void AutoHangarWorker() { //Significant performance increase Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); List <MyCubeGrid> ExportedGrids = new List <MyCubeGrid>(); List <long> ExportPlayerIdentities = new List <long>(); Log.Warn("AutoHangar: Getting Players!"); foreach (MyIdentity player in MySession.Static.Players.GetAllIdentities()) { if (player == null) { continue; } DateTime LastLogin; LastLogin = player.LastLoginTime; ulong SteamID = MySession.Static.Players.TryGetSteamId(player.IdentityId); if (SteamID == 0) { continue; } if (LastLogin.AddDays(Config.AutoHangarDayAmount) < DateTime.Now) { //AutoHangarBlacklist if (!Config.AutoHangarPlayerBlacklist.Any(x => x.SteamID == SteamID)) { ExportPlayerIdentities.Add(player.IdentityId); } } } Log.Warn("AutoHangar: Total players to check:" + ExportPlayerIdentities.Count()); int GridCounter = 0; //This gets all the grids foreach (long player in ExportPlayerIdentities) { ulong id = MySession.Static.Players.TryGetSteamId(player); //string path = GridMethods.CreatePathForPlayer(Config.FolderDirectory, id); ConcurrentBag <List <MyCubeGrid> > gridGroups = GridUtilities.FindGridList(player, false); //Log.Warn(player + ":" + gridGroups.Count); if (gridGroups.Count == 0) { continue; } long LargestGridID = 0; if (Config.KeepPlayersLargestGrid) { //First need to find their largets grid int BlocksCount = 0; foreach (List <MyCubeGrid> grids in gridGroups) { int GridBlockCounts = 0; int LargestSingleGridCount = 0; MyCubeGrid LargetsGrid = grids[0]; foreach (MyCubeGrid grid in grids) { if (grid.BlocksCount > LargestSingleGridCount) { LargestSingleGridCount = grid.BlocksCount; LargetsGrid = grid; } } GridBlockCounts = LargetsGrid.BlocksCount; if (GridBlockCounts > BlocksCount) { BlocksCount = GridBlockCounts; LargestGridID = LargetsGrid.EntityId; } } } if (gridGroups.Count == 0) { continue; } PlayerHangar PlayersHangar = new PlayerHangar(id, null); foreach (List <MyCubeGrid> grids in gridGroups) { if (grids.Count == 0) { continue; } if (grids[0].IsRespawnGrid && Config.DeleteRespawnPods) { grids[0].Close(); continue; } GridResult Result = new GridResult(); Result.Grids = grids; var BiggestGrid = grids[0]; foreach (MyCubeGrid grid in grids) { if (grid.BlocksCount > BiggestGrid.BlocksCount) { BiggestGrid = grid; } } Result.BiggestGrid = BiggestGrid; if (Config.KeepPlayersLargestGrid) { if (BiggestGrid.EntityId == LargestGridID) { //Skip players largest grid continue; } } //Grid Size Checks if (BiggestGrid.GridSizeEnum == MyCubeSize.Large) { if (BiggestGrid.IsStatic && !Config.AutoHangarStaticGrids) { continue; } else if (!BiggestGrid.IsStatic && !Config.AutoHangarLargeGrids) { continue; } } else if (BiggestGrid.GridSizeEnum == MyCubeSize.Small && !Config.AutoHangarSmallGrids) { continue; } GridStamp Stamp = Result.GenerateGridStamp(); GridUtilities.FormatGridName(PlayersHangar, Stamp); if (PlayersHangar.SaveGridsToFile(Result, Stamp.GridName)) { //Load player file and update! //Fill out grid info and store in file PlayersHangar.SaveGridStamp(Stamp, false, true); GridCounter++; Log.Info(Result.BiggestGrid.DisplayName + " was sent to Hangar due to inactivity!"); } else { Log.Info(Result.BiggestGrid.DisplayName + " FAILED to Hangar due to inactivity!"); } } //Save players file! PlayersHangar.SavePlayerFile(); } stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; Log.Warn("Finished Hangaring: " + GridCounter + " grids! Action took: " + ts.ToString()); }
public bool GetGrids(Chat Response, MyCharacter character, string GridNameOrEntity = null) { if (!GridUtilities.FindGridList(GridNameOrEntity, character, out Grids)) { Response.Respond("No grids found. Check your viewing angle or make sure you spelled right!"); return(false); } Grids.BiggestGrid(out BiggestGrid); if (BiggestGrid == null) { Response.Respond("Grid incompatible!"); return(false); } if (!IsAdmin) { var FatBlocks = BiggestGrid.GetFatBlocks().ToList(); long OwnerID = character.GetPlayerIdentityId(); int TotalFatBlocks = 0; int OwnedFatBlocks = 0; foreach (var fat in FatBlocks) { //Only count blocks with ownership if (!fat.IsFunctional || fat.IDModule == null) { continue; } //WTF happened here? //if (fat.OwnerId == 0) // Log.Error($"WTF: {fat.BlockDefinition.Id} - {fat.GetType()} - {fat.OwnerId}"); TotalFatBlocks++; if (fat.OwnerId == OwnerID) { OwnedFatBlocks++; } } double Percent = Math.Round((double)OwnedFatBlocks / TotalFatBlocks * 100, 3); int TotalBlocksLeftNeeded = (TotalFatBlocks / 2) + 1 - (OwnedFatBlocks); if (Percent <= 50) { Response.Respond($"You own {Percent}% of the biggest grid! Need {TotalBlocksLeftNeeded} more blocks to be the majority owner!"); return(false); } } else { //Compute biggest owner } if (BiggestGrid.BigOwners.Count == 0) { BiggestOwner = 0; } else { BiggestOwner = BiggestGrid.BigOwners[0]; } if (!GetOwner(BiggestOwner, out OwnerSteamID)) { Response.Respond("Unable to get owners SteamID! Are you an NPC?"); return(false); } GridName = BiggestGrid.DisplayName; return(true); }