Esempio n. 1
0
        public bool[] getRelearnValidity(int[] Moves)
        {
            if (Moves.Length != 4)
            {
                return(new bool[4]);
            }

            bool[] res = { true, true, true, true };
            if (!pk6.Gen6)
            {
                goto noRelearn;
            }

            bool egg      = Legal.EggLocations.Contains(pk6.Egg_Location) && pk6.Met_Level == 1;
            bool evnt     = pk6.FatefulEncounter && pk6.Met_Location > 40000;
            bool eventEgg = pk6.FatefulEncounter && (pk6.Egg_Location > 40000 || pk6.Egg_Location == 30002) && pk6.Met_Level == 1;

            int[] relearnMoves = Legal.getValidRelearn(pk6, 0);
            if (evnt || eventEgg)
            {
                // Check Event Info
                // Not Implemented
            }
            else if (egg)
            {
                if (Legal.SplitBreed.Contains(pk6.Species))
                {
                    res = new bool[4];
                    for (int i = 0; i < 4; i++)
                    {
                        res[i] = relearnMoves.Contains(Moves[i]);
                    }
                    if (!res.Any(move => !move))
                    {
                        return(res);
                    }

                    // Try Next Species up
                    Legal.getValidRelearn(pk6, 1);
                    for (int i = 0; i < 4; i++)
                    {
                        res[i] = relearnMoves.Contains(Moves[i]);
                    }
                    return(res);
                }

                if (Legal.LightBall.Contains(pk6.Species))
                {
                    relearnMoves = relearnMoves.Concat(new[] { 344 }).ToArray();
                }
                for (int i = 0; i < 4; i++)
                {
                    res[i] &= relearnMoves.Contains(Moves[i]);
                }
                return(res);
            }
            else if (Moves[0] != 0) // DexNav only?
            {
                // Check DexNav
                for (int i = 0; i < 4; i++)
                {
                    res[i] &= Moves[i] == 0;
                }
                if (DexNav)
                {
                    res[0] = relearnMoves.Contains(Moves[0]);
                }

                return(res);
            }

            // Should have no relearn moves.
noRelearn:
            for (int i = 0; i < 4; i++)
            {
                res[i] &= Moves[i] == 0;
            }
            return(res);
        }
Esempio n. 2
0
        private LegalityCheck[] verifyMoves()
        {
            int[]           Moves = pk6.Moves;
            LegalityCheck[] res   = new LegalityCheck[4];
            for (int i = 0; i < 4; i++)
            {
                res[i] = new LegalityCheck();
            }
            if (!pk6.Gen6)
            {
                return(res);
            }

            var validMoves = Legal.getValidMoves(pk6).ToArray();

            if (pk6.Species == 235)
            {
                for (int i = 0; i < 4; i++)
                {
                    res[i] = Legal.InvalidSketch.Contains(Moves[i])
                        ? new LegalityCheck(Severity.Invalid, "Invalid Sketch move.")
                        : new LegalityCheck();
                }
            }
            else
            {
                int[] RelearnMoves = pk6.RelearnMoves;
                int[] WC6Moves     = MatchedWC6?.Moves ?? new int[0];
                for (int i = 0; i < 4; i++)
                {
                    if (Moves[i] == Legal.Struggle)
                    {
                        res[i] = new LegalityCheck(Severity.Invalid, "Invalid Move: Struggle.");
                    }
                    else if (validMoves.Contains(Moves[i]))
                    {
                        res[i] = new LegalityCheck(Severity.Valid, "Level-up.");
                    }
                    else if (RelearnMoves.Contains(Moves[i]))
                    {
                        res[i] = new LegalityCheck(Severity.Valid, "Relearn Move.");
                    }
                    else if (WC6Moves.Contains(Moves[i]))
                    {
                        res[i] = new LegalityCheck(Severity.Valid, "Wondercard Non-Relearn Move.");
                    }
                    else
                    {
                        res[i] = new LegalityCheck(Severity.Invalid, "Invalid Move.");
                    }
                }
            }
            if (Moves[0] == 0)
            {
                res[0] = new LegalityCheck(Severity.Invalid, "Invalid Move.");
            }


            if (pk6.Species == 647) // Keldeo
            {
                if (pk6.AltForm == 1 ^ pk6.Moves.Contains(548))
                {
                    res[0] = new LegalityCheck(Severity.Invalid, "Secret Sword / Resolute Keldeo Mismatch.");
                }
            }

            // Duplicate Moves Check
            for (int i = 0; i < 4; i++)
            {
                if (Moves.Count(m => m != 0 && m == Moves[i]) > 1)
                {
                    res[i] = new LegalityCheck(Severity.Invalid, "Duplicate Move.");
                }
            }

            return(res);
        }
