/// <summary> Rebuild the list of available filters. </summary> private void BuildFilterList() { Filters.Clear(); if (UnitDetails == null || UnitDetails.Count() == 0) { return; } // Add a few generic filters at the top of the list. Filters.Add("All"); Filters.Add("Light Side"); Filters.Add("Dark Side"); // Add filters based on unit tags Filters.AddRange(UnitDetails.Select(u => u.categoryIdList).SelectMany(x => x).Distinct().OrderBy(x => x)); }
/// <summary> Generate and save the roster report. </summary> private void DoReport() { if (!ValidateFilters()) { return; } int char_power = 0, team_power = 0; try { if (CharPowerSelected) { char_power = int.Parse(CharPower); } if (TeamPowerSelected) { team_power = int.Parse(TeamPower); } } catch (Exception) { // Should never happen since we validated earlier ErrorMessage("Invalid character or team power specified."); return; } // Load squad presets from file List <SquadPreset> PresetsList = SquadPreset.LoadPresets(); if (PresetsList.Count == 0) { ErrorMessage("Unable to load squad presets."); return; } // Normalize names in presets var unit_names = UnitDetails.Select((u) => u.name); foreach (var preset in PresetsList) { preset.Character1 = SquadFinderViewmodel.FindUnit(preset.Character1, unit_names); preset.Character2 = SquadFinderViewmodel.FindUnit(preset.Character2, unit_names); preset.Character3 = SquadFinderViewmodel.FindUnit(preset.Character3, unit_names); preset.Character4 = SquadFinderViewmodel.FindUnit(preset.Character4, unit_names); preset.Character5 = SquadFinderViewmodel.FindUnit(preset.Character5, unit_names); } // Find out who has each squad List <PresetMatch> results = new List <PresetMatch>(); foreach (var preset in PresetsList) { PresetMatch this_preset = new PresetMatch(preset); List <string> names = new List <string>() { preset.Character1, preset.Character2, preset.Character3, preset.Character4, preset.Character5 }; // Check each guild member's roster foreach (var player in Members) { PresetSquad ps = new PresetSquad() { Owner = player.Name, Characters = null }; // Make sure this player has all of the characters, and that they meet any // filter criteria that was set. bool problem = false; var candidates = player.Roster.Where(c => names.Contains(c.name)).ToList(); if (candidates == null || candidates.Count() != 5) { problem = true; } else { if (StarLevelSelected && (candidates.Select(m => m.rarity).Min() < SelectedStarLevel)) { problem = true; } if (GearLevelSelected && (candidates.Select(m => m.gear).Min() < SelectedGearLevel)) { problem = true; } if (CharPowerSelected && (candidates.Select(m => m.TruePower).Min() < char_power)) { problem = true; } if (TeamPowerSelected && (candidates.Select(m => m.TruePower).Sum() < team_power)) { problem = true; } } if (!problem) { ps.Characters = new List <Character>(candidates); } // Add this squad to the list this_preset.Matches.Add(ps); } // Add results for this preset to the master list results.Add(this_preset); } // Generate output file try { GenerateReportFile(PresetsList, results); } catch (Exception e) { ErrorMessage($"Error saving file:\n{e.Message}"); return; } MessageBox.Show("Report generation complete.", "Success", MessageBoxButton.OK, MessageBoxImage.None); }