Example #1
0
        internal static int GetRandomForme(int species, bool mega, bool alola, PersonalInfo[] stats = null)
        {
            if (stats == null)
            {
                return(0);
            }
            if (stats[species].FormeCount <= 1)
            {
                return(0);
            }

            if (species == 658 && !mega) // Greninja
            {
                return(0);
            }
            if (species == 664 || species == 665 || species == 666) // vivillon
            {
                return(30);                                         // save file specific
            }
            if (species == 774)                                     // minior
            {
                return(Util.Rand.Next(7));
            }

            if (alola && EvolveToAlolanForms.Contains(species))
            {
                return(Util.Rand.Next(2));
            }
            if (!BattleExclusiveForms.Contains(species) || mega)
            {
                return(Util.Rand.Next(stats[species].FormeCount)); // Slot-Random
            }
            return(0);
        }
Example #2
0
        public static int GetRandomForme(int species, bool mega, bool alola, bool galar, PersonalTable stats)
        {
            if (stats == null)
            {
                return(0);
            }
            if (stats[species].FormeCount <= 1)
            {
                return(0);
            }

            if (species == 658 && !mega) // Greninja
            {
                return(0);
            }
            if (species == 664 || species == 665 || species == 666) // vivillon
            {
                return(30);                                         // save file specific
            }
            if (species == 774)                                     // minior
            {
                return(Util.Rand.Next(7));
            }
            if (species == 890) // Eternatus
            {
                return(0);
            }

            if (galar && species == 052) // Galarian Meowth is altform 2
            {
                return(Util.Rand.Next(3));
            }
            if (galar && species == 079) // todo: remove when Kanto Slowpoke is made usable in SWSH
            {
                return(1);
            }
            if (galar && species == 555) // Galarian Darmanitan is altform 2, Galarian Zen is altform 3
            {
                return(Util.Rand.Next(4));
            }

            if (stats.TableLength == 980 && (species == 25 || species == 133)) // gg tableB -- no starters, they crash trainer battles.
            {
                return(0);                                                     // Pikachu
            }
            if (EvolveToAlolanForms.Contains(species))
            {
                return(alola ? Util.Rand.Next(2) : 0);
            }
            if (EvolveToGalarForms.Contains(species))
            {
                return(galar ? Util.Rand.Next(2) : 0);
            }
            if (!BattleExclusiveForms.Contains(species) || mega)
            {
                return(Util.Rand.Next(stats[species].FormeCount)); // Slot-Random
            }
            return(0);
        }
Example #3
0
        public static int GetRandomForme(int species, bool mega, bool alola, PersonalTable stats)
        {
            if (stats == null)
            {
                return(0);
            }
            if (stats[species].FormeCount <= 1)
            {
                return(0);
            }

            if (species == 658 && !mega) // Greninja
            {
                return(0);
            }
            if (species == 664 || species == 665 || species == 666) // vivillon
            {
                return(30);                                         // save file specific
            }
            if (species == 774)                                     // minior
            {
                return(Util.Rand.Next(7));
            }

            if (stats.TableLength == 980 && (species == 25 || species == 133)) // gg tableB -- no starters, they crash trainer battles.
            {
                return(0);                                                     // Pikachu
            }
            if (EvolveToAlolanForms.Contains(species))
            {
                return(alola ? Util.Rand.Next(2) : 0);
            }
            if (!BattleExclusiveForms.Contains(species) || mega)
            {
                return(Util.Rand.Next(stats[species].FormeCount)); // Slot-Random
            }
            return(0);
        }
Example #4
0
        private static List <EvoCriteria>[] GetChainAll(PKM pkm, IEncounterable Encounter, IEnumerable <EvoCriteria> CompleteEvoChain)
        {
            int maxgen        = pkm is PK1 && !pkm.Gen1_NotTradeback ? 2 : pkm.Format;
            var GensEvoChains = GetChainBase(maxgen);

            var queue       = new Queue <EvoCriteria>(CompleteEvoChain);
            var mostEvolved = queue.Dequeue();

            int lvl      = pkm.CurrentLevel;
            int maxLevel = lvl;
            int pkGen    = Encounter.Generation;

            // Iterate generations backwards
            // Maximum level of an earlier generation (GenX) will never be greater than a later generation (GenX+Y).
            int  mingen           = pkGen >= 3 ? pkGen : pkm.Gen2_NotTradeback ? 2 : 1;
            bool noxfrDecremented = true;

            for (int g = GensEvoChains.Length - 1; g >= mingen; g--)
            {
                if (pkGen <= 2)
                {
                    if (3 <= g && g <= 6)
                    {
                        continue;
                    }
                    if (g == 2 && pkm.Gen1_NotTradeback)
                    {
                        continue;
                    }
                }

                if (g <= 4 && pkm.Format > 2 && pkm.Format > g && !pkm.HasOriginalMetLocation && lvl > pkm.Met_Level)
                {
                    // 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
                    lvl = pkm.Met_Level;
                }

                int maxspeciesgen = g == 2 && pkm.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 (queue.Count == 0)
                    {
                        if (g <= 2 && pkm.VC1)
                        {
                            GensEvoChains[pkm.Format] = NONE; // invalidate here since we haven't reached the regular invalidation
                        }
                        return(GensEvoChains);
                    }
                    if (mostEvolved.RequiresLvlUp)
                    {
                        // This is a Gen3 pokemon in a Gen4 phase evolution that requires level up and then transferred to Gen5+
                        // We can deduce that it existed in Gen4 until met level,
                        // but if current level is met level we can also deduce it existed in Gen3 until maximum met level -1
                        if (g == 3 && pkm.Format > 4 && lvl == maxLevel)
                        {
                            lvl--;
                        }

                        // The same condition for Gen2 evolution of Gen1 pokemon, level of the pokemon in Gen1 games would be CurrentLevel -1 one level below Gen2 level
                        else if (g == 1 && pkm.Format == 2 && lvl == maxLevel)
                        {
                            lvl--;
                        }
                    }
                    mostEvolved = queue.Dequeue();
                }

                // Alolan form evolutions, remove from gens 1-6 chains
                if (EvolveToAlolanForms.Contains(mostEvolved.Species))
                {
                    if (g < 7 && pkm.Format >= 7 && mostEvolved.Form > 0)
                    {
                        if (queue.Count == 0)
                        {
                            break;
                        }
                        mostEvolved = queue.Dequeue();
                    }
                }

                GensEvoChains[g] = GetEvolutionChain(pkm, Encounter, mostEvolved.Species, lvl);
                if (GensEvoChains[g].Count == 0)
                {
                    continue;
                }

                if (g > 2 && !pkm.HasOriginalMetLocation && g >= pkGen && noxfrDecremented)
                {
                    bool isTransferred = HasMetLocationUpdatedTransfer(pkGen, g);
                    if (!isTransferred)
                    {
                        continue;
                    }

                    noxfrDecremented = g > (pkGen != 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(pkm, g);
                    GensEvoChains[g].RemoveAll(e => e.Level < minlvl);
                }
                else if (g == 2 && pkm.TradebackStatus == TradebackType.Gen1_NotTradeback)
                {
                    GensEvoChains[2] = NONE;
                }
                else if (g == 1)
                {
                    // Remove Gen2 post-evolutions (Scizor, Blissey...)
                    if (GensEvoChains[1][0].Species > MaxSpeciesID_1)
                    {
                        GensEvoChains[1].RemoveAt(0);
                    }

                    // Remove Gen2 pre-evolutions (Pichu, Cleffa...)
                    int lastIndex = GensEvoChains[1].Count - 1;
                    if (lastIndex >= 0 && GensEvoChains[1][lastIndex].Species > MaxSpeciesID_1)
                    {
                        GensEvoChains[1].RemoveAt(lastIndex);
                    }

                    // Remove Gen7 pre-evolutions and chain break scenarios
                    if (pkm.VC1)
                    {
                        TrimVC1Transfer(pkm, GensEvoChains);
                    }
                }
            }
            return(GensEvoChains);
        }
