Move stat calc to PKM object

ref PersonalInfo entry to calculate from

Fixes species with changed BST between gens.
Worked fine before PKX Personal was split from SAV (to fix box report),
this fixes by requiring the actual personal reference instead of looking
it up.
This commit is contained in:
Kaphotics 2016-07-20 20:40:03 -07:00
parent 45d99406f6
commit 6029913b55
3 changed files with 39 additions and 70 deletions

View file

@ -1473,19 +1473,22 @@ namespace PKHeX
}
private void updateEVs(object sender, EventArgs e)
{
if (sender != null)
if (Util.ToInt32(((MaskedTextBox) sender).Text) > SAV.MaxEV)
((MaskedTextBox) sender).Text = SAV.MaxEV.ToString();
if (sender is MaskedTextBox)
{
MaskedTextBox m = (MaskedTextBox)sender;
if (Util.ToInt32(m.Text) > SAV.MaxEV)
{ m.Text = SAV.MaxEV.ToString(); return; } // recursive on text set
}
changingFields = true;
int EV_HP = Util.ToInt32(TB_HPEV.Text);
int EV_ATK = Util.ToInt32(TB_ATKEV.Text);
int EV_DEF = Util.ToInt32(TB_DEFEV.Text);
int EV_SPA = Util.ToInt32(TB_SPAEV.Text);
int EV_SPD = Util.ToInt32(TB_SPDEV.Text);
int EV_SPE = Util.ToInt32(TB_SPEEV.Text);
if (sender == TB_HPEV) pkm.EV_HP = Util.ToInt32(TB_HPEV.Text);
else if (sender == TB_ATKEV) pkm.EV_ATK = Util.ToInt32(TB_ATKEV.Text);
else if (sender == TB_DEFEV) pkm.EV_DEF = Util.ToInt32(TB_DEFEV.Text);
else if (sender == TB_SPEEV) pkm.EV_SPE = Util.ToInt32(TB_SPEEV.Text);
else if (sender == TB_SPAEV) pkm.EV_SPA = Util.ToInt32(TB_SPAEV.Text);
else if (sender == TB_SPDEV) pkm.EV_SPD = Util.ToInt32(TB_SPDEV.Text);
int evtotal = EV_HP + EV_ATK + EV_DEF + EV_SPA + EV_SPD + EV_SPE;
int evtotal = pkm.EVs.Sum();
if (evtotal > 510) // Background turns Red
TB_EVTotal.BackColor = Color.Red;
@ -1615,6 +1618,7 @@ namespace PKHeX
}
private void updateForm(object sender, EventArgs e)
{
pkm.AltForm = CB_Form.SelectedIndex;
updateStats();
// Repopulate Abilities if Species Form has different abilities
setAbilityList();
@ -1634,7 +1638,7 @@ namespace PKHeX
if (changingFields)
return;
changingFields = true;
int form = Util.ToInt32(MT_Form.Text);
int form = pkm.AltForm = Util.ToInt32(MT_Form.Text);
CB_Form.SelectedIndex = CB_Form.Items.Count > form ? form : -1;
changingFields = false;
}
@ -2190,31 +2194,8 @@ namespace PKHeX
}
private void updateStats()
{
// Gather the needed information.
int species = Util.getIndex(CB_Species);
int level = Util.ToInt32(MT_Level.Enabled ? MT_Level.Text : TB_Level.Text);
if (level == 0) level = 1;
int form = CB_Form.SelectedIndex;
int HP_IV = Util.ToInt32(TB_HPIV.Text);
int ATK_IV = Util.ToInt32(TB_ATKIV.Text);
int DEF_IV = Util.ToInt32(TB_DEFIV.Text);
int SPA_IV = Util.ToInt32(TB_SPAIV.Text);
int SPD_IV = Util.ToInt32(TB_SPDIV.Text);
int SPE_IV = Util.ToInt32(TB_SPEIV.Text);
int HP_EV = Util.ToInt32(TB_HPEV.Text);
int ATK_EV = Util.ToInt32(TB_ATKEV.Text);
int DEF_EV = Util.ToInt32(TB_DEFEV.Text);
int SPA_EV = Util.ToInt32(TB_SPAEV.Text);
int SPD_EV = Util.ToInt32(TB_SPDEV.Text);
int SPE_EV = Util.ToInt32(TB_SPEEV.Text);
int nature = Util.getIndex(CB_Nature);
// Generate the stats.
ushort[] stats = PKX.getStats(species, level, nature, form,
HP_EV, ATK_EV, DEF_EV, SPA_EV, SPD_EV, SPE_EV,
HP_IV, ATK_IV, DEF_IV, SPA_IV, SPD_IV, SPE_IV);
ushort[] stats = pkm.getStats(SAV.Personal.getFormeEntry(pkm.Species, pkm.AltForm));
Stat_HP.Text = stats[0].ToString();
Stat_ATK.Text = stats[1].ToString();
@ -2225,8 +2206,8 @@ namespace PKHeX
// Recolor the Stat Labels based on boosted stats.
{
int incr = nature / 5;
int decr = nature % 5;
int incr = pkm.Nature / 5;
int decr = pkm.Nature % 5;
Label[] labarray = { Label_ATK, Label_DEF, Label_SPE, Label_SPA, Label_SPD };
// Reset Label Colors

View file

@ -268,10 +268,28 @@ namespace PKHeX
return ivTotal <= 150 ? 2 : 3;
}
}
public void CalculateStats()
public ushort[] getStats(PersonalInfo p)
{
int level = CurrentLevel;
ushort[] Stats = new ushort[6];
Stats[0] = (ushort)(p.HP == 1 ? 1 : (IV_HP + 2 * p.HP + EV_HP / 4 + 100) * level / 100 + 10);
Stats[1] = (ushort)((IV_ATK + 2 * p.ATK + EV_ATK / 4) * level / 100 + 5);
Stats[2] = (ushort)((IV_DEF + 2 * p.DEF + EV_DEF / 4) * level / 100 + 5);
Stats[4] = (ushort)((IV_SPA + 2 * p.SPA + EV_SPA / 4) * level / 100 + 5);
Stats[5] = (ushort)((IV_SPD + 2 * p.SPD + EV_SPD / 4) * level / 100 + 5);
Stats[3] = (ushort)((IV_SPE + 2 * p.SPE + EV_SPE / 4) * level / 100 + 5);
// Account for nature
int incr = Nature / 5 + 1;
int decr = Nature % 5 + 1;
if (incr == decr) return Stats;
Stats[incr] *= 11; Stats[incr] /= 10;
Stats[decr] *= 9; Stats[decr] /= 10;
return Stats;
}
public void setStats(ushort[] Stats)
{
ushort[] Stats = PKX.getStats(this);
Stat_HPMax = Stat_HPCurrent = Stats[0];
Stat_ATK = Stats[1];
Stat_DEF = Stats[2];

View file

@ -381,36 +381,6 @@ namespace PKHeX
return
$"{pkm.Species.ToString("000")}{(pkm.IsShiny ? " " : "")} - {pkm.Nickname} - {pkm.Checksum.ToString("X4")}{pkm.EncryptionConstant.ToString("X8")}.{pkm.Extension}";
}
internal static ushort[] getStats(PKM pkm)
{
return getStats(pkm.Species, pkm.Stat_Level, pkm.Nature, pkm.AltForm,
pkm.EV_HP, pkm.EV_ATK, pkm.EV_DEF, pkm.EV_SPA, pkm.EV_SPD, pkm.EV_SPE,
pkm.IV_HP, pkm.IV_ATK, pkm.IV_DEF, pkm.IV_SPA, pkm.IV_SPD, pkm.IV_SPE);
}
internal static ushort[] getStats(int species, int level, int nature, int form,
int HP_EV, int ATK_EV, int DEF_EV, int SPA_EV, int SPD_EV, int SPE_EV,
int HP_IV, int ATK_IV, int DEF_IV, int SPA_IV, int SPD_IV, int SPE_IV)
{
PersonalInfo p = Personal.getFormeEntry(species, form);
// Calculate Stats
ushort[] stats = new ushort[6]; // Stats are stored as ushorts in the PKX structure. We'll cap them as such.
stats[0] = (ushort)(p.HP == 1 ? 1 : (HP_IV + 2 * p.HP + HP_EV / 4 + 100) * level / 100 + 10);
stats[1] = (ushort)((ATK_IV + 2 * p.ATK + ATK_EV / 4) * level / 100 + 5);
stats[2] = (ushort)((DEF_IV + 2 * p.DEF + DEF_EV / 4) * level / 100 + 5);
stats[4] = (ushort)((SPA_IV + 2 * p.SPA + SPA_EV / 4) * level / 100 + 5);
stats[5] = (ushort)((SPD_IV + 2 * p.SPD + SPD_EV / 4) * level / 100 + 5);
stats[3] = (ushort)((SPE_IV + 2 * p.SPE + SPE_EV / 4) * level / 100 + 5);
// Account for nature
int incr = nature / 5 + 1;
int decr = nature % 5 + 1;
if (incr == decr) return stats; // if neutral return stats without mod
stats[incr] *= 11; stats[incr] /= 10;
stats[decr] *= 9; stats[decr] /= 10;
// Return Result
return stats;
}
// PKX Manipulation
internal static readonly byte[][] blockPosition =