From 037db7b8a385670cd9bff929267e2a7c3743e375 Mon Sep 17 00:00:00 2001 From: Kurt Date: Mon, 16 Nov 2020 21:17:45 -0800 Subject: [PATCH] Add xmldoc for new obj/func related to GO legality --- PKHeX.Core/Legality/Areas/EncounterArea7g.cs | 6 ++- PKHeX.Core/Legality/Areas/EncounterArea8g.cs | 10 ++++- .../EncounterSlot/GO/EncounterSlot7GO.cs | 7 +++- .../EncounterSlot/GO/EncounterSlot8GO.cs | 13 +++++-- .../EncounterSlot/GO/EncounterSlotGO.cs | 29 ++++++++++++--- .../Encounters/EncounterSlot/GO/IPogoSlot.cs | 12 ++++++ .../EncounterSlot/GO/IPogoSlotTime.cs | 8 ---- .../Encounters/EncounterSlot/GO/PogoType.cs | 37 +++++++++++++++---- PKHeX.Core/Legality/Verifiers/BallVerifier.cs | 10 +---- 9 files changed, 95 insertions(+), 37 deletions(-) delete mode 100644 PKHeX.Core/Legality/Encounters/EncounterSlot/GO/IPogoSlotTime.cs diff --git a/PKHeX.Core/Legality/Areas/EncounterArea7g.cs b/PKHeX.Core/Legality/Areas/EncounterArea7g.cs index dac01c0fa..345909bab 100644 --- a/PKHeX.Core/Legality/Areas/EncounterArea7g.cs +++ b/PKHeX.Core/Legality/Areas/EncounterArea7g.cs @@ -10,7 +10,10 @@ namespace PKHeX.Core /// public sealed class EncounterArea7g : EncounterArea { + /// Species for the area + /// Due to how the encounter data is packaged by PKHeX, each species-form is grouped together. public int Species { get; } + /// Form of the Species public int Form { get; } private EncounterArea7g(int species, int form) : base(GameVersion.GO) @@ -53,7 +56,7 @@ namespace PKHeX.Core int end = BitConverter.ToInt32(data, offset + 4); var shiny = (Shiny)data[offset + 8]; var type = (PogoType)data[offset + 9]; - return new EncounterSlot7GO(area, species, form, type, shiny, start, end); + return new EncounterSlot7GO(area, species, form, start, end, shiny, type); } public override IEnumerable GetMatchingSlots(PKM pkm, IReadOnlyList chain) @@ -75,6 +78,7 @@ namespace PKHeX.Core continue; if (!slot.IsWithinStartEnd(stamp)) continue; + yield return slot; } } diff --git a/PKHeX.Core/Legality/Areas/EncounterArea8g.cs b/PKHeX.Core/Legality/Areas/EncounterArea8g.cs index 438849f3f..56bee0550 100644 --- a/PKHeX.Core/Legality/Areas/EncounterArea8g.cs +++ b/PKHeX.Core/Legality/Areas/EncounterArea8g.cs @@ -10,7 +10,10 @@ namespace PKHeX.Core /// public sealed class EncounterArea8g : EncounterArea { + /// Species for the area + /// Due to how the encounter data is packaged by PKHeX, each species-form is grouped together. public int Species { get; } + /// Form of the Species public int Form { get; } private EncounterArea8g(int species, int form) : base(GameVersion.GO) @@ -55,11 +58,16 @@ namespace PKHeX.Core int end = BitConverter.ToInt32(data, offset + 4); var shiny = (Shiny)data[offset + 8]; var type = (PogoType)data[offset + 9]; - return new EncounterSlot8GO(area, species, form, group, type, shiny, start, end); + return new EncounterSlot8GO(area, species, form, start, end, shiny, type, group); } private static GameVersion GetGroup(int species, int form) { + // Transfer Rules: + // If it can exist in LGP/E, it uses LGP/E's move data for the initial moves. + // Else, if it can exist in SW/SH, it uses SW/SH's move data for the initial moves. + // Else, it must exist in US/UM, thus it uses US/UM's moves. + var pt8 = PersonalTable.SWSH; var ptGG = PersonalTable.GG; diff --git a/PKHeX.Core/Legality/Encounters/EncounterSlot/GO/EncounterSlot7GO.cs b/PKHeX.Core/Legality/Encounters/EncounterSlot/GO/EncounterSlot7GO.cs index bf1c44cd0..9d0fc9ae9 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterSlot/GO/EncounterSlot7GO.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterSlot/GO/EncounterSlot7GO.cs @@ -1,11 +1,14 @@ namespace PKHeX.Core { + /// + /// Generation 7 Wild Encounter Slot data (GO Park) + /// public sealed class EncounterSlot7GO : EncounterSlotGO { public override int Generation => 7; - public EncounterSlot7GO(EncounterArea7g area, int species, int form, PogoType type, Shiny shiny, int start, int end) - : base(area, start, end, type, shiny) + public EncounterSlot7GO(EncounterArea7g area, int species, int form, int start, int end, Shiny shiny, PogoType type) + : base(area, start, end, shiny, type) { Species = species; Form = form; diff --git a/PKHeX.Core/Legality/Encounters/EncounterSlot/GO/EncounterSlot8GO.cs b/PKHeX.Core/Legality/Encounters/EncounterSlot/GO/EncounterSlot8GO.cs index aec48854c..e6b753458 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterSlot/GO/EncounterSlot8GO.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterSlot/GO/EncounterSlot8GO.cs @@ -1,17 +1,20 @@ namespace PKHeX.Core { + /// + /// Generation 8 Wild Encounter Slot data (GO -> HOME) + /// public sealed class EncounterSlot8GO : EncounterSlotGO { public override int Generation => 8; public GameVersion OriginGroup { get; } - public EncounterSlot8GO(EncounterArea8g area, int species, int form, GameVersion gameVersion, PogoType type, Shiny shiny, int start, int end) - : base(area, start, end, type, shiny) + public EncounterSlot8GO(EncounterArea8g area, int species, int form, int start, int end, Shiny shiny, PogoType type, GameVersion originGroup) + : base(area, start, end, shiny, type) { Species = species; Form = form; - OriginGroup = gameVersion; + OriginGroup = originGroup; } public int GetMinIV() => Type.GetMinIV(); @@ -25,7 +28,9 @@ namespace PKHeX.Core pk8.CurrentHandler = 1; base.ApplyDetails(sav, criteria, pk); - pk.Ball = (int)Type.GetValidBall(); + var ball = Type.GetValidBall(); + if (ball != Ball.None) + pk.Ball = (int)ball; pk8.HeightScalar = PokeSizeUtil.GetRandomScalar(); pk8.WeightScalar = PokeSizeUtil.GetRandomScalar(); diff --git a/PKHeX.Core/Legality/Encounters/EncounterSlot/GO/EncounterSlotGO.cs b/PKHeX.Core/Legality/Encounters/EncounterSlot/GO/EncounterSlotGO.cs index 181b78679..8415ab6f5 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterSlot/GO/EncounterSlotGO.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterSlot/GO/EncounterSlotGO.cs @@ -2,14 +2,25 @@ using System; namespace PKHeX.Core { - public abstract class EncounterSlotGO : EncounterSlot, IPogoSlotTime + /// + /// Contains details about an encounter that can be found in + /// + public abstract class EncounterSlotGO : EncounterSlot, IPogoSlot { - public PogoType Type { get; } - public Shiny Shiny { get; } + /// Start Date timestamp of when the encounter became available. public int Start { get; } + + /// End Date timestamp of when the encounter became unavailable. + /// If there is no end date (yet), we'll try to clamp to a date in the near-future to prevent it from being open-ended. public int End { get; } - protected EncounterSlotGO(EncounterArea area, int start, int end, PogoType type, Shiny shiny) : base(area) + /// Possibility of being shiny. + public Shiny Shiny { get; } + + /// How the encounter was captured. + public PogoType Type { get; } + + protected EncounterSlotGO(EncounterArea area, int start, int end, Shiny shiny, PogoType type) : base(area) { LevelMin = type.GetMinLevel(); LevelMax = EncountersGO.MAX_LEVEL; @@ -49,14 +60,20 @@ namespace PKHeX.Core const int tolerance = 1; if (End == 0) - return Start <= stamp; + return Start <= stamp && GetDate(stamp) <= DateTime.Now.AddDays(tolerance); if (Start == 0) return stamp <= End + tolerance; return Start <= stamp && stamp <= End + tolerance; } - public static int GetTimeStamp(int y, int m, int d) => (y << 16) | (m << 8) | d; + /// + /// Converts a split timestamp into a single integer. + /// + public static int GetTimeStamp(int year, int month, int day) => (year << 16) | (month << 8) | day; + /// + /// Gets a random date within the availability range. + /// public DateTime GetRandomValidDate() { if (Start == 0) diff --git a/PKHeX.Core/Legality/Encounters/EncounterSlot/GO/IPogoSlot.cs b/PKHeX.Core/Legality/Encounters/EncounterSlot/GO/IPogoSlot.cs index d041f1b37..0e194459f 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterSlot/GO/IPogoSlot.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterSlot/GO/IPogoSlot.cs @@ -1,8 +1,20 @@ namespace PKHeX.Core { + /// + /// Stores details about encounters relevant for legality. + /// public interface IPogoSlot { + /// Start date the encounter became available. If zero, no date specified (unbounded start). + int Start { get; } + + /// Last day the encounter was available. If zero, no date specified (unbounded finish). + int End { get; } + + /// Possibility of shiny for the encounter. Shiny Shiny { get; } + + /// Method the Pokémon may be encountered with. PogoType Type { get; } } } diff --git a/PKHeX.Core/Legality/Encounters/EncounterSlot/GO/IPogoSlotTime.cs b/PKHeX.Core/Legality/Encounters/EncounterSlot/GO/IPogoSlotTime.cs deleted file mode 100644 index 36450cc14..000000000 --- a/PKHeX.Core/Legality/Encounters/EncounterSlot/GO/IPogoSlotTime.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace PKHeX.Core -{ - public interface IPogoSlotTime : IPogoSlot - { - int Start { get; } - int End { get; } - } -} diff --git a/PKHeX.Core/Legality/Encounters/EncounterSlot/GO/PogoType.cs b/PKHeX.Core/Legality/Encounters/EncounterSlot/GO/PogoType.cs index d072cb06f..d5508f610 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterSlot/GO/PogoType.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterSlot/GO/PogoType.cs @@ -1,5 +1,8 @@ namespace PKHeX.Core { + /// + /// Encounter Type for various encounters. + /// public enum PogoType : byte { None, // Don't use this. @@ -29,7 +32,11 @@ namespace PKHeX.Core public static class PogoTypeExtensions { - public static int GetMinLevel(this PogoType t) => t switch + /// + /// Gets the minimum level (relative to GO's 1-) the must have. + /// + /// Descriptor indicating how the Pokémon was encountered in GO. + public static int GetMinLevel(this PogoType encounterType) => encounterType switch { PogoType.Raid15 => 15, PogoType.Raid20 => 20, @@ -41,7 +48,12 @@ namespace PKHeX.Core _ => 1, }; - public static int GetMinIV(this PogoType t) => t switch + /// + /// Gets the minimum IVs (relative to GO's 0-15) the must have. + /// + /// Descriptor indicating how the Pokémon was encountered in GO. + /// Required minimum IV (0-15) + public static int GetMinIV(this PogoType encounterType) => encounterType switch { PogoType.Wild => 0, PogoType.Raid20 => 10, @@ -51,15 +63,26 @@ namespace PKHeX.Core _ => 1, }; - public static bool IsBallValid(this PogoType t, Ball b) + /// + /// Checks if the is valid for the . + /// + /// Descriptor indicating how the Pokémon was encountered in GO. + /// Current the Pokémon is in. + /// True if valid, false if invalid. + public static bool IsBallValid(this PogoType encounterType, Ball ball) { - var req = t.GetValidBall(); + var req = encounterType.GetValidBall(); if (req == Ball.None) - return (uint)(b - 2) <= 2; // Poke, Great, Ultra - return b == req; + return (uint)(ball - 2) <= 2; // Poke, Great, Ultra + return ball == req; } - public static Ball GetValidBall(this PogoType t) => t switch + /// + /// Gets a valid ball that the can have based on the type of capture in Pokémon GO. + /// + /// Descriptor indicating how the Pokémon was encountered in GO. + /// if no specific ball is required, otherwise returns the required ball. + public static Ball GetValidBall(this PogoType encounterType) => encounterType switch { PogoType.Egg => Ball.Poke, PogoType.FieldP => Ball.Poke, diff --git a/PKHeX.Core/Legality/Verifiers/BallVerifier.cs b/PKHeX.Core/Legality/Verifiers/BallVerifier.cs index 4566ab2dd..0e572a023 100644 --- a/PKHeX.Core/Legality/Verifiers/BallVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/BallVerifier.cs @@ -34,8 +34,8 @@ namespace PKHeX.Core return VerifyBallEquals(data, t.Ball); case EncounterStatic s when s.Gift: return VerifyBallEquals(data, s.Ball); - case EncounterSlot8GO g: - return VerifyBallGOHOME(data, g); + case EncounterSlot8GO _: // Already a strict match + return GetResult(true); } // Capture / Inherit cases -- can be one of many balls @@ -85,12 +85,6 @@ namespace PKHeX.Core return VerifyBallEquals(data, Legal.GetWildBalls(data.Info.Generation, data.Info.Game)); } - private CheckResult VerifyBallGOHOME(LegalityAnalysis data, EncounterSlot8GO enc) - { - var valid = enc.IsBallValid((Ball)data.pkm.Ball); - return GetResult(valid); - } - private CheckResult VerifyBallEgg(LegalityAnalysis data) { var pkm = data.pkm;