diff --git a/PKHeX.Core/Legality/Encounters/EncounterStatic.cs b/PKHeX.Core/Legality/Encounters/EncounterStatic.cs
index 6e6c184a2..29f1bf8a6 100644
--- a/PKHeX.Core/Legality/Encounters/EncounterStatic.cs
+++ b/PKHeX.Core/Legality/Encounters/EncounterStatic.cs
@@ -6,7 +6,7 @@
///
/// Static Encounters are fixed position encounters with properties that are not subject to Wild Encounter conditions.
///
- public class EncounterStatic : IEncounterable, IMoveset, IGeneration, ILocation
+ public class EncounterStatic : IEncounterable, IMoveset, IGeneration, ILocation, IContestStats
{
public int Species { get; set; }
public int[] Moves { get; set; }
@@ -29,7 +29,15 @@ public class EncounterStatic : IEncounterable, IMoveset, IGeneration, ILocation
public int[] IVs { get; set; }
public int FlawlessIVCount { get; internal set; }
public bool IV3 { set => FlawlessIVCount = value ? 3 : 0; }
- public int[] Contest { get; set; }
+
+ public int[] Contest { set => 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 HeldItem { get; set; }
public int EggCycles { get; set; }
@@ -45,7 +53,6 @@ private void CloneArrays()
Moves = (int[])Moves?.Clone();
Relearn = (int[])Relearn.Clone();
IVs = (int[])IVs?.Clone();
- Contest = (int[])Contest?.Clone();
}
internal virtual EncounterStatic Clone()
{
diff --git a/PKHeX.Core/Legality/Encounters/EncounterTrade.cs b/PKHeX.Core/Legality/Encounters/EncounterTrade.cs
index 319875c27..63dbce9a9 100644
--- a/PKHeX.Core/Legality/Encounters/EncounterTrade.cs
+++ b/PKHeX.Core/Legality/Encounters/EncounterTrade.cs
@@ -6,7 +6,7 @@
///
/// Trade data is fixed level in all cases except for the first few generations of games.
///
- public class EncounterTrade : IEncounterable, IMoveset, IGeneration, ILocation
+ public class EncounterTrade : IEncounterable, IMoveset, IGeneration, ILocation, IContestStats
{
public int Species { get; set; }
public int[] Moves { get; set; }
@@ -22,7 +22,13 @@ public class EncounterTrade : IEncounterable, IMoveset, IGeneration, ILocation
public int SID { get; set; }
public GameVersion Version { get; set; } = GameVersion.Any;
public int[] IVs { get; set; }
- public int[] Contest { get; set; }
+ public int[] Contest { set => 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 Form { get; set; }
public virtual Shiny Shiny { get; set; } = Shiny.Never;
public int Gender { get; set; } = -1;
diff --git a/PKHeX.Core/Legality/Encounters/Generator/EncounterStaticGenerator.cs b/PKHeX.Core/Legality/Encounters/Generator/EncounterStaticGenerator.cs
index c28cdad78..b499971b7 100644
--- a/PKHeX.Core/Legality/Encounters/Generator/EncounterStaticGenerator.cs
+++ b/PKHeX.Core/Legality/Encounters/Generator/EncounterStaticGenerator.cs
@@ -151,10 +151,8 @@ private static bool GetIsMatchStatic(PKM pkm, EncounterStatic e, int lvl)
if (e.IVs[i] != -1 && e.IVs[i] != pkm.IVs[i])
return false;
- if (e.Contest != null)
- for (int i = 0; i < 6; i++)
- if (e.Contest[i] > pkm.Contest[i])
- return false;
+ if (pkm.IsContestBelow(e))
+ return false;
// Defer to EC/PID check
// if (e.Shiny != null && e.Shiny != pkm.IsShiny)
diff --git a/PKHeX.Core/Legality/Encounters/Generator/EncounterTradeGenerator.cs b/PKHeX.Core/Legality/Encounters/Generator/EncounterTradeGenerator.cs
index c593ce1c3..bad02d1de 100644
--- a/PKHeX.Core/Legality/Encounters/Generator/EncounterTradeGenerator.cs
+++ b/PKHeX.Core/Legality/Encounters/Generator/EncounterTradeGenerator.cs
@@ -185,10 +185,8 @@ private static bool IsEncounterTradeValid(PKM pkm, EncounterTrade z, int lvl)
// if (z.Ability == 4 ^ pkm.AbilityNumber == 4) // defer to Ability
// countinue;
- if (z.Contest != null)
- for (int i = 0; i < 6; i++)
- if (z.Contest[i] > pkm.Contest[i])
- return false;
+ if (pkm.IsContestBelow(z))
+ return false;
return true;
}
diff --git a/PKHeX.Core/Legality/Encounters/Generator/MysteryGiftGenerator.cs b/PKHeX.Core/Legality/Encounters/Generator/MysteryGiftGenerator.cs
index 423eedad4..06a811a24 100644
--- a/PKHeX.Core/Legality/Encounters/Generator/MysteryGiftGenerator.cs
+++ b/PKHeX.Core/Legality/Encounters/Generator/MysteryGiftGenerator.cs
@@ -248,12 +248,8 @@ private static bool GetIsMatchPCD(PKM pkm, PKM wc, IEnumerable vs)
if (wc.PID == 1 && pkm.IsShiny) return false;
if (wc.Gender != 3 && wc.Gender != pkm.Gender) return false;
- if (wc.CNT_Cool > pkm.CNT_Cool) return false;
- if (wc.CNT_Beauty > pkm.CNT_Beauty) return false;
- if (wc.CNT_Cute > pkm.CNT_Cute) return false;
- if (wc.CNT_Smart > pkm.CNT_Smart) return false;
- if (wc.CNT_Tough > pkm.CNT_Tough) return false;
- if (wc.CNT_Sheen > pkm.CNT_Sheen) return false;
+ if (pkm.IsContestBelow(wc))
+ return false;
return true;
}
@@ -294,12 +290,8 @@ private static bool GetIsMatchPGF(PKM pkm, PGF wc, IEnumerable vs)
if (wc.Nature != 0xFF && wc.Nature != pkm.Nature) return false;
if (wc.Gender != 2 && wc.Gender != pkm.Gender) return false;
- if (wc.CNT_Cool > pkm.CNT_Cool) return false;
- if (wc.CNT_Beauty > pkm.CNT_Beauty) return false;
- if (wc.CNT_Cute > pkm.CNT_Cute) return false;
- if (wc.CNT_Smart > pkm.CNT_Smart) return false;
- if (wc.CNT_Tough > pkm.CNT_Tough) return false;
- if (wc.CNT_Sheen > pkm.CNT_Sheen) return false;
+ if (pkm.IsContestBelow(wc))
+ return false;
return true;
}
@@ -343,12 +335,8 @@ private static bool GetIsMatchWC6(PKM pkm, WC6 wc, IEnumerable vs)
if (wc.Nature != 0xFF && wc.Nature != pkm.Nature) return false;
if (wc.Gender != 3 && wc.Gender != pkm.Gender) return false;
- if (wc.CNT_Cool > pkm.CNT_Cool) return false;
- if (wc.CNT_Beauty > pkm.CNT_Beauty) return false;
- if (wc.CNT_Cute > pkm.CNT_Cute) return false;
- if (wc.CNT_Smart > pkm.CNT_Smart) return false;
- if (wc.CNT_Tough > pkm.CNT_Tough) return false;
- if (wc.CNT_Sheen > pkm.CNT_Sheen) return false;
+ if (pkm.IsContestBelow(wc))
+ return false;
return true;
}
@@ -402,12 +390,8 @@ private static bool GetIsMatchWC7(PKM pkm, WC7 wc, IEnumerable vs)
if (wc.Nature != 0xFF && wc.Nature != pkm.Nature) return false;
if (wc.Gender != 3 && wc.Gender != pkm.Gender) return false;
- if (wc.CNT_Cool > pkm.CNT_Cool) return false;
- if (wc.CNT_Beauty > pkm.CNT_Beauty) return false;
- if (wc.CNT_Cute > pkm.CNT_Cute) return false;
- if (wc.CNT_Smart > pkm.CNT_Smart) return false;
- if (wc.CNT_Tough > pkm.CNT_Tough) return false;
- if (wc.CNT_Sheen > pkm.CNT_Sheen) return false;
+ if (pkm.IsContestBelow(wc))
+ return false;
switch (wc.CardID)
{
diff --git a/PKHeX.Core/MysteryGifts/PGF.cs b/PKHeX.Core/MysteryGifts/PGF.cs
index a7aa21fcc..ba6334f19 100644
--- a/PKHeX.Core/MysteryGifts/PGF.cs
+++ b/PKHeX.Core/MysteryGifts/PGF.cs
@@ -6,7 +6,7 @@ namespace PKHeX.Core
///
/// Generation 5 Mystery Gift Template File
///
- public sealed class PGF : MysteryGift, IRibbonSetEvent3, IRibbonSetEvent4
+ public sealed class PGF : MysteryGift, IRibbonSetEvent3, IRibbonSetEvent4, IContestStats
{
public const int Size = 0xCC;
public override int Format => 5;
diff --git a/PKHeX.Core/MysteryGifts/WC6.cs b/PKHeX.Core/MysteryGifts/WC6.cs
index 4a1a5596a..ff7c2f559 100644
--- a/PKHeX.Core/MysteryGifts/WC6.cs
+++ b/PKHeX.Core/MysteryGifts/WC6.cs
@@ -7,7 +7,7 @@ namespace PKHeX.Core
///
/// Generation 6 Mystery Gift Template File
///
- public sealed class WC6 : MysteryGift, IRibbonSetEvent3, IRibbonSetEvent4
+ public sealed class WC6 : MysteryGift, IRibbonSetEvent3, IRibbonSetEvent4, IContestStats
{
public const int Size = 0x108;
public const int SizeFull = 0x310;
diff --git a/PKHeX.Core/MysteryGifts/WC7.cs b/PKHeX.Core/MysteryGifts/WC7.cs
index 15d11c181..ec32ac5da 100644
--- a/PKHeX.Core/MysteryGifts/WC7.cs
+++ b/PKHeX.Core/MysteryGifts/WC7.cs
@@ -7,7 +7,7 @@ namespace PKHeX.Core
///
/// Generation 7 Mystery Gift Template File
///
- public sealed class WC7 : MysteryGift, IRibbonSetEvent3, IRibbonSetEvent4
+ public sealed class WC7 : MysteryGift, IRibbonSetEvent3, IRibbonSetEvent4, IContestStats
{
public const int Size = 0x108;
public const int SizeFull = 0x310;
diff --git a/PKHeX.Core/PKM/PKM.cs b/PKHeX.Core/PKM/PKM.cs
index 351bca0c9..fc19628e8 100644
--- a/PKHeX.Core/PKM/PKM.cs
+++ b/PKHeX.Core/PKM/PKM.cs
@@ -6,7 +6,7 @@ namespace PKHeX.Core
///
/// Object representing a 's data and derived properties.
///
- public abstract class PKM
+ public abstract class PKM : IContestStats
{
public static readonly string[] Extensions = PKX.GetPKMExtensions();
public abstract int SIZE_PARTY { get; }
diff --git a/PKHeX.Core/PKM/Shared/IContestStats.cs b/PKHeX.Core/PKM/Shared/IContestStats.cs
new file mode 100644
index 000000000..79b269111
--- /dev/null
+++ b/PKHeX.Core/PKM/Shared/IContestStats.cs
@@ -0,0 +1,46 @@
+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; }
+ }
+
+ public static partial class Extensions
+ {
+ public static void SetContestStats(this IContestStats dest, int[] stats)
+ {
+ if (stats?.Length != 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 bool IsContestBelow(this PKM current, IContestStats initial) => !current.IsContestAboveOrEqual(initial);
+ public static bool IsContestAboveOrEqual(this PKM current, IContestStats initial)
+ {
+ if (current.CNT_Cool < initial.CNT_Cool)
+ return false;
+ if (current.CNT_Beauty < initial.CNT_Beauty)
+ return false;
+ if (current.CNT_Cute < initial.CNT_Cute)
+ return false;
+ if (current.CNT_Smart < initial.CNT_Smart)
+ return false;
+ if (current.CNT_Tough < initial.CNT_Tough)
+ return false;
+ if (current.CNT_Sheen < initial.CNT_Sheen)
+ return false;
+ return true;
+ }
+ }
+}