Esempio n. 3
0
        private LegalityCheck[] verifyRelearn()
        {
            LegalityCheck[] res = new LegalityCheck[4];
            MatchedWC6 = null; // Reset
            int[] Moves = pk6.RelearnMoves;
            if (!pk6.Gen6)
            {
                goto noRelearn;
            }
            if (pk6.WasLink)
            {
                int[] moves = Legal.getLinkMoves(pk6);
                for (int i = 0; i < 4; i++)
                {
                    res[i] = moves[i] != Moves[i]
                        ? new LegalityCheck(Severity.Invalid, $"Expected ID:{moves[i]}.")
                        : new LegalityCheck();
                }
                return(res);
            }
            if (pk6.WasEvent || pk6.WasEventEgg)
            {
                // Get WC6's that match
                IEnumerable <WC6> vwc6 = Legal.getValidWC6s(pk6);
                foreach (var wc in vwc6)
                {
                    int[] moves = wc.RelearnMoves;
                    for (int i = 0; i < 4; i++)
                    {
                        res[i] = moves[i] != Moves[i]
                            ? new LegalityCheck(Severity.Invalid, $"Expected ID:{moves[i]}.")
                            : new LegalityCheck(Severity.Valid, $"Matched WC #{wc.CardID.ToString("0000")}");
                    }
                    if (res.All(r => r.Valid))
                    {
                        MatchedWC6 = wc; return(res);
                    }
                }
                goto noRelearn; // No WC match
            }

            if (pk6.WasEgg)
            {
                const int games         = 2;
                bool      checkAllGames = pk6.WasTradedEgg;
                bool      splitBreed    = Legal.SplitBreed.Contains(pk6.Species);

                int iterate = (checkAllGames ? games : 1) * (splitBreed ? 2 : 1);
                for (int i = 0; i < iterate; i++)
                {
                    int gameSource = !checkAllGames ? -1 : i % iterate / (splitBreed ? 2 : 1);
                    int skipOption = splitBreed && iterate / 2 <= i ? 1 : 0;

                    // Obtain level1 moves
                    List <int> baseMoves = new List <int>(Legal.getBaseEggMoves(pk6, skipOption, gameSource));
                    int        baseCt    = baseMoves.Count;
                    if (baseCt > 4)
                    {
                        baseCt = 4;
                    }

                    // Obtain Nonstandard moves
                    var relearnMoves = Legal.getValidRelearn(pk6, skipOption).ToArray();
                    var relearn      = pk6.RelearnMoves.Where(move => move != 0 &&
                                                              (!baseMoves.Contains(move) || relearnMoves.Contains(move))
                                                              ).ToArray();
                    int relearnCt = relearn.Length;

                    // Get Move Window
                    List <int> window = new List <int>(baseMoves);
                    window.AddRange(relearn);
                    int[] moves = window.Skip(baseCt + relearnCt - 4).Take(4).ToArray();
                    Array.Resize(ref moves, 4);

                    int req;
                    if (relearnCt == 4)
                    {
                        req = 0;
                    }
                    else if (baseCt + relearnCt > 4)
                    {
                        req = 4 - relearnCt;
                    }
                    else
                    {
                        req = baseCt;
                    }

                    // Movepool finalized! Check validity.

                    int[]  rl = pk6.RelearnMoves;
                    string em = string.Join(", ", baseMoves);
                    // Base Egg Move
                    for (int j = 0; j < req; j++)
                    {
                        res[j] = !baseMoves.Contains(rl[j])
                            ? new LegalityCheck(Severity.Invalid, $"Base egg move missing; expected one of: {em}.")
                            : new LegalityCheck(Severity.Valid, "Base egg move.");
                    }

                    // Non-Base
                    if (Legal.LightBall.Contains(pk6.Species))
                    {
                        relearnMoves = relearnMoves.Concat(new[] { 344 }).ToArray();
                    }
                    for (int j = req; j < 4; j++)
                    {
                        res[j] = !relearnMoves.Contains(rl[j])
                            ? new LegalityCheck(Severity.Invalid, "Not an expected relearn move.")
                            : new LegalityCheck(Severity.Valid, "Relearn move.");
                    }

                    if (res.All(r => r.Valid))
                    {
                        break;
                    }
                }
                return(res);
            }
            if (Moves[0] != 0) // DexNav only?
            {
                // Check DexNav
                if (!Legal.getDexNavValid(pk6))
                {
                    goto noRelearn;
                }

                res[0] = !Legal.getValidRelearn(pk6, 0).Contains(Moves[0])
                        ? new LegalityCheck(Severity.Invalid, "Not an expected DexNav move.")
                        : new LegalityCheck();
                for (int i = 1; i < 4; i++)
                {
                    res[i] = Moves[i] != 0
                        ? new LegalityCheck(Severity.Invalid, "Expected no Relearn Move in slot.")
                        : new LegalityCheck();
                }

                return(res);
            }

            // Should have no relearn moves.
noRelearn:
            for (int i = 0; i < 4; i++)
            {
                res[i] = Moves[i] != 0
                    ? new LegalityCheck(Severity.Invalid, "Expected no Relearn Moves.")
                    : new LegalityCheck();
            }
            return(res);
        }
