Mark EncounterSlot/Static types as immutable record types

This commit is contained in:
Kurt 2020-12-23 20:40:59 -08:00
parent 0a3f45218f
commit afdd2bd57e
45 changed files with 67 additions and 81 deletions

View file

@ -67,28 +67,18 @@ namespace PKHeX.Core
if (slot.Form != evo.Form && slot.Form != RandomForm)
break;
var clone = (EncounterSlot6AO)slot.Clone();
MarkSlotDetails(pkm, clone, evo);
// Track some metadata about how this slot was matched.
var ao = (EncounterSlot6AO)slot;
var clone = ao with
{
WhiteFlute = evo.MinLevel < slot.LevelMin,
BlackFlute = evo.MinLevel > slot.LevelMax && evo.MinLevel <= slot.LevelMax + FluteBoostMax,
DexNav = ao.CanDexNav && (evo.MinLevel != slot.LevelMax || pkm.RelearnMove1 != 0 || pkm.AbilityNumber == 4),
};
yield return clone;
break;
}
}
}
private static void MarkSlotDetails(PKM pkm, EncounterSlot6AO slot, EvoCriteria evo)
{
if (slot.LevelMin > evo.MinLevel)
slot.WhiteFlute = true;
if (slot.LevelMax + 1 <= evo.MinLevel && evo.MinLevel <= slot.LevelMax + FluteBoostMax)
slot.BlackFlute = true;
if (!slot.CanDexNav)
return;
if (slot.LevelMax != evo.MinLevel)
slot.DexNav = true;
if (pkm.RelearnMove1 != 0 || pkm.AbilityNumber == 4)
slot.DexNav = true;
}
}
}

View file

