Add GameConsole enum and EncounterDate pivot

Can now fetch a valid date for a context
This commit is contained in:
Kurt
2023-10-28 22:01:26 -07:00
parent b088a29c88
commit 9cc36578c5
8 changed files with 139 additions and 51 deletions

View File

@@ -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
/// <param name="dest">Game the egg is currently present on</param>
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)
/// <param name="pk">Pokémon to modify.</param>
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 => "+++",
_ => "++++",
};
/// <summary>
/// Gets the Potential evaluation of the input <see cref="pk"/>.
/// </summary>
/// <param name="pk">Pokémon to analyze.</param>
/// <param name="unicode">Returned value is unicode or not</param>
/// <returns>Potential string</returns>
public static string GetPotentialString(this PKM pk, bool unicode = true)
{
var rating = pk.PotentialRating;
if (unicode)
return GetPotentialUnicode(rating);
return GetPotentialASCII(rating);
}
// Extensions
/// <summary>
/// Gets the Location Name for the <see cref="PKM"/>
@@ -465,25 +441,36 @@ public static string GetLocationString(this PKM pk, bool eggmet)
/// Gets a <see cref="PKM.EncryptionConstant"/> to match the requested option.
/// </summary>
public static uint GetComplicatedEC(ISpeciesForm pk, char option = ' ')
{
var species = pk.Species;
var form = pk.Form;
return GetComplicatedEC(species, form, option);
}
/// <inheritdoc cref="GetComplicatedEC(ISpeciesForm,char)"/>
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')

View File

@@ -1,5 +1,3 @@
using System;
namespace PKHeX.Core;
/// <summary>
@@ -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;

View File

@@ -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);

View File

@@ -0,0 +1,48 @@
namespace PKHeX.Core;
/// <summary>
/// Logic for determining the hidden potential (overall IV grade) of a Pokémon.
/// </summary>
public static class PowerPotential
{
/// <summary>
/// Gets the Potential evaluation of the input <see cref="ivTotal"/>.
/// </summary>
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 => "+++",
_ => "++++",
};
/// <summary>
/// Gets the Potential evaluation of the input <see cref="pk"/>.
/// </summary>
/// <param name="pk">Pokémon to analyze.</param>
/// <param name="unicode">Returned value is unicode or not</param>
/// <returns>Potential string</returns>
public static string GetPotentialString(this PKM pk, bool unicode = true)
{
var rating = pk.PotentialRating;
if (unicode)
return GetPotentialUnicode(rating);
return GetPotentialASCII(rating);
}
}

View File

@@ -29,6 +29,17 @@ public static class EncounterDate
/// </summary>
public static DateOnly GetDateSwitch() => DateOnly.FromDateTime(Now);
/// <summary>
/// Fetches a valid date for the specified <see cref="GameConsole"/>.
/// </summary>
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)

View File

@@ -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).<br/>
/// Assumes IVs are in the 0-31 range, so this isn't really useful for Gen1/2 formats that are 0-15 per IV.
/// </remarks>
public int PotentialRating => IVTotal switch
{
<= 90 => 0,
<= 120 => 1,
<= 150 => 2,
_ => 3,
};
public int PotentialRating => PowerPotential.GetPotential(IVTotal);
/// <summary>
/// Gets the current Battle Stats.
@@ -900,6 +899,27 @@ public void SetPIDUnown3(byte form)
/// <inheritdoc cref="SetRandomIVs(Span{int},int)"/>
public void SetRandomIVs(int minFlawless = 0) => SetRandomIVs(stackalloc int[6], minFlawless);
/// <inheritdoc cref="SetRandomIVs(Span{int},int)"/>
public void SetRandomIVs(IndividualValueSet template)
{
Span<int> ivs = stackalloc int[6];
SetRandomIVs(ivs, template);
}
/// <inheritdoc cref="SetRandomIVs(Span{int},int)"/>
public void SetRandomIVs(Span<int> 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);
}
/// <summary>
/// Randomizes the IVs within game constraints.
/// </summary>

View File

@@ -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

View File

@@ -0,0 +1,12 @@
namespace PKHeX.Core;
public enum GameConsole : byte
{
None,
GB,
GBA,
GC = GBA,
NDS,
_3DS,
NX,
}