Esempio n. 4
0
        private LegalityCheck[] verifyRelearn()
        {
            RelearnBase = null;
            LegalityCheck[] res = new LegalityCheck[4];

            int[] Moves = pk6.RelearnMoves;
            if (!pk6.Gen6)
            {
                goto noRelearn;
            }
            if (pk6.WasLink)
            {
                var Link = Legal.getValidLinkGifts(pk6);
                if (Link == null)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        res[i] = new LegalityCheck();
                    }
                    return(res);
                }
                EncounterMatch = Link;

                int[] moves = ((EncounterLink)EncounterMatch).RelearnMoves;
                RelearnBase = moves;
                for (int i = 0; i < 4; i++)
                {
                    res[i] = moves[i] != Moves[i]
                        ? new LegalityCheck(Severity.Invalid, $"Expected: {movelist[moves[i]]}.")
                        : new LegalityCheck();
                }
                return(res);
            }
            if (pk6.WasEvent || pk6.WasEventEgg)
            {
                // Get WC6's that match
                CardMatch = new List <WC6>(Legal.getValidWC6s(pk6));
                foreach (var wc in CardMatch)
                {
                    int[] moves = wc.RelearnMoves;
                    for (int i = 0; i < 4; i++)
                    {
                        res[i] = moves[i] != Moves[i]
                            ? new LegalityCheck(Severity.Invalid, $"Expected ID: {movelist[moves[i]]}.")
                            : new LegalityCheck(Severity.Valid, $"Matched WC #{wc.CardID.ToString("0000")}");
                    }
                    if (res.Any(r => !r.Valid))
                    {
                        CardMatch.Remove(wc);
                    }
                }
                if (CardMatch.Count > 1)
                {
                    return(res);
                }
                if (CardMatch.Count == 1)
                {
                    EncounterMatch = CardMatch[0]; RelearnBase = CardMatch[0].RelearnMoves; return(res);
                }

                EncounterMatch = EncounterType = null;
                goto noRelearn; // No WC match
            }

            if (pk6.WasEgg)
            {
                const int games         = 2;
                bool      checkAllGames = pk6.WasTradedEgg;
                bool      splitBreed    = Legal.SplitBreed.Contains(pk6.Species);

                int iterate = (checkAllGames ? games : 1) * (splitBreed ? 2 : 1);
                for (int i = 0; i < iterate; i++)
                {
                    int gameSource = !checkAllGames ? -1 : i % iterate / (splitBreed ? 2 : 1);
                    int skipOption = splitBreed && iterate / 2 <= i ? 1 : 0;

                    // Obtain level1 moves
                    List <int> baseMoves = new List <int>(Legal.getBaseEggMoves(pk6, skipOption, gameSource));
                    int        baseCt    = baseMoves.Count;
                    if (baseCt > 4)
                    {
                        baseCt = 4;
                    }

                    // Obtain Nonstandard moves
                    var relearnMoves = Legal.getValidRelearn(pk6, skipOption).ToArray();
                    var relearn      = pk6.RelearnMoves.Where(move => move != 0 &&
                                                              (!baseMoves.Contains(move) || relearnMoves.Contains(move))
                                                              ).ToArray();
                    int relearnCt = relearn.Length;

                    // Get Move Window
                    List <int> window = new List <int>(baseMoves);
                    window.AddRange(relearn);
                    int[] moves = window.Skip(baseCt + relearnCt - 4).Take(4).ToArray();
                    Array.Resize(ref moves, 4);

                    int req;
                    if (relearnCt == 4)
                    {
                        req = 0;
                    }
                    else if (baseCt + relearnCt > 4)
                    {
                        req = 4 - relearnCt;
                    }
                    else
                    {
                        req = baseCt;
                    }

                    // Movepool finalized! Check validity.

                    int[]  rl = pk6.RelearnMoves;
                    string em = string.Join(", ", baseMoves.Select(r => r >= movelist.Length ? "ERROR" : movelist[r]));
                    RelearnBase = baseMoves.ToArray();
                    // Base Egg Move
                    for (int j = 0; j < req; j++)
                    {
                        if (baseMoves.Contains(rl[j]))
                        {
                            res[j] = new LegalityCheck(Severity.Valid, "Base egg move.");
                        }
                        else
                        {
                            res[j] = new LegalityCheck(Severity.Invalid, "Base egg move missing.");
                            for (int f = j + 1; f < req; f++)
                            {
                                res[f] = new LegalityCheck(Severity.Invalid, "Base egg move missing.");
                            }
                            res[req - 1].Comment += $"{Environment.NewLine}Expected the following Relearn Moves: {em}.";
                            break;
                        }
                    }

                    // Non-Base
                    if (Legal.LightBall.Contains(pk6.Species))
                    {
                        relearnMoves = relearnMoves.Concat(new[] { 344 }).ToArray();
                    }
                    for (int j = req; j < 4; j++)
                    {
                        res[j] = !relearnMoves.Contains(rl[j])
                            ? new LegalityCheck(Severity.Invalid, "Not an expected relearn move.")
                            : new LegalityCheck(Severity.Valid, rl[j] == 0 ? "Empty" : "Relearn move.");
                    }

                    if (res.All(r => r.Valid))
                    {
                        break;
                    }
                }
                return(res);
            }
            if (Moves[0] != 0) // DexNav only?
            {
                // Check DexNav
                if (!Legal.getDexNavValid(pk6))
                {
                    goto noRelearn;
                }

                res[0] = !Legal.getValidRelearn(pk6, 0).Contains(Moves[0])
                        ? new LegalityCheck(Severity.Invalid, "Not an expected DexNav move.")
                        : new LegalityCheck();
                for (int i = 1; i < 4; i++)
                {
                    res[i] = Moves[i] != 0
                        ? new LegalityCheck(Severity.Invalid, "Expected no Relearn Move in slot.")
                        : new LegalityCheck();
                }

                if (res[0].Valid)
                {
                    RelearnBase = new[] { Moves[0], 0, 0, 0 }
                }
                ;
                return(res);
            }

            // Should have no relearn moves.
noRelearn:
            for (int i = 0; i < 4; i++)
            {
                res[i] = Moves[i] != 0
                    ? new LegalityCheck(Severity.Invalid, "Expected no Relearn Moves.")
                    : new LegalityCheck();
            }
            return(res);
        }
