Example #1
0
        /// <summary>
        /// Gets the current Battle Stats.
        /// </summary>
        /// <param name="p"><see cref="PersonalInfo"/> entry containing Base Stat Info</param>
        /// <returns>Battle Stats (H/A/B/S/C/D)</returns>
        public virtual ushort[] getStats(PersonalInfo p)
        {
            int level = CurrentLevel;

            ushort[] Stats = new ushort[6];
            Stats[0] = (ushort)(p.HP == 1 ? 1 : ((HT_HP ? 31 : IV_HP) + 2 * p.HP + EV_HP / 4 + 100) * level / 100 + 10);
            Stats[1] = (ushort)(((HT_ATK ? 31 : IV_ATK) + 2 * p.ATK + EV_ATK / 4) * level / 100 + 5);
            Stats[2] = (ushort)(((HT_DEF ? 31 : IV_DEF) + 2 * p.DEF + EV_DEF / 4) * level / 100 + 5);
            Stats[4] = (ushort)(((HT_SPA ? 31 : IV_SPA) + 2 * p.SPA + EV_SPA / 4) * level / 100 + 5);
            Stats[5] = (ushort)(((HT_SPD ? 31 : IV_SPD) + 2 * p.SPD + EV_SPD / 4) * level / 100 + 5);
            Stats[3] = (ushort)(((HT_SPE ? 31 : IV_SPE) + 2 * p.SPE + EV_SPE / 4) * level / 100 + 5);

            // Account for nature
            int incr = Nature / 5 + 1;
            int decr = Nature % 5 + 1;

            if (incr == decr)
            {
                return(Stats);
            }
            Stats[incr] *= 11; Stats[incr] /= 10;
            Stats[decr] *= 9; Stats[decr] /= 10;
            return(Stats);
        }
Example #2
0
        private PersonalTable(byte[] data, GameVersion format)
        {
            int size = 0;

            switch (format)
            {
            case GameVersion.RBY: size = PersonalInfoG1.SIZE; break;

            case GameVersion.GS:
            case GameVersion.C: size = PersonalInfoG2.SIZE; break;

            case GameVersion.RS:
            case GameVersion.E:
            case GameVersion.FR:
            case GameVersion.LG: size = PersonalInfoG3.SIZE; break;

            case GameVersion.DP:
            case GameVersion.Pt:
            case GameVersion.HGSS: size = PersonalInfoG4.SIZE; break;

            case GameVersion.BW: size = PersonalInfoBW.SIZE; break;

            case GameVersion.B2W2: size = PersonalInfoB2W2.SIZE; break;

            case GameVersion.XY: size = PersonalInfoXY.SIZE; break;

            case GameVersion.ORAS: size = PersonalInfoORAS.SIZE; break;

            case GameVersion.SM: size = PersonalInfoSM.SIZE; break;
            }

            if (size == 0)
            {
                Table = null; return;
            }

            byte[][]       entries = splitBytes(data, size);
            PersonalInfo[] d       = new PersonalInfo[data.Length / size];

            switch (format)
            {
            case GameVersion.RBY:
                for (int i = 0; i < d.Length; i++)
                {
                    d[i] = new PersonalInfoG1(entries[i]);
                }
                break;

            case GameVersion.GS:
            case GameVersion.C:
                for (int i = 0; i < d.Length; i++)
                {
                    d[i] = new PersonalInfoG2(entries[i]);
                }
                break;

            case GameVersion.RS:
            case GameVersion.E:
            case GameVersion.FR:
            case GameVersion.LG:
                Array.Resize(ref d, 387);
                for (int i = 0; i < d.Length; i++)     // entries are not in order of natdexID
                {
                    d[i] = new PersonalInfoG3(entries[PKX.getG3Species(i)]);
                }
                break;

            case GameVersion.DP:
            case GameVersion.Pt:
            case GameVersion.HGSS:
                for (int i = 0; i < d.Length; i++)
                {
                    d[i] = new PersonalInfoG4(entries[i]);
                }
                break;

            case GameVersion.BW:
                for (int i = 0; i < d.Length; i++)
                {
                    d[i] = new PersonalInfoBW(entries[i]);
                }
                break;

            case GameVersion.B2W2:
                for (int i = 0; i < d.Length; i++)
                {
                    d[i] = new PersonalInfoB2W2(entries[i]);
                }
                break;

            case GameVersion.XY:
                for (int i = 0; i < d.Length; i++)
                {
                    d[i] = new PersonalInfoXY(entries[i]);
                }
                break;

            case GameVersion.ORAS:
                for (int i = 0; i < d.Length; i++)
                {
                    d[i] = new PersonalInfoORAS(entries[i]);
                }
                break;

            case GameVersion.SM:
                for (int i = 0; i < d.Length; i++)
                {
                    d[i] = new PersonalInfoSM(entries[i]);
                }
                break;
            }
            Table = d;
        }
