Esempio n. 1
0
    private static int[] GetSuggestedMoves(PKM pk, EvolutionHistory evoChains, MoveSourceType types, IEncounterTemplate enc)
    {
        if (pk.IsEgg && pk.Format <= 5) // pre relearn
        {
            return(MoveList.GetBaseEggMoves(pk, pk.Species, 0, (GameVersion)pk.Version, pk.CurrentLevel));
        }

        if (types != MoveSourceType.None)
        {
            return(GetValidMoves(pk, evoChains, types).Skip(1).ToArray()); // skip move 0
        }
        // try to give current moves
        if (enc.Generation <= 2)
        {
            var lvl = pk.Format >= 7 ? pk.Met_Level : pk.CurrentLevel;
            var ver = enc.Version;
            return(MoveLevelUp.GetEncounterMoves(enc.Species, 0, lvl, ver));
        }

        if (pk.Species == enc.Species)
        {
            return(MoveLevelUp.GetEncounterMoves(pk.Species, pk.Form, pk.CurrentLevel, (GameVersion)pk.Version));
        }

        return(GetValidMoves(pk, evoChains, types).Skip(1).ToArray()); // skip move 0
    }
Esempio n. 2
0
    private static IEnumerable <int> GetValidMoves(PKM pk, GameVersion version, EvolutionHistory evoChains, MoveSourceType types = MoveSourceType.Reminder, bool RemoveTransferHM = true)
    {
        var r = new List <int> {
            0
        };

        if (types.HasFlagFast(MoveSourceType.RelearnMoves) && pk.Format >= 6)
        {
            r.AddRange(pk.RelearnMoves);
        }

        int start = pk.Generation;

        if (start < 0)
        {
            start = pk.Format; // be generous instead of returning nothing
        }
        if (pk is IBattleVersion b)
        {
            start = Math.Max(0, b.GetMinGeneration());
        }

        for (int generation = start; generation <= pk.Format; generation++)
        {
            var chain = evoChains[generation];
            if (chain.Length == 0)
            {
                continue;
            }
            r.AddRange(MoveList.GetValidMoves(pk, version, chain, generation, types: types, RemoveTransferHM: RemoveTransferHM));
        }

        return(r.Distinct());
    }