Esempio n. 5
0
        private LegalityCheck verifyEncounter()
        {
            if (!pk6.Gen6)
            {
                return new LegalityCheck {
                           Judgement = Severity.NotImplemented
                }
            }
            ;

            if (pk6.WasLink)
            {
                // Should NOT be Fateful, and should be in Database
                return(pk6.FatefulEncounter || Legal.getLinkMoves(pk6).Length == 0
                    ? new LegalityCheck(Severity.Invalid, "Not a valid Link gift.")
                    : new LegalityCheck(Severity.Valid, "Valid Link gift."));
            }
            if (pk6.WasEvent || pk6.WasEventEgg)
            {
                return(MatchedWC6 != null // Matched in RelearnMoves check.
                    ? new LegalityCheck(Severity.Valid, $"Matches #{MatchedWC6.CardID.ToString("0000")} ({MatchedWC6.CardTitle})")
                    : new LegalityCheck(Severity.Invalid, "Not a valid Wonder Card gift."));
            }
            if (pk6.WasEgg)
            {
                // Check Hatch Locations
                if (pk6.Met_Level != 1)
                {
                    return(new LegalityCheck(Severity.Invalid, "Invalid met level, expected 1."));
                }
                if (pk6.IsEgg)
                {
                    return(pk6.Met_Location == 0
                        ? new LegalityCheck(Severity.Valid, "Valid un-hatched egg.")
                        : new LegalityCheck(Severity.Invalid, "Invalid location for un-hatched egg (expected ID:0)"));
                }
                if (pk6.XY)
                {
                    return(Legal.ValidMet_XY.Contains(pk6.Met_Location)
                        ? new LegalityCheck(Severity.Valid, "Valid X/Y hatched egg.")
                        : new LegalityCheck(Severity.Invalid, "Invalid X/Y location for hatched egg."));
                }
                if (pk6.AO)
                {
                    return(Legal.ValidMet_AO.Contains(pk6.Met_Location)
                        ? new LegalityCheck(Severity.Valid, "Valid OR/AS hatched egg.")
                        : new LegalityCheck(Severity.Invalid, "Invalid OR/AS location for hatched egg."));
                }
                return(new LegalityCheck(Severity.Invalid, "Invalid location for hatched egg."));
            }

            EncounterStatic z = Legal.getStaticEncounter(pk6);

            if (z != null)
            {
                return(new LegalityCheck(Severity.Valid, "Valid gift/static encounter."));
            }

            if (Legal.getIsFossil(pk6))
            {
                return(pk6.AbilityNumber != 4
                    ? new LegalityCheck(Severity.Valid, "Valid revived fossil.")
                    : new LegalityCheck(Severity.Invalid, "Hidden ability on revived fossil."));
            }
            int FriendSafari = Legal.getFriendSafariValid(pk6);

            if (FriendSafari > 0)
            {
                if (pk6.Species == 670 || pk6.Species == 671) // Floette
                {
                    if (pk6.AltForm % 2 != 0)                 // 0/2/4
                    {
                        return(new LegalityCheck(Severity.Invalid, "Friend Safari: Not valid color."));
                    }
                    else if (pk6.Species == 710 || pk6.Species == 711) // Pumpkaboo
                    {
                        if (pk6.AltForm != 1)                          // Average
                        {
                            return(new LegalityCheck(Severity.Invalid, "Friend Safari: Not average sized."));
                        }
                        else if (pk6.Species == 586) // Sawsbuck
                        {
                            if (pk6.AltForm != 0)
                            {
                                return(new LegalityCheck(Severity.Invalid, "Friend Safari: Not Spring form."));
                            }
                        }
                    }
                }

                return(new LegalityCheck(Severity.Valid, "Valid friend safari encounter."));
            }

            if (Legal.getDexNavValid(pk6))
            {
                return(new LegalityCheck(Severity.Valid, "Valid (DexNav) encounter at location."));
            }
            if (Legal.getWildEncounterValid(pk6))
            {
                return(pk6.AbilityNumber != 4
                    ? new LegalityCheck(Severity.Valid, "Valid encounter at location.")
                    : new LegalityCheck(Severity.Invalid, "Hidden ability on valid encounter."));
            }
            EncounterTrade t = Legal.getIngameTrade(pk6);

            if (t != null)
            {
                EncounterMatch = t; // Check in individual methods
                return(new LegalityCheck(Severity.Valid, "Valid ingame trade."));
            }
            return(new LegalityCheck(Severity.Invalid, "Not a valid encounter."));
        }
