diff --git a/PKHeX.Core/Editing/CommonEdits.cs b/PKHeX.Core/Editing/CommonEdits.cs
index 1693e2741..9b508d2aa 100644
--- a/PKHeX.Core/Editing/CommonEdits.cs
+++ b/PKHeX.Core/Editing/CommonEdits.cs
@@ -350,7 +350,8 @@ public static void ForceHatchPKM(this PKM pk, ITrainerInfo? tr = null, bool reHa
var loc = EncounterSuggestion.GetSuggestedEggMetLocation(pk);
if (loc >= 0)
pk.Met_Location = loc;
- pk.MetDate = DateOnly.FromDateTime(DateTime.Today);
+ if (pk.Format >= 4)
+ pk.MetDate = EncounterDate.GetDate(pk.Context.GetConsole());
if (pk.Gen6)
pk.SetHatchMemory6();
}
@@ -363,8 +364,13 @@ public static void ForceHatchPKM(this PKM pk, ITrainerInfo? tr = null, bool reHa
/// Game the egg is currently present on
public static void SetEggMetData(this PKM pk, GameVersion origin, GameVersion dest)
{
+ if (pk.Format < 4)
+ return;
+
+ var console = pk.Context.GetConsole();
+ var date = EncounterDate.GetDate(console);
+ var today = pk.MetDate = date;
bool traded = origin != dest;
- var today = pk.MetDate = DateOnly.FromDateTime(DateTime.Today);
pk.Egg_Location = EncounterSuggestion.GetSuggestedEncounterEggLocationEgg(pk.Generation, origin, traded);
pk.EggMetDate = today;
}
@@ -415,36 +421,6 @@ public static void SetDefaultNickname(this PKM pk, LegalityAnalysis la)
/// Pokémon to modify.
public static void SetDefaultNickname(this PKM pk) => pk.SetDefaultNickname(new LegalityAnalysis(pk));
- private static string GetPotentialUnicode(int rating) => rating switch
- {
- 0 => "★☆☆☆",
- 1 => "★★☆☆",
- 2 => "★★★☆",
- _ => "★★★★",
- };
-
- private static string GetPotentialASCII(int rating) => rating switch
- {
- 0 => "+",
- 1 => "++",
- 2 => "+++",
- _ => "++++",
- };
-
- ///
- /// Gets the Potential evaluation of the input .
- ///
- /// Pokémon to analyze.
- /// Returned value is unicode or not
- /// Potential string
- public static string GetPotentialString(this PKM pk, bool unicode = true)
- {
- var rating = pk.PotentialRating;
- if (unicode)
- return GetPotentialUnicode(rating);
- return GetPotentialASCII(rating);
- }
-
// Extensions
///
/// Gets the Location Name for the
@@ -465,25 +441,36 @@ public static string GetLocationString(this PKM pk, bool eggmet)
/// Gets a to match the requested option.
///
public static uint GetComplicatedEC(ISpeciesForm pk, char option = ' ')
+ {
+ var species = pk.Species;
+ var form = pk.Form;
+ return GetComplicatedEC(species, form, option);
+ }
+
+ ///
+ public static uint GetComplicatedEC(ushort species, byte form, char option = ' ')
{
var rng = Util.Rand;
uint rand = rng.Rand32();
uint mod = 1, noise = 0;
- if (pk.Species is >= (int)Species.Wurmple and <= (int)Species.Dustox)
+ if (species is >= (int)Species.Wurmple and <= (int)Species.Dustox)
{
mod = 10;
- bool lower = option is '0' or 'B' or 'S' || WurmpleUtil.GetWurmpleEvoGroup(pk.Species) == 0;
+ bool lower = option is '0' or 'B' or 'S' || WurmpleUtil.GetWurmpleEvoGroup(species) == 0;
noise = (lower ? 0u : 5u) + (uint)rng.Next(0, 5);
}
- else if (pk.Species is (int)Species.Dunsparce or (int)Species.Dudunsparce or (int)Species.Tandemaus or (int)Species.Maushold)
+ else if (species is (int)Species.Dunsparce or (int)Species.Dudunsparce or (int)Species.Tandemaus or (int)Species.Maushold)
{
mod = 100;
noise = option switch
{
'0' or '3' => 0u,
- _ when pk.Species is (int)Species.Dudunsparce && pk.Form == 1 => 0, // 3 Segment
- _ when pk.Species is (int)Species.Maushold && pk.Form == 0 => 0, // Family of 3
- _ => (uint)rng.Next(1, 100),
+ _ => species switch
+ {
+ (int)Species.Dudunsparce when form == 1 => 0, // 3 Segment
+ (int)Species.Maushold when form == 0 => 0, // Family of 3
+ _ => (uint)rng.Next(1, 100),
+ },
};
}
else if (option is >= '0' and <= '5')
diff --git a/PKHeX.Core/Editing/PKM/EntityTemplates.cs b/PKHeX.Core/Editing/PKM/EntityTemplates.cs
index e73b0f56c..267eaafd1 100644
--- a/PKHeX.Core/Editing/PKM/EntityTemplates.cs
+++ b/PKHeX.Core/Editing/PKM/EntityTemplates.cs
@@ -1,5 +1,3 @@
-using System;
-
namespace PKHeX.Core;
///
@@ -17,7 +15,8 @@ public static void TemplateFields(PKM pk, ITrainerInfo tr)
pk.Move1 = (int)Move.Pound;
pk.HealPP();
pk.Ball = 4;
- pk.MetDate = DateOnly.FromDateTime(DateTime.Today);
+ if (pk.Format >= 4)
+ pk.MetDate = EncounterDate.GetDate(pk.Context.GetConsole());
if (tr.Game >= 0)
pk.Version = tr.Game;
diff --git a/PKHeX.Core/Editing/PKM/QR/QRPK7.cs b/PKHeX.Core/Editing/PKM/QR/QRPK7.cs
index c5516ef40..3a8ff890f 100644
--- a/PKHeX.Core/Editing/PKM/QR/QRPK7.cs
+++ b/PKHeX.Core/Editing/PKM/QR/QRPK7.cs
@@ -113,7 +113,7 @@ public PKM ConvertToPKM(ITrainerInfo tr, EncounterCriteria criteria)
HT_Name = tr.OT,
CurrentLevel = Level,
Met_Level = Level,
- MetDate = DateOnly.FromDateTime(DateTime.Today),
+ MetDate = EncounterDate.GetDate3DS(),
};
RecentTrainerCache.SetConsoleRegionData3DS(pk, tr);
diff --git a/PKHeX.Core/Editing/PowerPotential.cs b/PKHeX.Core/Editing/PowerPotential.cs
new file mode 100644
index 000000000..92a83b78b
--- /dev/null
+++ b/PKHeX.Core/Editing/PowerPotential.cs
@@ -0,0 +1,48 @@
+namespace PKHeX.Core;
+
+///
+/// Logic for determining the hidden potential (overall IV grade) of a Pokémon.
+///
+public static class PowerPotential
+{
+ ///
+ /// Gets the Potential evaluation of the input .
+ ///
+ public static int GetPotential(int ivTotal) => ivTotal switch
+ {
+ <= 90 => 0,
+ <= 120 => 1,
+ <= 150 => 2,
+ _ => 3,
+ };
+
+ private static string GetPotentialUnicode(int rating) => rating switch
+ {
+ 0 => "★☆☆☆",
+ 1 => "★★☆☆",
+ 2 => "★★★☆",
+ _ => "★★★★",
+ };
+
+ private static string GetPotentialASCII(int rating) => rating switch
+ {
+ 0 => "+",
+ 1 => "++",
+ 2 => "+++",
+ _ => "++++",
+ };
+
+ ///
+ /// Gets the Potential evaluation of the input .
+ ///
+ /// Pokémon to analyze.
+ /// Returned value is unicode or not
+ /// Potential string
+ public static string GetPotentialString(this PKM pk, bool unicode = true)
+ {
+ var rating = pk.PotentialRating;
+ if (unicode)
+ return GetPotentialUnicode(rating);
+ return GetPotentialASCII(rating);
+ }
+}
diff --git a/PKHeX.Core/Legality/Encounters/Information/EncounterDate.cs b/PKHeX.Core/Legality/Encounters/Information/EncounterDate.cs
index f578fdfc8..b9c6013d3 100644
--- a/PKHeX.Core/Legality/Encounters/Information/EncounterDate.cs
+++ b/PKHeX.Core/Legality/Encounters/Information/EncounterDate.cs
@@ -29,6 +29,17 @@ public static class EncounterDate
///
public static DateOnly GetDateSwitch() => DateOnly.FromDateTime(Now);
+ ///
+ /// Fetches a valid date for the specified .
+ ///
+ public static DateOnly GetDate(GameConsole console) => console switch
+ {
+ GameConsole.NDS => GetDateNDS(),
+ GameConsole._3DS => GetDate3DS(),
+ GameConsole.NX => GetDateSwitch(),
+ _ => throw new ArgumentOutOfRangeException(nameof(console), console, null)
+ };
+
public static bool IsValidDateNDS(DateOnly date)
{
if (date.Year is < 2000 or > 2099)
diff --git a/PKHeX.Core/PKM/PKM.cs b/PKHeX.Core/PKM/PKM.cs
index e474b5a32..b6efc745b 100644
--- a/PKHeX.Core/PKM/PKM.cs
+++ b/PKHeX.Core/PKM/PKM.cs
@@ -427,16 +427,21 @@ public ushort[] Moves
set => SetMoves(value);
}
- public void PushMove(ushort move)
+ public bool AddMove(ushort move, bool pushOut = true)
{
if (move == 0 || move >= MaxMoveID || HasMove(move))
- return;
+ return false;
var ct = MoveCount;
if (ct == 4)
+ {
+ if (!pushOut)
+ return false;
ct = 0;
+ }
SetMove(ct, move);
HealPPIndex(ct);
+ return true;
}
public int MoveCount => Convert.ToInt32(Move1 != 0) + Convert.ToInt32(Move2 != 0) + Convert.ToInt32(Move3 != 0) + Convert.ToInt32(Move4 != 0);
@@ -649,13 +654,7 @@ public virtual void RefreshAbility(int n)
/// IV Judge scales his response 0 (worst) to 3 (best).
/// Assumes IVs are in the 0-31 range, so this isn't really useful for Gen1/2 formats that are 0-15 per IV.
///
- public int PotentialRating => IVTotal switch
- {
- <= 90 => 0,
- <= 120 => 1,
- <= 150 => 2,
- _ => 3,
- };
+ public int PotentialRating => PowerPotential.GetPotential(IVTotal);
///
/// Gets the current Battle Stats.
@@ -900,6 +899,27 @@ public void SetPIDUnown3(byte form)
///
public void SetRandomIVs(int minFlawless = 0) => SetRandomIVs(stackalloc int[6], minFlawless);
+ ///
+ public void SetRandomIVs(IndividualValueSet template)
+ {
+ Span ivs = stackalloc int[6];
+ SetRandomIVs(ivs, template);
+ }
+
+ ///
+ public void SetRandomIVs(Span ivs, IndividualValueSet template)
+ {
+ var rnd = Util.Rand;
+ for (int i = 0; i < ivs.Length; i++)
+ {
+ if (template[i] == -1)
+ ivs[i] = rnd.Next(MaxIV + 1);
+ else
+ ivs[i] = template[i];
+ }
+ SetIVs(ivs);
+ }
+
///
/// Randomizes the IVs within game constraints.
///
diff --git a/PKHeX.Core/PKM/Shared/EntityFormat.cs b/PKHeX.Core/PKM/Util/EntityContext.cs
similarity index 88%
rename from PKHeX.Core/PKM/Shared/EntityFormat.cs
rename to PKHeX.Core/PKM/Util/EntityContext.cs
index d6795ddd8..737206695 100644
--- a/PKHeX.Core/PKM/Shared/EntityFormat.cs
+++ b/PKHeX.Core/PKM/Util/EntityContext.cs
@@ -63,6 +63,17 @@ public static class EntityContextExtensions
_ => throw new ArgumentOutOfRangeException(nameof(value), value, null),
};
+ public static GameConsole GetConsole(this EntityContext value) => value switch
+ {
+ Gen1 or Gen2 => GameConsole.GB,
+ Gen3 => GameConsole.GBA,
+ Gen4 or Gen5 => GameConsole.NDS,
+ Gen6 or Gen7 => GameConsole._3DS,
+ Gen7b or Gen8 or Gen8a or Gen8b or Gen9 => GameConsole.NX,
+
+ _ => throw new ArgumentOutOfRangeException(nameof(value), value, null),
+ };
+
public static GameVersion[] GetVersionsWithin(this EntityContext value, GameVersion[] source) => value.GetVersionLump().GetVersionsWithinRange(source);
public static GameVersion GetVersionLump(this EntityContext value) => value switch
diff --git a/PKHeX.Core/PKM/Util/GameConsole.cs b/PKHeX.Core/PKM/Util/GameConsole.cs
new file mode 100644
index 000000000..ad9275d1d
--- /dev/null
+++ b/PKHeX.Core/PKM/Util/GameConsole.cs
@@ -0,0 +1,12 @@
+namespace PKHeX.Core;
+
+public enum GameConsole : byte
+{
+ None,
+ GB,
+ GBA,
+ GC = GBA,
+ NDS,
+ _3DS,
+ NX,
+}