diff --git a/PKHeX/MainWindow/Main.cs b/PKHeX/MainWindow/Main.cs index 4071e375d..b969a6449 100644 --- a/PKHeX/MainWindow/Main.cs +++ b/PKHeX/MainWindow/Main.cs @@ -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 ability_list = abils.Where(a => a != 0).Select((t, i) => abilitylist[t] + abilIdentifier[i]).ToList(); if (!ability_list.Any()) @@ -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) @@ -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 } diff --git a/PKHeX/MainWindow/MainPK4.cs b/PKHeX/MainWindow/MainPK4.cs index 4e27d2d69..fef518fd0 100644 --- a/PKHeX/MainWindow/MainPK4.cs +++ b/PKHeX/MainWindow/MainPK4.cs @@ -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() diff --git a/PKHeX/MainWindow/MainPK5.cs b/PKHeX/MainWindow/MainPK5.cs index c48dde3d3..286871469 100644 --- a/PKHeX/MainWindow/MainPK5.cs +++ b/PKHeX/MainWindow/MainPK5.cs @@ -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() diff --git a/PKHeX/PKM/PKM.cs b/PKHeX/PKM/PKM.cs index 2c338ed30..949efd682 100644 --- a/PKHeX/PKM/PKM.cs +++ b/PKHeX/PKM/PKM.cs @@ -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 {