Esempio n. 6
0
        private LegalityCheck[] verifyMoves()
        {
            int[]           Moves = pk6.Moves;
            LegalityCheck[] res   = new LegalityCheck[4];
            for (int i = 0; i < 4; i++)
            {
                res[i] = new LegalityCheck();
            }
            if (!pk6.Gen6)
            {
                return(res);
            }

            var validMoves = Legal.getValidMoves(pk6).ToArray();

            if (pk6.Species == 235)
            {
                for (int i = 0; i < 4; i++)
                {
                    res[i] = Legal.InvalidSketch.Contains(Moves[i])
                        ? new LegalityCheck(Severity.Invalid, "Invalid Sketch move.")
                        : new LegalityCheck();
                }
            }
            else if (CardMatch?.Count > 1) // Multiple possible WC6 matched
            {
                int[] RelearnMoves = pk6.RelearnMoves;
                foreach (var wc in CardMatch)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        if (Moves[i] == Legal.Struggle)
                        {
                            res[i] = new LegalityCheck(Severity.Invalid, "Invalid Move: Struggle.");
                        }
                        else if (validMoves.Contains(Moves[i]))
                        {
                            res[i] = new LegalityCheck(Severity.Valid, Moves[i] == 0 ? "Empty" : "Level-up.");
                        }
                        else if (RelearnMoves.Contains(Moves[i]))
                        {
                            res[i] = new LegalityCheck(Severity.Valid, Moves[i] == 0 ? "Empty" : "Relearn Move.")
                            {
                                Flag = true
                            }
                        }
                        ;
                        else if (wc.Moves.Contains(Moves[i]))
                        {
                            res[i] = new LegalityCheck(Severity.Valid, "Wonder Card Non-Relearn Move.");
                        }
                        else
                        {
                            res[i] = new LegalityCheck(Severity.Invalid, "Invalid Move.");
                        }
                    }
                    if (res.All(r => r.Valid)) // Card matched
                    {
                        EncounterMatch = wc; RelearnBase = wc.RelearnMoves;
                    }
                }
            }
            else
            {
                int[] RelearnMoves = pk6.RelearnMoves;
                WC6   MatchedWC6   = EncounterMatch as WC6;
                int[] WC6Moves     = MatchedWC6?.Moves ?? new int[0];
                for (int i = 0; i < 4; i++)
                {
                    if (Moves[i] == Legal.Struggle)
                    {
                        res[i] = new LegalityCheck(Severity.Invalid, "Invalid Move: Struggle.");
                    }
                    else if (validMoves.Contains(Moves[i]))
                    {
                        res[i] = new LegalityCheck(Severity.Valid, Moves[i] == 0 ? "Empty" : "Level-up.");
                    }
                    else if (RelearnMoves.Contains(Moves[i]))
                    {
                        res[i] = new LegalityCheck(Severity.Valid, Moves[i] == 0 ? "Empty" : "Relearn Move.")
                        {
                            Flag = true
                        }
                    }
                    ;
                    else if (WC6Moves.Contains(Moves[i]))
                    {
                        res[i] = new LegalityCheck(Severity.Valid, "Wonder Card Non-Relearn Move.");
                    }
                    else
                    {
                        res[i] = new LegalityCheck(Severity.Invalid, "Invalid Move.");
                    }
                }
            }
            if (Moves[0] == 0)
            {
                res[0] = new LegalityCheck(Severity.Invalid, "Invalid Move.");
            }


            if (pk6.Species == 647) // Keldeo
            {
                if (pk6.AltForm == 1 ^ pk6.Moves.Contains(548))
                {
                    res[0] = new LegalityCheck(Severity.Invalid, "Secret Sword / Resolute Keldeo Mismatch.");
                }
            }

            // Duplicate Moves Check
            for (int i = 0; i < 4; i++)
            {
                if (Moves.Count(m => m != 0 && m == Moves[i]) > 1)
                {
                    res[i] = new LegalityCheck(Severity.Invalid, "Duplicate Move.");
                }
            }

            return(res);
        }
Esempio n. 7
0
        private LegalityCheck verifyNickname()
        {
            // If the Pokémon is not nicknamed, it should match one of the language strings.
            if (pk6.Nickname.Length == 0)
            {
                return(new LegalityCheck(Severity.Indeterminate, "Nickname is empty."));
            }
            if (pk6.Species > PKX.SpeciesLang[0].Length)
            {
                return(new LegalityCheck(Severity.Indeterminate, "Species index invalid for Nickname comparison."));
            }
            if (!Encounter.Valid)
            {
                return(new LegalityCheck(Severity.Valid, "Skipped Nickname check due to other check being invalid."));
            }

            if (pk6.Language > 8)
            {
                return(new LegalityCheck(Severity.Indeterminate, "Language ID > 8."));
            }

            if (EncounterType == typeof(EncounterTrade))
            {
                string[] validOT = new string[0];
                int      index   = -1;
                if (pk6.XY)
                {
                    validOT = Legal.TradeXY[pk6.Language];
                    index   = Array.IndexOf(Legal.TradeGift_XY, EncounterMatch);
                }
                else if (pk6.AO)
                {
                    validOT = Legal.TradeAO[pk6.Language];
                    index   = Array.IndexOf(Legal.TradeGift_AO, EncounterMatch);
                }
                if (validOT.Length == 0)
                {
                    return(new LegalityCheck(Severity.Indeterminate, "Ingame Trade invalid version?"));
                }
                if (index == -1 || validOT.Length < index * 2)
                {
                    return(new LegalityCheck(Severity.Indeterminate, "Ingame Trade invalid lookup?"));
                }

                string nick = validOT[index];
                string OT   = validOT[validOT.Length / 2 + index];

                if (nick != pk6.Nickname)
                {
                    return(new LegalityCheck(Severity.Fishy, "Ingame Trade nickname has been altered."));
                }
                if (OT != pk6.OT_Name)
                {
                    return(new LegalityCheck(Severity.Invalid, "Ingame Trade OT has been altered."));
                }

                return(new LegalityCheck(Severity.Valid, "Ingame Trade OT/Nickname have not been altered."));
            }

            if (pk6.IsEgg)
            {
                if (!pk6.IsNicknamed)
                {
                    return(new LegalityCheck(Severity.Invalid, "Eggs must be nicknamed."));
                }
                return(PKX.SpeciesLang[pk6.Language][0] == pk6.Nickname
                    ? new LegalityCheck(Severity.Valid, "Egg matches language Egg name.")
                    : new LegalityCheck(Severity.Invalid, "Egg name does not match language Egg name."));
            }
            string nickname = pk6.Nickname.Replace("'", "’");

            if (pk6.IsNicknamed)
            {
                for (int i = 0; i < PKX.SpeciesLang.Length; i++)
                {
                    string[] lang  = PKX.SpeciesLang[i];
                    int      index = Array.IndexOf(lang, nickname);
                    if (index < 0)
                    {
                        continue;
                    }

                    return(index == pk6.Species && i != pk6.Language
                        ? new LegalityCheck(Severity.Fishy, "Nickname matches another species name (+language).")
                        : new LegalityCheck(Severity.Fishy, "Nickname flagged, matches species name."));
                }
                return(new LegalityCheck(Severity.Valid, "Nickname does not match another species name."));
            }
            // else
            {
                // Can't have another language name if it hasn't evolved.
                return(Legal.getHasEvolved(pk6) && PKX.SpeciesLang.Any(lang => lang[pk6.Species] == nickname) ||
                       PKX.SpeciesLang[pk6.Language][pk6.Species] == nickname
                    ? new LegalityCheck(Severity.Valid, "Nickname matches species name.")
                    : new LegalityCheck(Severity.Invalid, "Nickname does not match species name."));
            }
        }
