Skip to content

Commit

Permalink
remove unnecessary enum
Browse files Browse the repository at this point in the history
  • Loading branch information
architdate committed Dec 4, 2021
1 parent 18feb98 commit 8042e6d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
7 changes: 3 additions & 4 deletions AutoLegalityMod/GUI/ShowdownSetLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,15 @@ private static AutoModErrorCode ImportSetToTabs(ShowdownSet set, bool skipDialog
var legal = sav.GetLegalFromSet(regen, out var msg);
timer.Stop();

var analysis = BattleTemplateLegality.ANALYSIS_INVALID;
var set_legality = SetLegality.InvalidSet;
string? analysis = null;
if (msg is LegalizationResult.Failed)
set_legality = regen.SetAnalysis(sav, out analysis);
analysis = regen.SetAnalysis(sav);

if (msg is LegalizationResult.Timeout or LegalizationResult.Failed)
{
Legalizer.Dump(regen, msg == LegalizationResult.Failed);
var errorstr = msg == LegalizationResult.Failed ? "failed to generate" : "timed out";
var invalid_set_error = (set_legality == SetLegality.InvalidSet ? $"Set {errorstr}." : $"Set Invalid: {analysis}") +
var invalid_set_error = (analysis == null ? $"Set {errorstr}." : $"Set Invalid: {analysis}") +
"\n\nIf you are sure this set is valid, please create an issue on GitHub and upload the error_log.txt file in the issue." +
"\n\nAlternatively, join the support Discord and post the same file in the #autolegality-livehex-help channel.";
var res = WinFormsUtil.ALMError(invalid_set_error);
Expand Down
22 changes: 6 additions & 16 deletions PKHeX.Core.AutoMod/Enhancements/BattleTemplateLegality.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,25 @@ public static class BattleTemplateLegality
private static string INVALID_MOVES => "{0} cannot learn the following moves in the game: {1}.";
private static string ALL_MOVES_INVALID => "All the requested moves for this Pokémon are invalid.";

public static SetLegality SetAnalysis(this RegenTemplate set, SaveFile sav, out string analysis)
public static string SetAnalysis(this RegenTemplate set, SaveFile sav)
{
var species_name = SpeciesName.GetSpeciesNameGeneration(set.Species, (int)LanguageID.English, sav.Generation);
analysis = set.Form == 0 ? string.Format(SPECIES_UNAVAILABLE, species_name)
var analysis = set.Form == 0 ? string.Format(SPECIES_UNAVAILABLE, species_name)
: string.Format(SPECIES_UNAVAILABLE_FORM, species_name, set.FormName);

// Species checks
var gv = (GameVersion)sav.Game;
if (!gv.ExistsInGame(set.Species, set.Form))
return SetLegality.SpeciesUnavilable; // Species does not exist in the game
return analysis; // Species does not exist in the game

// Species exists -- check if it has atleast one move. If it has no moves and it didn't generate, that makes the mon still illegal in game (moves are set to legal ones)
var moves = set.Moves.Where(z => z != 0);
var count = moves.Count();
if (count == 0)
return SetLegality.SpeciesUnavilable; // Species does not exist in the game
return analysis; // Species does not exist in the game

analysis = string.Format(INVALID_MOVE, species_name, (Move)set.Moves[0]);
if (count == 1)
return SetLegality.InvalidMoves; // The only move specified cannot be learnt by the mon
return string.Format(INVALID_MOVE, species_name, (Move)set.Moves[0]); // The only move specified cannot be learnt by the mon

List<IEnumerable<int>> move_combinations = new();
for (int i = moves.Count() - 1; i >= 1; i--)
Expand Down Expand Up @@ -68,8 +67,7 @@ public static SetLegality SetAnalysis(this RegenTemplate set, SaveFile sav, out
successful_combination = combination.ToArray();
}
var invalid_moves = string.Join(", ", original_moves.Where(z => !successful_combination.Contains(z) && z != 0).Select(z => $"{(Move)z}"));
analysis = successful_combination.Length > 0 ? string.Format(INVALID_MOVES, species_name, invalid_moves) : ALL_MOVES_INVALID;
return SetLegality.InvalidMoves;
return successful_combination.Length > 0 ? string.Format(INVALID_MOVES, species_name, invalid_moves) : ALL_MOVES_INVALID;
}

private static IEnumerable<IEnumerable<T>> GetKCombs<T>(IEnumerable<T> list, int length) where T : IComparable
Expand All @@ -80,12 +78,4 @@ private static IEnumerable<IEnumerable<T>> GetKCombs<T>(IEnumerable<T> list, int
(t1, t2) => t1.Concat(new T[] { t2 }));
}
}

public enum SetLegality
{
Valid,
SpeciesUnavilable,
InvalidMoves,
InvalidSet
}
}

0 comments on commit 8042e6d

Please sign in to comment.