/// <summary> /// Gets a legal <see cref="PKM"/> from a random in-game encounter's data. /// </summary> /// <param name="blank">Template data that will have its properties modified</param> /// <param name="tr">Trainer Data to use in generating the encounter</param> /// <param name="species">Species ID to generate</param> /// <returns>Result legal pkm, null if data should be ignored.</returns> private static PKM?GetRandomEncounter(PKM blank, ITrainerInfo tr, int species) { blank.Species = species; blank.Gender = blank.GetSaneGender(); if (species == (int)Species.Meowstic || species == (int)Species.Indeedee) { blank.AltForm = blank.Gender; } var legalencs = EncounterMovesetGenerator.GeneratePKMs(blank, tr).Where(z => new LegalityAnalysis(z).Valid); var f = legalencs.FirstOrDefault(); if (f == null) { return(null); } var an = f.AbilityNumber; f.Species = species; f.Gender = f.GetSaneGender(); if (species == (int)Species.Meowstic || species == (int)Species.Indeedee) { f.AltForm = f.Gender; } f.CurrentLevel = 100; f.Nickname = SpeciesName.GetSpeciesNameGeneration(f.Species, f.Language, f.Format); f.IsNicknamed = false; f.SetSuggestedMoves(); f.SetSuggestedMovePP(0); f.SetSuggestedMovePP(1); f.SetSuggestedMovePP(2); f.SetSuggestedMovePP(3); f.RefreshAbility(an >> 1); var info = new LegalityAnalysis(f).Info; if (info.Generation > 0 && info.EvoChainsAllGens[info.Generation].All(z => z.Species != info.EncounterMatch.Species)) { f.CurrentHandler = 1; f.HT_Name = f.OT_Name; if (f is IHandlerLanguage h) { h.HT_Language = 1; } } if (f is IFormArgument fa) { fa.FormArgument = ShowdownEdits.GetSuggestedFormArgument(f, info.EncounterMatch.Species); } int wIndex = WurmpleUtil.GetWurmpleEvoGroup(f.Species); if (wIndex != -1) { f.EncryptionConstant = WurmpleUtil.GetWurmpleEC(wIndex); } return(f); }
/// <summary> /// Gets a legal <see cref="PKM"/> from a random in-game encounter's data. /// </summary> /// <param name="blank">Template data that will have its properties modified</param> /// <param name="tr">Trainer Data to use in generating the encounter</param> /// <param name="species">Species ID to generate</param> /// <returns>Result legal pkm, null if data should be ignored.</returns> private static PKM?GetRandomEncounter(PKM blank, ITrainerInfo tr, int species) { blank.Species = species; blank.Gender = blank.GetSaneGender(); if (species == (int)Species.Meowstic || species == (int)Species.Indeedee) { blank.AltForm = blank.Gender; } var legalencs = EncounterMovesetGenerator.GeneratePKMs(blank, tr).Where(z => new LegalityAnalysis(z).Valid); var f = legalencs.FirstOrDefault(); if (f == null) { var template = PKMConverter.GetBlank(tr.Generation, (GameVersion)tr.Game); var set = new ShowdownSet(new ShowdownSet(blank).Text.Split('\r')[0]); template.ApplySetDetails(set); bool success = tr.TryAPIConvert(set, template, out PKM pk); return(success ? pk : null); } var an = f.AbilityNumber; f.Species = species; f.Gender = f.GetSaneGender(); if (species == (int)Species.Meowstic || species == (int)Species.Indeedee) { f.AltForm = f.Gender; } f.CurrentLevel = 100; f.Nickname = SpeciesName.GetSpeciesNameGeneration(f.Species, f.Language, f.Format); f.IsNicknamed = false; f.SetSuggestedMoves(); f.SetSuggestedMovePP(0); f.SetSuggestedMovePP(1); f.SetSuggestedMovePP(2); f.SetSuggestedMovePP(3); f.RefreshAbility(an >> 1); var info = new LegalityAnalysis(f).Info; if (info.Generation > 0 && info.EvoChainsAllGens[info.Generation].All(z => z.Species != info.EncounterMatch.Species)) { f.CurrentHandler = 1; f.HT_Name = f.OT_Name; if (f is IHandlerLanguage h) { h.HT_Language = 1; } } if (f is IFormArgument fa) { fa.FormArgument = ShowdownEdits.GetSuggestedFormArgument(f, info.EncounterMatch.Species); } int wIndex = WurmpleUtil.GetWurmpleEvoGroup(f.Species); if (wIndex != -1) { f.EncryptionConstant = WurmpleUtil.GetWurmpleEncryptionConstant(wIndex); } if (f is IHomeTrack ht && ht.Tracker == 0 && APILegality.SetRandomTracker) { ht.Tracker = APILegality.GetRandomULong(); } if (new LegalityAnalysis(f).Valid) { return(f); } else { var template = PKMConverter.GetBlank(tr.Generation, (GameVersion)tr.Game); var set = new ShowdownSet(new ShowdownSet(blank).Text.Split('\r')[0]); template.ApplySetDetails(set); bool success = tr.TryAPIConvert(set, template, out PKM pk); return(success ? pk : null); } }