Example #5
0
        private static EvoCriteria[][] GetChainAll(PKM pkm, IEncounterable Encounter, IEnumerable <EvoCriteria> CompleteEvoChain)
        {
            int maxgen        = pkm is PK1 && !pkm.Gen1_NotTradeback ? 2 : pkm.Format;
            var GensEvoChains = GetChainBase(maxgen);

            var queue       = new Queue <EvoCriteria>(CompleteEvoChain);
            var mostEvolved = queue.Dequeue();

            int lvl      = pkm.CurrentLevel;
            int maxLevel = lvl;
            int pkGen    = pkm.GenNumber;

            // Iterate generations backwards
            // Maximum level of an earlier generation (GenX) will never be greater than a later generation (GenX+Y).
            int mingen = (pkm is PK2 || pkm.VC2) && !pkm.Gen2_NotTradeback ? 1 : pkGen;

            for (int g = GensEvoChains.Length - 1; g >= mingen; g--)
            {
                if (pkGen == 1 && pkm.Gen1_NotTradeback && g == 2)
                {
                    continue;
                }
                if (pkGen <= 2 && 3 <= g && g <= 6)
                {
                    continue;
                }

                if (g <= 4 && 2 < pkm.Format && g < pkm.Format && !pkm.HasOriginalMetLocation && lvl > pkm.Met_Level)
                {
                    // 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
                    lvl = pkm.Met_Level;
                }

                int maxspeciesgen = g == 2 && pkm.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 (queue.Count == 0)
                    {
                        return(GensEvoChains);
                    }
                    if (mostEvolved.RequiresLvlUp)
                    {
                        // Eevee requires a single levelup to be Sylveon, it can be deduced in gen 5 and before it existed with maximum one level below current
                        if (g == 5 && mostEvolved.Species == 700)
                        {
                            lvl--;
                        }

                        // This is a gen 3 pokemon in a gen 4 phase evolution that requieres level up and then transfered to gen 5+
                        // We can deduce that it existed in gen 4 until met level,
                        // but if current level is met level we can also deduce it existed in gen 3 until maximum met level -1
                        else if (g == 3 && pkm.Format > 4 && lvl == maxLevel)
                        {
                            lvl--;
                        }

                        // The same condition for gen2 evolution of gen 1 pokemon, level of the pokemon in gen 1 games would be CurrentLevel -1 one level below gen 2 level
                        else if (g == 1 && pkm.Format == 2 && lvl == maxLevel)
                        {
                            lvl--;
                        }
                    }
                    mostEvolved = queue.Dequeue();
                }

                // Alolan form evolutions, remove from gens 1-6 chains
                if (EvolveToAlolanForms.Contains(mostEvolved.Species))
                {
                    if (g < 7 && pkm.Format >= 7 && mostEvolved.Form > 0)
                    {
                        if (queue.Count == 0)
                        {
                            break;
                        }
                        mostEvolved = queue.Dequeue();
                    }
                }

                GensEvoChains[g] = GetEvolutionChain(pkm, Encounter, mostEvolved.Species, lvl);
                if (GensEvoChains[g].Length == 0)
                {
                    continue;
                }

                if (g > 2 && !pkm.HasOriginalMetLocation && g >= pkGen)
                {
                    bool isTransferred = GetCanPruneChainTransfer(pkm, pkGen, g);
                    if (isTransferred)
                    {
                        // 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(pkm, g);
                        GensEvoChains[g] = GensEvoChains[g].Where(e => e.Level >= minlvl).ToArray();
                    }
                }
                else if (g == 2 && pkm.TradebackStatus == TradebackType.Gen1_NotTradeback)
                {
                    GensEvoChains[2] = NONE;
                }
                else if (g == 1 && GensEvoChains[g][GensEvoChains[g].Length - 1].Species > MaxSpeciesID_1)
                {
                    // Remove generation 2 pre-evolutions
                    GensEvoChains[1] = GensEvoChains[1].Take(GensEvoChains[1].Length - 1).ToArray();
                    if (!pkm.VC1)
                    {
                        return(GensEvoChains);
                    }

                    // Remove generation 2 pre-evolutions from gen 7 and future generations
                    for (int fgen = 7; fgen < GensEvoChains.Length; fgen++)
                    {
                        var chain   = GensEvoChains[fgen];
                        var g1Index = Array.FindIndex(chain, e => e.Species <= MaxSpeciesID_1);
                        if (g1Index < 0) // no g2 species present
                        {
                            continue;
                        }
                        if (g1Index + 1 == chain.Length) // already pruned or no g2prevo
                        {
                            continue;
                        }
                        GensEvoChains[fgen] = chain.Take(g1Index + 1).ToArray();
                    }
                }
            }
            return(GensEvoChains);
        }
Example #6
0
        public static int GetRandomForme(int species, bool mega, bool alola, bool galar, PersonalTable stats)
        {
            if (stats == null)
            {
                return(0);
            }
            if (stats[species].FormeCount <= 1)
            {
                return(0);
            }

            if (species == (int)Species.Unown || species == (int)Species.Deerling || species == (int)Species.Sawsbuck)
            {
                return(31); // Random
            }
            if ((species == (int)Species.Greninja && !mega) || species == (int)Species.Eternatus)
            {
                return(0);
            }
            if (species == (int)Species.Scatterbug || species == (int)Species.Spewpa || species == (int)Species.Vivillon)
            {
                return(30); // save file specific
            }
            if (species == (int)Species.Minior)
            {
                return(Util.Rand.Next(7)); // keep the core color a surprise
            }
            if (galar)
            {
                switch ((Species)species)
                {
                case Species.Meowth:
                    return(Util.Rand.Next(3));    // Kanto, Alola, Galar

                case Species.Darmanitan:
                    return(Util.Rand.Next(4));    // Standard, Zen, Galar Standard, Galar Zen

                case Species.Slowbro:
                {
                    int form = Util.Rand.Next(2);         // Slowbro-1 is Mega and Slowbro-2 is Galar, so only return 0 or 2
                    if (form == 1)
                    {
                        form++;
                    }
                    return(form);
                }
                }
            }

            if (stats.TableLength == 980 && (species == (int)Species.Pikachu || species == (int)Species.Eevee)) // gg tableB -- no starters, they crash trainer battles.
            {
                return(0);
            }
            if (stats.TableLength == 1181 && species == (int)Species.Pikachu) // SWSH -- disallow Partner Pikachu from LGPE, but allow World Cap
            {
                int form = Util.Rand.Next(9);
                if (form == 8)
                {
                    form++;
                }
                return(form);
            }
            if (EvolveToAlolanForms.Contains(species))
            {
                return(alola ? Util.Rand.Next(2) : 0);
            }
            if (EvolveToGalarForms.Contains(species))
            {
                return(galar ? Util.Rand.Next(2) : 0);
            }
            if (!BattleExclusiveForms.Contains(species) || mega)
            {
                return(Util.Rand.Next(stats[species].FormeCount)); // Slot-Random
            }
            return(0);
        }