mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-09-07 23:08:47 -05:00
Pull out Contest Stat logic to interface
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
/// <remarks>
|
||||
/// Static Encounters are fixed position encounters with properties that are not subject to Wild Encounter conditions.
|
||||
/// </remarks>
|
||||
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()
|
||||
{
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/// <remarks>
|
||||
/// Trade data is fixed level in all cases except for the first few generations of games.
|
||||
/// </remarks>
|
||||
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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -248,12 +248,8 @@ private static bool GetIsMatchPCD(PKM pkm, PKM wc, IEnumerable<DexLevel> 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<DexLevel> 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<DexLevel> 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<DexLevel> 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)
|
||||
{
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace PKHeX.Core
|
||||
/// <summary>
|
||||
/// Generation 5 Mystery Gift Template File
|
||||
/// </summary>
|
||||
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;
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace PKHeX.Core
|
||||
/// <summary>
|
||||
/// Generation 6 Mystery Gift Template File
|
||||
/// </summary>
|
||||
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;
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace PKHeX.Core
|
||||
/// <summary>
|
||||
/// Generation 7 Mystery Gift Template File
|
||||
/// </summary>
|
||||
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;
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace PKHeX.Core
|
||||
/// <summary>
|
||||
/// Object representing a <see cref="PKM"/>'s data and derived properties.
|
||||
/// </summary>
|
||||
public abstract class PKM
|
||||
public abstract class PKM : IContestStats
|
||||
{
|
||||
public static readonly string[] Extensions = PKX.GetPKMExtensions();
|
||||
public abstract int SIZE_PARTY { get; }
|
||||
|
||||
46
PKHeX.Core/PKM/Shared/IContestStats.cs
Normal file
46
PKHeX.Core/PKM/Shared/IContestStats.cs
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user