public PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria) { int gen = Generation; var version = Version; var pk = PKMConverter.GetBlank(gen, version); sav.ApplyTo(pk); pk.Species = Species; pk.Nickname = SpeciesName.GetSpeciesNameGeneration(Species, sav.Language, gen); pk.CurrentLevel = Level; pk.Version = (int)version; pk.Ball = (int)Ball.Poke; pk.OT_Friendship = pk.PersonalInfo.BaseFriendship; int[] moves = SetEncounterMoves(pk, version); SetPINGA(pk, criteria); if (gen <= 2 && version != GameVersion.C) { return(pk); } SetMetData(pk); if (gen < 3) { return(pk); } if (gen >= 4) { pk.SetEggMetData(version, (GameVersion)sav.Game); } if (gen < 6) { return(pk); } if (pk is PK6 pk6) { pk6.SetHatchMemory6(); } SetAltForm(pk, sav); pk.SetRandomEC(); pk.RelearnMoves = moves; return(pk); }
protected override void ApplyDetails(ITrainerInfo SAV, EncounterCriteria criteria, PKM pk) { base.ApplyDetails(SAV, criteria, pk); pk.SetRelearnMoves(Relearn); var pk8 = (PK8)pk; pk8.DynamaxLevel = DynamaxLevel; pk8.HT_Language = SAV.Language; pk8.OT_Memory = OT_Memory; pk8.OT_TextVar = OT_TextVar; pk8.OT_Feeling = OT_Feeling; pk8.OT_Intensity = OT_Intensity; }
protected override void ApplyDetails(ITrainerInfo sav, EncounterCriteria criteria, PKM pk) { base.ApplyDetails(sav, criteria, pk); if (TID != -1) { pk.TID = TID; } if (OT_Name.Length != 0) { pk.OT_Name = OT_Name; } else if (OT_Names.Count != 0) { pk.OT_Name = OT_Names[Util.Rand.Next(OT_Names.Count)]; } }
private static void SetNatureGenderAbility(PKM pk, EncounterCriteria criteria) { int gender = criteria.GetGender(-1, pk.PersonalInfo); int nature = (int)criteria.GetNature(Nature.Random); if (pk.Format <= 5) { pk.SetPIDGender(gender); pk.Gender = gender; pk.SetPIDNature(nature); pk.Nature = nature; pk.RefreshAbility(pk.PIDAbility); } else { pk.PID = Util.Rand32(); pk.Nature = nature; pk.Gender = gender; pk.RefreshAbility(Util.Rand.Next(2)); } }
protected override void ApplyDetails(ITrainerInfo sav, EncounterCriteria criteria, PKM pk) { base.ApplyDetails(sav, criteria, pk); if (CurrentLevel != -1) // Restore met level { pk.Met_Level = LevelMin; } if (TID != -1) { pk.TID = TID; } if (OT_Name.Length != 0) { pk.OT_Name = OT_Name; } else if (OT_Names.Count != 0) { pk.OT_Name = OT_Names[Util.Rand.Next(OT_Names.Count)]; } }
public static void ApplyDetails(PKM pk, EncounterCriteria criteria, Shiny shiny = Shiny.FixedValue, int flawless = -1, AbilityPermission ability = AbilityPermission.Any12) { if (shiny == Shiny.FixedValue) { shiny = criteria.Shiny is Shiny.Random or Shiny.Never ? Shiny.Never : Shiny.Always; } if (flawless == -1) { flawless = 0; } int ctr = 0; const int maxAttempts = 50_000; var rnd = Util.Rand; do { ulong s0 = rnd.Rand64(); ulong s1 = rnd.Rand64(); var xors = new XorShift128(s0, s1); if (TryApplyFromSeed(pk, criteria, shiny, flawless, xors, ability)) { return; } } while (++ctr != maxAttempts); { ulong s0 = rnd.Rand64(); ulong s1 = rnd.Rand64(); var xors = new XorShift128(s0, s1); TryApplyFromSeed(pk, EncounterCriteria.Unrestricted, shiny, flawless, xors, ability); } }
private static bool TryApplyFromSeed(PKM pk, EncounterCriteria criteria, Shiny shiny, int flawless, uint seed) { var xoro = new Xoroshiro128Plus(seed); // Encryption Constant pk.EncryptionConstant = (uint)xoro.NextInt(uint.MaxValue); // PID var pid = (uint)xoro.NextInt(uint.MaxValue); if (shiny == Shiny.Never) { if (GetIsShiny(pk.TID, pk.SID, pid)) { pid ^= 0x1000_0000; } } else if (shiny != Shiny.Random) { if (!GetIsShiny(pk.TID, pk.SID, pid)) { pid = GetShinyPID(pk.TID, pk.SID, pid, 0); } if (shiny == Shiny.AlwaysSquare && pk.ShinyXor != 0) { return(false); } if (shiny == Shiny.AlwaysStar && pk.ShinyXor == 0) { return(false); } } pk.PID = pid; // IVs Span <int> ivs = stackalloc[] { UNSET, UNSET, UNSET, UNSET, UNSET, UNSET }; const int MAX = 31; for (int i = 0; i < flawless; i++) { int index; do { index = (int)xoro.NextInt(6); }while (ivs[index] != UNSET); ivs[index] = MAX; } for (int i = 0; i < ivs.Length; i++) { if (ivs[i] == UNSET) { ivs[i] = (int)xoro.NextInt(32); } } if (!criteria.IsIVsCompatible(ivs, 8)) { return(false); } pk.IV_HP = ivs[0]; pk.IV_ATK = ivs[1]; pk.IV_DEF = ivs[2]; pk.IV_SPA = ivs[3]; pk.IV_SPD = ivs[4]; pk.IV_SPE = ivs[5]; // Remainder var scale = (IScaledSize)pk; scale.HeightScalar = (byte)((int)xoro.NextInt(0x81) + (int)xoro.NextInt(0x80)); scale.WeightScalar = (byte)((int)xoro.NextInt(0x81) + (int)xoro.NextInt(0x80)); return(true); }
public PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) => throw new ArgumentException($"Cannot convert an {nameof(EncounterInvalid)} to PKM.");
public abstract PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria);
public static bool TryApplyFromSeed(PKM pk, EncounterCriteria criteria, Shiny shiny, int flawless, XorShift128 xors, AbilityPermission ability) { // Encryption Constant pk.EncryptionConstant = xors.NextUInt(); // PID var fakeTID = xors.NextUInt(); // fakeTID var pid = xors.NextUInt(); pid = GetRevisedPID(fakeTID, pid, pk); if (shiny == Shiny.Never) { if (GetIsShiny(pk.TID, pk.SID, pid)) { return(false); } } else if (shiny != Shiny.Random) { if (!GetIsShiny(pk.TID, pk.SID, pid)) { return(false); } if (shiny == Shiny.AlwaysSquare && pk.ShinyXor != 0) { return(false); } if (shiny == Shiny.AlwaysStar && pk.ShinyXor == 0) { return(false); } } pk.PID = pid; // Check IVs: Create flawless IVs at random indexes, then the random IVs for not flawless. Span <int> ivs = stackalloc[] { UNSET, UNSET, UNSET, UNSET, UNSET, UNSET }; const int MAX = 31; var determined = 0; while (determined < flawless) { var idx = (int)xors.NextUInt(6); if (ivs[idx] != UNSET) { continue; } ivs[idx] = 31; determined++; } for (var i = 0; i < ivs.Length; i++) { if (ivs[i] == UNSET) { ivs[i] = xors.NextInt(0, MAX + 1); } } if (!criteria.IsIVsCompatible(ivs, 8)) { return(false); } pk.IV_HP = ivs[0]; pk.IV_ATK = ivs[1]; pk.IV_DEF = ivs[2]; pk.IV_SPA = ivs[3]; pk.IV_SPD = ivs[4]; pk.IV_SPE = ivs[5]; // Ability var n = ability switch { AbilityPermission.Any12 => (int)xors.NextUInt(2), AbilityPermission.Any12H => (int)xors.NextUInt(3), _ => (int)ability >> 1, }; pk.SetAbilityIndex(n); // Gender (skip this if gender is fixed) var genderRatio = PersonalTable.BDSP.GetFormEntry(pk.Species, pk.Form).Gender; if (genderRatio == PersonalInfo.RatioMagicGenderless) { pk.Gender = 2; } else if (genderRatio == PersonalInfo.RatioMagicMale) { pk.Gender = 0; } else if (genderRatio == PersonalInfo.RatioMagicFemale) { pk.Gender = 1; } else { var next = (((int)xors.NextUInt(253) + 1 < genderRatio) ? 1 : 0); if (criteria.Gender is 0 or 1 && next != criteria.Gender) { return(false); } pk.Gender = next; } if (criteria.Nature is Nature.Random) { pk.Nature = (int)xors.NextUInt(25); } else // Skip nature, assuming Synchronize { pk.Nature = (int)criteria.Nature; } pk.StatNature = pk.Nature; // Remainder var scale = (IScaledSize)pk; scale.HeightScalar = (byte)((int)xors.NextUInt(0x81) + (int)xors.NextUInt(0x80)); scale.WeightScalar = (byte)((int)xors.NextUInt(0x81) + (int)xors.NextUInt(0x80)); // Item, don't care return(true); }
public PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria) => ConvertToPB7(sav, criteria);
private static bool TryApplyFromSeed(PKM pk, EncounterCriteria criteria, Shiny shiny, int flawless, uint seed) { var xoro = new Xoroshiro128Plus8b(seed); // Encryption Constant pk.EncryptionConstant = seed; // PID var fakeTID = xoro.NextUInt(); // fakeTID var pid = xoro.NextUInt(); pid = GetRevisedPID(fakeTID, pid, pk); if (shiny == Shiny.Never) { if (GetIsShiny(pk.TID, pk.SID, pid)) { return(false); } } else if (shiny != Shiny.Random) { if (!GetIsShiny(pk.TID, pk.SID, pid)) { return(false); } if (shiny == Shiny.AlwaysSquare && pk.ShinyXor != 0) { return(false); } if (shiny == Shiny.AlwaysStar && pk.ShinyXor == 0) { return(false); } } pk.PID = pid; // Check IVs: Create flawless IVs at random indexes, then the random IVs for not flawless. Span <int> ivs = stackalloc [] { UNSET, UNSET, UNSET, UNSET, UNSET, UNSET }; const int MAX = 31; var determined = 0; while (determined < flawless) { var idx = (int)xoro.NextUInt(6); if (ivs[idx] != UNSET) { continue; } ivs[idx] = 31; determined++; } for (var i = 0; i < ivs.Length; i++) { if (ivs[i] == UNSET) { ivs[i] = (int)xoro.NextUInt(MAX + 1); } } if (!criteria.IsIVsCompatible(ivs, 8)) { return(false); } pk.IV_HP = ivs[0]; pk.IV_ATK = ivs[1]; pk.IV_DEF = ivs[2]; pk.IV_SPA = ivs[3]; pk.IV_SPD = ivs[4]; pk.IV_SPE = ivs[5]; // Ability pk.SetAbilityIndex((int)xoro.NextUInt(2)); // Remainder var scale = (IScaledSize)pk; scale.HeightScalar = (int)xoro.NextUInt(0x81) + (int)xoro.NextUInt(0x80); scale.WeightScalar = (int)xoro.NextUInt(0x81) + (int)xoro.NextUInt(0x80); return(true); }