@ -6,7 +6,7 @@ namespace PKHeX.Core
/// <summary>
/// Egg Encounter Data
/// </summary>
public class EncounterEgg : IEncounterable
public record EncounterEgg : IEncounterable
{
public int Species { get; }
public int Form { get; }
@ -144,7 +144,7 @@ namespace PKHeX.Core
}
}
public sealed class EncounterEggSplit : EncounterEgg
public sealed record EncounterEggSplit : EncounterEgg
{
public int OtherSpecies { get; }
public EncounterEggSplit(int species, int form, int level, int gen, GameVersion game, int otherSpecies) : base(species, form, level, gen, game) => OtherSpecies = otherSpecies;

View file

@ -5,7 +5,7 @@ namespace PKHeX.Core
/// <summary>
/// Invalid Encounter Data
/// </summary>
public sealed class EncounterInvalid : IEncounterable
public sealed record EncounterInvalid : IEncounterable
{
public static readonly EncounterInvalid Default = new();

View file

@ -5,7 +5,7 @@ namespace PKHeX.Core
/// <summary>
/// Rejected Encounter Data containing a reason why the encounter was rejected (not compatible).
/// </summary>
public sealed class EncounterRejected : IEncounterable
public sealed record EncounterRejected : IEncounterable
{
public readonly IEncounterable Encounter;
public readonly CheckResult Check;

View file

@ -6,7 +6,7 @@ namespace PKHeX.Core
/// Wild Encounter Slot data
/// </summary>
/// <remarks>Wild encounter slots are found as random encounters in-game.</remarks>
public abstract class EncounterSlot : IEncounterable, ILocation
public abstract record EncounterSlot : IEncounterable, ILocation
{
public int Species { get; protected init; }
public int Form { get; protected init; }
@ -23,8 +23,6 @@ namespace PKHeX.Core
protected EncounterSlot(EncounterArea area) => Area = area;
public EncounterSlot Clone() => (EncounterSlot)MemberwiseClone();
public bool FixedLevel => LevelMin == LevelMax;
private protected const string wild = "Wild Encounter";

View file

@ -4,7 +4,7 @@
/// Encounter Slot found in <see cref="GameVersion.Gen1"/>.
/// </summary>
/// <inheritdoc cref="EncounterSlot"/>
public sealed class EncounterSlot1 : EncounterSlot, INumberedSlot
public sealed record EncounterSlot1 : EncounterSlot, INumberedSlot
{
public override int Generation => 1;
public int SlotNumber { get; }

View file

@ -7,7 +7,7 @@
/// Referenced Area object contains Time data which is used for <see cref="GameVersion.C"/> origin data.
/// </remarks>
/// <inheritdoc cref="EncounterSlot"/>
public sealed class EncounterSlot2 : EncounterSlot, INumberedSlot
public sealed record EncounterSlot2 : EncounterSlot, INumberedSlot
{
public override int Generation => 2;
public int SlotNumber { get; }

View file

@ -4,7 +4,7 @@ namespace PKHeX.Core
/// Encounter Slot found in <see cref="GameVersion.Gen3"/>.
/// </summary>
/// <inheritdoc cref="EncounterSlot"/>
public class EncounterSlot3 : EncounterSlot, IMagnetStatic, INumberedSlot
public record EncounterSlot3 : EncounterSlot, IMagnetStatic, INumberedSlot
{
public sealed override int Generation => 3;

View file

@ -4,7 +4,7 @@ namespace PKHeX.Core
/// Encounter Slot found in <see cref="GameVersion.XD"/>.
/// </summary>
/// <inheritdoc cref="EncounterSlot"/>
public sealed class EncounterSlot3PokeSpot : EncounterSlot, INumberedSlot
public sealed record EncounterSlot3PokeSpot : EncounterSlot, INumberedSlot
{
public override int Generation => 3;

View file

@ -9,7 +9,7 @@ namespace PKHeX.Core
/// Handled differently as these slots have fixed moves that are different from their normal level-up moves.
/// </remarks>
/// <inheritdoc cref="EncounterSlot"/>
internal sealed class EncounterSlot3Swarm : EncounterSlot3, IMoveset
internal sealed record EncounterSlot3Swarm : EncounterSlot3, IMoveset
{
public IReadOnlyList<int> Moves { get; }

View file

@ -4,7 +4,7 @@ namespace PKHeX.Core
/// Encounter Slot found in <see cref="GameVersion.Gen4"/>.
/// </summary>
/// <inheritdoc cref="EncounterSlot"/>
public sealed class EncounterSlot4 : EncounterSlot, IMagnetStatic, INumberedSlot, IEncounterTypeTile
public sealed record EncounterSlot4 : EncounterSlot, IMagnetStatic, INumberedSlot, IEncounterTypeTile
{
public override int Generation => 4;
public EncounterType TypeEncounter => ((EncounterArea4)Area).TypeEncounter;

View file

@ -4,7 +4,7 @@ namespace PKHeX.Core
/// Encounter Slot found in <see cref="GameVersion.Gen5"/>.
/// </summary>
/// <inheritdoc cref="EncounterSlot"/>
public sealed class EncounterSlot5 : EncounterSlot
public sealed record EncounterSlot5 : EncounterSlot
{
public override int Generation => 5;

View file

@ -4,15 +4,15 @@ namespace PKHeX.Core
/// Encounter Slot found in <see cref="GameVersion.ORAS"/>.
/// </summary>
/// <inheritdoc cref="EncounterSlot"/>
public sealed class EncounterSlot6AO : EncounterSlot
public sealed record EncounterSlot6AO : EncounterSlot
{
public override int Generation => 6;
public bool CanDexNav => Area.Type != SlotType.Rock_Smash;
public bool Pressure { get; set; }
public bool DexNav { get; set; }
public bool WhiteFlute { get; set; }
public bool BlackFlute { get; set; }
public bool Pressure { get; init; }
public bool DexNav { get; init; }
public bool WhiteFlute { get; init; }
public bool BlackFlute { get; init; }
public EncounterSlot6AO(EncounterArea6AO area, int species, int form, int min, int max) : base(area)
{

View file

@ -4,7 +4,7 @@ namespace PKHeX.Core
/// Encounter Slot found in <see cref="GameVersion.XY"/>.
/// </summary>
/// <inheritdoc cref="EncounterSlot"/>
public sealed class EncounterSlot6XY : EncounterSlot
public sealed record EncounterSlot6XY : EncounterSlot
{
public override int Generation => 6;
public bool Pressure { get; init; }

View file

@ -4,7 +4,7 @@ namespace PKHeX.Core
/// Encounter Slot found in <see cref="GameVersion.Gen7"/>.
/// </summary>
/// <inheritdoc cref="EncounterSlot"/>
public sealed class EncounterSlot7 : EncounterSlot
public sealed record EncounterSlot7 : EncounterSlot
{
public override int Generation => 7;

View file

@ -4,7 +4,7 @@ namespace PKHeX.Core
/// Encounter Slot found in <see cref="GameVersion.GG"/>.
/// </summary>
/// <inheritdoc cref="EncounterSlot"/>
public sealed class EncounterSlot7b : EncounterSlot
public sealed record EncounterSlot7b : EncounterSlot
{
public override int Generation => 7;

View file

@ -4,7 +4,7 @@ namespace PKHeX.Core
/// Encounter Slot found in <see cref="GameVersion.SWSH"/>.
/// </summary>
/// <inheritdoc cref="EncounterSlot"/>
public sealed class EncounterSlot8 : EncounterSlot
public sealed record EncounterSlot8 : EncounterSlot
{
public readonly AreaWeather8 Weather;
public override string LongName => Weather == AreaWeather8.All ? wild : $"{wild} - {Weather.ToString().Replace("_", string.Empty)}";

View file

@ -2,9 +2,9 @@ namespace PKHeX.Core
{
/// <summary>
/// Encounter Slot found in <see cref="GameVersion.Gen7"/> (GO Park, <seealso cref="GameVersion.GG"/>).
/// <inheritdoc/>
/// <inheritdoc cref="EncounterSlotGO" />
/// </summary>
public sealed class EncounterSlot7GO : EncounterSlotGO
public sealed record EncounterSlot7GO : EncounterSlotGO
{
public override int Generation => 7;

View file

@ -2,9 +2,9 @@ namespace PKHeX.Core
{
/// <summary>
/// Encounter Slot representing data transferred to <see cref="GameVersion.Gen8"/> (HOME).
/// <inheritdoc/>
/// <inheritdoc cref="EncounterSlotGO" />
/// </summary>
public sealed class EncounterSlot8GO : EncounterSlotGO
public sealed record EncounterSlot8GO : EncounterSlotGO
{
public override int Generation => 8;

View file

@ -5,7 +5,7 @@ namespace PKHeX.Core
/// <summary>
/// Contains details about an encounter that can be found in <see cref="GameVersion.GO"/>.
/// </summary>
public abstract class EncounterSlotGO : EncounterSlot, IPogoSlot
public abstract record EncounterSlotGO : EncounterSlot, IPogoSlot
{
/// <inheritdoc/>
public int Start { get; }

View file

@ -9,7 +9,7 @@ namespace PKHeX.Core
/// <remarks>
/// Static Encounters are fixed position encounters with properties that are not subject to Wild Encounter conditions.
/// </remarks>
public abstract class EncounterStatic : IEncounterable, IMoveset, ILocation, IVersionSet
public abstract record EncounterStatic : IEncounterable, IMoveset, ILocation, IVersionSet
{
public int Species { get; init; }
public int Form { get; init; }
@ -39,8 +39,6 @@ namespace PKHeX.Core
public bool SkipFormCheck { get; init; }
public bool EggEncounter => EggLocation > 0;
internal EncounterStatic Clone() => (EncounterStatic)MemberwiseClone();
private const string _name = "Static Encounter";
public string Name => _name;
public string LongName => Version == GameVersion.Any ? _name : $"{_name} ({Version})";

View file

@ -4,7 +4,7 @@
/// Generation 1 Static Encounter
/// </summary>
/// <inheritdoc cref="EncounterStatic"/>
public class EncounterStatic1 : EncounterStatic
public record EncounterStatic1 : EncounterStatic
{
public override int Generation => 1;

View file

@ -8,7 +8,7 @@ namespace PKHeX.Core
/// Event data for Generation 1
/// </summary>
/// <inheritdoc cref="EncounterStatic1"/>
public sealed class EncounterStatic1E : EncounterStatic1, IFixedGBLanguage
public sealed record EncounterStatic1E : EncounterStatic1, IFixedGBLanguage
{
public EncounterGBLanguage Language { get; init; } = EncounterGBLanguage.Japanese;

View file

@ -7,7 +7,7 @@ namespace PKHeX.Core
/// Generation 2 Static Encounter
/// </summary>
/// <inheritdoc cref="EncounterStatic"/>
public class EncounterStatic2 : EncounterStatic
public record EncounterStatic2 : EncounterStatic
{
public sealed override int Generation => 2;
public sealed override int Level { get; init; }
@ -81,7 +81,7 @@ namespace PKHeX.Core
}
}
public sealed class EncounterStatic2Odd : EncounterStatic2
public sealed record EncounterStatic2Odd : EncounterStatic2
{
private const int Dizzy = 146;
private static readonly int[] _dizzy = { Dizzy };
@ -106,7 +106,7 @@ namespace PKHeX.Core
}
}
public sealed class EncounterStatic2Roam : EncounterStatic2
public sealed record EncounterStatic2Roam : EncounterStatic2
{
private static readonly int[] Roaming_MetLocation_GSC_Grass =
{

View file

@ -8,7 +8,7 @@ namespace PKHeX.Core
/// Event data for Generation 2
/// </summary>
/// <inheritdoc cref="EncounterStatic2"/>
public sealed class EncounterStatic2E : EncounterStatic2, IFixedGBLanguage
public sealed record EncounterStatic2E : EncounterStatic2, IFixedGBLanguage
{
public EncounterGBLanguage Language { get; init; } = EncounterGBLanguage.Japanese;

View file

@ -7,7 +7,7 @@ namespace PKHeX.Core
/// Generation 3 Static Encounter
/// </summary>
/// <inheritdoc cref="EncounterStatic"/>
public sealed class EncounterStatic3 : EncounterStatic
public sealed record EncounterStatic3 : EncounterStatic
{
public override int Generation => 3;
public bool Roaming { get; init; }

View file

@ -7,7 +7,7 @@ namespace PKHeX.Core
/// Generation 4 Static Encounter
/// </summary>
/// <inheritdoc cref="EncounterStatic"/>
public sealed class EncounterStatic4 : EncounterStatic, IEncounterTypeTile
public sealed record EncounterStatic4 : EncounterStatic, IEncounterTypeTile
{
public override int Generation => 4;

View file

@ -4,7 +4,7 @@
/// Generation 4 Pokéwalker Encounter
/// </summary>
/// <inheritdoc cref="EncounterStatic"/>
public sealed class EncounterStatic4Pokewalker : EncounterStatic
public sealed record EncounterStatic4Pokewalker : EncounterStatic
{
public override int Generation => 4;

View file

@ -6,7 +6,7 @@ namespace PKHeX.Core
/// Generation 5 Static Encounter
/// </summary>
/// <inheritdoc cref="EncounterStatic"/>
public class EncounterStatic5 : EncounterStatic
public record EncounterStatic5 : EncounterStatic
{
public sealed override int Generation => 5;
public bool Roaming { get; init; }

View file

@ -4,7 +4,7 @@
/// Generation 5 Dream Radar gift encounters
/// </summary>
/// <inheritdoc cref="EncounterStatic"/>
public sealed class EncounterStatic5DR : EncounterStatic5
public sealed record EncounterStatic5DR : EncounterStatic5
{
public EncounterStatic5DR(int species, int form, int abilityIndex = 4)
{

View file

@ -4,7 +4,7 @@
/// Generation 5 Static Encounter from N
/// </summary>
/// <inheritdoc cref="EncounterStatic"/>
internal sealed class EncounterStatic5N : EncounterStatic5
internal sealed record EncounterStatic5N : EncounterStatic5
{
public readonly uint PID;
public const bool NSparkle = true;

View file

@ -6,7 +6,7 @@ namespace PKHeX.Core
/// Generation 6 Static Encounter
/// </summary>
/// <inheritdoc cref="EncounterStatic"/>
public sealed class EncounterStatic6 : EncounterStatic, IContestStats
public sealed record EncounterStatic6 : EncounterStatic, IContestStats
{
public override int Generation => 6;

View file

@ -7,7 +7,7 @@ namespace PKHeX.Core
/// Generation 7 Static Encounter
/// </summary>
/// <inheritdoc cref="EncounterStatic"/>
public sealed class EncounterStatic7 : EncounterStatic, IRelearn
public sealed record EncounterStatic7 : EncounterStatic, IRelearn
{
public override int Generation => 7;
public IReadOnlyList<int> Relearn { get; init; } = Array.Empty<int>();

View file

@ -4,7 +4,7 @@
/// Generation 7 Static Encounter (<see cref="GameVersion.GG"/>
/// </summary>
/// <inheritdoc cref="EncounterStatic"/>
public sealed class EncounterStatic7b : EncounterStatic
public sealed record EncounterStatic7b : EncounterStatic
{
public override int Generation => 7;
}

View file

@ -7,7 +7,7 @@ namespace PKHeX.Core
/// Generation 8 Static Encounter
/// </summary>
/// <inheritdoc cref="EncounterStatic"/>
public class EncounterStatic8 : EncounterStatic, IDynamaxLevel, IGigantamax, IRelearn
public record EncounterStatic8 : EncounterStatic, IDynamaxLevel, IGigantamax, IRelearn
{
public sealed override int Generation => 8;
public bool ScriptedNoMarks { get; init; }

View file

@ -8,7 +8,7 @@ namespace PKHeX.Core
/// Generation 8 Nest Encounter (Regular Raid Dens)
/// </summary>
/// <inheritdoc cref="EncounterStatic8Nest{T}"/>
public sealed class EncounterStatic8N : EncounterStatic8Nest<EncounterStatic8N>
public sealed record EncounterStatic8N : EncounterStatic8Nest<EncounterStatic8N>
{
private readonly uint MinRank;
private readonly uint MaxRank;

View file

@ -6,7 +6,7 @@ namespace PKHeX.Core
/// Generation 8 Nest Encounter (Distributed Crystal Data)
/// </summary>
/// <inheritdoc cref="EncounterStatic8Nest{T}"/>
public sealed class EncounterStatic8NC : EncounterStatic8Nest<EncounterStatic8NC>
public sealed record EncounterStatic8NC : EncounterStatic8Nest<EncounterStatic8NC>
{
protected override bool IsMatchLocation(PKM pkm)
{

View file

@ -6,7 +6,7 @@ namespace PKHeX.Core
/// Generation 8 Nest Encounter (Distributed Data)
/// </summary>
/// <inheritdoc cref="EncounterStatic8Nest{T}"/>
public sealed class EncounterStatic8ND : EncounterStatic8Nest<EncounterStatic8ND>
public sealed record EncounterStatic8ND : EncounterStatic8Nest<EncounterStatic8ND>
{
public EncounterStatic8ND(byte lvl, byte dyna, byte flawless)
{

View file

@ -7,7 +7,7 @@ namespace PKHeX.Core
/// Generation 8 Nest Encounter (Raid)
/// </summary>
/// <inheritdoc cref="EncounterStatic"/>
public abstract class EncounterStatic8Nest<T> : EncounterStatic, IGigantamax, IDynamaxLevel where T : EncounterStatic8Nest<T>
public abstract record EncounterStatic8Nest<T> : EncounterStatic, IGigantamax, IDynamaxLevel where T : EncounterStatic8Nest<T>
{
public sealed override int Generation => 8;
public static Func<PKM, T, bool>? VerifyCorrelation { private get; set; }

View file

@ -8,7 +8,7 @@ namespace PKHeX.Core
/// <see cref="EncounterStatic8"/> with multiple references (used for multiple met locations)
/// </summary>
/// <inheritdoc cref="EncounterStatic"/>
public sealed class EncounterStatic8S : EncounterStatic8
public sealed record EncounterStatic8S : EncounterStatic8
{
public override int Location { get => Locations[0]; init { } }
public IReadOnlyList<int> Locations { get; init; } = Array.Empty<int>();

View file

@ -6,7 +6,7 @@ namespace PKHeX.Core
/// Generation 8 Nest Encounter (Max Raid) Underground
/// </summary>
/// <inheritdoc cref="EncounterStatic8Nest{T}"/>
public sealed class EncounterStatic8U : EncounterStatic8Nest<EncounterStatic8U>
public sealed record EncounterStatic8U : EncounterStatic8Nest<EncounterStatic8U>
{
public override int Location { get => MaxLair; init { } }

View file

@ -8,7 +8,7 @@ namespace PKHeX.Core
/// Shadow Pokémon Encounter found in <see cref="GameVersion.CXD"/>
/// </summary>
/// <inheritdoc cref="EncounterStatic"/>
public sealed class EncounterStaticShadow : EncounterStatic
public sealed record EncounterStaticShadow : EncounterStatic
{
public override int Generation => 3;

View file

@ -22,7 +22,7 @@ namespace PKHeX.Core
get => _match;
set
{
if (_match != EncounterInvalid.Default && (value.LevelMin != _match.LevelMin || value.Species != _match.Species))
if (!ReferenceEquals(_match, EncounterInvalid.Default) && (value.LevelMin != _match.LevelMin || value.Species != _match.Species))
_evochains = null; // clear if evo chain has the potential to be different
_match = value;
Parse.Clear();

View file

@ -28,7 +28,7 @@ namespace PKHeX.Core
return;
if (pkm.OT_Gender != 0)
data.AddLine(GetInvalid(LG5OTGenderN, CheckIdentifier.Shiny));
data.AddLine(GetInvalid(LG5OTGenderN, CheckIdentifier.Trainer));
if (pkm.IVTotal != 30*6)
data.AddLine(GetInvalid(LG5IVAll30, CheckIdentifier.IVs));
if (!VerifyNsPKMOTValid(pkm))

View file

@ -21,19 +21,19 @@ namespace PKHeX.Core
public PIDType Method;
public override string OT_Name { get; set; } = string.Empty;
public int OT_Gender { get; set; } = 3;
public int OT_Gender { get; init; } = 3;
public override int TID { get; set; }
public override int SID { get; set; }
public override int Location { get; set; } = 255;
public override int EggLocation { get => 0; set {} }
public override GameVersion Version { get; set; }
public int Language { get; set; } = -1;
public int Language { get; init; } = -1;
public override int Species { get; set; }
public override bool IsEgg { get; set; }
public override IReadOnlyList<int> Moves { get; set; } = Array.Empty<int>();
public bool NotDistributed { get; set; }
public Shiny Shiny { get; set; } = Shiny.Random;
public bool Fateful { get; set; } // Obedience Flag
public bool NotDistributed { get; init; }
public Shiny Shiny { get; init; } = Shiny.Random;
public bool Fateful { get; init; } // Obedience Flag
// Mystery Gift Properties
public override int Generation => 3;
@ -62,12 +62,12 @@ namespace PKHeX.Core
public override int Form { get; set; }
// Synthetic
private int? _metLevel;
private readonly int? _metLevel;
public int Met_Level
{
get => _metLevel ?? (IsEgg ? 0 : Level);
set => _metLevel = value;
init => _metLevel = value;
}
public override PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria)