mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-26 22:10:21 +00:00
Eggs: explicitly pass generation instead of calculating
This commit is contained in:
parent
9171d7f87e
commit
0719320e33
10 changed files with 25 additions and 21 deletions
|
@ -91,12 +91,16 @@ namespace PKHeX.Core
|
|||
/// Checks if the <see cref="species"/> can be obtained from a daycare egg.
|
||||
/// </summary>
|
||||
/// <remarks>Chained with the other 2 overloads for incremental checks with different parameters.</remarks>
|
||||
/// <param name="species">Current species</param>
|
||||
public static bool CanHatchAsEgg(int species) => !NoHatchFromEgg.Contains(species);
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the <see cref="species"/>-<see cref="form"/> can exist as a hatched egg in the requested <see cref="generation"/>.
|
||||
/// </summary>
|
||||
/// <remarks>Chained with the other 2 overloads for incremental checks with different parameters.</remarks>
|
||||
/// <param name="species">Current species</param>
|
||||
/// <param name="form">Current form</param>
|
||||
/// <param name="generation">Generation of origin</param>
|
||||
public static bool CanHatchAsEgg(int species, int form, int generation)
|
||||
{
|
||||
if (form == 0)
|
||||
|
@ -116,6 +120,9 @@ namespace PKHeX.Core
|
|||
/// Checks if the <see cref="species"/>-<see cref="form"/> can exist as a hatched egg in the requested <see cref="game"/>.
|
||||
/// </summary>
|
||||
/// <remarks>Chained with the other 2 overloads for incremental checks with different parameters.</remarks>
|
||||
/// <param name="species">Current species</param>
|
||||
/// <param name="form">Current form</param>
|
||||
/// <param name="game">Game of origin</param>
|
||||
public static bool CanHatchAsEgg(int species, int form, GameVersion game)
|
||||
{
|
||||
// Sanity check form for origin
|
||||
|
|
|
@ -187,7 +187,7 @@ namespace PKHeX.Core
|
|||
|
||||
if (pkm.Version != (int)GameVersion.CXD) // no eggs in C/XD
|
||||
{
|
||||
foreach (var z in GenerateEggs(pkm))
|
||||
foreach (var z in GenerateEggs(pkm, 3))
|
||||
yield return z;
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ namespace PKHeX.Core
|
|||
}
|
||||
if (pkm.WasBredEgg)
|
||||
{
|
||||
foreach (var z in GenerateEggs(pkm))
|
||||
foreach (var z in GenerateEggs(pkm, 4))
|
||||
yield return z;
|
||||
}
|
||||
foreach (var z in GetValidEncounterTrades(pkm, chain))
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace PKHeX.Core
|
|||
|
||||
if (pkm.WasBredEgg)
|
||||
{
|
||||
foreach (var z in GenerateEggs(pkm))
|
||||
foreach (var z in GenerateEggs(pkm, 5))
|
||||
{ yield return z; ++ctr; }
|
||||
if (ctr == 0) yield break;
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ namespace PKHeX.Core
|
|||
|
||||
if (pkm.WasBredEgg)
|
||||
{
|
||||
foreach (var z in GenerateEggs(pkm))
|
||||
foreach (var z in GenerateEggs(pkm, 6))
|
||||
{ yield return z; ++ctr; }
|
||||
if (ctr == 0) yield break;
|
||||
}
|
||||
|
|
|
@ -114,7 +114,7 @@ namespace PKHeX.Core
|
|||
|
||||
if (pkm.WasBredEgg)
|
||||
{
|
||||
foreach (var z in GenerateEggs(pkm))
|
||||
foreach (var z in GenerateEggs(pkm, 7))
|
||||
{ yield return z; ++ctr; }
|
||||
if (ctr == 0) yield break;
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ namespace PKHeX.Core
|
|||
|
||||
if (pkm.WasBredEgg)
|
||||
{
|
||||
foreach (var z in GenerateEggs(pkm))
|
||||
foreach (var z in GenerateEggs(pkm, 8))
|
||||
{ yield return z; ++ctr; }
|
||||
if (ctr == 0) yield break;
|
||||
}
|
||||
|
|
|
@ -230,7 +230,7 @@ namespace PKHeX.Core
|
|||
yield break;
|
||||
var eggs = gen == 2
|
||||
? EncounterEggGenerator2.GenerateEggs(pk, chain, all: true)
|
||||
: EncounterEggGenerator.GenerateEggs(pk, chain, all: true);
|
||||
: EncounterEggGenerator.GenerateEggs(pk, chain, gen, all: true);
|
||||
foreach (var egg in eggs)
|
||||
{
|
||||
if (needs.Count == 0)
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using static PKHeX.Core.Legal;
|
||||
|
||||
|
@ -7,23 +6,20 @@ namespace PKHeX.Core
|
|||
{
|
||||
public static class EncounterEggGenerator
|
||||
{
|
||||
public static IEnumerable<EncounterEgg> GenerateEggs(PKM pkm, bool all = false)
|
||||
public static IEnumerable<EncounterEgg> GenerateEggs(PKM pkm, int generation, bool all = false)
|
||||
{
|
||||
var table = EvolutionTree.GetEvolutionTree(pkm, Math.Max(2, pkm.Format));
|
||||
int maxSpeciesOrigin = GetMaxSpeciesOrigin(pkm.Generation);
|
||||
var table = EvolutionTree.GetEvolutionTree(pkm, pkm.Format);
|
||||
int maxSpeciesOrigin = GetMaxSpeciesOrigin(generation);
|
||||
var evos = table.GetValidPreEvolutions(pkm, maxLevel: 100, maxSpeciesOrigin: maxSpeciesOrigin, skipChecks: true);
|
||||
return GenerateEggs(pkm, evos, all);
|
||||
return GenerateEggs(pkm, evos, generation, all);
|
||||
}
|
||||
|
||||
public static IEnumerable<EncounterEgg> GenerateEggs(PKM pkm, IReadOnlyList<EvoCriteria> chain, bool all = false)
|
||||
public static IEnumerable<EncounterEgg> GenerateEggs(PKM pkm, IReadOnlyList<EvoCriteria> chain, int generation, bool all = false)
|
||||
{
|
||||
System.Diagnostics.Debug.Assert(generation >= 3); // if generating Gen2 eggs, use the other generator.
|
||||
int species = pkm.Species;
|
||||
if (!Breeding.CanHatchAsEgg(species))
|
||||
yield break;
|
||||
|
||||
int generation = pkm.Generation;
|
||||
if (generation <= 2)
|
||||
yield break; // can't get eggs; if generating Gen2 eggs, use the other generator.
|
||||
if (!Breeding.CanHatchAsEgg(species, pkm.Form, generation))
|
||||
yield break; // can't originate from eggs
|
||||
|
||||
|
|
|
@ -108,7 +108,7 @@ namespace PKHeX.Core
|
|||
/// Gets the current <see cref="PKM.RelearnMoves"/> array of four moves that might be legal.
|
||||
/// </summary>
|
||||
/// <remarks>Use <see cref="GetSuggestedRelearnMovesFromEncounter"/> instead of calling directly; this method just puts default values in without considering the final moveset.</remarks>
|
||||
public static IReadOnlyList<int> GetSuggestedRelearn(this IEncounterable enc, PKM pkm)
|
||||
public static IReadOnlyList<int> GetSuggestedRelearn(this IEncounterTemplate enc, PKM pkm)
|
||||
{
|
||||
if (VerifyRelearnMoves.ShouldNotHaveRelearnMoves(enc, pkm))
|
||||
return Empty;
|
||||
|
@ -148,7 +148,8 @@ namespace PKHeX.Core
|
|||
// Split-breed species like Budew & Roselia may be legal for one, and not the other.
|
||||
// If we're not a split-breed or are already legal, return.
|
||||
var result = enc.GetEggRelearnMoves(parse, pkm);
|
||||
var split = Breeding.GetSplitBreedGeneration(enc.Generation);
|
||||
int generation = enc.Generation;
|
||||
var split = Breeding.GetSplitBreedGeneration(generation);
|
||||
if (!split.Contains(enc.Species) || enc.Generation <= 2)
|
||||
return result;
|
||||
|
||||
|
@ -159,7 +160,7 @@ namespace PKHeX.Core
|
|||
return result;
|
||||
|
||||
// Try again with the other split-breed species if possible.
|
||||
var incense = EncounterEggGenerator.GenerateEggs(tmp).FirstOrDefault();
|
||||
var incense = EncounterEggGenerator.GenerateEggs(tmp, generation).FirstOrDefault();
|
||||
if (incense is null || incense.Species == enc.Species)
|
||||
return result;
|
||||
|
||||
|
|
Loading…
Reference in a new issue