Esempio n. 8
0
        private LegalityCheck verifyHandlerMemories()
        {
            if (!Encounter.Valid)
            {
                return(new LegalityCheck(Severity.Valid, "Skipped Memory check due to other check being invalid."));
            }

            WC6 MatchedWC6 = EncounterMatch as WC6;

            if (MatchedWC6?.OT.Length > 0) // Has Event OT -- null propagation yields false if MatchedWC6=null
            {
                if (pk6.OT_Friendship != PKX.getBaseFriendship(pk6.Species))
                {
                    return(new LegalityCheck(Severity.Invalid, "Event OT Friendship does not match base friendship."));
                }
                if (pk6.OT_Affection != 0)
                {
                    return(new LegalityCheck(Severity.Invalid, "Event OT Affection should be zero."));
                }
                if (pk6.CurrentHandler != 1)
                {
                    return(new LegalityCheck(Severity.Invalid, "Current handler should not be Event OT."));
                }
            }
            if (!pk6.WasEvent && (pk6.HT_Name.Length == 0 || pk6.Geo1_Country == 0)) // Is not Traded
            {
                if (pk6.HT_Name.Length != 0)
                {
                    return(new LegalityCheck(Severity.Invalid, "GeoLocation -- HT Name present but has no previous Country."));
                }
                if (pk6.Geo1_Country != 0)
                {
                    return(new LegalityCheck(Severity.Invalid, "GeoLocation -- Previous country of residence but no Handling Trainer."));
                }
                if (pk6.HT_Memory != 0)
                {
                    return(new LegalityCheck(Severity.Invalid, "Memory -- Handling Trainer memory present but no Handling Trainer."));
                }
                if (pk6.CurrentHandler != 0) // Badly edited; PKHeX doesn't trip this.
                {
                    return(new LegalityCheck(Severity.Invalid, "Untraded -- Current handler should not be the Handling Trainer."));
                }
                if (pk6.HT_Friendship != 0)
                {
                    return(new LegalityCheck(Severity.Invalid, "Untraded -- Handling Trainer Friendship should be zero."));
                }
                if (pk6.HT_Affection != 0)
                {
                    return(new LegalityCheck(Severity.Invalid, "Untraded -- Handling Trainer Affection should be zero."));
                }
                if (pk6.XY && pk6.CNTs.Any(stat => stat > 0))
                {
                    return(new LegalityCheck(Severity.Invalid, "Untraded -- Contest stats on XY should be zero."));
                }

                // We know it is untraded (HT is empty), if it must be trade evolved flag it.
                if (Legal.getHasTradeEvolved(pk6))
                {
                    if (pk6.Species != 350) // Milotic
                    {
                        return(new LegalityCheck(Severity.Invalid, "Untraded -- requires a trade evolution."));
                    }
                    if (pk6.CNT_Beauty < 170) // Beauty Contest Stat Requirement
                    {
                        return(new LegalityCheck(Severity.Invalid, "Untraded -- Beauty is not high enough for Levelup Evolution."));
                    }
                }
            }
            else // Is Traded
            {
                if (pk6.HT_Memory == 0)
                {
                    return(new LegalityCheck(Severity.Invalid, "Memory -- missing Handling Trainer Memory."));
                }
            }

            // Memory Checks
            if (pk6.IsEgg)
            {
                if (pk6.HT_Memory != 0)
                {
                    return(new LegalityCheck(Severity.Invalid, "Memory -- has Handling Trainer Memory."));
                }
                if (pk6.OT_Memory != 0)
                {
                    return(new LegalityCheck(Severity.Invalid, "Memory -- has Original Trainer Memory."));
                }
            }
            else if (EncounterType != typeof(WC6))
            {
                if (pk6.OT_Memory == 0 ^ !pk6.Gen6)
                {
                    return(new LegalityCheck(Severity.Invalid, "Memory -- missing Original Trainer Memory."));
                }
                if (!pk6.Gen6 && pk6.OT_Affection != 0)
                {
                    return(new LegalityCheck(Severity.Invalid, "OT Affection should be zero."));
                }
            }
            // Unimplemented: Ingame Trade Memories

            return(new LegalityCheck(Severity.Valid, "History is valid."));
        }
