public static StringBuilder GetLimit(long playerId) { var sb = new StringBuilder(); if (playerId == 0) { sb.AppendLine("Player not found"); return(sb); } var limitItems = BlockLimiterConfig.Instance.AllLimits; if (limitItems.Count < 1) { sb.AppendLine("No limit found"); return(sb); } var playerFaction = MySession.Static.Factions.GetPlayerFaction(playerId); foreach (var item in limitItems) { if (item.BlockList.Count == 0 || item.FoundEntities.Count == 0) { continue; } var itemName = string.IsNullOrEmpty(item.Name) ? item.BlockList.FirstOrDefault() : item.Name; sb.AppendLine(); sb.AppendLine($"----->{itemName}<-----"); if (item.LimitPlayers && item.FoundEntities.TryGetValue(playerId, out var pCount)) { if (pCount < 1) { continue; } sb.AppendLine($"Player Limit = {pCount}/{item.Limit}"); } if (item.LimitFaction && playerFaction != null && item.FoundEntities.TryGetValue(playerFaction.FactionId, out var fCount)) { if (fCount < 1) { continue; } sb.AppendLine($"Faction Limit = {fCount}/{item.Limit} "); } if (!item.LimitGrids || (!item.FoundEntities.Any(x => GridCache.TryGetGridById(x.Key, out var grid) && Grid.IsOwner(grid, playerId)))) { continue; } sb.AppendLine("Grid Limits:"); foreach (var(id, gCount) in item.FoundEntities) { if (!GridCache.TryGetGridById(id, out var grid) || !Grid.IsOwner(grid, playerId)) { continue; } if (gCount < 1) { continue; } sb.AppendLine($"->{grid.DisplayName} = {gCount} / {item.Limit}"); } } return(sb); }
public static StringBuilder GetLimit(long playerId) { var sb = new StringBuilder(); sb.AppendLine("Ain't find shit"); if (playerId == 0) { return(sb); } var limitItems = BlockLimiterConfig.Instance.AllLimits; if (limitItems.Count < 1) { return(sb); } sb.Clear(); var playerFaction = MySession.Static.Factions.GetPlayerFaction(playerId); var playerBlocks = new HashSet <MySlimBlock>(); if (playerId > 0) { GridCache.GetPlayerBlocks(playerBlocks, playerId); var grids = new HashSet <MyCubeGrid>(); GridCache.GetPlayerGrids(grids, playerId); if (grids.Count > 0) { if (BlockLimiterConfig.Instance.MaxBlockSizeShips > 0) { sb.AppendLine($"Ship Limits"); foreach (var grid in grids.Where(x => x.BlocksCount > 0 && !x.IsStatic)) { sb.AppendLine( $"{grid.DisplayName}: {grid.BlocksCount}/{BlockLimiterConfig.Instance.MaxBlockSizeShips}"); } } if (BlockLimiterConfig.Instance.MaxBlockSizeStations > 0) { sb.AppendLine($"Station Limits"); foreach (var grid in grids.Where(x => x.BlocksCount > 0 && x.IsStatic)) { sb.AppendLine( $"{grid.DisplayName}: {grid.BlocksCount}/{BlockLimiterConfig.Instance.MaxBlockSizeStations}"); } } if (BlockLimiterConfig.Instance.MaxBlocksLargeGrid > 0) { sb.AppendLine($"Large Grid Block Limits"); foreach (var grid in grids.Where(x => x.BlocksCount > 0 && x.GridSizeEnum == MyCubeSize.Large)) { sb.AppendLine( $"{grid.DisplayName}: {grid.BlocksCount}/{BlockLimiterConfig.Instance.MaxBlocksLargeGrid}"); } } if (BlockLimiterConfig.Instance.MaxBlocksSmallGrid > 0) { sb.AppendLine($"Small Grid Block Limits"); foreach (var grid in grids.Where(x => x.BlocksCount > 0 && x.GridSizeEnum == MyCubeSize.Small)) { sb.AppendLine( $"{grid.DisplayName}: {grid.BlocksCount}/{BlockLimiterConfig.Instance.MaxBlocksSmallGrid}"); } } if (BlockLimiterConfig.Instance.MaxSmallGrids > 0) { sb.AppendLine($"Small Grids Limits: {grids.Count(x=>x.GridSizeEnum == MyCubeSize.Small)}/{BlockLimiterConfig.Instance.MaxSmallGrids}"); } if (BlockLimiterConfig.Instance.MaxLargeGrids > 0) { sb.AppendLine($"Large Grid Limits: {grids.Count(x=>x.GridSizeEnum == MyCubeSize.Large)}/{BlockLimiterConfig.Instance.MaxLargeGrids}"); } } } foreach (var item in limitItems) { if (item.BlockList.Count == 0 || item.FoundEntities.Count == 0) { continue; } var itemName = string.IsNullOrEmpty(item.Name) ? item.BlockList.FirstOrDefault() : item.Name; sb.AppendLine(); sb.AppendLine($"----->{itemName}<-----"); if (item.LimitPlayers && item.FoundEntities.TryGetValue(playerId, out var pCount)) { if (pCount > 1) { var dictionary = new ConcurrentDictionary <long, double>(); sb.AppendLine($"Player Limit = {pCount}/{item.Limit}"); if (playerBlocks.Count > 0) { foreach (var block in playerBlocks) { if (!item.IsMatch(block.BlockDefinition)) { continue; } dictionary.AddOrUpdate(block.CubeGrid.EntityId, 1, (l, i) => i + 1); } foreach (var(gridId, amount) in dictionary) { if (!GridCache.TryGetGridById(gridId, out var grid) && Grid.IsOwner(grid, playerId)) { sb.AppendLine($"[UnknownGrid] = {amount}"); continue; } sb.AppendLine($"{grid.DisplayName} = {amount}"); } } } } if (item.LimitFaction && playerFaction != null && item.FoundEntities.TryGetValue(playerFaction.FactionId, out var fCount)) { if (fCount > 1) { sb.AppendLine($"Faction Limit = {fCount}/{item.Limit} "); } } if (!item.LimitGrids) { continue; } var gridDictionary = new Dictionary <string, int>(); foreach (var(id, gCount) in item.FoundEntities) { if (!GridCache.TryGetGridById(id, out var grid) || !Grid.IsOwner(grid, playerId)) { continue; } if (!item.IsGridType(grid)) { item.FoundEntities.Remove(id); continue; } if (gCount < 1) { continue; } gridDictionary[grid.DisplayName] = gCount; } if (gridDictionary.Count == 0) { continue; } sb.AppendLine("Grid Limits:"); foreach (var(name, gCount) in gridDictionary) { sb.AppendLine($"->{name} = {gCount} / {item.Limit}"); } } return(sb); }