diff --git a/PKHeX.Core.AutoMod/AutoMod/APILegality.cs b/PKHeX.Core.AutoMod/AutoMod/APILegality.cs
index 0afbdfa5..bf8026aa 100644
--- a/PKHeX.Core.AutoMod/AutoMod/APILegality.cs
+++ b/PKHeX.Core.AutoMod/AutoMod/APILegality.cs
@@ -133,7 +133,7 @@ public static PKM GetLegalFromTemplate(this ITrainerInfo dest, PKM template, IBa
continue;
// Apply final details
- ApplySetDetails(pk, set, dest, enc, regen);
+ ApplySetDetails(pk, set, dest, enc, regen,criteria);
// Apply final tweaks to the data.
if (pk is IGigantamax gmax && gmax.CanGigantamax != set.CanGigantamax)
@@ -413,6 +413,8 @@ private static GameVersion[] PrioritizeVersion(GameVersion[] gamelist, GameVersi
/// if the encounter is valid or not
private static bool IsEncounterValid(IBattleTemplate set, IEncounterable enc, AbilityRequest abilityreq, GameVersion destVer)
{
+ if (enc is EncounterSlot3 && enc.Species == (ushort)Species.Unown && enc.Form != set.Form)
+ return false;
// Don't process if encounter min level is higher than requested level
if (!IsRequestedLevelValid(set, enc))
return false;
@@ -548,8 +550,8 @@ public static bool IsPIDIVSet(PKM pk, IEncounterable enc)
if (enc is IStaticCorrelation8b s && s.GetRequirement(pk) == StaticCorrelation8bRequirement.MustHave)
return true;
- if (enc is EncounterSlot4 && pk.Species == (ushort)Species.Unown)
- return true;
+ // if (enc is EncounterSlot4 && pk.Species == (ushort)Species.Unown)
+ // return true;
if (enc is EncounterSlot3 && pk.Species == (ushort)Species.Unown)
return true;
return enc is EncounterEgg && GameVersion.BDSP.Contains(enc.Version);
@@ -582,13 +584,13 @@ private static PKM SanityCheckLocation(this PKM pk, IEncounterable enc)
/// Trainer to handle the Pokémon
/// Encounter details matched to the Pokémon
/// Regeneration information
- private static void ApplySetDetails(PKM pk, IBattleTemplate set, ITrainerInfo handler, IEncounterable enc, RegenSet regen)
+ private static void ApplySetDetails(PKM pk, IBattleTemplate set, ITrainerInfo handler, IEncounterable enc, RegenSet regen, EncounterCriteria criteria)
{
byte Form = set.Form;
var language = regen.Extra.Language;
var pidiv = MethodFinder.Analyze(pk);
- pk.SetPINGA(set, pidiv.Type, set.HiddenPowerType, enc);
+ pk.SetPINGA(set, pidiv.Type, set.HiddenPowerType, enc, criteria);
pk.SetSpeciesLevel(set, Form, enc, language);
pk.SetDateLocks(enc);
pk.SetHeldItem(set);
@@ -819,7 +821,7 @@ private static void HandleEggEncounters(this PKM pk, IEncounterable enc, ITraine
///
///
///
- private static void SetPINGA(this PKM pk, IBattleTemplate set, PIDType method, int hpType, IEncounterable enc)
+ private static void SetPINGA(this PKM pk, IBattleTemplate set, PIDType method, int hpType, IEncounterable enc, EncounterCriteria criteria)
{
var ivprop = enc.GetType().GetProperty("IVs");
if (enc is not EncounterStatic4Pokewalker && enc.Generation > 2)
@@ -879,7 +881,7 @@ private static void SetPINGA(this PKM pk, IBattleTemplate set, PIDType method, i
pk.SetEncounterTradeIVs();
return; // Fixed PID, no need to mutate
default:
- FindPIDIV(pk, method, hpType, set.Shiny, enc, set);
+ FindPIDIV(pk, method, hpType, set.Shiny, enc, set,criteria);
ValidateGender(pk);
break;
}
@@ -1018,14 +1020,6 @@ private static void PreSetPIDIV(this PKM pk, IEncounterable enc, IBattleTemplate
FindEggPIDIV8b(pk, shiny, set.Gender, criteria);
}
- else if (enc is EncounterSlot4 enc4 && pk.Species == (ushort)Species.Unown)
- {
- var pi = PersonalTable.HGSS[pk.Species];
- if (pk.HGSS)
- enc4.SetFromIVsK((PK4)pk, pi, criteria, out var _);
- else
- enc4.SetFromIVsJ((PK4)pk, pi, criteria, out var _);
- }
else if (enc is EncounterSlot3 enc3 && pk.Species == (ushort)Species.Unown)
{
enc3.SetFromIVsUnown((PK3)pk, criteria);
@@ -1126,14 +1120,14 @@ private static void FindTeraPIDIV(PK9 pk, T enc, IBattleTemplate set, Encount
pk.RefreshAbility(abil >> 1);
var gender_ratio = pi.Gender;
- int gender = gender_ratio switch
+ Gender gender = gender_ratio switch
{
- PersonalInfo.RatioMagicGenderless => 2,
- PersonalInfo.RatioMagicFemale => 1,
- PersonalInfo.RatioMagicMale => 0,
- _ => Encounter9RNG.GetGender(gender_ratio, rand.NextInt(100)),
+ PersonalInfo.RatioMagicGenderless => Gender.Genderless,
+ PersonalInfo.RatioMagicFemale => Gender.Female,
+ PersonalInfo.RatioMagicMale => Gender.Male,
+ _ => (Gender)Encounter9RNG.GetGender(gender_ratio, rand.NextInt(100)),
};
- if (criteria.Gender is not null && gender != criteria.Gender)
+ if (gender != criteria.Gender)
continue;
pk.Gender = (byte)gender;
@@ -1390,8 +1384,10 @@ private static bool IsMatchCriteria9(PK9 pk, IBattleTemplate template, Encounter
/// HPType INT for preserving Hidden powers
/// Only used for CHANNEL RNG type
///
- private static void FindPIDIV(PKM pk, PIDType Method, int HPType, bool shiny, IEncounterable enc, IBattleTemplate set)
+ private static void FindPIDIV(PKM pk, PIDType Method, int HPType, bool shiny, IEncounterable enc, IBattleTemplate set, EncounterCriteria criteria)
{
+ if (enc.Generation == 4 && pk.Species == (ushort)Species.Unown)
+ pk.Form = set.Form;
if (Method == PIDType.None)
{
if (enc is EncounterGift3 wc3)
@@ -1431,7 +1427,7 @@ private static void FindPIDIV(PKM pk, PIDType Method, int HPType, bool shiny, IE
return;
do
{
- if (count >= 2_500_000)
+ if (count >= 2_500_000 && pk.Species != (ushort)Species.Unown)
compromise = true;
seed = Util.Rand32();
@@ -1443,6 +1439,7 @@ private static void FindPIDIV(PKM pk, PIDType Method, int HPType, bool shiny, IE
if (PokeWalkerSeedFail(seed, Method, pk, iterPKM))
continue;
PIDGenerator.SetValuesFromSeed(pk, Method, seed);
+
if (pk.AbilityNumber != iterPKM.AbilityNumber )
continue;
if (!compromise && pk.Nature != iterPKM.Nature)
@@ -1479,9 +1476,15 @@ private static void FindPIDIV(PKM pk, PIDType Method, int HPType, bool shiny, IE
}
if (pk.Species == (ushort)Species.Unown)
{
- if (pk.Form != iterPKM.Form)
- continue;
- if (enc.Generation == 3 && pk.Form != EntityPID.GetUnownForm3(pk.PID))
+ if (enc is EncounterSlot4 enc4)
+ {
+ var pi = PersonalTable.HGSS[pk.Species];
+ if (pk.HGSS)
+ enc4.SetFromIVsK((PK4)pk, pi, criteria, out var _);
+ else
+ enc4.SetFromIVsJ((PK4)pk, pi, criteria, out var _);
+ }
+ if (enc is EncounterSlot3 && pk.Form != EntityPID.GetUnownForm3(pk.PID))
continue;
}
var pidxor = ((pk.TID16 ^ pk.SID16 ^ (int)(pk.PID & 0xFFFF) ^ (int)(pk.PID >> 16)) & ~0x7) == 8;
@@ -1785,14 +1788,26 @@ public static EncounterCriteria SetSpecialCriteria(EncounterCriteria criteria, I
IV_SPE = criteria.IV_SPE
};
}
+ if(enc is EncounterSlot4 && enc.Species == (ushort)Species.Unown)
+ {
+ return criteria with
+ {
+ IV_ATK = criteria.IV_ATK,
+ IV_HP = criteria.IV_HP,
+ IV_DEF = criteria.IV_DEF,
+ IV_SPA = criteria.IV_SPA,
+ IV_SPD = criteria.IV_SPD,
+ IV_SPE = criteria.IV_SPE
+ };
+ }
return criteria with
{
- IV_ATK = criteria.IV_ATK == 0 ? 0 : -1,
+ IV_ATK = criteria.IV_ATK == 0 ? (sbyte)0 : (sbyte)-1,
IV_DEF = -1,
IV_HP = -1,
IV_SPA = -1,
IV_SPD = -1,
- IV_SPE = criteria.IV_SPE == 0 ? 0 : -1
+ IV_SPE = criteria.IV_SPE == 0 ? (sbyte)0 : (sbyte)-1
};
}
diff --git a/PKHeX.Core.AutoMod/AutoMod/Regeneration/RegenTemplate.cs b/PKHeX.Core.AutoMod/AutoMod/Regeneration/RegenTemplate.cs
index c05f392e..23df8f8b 100644
--- a/PKHeX.Core.AutoMod/AutoMod/Regeneration/RegenTemplate.cs
+++ b/PKHeX.Core.AutoMod/AutoMod/Regeneration/RegenTemplate.cs
@@ -20,7 +20,7 @@ public sealed class RegenTemplate : IBattleTemplate
public Nature Nature { get; set; }
public string FormName { get; set; }
public byte Form { get; set; }
- public int HiddenPowerType { get; set; }
+ public sbyte HiddenPowerType { get; set; }
public bool CanGigantamax { get; set; }
public byte DynamaxLevel { get; set; }
public MoveType TeraType { get; set; }