PKHeX/PKHeX.Core/Legality/Moves/Breeding/EggSource.cs

123 lines
3.3 KiB
C#
Raw Normal View History

using System;
using static PKHeX.Core.LegalityCheckStrings;
Add Breeding move ordering logic, and use in legality analysis (#3183) * Initial bred moveset validation logic Unpeel the inheritance via recursion and permitted moves * Volt tackle considerations * Optimize out empty slot skips * Add tests, fix off-by-one's * Require all base moves if empty slot in moveset * Add test to prove failure per Anubis' provided test * Tweak enum labels for easier debugging When two enums share the same underlying value, the ToString/name of the value may be either of the two (or the last defined one, in my debugging). Just give it a separate magic value. * Fix recursion oopsie Also check for scenario where no-base-moves but not enough moves to push base moves out * Add Crystal tutor checks * Add specialized gen2 verification method Game loops through father's moves and pushes in one iteration, rather than checking by type. * Add another case with returning base move * Add push-out requirement for re-added base moves * Minor tweaks Condense tests, fix another off-by-one noticed when creating tests * Disallow inherited parent levelup moves Disallow volt tackle on Gen2/R/S * Split MoveBreed into generation specific classes Gen2 behaves slightly different from Gen3/4, which behaves slightly different from Gen5... and Gen6 behaves differently too. Add some xmldoc as the api is starting to solidify * Add method overload that returns the parse Verify that the parse order is as expected * Add reordering suggestion logic Try sorting first, then go nuclear with rebuilding. * Return base moves if complete fail * Set base moves when generating eggs, only. * Use breed logic to check for egg ordering legality Don't bother helping for split-breed species
2021-04-05 01:30:01 +00:00
namespace PKHeX.Core
{
public enum EggSource2 : byte
{
None,
Base,
FatherEgg,
FatherTM,
ParentLevelUp,
Tutor,
Max,
}
public enum EggSource34 : byte
{
None,
Base,
FatherEgg,
FatherTM,
ParentLevelUp,
Max,
VoltTackle,
}
public enum EggSource5 : byte
{
None,
Base,
FatherEgg,
ParentLevelUp,
FatherTM, // after level up, unlike Gen3/4!
Max,
VoltTackle,
}
public enum EggSource6 : byte
{
None,
Base,
ParentLevelUp,
ParentEgg,
Max,
VoltTackle,
}
public static class EggSourceUtil
Add Breeding move ordering logic, and use in legality analysis (#3183) * Initial bred moveset validation logic Unpeel the inheritance via recursion and permitted moves * Volt tackle considerations * Optimize out empty slot skips * Add tests, fix off-by-one's * Require all base moves if empty slot in moveset * Add test to prove failure per Anubis' provided test * Tweak enum labels for easier debugging When two enums share the same underlying value, the ToString/name of the value may be either of the two (or the last defined one, in my debugging). Just give it a separate magic value. * Fix recursion oopsie Also check for scenario where no-base-moves but not enough moves to push base moves out * Add Crystal tutor checks * Add specialized gen2 verification method Game loops through father's moves and pushes in one iteration, rather than checking by type. * Add another case with returning base move * Add push-out requirement for re-added base moves * Minor tweaks Condense tests, fix another off-by-one noticed when creating tests * Disallow inherited parent levelup moves Disallow volt tackle on Gen2/R/S * Split MoveBreed into generation specific classes Gen2 behaves slightly different from Gen3/4, which behaves slightly different from Gen5... and Gen6 behaves differently too. Add some xmldoc as the api is starting to solidify * Add method overload that returns the parse Verify that the parse order is as expected * Add reordering suggestion logic Try sorting first, then go nuclear with rebuilding. * Return base moves if complete fail * Set base moves when generating eggs, only. * Use breed logic to check for egg ordering legality Don't bother helping for split-breed species
2021-04-05 01:30:01 +00:00
{
#pragma warning disable RCS1224 // Make method an extension method.
public static string GetSource(object parse, int gen, int index)
Add Breeding move ordering logic, and use in legality analysis (#3183) * Initial bred moveset validation logic Unpeel the inheritance via recursion and permitted moves * Volt tackle considerations * Optimize out empty slot skips * Add tests, fix off-by-one's * Require all base moves if empty slot in moveset * Add test to prove failure per Anubis' provided test * Tweak enum labels for easier debugging When two enums share the same underlying value, the ToString/name of the value may be either of the two (or the last defined one, in my debugging). Just give it a separate magic value. * Fix recursion oopsie Also check for scenario where no-base-moves but not enough moves to push base moves out * Add Crystal tutor checks * Add specialized gen2 verification method Game loops through father's moves and pushes in one iteration, rather than checking by type. * Add another case with returning base move * Add push-out requirement for re-added base moves * Minor tweaks Condense tests, fix another off-by-one noticed when creating tests * Disallow inherited parent levelup moves Disallow volt tackle on Gen2/R/S * Split MoveBreed into generation specific classes Gen2 behaves slightly different from Gen3/4, which behaves slightly different from Gen5... and Gen6 behaves differently too. Add some xmldoc as the api is starting to solidify * Add method overload that returns the parse Verify that the parse order is as expected * Add reordering suggestion logic Try sorting first, then go nuclear with rebuilding. * Return base moves if complete fail * Set base moves when generating eggs, only. * Use breed logic to check for egg ordering legality Don't bother helping for split-breed species
2021-04-05 01:30:01 +00:00
#pragma warning restore RCS1224 // Make method an extension method.
{
static string GetLine<T>(T[] arr, Func<T, string> act, int i)
{
if (i >= arr.Length)
return LMoveSourceEmpty;
return act(arr[i]);
}
return gen switch
{
2 => GetLine((EggSource2[]) parse, GetSource, index),
3 or 4 => GetLine((EggSource34[])parse, GetSource, index),
5 => GetLine((EggSource5[]) parse, GetSource, index),
>= 6 => GetLine((EggSource6[]) parse, GetSource, index),
_ => LMoveSourceEmpty,
};
}
Add Breeding move ordering logic, and use in legality analysis (#3183) * Initial bred moveset validation logic Unpeel the inheritance via recursion and permitted moves * Volt tackle considerations * Optimize out empty slot skips * Add tests, fix off-by-one's * Require all base moves if empty slot in moveset * Add test to prove failure per Anubis' provided test * Tweak enum labels for easier debugging When two enums share the same underlying value, the ToString/name of the value may be either of the two (or the last defined one, in my debugging). Just give it a separate magic value. * Fix recursion oopsie Also check for scenario where no-base-moves but not enough moves to push base moves out * Add Crystal tutor checks * Add specialized gen2 verification method Game loops through father's moves and pushes in one iteration, rather than checking by type. * Add another case with returning base move * Add push-out requirement for re-added base moves * Minor tweaks Condense tests, fix another off-by-one noticed when creating tests * Disallow inherited parent levelup moves Disallow volt tackle on Gen2/R/S * Split MoveBreed into generation specific classes Gen2 behaves slightly different from Gen3/4, which behaves slightly different from Gen5... and Gen6 behaves differently too. Add some xmldoc as the api is starting to solidify * Add method overload that returns the parse Verify that the parse order is as expected * Add reordering suggestion logic Try sorting first, then go nuclear with rebuilding. * Return base moves if complete fail * Set base moves when generating eggs, only. * Use breed logic to check for egg ordering legality Don't bother helping for split-breed species
2021-04-05 01:30:01 +00:00
public static string GetSource(this EggSource2 source) => source switch
{
EggSource2.Base => LMoveRelearnEgg,
EggSource2.FatherEgg => LMoveEggLevelUp,
EggSource2.FatherTM => LMoveEggTMHM,
EggSource2.ParentLevelUp => LMoveEggInherited,
EggSource2.Tutor => LMoveEggInheritedTutor,
EggSource2.Max => "Any",
_ => LMoveEggInvalid,
};
public static string GetSource(this EggSource34 source) => source switch
{
EggSource34.Base => LMoveRelearnEgg,
EggSource34.FatherEgg => LMoveEggLevelUp,
EggSource34.FatherTM => LMoveEggTMHM,
EggSource34.ParentLevelUp => LMoveEggInherited,
EggSource34.VoltTackle => LMoveSourceSpecial,
EggSource34.Max => "Any",
_ => LMoveEggInvalid,
};
public static string GetSource(this EggSource5 source) => source switch
{
EggSource5.Base => LMoveRelearnEgg,
EggSource5.FatherEgg => LMoveEggLevelUp,
EggSource5.FatherTM => LMoveEggTMHM,
EggSource5.ParentLevelUp => LMoveEggInherited,
EggSource5.VoltTackle => LMoveSourceSpecial,
EggSource5.Max => "Any",
_ => LMoveEggInvalid,
};
public static string GetSource(this EggSource6 source) => source switch
{
EggSource6.Base => LMoveRelearnEgg,
EggSource6.ParentEgg => LMoveEggLevelUp,
EggSource6.ParentLevelUp => LMoveEggInherited,
EggSource6.VoltTackle => LMoveSourceSpecial,
EggSource6.Max => "Any",
_ => LMoveEggInvalid,
};
}
}