Merge IGeneration into IEncounterable

all but egg exposed it; now, just make egg expose it and remove the unnecessary interface

we still need to Set generation for non-eggs/mgift, so have a separate Settable interface for internal purposes.
This commit is contained in:
Kurt 2020-05-17 12:32:28 -07:00
parent 4f40330af9
commit 6164884700
17 changed files with 40 additions and 39 deletions

View File

@ -160,18 +160,18 @@ internal static void MarkEncountersVersion(IEnumerable<EncounterArea> Areas, Gam
}
/// <summary>
/// Sets the <see cref="IGeneration.Generation"/> value.
/// Sets the <see cref="IGenerationSet.Generation"/> value.
/// </summary>
/// <param name="Generation">Generation number to set</param>
/// <param name="Encounters">Ingame encounter data</param>
internal static void MarkEncountersGeneration(int Generation, params IEnumerable<IGeneration>[] Encounters)
internal static void MarkEncountersGeneration(int Generation, params IEnumerable<IGenerationSet>[] Encounters)
{
foreach (var table in Encounters)
MarkEncountersGeneration(Generation, table);
}
/// <summary>
/// Sets the <see cref="IGeneration.Generation"/> value, for use in determining split-generation origins.
/// Sets the <see cref="IGenerationSet.Generation"/> value, for use in determining split-generation origins.
/// </summary>
/// <param name="Generation">Generation number to set</param>
/// <param name="Areas">Ingame encounter data</param>
@ -184,9 +184,9 @@ internal static void MarkEncountersGeneration(int Generation, params IEnumerable
}
}
private static void MarkEncountersGeneration(int Generation, IEnumerable<IGeneration> Encounters)
private static void MarkEncountersGeneration(int Generation, IEnumerable<IGenerationSet> Encounters)
{
foreach (IGeneration enc in Encounters)
foreach (var enc in Encounters)
enc.Generation = Generation;
}

View File

@ -16,12 +16,14 @@ public class EncounterEgg : IEncounterable, IVersion
public int LevelMin => Level;
public int LevelMax => Level;
public readonly int Level;
public int Generation { get; }
public EncounterEgg(int species, int form, int level)
public EncounterEgg(int species, int form, int level, int gen)
{
Species = species;
Form = form;
Level = level;
Generation = gen;
}
public GameVersion Version { get; set; }
@ -147,6 +149,6 @@ private int[] GetCurrentEggMoves(PKM pk, GameVersion version)
public sealed class EncounterEggSplit : EncounterEgg
{
public int OtherSpecies { get; }
public EncounterEggSplit(int species, int form, int level, int otherSpecies) : base(species, form, level) => OtherSpecies = otherSpecies;
public EncounterEggSplit(int species, int form, int level, int gen, int otherSpecies) : base(species, form, level, gen) => OtherSpecies = otherSpecies;
}
}

View File

@ -14,6 +14,7 @@ public sealed class EncounterInvalid : IEncounterable
public int LevelMin { get; }
public int LevelMax { get; }
public bool EggEncounter { get; }
public int Generation { get; set; }
public string Name => "Invalid";
public string LongName => "Invalid";
@ -27,6 +28,7 @@ public EncounterInvalid(PKM pkm)
LevelMin = pkm.Met_Level;
LevelMax = pkm.CurrentLevel;
EggEncounter = pkm.WasEgg;
Generation = pkm.GenNumber;
}
public PKM ConvertToPKM(ITrainerInfo SAV) => ConvertToPKM(SAV, EncounterCriteria.Unrestricted);

View File

