private void UpdateStats(object sender, EventArgs e) { if (updatingStats) { return; } var tb_iv = new[] { TB_HPIV, TB_ATKIV, TB_DEFIV, TB_SPEIV, TB_SPAIV, TB_SPDIV }; var tb_ev = new[] { TB_HPEV, TB_ATKEV, TB_DEFEV, TB_SPEEV, TB_SPAEV, TB_SPDEV }; for (int i = 0; i < 6; i++) { updatingStats = true; if (WinFormsUtil.ToInt32(tb_iv[i]) > 31) { tb_iv[i].Text = "31"; } if (WinFormsUtil.ToInt32(tb_ev[i]) > 255) { tb_ev[i].Text = "255"; } updatingStats = false; } int species = CB_Species.SelectedIndex; species = Main.SpeciesStat[species].FormeIndex(species, CB_Forme.SelectedIndex); var p = Main.SpeciesStat[species]; int level = (int)NUD_Level.Value; int Nature = CB_Nature.SelectedIndex; ushort[] Stats = new ushort[6]; Stats[0] = (ushort)(p.HP == 1 ? 1 : ((Util.ToInt32(TB_HPIV.Text) + (2 * p.HP) + (Util.ToInt32(TB_HPEV.Text) / 4) + 100) * level / 100) + 10); Stats[1] = (ushort)(((Util.ToInt32(TB_ATKIV.Text) + (2 * p.ATK) + (Util.ToInt32(TB_ATKEV.Text) / 4)) * level / 100) + 5); Stats[2] = (ushort)(((Util.ToInt32(TB_DEFIV.Text) + (2 * p.DEF) + (Util.ToInt32(TB_DEFEV.Text) / 4)) * level / 100) + 5); Stats[4] = (ushort)(((Util.ToInt32(TB_SPAIV.Text) + (2 * p.SPA) + (Util.ToInt32(TB_SPAEV.Text) / 4)) * level / 100) + 5); Stats[5] = (ushort)(((Util.ToInt32(TB_SPDIV.Text) + (2 * p.SPD) + (Util.ToInt32(TB_SPDEV.Text) / 4)) * level / 100) + 5); Stats[3] = (ushort)(((Util.ToInt32(TB_SPEIV.Text) + (2 * p.SPE) + (Util.ToInt32(TB_SPEEV.Text) / 4)) * level / 100) + 5); // Account for nature int incr = (Nature / 5) + 1; int decr = (Nature % 5) + 1; if (incr != decr) { Stats[incr] *= 11; Stats[incr] /= 10; Stats[decr] *= 9; Stats[decr] /= 10; } Stat_HP.Text = Stats[0].ToString(); Stat_ATK.Text = Stats[1].ToString(); Stat_DEF.Text = Stats[2].ToString(); Stat_SPA.Text = Stats[4].ToString(); Stat_SPD.Text = Stats[5].ToString(); Stat_SPE.Text = Stats[3].ToString(); TB_IVTotal.Text = tb_iv.Select(WinFormsUtil.ToInt32).Sum().ToString(); TB_EVTotal.Text = tb_ev.Select(WinFormsUtil.ToInt32).Sum().ToString(); // Recolor the Stat Labels based on boosted stats. { incr--; decr--; Label[] labarray = { Label_ATK, Label_DEF, Label_SPE, Label_SPA, Label_SPD }; // Reset Label Colors foreach (Label label in labarray) { label.ResetForeColor(); } // Set Colored StatLabels only if Nature isn't Neutral if (incr != decr) { labarray[incr].ForeColor = Color.Red; labarray[decr].ForeColor = Color.Blue; } } var ivs = tb_iv.Select(tb => WinFormsUtil.ToInt32(tb) & 1).ToArray(); updatingStats = true; CB_HPType.SelectedIndex = 15 * (ivs[0] + (2 * ivs[1]) + (4 * ivs[2]) + (8 * ivs[3]) + (16 * ivs[4]) + (32 * ivs[5])) / 63; updatingStats = false; }
public static int ToInt32(MaskedTextBox tb) { string value = tb.Text; return(Util.ToInt32(value)); }