Reduce reliance on PKX

Certain calculations are best done with direct references.
Indirectly fixed Shiny button bug (8 <= xor < 16) for past gen games.
This commit is contained in:
Kaphotics
2016-07-17 23:40:40 -07:00
parent f981621452
commit 016a0e3aee
11 changed files with 26 additions and 50 deletions

View File

@@ -584,7 +584,7 @@ private LegalityCheck verifyHistory()
WC6 MatchedWC6 = EncounterMatch as WC6;
if (MatchedWC6?.OT.Length > 0) // Has Event OT -- null propagation yields false if MatchedWC6=null
{
if (pk6.OT_Friendship != PKX.getBaseFriendship(pk6.Species))
if (pk6.OT_Friendship != PersonalTable.AO[pk6.Species].BaseFriendship)
return new LegalityCheck(Severity.Invalid, "Event OT Friendship does not match base friendship.");
if (pk6.OT_Affection != 0)
return new LegalityCheck(Severity.Invalid, "Event OT Affection should be zero.");

View File

@@ -386,7 +386,7 @@ private void clickShowdownImportPK6(object sender, EventArgs e)
CB_Form.SelectedIndex = form;
// Set Ability
int[] abilities = PKX.getAbilities(Set.Species, form);
int[] abilities = SAV.Personal.getAbilities(Set.Species, form);
int ability = Array.IndexOf(abilities, Set.Ability);
if (ability < 0) ability = 0;
CB_Ability.SelectedIndex = ability;
@@ -1165,7 +1165,10 @@ private void setAbilityList()
// PKX Data Calculation Functions //
private void setIsShiny()
{
bool isShiny = PKX.getIsShiny(Util.getHEXval(TB_PID.Text), Util.ToUInt32(TB_TID.Text), Util.ToUInt32(TB_SID.Text));
pkm.PID = Util.getHEXval(TB_PID.Text);
pkm.TID = (int)Util.ToUInt32(TB_TID.Text);
pkm.SID = (int)Util.ToUInt32(TB_SID.Text);
bool isShiny = pkm.IsShiny;
// Set the Controls
BTN_Shinytize.Visible = BTN_Shinytize.Enabled = !isShiny;
@@ -1229,7 +1232,7 @@ private void clickFriendship(object sender, EventArgs e)
if (ModifierKeys == Keys.Control) // prompt to reset
TB_Friendship.Text = pkm.CurrentFriendship.ToString();
else
TB_Friendship.Text = TB_Friendship.Text == "255" ? PKX.getBaseFriendship(pkm.Species).ToString() : "255";
TB_Friendship.Text = TB_Friendship.Text == "255" ? SAV.Personal[pkm.Species].BaseFriendship.ToString() : "255";
}
private void clickGender(object sender, EventArgs e)
{
@@ -1981,7 +1984,7 @@ private void updateIsEgg(object sender, EventArgs e)
if (!CHK_Nicknamed.Checked)
updateNickname(null, null);
TB_Friendship.Text = PKX.getBaseFriendship(Util.getIndex(CB_Species)).ToString();
TB_Friendship.Text = SAV.Personal[Util.getIndex(CB_Species)].BaseFriendship.ToString();
if (CB_EggLocation.SelectedIndex == 0)
{
@@ -2050,13 +2053,15 @@ private void updateTSV(object sender, EventArgs e)
{
if (SAV.Generation < 6)
return;
ushort TID = (ushort)Util.ToUInt32(TB_TID.Text);
ushort SID = (ushort)Util.ToUInt32(TB_SID.Text);
uint TSV = PKX.getTSV(TID, SID);
pkm.TID = (int)Util.ToUInt32(TB_TID.Text);
pkm.SID = (int)Util.ToUInt32(TB_SID.Text);
var TSV = pkm.TSV;
Tip1.SetToolTip(TB_TID, "TSV: " + TSV.ToString("0000"));
Tip2.SetToolTip(TB_SID, "TSV: " + TSV.ToString("0000"));
uint PSV = PKX.getPSV(Util.getHEXval(TB_PID.Text));
pkm.PID = Util.getHEXval(TB_PID.Text);
var PSV = pkm.PSV;
Tip3.SetToolTip(TB_PID, "PSV: " + PSV.ToString("0000"));
}
private void update_ID(object sender, EventArgs e)

View File

@@ -29,7 +29,7 @@ private void populateFieldsPK3()
TB_PID.Text = pk3.PID.ToString("X8");
CB_HeldItem.SelectedValue = pk3.G3Item;
setAbilityList();
int[] abils = PKX.getAbilities(pk3.Species, 0);
int[] abils = SAV.Personal.getAbilities(pk3.Species, 0);
int abil = Array.IndexOf(abils, pk3.Ability);
CB_Ability.SelectedIndex = abil < 0 || abil >= CB_Ability.Items.Count ? 0 : abil;
CB_Nature.SelectedValue = pk3.Nature;

View File

@@ -123,7 +123,7 @@ private void populateFieldsPK4()
DEV_Ability.SelectedValue = pk4.Ability;
else
{
int[] abils = PKX.getAbilities(pk4.Species, pk4.AltForm);
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;
}

View File

@@ -134,7 +134,7 @@ private void populateFieldsPK5()
CB_Ability.SelectedIndex = CB_Ability.Items.Count - 1;
else
{
int[] abils = PKX.getAbilities(pk5.Species, pk5.AltForm);
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;
}

View File

@@ -186,7 +186,7 @@ public override PKM convertToPKM(SaveFile SAV)
RibbonChampionNational = RibbonChampionNational,
RibbonChampionWorld = RibbonChampionWorld,
OT_Friendship = PKX.getBaseFriendship(Species),
OT_Friendship = PersonalTable.B2W2[Species].BaseFriendship,
FatefulEncounter = true,
};
if (OTGender == 3) // User's

View File

@@ -273,7 +273,7 @@ public override PKM convertToPKM(SaveFile SAV)
RibbonChampionNational = RibbonChampionNational,
RibbonChampionWorld = RibbonChampionWorld,
OT_Friendship = PKX.getBaseFriendship(Species),
OT_Friendship = PersonalTable.AO[Species].BaseFriendship,
OT_Intensity = OT_Intensity,
OT_Memory = OT_Memory,
OT_TextVar = OT_TextVar,

View File

@@ -332,8 +332,10 @@ public PK6 convertToPK6()
Ability = Ability
};
int abilnum = PKX.getAbilityNumber(Species, Ability, AltForm);
if (abilnum > 0) pk6.AbilityNumber = abilnum;
int[] abilities = PersonalTable.AO.getAbilities(Species, AltForm);
int abilval = Array.IndexOf(abilities, Ability);
if (abilval >= 0)
pk6.AbilityNumber = 1 << abilval;
else // Fallback (shouldn't happen)
{
if (HiddenAbility) pk6.AbilityNumber = 4; // Hidden, else G5 or G3/4 correlation.
@@ -517,7 +519,7 @@ public PK6 convertToPK6()
pk6.HT_Memory = 4;
pk6.HT_Feeling = (int)(Util.rnd32() % 10);
// When transferred, friendship gets reset.
pk6.OT_Friendship = pk6.HT_Friendship = PKX.getBaseFriendship(Species);
pk6.OT_Friendship = pk6.HT_Friendship = PersonalTable.B2W2[Species].BaseFriendship;
// Antishiny Mechanism
ushort LID = (ushort)(PID & 0xFFFF);

View File

@@ -629,7 +629,7 @@ public void TradeFriendshipAffection(string SAV_TRAINER)
return;
// Reset
HT_Friendship = PKX.getBaseFriendship(Species);
HT_Friendship = PersonalTable.AO[Species].BaseFriendship;
HT_Affection = 0;
}

View File

@@ -243,10 +243,6 @@ internal static byte[] getRandomEVs()
Util.Shuffle(evs);
return evs;
}
internal static int getBaseFriendship(int species)
{
return Personal[species].BaseFriendship;
}
internal static int getLevel(int species, uint exp)
{
int growth = Personal[species].EXPGrowth;
@@ -255,30 +251,12 @@ internal static int getLevel(int species, uint exp)
if (tl == 100) return 100;
return --tl;
}
internal static bool getIsShiny(uint PID, uint TID, uint SID)
{
uint PSV = getPSV(PID);
uint TSV = getTSV(TID, SID);
return TSV == PSV;
}
internal static uint getEXP(int level, int species)
{
if (level <= 1) return 0;
if (level > 100) level = 100;
return ExpTable[level, Personal[species].EXPGrowth];
}
internal static int[] getAbilities(int species, int formnum)
{
return Personal[Personal[species].FormeIndex(species, formnum)].Abilities;
}
internal static int getAbilityNumber(int species, int ability, int formnum)
{
int[] spec_abilities = getAbilities(species, formnum);
int abilval = Array.IndexOf(spec_abilities, ability);
if (abilval >= 0)
return 1 << abilval;
return -1;
}
internal static int getGender(string s)
{
if (s == null)
@@ -435,7 +413,6 @@ internal static ushort[] getStats(PKM pkm)
return stats;
}
// PKX Manipulation
internal static readonly byte[][] blockPosition =
{
@@ -547,14 +524,6 @@ internal static bool verifychk(byte[] input)
return chk == BitConverter.ToUInt16(input, 0x6);
}
internal static uint getPSV(uint PID)
{
return (PID >> 16 ^ PID & 0xFFFF) >> 4;
}
internal static uint getTSV(uint TID, uint SID)
{
return (TID ^ SID) >> 4;
}
internal static uint getRandomPID(int species, int cg, int origin, int nature, int form)
{
int gt = Personal[species].Gender;

View File

@@ -560,7 +560,7 @@ private void showTSV(object sender, EventArgs e)
{
uint TID = Util.ToUInt32(MT_TID.Text);
uint SID = Util.ToUInt32(MT_SID.Text);
uint tsv = PKX.getTSV(TID, SID);
uint tsv = (TID ^ SID) >> 4;
Tip1.SetToolTip(MT_TID, "TSV: " + tsv.ToString("0000"));
Tip2.SetToolTip(MT_SID, "TSV: " + tsv.ToString("0000"));
}