mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-08-21 21:15:16 -05:00
Merge pull request #77 from chenzw95/nature-pid
For Gen III & IV Pokemon, generate PIDs to ensure legal nature
This commit is contained in:
45
Misc/PKX.cs
45
Misc/PKX.cs
@@ -520,21 +520,42 @@ internal static uint getTSV(uint TID, uint SID)
|
||||
{
|
||||
return (TID ^ SID) >> 4;
|
||||
}
|
||||
internal static uint getRandomPID(int species, int cg)
|
||||
internal static uint getRandomPID(int species, int cg, int origin, int nature)
|
||||
{
|
||||
int gt = Personal[species].Gender;
|
||||
if (gt == 255 || gt == 254 || gt == 0) // Set Gender(less)
|
||||
return Util.rnd32(); // PID can be anything
|
||||
|
||||
do
|
||||
if (origin <= 15) // Gen III/IV
|
||||
{
|
||||
uint pid = Util.rnd32();
|
||||
uint gv = pid & 0xFF;
|
||||
if (cg == 1 && gv <= gt) // Female
|
||||
return pid; // PID Passes
|
||||
if (cg == 0 && gv > gt) // Male
|
||||
return pid; // PID Passes
|
||||
} while (true); // Loop until we find a suitable PID
|
||||
do
|
||||
{
|
||||
uint pid = Util.rnd32();
|
||||
uint gv = pid & 0xFF;
|
||||
if (pid % 25 == nature)
|
||||
{
|
||||
if (gt == 255 || gt == 254 || gt == 0) // Set Gender(less)
|
||||
return pid; // PID can be anything
|
||||
else
|
||||
if (cg == 1 && gv <= gt) // Female
|
||||
return pid; // PID Passes
|
||||
if (cg == 0 && gv > gt) // Male
|
||||
return pid; // PID Passes
|
||||
}
|
||||
} while (true); // Loop until we find a suitable PID
|
||||
}
|
||||
else
|
||||
{
|
||||
if (gt == 255 || gt == 254 || gt == 0) // Set Gender(less)
|
||||
return Util.rnd32(); // PID can be anything
|
||||
|
||||
do
|
||||
{
|
||||
uint pid = Util.rnd32();
|
||||
uint gv = pid & 0xFF;
|
||||
if (cg == 1 && gv <= gt) // Female
|
||||
return pid; // PID Passes
|
||||
if (cg == 0 && gv > gt) // Male
|
||||
return pid; // PID Passes
|
||||
} while (true); // Loop until we find a suitable PID
|
||||
}
|
||||
}
|
||||
|
||||
// SAV Manipulation
|
||||
|
||||
@@ -1603,7 +1603,7 @@ private void updateRandomEVs(object sender, EventArgs e)
|
||||
}
|
||||
private void updateRandomPID(object sender, EventArgs e)
|
||||
{
|
||||
TB_PID.Text = PKX.getRandomPID(Util.getIndex(CB_Species), PKX.getGender(Label_Gender.Text)).ToString("X8");
|
||||
TB_PID.Text = PKX.getRandomPID(Util.getIndex(CB_Species), PKX.getGender(Label_Gender.Text), Util.getIndex(CB_GameOrigin), Util.getIndex(CB_Nature)).ToString("X8");
|
||||
getQuickFiller(dragout);
|
||||
}
|
||||
private void updateRandomEC(object sender, EventArgs e)
|
||||
|
||||
Reference in New Issue
Block a user