-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Labels
Description
#if DEBUG だったときはデバッグありで、ない場合はすべてのLinqをチェインしたやつにしたほうがラグスパイク避けられそう
MapChooserSharp/MapChooserSharp/Modules/MapVote/McsMapVoteController.cs
Lines 1070 to 1125 in 4f3bcf0
| private List<IMapConfig> PickRandomFilteredMaps(List<IMapConfig> unusedMapList, int numToPick) | |
| { | |
| // This method will not use Linq to make debug logging easier | |
| var shuffledMaps = unusedMapList | |
| .OrderBy(_ => _random.Next()).ToList(); | |
| var disabledMaps = shuffledMaps.Where(map => !map.IsDisabled).ToList(); | |
| DebugLogger.LogTrace($"[Filter | Disabled Maps] {disabledMaps.Count} maps found."); | |
| var cooldownEndedMaps = disabledMaps.Where(map => map.MapCooldown.CurrentCooldown <= 0).ToList(); | |
| DebugLogger.LogTrace($"[Filter | Map Cooldown] {cooldownEndedMaps.Count} maps found."); | |
| var alsoGroupCooldownEnded = cooldownEndedMaps.Where(map => | |
| !map.GroupSettings.Any() || | |
| map.GroupSettings.Count(setting => setting.GroupCooldown.CurrentCooldown > 0) == 0).ToList(); | |
| DebugLogger.LogTrace($"[Filter | Gorup Cooldown] {cooldownEndedMaps.Count} maps found."); | |
| var notRestrectedToNominationOnly = alsoGroupCooldownEnded.Where(map => !map.OnlyNomination).ToList(); | |
| DebugLogger.LogTrace($"[Filter | No Nomination Restriction] {notRestrectedToNominationOnly.Count} maps found."); | |
| var notRestrictedToCertainUsers = notRestrectedToNominationOnly.Where(map => !map.NominationConfig.RestrictToAllowedUsersOnly).ToList(); | |
| DebugLogger.LogTrace($"[Filter | Not Restricted Certain users] {notRestrictedToCertainUsers.Count} maps found."); | |
| var greaterThanMinPlayers = notRestrictedToCertainUsers.Where(map => map.NominationConfig.MinPlayers == 0 || map.NominationConfig.MinPlayers <= Utilities.GetPlayers().Count(p => p is { IsBot: false, IsHLTV: false })).ToList(); | |
| DebugLogger.LogTrace($"[Filter | Greater Than Min Players] {greaterThanMinPlayers.Count} maps found."); | |
| var lowerThanMaxPlayers = greaterThanMinPlayers.Where(map => map.NominationConfig.MaxPlayers == 0 || map.NominationConfig.MaxPlayers >= Utilities.GetPlayers().Count(p => p is { IsBot: false, IsHLTV: false })).ToList(); | |
| DebugLogger.LogTrace($"[Filter | Lower Than Max Players] {lowerThanMaxPlayers.Count} maps found."); | |
| var notRequiresPermission = lowerThanMaxPlayers.Where(map => !map.NominationConfig.RequiredPermissions.Any()).ToList(); | |
| DebugLogger.LogTrace($"[Filter | Not Requires Permission] {notRequiresPermission.Count} maps found."); | |
| var withinAllowedDays = notRequiresPermission.Where(map => !map.NominationConfig.DaysAllowed.Any() || map.NominationConfig.DaysAllowed.Contains(DateTime.Today.DayOfWeek)).ToList(); | |
| DebugLogger.LogTrace($"[Filter | Within Allowed Days] {withinAllowedDays.Count} maps found."); | |
| var whithinAllowedTimeRange = withinAllowedDays.Where(map => !map.NominationConfig.AllowedTimeRanges.Any() || map.NominationConfig.AllowedTimeRanges.Count(range => range.IsInRange(TimeOnly.FromDateTime(DateTime.Now))) >= 1).ToList(); | |
| DebugLogger.LogTrace($"[Filter | Within Allowed Time Range] {whithinAllowedTimeRange.Count} maps found."); | |
| var withoutCurrentMap = whithinAllowedTimeRange.Where(map => !map.MapName.Equals(_mapCycleController.CurrentMap?.MapName)).ToList(); | |
| DebugLogger.LogTrace($"[Filter | Without Current Map] {withoutCurrentMap.Count} maps found."); | |
| var pickedMaps = withoutCurrentMap.Take(numToPick).ToList(); | |
| DebugLogger.LogTrace($"[Filter | Finally] {pickedMaps.Count} maps picked."); | |
| return pickedMaps; | |
| } |