Use primary constructors for some records

This commit is contained in:
Kurt 2021-12-09 01:08:46 -08:00
parent 51c75dd102
commit 870a38c607
16 changed files with 32 additions and 125 deletions

View file

@ -269,15 +269,7 @@ namespace PKHeX.Core
public record NamedEventValue(string Name, int Index, NamedEventType Type);
public sealed record NamedEventWork : NamedEventValue
{
public readonly IReadOnlyList<NamedEventConst> PredefinedValues;
public NamedEventWork(string Name, int Index, NamedEventType Type, IReadOnlyList<NamedEventConst> values) : base(Name, Index, Type)
{
PredefinedValues = values;
}
}
public sealed record NamedEventWork(string Name, int Index, NamedEventType Type, IReadOnlyList<NamedEventConst> PredefinedValues) : NamedEventValue(Name, Index, Type);
public sealed record NamedEventConst(string Name, ushort Value)
{

View file

@ -5,32 +5,18 @@ namespace PKHeX.Core
/// <summary>
/// Egg Encounter Data
/// </summary>
public sealed record EncounterEgg : IEncounterable
public sealed record EncounterEgg(int Species, int Form, int Level, int Generation, GameVersion Version) : IEncounterable
{
public int Species { get; }
public int Form { get; }
public string Name => "Egg";
public string LongName => "Egg";
public bool EggEncounter => true;
public int LevelMin => Level;
public int LevelMax => Level;
public readonly int Level;
public int Generation { get; }
public GameVersion Version { get; }
public bool IsShiny => false;
public bool CanHaveVoltTackle => Species is (int)Core.Species.Pichu && (Generation > 3 || Version is GameVersion.E);
public EncounterEgg(int species, int form, int level, int gen, GameVersion game)
{
Species = species;
Form = form;
Level = level;
Generation = gen;
Version = game;
}
public PKM ConvertToPKM(ITrainerInfo sav) => ConvertToPKM(sav, EncounterCriteria.Unrestricted);
public PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria)

View file

@ -1,18 +1,9 @@
namespace PKHeX.Core
{
/// <summary>
/// Rejected Encounter Data containing a reason why the encounter was rejected (not compatible).
/// </summary>
public sealed record EncounterRejected
{
public readonly IEncounterable Encounter;
public readonly CheckResult Check;
public string Reason => Check.Comment;
namespace PKHeX.Core;
public EncounterRejected(IEncounterable encounter, CheckResult check)
{
Encounter = encounter;
Check = check;
}
}
/// <summary>
/// Rejected Encounter Data containing a reason why the encounter was rejected (not compatible).
/// </summary>
public sealed record EncounterRejected(IEncounterable Encounter, CheckResult Check)
{
public string Reason => Check.Comment;
}

View file

@ -7,26 +7,13 @@ namespace PKHeX.Core
/// Wild Encounter Slot data
/// </summary>
/// <remarks>Wild encounter slots are found as random encounters in-game.</remarks>
public abstract record EncounterSlot : IEncounterable, ILocation, IEncounterMatch, IFixedAbilityNumber
public abstract record EncounterSlot(EncounterArea Area, int Species, int Form, int LevelMin, int LevelMax) : IEncounterable, ILocation, IEncounterMatch, IFixedAbilityNumber
{
public int Species { get; }
public int Form { get; }
public int LevelMin { get; }
public int LevelMax { get; }
public abstract int Generation { get; }
public bool EggEncounter => false;
public virtual bool IsShiny => false;
protected EncounterSlot(EncounterArea area, int species, int form, int min, int max)
{
Area = area;
Species = species;
Form = form;
LevelMin = min;
LevelMax = max;
}
protected readonly EncounterArea Area;
protected readonly EncounterArea Area = Area;
public GameVersion Version => Area.Version;
public int Location => Area.Location;
public int EggLocation => 0;

View file

@ -8,7 +8,7 @@ namespace PKHeX.Core
/// Generation 4 Static Encounter
/// </summary>
/// <inheritdoc cref="EncounterStatic"/>
public sealed record EncounterStatic4 : EncounterStatic, IGroundTypeTile
public sealed record EncounterStatic4(GameVersion Version) : EncounterStatic(Version), IGroundTypeTile
{
public override int Generation => 4;
@ -18,8 +18,6 @@ namespace PKHeX.Core
/// <summary> <see cref="PK4.GroundTile"/> values permitted for the encounter. </summary>
public GroundTilePermission GroundTile { get; init; } = None;
public EncounterStatic4(GameVersion game) : base(game) { }
protected override bool IsMatchLocation(PKM pkm)
{
if (!Roaming)

View file

@ -6,14 +6,12 @@ namespace PKHeX.Core
/// Generation 5 Static Encounter
/// </summary>
/// <inheritdoc cref="EncounterStatic"/>
public record EncounterStatic5 : EncounterStatic
public record EncounterStatic5(GameVersion Version) : EncounterStatic(Version)
{
public sealed override int Generation => 5;
public bool Roaming { get; init; }
public bool IsWildCorrelationPID => !Roaming && Shiny == Shiny.Random && Species != (int)Core.Species.Crustle;
public EncounterStatic5(GameVersion game) : base(game) { }
protected sealed override bool IsMatchPartial(PKM pkm)
{
if (Ability == 4 && pkm.AbilityNumber != 4 && pkm.Format <= 7) // BW/2 Jellicent collision with wild surf slot, resolved by duplicating the encounter with any abil

View file

@ -4,7 +4,7 @@
/// Generation 6 Static Encounter
/// </summary>
/// <inheritdoc cref="EncounterStatic"/>
public sealed record EncounterStatic6 : EncounterStatic, IContestStats
public sealed record EncounterStatic6(GameVersion Version) : EncounterStatic(Version), IContestStats
{
public override int Generation => 6;
@ -15,8 +15,6 @@
public byte CNT_Tough { get; init; }
public byte CNT_Sheen { get; init; }
public EncounterStatic6(GameVersion game) : base(game) { }
protected override bool IsMatchLocation(PKM pkm)
{
if (base.IsMatchLocation(pkm))

View file

@ -7,15 +7,13 @@ namespace PKHeX.Core
/// Generation 7 Static Encounter
/// </summary>
/// <inheritdoc cref="EncounterStatic"/>
public sealed record EncounterStatic7 : EncounterStatic, IRelearn
public sealed record EncounterStatic7(GameVersion Version) : EncounterStatic(Version), IRelearn
{
public override int Generation => 7;
public IReadOnlyList<int> Relearn { get; init; } = Array.Empty<int>();
public bool IsTotem => FormInfo.IsTotemForm(Species, Form);
public EncounterStatic7(GameVersion game) : base(game) { }
protected override bool IsMatchLocation(PKM pkm)
{
if (EggLocation == Locations.Daycare5 && Relearn.Count == 0 && pkm.RelearnMove1 != 0) // Gift Eevee edge case

View file

@ -4,12 +4,10 @@
/// Generation 7 Static Encounter (<see cref="GameVersion.GG"/>
/// </summary>
/// <inheritdoc cref="EncounterStatic"/>
public sealed record EncounterStatic7b : EncounterStatic
public sealed record EncounterStatic7b(GameVersion Version) : EncounterStatic(Version)
{
public override int Generation => 7;
public EncounterStatic7b(GameVersion game) : base(game) { }
protected override void ApplyDetails(ITrainerInfo sav, EncounterCriteria criteria, PKM pk)
{
base.ApplyDetails(sav, criteria, pk);

View file

@ -8,7 +8,7 @@ namespace PKHeX.Core
/// Generation 8 Static Encounter
/// </summary>
/// <inheritdoc cref="EncounterStatic"/>
public record EncounterStatic8 : EncounterStatic, IDynamaxLevel, IGigantamax, IRelearn, IOverworldCorrelation8
public record EncounterStatic8(GameVersion Version) : EncounterStatic(Version), IDynamaxLevel, IGigantamax, IRelearn, IOverworldCorrelation8
{
public sealed override int Generation => 8;
public bool ScriptedNoMarks { get; init; }
@ -18,8 +18,6 @@ namespace PKHeX.Core
public AreaWeather8 Weather {get; init; } = AreaWeather8.Normal;
public EncounterStatic8(GameVersion game) : base(game) { }
protected override bool IsMatchLevel(PKM pkm, DexLevel evo)
{
var met = pkm.Met_Level;

View file

@ -7,7 +7,7 @@ namespace PKHeX.Core
/// Generation 8 Nest Encounter (Raid)
/// </summary>
/// <inheritdoc cref="EncounterStatic"/>
public abstract record EncounterStatic8Nest<T> : EncounterStatic, IGigantamax, IDynamaxLevel where T : EncounterStatic8Nest<T>
public abstract record EncounterStatic8Nest<T>(GameVersion Version) : EncounterStatic(Version), IGigantamax, IDynamaxLevel where T : EncounterStatic8Nest<T>
{
public sealed override int Generation => 8;
public static Func<PKM, T, bool>? VerifyCorrelation { private get; set; }
@ -17,8 +17,6 @@ namespace PKHeX.Core
public byte DynamaxLevel { get; set; }
public override int Location { get => SharedNest; init { } }
protected EncounterStatic8Nest(GameVersion game) : base(game) { }
public override bool IsMatchExact(PKM pkm, DexLevel evo)
{
if (pkm is IDynamaxLevel d && d.DynamaxLevel < DynamaxLevel)

View file

@ -6,25 +6,15 @@ namespace PKHeX.Core
/// Shadow Pokémon Encounter found in <see cref="GameVersion.CXD"/>
/// </summary>
/// <inheritdoc cref="EncounterStatic"/>
public sealed record EncounterStaticShadow : EncounterStatic
/// <param name="ID">Initial Shadow Gauge value.</param>
/// <param name="Gauge">Initial Shadow Gauge value.</param>
/// <param name="Locks">Team Specification with required <see cref="Species"/>, <see cref="Nature"/> and Gender.</param>
// ReSharper disable NotAccessedPositionalProperty.Global
public sealed record EncounterStaticShadow(GameVersion Version, byte ID, short Gauge, TeamLock[] Locks) : EncounterStatic(Version)
{
// ReSharper restore NotAccessedPositionalProperty.Global
public override int Generation => 3;
/// <summary>
/// Team Specification with required <see cref="Species"/>, <see cref="Nature"/> and Gender.
/// </summary>
public readonly TeamLock[] Locks;
/// <summary>
/// Initial Shadow Gauge value.
/// </summary>
public byte ID { get; }
/// <summary>
/// Initial Shadow Gauge value.
/// </summary>
public short Gauge { get; }
/// <summary>
/// Originates from the EReader scans (Japanese Only)
/// </summary>
@ -32,13 +22,6 @@ namespace PKHeX.Core
public static readonly IReadOnlyList<int> EReaderEmpty = new[] {0,0,0,0,0,0};
public EncounterStaticShadow(GameVersion game, byte id, short gauge, TeamLock[] locks) : base(game)
{
ID = id;
Gauge = gauge;
Locks = locks;
}
protected override bool IsMatchLocation(PKM pkm)
{
if (pkm.Format != 3)

View file

@ -4,15 +4,11 @@
/// Generation 4 Trade Encounter
/// </summary>
/// <inheritdoc cref="EncounterTradeGB"/>
public abstract record EncounterTrade4 : EncounterTrade
public abstract record EncounterTrade4(GameVersion Version) : EncounterTrade(Version)
{
public sealed override int Generation => 4;
protected static readonly string[] RanchOTNames = { string.Empty, "ユカリ", "Hayley", "EULALIE", "GIULIA", "EUKALIA", string.Empty, "Eulalia" };
protected EncounterTrade4(GameVersion game) : base(game)
{
}
}
/// <summary>

View file

@ -4,14 +4,10 @@
/// Generation 5 Trade Encounter
/// </summary>
/// <inheritdoc cref="EncounterTrade"/>
public sealed record EncounterTrade5 : EncounterTrade
public sealed record EncounterTrade5(GameVersion Version) : EncounterTrade(Version)
{
public override int Generation => 5;
public override int Location => Locations.LinkTrade5NPC;
public EncounterTrade5(GameVersion game) : base(game)
{
}
}
public sealed record EncounterTrade5PID : EncounterTrade

View file

@ -4,22 +4,14 @@
/// Generation 6 Trade Encounter
/// </summary>
/// <inheritdoc cref="EncounterTrade"/>
public sealed record EncounterTrade6 : EncounterTrade, IMemoryOT
public sealed record EncounterTrade6(GameVersion Version, int OT_Memory, int OT_Intensity, int OT_Feeling, int OT_TextVar) : EncounterTrade(Version), IMemoryOT
{
public override int Generation => 6;
public override int Location => Locations.LinkTrade6NPC;
public int OT_Memory { get; set; }
public int OT_Intensity { get; set; }
public int OT_Feeling { get; set; }
public int OT_TextVar { get; set; }
public EncounterTrade6(GameVersion game, int m, int i, int f, int v) : base(game)
{
OT_Memory = m;
OT_Intensity = i;
OT_Feeling = f;
OT_TextVar = v;
}
public int OT_Memory { get; set; } = OT_Memory;
public int OT_Intensity { get; set; } = OT_Intensity;
public int OT_Feeling { get; set; } = OT_Feeling;
public int OT_TextVar { get; set; } = OT_TextVar;
protected override void ApplyDetails(ITrainerInfo sav, EncounterCriteria criteria, PKM pk)
{

View file

@ -6,7 +6,7 @@ namespace PKHeX.Core
/// Generation 7 Trade Encounter
/// </summary>
/// <inheritdoc cref="EncounterTrade"/>
public sealed record EncounterTrade7 : EncounterTrade, IMemoryOT
public sealed record EncounterTrade7(GameVersion Version) : EncounterTrade(Version), IMemoryOT
{
public override int Generation => 7;
public override int Location => Locations.LinkTrade6NPC;
@ -16,8 +16,6 @@ namespace PKHeX.Core
public int OT_Feeling { get => 5; set => throw new InvalidOperationException(); }
public int OT_TextVar { get => 40; set => throw new InvalidOperationException(); }
public EncounterTrade7(GameVersion game) : base(game) { }
protected override void ApplyDetails(ITrainerInfo sav, EncounterCriteria criteria, PKM pk)
{
base.ApplyDetails(sav, criteria, pk);