From 3813d5dba963e50f877a6171ee6ffe7eb295ed49 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sat, 25 Jan 2020 15:42:17 -0800 Subject: [PATCH] Readonly init EvolutionMethod Add xmldoc --- .../Legality/Evolutions/EvolutionMethod.cs | 47 ++++++++++++++++--- .../Evolutions/EvolutionSets/EvolutionSet1.cs | 9 ++-- .../Evolutions/EvolutionSets/EvolutionSet3.cs | 8 ++-- .../Evolutions/EvolutionSets/EvolutionSet4.cs | 13 +---- .../Evolutions/EvolutionSets/EvolutionSet5.cs | 13 +---- .../Evolutions/EvolutionSets/EvolutionSet6.cs | 17 ++----- .../Evolutions/EvolutionSets/EvolutionSet7.cs | 14 +++--- 7 files changed, 62 insertions(+), 59 deletions(-) diff --git a/PKHeX.Core/Legality/Evolutions/EvolutionMethod.cs b/PKHeX.Core/Legality/Evolutions/EvolutionMethod.cs index 1faa578cb..cab0a1edc 100644 --- a/PKHeX.Core/Legality/Evolutions/EvolutionMethod.cs +++ b/PKHeX.Core/Legality/Evolutions/EvolutionMethod.cs @@ -7,17 +7,50 @@ namespace PKHeX.Core /// public sealed class EvolutionMethod { - public int Method; - public int Species; - public int Argument; - public int Form = AnyForm; - public int Level; + /// + /// Evolution Method + /// + public readonly int Method; - public const int AnyForm = -1; + /// + /// Evolve to Species + /// + public readonly int Species; + + /// + /// Conditional Argument (different from ) + /// + public readonly int Argument; + + /// + /// Conditional Argument (different from ) + /// + public readonly int Level; + + /// + /// Destination Form + /// + /// Is if the evolved form isn't modified. Special consideration for , which forces 1. + public readonly int Form; + + private const int AnyForm = -1; // Not stored in binary data public bool RequiresLevelUp; // tracks if this method requires a Level Up, lazily set + public EvolutionMethod(int method, int species, int argument = 0, int level = 0, int form = AnyForm) + { + Method = method; + Species = species; + Argument = argument; + Form = form; + Level = level; + } + + /// + /// Returns the form that the Pokémon will have after evolution. + /// + /// Un-evolved Form ID public int GetDestinationForm(int form) { if (Method == (int)LevelUpFormFemale1) @@ -55,11 +88,11 @@ public bool Valid(PKM pkm, int lvl, bool skipChecks) case TradeSpecies: return !pkm.IsUntraded || skipChecks; + // Special Level Up Cases -- return false if invalid case LevelUpNatureAmped when GetAmpLowKeyResult(pkm.Nature) != pkm.AltForm && !skipChecks: case LevelUpNatureLowKey when GetAmpLowKeyResult(pkm.Nature) != pkm.AltForm && !skipChecks: return false; - // Special Level Up Cases -- return false if invalid case LevelUpBeauty when !(pkm is IContestStats s) || s.CNT_Beauty < Argument: return skipChecks; case LevelUpMale when pkm.Gender != 0: diff --git a/PKHeX.Core/Legality/Evolutions/EvolutionSets/EvolutionSet1.cs b/PKHeX.Core/Legality/Evolutions/EvolutionSets/EvolutionSet1.cs index 585c11f21..7f326508b 100644 --- a/PKHeX.Core/Legality/Evolutions/EvolutionSets/EvolutionSet1.cs +++ b/PKHeX.Core/Legality/Evolutions/EvolutionSets/EvolutionSet1.cs @@ -13,12 +13,9 @@ private static EvolutionMethod GetMethod(byte[] data, int offset) int method = data[offset]; int species = data[offset + 1]; int arg = data[offset + 2]; - var obj = new EvolutionMethod {Method = method, Species = species}; - if (method == 1) - obj.Level = arg; - else - obj.Argument = arg; - return obj; + return (method == 1) + ? new EvolutionMethod(method, species, level: arg) + : new EvolutionMethod(method, species, argument: arg); } public static IReadOnlyList GetArray(byte[] data, int maxSpecies) diff --git a/PKHeX.Core/Legality/Evolutions/EvolutionSets/EvolutionSet3.cs b/PKHeX.Core/Legality/Evolutions/EvolutionSets/EvolutionSet3.cs index 89f06361c..7103e3c99 100644 --- a/PKHeX.Core/Legality/Evolutions/EvolutionSets/EvolutionSet3.cs +++ b/PKHeX.Core/Legality/Evolutions/EvolutionSets/EvolutionSet3.cs @@ -22,12 +22,12 @@ private static EvolutionMethod GetMethod(byte[] data, int offset) case 3: /* Friendship night*/ case 5: /* Trade */ case 6: /* Trade while holding */ - return new EvolutionMethod { Method = method, Species = species, Argument = arg }; + return new EvolutionMethod(method, species, argument: arg); case 4: /* Level Up */ - return new EvolutionMethod { Method = 4, Species = species, Level = arg, Argument = arg }; + return new EvolutionMethod(4, species, argument: arg, level:arg); case 7: /* Use item */ case 15: /* Beauty evolution*/ - return new EvolutionMethod { Method = method + 1, Species = species, Argument = arg }; + return new EvolutionMethod(method + 1, species, argument: arg); case 8: /* Tyrogue -> Hitmonchan */ case 9: /* Tyrogue -> Hitmonlee */ case 10: /* Tyrogue -> Hitmontop*/ @@ -35,7 +35,7 @@ private static EvolutionMethod GetMethod(byte[] data, int offset) case 12: /* Wurmple -> Cascoon evolution */ case 13: /* Nincada -> Ninjask evolution */ case 14: /* Shedinja spawn in Nincada -> Ninjask evolution */ - return new EvolutionMethod { Method = method + 1, Species = species, Level = arg, Argument = arg }; + return new EvolutionMethod(method + 1, species, argument: arg, level: arg); default: throw new ArgumentException(nameof(method)); diff --git a/PKHeX.Core/Legality/Evolutions/EvolutionSets/EvolutionSet4.cs b/PKHeX.Core/Legality/Evolutions/EvolutionSets/EvolutionSet4.cs index caf0c5106..28be3e466 100644 --- a/PKHeX.Core/Legality/Evolutions/EvolutionSets/EvolutionSet4.cs +++ b/PKHeX.Core/Legality/Evolutions/EvolutionSets/EvolutionSet4.cs @@ -22,17 +22,8 @@ private static EvolutionMethod GetMethod(byte[] data, int offset) if (method > 6) method++; - var evo = new EvolutionMethod - { - Method = method, - Argument = arg, - Species = species, - Level = arg, - }; - - if (EvolutionSet6.EvosWithArg.Contains(method)) - evo.Level = 0; - return evo; + var lvl = EvolutionSet6.EvosWithArg.Contains(method) ? 0 : arg; + return new EvolutionMethod(method, species, argument: arg, level: lvl); } public static IReadOnlyList GetArray(byte[] data) diff --git a/PKHeX.Core/Legality/Evolutions/EvolutionSets/EvolutionSet5.cs b/PKHeX.Core/Legality/Evolutions/EvolutionSets/EvolutionSet5.cs index 70d71e94f..9b5c1b6aa 100644 --- a/PKHeX.Core/Legality/Evolutions/EvolutionSets/EvolutionSet5.cs +++ b/PKHeX.Core/Legality/Evolutions/EvolutionSets/EvolutionSet5.cs @@ -17,17 +17,8 @@ private static EvolutionMethod GetMethod(byte[] data, int offset) if (method == 0) throw new ArgumentException(nameof(data)); - var evo = new EvolutionMethod - { - Method = method, - Argument = arg, - Species = species, - Level = arg, - }; - - if (EvolutionSet6.EvosWithArg.Contains(method)) - evo.Level = 0; - return evo; + var lvl = EvolutionSet6.EvosWithArg.Contains(method) ? 0 : arg; + return new EvolutionMethod(method, species, argument: arg, level: lvl); } public static IReadOnlyList GetArray(byte[] data) diff --git a/PKHeX.Core/Legality/Evolutions/EvolutionSets/EvolutionSet6.cs b/PKHeX.Core/Legality/Evolutions/EvolutionSets/EvolutionSet6.cs index 13c0daa71..861bc9ce9 100644 --- a/PKHeX.Core/Legality/Evolutions/EvolutionSets/EvolutionSet6.cs +++ b/PKHeX.Core/Legality/Evolutions/EvolutionSets/EvolutionSet6.cs @@ -16,21 +16,14 @@ private static EvolutionMethod[] GetMethods(byte[] data) var evos = new EvolutionMethod[data.Length / SIZE]; for (int i = 0; i < data.Length; i += SIZE) { - var evo = new EvolutionMethod - { - Method = BitConverter.ToUInt16(data, i + 0), - Argument = BitConverter.ToUInt16(data, i + 2), - Species = BitConverter.ToUInt16(data, i + 4), - - // Copy - Level = BitConverter.ToUInt16(data, i + 2), - }; + var method = BitConverter.ToUInt16(data, i + 0); + var arg = BitConverter.ToUInt16(data, i + 2); + var spec = BitConverter.ToUInt16(data, i + 4); // Argument is used by both Level argument and Item/Move/etc. Clear if appropriate. - if (EvosWithArg.Contains(evo.Method)) - evo.Level = 0; + var lvl = EvosWithArg.Contains(method) ? 0 : arg; - evos[i/SIZE] = evo; + evos[i/SIZE] = new EvolutionMethod(method, spec, argument: arg, level: lvl); } return evos; } diff --git a/PKHeX.Core/Legality/Evolutions/EvolutionSets/EvolutionSet7.cs b/PKHeX.Core/Legality/Evolutions/EvolutionSets/EvolutionSet7.cs index 650421aae..5b746d425 100644 --- a/PKHeX.Core/Legality/Evolutions/EvolutionSets/EvolutionSet7.cs +++ b/PKHeX.Core/Legality/Evolutions/EvolutionSets/EvolutionSet7.cs @@ -15,14 +15,12 @@ private static EvolutionMethod[] GetMethods(byte[] data) var evos = new EvolutionMethod[data.Length / SIZE]; for (int i = 0; i < data.Length; i += SIZE) { - evos[i / SIZE] = new EvolutionMethod - { - Method = BitConverter.ToUInt16(data, i + 0), - Argument = BitConverter.ToUInt16(data, i + 2), - Species = BitConverter.ToUInt16(data, i + 4), - Form = (sbyte)data[i + 6], - Level = data[i + 7], - }; + var method = BitConverter.ToUInt16(data, i + 0); + var arg = BitConverter.ToUInt16(data, i + 2); + var spec = BitConverter.ToUInt16(data, i + 4); + var form = (sbyte) data[i + 6]; + var level = data[i + 7]; + evos[i / SIZE] = new EvolutionMethod(method, spec, argument: arg, level: level, form: form); } return evos; }