@ -18,6 +18,7 @@ public sealed class EncounterRejected : IEncounterable
public bool EggEncounter => Encounter.EggEncounter;
public int LevelMin => Encounter.LevelMin;
public int LevelMax => Encounter.LevelMax;
public int Generation => Encounter.Generation;
public EncounterRejected(IEncounterable encounter, CheckResult check)
{

View File

@ -5,7 +5,7 @@ namespace PKHeX.Core
/// <summary>
/// Wild Encounter Slot data
/// </summary>
public class EncounterSlot : IEncounterable, IGeneration, ILocation, IVersion
public class EncounterSlot : IEncounterable, IGenerationSet, ILocation, IVersion
{
public int Species { get; set; }
public int Form { get; set; }

View File

@ -10,7 +10,7 @@ namespace PKHeX.Core
/// <remarks>
/// Static Encounters are fixed position encounters with properties that are not subject to Wild Encounter conditions.
/// </remarks>
public class EncounterStatic : IEncounterable, IMoveset, IGeneration, ILocation, IContestStats, IVersion, IRelearn
public class EncounterStatic : IEncounterable, IMoveset, IGenerationSet, ILocation, IContestStats, IVersion, IRelearn
{
public int Species { get; set; }
public IReadOnlyList<int> Moves { get; set; } = Array.Empty<int>();

View File

@ -10,7 +10,7 @@ namespace PKHeX.Core
/// <remarks>
/// Trade data is fixed level in all cases except for the first few generations of games.
/// </remarks>
public class EncounterTrade : IEncounterable, IMoveset, IGeneration, ILocation, IContestStats, IVersion
public class EncounterTrade : IEncounterable, IGenerationSet, IMoveset, ILocation, IContestStats, IVersion
{
public int Species { get; set; }
public IReadOnlyList<int> Moves { get; set; } = Array.Empty<int>();

View File

@ -36,9 +36,9 @@ public static IEnumerable<EncounterEgg> GenerateEggs(PKM pkm, IReadOnlyList<EvoC
var e = GetBaseSpecies(vs, 0);
if (e.Species <= max && !NoHatchFromEggFormGen(e.Species, e.Form, ver))
{
yield return new EncounterEgg(e.Species, e.Form, lvl) { Version = ver };
yield return new EncounterEgg(e.Species, e.Form, lvl, gen) { Version = ver };
if (gen > 5 && (pkm.WasTradedEgg || all) && HasOtherGamePair(ver))
yield return new EncounterEgg(e.Species, e.Form, lvl) { Version = GetOtherTradePair(ver) };
yield return new EncounterEgg(e.Species, e.Form, lvl, gen) { Version = GetOtherTradePair(ver) };
}
if (!GetSplitBreedGeneration(gen).Contains(species))
@ -47,9 +47,9 @@ public static IEnumerable<EncounterEgg> GenerateEggs(PKM pkm, IReadOnlyList<EvoC
var o = GetBaseSpecies(vs, 1);
if (o.Species <= max && !NoHatchFromEggFormGen(o.Species, o.Form, ver))
{
yield return new EncounterEggSplit(o.Species, o.Form, lvl, e.Species) { Version = ver };
yield return new EncounterEggSplit(o.Species, o.Form, lvl, gen, e.Species) { Version = ver };
if (gen > 5 && (pkm.WasTradedEgg || all) && HasOtherGamePair(ver))
yield return new EncounterEggSplit(o.Species, o.Form, lvl, e.Species) { Version = GetOtherTradePair(ver) };
yield return new EncounterEggSplit(o.Species, o.Form, lvl, gen, e.Species) { Version = GetOtherTradePair(ver) };
}
}

View File

@ -48,7 +48,7 @@ private static IEnumerable<IEncounterable> GetEncounters12(PKM pkm, LegalInfo in
foreach (var z in GenerateFilteredEncounters12(pkm))
{
info.Generation = z is IGeneration g ? g.Generation : 2;
info.Generation = z.Generation;
info.Game = ((IVersion)z).Version;
yield return z;
}
@ -191,8 +191,8 @@ private static IEnumerable<IEncounterable> GenerateRawEncounters12(PKM pkm, Game
{
int eggspec = GetBaseEggSpecies(pkm).Species;
if (ParseSettings.AllowGen2Crystal(pkm))
yield return new EncounterEgg(eggspec, 0, 5) { Version = GameVersion.C }; // gen2 egg
yield return new EncounterEgg(eggspec, 0, 5) { Version = GameVersion.GS }; // gen2 egg
yield return new EncounterEgg(eggspec, 0, 5, 2) { Version = GameVersion.C }; // gen2 egg
yield return new EncounterEgg(eggspec, 0, 5, 2) { Version = GameVersion.GS }; // gen2 egg
}
}
@ -234,7 +234,7 @@ private static IEnumerable<IEncounterable> GenerateFilteredEncounters12(PKM pkm)
{
var move = GetPreferredGBIterator(pkm, g1i, g2i);
var obj = move.Peek();
int gen = obj is IGeneration g ? g.Generation : 2; // only eggs don't implement interface
int gen = obj.Generation;
if (gen == 1 && (pkm.Korean || (obj is EncounterTrade t && !IsEncounterTrade1Valid(pkm, t))))
deferred.Add(obj);

View File

@ -12,6 +12,7 @@ public interface IEncounterable
bool EggEncounter { get; }
int LevelMin { get; }
int LevelMax { get; }
int Generation { get; }
PKM ConvertToPKM(ITrainerInfo SAV);
PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria);

View File

@ -105,7 +105,7 @@ private EncounterSummary(IEncounterable z)
private static string GetLocationName(IEncounterable z)
{
var gen = z is IGeneration g ? g.Generation : -1;
var gen = z.Generation;
var version = z is IVersion v ? (int)v.Version : -1;
if (gen < 0 && version > 0)
gen = ((GameVersion)version).GetGeneration();

View File

@ -21,7 +21,7 @@ public ValidEncounterMoves(PKM pkm, LevelUpRestriction restrict, IEncounterable
{
var level = Legal.GetValidMovesAllGens(pkm, restrict.EvolutionChains, minLvLG1: restrict.MinimumLevelGen1, minLvLG2: restrict.MinimumLevelGen2, Tutor: false, Machine: false, RemoveTransferHM: false);
if (encounter is IGeneration g && level[g.Generation] is List<int> x)
if (level[encounter.Generation] is List<int> x)
AddEdgeCaseMoves(x, encounter, pkm);
LevelUpMoves = level;

View File

@ -47,7 +47,8 @@ private static CheckMoveResult[] ParseMovesForEncounters(PKM pkm, LegalInfo info
IReadOnlyList<int> defaultG2LevelMoves = Array.Empty<int>();
var defaultTradeback = pkm.TradebackStatus;
bool gb = false;
if (info.EncounterMatch is IGeneration g && g.Generation <= 2)
int gen = info.EncounterMatch.Generation;
if (gen <= 2)
{
gb = true;
defaultG1LevelMoves = info.EncounterMoves.LevelUpMoves[1];
@ -55,11 +56,11 @@ private static CheckMoveResult[] ParseMovesForEncounters(PKM pkm, LegalInfo info
defaultG2LevelMoves = info.EncounterMoves.LevelUpMoves[2];
// Generation 1 can have different minimum level in different encounter of the same species; update valid level moves
UpdateGen1LevelUpMoves(pkm, info.EncounterMoves, restrict.MinimumLevelGen1, g.Generation, info);
UpdateGen1LevelUpMoves(pkm, info.EncounterMoves, restrict.MinimumLevelGen1, gen, info);
// The same for Generation 2; if move reminder from Stadium 2 is not allowed
if (!ParseSettings.AllowGen2MoveReminder(pkm) && pkm.InhabitedGeneration(2))
UpdateGen2LevelUpMoves(pkm, info.EncounterMoves, restrict.MinimumLevelGen2, g.Generation, info);
UpdateGen2LevelUpMoves(pkm, info.EncounterMoves, restrict.MinimumLevelGen2, gen, info);
}
var res = info.Generation < 6
@ -167,7 +168,9 @@ private static CheckMoveResult[] ParseMovesPre3DS(PKM pkm, int[] Moves, LegalInf
}
if (info.EncounterMatch is EncounterEgg e)
return ParseMovesWasEggPreRelearn(pkm, Moves, info, e);
if (info.Generation <= 2 && info.EncounterMatch is IGeneration g && (g.Generation == 1 || (g.Generation == 2 && !ParseSettings.AllowGen2MoveReminder(pkm)))) // fixed encounter moves without relearning
int gen = info.EncounterMatch.Generation;
if (gen <= 2 && (gen == 1 || (gen == 2 && !ParseSettings.AllowGen2MoveReminder(pkm)))) // fixed encounter moves without relearning
return ParseMovesGenGB(pkm, Moves, info);
return ParseMovesSpecialMoveset(pkm, Moves, info);
@ -181,7 +184,7 @@ private static CheckMoveResult[] ParseMovesGenGB(PKM pkm, int[] Moves, LegalInfo
return ParseMovesSpecialMoveset(pkm, Moves, info);
var InitialMoves = Array.Empty<int>();
var SpecialMoves = GetSpecialMoves(info.EncounterMatch);
var games = info.EncounterMatch is IGeneration g && g.Generation == 1 ? GBRestrictions.GetGen1Versions(info) : GBRestrictions.GetGen2Versions(info, pkm.Korean);
var games = info.EncounterMatch.Generation == 1 ? GBRestrictions.GetGen1Versions(info) : GBRestrictions.GetGen2Versions(info, pkm.Korean);
foreach (var ver in games)
{
var VerInitialMoves = MoveLevelUp.GetEncounterMoves(G1Encounter.Species, 0, G1Encounter.LevelMin, ver);

View File

@ -1,15 +1,7 @@
namespace PKHeX.Core
{
/// <summary>
/// Interface that exposes a Generation value for the object.
/// </summary>
public interface IGeneration
internal interface IGenerationSet
{
int Generation { get; set; }
}
public static partial class Extensions
{
internal static PKM GetBlank(this IGeneration gen) => PKMConverter.GetBlank(gen.Generation);
int Generation { set; }
}
}

View File

@ -101,7 +101,7 @@ private CheckResult VerifyAbility345(LegalityAnalysis data, IReadOnlyList<int> a
private CheckResult VerifyFixedAbility(LegalityAnalysis data, IReadOnlyList<int> abilities, AbilityState state, int EncounterAbility, int abilval)
{
var pkm = data.pkm;
if (data.Info.EncounterMatch is IGeneration g && g.Generation >= 6)
if (data.Info.EncounterMatch.Generation >= 6)
{
if (IsAbilityCapsuleModified(pkm, abilities, EncounterAbility))
return GetValid(LAbilityCapsuleUsed);

View File

@ -41,7 +41,7 @@ public override MysteryGift Clone()
/// <summary>
/// Mystery Gift Template File
/// </summary>
public abstract class MysteryGift : IEncounterable, IMoveset, IRelearn, IGeneration, ILocation
public abstract class MysteryGift : IEncounterable, IMoveset, IRelearn, ILocation
{
/// <summary>
/// Determines whether or not the given length of bytes is valid for a mystery gift.

View File

@ -194,7 +194,7 @@ private IEnumerable<IEncounterable> SearchDatabase()
// when all sprites in new size are available, remove this filter
results = SAV is SAV8SWSH
? results.Where(z => ((PersonalInfoSWSH)PersonalTable.SWSH.GetFormeEntry(z.Species, z.Form)).IsPresentInGame)
: results.Where(z => !(z is IGeneration g) || g.Generation <= 7);
: results.Where(z => z.Generation <= 7);
return results;
}
@ -286,7 +286,7 @@ private void FillPKXBoxes(int start)
{
var enc = Results[i + begin];
var form = GetForm(enc);
PKXBOXES[i].Image = SpriteUtil.GetSprite(enc.Species, form, 0, 0, 0, enc.EggEncounter, false, enc is IGeneration g ? g.Generation : -1);
PKXBOXES[i].Image = SpriteUtil.GetSprite(enc.Species, form, 0, 0, 0, enc.EggEncounter, false, enc.Generation);
}
for (int i = end; i < RES_MAX; i++)
PKXBOXES[i].Image = null;