Use history for hypertraining possible check

Closes #3520
This commit is contained in:
Kurt 2022-06-12 09:26:45 -07:00
parent f5bc23d8af
commit 5ce8938440
3 changed files with 18 additions and 23 deletions

View file

@ -8,6 +8,7 @@ namespace PKHeX.Core;
public class EvolutionHistory
{
private static readonly EvoCriteria[] NONE = Array.Empty<EvoCriteria>();
public static readonly EvolutionHistory Empty = new(NONE, 0);
public EvoCriteria[] Gen1 = NONE;
public EvoCriteria[] Gen2 = NONE;

View file

@ -18,7 +18,7 @@ namespace PKHeX.Core
if (!t.IsHyperTrained())
return;
if (!t.IsHyperTrainingAvailable())
if (!t.IsHyperTrainingAvailable(data.Info.EvoChainsAllGens))
{
data.AddLine(GetInvalid(LHyperPerfectUnavailable));
return;

View file

@ -55,18 +55,18 @@ namespace PKHeX.Core
/// <summary>
/// Sets <see cref="IHyperTrain.HyperTrainFlags"/> to valid values which may best enhance the <see cref="PKM"/> stats.
/// </summary>
/// <param name="pkm"></param>
/// <param name="pk"></param>
/// <param name="h">History of evolutions present as</param>
/// <param name="IVs"><see cref="PKM.IVs"/> to use (if already known). Will fetch the current <see cref="PKM.IVs"/> if not provided.</param>
public static void SetSuggestedHyperTrainingData(this PKM pkm, int[]? IVs = null)
public static void SetSuggestedHyperTrainingData(this PKM pk, EvolutionHistory h, Span<int> IVs)
{
if (pkm is not IHyperTrain t)
if (pk is not IHyperTrain t)
return;
if (!pkm.IsHyperTrainingAvailable())
if (!pk.IsHyperTrainingAvailable(h))
{
t.HyperTrainFlags = 0;
return;
}
IVs ??= pkm.IVs;
t.HT_HP = IVs[0] != 31;
t.HT_ATK = IVs[1] != 31 && IVs[1] > 2;
@ -79,40 +79,34 @@ namespace PKHeX.Core
t.HT_SPE = IVs[3] != 31 && IVs[3] > 2 &&
(IVs[3] > 17 || t.HT_HP || t.HT_ATK || t.HT_DEF || t.HT_SPA || t.HT_SPD);
if (pkm is ICombatPower pb)
if (pk is ICombatPower pb)
pb.ResetCP();
}
/// <inheritdoc cref="SetSuggestedHyperTrainingData(PKM,EvolutionHistory,Span{int})"/>
public static void SetSuggestedHyperTrainingData(this PKM pk, int[]? IVs = null) => pk.SetSuggestedHyperTrainingData(EvolutionHistory.Empty, IVs ?? pk.IVs);
/// <summary>
/// Indicates if Hyper Training is available for toggling.
/// </summary>
/// <param name="t">Entity to train</param>
/// <param name="h">History of evolutions present as</param>
/// <returns>True if available, otherwise false.</returns>
public static bool IsHyperTrainingAvailable(this IHyperTrain t) => t switch
public static bool IsHyperTrainingAvailable(this IHyperTrain t, EvolutionHistory h) => t switch
{
// Check for game formats where training is unavailable:
PA8 pa8 => HasVisitedBDSPorSWSH(pa8),
PA8 pa8 => pa8.HasVisitedSWSH(h.Gen8) || pa8.HasVisitedBDSP(h.Gen8b),
_ => true,
};
private static bool HasVisitedBDSPorSWSH(PKM pk)
{
if (pk.IsUntraded)
return false;
if (PersonalTable.BDSP.IsPresentInGame(pk.Species, pk.Form))
return true;
if (PersonalTable.SWSH.IsPresentInGame(pk.Species, pk.Form))
return true;
return false;
}
/// <inheritdoc cref="IsHyperTrainingAvailable(IHyperTrain)"/>
/// <inheritdoc cref="IsHyperTrainingAvailable(IHyperTrain, EvolutionHistory)"/>
/// <param name="pk">Entity data</param>
public static bool IsHyperTrainingAvailable(this PKM pk)
/// <param name="h">History of evolutions present as</param>
public static bool IsHyperTrainingAvailable(this PKM pk, EvolutionHistory h)
{
if (pk is not IHyperTrain t)
return false;
if (!t.IsHyperTrainingAvailable())
if (!t.IsHyperTrainingAvailable(h))
return false;
// Gated behind level 100.