mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-09-12 21:05:27 -05:00
Remove IVersion.set property, as separate interface
I don't want people to mutate IEncounterable.Version; it's only intended to be set on-load
This commit is contained in:
@@ -264,10 +264,10 @@ internal static void MarkEncounterTradeStrings(EncounterTrade[] table, string[][
|
||||
string[] getNames(int i, IEnumerable<string[]> names) => names.Select(z => z.Length > i ? z[i] : string.Empty).ToArray();
|
||||
}
|
||||
|
||||
internal static void MarkEncounterGame(IEnumerable<IVersion> table, GameVersion version)
|
||||
internal static void MarkEncounterGame<T>(IEnumerable<T> table, GameVersion version) where T: IVersion, IVersionSet
|
||||
{
|
||||
foreach (var t in table.Where(z => z.Version == GameVersion.Any))
|
||||
t.Version = version;
|
||||
foreach (var t in table.Where(z => ((IVersion)z).Version == GameVersion.Any))
|
||||
((IVersionSet)t).Version = version;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,16 +17,17 @@ public class EncounterEgg : IEncounterable
|
||||
public int LevelMax => Level;
|
||||
public readonly int Level;
|
||||
public int Generation { get; }
|
||||
public GameVersion Version { get; }
|
||||
|
||||
public EncounterEgg(int species, int form, int level, int gen)
|
||||
public EncounterEgg(int species, int form, int level, int gen, GameVersion game)
|
||||
{
|
||||
Species = species;
|
||||
Form = form;
|
||||
Level = level;
|
||||
Generation = gen;
|
||||
Version = game;
|
||||
}
|
||||
|
||||
public GameVersion Version { get; set; }
|
||||
|
||||
public PKM ConvertToPKM(ITrainerInfo SAV) => ConvertToPKM(SAV, EncounterCriteria.Unrestricted);
|
||||
|
||||
@@ -149,6 +150,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 gen, int otherSpecies) : base(species, form, level, gen) => OtherSpecies = otherSpecies;
|
||||
public EncounterEggSplit(int species, int form, int level, int gen, GameVersion game, int otherSpecies) : base(species, form, level, gen, game) => OtherSpecies = otherSpecies;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,8 +14,8 @@ public sealed class EncounterInvalid : IEncounterable
|
||||
public int LevelMin { get; }
|
||||
public int LevelMax { get; }
|
||||
public bool EggEncounter { get; }
|
||||
public int Generation { get; set; }
|
||||
public GameVersion Version { get; set; }
|
||||
public int Generation { get; }
|
||||
public GameVersion Version { get; }
|
||||
|
||||
public string Name => "Invalid";
|
||||
public string LongName => "Invalid";
|
||||
|
||||
@@ -19,12 +19,7 @@ public sealed class EncounterRejected : IEncounterable
|
||||
public int LevelMin => Encounter.LevelMin;
|
||||
public int LevelMax => Encounter.LevelMax;
|
||||
public int Generation => Encounter.Generation;
|
||||
|
||||
public GameVersion Version
|
||||
{
|
||||
get => Encounter.Version;
|
||||
set => Encounter.Version = value;
|
||||
}
|
||||
public GameVersion Version => Encounter.Version;
|
||||
|
||||
public EncounterRejected(IEncounterable encounter, CheckResult check)
|
||||
{
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace PKHeX.Core
|
||||
/// <summary>
|
||||
/// Wild Encounter Slot data
|
||||
/// </summary>
|
||||
public class EncounterSlot : IEncounterable, IGenerationSet, ILocation
|
||||
public class EncounterSlot : IEncounterable, IGenerationSet, ILocation, IVersionSet
|
||||
{
|
||||
public int Species { get; set; }
|
||||
public int Form { get; set; }
|
||||
|
||||
@@ -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, IGenerationSet, ILocation, IContestStats, IRelearn
|
||||
public class EncounterStatic : IEncounterable, IMoveset, IGenerationSet, ILocation, IContestStats, IRelearn, IVersionSet
|
||||
{
|
||||
public int Species { get; set; }
|
||||
public IReadOnlyList<int> Moves { get; set; } = Array.Empty<int>();
|
||||
|
||||
@@ -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, IGenerationSet, IMoveset, ILocation, IContestStats
|
||||
public class EncounterTrade : IEncounterable, IGenerationSet, IMoveset, ILocation, IContestStats, IVersionSet
|
||||
{
|
||||
public int Species { get; set; }
|
||||
public IReadOnlyList<int> Moves { get; set; } = Array.Empty<int>();
|
||||
|
||||
@@ -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, gen) { Version = ver };
|
||||
yield return new EncounterEgg(e.Species, e.Form, lvl, gen, ver);
|
||||
if (gen > 5 && (pkm.WasTradedEgg || all) && HasOtherGamePair(ver))
|
||||
yield return new EncounterEgg(e.Species, e.Form, lvl, gen) { Version = GetOtherTradePair(ver) };
|
||||
yield return new EncounterEgg(e.Species, e.Form, lvl, gen, 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, gen, e.Species) { Version = ver };
|
||||
yield return new EncounterEggSplit(o.Species, o.Form, lvl, gen, ver, e.Species);
|
||||
if (gen > 5 && (pkm.WasTradedEgg || all) && HasOtherGamePair(ver))
|
||||
yield return new EncounterEggSplit(o.Species, o.Form, lvl, gen, e.Species) { Version = GetOtherTradePair(ver) };
|
||||
yield return new EncounterEggSplit(o.Species, o.Form, lvl, gen, GetOtherTradePair(ver), e.Species);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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, 2) { Version = GameVersion.C }; // gen2 egg
|
||||
yield return new EncounterEgg(eggspec, 0, 5, 2) { Version = GameVersion.GS }; // gen2 egg
|
||||
yield return new EncounterEgg(eggspec, 0, 5, 2, GameVersion.C); // gen2 egg
|
||||
yield return new EncounterEgg(eggspec, 0, 5, 2, GameVersion.GS); // gen2 egg
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,12 @@ namespace PKHeX.Core
|
||||
{
|
||||
public interface IVersion
|
||||
{
|
||||
GameVersion Version { get; set; }
|
||||
GameVersion Version { get; }
|
||||
}
|
||||
|
||||
internal interface IVersionSet
|
||||
{
|
||||
GameVersion Version { set; }
|
||||
}
|
||||
|
||||
public static partial class Extensions
|
||||
@@ -18,12 +23,12 @@ public static GameVersion GetCompatibleVersion(this IVersion ver, GameVersion pr
|
||||
return ver.GetSingleVersion();
|
||||
}
|
||||
|
||||
internal static void SetVersion(this IEnumerable<IVersion> arr, GameVersion game)
|
||||
internal static void SetVersion<T>(this IEnumerable<T> arr, GameVersion game) where T : IVersion, IVersionSet
|
||||
{
|
||||
foreach (var z in arr)
|
||||
{
|
||||
if (z.Version <= 0)
|
||||
z.Version = game;
|
||||
if (((IVersion)z).Version <= 0)
|
||||
((IVersionSet)z).Version = game;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user