public static IEnumerable <PKM> GetCompatible(this SaveFile sav, IEnumerable <PKM> pks) { var savtype = sav.PKMType; foreach (var temp in pks) { var pk = PKMConverter.ConvertToType(temp, savtype, out string c); if (pk == null) { Debug.WriteLine(c); continue; } if (sav is ILangDeviantSave il && PKMConverter.IsIncompatibleGB(temp, il.Japanese, pk.Japanese)) { c = PKMConverter.GetIncompatibleGBMessage(pk, il.Japanese); Debug.WriteLine(c); continue; } var compat = sav.IsPKMCompatible(pk); if (compat.Count > 0) { continue; } yield return(pk); } }
public static IEnumerable <PKM> GetCompatible(this SaveFile SAV, IEnumerable <PKM> pks) { var savtype = SAV.PKMType; foreach (var temp in pks) { var pk = PKMConverter.ConvertToType(temp, savtype, out string c); if (pk == null) { Debug.WriteLine(c); continue; } if (PKMConverter.IsIncompatibleGB(pk.Format, SAV.Japanese, pk.Japanese)) { c = PKMConverter.GetIncompatibleGBMessage(pk, SAV.Japanese); Debug.WriteLine(c); continue; } var compat = SAV.IsPKMCompatible(pk); if (compat.Count > 0) { continue; } yield return(pk); } }
public static IList <PKM> GetLivingDex(SaveFile sav) { var bd = sav.BoxData; var tr = sav; for (int i = 1; i <= sav.MaxSpeciesID; i++) // should really get a list of valid species IDs { var pk = sav.BlankPKM; pk.Species = i; pk.Gender = pk.GetSaneGender(); if (i == (int)Species.Meowstic) { pk.AltForm = pk.Gender; } var f = EncounterMovesetGenerator.GeneratePKMs(pk, tr).FirstOrDefault(); if (f == null) { continue; } var converted = PKMConverter.ConvertToType(f, sav.PKMType, out _); if (converted != null) { bd[i] = converted; } } return(bd); }
public static PKM?GetLivingEntry(this ITrainerInfo tr, PKM template, int species, int form, Type destType) { template.Species = species; template.Form = form; template.Gender = template.GetSaneGender(); var f = EncounterMovesetGenerator.GeneratePKMs(template, tr).FirstOrDefault(); if (f == null) { return(null); } var result = PKMConverter.ConvertToType(f, destType, out _); if (result == null) { return(null); } result.CurrentLevel = 100; result.Species = species; result.Form = form; result.Heal(); return(result); }
/// <summary> /// Gets a compatible <see cref="PKM"/> for editing with a new <see cref="SaveFile"/>. /// </summary> /// <param name="sav">SaveFile to receive the compatible <see cref="pk"/></param> /// <param name="pk">Current Pokémon being edited</param> /// <returns>Current Pokémon, assuming conversion is possible. If conversion is not possible, a blank <see cref="PKM"/> will be obtained from the <see cref="sav"/>.</returns> public static PKM GetCompatiblePKM(this SaveFile sav, PKM pk) { if (pk.Format >= 3 || sav.Generation >= 7) { return(PKMConverter.ConvertToType(pk, sav.PKMType, out _) ?? sav.BlankPKM); } // gen1-2 compatibility check if (pk.Japanese != ((ILangDeviantSave)sav).Japanese) { return(sav.BlankPKM); } if (sav is SAV2 s2 && s2.Korean != pk.Korean) { return(sav.BlankPKM); } return(PKMConverter.ConvertToType(pk, sav.PKMType, out _) ?? sav.BlankPKM); }
/// <summary> /// Gets a compatible <see cref="PKM"/> for editing with a new <see cref="SaveFile"/>. /// </summary> /// <param name="sav">SaveFile to receive the compatible <see cref="pk"/></param> /// <param name="pk">Current Pokémon being edited</param> /// <returns>Current Pokémon, assuming conversion is possible. If conversion is not possible, a blank <see cref="PKM"/> will be obtained from the <see cref="sav"/>.</returns> public static PKM GetCompatiblePKM(this SaveFile sav, PKM pk = null) { if (pk == null) { return(sav.BlankPKM); } if (pk.Format < 3 && sav.Generation < 7) { // gen1-2 compatibility check if (pk.Japanese != sav.Japanese) { return(sav.BlankPKM); } if (sav is SAV2 s2 && s2.Korean != pk.Korean) { return(sav.BlankPKM); } } return(PKMConverter.ConvertToType(pk, sav.PKMType, out _) ?? sav.BlankPKM); }
public static List <PKM> GetLivingDex(ITrainerInfo tr, IEnumerable <int> speciesToGenerate, PKM blank) { var result = new List <PKM>(); var destType = blank.GetType(); foreach (var s in speciesToGenerate) { var pk = blank.Clone(); pk.Species = s; pk.Gender = pk.GetSaneGender(); var pi = pk.PersonalInfo; for (int i = 0; i < pi.FormeCount; i++) { pk.AltForm = i; if (s == (int)Species.Indeedee || s == (int)Species.Meowstic) { pk.Gender = i; } var f = EncounterMovesetGenerator.GeneratePKMs(pk, tr).FirstOrDefault(); if (f == null) { continue; } var converted = PKMConverter.ConvertToType(f, destType, out _); if (converted == null) { continue; } converted.CurrentLevel = 100; converted.Species = s; converted.AltForm = i; result.Add(converted); } } return(result); }
/// <summary> /// Gets a blank file for the save file. If the template path exists, a template load will be attempted. /// </summary> /// <param name="sav">Save File to fetch a template for</param> /// <param name="templatePath">Path to look for a template in</param> /// <returns>Template if it exists, or a blank <see cref="PKM"/> from the <see cref="sav"/></returns> public static PKM LoadTemplate(this SaveFile sav, string templatePath = null) { var blank = sav.BlankPKM; if (!Directory.Exists(templatePath)) { return(blank); } var di = new DirectoryInfo(templatePath); string path = Path.Combine(templatePath, $"{di.Name}.{blank.Extension}"); if (!File.Exists(path) || !PKX.IsPKM(new FileInfo(path).Length)) { return(blank); } var pk = PKMConverter.GetPKMfromBytes(File.ReadAllBytes(path), prefer: blank.Format); return(PKMConverter.ConvertToType(pk, sav.BlankPKM.GetType(), out path) ?? blank); // no sneaky plz; reuse string }
/// <summary> /// Gets a blank file for the save file. If the template path exists, a template load will be attempted. /// </summary> /// <param name="sav">Save File to fetch a template for</param> /// <param name="templatePath">Path to look for a template in</param> /// <returns>Template if it exists, or a blank <see cref="PKM"/> from the <see cref="sav"/></returns> public static PKM LoadTemplate(this SaveFile sav, string templatePath) { if (!Directory.Exists(templatePath)) { return(LoadTemplate(sav)); } var di = new DirectoryInfo(templatePath); string path = Path.Combine(templatePath, $"{di.Name}.{sav.PKMType.Name.ToLower()}"); if (!File.Exists(path) || !PKX.IsPKM(new FileInfo(path).Length)) { return(LoadTemplate(sav)); } var pk = PKMConverter.GetPKMfromBytes(File.ReadAllBytes(path), prefer: sav.Generation); if (pk == null) { return(LoadTemplate(sav)); } return(PKMConverter.ConvertToType(pk, sav.BlankPKM.GetType(), out _) ?? LoadTemplate(sav)); }