Enhance IEncounterable list summarization

separates by type (wild, egg, etc) then groups by generation, listing
the locations and games that can obtain it in that location
This commit is contained in:
Kurt 2019-03-19 22:05:13 -07:00
parent fad5e4bdee
commit 8bc949152d
2 changed files with 37 additions and 14 deletions

View file

@ -635,8 +635,8 @@ namespace PKHeX.Core
internal static bool GetCanKnowMove(PKM pkm, int move, int generation, GameVersion version = GameVersion.Any)
{
if (pkm.Species == 235 && !InvalidSketch.Contains(move))
return true;
if (pkm.Species == 235)
return !InvalidSketch.Contains(move);
return GetValidMoves(pkm, version, EvolutionChain.GetValidPreEvolutions(pkm), generation, LVL: true, Relearn: true, Tutor: true, Machine: true).Contains(move);
}

View file

@ -71,19 +71,42 @@ namespace PKHeX.Core
public static IEnumerable<string> Summarize(IEnumerable<IEncounterable> encounters)
{
var types = encounters.GroupBy(z => z.Name);
foreach (var type in types)
{
var name = type.Key;
var versions = type.OfType<IVersion>().Select(z => z.Version).Distinct();
var locgroups = type.OfType<ILocation>().Select(z =>
z.GetEncounterLocation(
z is IGeneration g ? g.Generation : -1,
z is IVersion v ? (int) v.Version : -1));
yield return $"{name}: {string.Join(", ", versions)}";
return types.SelectMany(g => EnhancedSummary.SummarizeGroup(g.Key, g));
}
var locations = locgroups.Distinct().OrderBy(z => z).Where(z => !string.IsNullOrWhiteSpace(z)).ToArray();
if (locations.Length > 0)
yield return $"Locations: " + string.Join(", ", locations);
private struct EnhancedSummary
{
private readonly GameVersion Version;
private readonly string LocationName;
private EnhancedSummary(IEncounterable z)
{
Version = z is IVersion v ? v.Version : GameVersion.Any;
LocationName = GetLocationName(z);
}
private static string GetLocationName(IEncounterable z)
{
var gen = z is IGeneration g ? g.Generation : -1;
var version = z is IVersion v ? (int) v.Version : -1;
if (gen < 0 && version > 0)
gen = ((GameVersion)version).GetGeneration();
if (!(z is ILocation l))
return $"[Gen{gen}]\t";
var loc = l.GetEncounterLocation(gen, version);
if (string.IsNullOrWhiteSpace(loc))
return $"[Gen{gen}]\t";
return $"[Gen{gen}]\t{loc}: ";
}
public static IEnumerable<string> SummarizeGroup(string header, IEnumerable<IEncounterable> items)
{
yield return $"=={header}==";
var objs = items.Select(z => new EnhancedSummary(z)).GroupBy(z => z.LocationName);
foreach (var g in objs)
yield return $"\t{g.Key}{string.Join(", ", g.Select(z => z.Version).Distinct())}";
}
}
}