示例#1
0
文件: Checks.cs 项目: goofwear/PKHeX
        private CheckResult[] verifyMoves()
        {
            int[] Moves = pkm.Moves;
            CheckResult[] res = new CheckResult[4];
            for (int i = 0; i < 4; i++)
                res[i] = new CheckResult(CheckIdentifier.Move);
            if (!pkm.Gen6)
                return res;

            var validMoves = Legal.getValidMoves(pkm).ToArray();
            if (pkm.Species == 235) // Smeargle
            {
                for (int i = 0; i < 4; i++)
                    res[i] = Legal.InvalidSketch.Contains(Moves[i])
                        ? new CheckResult(Severity.Invalid, "Invalid Sketch move.", CheckIdentifier.Move)
                        : new CheckResult(CheckIdentifier.Move);
            }
            else if (EventGiftMatch?.Count > 1) // Multiple possible Mystery Gifts matched
            {
                int[] RelearnMoves = pkm.RelearnMoves;
                foreach (MysteryGift mg in EventGiftMatch)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        if (Moves[i] == Legal.Struggle)
                            res[i] = new CheckResult(Severity.Invalid, "Invalid Move: Struggle.", CheckIdentifier.Move);
                        else if (validMoves.Contains(Moves[i]))
                            res[i] = new CheckResult(Severity.Valid, Moves[i] == 0 ? "Empty" : "Level-up.", CheckIdentifier.Move);
                        else if (RelearnMoves.Contains(Moves[i]))
                            res[i] = new CheckResult(Severity.Valid, Moves[i] == 0 ? "Empty" : "Relearn Move.", CheckIdentifier.Move) { Flag = true };
                        else if (mg.Moves.Contains(Moves[i]))
                            res[i] = new CheckResult(Severity.Valid, "Wonder Card Non-Relearn Move.", CheckIdentifier.Move);
                        else
                            res[i] = new CheckResult(Severity.Invalid, "Invalid Move.", CheckIdentifier.Move);
                    }
                    if (res.Any(r => !r.Valid))
                        continue;

                    EncounterMatch = mg;
                    RelearnBase = mg.RelearnMoves;
                    break;
                }
            }
            else
            {
                int[] RelearnMoves = pkm.RelearnMoves;
                MysteryGift MatchedGift = EncounterMatch as MysteryGift;
                int[] GiftMoves = MatchedGift?.Moves ?? new int[0];
                for (int i = 0; i < 4; i++)
                {
                    if (Moves[i] == Legal.Struggle)
                        res[i] = new CheckResult(Severity.Invalid, "Invalid Move: Struggle.", CheckIdentifier.Move);
                    else if (validMoves.Contains(Moves[i]))
                        res[i] = new CheckResult(Severity.Valid, Moves[i] == 0 ? "Empty" : "Level-up.", CheckIdentifier.Move);
                    else if (RelearnMoves.Contains(Moves[i]))
                        res[i] = new CheckResult(Severity.Valid, Moves[i] == 0 ? "Empty" : "Relearn Move.", CheckIdentifier.Move) { Flag = true };
                    else if (GiftMoves.Contains(Moves[i]))
                        res[i] = new CheckResult(Severity.Valid, "Wonder Card Non-Relearn Move.", CheckIdentifier.Move);
                    else
                        res[i] = new CheckResult(Severity.Invalid, "Invalid Move.", CheckIdentifier.Move);
                }
            }
            if (Moves[0] == 0) // None
                res[0] = new CheckResult(Severity.Invalid, "Invalid Move.", CheckIdentifier.Move);

            if (pkm.Species == 647) // Keldeo
                if (pkm.AltForm == 1 ^ pkm.Moves.Contains(548))
                    res[Math.Max(Array.IndexOf(pkm.Moves, 548), 0)] = new CheckResult(Severity.Invalid, "Secret Sword / Resolute Keldeo Mismatch.", CheckIdentifier.Move);

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

            return res;
        }
示例#2
0
文件: Checks.cs 项目: goofwear/PKHeX
        private CheckResult[] verifyRelearn()
        {
            RelearnBase = null;
            CheckResult[] res = new CheckResult[4];

            int[] Moves = pkm.RelearnMoves;
            if (pkm.GenNumber < 6)
                goto noRelearn;

            if (pkm.WasLink)
            {
                var Link = Legal.getValidLinkGifts(pkm);
                if (Link == null)
                {
                    for (int i = 0; i < 4; i++)
                        res[i] = new CheckResult(CheckIdentifier.RelearnMove);
                    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 CheckResult(Severity.Invalid, $"Expected: {movelist[moves[i]]}.", CheckIdentifier.RelearnMove)
                        : new CheckResult(CheckIdentifier.RelearnMove);
                return res;
            }
            if (pkm.WasEvent || pkm.WasEventEgg)
            {
                // Get WC6's that match
                EventGiftMatch = new List<MysteryGift>(Legal.getValidGifts(pkm));
                foreach (MysteryGift mg in EventGiftMatch.ToArray())
                {
                    int[] moves = mg.RelearnMoves;
                    for (int i = 0; i < 4; i++)
                        res[i] = moves[i] != Moves[i]
                            ? new CheckResult(Severity.Invalid, $"Expected ID: {movelist[moves[i]]}.", CheckIdentifier.RelearnMove)
                            : new CheckResult(Severity.Valid, $"Matched {mg.CardID}", CheckIdentifier.RelearnMove);
                    if (res.Any(r => !r.Valid))
                        EventGiftMatch.Remove(mg);
                }
                if (EventGiftMatch.Count > 1)
                    return res;
                if (EventGiftMatch.Count == 1)
                { EncounterMatch = EventGiftMatch[0]; RelearnBase = EventGiftMatch[0].RelearnMoves; return res; }

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

            if (pkm.WasEgg && !Legal.NoHatchFromEgg.Contains(pkm.Species))
            {
                int games = 1;
                GameVersion[] Games = { GameVersion.XY };
                switch (pkm.GenNumber)
                {
                    case 6:
                        games = 2;
                        Games = new[] {GameVersion.XY, GameVersion.ORAS};
                        break;
                    case 7:
                        games = 1;
                        Games = new[] {GameVersion.SM};
                        break;
                }

                bool checkAllGames = pkm.WasTradedEgg;
                bool splitBreed = Legal.SplitBreed.Contains(pkm.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;
                    GameVersion ver = gameSource == -1 ? GameVersion.Any : Games[gameSource];

                    // Obtain level1 moves
                    List<int> baseMoves = new List<int>(Legal.getBaseEggMoves(pkm, skipOption, ver));
                    int baseCt = baseMoves.Count;
                    if (baseCt > 4) baseCt = 4;

                    // Obtain Nonstandard moves
                    var relearnMoves = Legal.getValidRelearn(pkm, skipOption).ToArray();
                    var relearn = pkm.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 = pkm.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 CheckResult(Severity.Valid, "Base egg move.", CheckIdentifier.RelearnMove);
                        else
                        {
                            res[j] = new CheckResult(Severity.Invalid, "Base egg move missing.", CheckIdentifier.RelearnMove);
                            for (int f = j+1; f < req; f++)
                                res[f] = new CheckResult(Severity.Invalid, "Base egg move missing.", CheckIdentifier.RelearnMove);
                            res[req-1].Comment += $"{Environment.NewLine}Expected the following Relearn Moves: {em}.";
                            break;
                        }
                    }

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

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

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

                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 CheckResult(Severity.Invalid, "Expected no Relearn Moves.", CheckIdentifier.RelearnMove)
                    : new CheckResult(CheckIdentifier.RelearnMove);
            return res;
        }