Exemple #1
0
        /// <summary>
        /// Checks a <see cref="PKM"/> file for compatibility to the <see cref="SaveFile"/>.
        /// </summary>
        /// <param name="SAV"><see cref="SaveFile"/> that is being checked.</param>
        /// <param name="pkm"><see cref="PKM"/> that is being tested for compatibility.</param>
        /// <returns></returns>
        public static string[] IsPKMCompatible(this SaveFile SAV, PKM pkm)
        {
            // Check if PKM properties are outside of the valid range
            List <string> errata = new List <string>();

            if (SAV.Generation > 1)
            {
                ushort held = (ushort)pkm.HeldItem;

                if (held > GameInfo.Strings.itemlist.Length)
                {
                    errata.Add($"Item Index beyond range: {held}");
                }
                else if (held > SAV.MaxItemID)
                {
                    errata.Add($"Game can't obtain item: {GameInfo.Strings.itemlist[held]}");
                }
                else if (!pkm.CanHoldItem(SAV.HeldItems))
                {
                    errata.Add($"Game can't hold item: {GameInfo.Strings.itemlist[held]}");
                }
            }

            int count = SAV.Personal[pkm.Species].FormeCount;

            if (pkm.AltForm >= SAV.Personal[pkm.Species].FormeCount && !FormConverter.IsValidOutOfBoundsForme(pkm.Species, pkm.AltForm, pkm.GenNumber))
            {
                errata.Add(string.Format(LegalityCheckStrings.V304, count - 1, pkm.AltForm));
            }

            if (pkm.Species > GameInfo.Strings.specieslist.Length)
            {
                errata.Add($"Species Index beyond range: {pkm.Species}");
            }
            else if (SAV.MaxSpeciesID < pkm.Species)
            {
                errata.Add($"Game can't obtain species: {GameInfo.Strings.specieslist[pkm.Species]}");
            }

            if (pkm.Moves.Any(m => m > GameInfo.Strings.movelist.Length))
            {
                errata.Add($"Item Index beyond range: {string.Join(", ", pkm.Moves.Where(m => m > GameInfo.Strings.movelist.Length).Select(m => m.ToString()))}");
            }
            else if (pkm.Moves.Any(m => m > SAV.MaxMoveID))
            {
                errata.Add($"Game can't have move: {string.Join(", ", pkm.Moves.Where(m => m > SAV.MaxMoveID).Select(m => GameInfo.Strings.movelist[m]))}");
            }

            if (pkm.Ability > GameInfo.Strings.abilitylist.Length)
            {
                errata.Add($"Ability Index beyond range: {pkm.Ability}");
            }
            else if (pkm.Ability > SAV.MaxAbilityID)
            {
                errata.Add($"Game can't have ability: {GameInfo.Strings.abilitylist[pkm.Ability]}");
            }

            return(errata.ToArray());
        }
Exemple #2
0
        /// <summary>
        /// Checks a <see cref="PKM"/> file for compatibility to the <see cref="SaveFile"/>.
        /// </summary>
        /// <param name="SAV"><see cref="SaveFile"/> that is being checked.</param>
        /// <param name="pkm"><see cref="PKM"/> that is being tested for compatibility.</param>
        /// <returns></returns>
        public static string[] IsPKMCompatible(this SaveFile SAV, PKM pkm)
        {
            // Check if PKM properties are outside of the valid range
            List <string> errata = new List <string>();

            if (SAV.Generation > 1)
            {
                ushort held = (ushort)pkm.HeldItem;

                if (held > GameInfo.Strings.itemlist.Length)
                {
                    errata.Add($"{MsgIndexItemRange} {held}");
                }
                else if (held > SAV.MaxItemID)
                {
                    errata.Add($"{MsgIndexItemGame} {GameInfo.Strings.itemlist[held]}");
                }
                else if (!pkm.CanHoldItem(SAV.HeldItems))
                {
                    errata.Add($"{MsgIndexItemHeld} {GameInfo.Strings.itemlist[held]}");
                }
            }

            if (pkm.Species > GameInfo.Strings.specieslist.Length)
            {
                errata.Add($"{MsgIndexSpeciesRange} {pkm.Species}");
            }
            else if (SAV.MaxSpeciesID < pkm.Species)
            {
                errata.Add($"{MsgIndexSpeciesGame} {GameInfo.Strings.specieslist[pkm.Species]}");
            }

            if (!SAV.Personal[pkm.Species].IsFormeWithinRange(pkm.AltForm) && !FormConverter.IsValidOutOfBoundsForme(pkm.Species, pkm.AltForm, pkm.GenNumber))
            {
                errata.Add(string.Format(LegalityCheckStrings.V304, Math.Max(0, SAV.Personal[pkm.Species].FormeCount - 1), pkm.AltForm));
            }

            if (pkm.Moves.Any(m => m > GameInfo.Strings.movelist.Length))
            {
                errata.Add($"{MsgIndexMoveRange} {string.Join(", ", pkm.Moves.Where(m => m > GameInfo.Strings.movelist.Length).Select(m => m.ToString()))}");
            }
            else if (pkm.Moves.Any(m => m > SAV.MaxMoveID))
            {
                errata.Add($"{MsgIndexMoveGame} {string.Join(", ", pkm.Moves.Where(m => m > SAV.MaxMoveID).Select(m => GameInfo.Strings.movelist[m]))}");
            }

            if (pkm.Ability > GameInfo.Strings.abilitylist.Length)
            {
                errata.Add($"{MsgIndexAbilityRange} {pkm.Ability}");
            }
            else if (pkm.Ability > SAV.MaxAbilityID)
            {
                errata.Add($"{MsgIndexAbilityGame} {GameInfo.Strings.abilitylist[pkm.Ability]}");
            }

            return(errata.ToArray());
        }