Implement PID-Ability corrections

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.
This commit is contained in:
Kaphotics
2016-08-22 20:37:50 -07:00
parent 4df390a9c1
commit 27d55b47fb
4 changed files with 43 additions and 6 deletions

View File

@@ -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())
@@ -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
}

View File

@@ -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()

View File

@@ -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()

View File

@@ -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
{