Add PID generating loop for criteria nature

This commit is contained in:
Kurt 2020-10-18 10:00:44 -07:00
parent 7a01b1249c
commit bfb9815782

View File

@ -185,12 +185,9 @@ private static void SetDefaultManaphyEggDetails(PK4 pk4, ITrainerInfo trainer)
private void SetPINGA(PK4 pk4, EncounterCriteria criteria)
{
// Ability is forced already, can't force anything
// todo: loop force the Nature/Gender
// Generate IV
uint seed = Util.Rand32();
if (pk4.PID == 1 || IsManaphyEgg) // Create Nonshiny
seed = GeneratePID(seed, pk4);
// Generate PID
var seed = SetPID(pk4, criteria);
if (!IsManaphyEgg)
seed = Util.Rand32(); // reseed, do not have method 1 correlation
@ -204,6 +201,25 @@ private void SetPINGA(PK4 pk4, EncounterCriteria criteria)
}
}
private uint SetPID(PK4 pk4, EncounterCriteria criteria)
{
uint seed = Util.Rand32();
if (pk4.PID != 1 && !IsManaphyEgg)
return seed; // PID is already set.
// The games don't decide the Nature/Gender up-front, but we can try to honor requests.
// Pre-determine the result values, and generate something.
var n = (int)criteria.GetNature(Nature.Random);
// Gender is already pre-determined in the template.
while (true)
{
seed = GeneratePID(seed, pk4);
if (pk4.Nature != n)
continue;
return seed;
}
}
private static void SetHatchedEggDetails(PK4 pk4)
{
pk4.IsEgg = false;