Esempio n. 9
0
        private LegalityCheck verifyBall()
        {
            if (!pk6.Gen6)
            {
                return(new LegalityCheck());
            }
            if (!Encounter.Valid)
            {
                return(new LegalityCheck(Severity.Valid, "Skipped Ball check due to other check being invalid."));
            }

            if (EncounterType == typeof(WC6))
            {
                return(pk6.Ball != ((WC6)EncounterMatch).Pokéball
                    ? new LegalityCheck(Severity.Invalid, "Ball does not match specified Wonder Card Ball.")
                    : new LegalityCheck(Severity.Valid, "Ball matches Wonder Card."));
            }
            if (EncounterType == typeof(EncounterLink))
            {
                return(((EncounterLink)EncounterMatch).Ball != pk6.Ball
                    ? new LegalityCheck(Severity.Invalid, "Incorrect ball on Link gift.")
                    : new LegalityCheck(Severity.Valid, "Correct ball on Link gift."));
            }
            if (EncounterType == typeof(EncounterTrade))
            {
                return(pk6.Ball != 4 // Pokeball
                    ? new LegalityCheck(Severity.Invalid, "Incorrect ball on ingame trade encounter.")
                    : new LegalityCheck(Severity.Valid, "Correct ball on ingame trade encounter."));
            }

            if (pk6.Ball == 0x04) // Poké Ball
            {
                return(new LegalityCheck(Severity.Valid, "Standard Poké Ball."));
            }

            if (EncounterType == typeof(EncounterStatic))
            {
                return(!Legal.WildPokeballs.Contains(pk6.Ball)
                    ? new LegalityCheck(Severity.Invalid, "Incorrect ball on ingame static encounter.")
                    : new LegalityCheck(Severity.Valid, "Correct ball on ingame static encounter."));
            }
            if (EncounterType == typeof(EncounterSlot[]))
            {
                return(!Legal.WildPokeballs.Contains(pk6.Ball)
                    ? new LegalityCheck(Severity.Invalid, "Incorrect ball on ingame encounter.")
                    : new LegalityCheck(Severity.Valid, "Correct ball on ingame encounter."));
            }

            if (pk6.WasEgg)
            {
                if (pk6.Ball == 0x01) // Master Ball
                {
                    return(new LegalityCheck(Severity.Invalid, "Master Ball on egg origin."));
                }
                if (pk6.Ball == 0x10) // Cherish Ball
                {
                    return(new LegalityCheck(Severity.Invalid, "Cherish Ball on non-event."));
                }

                if (pk6.Gender == 2)        // Genderless
                {
                    return(pk6.Ball != 0x04 // Must be Pokéball as ball can only pass via mother (not Ditto!)
                        ? new LegalityCheck(Severity.Invalid, "Non-Pokéball on genderless egg.")
                        : new LegalityCheck(Severity.Valid, "Pokéball on genderless egg."));
                }
                if (Legal.BreedMaleOnly.Contains(pk6.Species))
                {
                    return(pk6.Ball != 0x04 // Must be Pokéball as ball can only pass via mother (not Ditto!)
                        ? new LegalityCheck(Severity.Invalid, "Non-Pokéball on Male-Only egg.")
                        : new LegalityCheck(Severity.Valid, "Pokéball on Male-Only egg."));
                }

                if (pk6.Ball == 0x05) // Safari Ball
                {
                    if (Legal.getLineage(pk6).All(e => !Legal.Inherit_Safari.Contains(e)))
                    {
                        return(new LegalityCheck(Severity.Invalid, "Safari Ball not possible for species."));
                    }
                    if (pk6.AbilityNumber == 4)
                    {
                        return(new LegalityCheck(Severity.Invalid, "Safari Ball with Hidden Ability."));
                    }

                    return(new LegalityCheck(Severity.Valid, "Safari Ball possible for species."));
                }
                if (0x10 < pk6.Ball && pk6.Ball < 0x18) // Apricorn Ball
                {
                    if (Legal.getLineage(pk6).All(e => !Legal.Inherit_Apricorn.Contains(e)))
                    {
                        return(new LegalityCheck(Severity.Invalid, "Apricorn Ball not possible for species."));
                    }
                    if (pk6.AbilityNumber == 4)
                    {
                        return(new LegalityCheck(Severity.Invalid, "Apricorn Ball with Hidden Ability."));
                    }

                    return(new LegalityCheck(Severity.Valid, "Apricorn Ball possible for species."));
                }
                if (pk6.Ball == 0x18) // Sport Ball
                {
                    if (Legal.getLineage(pk6).All(e => !Legal.Inherit_Sport.Contains(e)))
                    {
                        return(new LegalityCheck(Severity.Invalid, "Sport Ball not possible for species."));
                    }
                    if (pk6.AbilityNumber == 4)
                    {
                        return(new LegalityCheck(Severity.Invalid, "Sport Ball with Hidden Ability."));
                    }

                    return(new LegalityCheck(Severity.Valid, "Sport Ball possible for species."));
                }
                if (pk6.Ball == 0x19) // Dream Ball
                {
                    if (Legal.getLineage(pk6).All(e => !Legal.Inherit_Dream.Contains(e)))
                    {
                        return(new LegalityCheck(Severity.Invalid, "Dream Ball not possible for species."));
                    }

                    return(new LegalityCheck(Severity.Valid, "Dream Ball possible for species."));
                }

                if (pk6.Species > 650 && pk6.Species != 700) // Sylveon
                {
                    return(!Legal.WildPokeballs.Contains(pk6.Ball)
                        ? new LegalityCheck(Severity.Invalid, "Unobtainable ball for Kalos origin.")
                        : new LegalityCheck(Severity.Valid, "Obtainable ball for Kalos origin."));
                }

                if (0x0D <= pk6.Ball && pk6.Ball <= 0x0F)
                {
                    if (Legal.Ban_Gen4Ball.Contains(pk6.Species))
                    {
                        return(new LegalityCheck(Severity.Invalid, "Unobtainable capture for Gen4 Ball."));
                    }

                    return(new LegalityCheck(Severity.Valid, "Obtainable capture for Gen4 Ball."));
                }
                if (0x02 <= pk6.Ball && pk6.Ball <= 0x0C) // Don't worry, Ball # 0x05 was already checked.
                {
                    if (Legal.Ban_Gen3Ball.Contains(pk6.Species))
                    {
                        return(new LegalityCheck(Severity.Invalid, "Unobtainable capture for Gen4 Ball."));
                    }

                    return(new LegalityCheck(Severity.Valid, "Obtainable capture for Gen4 Ball."));
                }
            }

            return(new LegalityCheck(Severity.Invalid, "No ball check satisfied, assuming illegal."));
        }