Example #3
0
        private static void MarkMovesForOrigin(BreedInfo <EggSource34> value, ICollection <int> eggMoves, int count, bool inheritLevelUp, PersonalInfo info)
        {
            var possible = value.Possible;
            var learn    = value.Learnset;
            var baseEgg  = value.Learnset.GetBaseEggMoves(value.Level);
            var tm       = info.TMHM;
            var tmlist   = Legal.TM_3.AsSpan(0, 50);

            var moves = value.Moves;

            for (int i = 0; i < count; i++)
            {
                var move = moves[i];

                if (baseEgg.IndexOf(move) != -1)
                {
                    possible[i] |= 1 << (int)Base;
                }

                if (inheritLevelUp && learn.GetLevelLearnMove(move) != -1)
                {
                    possible[i] |= 1 << (int)ParentLevelUp;
                }

                if (eggMoves.Contains(move))
                {
                    possible[i] |= 1 << (int)FatherEgg;
                }

                var tmIndex = tmlist.IndexOf(move);
                if (tmIndex != -1 && tm[tmIndex])
                {
                    possible[i] |= 1 << (int)FatherTM;
                }
            }
        }
Example #4
0
        /// <summary>
        /// Checks the input <see cref="PKM"/> data for legality.
        /// </summary>
        /// <param name="pk">Input data to check</param>
        /// <param name="table"><see cref="SaveFile"/> specific personal data</param>
        public LegalityAnalysis(PKM pk, PersonalTable table = null)
        {
#if SUPPRESS
            try
#endif
            {
                PersonalInfo = table?.GetFormeEntry(pk.Species, pk.AltForm) ?? pk.PersonalInfo;
                switch (pk.Format) // prior to storing GameVersion
                {
                case 1: ParsePK1(pk); break;

                case 2: ParsePK1(pk); break;
                }

                if (!Parse.Any())
                {
                    switch (pk.GenNumber)
                    {
                    case 3: ParsePK3(pk); break;

                    case 4: ParsePK4(pk); break;

                    case 5: ParsePK5(pk); break;

                    case 6: ParsePK6(pk); break;

                    case 1:
                    case 2:
                    case 7: ParsePK7(pk); break;
                    }
                }

                if (Parse.Count > 0)
                {
                    if (Parse.Any(chk => !chk.Valid))
                    {
                        Valid = false;
                    }
                    else if (Info.Moves.Any(m => m.Valid != true))
                    {
                        Valid = false;
                    }
                    else if (Info.Relearn.Any(m => m.Valid != true))
                    {
                        Valid = false;
                    }
                    else
                    {
                        Valid = true;
                    }

                    if (pkm.FatefulEncounter && Info.Relearn.Any(chk => !chk.Valid) && EncounterMatch == null)
                    {
                        AddLine(Severity.Indeterminate, V188, CheckIdentifier.Fateful);
                    }
                }
            }
#if SUPPRESS
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.Message);
                Valid = false;
                AddLine(Severity.Invalid, V190, CheckIdentifier.Misc);
                pkm   = pk;
                Error = true;
            }
#endif
            Parsed = true;
        }
Example #5
0
        private static IEnumerable <int> getMoves(PKM pkm, int species, int lvl, int form, bool moveTutor, GameVersion Version, bool LVL, bool specialTutors, bool Machine, int Generation, bool MoveReminder)
        {
            List <int> r = new List <int>();

            var ver = Version;

            switch (Generation)
            {
            case 6:
                switch (ver)
                {
                case GameVersion.Any:         // Start at the top, hit every table
                case GameVersion.X:
                case GameVersion.Y:
                case GameVersion.XY:
                {
                    int          index = PersonalTable.XY.getFormeIndex(species, form);
                    PersonalInfo pi    = PersonalTable.XY.getFormeEntry(species, form);

                    if (LVL)
                    {
                        r.AddRange(LevelUpXY[index].getMoves(lvl));
                    }
                    if (moveTutor)
                    {
                        r.AddRange(getTutorMoves(pkm, species, form, specialTutors));
                    }
                    if (Machine)
                    {
                        r.AddRange(TMHM_XY.Where((t, m) => pi.TMHM[m]));
                    }

                    if (ver == GameVersion.Any)         // Fall Through
                    {
                        goto case GameVersion.ORAS;
                    }
                    break;
                }

                case GameVersion.AS:
                case GameVersion.OR:
                case GameVersion.ORAS:
                {
                    int          index = PersonalTable.AO.getFormeIndex(species, form);
                    PersonalInfo pi    = PersonalTable.AO.getFormeEntry(species, form);

                    if (LVL)
                    {
                        r.AddRange(LevelUpAO[index].getMoves(lvl));
                    }
                    if (moveTutor)
                    {
                        r.AddRange(getTutorMoves(pkm, species, form, specialTutors));
                    }
                    if (Machine)
                    {
                        r.AddRange(TMHM_AO.Where((t, m) => pi.TMHM[m]));
                    }
                    break;
                }
                }
                break;

            case 7:
                switch (ver)
                {
                case GameVersion.Any:
                case GameVersion.SN:
                case GameVersion.MN:
                case GameVersion.SM:
                {
                    int          index = PersonalTable.SM.getFormeIndex(species, form);
                    PersonalInfo pi    = PersonalTable.SM.getFormeEntry(species, form);
                    if (MoveReminder)
                    {
                        lvl = 100;         // Move reminder can teach any level in movepool now!
                    }
                    if (LVL)
                    {
                        r.AddRange(LevelUpSM[index].getMoves(lvl));
                    }
                    if (moveTutor)
                    {
                        r.AddRange(getTutorMoves(pkm, species, form, specialTutors));
                    }
                    if (Machine)
                    {
                        r.AddRange(TMHM_SM.Where((t, m) => pi.TMHM[m]));
                    }
                    break;
                }
                }
                break;

            default:
                return(r);
            }
            return(r);
        }
Example #6
0
        private static PersonalInfo[] GetArray(byte[] data, GameVersion format, int size)
        {
            byte[][]       entries = SplitBytes(data, size);
            PersonalInfo[] d       = new PersonalInfo[data.Length / size];

            switch (format)
            {
            case GameVersion.RBY:
                for (int i = 0; i < d.Length; i++)
                {
                    d[i] = new PersonalInfoG1(entries[i]);
                }
                return(d);

            case GameVersion.GS:
            case GameVersion.C:
                for (int i = 0; i < d.Length; i++)
                {
                    d[i] = new PersonalInfoG2(entries[i]);
                }
                return(d);

            case GameVersion.RS:
            case GameVersion.E:
            case GameVersion.FR:
            case GameVersion.LG:
                for (int i = 0; i < d.Length; i++)
                {
                    d[i] = new PersonalInfoG3(entries[i]);
                }
                return(d);

            case GameVersion.DP:
            case GameVersion.Pt:
            case GameVersion.HGSS:
                for (int i = 0; i < d.Length; i++)
                {
                    d[i] = new PersonalInfoG4(entries[i]);
                }
                return(d);

            case GameVersion.BW:
                for (int i = 0; i < d.Length; i++)
                {
                    d[i] = new PersonalInfoBW(entries[i]);
                }
                return(d);

            case GameVersion.B2W2:
                for (int i = 0; i < d.Length; i++)
                {
                    d[i] = new PersonalInfoB2W2(entries[i]);
                }
                return(d);

            case GameVersion.XY:
                for (int i = 0; i < d.Length; i++)
                {
                    d[i] = new PersonalInfoXY(entries[i]);
                }
                return(d);

            case GameVersion.ORAS:
                for (int i = 0; i < d.Length; i++)
                {
                    d[i] = new PersonalInfoORAS(entries[i]);
                }
                return(d);

            case GameVersion.SM:
                for (int i = 0; i < d.Length; i++)
                {
                    d[i] = new PersonalInfoSM(entries[i]);
                }
                return(d);

            default:
                return(null);
            }
        }
Example #7
0
        private static void MarkMovesForOrigin(BreedInfo <EggSource2> value, ICollection <int> eggMoves, int count, bool inheritLevelUp, PersonalInfo info, GameVersion version)
        {
            var possible = value.Possible;
            var learn    = value.Learnset;
            var baseEgg  = value.Learnset.GetBaseEggMoves(value.Level);
            var tm       = info.TMHM;

            var moves = value.Moves;

            for (int i = 0; i < count; i++)
            {
                var move = moves[i];

                if (baseEgg.IndexOf(move) != -1)
                {
                    possible[i] |= 1 << (int)Base;
                }

                if (inheritLevelUp && learn.GetLevelLearnMove(move) != -1)
                {
                    possible[i] |= 1 << (int)ParentLevelUp;
                }

                if (eggMoves.Contains(move))
                {
                    possible[i] |= 1 << (int)FatherEgg;
                }

                var tmIndex = Array.IndexOf(Legal.TMHM_GSC, move, 0, 50);
                if (tmIndex != -1 && tm[tmIndex])
                {
                    possible[i] |= 1 << (int)FatherTM;
                }

                if (version is GameVersion.C)
                {
                    var tutorIndex = Array.IndexOf(Legal.Tutors_GSC, move);
                    if (tutorIndex != -1 && tm[57 + tutorIndex])
                    {
                        possible[i] |= 1 << (int)Tutor;
                    }
                }
            }
        }