Skip to content

Commit

Permalink
Implement PID-Ability corrections
Browse files Browse the repository at this point in the history
Line 2211:
When the fields are loaded, if the user modifies the Ability on a <=Gen5
save file, if the ability is modified, the PID will be randomized to fit
the new PID.

When the Ability combobox is loaded, the personal entry may have 0 for
the ability2 (indicating same as ability1); if so, copy ability1 instead
of filtering it out.

When the Ability index is loaded, hidden ability is checked first, else
it tries to match: invalid, hidden (unflagged=illegal), if abilities
same use PIDAbility, else use the actual ability index.
  • Loading branch information
kwsch committed Aug 23, 2016
1 parent 4df390a commit 27d55b4
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
18 changes: 14 additions & 4 deletions PKHeX/MainWindow/Main.cs
Expand Up @@ -1228,6 +1228,8 @@ private void setAbilityList()
formnum = CB_Form.SelectedIndex;

int[] abils = SAV.Personal.getAbilities(species, formnum);
if (abils[1] == 0)
abils[1] = abils[0];
string[] abilIdentifier = {" (1)", " (2)", " (H)"};
List<string> ability_list = abils.Where(a => a != 0).Select((t, i) => abilitylist[t] + abilIdentifier[i]).ToList();
if (!ability_list.Any())
Expand Down Expand Up @@ -1652,6 +1654,9 @@ private void updateRandomPID(object sender, EventArgs e)
pkm.setPIDNature(Util.getIndex(CB_Nature));
else if (sender == BTN_RerollPID)
pkm.setPIDGender(pkm.Gender);
else if (sender == CB_Ability && CB_Ability.SelectedIndex != pkm.PIDAbility && pkm.PIDAbility > -1)
pkm.PID = PKX.getRandomPID(pkm.Species, pkm.Gender, pkm.Version, pkm.Nature, pkm.Format, (uint)(CB_Ability.SelectedIndex * 0x10001));

TB_PID.Text = pkm.PID.ToString("X8");
getQuickFiller(dragout);
if (pkm.GenNumber < 6 && TB_EC.Visible)
Expand Down Expand Up @@ -2203,10 +2208,15 @@ private void validateComboBox2(object sender, EventArgs e)
if (!fieldsInitialized)
return;
validateComboBox(sender, e);
if (sender == CB_Ability)
TB_AbilityNumber.Text = (1 << CB_Ability.SelectedIndex).ToString();
if (fieldsLoaded && sender == CB_Nature && SAV.Generation <= 4)
updateRandomPID(sender, e);
if (fieldsLoaded)
{
if (sender == CB_Ability && SAV.Generation >= 6)
TB_AbilityNumber.Text = (1 << CB_Ability.SelectedIndex).ToString();
if (sender == CB_Ability && SAV.Generation <= 5 && CB_Ability.SelectedIndex < 2) // not hidden
updateRandomPID(sender, e);
if (sender == CB_Nature && SAV.Generation <= 4)
updateRandomPID(sender, e);
}
updateNatureModification(sender, null);
updateIVs(null, null); // updating Nature will trigger stats to update as well
}
Expand Down
10 changes: 9 additions & 1 deletion PKHeX/MainWindow/MainPK4.cs
Expand Up @@ -134,7 +134,15 @@ private void populateFieldsPK4()
{
int[] abils = SAV.Personal.getAbilities(pk4.Species, pk4.AltForm);
int abil = Array.IndexOf(abils, pk4.Ability);
CB_Ability.SelectedIndex = abil < 0 || abil >= CB_Ability.Items.Count ? 0 : abil;

if (abil < 0)
CB_Ability.SelectedIndex = 0;
else if (abil == 2)
CB_Ability.SelectedIndex = 2;
else if (abils[0] == abils[1] || abils[1] == 0)
CB_Ability.SelectedIndex = pk4.PIDAbility;
else
CB_Ability.SelectedIndex = abil < 0 || abil >= CB_Ability.Items.Count ? 0 : abil;
}
}
private PKM preparePK4()
Expand Down
10 changes: 9 additions & 1 deletion PKHeX/MainWindow/MainPK5.cs
Expand Up @@ -145,7 +145,15 @@ private void populateFieldsPK5()
{
int[] abils = SAV.Personal.getAbilities(pk5.Species, pk5.AltForm);
int abil = Array.IndexOf(abils, pk5.Ability);
CB_Ability.SelectedIndex = abil < 0 || abil >= CB_Ability.Items.Count ? 0 : abil;

if (abil < 0)
CB_Ability.SelectedIndex = 0;
else if (abil == 2)
CB_Ability.SelectedIndex = 2;
else if (abils[0] == abils[1] || abils[1] == 0)
CB_Ability.SelectedIndex = pk5.PIDAbility;
else
CB_Ability.SelectedIndex = abil < 0 || abil >= CB_Ability.Items.Count ? 0 : abil;
}
}
private PKM preparePK5()
Expand Down
11 changes: 11 additions & 0 deletions PKHeX/PKM/PKM.cs
Expand Up @@ -287,6 +287,17 @@ public int[] Moves
get { return new[] { Move1, Move2, Move3, Move4 }; }
set { if (value?.Length != 4) return; Move1 = value[0]; Move2 = value[1]; Move3 = value[2]; Move4 = value[3]; }
}
public int PIDAbility
{
get
{
if (GenNumber > 5 || Format > 5)
return -1;
if (GenNumber == 5)
return (int)((PID >> 16) & 1);
return (int)(PID & 1);
}
}

public bool[] Markings
{
Expand Down

0 comments on commit 27d55b4

Please sign in to comment.