Split IContestStats, mark trades as records

This commit is contained in:
Kurt 2020-12-24 00:06:40 -08:00
parent afdd2bd57e
commit 43dd390f21
26 changed files with 114 additions and 70 deletions

View file

@ -6,17 +6,29 @@ namespace PKHeX.Core
/// Generation 6 Static Encounter
/// </summary>
/// <inheritdoc cref="EncounterStatic"/>
public sealed record EncounterStatic6 : EncounterStatic, IContestStats
public sealed record EncounterStatic6 : EncounterStatic, IContestStats, IContestStatsRecord
{
public override int Generation => 6;
internal IReadOnlyList<int> Contest { init => this.SetContestStats(value); }
public int CNT_Cool { get; set; }
public int CNT_Beauty { get; set; }
public int CNT_Cute { get; set; }
public int CNT_Smart { get; set; }
public int CNT_Tough { get; set; }
public int CNT_Sheen { get; set; }
public int CNT_Cool { get; init; }
public int CNT_Beauty { get; init; }
public int CNT_Cute { get; init; }
public int CNT_Smart { get; init; }
public int CNT_Tough { get; init; }
public int CNT_Sheen { get; init; }
public IReadOnlyList<int> Contest
{
init
{
CNT_Cool = value[0];
CNT_Beauty = value[1];
CNT_Cute = value[2];
CNT_Smart = value[3];
CNT_Tough = value[4];
CNT_Sheen = value[5];
}
}
protected override bool IsMatchLocation(PKM pkm)
{

View file

@ -13,6 +13,7 @@ namespace PKHeX.Core
public bool ScriptedNoMarks { get; init; }
public bool CanGigantamax { get; set; }
public byte DynamaxLevel { get; set; }
public IReadOnlyList<int> Relearn { get; init; } = Array.Empty<int>();
protected override bool IsMatchLevel(PKM pkm, DexLevel evo)
{
@ -31,7 +32,5 @@ namespace PKHeX.Core
return false;
return base.IsMatch(pkm, evo);
}
public IReadOnlyList<int> Relearn { get; init; } = 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 abstract class EncounterTrade : IEncounterable, IMoveset, ILocation, IVersionSet
public abstract record EncounterTrade : IEncounterable, IMoveset, ILocation, IVersionSet
{
public int Species { get; init; }
public int Form { get; init; }

View file

@ -9,7 +9,7 @@ namespace PKHeX.Core
/// Generation 1 specific value used in detecting unmodified/un-traded Generation 1 Trade Encounter data.
/// Species & Minimum level (legal) possible to acquire at.
/// </remarks>
public sealed class EncounterTrade1 : EncounterTradeGB
public sealed record EncounterTrade1 : EncounterTradeGB
{
public override int Generation => 1;
public override int LevelMin => CanObtainMinGSC() ? LevelMinGSC : LevelMinRBY;

View file

@ -2,7 +2,7 @@
namespace PKHeX.Core
{
public sealed class EncounterTrade2 : EncounterTradeGB
public sealed record EncounterTrade2 : EncounterTradeGB
{
public override int Generation => 2;

View file

@ -2,7 +2,7 @@
namespace PKHeX.Core
{
public sealed class EncounterTrade3 : EncounterTrade, IContestStats
public sealed record EncounterTrade3 : EncounterTrade, IContestStats, IContestStatsRecord
{
public override int Generation => 3;
@ -11,13 +11,25 @@ namespace PKHeX.Core
/// </summary>
public readonly uint PID;
internal IReadOnlyList<int> Contest { init => this.SetContestStats(value); }
public int CNT_Cool { get; set; }
public int CNT_Beauty { get; set; }
public int CNT_Cute { get; set; }
public int CNT_Smart { get; set; }
public int CNT_Tough { get; set; }
public int CNT_Sheen { get; set; }
public int CNT_Cool { get; init; }
public int CNT_Beauty { get; init; }
public int CNT_Cute { get; init; }
public int CNT_Smart { get; init; }
public int CNT_Tough { get; init; }
public int CNT_Sheen { get; init; }
public IReadOnlyList<int> Contest
{
init
{
CNT_Cool = value[0];
CNT_Beauty = value[1];
CNT_Cute = value[2];
CNT_Smart = value[3];
CNT_Tough = value[4];
CNT_Sheen = value[5];
}
}
public EncounterTrade3(uint pid)
{

View file

@ -2,7 +2,7 @@
namespace PKHeX.Core
{
public sealed class EncounterTrade4PID : EncounterTrade, IContestStats
public sealed record EncounterTrade4PID : EncounterTrade, IContestStats, IContestStatsRecord
{
public override int Generation => 4;
@ -17,13 +17,25 @@ namespace PKHeX.Core
Shiny = Shiny.FixedValue;
}
internal IReadOnlyList<int> Contest { init => this.SetContestStats(value); }
public int CNT_Cool { get; set; }
public int CNT_Beauty { get; set; }
public int CNT_Cute { get; set; }
public int CNT_Smart { get; set; }
public int CNT_Tough { get; set; }
public int CNT_Sheen { get; set; }
public int CNT_Cool { get; init; }
public int CNT_Beauty { get; init; }
public int CNT_Cute { get; init; }
public int CNT_Smart { get; init; }
public int CNT_Tough { get; init; }
public int CNT_Sheen { get; init; }
public IReadOnlyList<int> Contest
{
init
{
CNT_Cool = value[0];
CNT_Beauty = value[1];
CNT_Cute = value[2];
CNT_Smart = value[3];
CNT_Tough = value[4];
CNT_Sheen = value[5];
}
}
public override bool IsMatch(PKM pkm, DexLevel evo)
{
@ -63,7 +75,7 @@ namespace PKHeX.Core
}
}
public sealed class EncounterTrade4Ranch : EncounterTrade
public sealed record EncounterTrade4Ranch : EncounterTrade
{
public override int Generation => 4;

View file

@ -1,11 +1,11 @@
namespace PKHeX.Core
{
public sealed class EncounterTrade5 : EncounterTrade
public sealed record EncounterTrade5 : EncounterTrade
{
public override int Generation => 5;
}
public sealed class EncounterTrade5PID : EncounterTrade
public sealed record EncounterTrade5PID : EncounterTrade
{
public override int Generation => 5;

View file

@ -1,6 +1,6 @@
namespace PKHeX.Core
{
public sealed class EncounterTrade6 : EncounterTrade, IMemoryOT
public sealed record EncounterTrade6 : EncounterTrade, IMemoryOT
{
public override int Generation => 6;
public int OT_Memory { get; set; }

View file

@ -2,7 +2,7 @@
namespace PKHeX.Core
{
public sealed class EncounterTrade7 : EncounterTrade, IMemoryOT
public sealed record EncounterTrade7 : EncounterTrade, IMemoryOT
{
public override int Generation => 7;
// immutable setters

View file

@ -1,6 +1,6 @@
namespace PKHeX.Core
{
public sealed class EncounterTrade7b : EncounterTrade
public sealed record EncounterTrade7b : EncounterTrade
{
public override int Generation => 7;
}

View file

@ -3,12 +3,12 @@ using System.Collections.Generic;
namespace PKHeX.Core
{
public sealed class EncounterTrade8 : EncounterTrade, IDynamaxLevel, IRelearn, IMemoryOT
public sealed record EncounterTrade8 : EncounterTrade, IDynamaxLevel, IRelearn, IMemoryOT
{
public override int Generation => 8;
public byte DynamaxLevel { get; set; }
public IReadOnlyList<int> Relearn { get; set; } = Array.Empty<int>();
public IReadOnlyList<int> Relearn { get; init; } = Array.Empty<int>();
public int OT_Memory { get; set; }
public int OT_TextVar { get; set; }

View file

@ -1,6 +1,6 @@
namespace PKHeX.Core
{
public abstract class EncounterTradeGB : EncounterTrade
public abstract record EncounterTradeGB : EncounterTrade
{
protected EncounterTradeGB(int species, int level)
{

View file

@ -7,7 +7,7 @@ namespace PKHeX.Core
/// <summary>
/// Generation 5 Mystery Gift Template File
/// </summary>
public sealed class PGF : DataMysteryGift, IRibbonSetEvent3, IRibbonSetEvent4, ILangNick, IContestStats, INature
public sealed class PGF : DataMysteryGift, IRibbonSetEvent3, IRibbonSetEvent4, ILangNick, IContestStats, IContestStatsMutable, INature
{
public const int Size = 0xCC;
public override int Generation => 5;

View file

@ -8,7 +8,7 @@ namespace PKHeX.Core
/// <summary>
/// Generation 6 Mystery Gift Template File
/// </summary>
public sealed class WC6 : DataMysteryGift, IRibbonSetEvent3, IRibbonSetEvent4, ILangNick, IContestStats, INature, IMemoryOT
public sealed class WC6 : DataMysteryGift, IRibbonSetEvent3, IRibbonSetEvent4, ILangNick, IContestStats, IContestStatsMutable, INature, IMemoryOT
{
public const int Size = 0x108;
public const uint EonTicketConst = 0x225D73C2;

View file

@ -8,7 +8,7 @@ namespace PKHeX.Core
/// <summary>
/// Generation 7 Mystery Gift Template File
/// </summary>
public sealed class WC7 : DataMysteryGift, IRibbonSetEvent3, IRibbonSetEvent4, ILangNick, IContestStats, INature, IMemoryOT
public sealed class WC7 : DataMysteryGift, IRibbonSetEvent3, IRibbonSetEvent4, ILangNick, IContestStats, IContestStatsMutable, INature, IMemoryOT
{
public const int Size = 0x108;
public override int Generation => 7;

View file

@ -4,7 +4,7 @@ using System.Collections.Generic;
namespace PKHeX.Core
{
/// <summary> Generation 5 <see cref="PKM"/> format. </summary>
public sealed class PK5 : PKM, IRibbonSetEvent3, IRibbonSetEvent4, IRibbonSetUnique3, IRibbonSetUnique4, IRibbonSetCommon3, IRibbonSetCommon4, IContestStats
public sealed class PK5 : PKM, IRibbonSetEvent3, IRibbonSetEvent4, IRibbonSetUnique3, IRibbonSetUnique4, IRibbonSetCommon3, IRibbonSetCommon4, IContestStats, IContestStatsMutable
{
private static readonly ushort[] Unused =
{

View file

@ -5,7 +5,7 @@ namespace PKHeX.Core
{
/// <summary> Generation 6 <see cref="PKM"/> format. </summary>
public sealed class PK6 : G6PKM, IRibbonSetEvent3, IRibbonSetEvent4, IRibbonSetCommon3, IRibbonSetCommon4, IRibbonSetCommon6,
IContestStats, IGeoTrack, ISuperTrain, IFormArgument, ITrainerMemories, IAffection
IContestStats, IContestStatsMutable, IGeoTrack, ISuperTrain, IFormArgument, ITrainerMemories, IAffection
{
private static readonly ushort[] Unused =
{

View file

@ -5,7 +5,7 @@ namespace PKHeX.Core
{
/// <summary> Generation 7 <see cref="PKM"/> format. </summary>
public sealed class PK7 : G6PKM, IRibbonSetEvent3, IRibbonSetEvent4, IRibbonSetCommon3, IRibbonSetCommon4, IRibbonSetCommon6, IRibbonSetCommon7,
IContestStats, IHyperTrain, IGeoTrack, ISuperTrain, IFormArgument, ITrainerMemories, IAffection
IContestStats, IContestStatsMutable, IHyperTrain, IGeoTrack, ISuperTrain, IFormArgument, ITrainerMemories, IAffection
{
private static readonly ushort[] Unused =
{

View file

@ -6,7 +6,7 @@ namespace PKHeX.Core
/// <summary> Generation 8 <see cref="PKM"/> format. </summary>
public sealed class PK8 : PKM,
IRibbonSetEvent3, IRibbonSetEvent4, IRibbonSetCommon3, IRibbonSetCommon4, IRibbonSetCommon6, IRibbonSetCommon7, IRibbonSetCommon8, IRibbonSetMark8,
IContestStats, IHyperTrain, IScaledSize, IGigantamax, IFavorite, IDynamaxLevel, IRibbonIndex, IHandlerLanguage, IFormArgument, IHomeTrack, IBattleVersion, ITrainerMemories
IContestStats, IContestStatsMutable, IHyperTrain, IScaledSize, IGigantamax, IFavorite, IDynamaxLevel, IRibbonIndex, IHandlerLanguage, IFormArgument, IHomeTrack, IBattleVersion, ITrainerMemories
{
private static readonly ushort[] Unused =
{

View file

@ -3,7 +3,7 @@
/// <summary>
/// Generation 3 Base <see cref="PKM"/> Class
/// </summary>
public abstract class G3PKM : PKM, IRibbonSetEvent3, IRibbonSetCommon3, IRibbonSetUnique3, IRibbonSetOnly3, IContestStats
public abstract class G3PKM : PKM, IRibbonSetEvent3, IRibbonSetCommon3, IRibbonSetUnique3, IRibbonSetOnly3, IContestStats, IContestStatsMutable
{
protected G3PKM(byte[] data) : base(data) { }
protected G3PKM(int size) : base(size) { }

View file

@ -1,6 +1,6 @@
namespace PKHeX.Core
{
public abstract class G4PKM : PKM, IRibbonSetEvent3, IRibbonSetEvent4, IRibbonSetUnique3, IRibbonSetUnique4, IRibbonSetCommon3, IRibbonSetCommon4, IContestStats
public abstract class G4PKM : PKM, IRibbonSetEvent3, IRibbonSetEvent4, IRibbonSetUnique3, IRibbonSetUnique4, IRibbonSetCommon3, IRibbonSetCommon4, IContestStats, IContestStatsMutable
{
protected G4PKM(byte[] data) : base(data) { }
protected G4PKM(int size) : base(size) { }

View file

@ -4,29 +4,38 @@ namespace PKHeX.Core
{
public interface IContestStats
{
int CNT_Cool { get; set; }
int CNT_Beauty { get; set; }
int CNT_Cute { get; set; }
int CNT_Smart { get; set; }
int CNT_Tough { get; set; }
int CNT_Sheen { get; set; }
int CNT_Cool { get; }
int CNT_Beauty { get; }
int CNT_Cute { get; }
int CNT_Smart { get; }
int CNT_Tough { get; }
int CNT_Sheen { get; }
}
public interface IContestStatsMutable
{
int CNT_Cool { set; }
int CNT_Beauty { set; }
int CNT_Cute { set; }
int CNT_Smart { set; }
int CNT_Tough { set; }
int CNT_Sheen { set; }
}
public interface IContestStatsRecord
{
// int CNT_Cool { init; }
// int CNT_Beauty { init; }
// int CNT_Cute { init; }
// int CNT_Smart { init; }
// int CNT_Tough { init; }
// int CNT_Sheen { init; }
IReadOnlyList<int> Contest { init; }
}
public static partial class Extensions
{
public static void SetContestStats(this IContestStats dest, IReadOnlyList<int> stats)
{
if (stats.Count != 6)
return;
dest.CNT_Cool = stats[0];
dest.CNT_Beauty = stats[1];
dest.CNT_Cute = stats[2];
dest.CNT_Smart = stats[3];
dest.CNT_Tough = stats[4];
dest.CNT_Sheen = stats[5];
}
public static int[] GetContestStats(this IContestStats stats) => new[]
{
stats.CNT_Cool,
@ -78,7 +87,7 @@ namespace PKHeX.Core
return true;
}
public static void CopyContestStatsTo(this IContestStats source, IContestStats dest)
public static void CopyContestStatsTo(this IContestStats source, IContestStatsMutable dest)
{
dest.CNT_Cool = source.CNT_Cool;
dest.CNT_Beauty = source.CNT_Beauty;

View file

@ -2,7 +2,7 @@
namespace PKHeX.Core
{
public sealed class Roamer3 : IContestStats
public sealed class Roamer3 : IContestStats, IContestStatsMutable
{
private readonly SaveFile SAV;
private readonly int Offset;

View file

@ -4,7 +4,7 @@ using PKHeX.Core;
namespace PKHeX.WinForms.Controls
{
public partial class ContestStat : UserControl, IContestStats
public partial class ContestStat : UserControl, IContestStats, IContestStatsMutable
{
public ContestStat()
{

View file

@ -219,7 +219,7 @@ namespace PKHeX.WinForms.Controls
pk.Nature = WinFormsUtil.GetIndex(CB_Nature);
pk.Gender = PKX.GetGenderFromString(Label_Gender.Text);
if (pk is IContestStats s)
if (pk is IContestStatsMutable s)
Contest.CopyContestStatsTo(s);
pk.FatefulEncounter = CHK_Fateful.Checked;