Ejemplo n.º 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());
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 3
0
    private static IReadOnlyList <string> GetSaveFileErrata(this SaveFile sav, PKM pk, IBasicStrings strings)
    {
        var    errata = new List <string>();
        ushort held   = (ushort)pk.HeldItem;

        if (sav.Generation > 1 && held != 0)
        {
            string?msg = null;
            if (held > sav.MaxItemID)
            {
                msg = MsgIndexItemGame;
            }
            else if (!pk.CanHoldItem(sav.HeldItems))
            {
                msg = MsgIndexItemHeld;
            }
            if (msg != null)
            {
                var itemstr = GameInfo.Strings.GetItemStrings(pk.Format, (GameVersion)pk.Version);
                errata.Add($"{msg} {(held >= itemstr.Length ? held.ToString() : itemstr[held])}");
            }
        }

        if (pk.Species > strings.Species.Count)
        {
            errata.Add($"{MsgIndexSpeciesRange} {pk.Species}");
        }
        else if (sav.MaxSpeciesID < pk.Species)
        {
            errata.Add($"{MsgIndexSpeciesGame} {strings.Species[pk.Species]}");
        }

        if (!sav.Personal[pk.Species].IsFormWithinRange(pk.Form) && !FormInfo.IsValidOutOfBoundsForm(pk.Species, pk.Form, pk.Generation))
        {
            errata.Add(string.Format(LegalityCheckStrings.LFormInvalidRange, Math.Max(0, sav.Personal[pk.Species].FormCount - 1), pk.Form));
        }

        if (pk.Moves.Any(m => m > strings.Move.Count))
        {
            errata.Add($"{MsgIndexMoveRange} {string.Join(", ", pk.Moves.Where(m => m > strings.Move.Count).Select(m => m.ToString()))}");
        }
        else if (pk.Moves.Any(m => m > sav.MaxMoveID))
        {
            errata.Add($"{MsgIndexMoveGame} {string.Join(", ", pk.Moves.Where(m => m > sav.MaxMoveID).Select(m => strings.Move[m]))}");
        }

        if (pk.Ability > strings.Ability.Count)
        {
            errata.Add($"{MsgIndexAbilityRange} {pk.Ability}");
        }
        else if (pk.Ability > sav.MaxAbilityID)
        {
            errata.Add($"{MsgIndexAbilityGame} {strings.Ability[pk.Ability]}");
        }

        return(errata);
    }
Ejemplo n.º 4
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]}");
                }
            }

            if (pkm.Species > GameInfo.Strings.specieslist.Length)
            {
                errata.Add($"Species Index beyond range: {pkm.HeldItem}");
            }
            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());
        }