Esempio n. 10
0
        private LegalityCheck verifyEncounter()
        {
            if (!pk6.Gen6)
            {
                return new LegalityCheck {
                           Judgement = Severity.NotImplemented
                }
            }
            ;

            if (pk6.WasLink)
            {
                // Should NOT be Fateful, and should be in Database
                EncounterLink enc = EncounterMatch as EncounterLink;

                if (enc == null)
                {
                    return(new LegalityCheck(Severity.Invalid, "Not a valid Link gift -- unable to find matching gift."));
                }

                if (pk6.XY && !enc.XY)
                {
                    return(new LegalityCheck(Severity.Invalid, "Not a valid Link gift -- can't obtain in XY."));
                }
                if (pk6.AO && !enc.ORAS)
                {
                    return(new LegalityCheck(Severity.Invalid, "Not a valid Link gift -- can't obtain in ORAS."));
                }

                if (enc.Shiny != null && (bool)enc.Shiny ^ pk6.IsShiny)
                {
                    return(new LegalityCheck(Severity.Invalid, "Shiny Link gift mismatch."));
                }

                return(pk6.FatefulEncounter
                    ? new LegalityCheck(Severity.Invalid, "Not a valid Link gift -- should not be Fateful Encounter.")
                    : new LegalityCheck(Severity.Valid, "Valid Link gift."));
            }
            if (pk6.WasEvent || pk6.WasEventEgg)
            {
                WC6 MatchedWC6 = EncounterMatch as WC6;
                return(MatchedWC6 != null // Matched in RelearnMoves check.
                    ? new LegalityCheck(Severity.Valid, $"Matches #{MatchedWC6.CardID.ToString("0000")} ({MatchedWC6.CardTitle})")
                    : new LegalityCheck(Severity.Invalid, "Not a valid Wonder Card gift."));
            }

            EncounterMatch = null; // Reset object
            if (pk6.WasEgg)
            {
                // Check Hatch Locations
                if (pk6.Met_Level != 1)
                {
                    return(new LegalityCheck(Severity.Invalid, "Invalid met level, expected 1."));
                }
                // Check species
                if (Legal.NoHatchFromEgg.Contains(pk6.Species))
                {
                    return(new LegalityCheck(Severity.Invalid, "Species cannot be hatched from an egg."));
                }
                if (pk6.IsEgg)
                {
                    if (pk6.Egg_Location == 30002)
                    {
                        return(new LegalityCheck(Severity.Invalid, "Egg location shouldn't be 'traded' for an un-hatched egg."));
                    }

                    if (pk6.Met_Location == 30002)
                    {
                        return(new LegalityCheck(Severity.Valid, "Valid traded un-hatched egg."));
                    }
                    return(pk6.Met_Location == 0
                        ? new LegalityCheck(Severity.Valid, "Valid un-hatched egg.")
                        : new LegalityCheck(Severity.Invalid, "Invalid location for un-hatched egg (expected no met location)."));
                }
                if (pk6.XY)
                {
                    return(Legal.ValidMet_XY.Contains(pk6.Met_Location)
                        ? new LegalityCheck(Severity.Valid, "Valid X/Y hatched egg.")
                        : new LegalityCheck(Severity.Invalid, "Invalid X/Y location for hatched egg."));
                }
                if (pk6.AO)
                {
                    return(Legal.ValidMet_AO.Contains(pk6.Met_Location)
                        ? new LegalityCheck(Severity.Valid, "Valid OR/AS hatched egg.")
                        : new LegalityCheck(Severity.Invalid, "Invalid OR/AS location for hatched egg."));
                }
                return(new LegalityCheck(Severity.Invalid, "Invalid location for hatched egg."));
            }

            EncounterMatch = Legal.getValidStaticEncounter(pk6);
            if (EncounterMatch != null)
            {
                return(new LegalityCheck(Severity.Valid, "Valid gift/static encounter."));
            }

            if (Legal.getIsFossil(pk6))
            {
                return(pk6.AbilityNumber != 4
                    ? new LegalityCheck(Severity.Valid, "Valid revived fossil.")
                    : new LegalityCheck(Severity.Invalid, "Hidden ability on revived fossil."));
            }
            EncounterMatch = Legal.getValidFriendSafari(pk6);
            if (EncounterMatch != null)
            {
                if (pk6.Species == 670 || pk6.Species == 671) // Floette
                {
                    if (pk6.AltForm % 2 != 0)                 // 0/2/4
                    {
                        return(new LegalityCheck(Severity.Invalid, "Friend Safari: Not valid color."));
                    }
                    else if (pk6.Species == 710 || pk6.Species == 711) // Pumpkaboo
                    {
                        if (pk6.AltForm != 1)                          // Average
                        {
                            return(new LegalityCheck(Severity.Invalid, "Friend Safari: Not average sized."));
                        }
                        else if (pk6.Species == 586) // Sawsbuck
                        {
                            if (pk6.AltForm != 0)
                            {
                                return(new LegalityCheck(Severity.Invalid, "Friend Safari: Not Spring form."));
                            }
                        }
                    }
                }

                return(new LegalityCheck(Severity.Valid, "Valid friend safari encounter."));
            }

            EncounterMatch = Legal.getValidWildEncounters(pk6);
            if (EncounterMatch != null)
            {
                return(((EncounterSlot[])EncounterMatch).Any(slot => !slot.DexNav)
                    ? new LegalityCheck(Severity.Valid, "Valid encounter at location.")
                    : new LegalityCheck(Severity.Valid, "Valid DexNav encounter at location."));
            }
            EncounterMatch = Legal.getValidIngameTrade(pk6);
            if (EncounterMatch != null)
            {
                return(new LegalityCheck(Severity.Valid, "Valid ingame trade."));
            }
            return(new LegalityCheck(Severity.Invalid, "Not a valid encounter."));
        }