Esempio n. 3
0
    public static void SetSuggestedContestStats(this PKM pk, IEncounterTemplate enc, EvolutionHistory h)
    {
        if (pk is not IContestStatsMutable s)
        {
            return;
        }

        var restrict = GetContestStatRestriction(pk, pk.Generation, h);
        var baseStat = GetReferenceTemplate(enc);

        if (restrict == None || pk.Species is not(int) Species.Milotic)
        {
            baseStat.CopyContestStatsTo(s); // reset
        }
    public ValidEncounterMoves(PKM pk, IEncounterTemplate encounter, EvolutionHistory chains)
    {
        var level = MoveList.GetValidMovesAllGens(pk, chains, types: MoveSourceType.Encounter, RemoveTransferHM: false);

        int gen = encounter.Generation;

        if ((uint)gen < level.Length && level[gen] is List <int> x)
        {
            AddEdgeCaseMoves(x, encounter, pk);
        }

        LevelUpMoves = level;
        TMHMMoves    = MoveList.GetValidMovesAllGens(pk, chains, types: MoveSourceType.AllMachines);
        TutorMoves   = MoveList.GetValidMovesAllGens(pk, chains, types: MoveSourceType.AllTutors);
    }
     public void CanGenerateSql()
     {
         var genome = new Genome();
         var evolutionHistory = new EvolutionHistory();
         var sql = WhenGenerateSql(genome, evolutionHistory);
         sql.Should().Contain(@"CREATE TABLE [Mathematicians].[dbo].[Mathematician](
 [MathematicianId] INT IDENTITY (1,1) NOT NULL,
 CONSTRAINT [PK_Mathematician] PRIMARY KEY CLUSTERED ([MathematicianId]),
 [Name] NVARCHAR(100) NOT NULL,
 [BirthYear] INT NOT NULL,
 [DeathYear] INT NULL)");
         sql.Should().Contain(@"CREATE TABLE [Mathematicians].[dbo].[Contribution](
 [ContributionId] INT IDENTITY (1,1) NOT NULL,
 CONSTRAINT [PK_Contribution] PRIMARY KEY CLUSTERED ([ContributionId]),
 [MathematicianId] INT NOT NULL,
 [Description] NVARCHAR(500) NOT NULL,
 INDEX [IX_Contribution_MathematicianId] NONCLUSTERED ([MathematicianId]),
 CONSTRAINT [FK_Contribution_MathematicianId] FOREIGN KEY ([MathematicianId])
     REFERENCES [Mathematicians].[dbo].[Mathematician] ([MathematicianId]))");
     }
Esempio n. 6
0
        private EvolutionHistory LoadEvolutionHistory()
        {
            var ids = ExecuteSqlQuery($"SELECT database_id FROM master.sys.databases WHERE name = '{_databaseName}'",
                                      row => (int)row["database_id"]);

            if (ids.Any())
            {
                string upgrade = $@"IF COL_LENGTH('[{_databaseName}].[dbo].[__EvolutionHistoryPrerequisite]', 'Ordinal') IS NULL
                    BEGIN
	                    ALTER TABLE [{_databaseName}].[dbo].[__EvolutionHistoryPrerequisite]
	                    ADD [Ordinal] INT NOT NULL
	                    CONSTRAINT [DF_EvolutionHistoryPrerequisite_Ordinal] DEFAULT (1)

	                    ALTER TABLE [{_databaseName}].[dbo].[__EvolutionHistoryPrerequisite]
                        DROP CONSTRAINT [DF_EvolutionHistoryPrerequisite_Ordinal]
                    END";
                ExecuteSqlCommand(upgrade);

                var rows = ExecuteSqlQuery($@"SELECT h.[Type], h.[HashCode], h.[Attributes], j.[Role], p.[HashCode] AS [PrerequisiteHashCode]
                        FROM [{_databaseName}].[dbo].[__EvolutionHistory] h
                        LEFT JOIN [{_databaseName}].[dbo].[__EvolutionHistoryPrerequisite] j
                          ON h.GeneId = j.GeneId
                        LEFT JOIN [{_databaseName}].[dbo].[__EvolutionHistory] p
                          ON j.PrerequisiteGeneId = p.GeneId
                        ORDER BY h.GeneId, j.Role, j.Ordinal, p.GeneId",
                                           row => new EvolutionHistoryRow
                {
                    Type                 = LoadString(row["Type"]),
                    HashCode             = LoadBigInteger(row["HashCode"]),
                    Attributes           = LoadString(row["Attributes"]),
                    Role                 = LoadString(row["Role"]),
                    PrerequisiteHashCode = LoadBigInteger(row["PrerequisiteHashCode"])
                });

                return(EvolutionHistory.LoadMementos(LoadMementos(rows)));
            }
            else
            {
                return(new EvolutionHistory());
            }
        }
Esempio n. 7
0
    private static bool CanHaveMemoryForOT(PKM pk, int origin, int memory, EvolutionHistory evos)
    {
        switch (origin)
        {
        // Bank Memories only: Gen7 does not set memories.
        case 1 or 2 or 7 when memory != 4:     // VC transfers

        // Memories don't exist
        case 7 when pk.GG:                                    // LGPE does not set memories.
        case 8 when pk.GO_HOME:                               // HOME does not set memories.
        case 8 when pk.Met_Location == Locations.HOME8:       // HOME does not set memories.
        case 8 when pk.BDSP && !pk.HasVisitedSWSH(evos.Gen8): // BDSP does not set memories.
        case 8 when pk.LA && !pk.HasVisitedSWSH(evos.Gen8):   // LA does not set memories.
            return(false);

        // Eggs cannot have memories
        // Cannot have memories if the OT was from a generation prior to Gen6.
        default:
            return(origin >= 6 && !pk.IsEgg);
        }
    }
Esempio n. 8
0
    private static List <string> GetIncorrectRibbons(PKM pk, EvolutionHistory evos, IEncounterTemplate enc)
    {
        List <string> missingRibbons = new();
        List <string> invalidRibbons = new();
        var           ribs           = GetRibbonResults(pk, evos, enc);

        foreach (var bad in ribs)
        {
            (bad.Invalid ? invalidRibbons : missingRibbons).Add(bad.Name);
        }

        var result = new List <string>();

        if (missingRibbons.Count > 0)
        {
            result.Add(string.Format(LRibbonFMissing_0, string.Join(", ", missingRibbons).Replace(RibbonInfo.PropertyPrefix, string.Empty)));
        }
        if (invalidRibbons.Count > 0)
        {
            result.Add(string.Format(LRibbonFInvalid_0, string.Join(", ", invalidRibbons).Replace(RibbonInfo.PropertyPrefix, string.Empty)));
        }
        return(result);
    }
Esempio n. 9
0
    private static EvolutionHistory GetChainAll(PKM pk, IEncounterTemplate enc, EvoCriteria[] fullChain)
    {
        int maxgen        = ParseSettings.AllowGen1Tradeback && pk.Context == EntityContext.Gen1 ? 2 : pk.Format;
        var GensEvoChains = new EvolutionHistory(fullChain, maxgen + 1);

        var head        = 0; // inlined FIFO queue indexing
        var mostEvolved = fullChain[head++];

        var lvl      = (byte)pk.CurrentLevel;
        var maxLevel = lvl;

        // Iterate generations backwards
        // Maximum level of an earlier generation (GenX) will never be greater than a later generation (GenX+Y).
        int mingen = enc.Generation;

        if (mingen is 1 or 2)
        {
            mingen = GBRestrictions.GetTradebackStatusInitial(pk) == PotentialGBOrigin.Gen2Only ? 2 : 1;
        }

        bool noxfrDecremented = true;

        for (int g = GensEvoChains.Length - 1; g >= mingen; g--)
        {
            if (g == 6 && enc.Generation < 3)
            {
                g = 2; // skip over 6543 as it never existed in these.
            }
            if (g <= 4 && pk.Format > 2 && pk.Format > g && !pk.HasOriginalMetLocation)
            {
                // Met location was lost at this point but it also means the pokemon existed in generations 1 to 4 with maximum level equals to met level
                var met = pk.Met_Level;
                if (lvl > pk.Met_Level)
                {
                    lvl = (byte)met;
                }
            }

            int maxspeciesgen = g == 2 && pk.VC1 ? MaxSpeciesID_1 : GetMaxSpeciesOrigin(g);

            // Remove future gen evolutions after a few special considerations:
            // If the pokemon origin is illegal (e.g. Gen3 Infernape) the list will be emptied -- species lineage did not exist at any evolution stage.
            while (mostEvolved.Species > maxspeciesgen)
            {
                if (head >= fullChain.Length)
                {
                    if (g <= 2 && pk.VC1)
                    {
                        GensEvoChains.Invalidate(); // invalidate here since we haven't reached the regular invalidation
                    }
                    return(GensEvoChains);
                }
                if (mostEvolved.RequiresLvlUp)
                {
                    ReviseMaxLevel(ref lvl, pk, g, maxLevel);
                }

                mostEvolved = fullChain[head++];
            }

            // Alolan form evolutions, remove from gens 1-6 chains
            if (g < 7 && HasAlolanForm(mostEvolved.Species) && pk.Format >= 7 && mostEvolved.Form > 0)
            {
                if (head >= fullChain.Length)
                {
                    return(GensEvoChains);
                }
                mostEvolved = fullChain[head++];
            }

            var tmp = GetEvolutionChain(pk, enc, mostEvolved.Species, lvl);
            if (tmp.Length == 0)
            {
                continue;
            }

            GensEvoChains[g] = tmp;
            if (g == 1)
            {
                CleanGen1(pk, enc, GensEvoChains);
                continue;
            }

            if (g >= 3 && !pk.HasOriginalMetLocation && g >= enc.Generation && noxfrDecremented)
            {
                bool isTransferred = HasMetLocationUpdatedTransfer(enc.Generation, g);
                if (!isTransferred)
                {
                    continue;
                }

                noxfrDecremented = g > (enc.Generation != 3 ? 4 : 5);

                // Remove previous evolutions below transfer level
                // For example a gen3 Charizard in format 7 with current level 36 and met level 36, thus could never be Charmander / Charmeleon in Gen5+.
                // chain level for Charmander is 35, is below met level.
                int minlvl = GetMinLevelGeneration(pk, g);

                ref var genChain = ref GensEvoChains[g];
                int     minIndex = Array.FindIndex(genChain, e => e.LevelMax >= minlvl);
                if (minIndex != -1)
                {
                    genChain = genChain.AsSpan(minIndex).ToArray();
                }
            }
        }
Esempio n. 10
0
 private static IEnumerable <int> GetValidMoves(PKM pk, EvolutionHistory evoChains, MoveSourceType types = MoveSourceType.ExternalSources, bool RemoveTransferHM = true)
 {
     var(_, version) = pk.IsMovesetRestricted();
     return(GetValidMoves(pk, version, evoChains, types: types, RemoveTransferHM: RemoveTransferHM));
 }
 private static string[] WhenGenerateRollbackSql(IGenome genome, EvolutionHistory evolutionHistory)
 {
     var sqlGenerator = new SqlGenerator(genome, evolutionHistory);
     return sqlGenerator.GenerateRollbackSql("Mathematicians");
 }
 private EvolutionHistory WhenLoadEvolutionHistory(GeneMemento[] mementos)
 {
     return EvolutionHistory.LoadMementos(mementos);
 }
Esempio n. 13
0
 public static bool IsBattleVersionValid <T>(this T pk, EvolutionHistory h) where T : PKM, IBattleVersion => pk.BattleVersion switch
 {
     0 => true,
     (int)GameVersion.SW or(int) GameVersion.SH => !(pk.SWSH || pk.BDSP || pk.LA) && pk.HasVisitedSWSH(h.Gen8),
Esempio n. 14
0
 public SqlGenerator(IGenome genome, EvolutionHistory evolutionHistory)
 {
     _genome           = genome;
     _evolutionHistory = evolutionHistory;
 }