mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-10-02 14:57:16 -05:00
Improve ForceHatchPKM when Version=0 (SV)
BoxManipModifyComplex finally used after 3-4 years of wait
This commit is contained in:
@@ -341,8 +341,9 @@ public static int GetMaximumIV(this PKM pk, int index, bool allow30 = false)
|
||||
/// Force hatches a PKM by applying the current species name and a valid Met Location from the origin game.
|
||||
/// </summary>
|
||||
/// <param name="pk">PKM to apply hatch details to</param>
|
||||
/// <param name="tr">Trainer to force hatch with if Version is not currently set.</param>
|
||||
/// <param name="reHatch">Re-hatch already hatched <see cref="PKM"/> inputs</param>
|
||||
public static void ForceHatchPKM(this PKM pk, bool reHatch = false)
|
||||
public static void ForceHatchPKM(this PKM pk, ITrainerInfo? tr = null, bool reHatch = false)
|
||||
{
|
||||
if (!pk.IsEgg && !reHatch)
|
||||
return;
|
||||
@@ -351,6 +352,8 @@ public static void ForceHatchPKM(this PKM pk, bool reHatch = false)
|
||||
pk.CurrentFriendship = pk.PersonalInfo.BaseFriendship;
|
||||
if (pk.IsTradedEgg)
|
||||
pk.Egg_Location = pk.Met_Location;
|
||||
if (pk.Version == 0)
|
||||
pk.Version = EggStateLegality.GetEggHatchVersion(pk, (GameVersion)(tr?.Game ?? RecentTrainerCache.Game));
|
||||
var loc = EncounterSuggestion.GetSuggestedEggMetLocation(pk);
|
||||
if (loc >= 0)
|
||||
pk.Met_Location = loc;
|
||||
|
||||
@@ -64,17 +64,17 @@ public static class BoxManipDefaults
|
||||
/// <summary>
|
||||
/// Common modifying actions.
|
||||
/// </summary>
|
||||
public static readonly IReadOnlyList<BoxManipModify> ModifyCommon = new List<BoxManipModify>
|
||||
public static readonly IReadOnlyList<BoxManipBase> ModifyCommon = new List<BoxManipBase>
|
||||
{
|
||||
new(ModifyHatchEggs, pk => pk.ForceHatchPKM(), s => s.Generation >= 2 && s is not SAV8LA),
|
||||
new(ModifyMaxFriendship, pk => pk.MaximizeFriendship()),
|
||||
new(ModifyMaxLevel, pk => pk.MaximizeLevel()),
|
||||
new(ModifyResetMoves, pk => pk.SetMoves(pk.GetMoveSet()), s => s.Generation >= 3),
|
||||
new(ModifyRandomMoves, pk => pk.SetMoves(pk.GetMoveSet(true))),
|
||||
new(ModifyHyperTrain,pk => pk.SetSuggestedHyperTrainingData(), s => s.Generation >= 7 && s is not SAV8LA),
|
||||
new(ModifyGanbaru,pk => ((IGanbaru)pk).SetSuggestedGanbaruValues(pk), s => s is SAV8LA),
|
||||
new(ModifyRemoveNicknames, pk => pk.SetDefaultNickname()),
|
||||
new(ModifyRemoveItem, pk => pk.HeldItem = 0, s => s.Generation >= 2),
|
||||
new(ModifyHeal, pk => pk.Heal(), s => s.Generation >= 6), // HP stored in box, or official code has bugged transfer PP the user would like to rectify.
|
||||
new BoxManipModifyComplex(ModifyHatchEggs, (pk, sav) => pk.ForceHatchPKM(sav), s => s.Generation >= 2 && s is not SAV8LA),
|
||||
new BoxManipModify(ModifyMaxFriendship, pk => pk.MaximizeFriendship()),
|
||||
new BoxManipModify(ModifyMaxLevel, pk => pk.MaximizeLevel()),
|
||||
new BoxManipModify(ModifyResetMoves, pk => pk.SetMoves(pk.GetMoveSet()), s => s.Generation >= 3),
|
||||
new BoxManipModify(ModifyRandomMoves, pk => pk.SetMoves(pk.GetMoveSet(true))),
|
||||
new BoxManipModify(ModifyHyperTrain,pk => pk.SetSuggestedHyperTrainingData(), s => s.Generation >= 7 && s is not SAV8LA),
|
||||
new BoxManipModify(ModifyGanbaru,pk => ((IGanbaru)pk).SetSuggestedGanbaruValues(pk), s => s is SAV8LA),
|
||||
new BoxManipModify(ModifyRemoveNicknames, pk => pk.SetDefaultNickname()),
|
||||
new BoxManipModify(ModifyRemoveItem, pk => pk.HeldItem = 0, s => s.Generation >= 2),
|
||||
new BoxManipModify(ModifyHeal, pk => pk.Heal(), s => s.Generation >= 6), // HP stored in box, or official code has bugged transfer PP the user would like to rectify.
|
||||
};
|
||||
}
|
||||
|
||||
@@ -89,6 +89,18 @@ public static int GetMaximumEggHatchCycles(PKM pk, IEncounterTemplate enc)
|
||||
_ => false,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets a suggested Version for a hatched egg that originally lacked a Version value.
|
||||
/// </summary>
|
||||
/// <param name="pk">Egg Entity</param>
|
||||
/// <param name="version">Potential version the egg was hatched in</param>
|
||||
/// <returns>Very roughly sanitized version the egg was hatched in.</returns>
|
||||
public static GameVersion GetEggHatchVersion(PKM pk, GameVersion version) => pk switch
|
||||
{
|
||||
PK9 => version is SL or VL ? version : SL,
|
||||
_ => version,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Indicates if the <see cref="PKM.IsNicknamed"/> flag should be set for an Egg entity.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user