コード例 #1
0
        private void changeFFFF(object sender, EventArgs e)
        {
            MaskedTextBox box = sender as MaskedTextBox;

            if (box?.Text == "")
            {
                box.Text = "0";
            }
            if (Util.ToInt32(box.Text) > 65535)
            {
                box.Text = "65535";
            }
        }
コード例 #2
0
ファイル: Util.cs プロジェクト: piva-xx/PKHeX
 internal static string[] getNulledStringArray(string[] SimpleStringList)
 {
     try
     {
         string[] newlist = new string[Util.ToInt32(SimpleStringList[SimpleStringList.Length - 1].Split(',')[0]) + 1];
         for (int i = 1; i < SimpleStringList.Length; i++)
         {
             newlist[Util.ToInt32(SimpleStringList[i].Split(',')[0])] = SimpleStringList[i].Split(',')[1];
         }
         return(newlist);
     }
     catch { return(null); }
 }
コード例 #3
0
ファイル: SAV_Trainer.cs プロジェクト: Zelda123/PKHeX
        private void change255(object sender, EventArgs e)
        {
            MaskedTextBox box = sender as MaskedTextBox;

            if (box.Text == "")
            {
                box.Text = "0";
            }
            if (Util.ToInt32(box.Text) > 255)
            {
                box.Text = "255";
            }
        }
コード例 #4
0
        private void changeSpecial(object sender, EventArgs e)
        {
            MaskedTextBox box = sender as MaskedTextBox;
            int           val = Util.ToInt32(box.Text);

            if (box == MT_HairColor)
            {
                box.Text = (val > 7 ? 7 : val).ToString();
            }
            if (box == MT_Hat)
            {
                box.Text = (val > 31 ? 31 : val).ToString();
            }
        }
コード例 #5
0
ファイル: MemoryAmie.cs プロジェクト: 0ver-flow/PKHeX
        private void update255_MTB(object sender, EventArgs e)
        {
            MaskedTextBox mtb = sender as MaskedTextBox;

            try
            {
                int val = Util.ToInt32(mtb?.Text);
                if (val > 255)
                {
                    mtb.Text = "255";
                }
            }
            catch { mtb.Text = "0"; }
        }
コード例 #6
0
        internal static int getIndex(ComboBox cb)
        {
            int val = 0;

            try { val = Util.ToInt32(cb.SelectedValue.ToString()); }
            catch
            {
                val = cb.SelectedIndex;
                if (val < 0)
                {
                    val = 0;
                }
            };
            return(val);
        }
コード例 #7
0
        private void B_GiveAll_Click(object sender, EventArgs e)
        {
            if (CHK_L1.Enabled)
            {
                CHK_L1.Checked                         =
                    CHK_L2.Checked                     =
                        CHK_L3.Checked                 =
                            CHK_L4.Checked             =
                                CHK_L5.Checked         =
                                    CHK_L6.Checked     =
                                        CHK_L7.Checked = ModifierKeys != Keys.Control;
            }
            if (CHK_P1.Enabled)
            {
                CHK_P1.Checked = ModifierKeys != Keys.Control;
            }
            int index = LB_Species.SelectedIndex + 1;
            int gt    = PKX.Personal[index].Gender;

            CHK_P2.Checked = CHK_P4.Checked = gt != 254 && ModifierKeys != Keys.Control;
            CHK_P3.Checked = CHK_P5.Checked = gt != 0 && gt != 255 && ModifierKeys != Keys.Control;

            if (ModifierKeys == Keys.Control)
            {
                foreach (var chk in new[] { CHK_P6, CHK_P7, CHK_P8, CHK_P9 })
                {
                    chk.Checked = false;
                }
            }
            else if (!(CHK_P6.Checked || CHK_P7.Checked || CHK_P8.Checked || CHK_P9.Checked))
            {
                (gt != 254 ? CHK_P6 : CHK_P7).Checked = true;
            }

            for (int i = 0; i < CLB_FormsSeen.Items.Count; i++)
            {
                CLB_FormsSeen.SetItemChecked(i, ModifierKeys != Keys.Control);
            }
            if (CLB_FormsSeen.Items.Count > 0 && CLB_FormDisplayed.CheckedItems.Count == 0)
            {
                CLB_FormDisplayed.SetItemChecked(0, ModifierKeys != Keys.Control);
            }

            if (Util.ToInt32(MT_Count.Text) == 0)
            {
                MT_Count.Text = "1";
            }
        }
コード例 #8
0
        private void B_Save_Click(object sender, EventArgs e)
        {
            byte[] puffarray  = new byte[100];
            int    emptyslots = 0;

            for (int i = 0; i < 100; i++)
            {
                string puff = dgv.Rows[i].Cells[1].Value.ToString();
                if (Array.IndexOf(pfa, puff) == 0)
                {
                    emptyslots++;
                    continue;
                }
                puffarray[i - emptyslots] = (byte)Array.IndexOf(pfa, puff);
            }
            Main.SAV.Puffs     = puffarray;
            Main.SAV.PuffCount = Util.ToInt32(MT_CNT);
            Main.SAV.Edited    = true;
            Close();
        }
コード例 #9
0
ファイル: MainPK1.cs プロジェクト: resonancellc/Mass-Editor
        private PKM preparePK1()
        {
            PK1 pk1 = pkm as PK1;

            if (pk1 == null)
            {
                return(null);
            }

            pk1.Species = Util.getIndex(CB_Species);
            pk1.TID     = Util.ToInt32(TB_TID.Text);
            pk1.EXP     = Util.ToUInt32(TB_EXP.Text);

            pk1.EV_HP  = Util.ToInt32(TB_HPEV.Text);
            pk1.EV_ATK = Util.ToInt32(TB_ATKEV.Text);
            pk1.EV_DEF = Util.ToInt32(TB_DEFEV.Text);
            pk1.EV_SPE = Util.ToInt32(TB_SPEEV.Text);
            pk1.EV_SPC = Util.ToInt32(TB_SPAEV.Text);

            if (CHK_Nicknamed.Checked)
            {
                pk1.Nickname = TB_Nickname.Text;
            }
            else
            {
                pk1.setNotNicknamed();
            }
            pk1.Move1       = Util.getIndex(CB_Move1);
            pk1.Move2       = Util.getIndex(CB_Move2);
            pk1.Move3       = Util.getIndex(CB_Move3);
            pk1.Move4       = Util.getIndex(CB_Move4);
            pk1.Move1_PP    = Util.getIndex(CB_Move1) > 0 ? Util.ToInt32(TB_PP1.Text) : 0;
            pk1.Move2_PP    = Util.getIndex(CB_Move2) > 0 ? Util.ToInt32(TB_PP2.Text) : 0;
            pk1.Move3_PP    = Util.getIndex(CB_Move3) > 0 ? Util.ToInt32(TB_PP3.Text) : 0;
            pk1.Move4_PP    = Util.getIndex(CB_Move4) > 0 ? Util.ToInt32(TB_PP4.Text) : 0;
            pk1.Move1_PPUps = Util.getIndex(CB_Move1) > 0 ? CB_PPu1.SelectedIndex : 0;
            pk1.Move2_PPUps = Util.getIndex(CB_Move2) > 0 ? CB_PPu2.SelectedIndex : 0;
            pk1.Move3_PPUps = Util.getIndex(CB_Move3) > 0 ? CB_PPu3.SelectedIndex : 0;
            pk1.Move4_PPUps = Util.getIndex(CB_Move4) > 0 ? CB_PPu4.SelectedIndex : 0;

            pk1.IV_HP  = Util.ToInt32(TB_HPIV.Text);
            pk1.IV_ATK = Util.ToInt32(TB_ATKIV.Text);
            pk1.IV_DEF = Util.ToInt32(TB_DEFIV.Text);
            pk1.IV_SPE = Util.ToInt32(TB_SPEIV.Text);
            pk1.IV_SPA = Util.ToInt32(TB_SPAIV.Text);

            pk1.OT_Name = TB_OT.Text;

            // Toss in Party Stats
            Array.Resize(ref pk1.Data, pk1.SIZE_PARTY);
            pk1.Stat_Level     = Util.ToInt32(TB_Level.Text);
            pk1.Stat_HPCurrent = Util.ToInt32(Stat_HP.Text);
            pk1.Stat_HPMax     = Util.ToInt32(Stat_HP.Text);
            pk1.Stat_ATK       = Util.ToInt32(Stat_ATK.Text);
            pk1.Stat_DEF       = Util.ToInt32(Stat_DEF.Text);
            pk1.Stat_SPE       = Util.ToInt32(Stat_SPE.Text);
            pk1.Stat_SPA       = Util.ToInt32(Stat_SPA.Text);
            pk1.Stat_SPD       = Util.ToInt32(Stat_SPD.Text);

            if (HaX)
            {
                pk1.Stat_Level = (byte)Math.Min(Convert.ToInt32(MT_Level.Text), byte.MaxValue);
            }

            // Fix Moves if a slot is empty
            pk1.FixMoves();

            pk1.RefreshChecksum();
            return(pk1);
        }
コード例 #10
0
        private PKM preparePK3()
        {
            PK3 pk3 = pkm as PK3;

            if (pk3 == null)
            {
                return(null);
            }

            pk3.Species       = Util.getIndex(CB_Species);
            pk3.HeldItem      = Util.getIndex(CB_HeldItem);
            pk3.TID           = Util.ToInt32(TB_TID.Text);
            pk3.SID           = Util.ToInt32(TB_SID.Text);
            pk3.EXP           = Util.ToUInt32(TB_EXP.Text);
            pk3.PID           = Util.getHEXval(TB_PID.Text);
            pk3.AbilityNumber = CB_Ability.SelectedIndex; // 0/1 (stored in IVbits)

            pk3.FatefulEncounter = CHK_Fateful.Checked;
            pk3.Gender           = PKX.getGender(Label_Gender.Text);
            pk3.EV_HP            = Util.ToInt32(TB_HPEV.Text);
            pk3.EV_ATK           = Util.ToInt32(TB_ATKEV.Text);
            pk3.EV_DEF           = Util.ToInt32(TB_DEFEV.Text);
            pk3.EV_SPE           = Util.ToInt32(TB_SPEEV.Text);
            pk3.EV_SPA           = Util.ToInt32(TB_SPAEV.Text);
            pk3.EV_SPD           = Util.ToInt32(TB_SPDEV.Text);

            pk3.CNT_Cool   = Util.ToInt32(TB_Cool.Text);
            pk3.CNT_Beauty = Util.ToInt32(TB_Beauty.Text);
            pk3.CNT_Cute   = Util.ToInt32(TB_Cute.Text);
            pk3.CNT_Smart  = Util.ToInt32(TB_Smart.Text);
            pk3.CNT_Tough  = Util.ToInt32(TB_Tough.Text);
            pk3.CNT_Sheen  = Util.ToInt32(TB_Sheen.Text);

            pk3.PKRS_Days   = CB_PKRSDays.SelectedIndex;
            pk3.PKRS_Strain = CB_PKRSStrain.SelectedIndex;
            pk3.Nickname    = TB_Nickname.Text;
            pk3.Move1       = Util.getIndex(CB_Move1);
            pk3.Move2       = Util.getIndex(CB_Move2);
            pk3.Move3       = Util.getIndex(CB_Move3);
            pk3.Move4       = Util.getIndex(CB_Move4);
            pk3.Move1_PP    = Util.getIndex(CB_Move1) > 0 ? Util.ToInt32(TB_PP1.Text) : 0;
            pk3.Move2_PP    = Util.getIndex(CB_Move2) > 0 ? Util.ToInt32(TB_PP2.Text) : 0;
            pk3.Move3_PP    = Util.getIndex(CB_Move3) > 0 ? Util.ToInt32(TB_PP3.Text) : 0;
            pk3.Move4_PP    = Util.getIndex(CB_Move4) > 0 ? Util.ToInt32(TB_PP4.Text) : 0;
            pk3.Move1_PPUps = Util.getIndex(CB_Move1) > 0 ? CB_PPu1.SelectedIndex : 0;
            pk3.Move2_PPUps = Util.getIndex(CB_Move2) > 0 ? CB_PPu2.SelectedIndex : 0;
            pk3.Move3_PPUps = Util.getIndex(CB_Move3) > 0 ? CB_PPu3.SelectedIndex : 0;
            pk3.Move4_PPUps = Util.getIndex(CB_Move4) > 0 ? CB_PPu4.SelectedIndex : 0;

            pk3.IV_HP       = Util.ToInt32(TB_HPIV.Text);
            pk3.IV_ATK      = Util.ToInt32(TB_ATKIV.Text);
            pk3.IV_DEF      = Util.ToInt32(TB_DEFIV.Text);
            pk3.IV_SPE      = Util.ToInt32(TB_SPEIV.Text);
            pk3.IV_SPA      = Util.ToInt32(TB_SPAIV.Text);
            pk3.IV_SPD      = Util.ToInt32(TB_SPDIV.Text);
            pk3.IsEgg       = CHK_IsEgg.Checked;
            pk3.IsNicknamed = CHK_Nicknamed.Checked;

            pk3.OT_Name           = TB_OT.Text;
            pk3.CurrentFriendship = Util.ToInt32(TB_Friendship.Text);

            pk3.Ball      = Util.getIndex(CB_Ball);
            pk3.Met_Level = Util.ToInt32(TB_MetLevel.Text);
            pk3.OT_Gender = PKX.getGender(Label_OTGender.Text);
            pk3.Version   = Util.getIndex(CB_GameOrigin);
            pk3.Language  = Util.getIndex(CB_Language);

            pk3.Met_Location = Util.getIndex(CB_MetLocation);

            // Toss in Party Stats
            Array.Resize(ref pk3.Data, pk3.SIZE_PARTY);
            pk3.Stat_Level     = Util.ToInt32(TB_Level.Text);
            pk3.Stat_HPCurrent = Util.ToInt32(Stat_HP.Text);
            pk3.Stat_HPMax     = Util.ToInt32(Stat_HP.Text);
            pk3.Stat_ATK       = Util.ToInt32(Stat_ATK.Text);
            pk3.Stat_DEF       = Util.ToInt32(Stat_DEF.Text);
            pk3.Stat_SPE       = Util.ToInt32(Stat_SPE.Text);
            pk3.Stat_SPA       = Util.ToInt32(Stat_SPA.Text);
            pk3.Stat_SPD       = Util.ToInt32(Stat_SPD.Text);

            if (HaX)
            {
                pk3.Stat_Level = (byte)Math.Min(Convert.ToInt32(MT_Level.Text), byte.MaxValue);
            }

            // Fix Moves if a slot is empty
            pk3.FixMoves();

            pk3.RefreshChecksum();
            return(pk3);
        }
コード例 #11
0
ファイル: ShowdownSet.cs プロジェクト: wbsr9876/PKHeX
        // Parsing Utility
        public ShowdownSet(string input = null)
        {
            if (input == null)
            {
                return;
            }

            string[] lines = input.Split(new[] { "\r\n", "\n" }, StringSplitOptions.None);
            for (int i = 0; i < lines.Length; i++)
            {
                lines[i] = lines[i].Replace("'", "’").Trim();                                    // Sanitize apostrophes
            }
            lines = lines.Where(line => line.Length > 2).ToArray();

            if (lines.Length < 3)
            {
                return;
            }

            // Seek for start of set
            int start = Array.FindIndex(lines, line => line.Contains(" @ "));

            if (start != -1) // Has Item -- skip to start.
            {
                lines = lines.Skip(start).Take(lines.Length - start).ToArray();
            }
            else // Has no Item -- try parsing the first line anyway.
            {
                parseFirstLine(lines[0]);
                if (Species < -1)
                {
                    return; // Abort if no text is found
                }
                lines = lines.Skip(1).Take(lines.Length - 1).ToArray();
            }
            int movectr = 0;

            // Detect relevant data
            foreach (string line in lines)
            {
                if (line.StartsWith("-"))
                {
                    string moveString = parseLineMove(line);
                    int    move       = Array.IndexOf(moves, moveString);
                    if (move < 0)
                    {
                        InvalidLines.Add($"Unknown Move: {moveString}");
                    }
                    else
                    {
                        Moves[movectr++] = move;
                    }

                    if (movectr == 4)
                    {
                        break; // End of moves
                    }
                    continue;
                }

                string[] brokenline = line.Split(new[] { ": " }, StringSplitOptions.None);
                switch (brokenline[0])
                {
                case "Trait":
                case "Ability": { Ability = Array.IndexOf(abilities, brokenline[1].Trim()); break; }

                case "Level": { Level = Util.ToInt32(brokenline[1].Trim()); break; }

                case "Shiny": { Shiny = brokenline[1].Trim() == "Yes"; break; }

                case "Happiness": { Friendship = Util.ToInt32(brokenline[1].Trim()); break; }

                case "Nature": { Nature = Array.IndexOf(natures, brokenline[1].Trim()); break; }

                case "EV":
                case "EVs": { parseLineEVs(brokenline[1].Trim()); break; }

                case "IV":
                case "IVs": { parseLineIVs(brokenline[1].Trim()); break; }

                default:
                {
                    // Either Nature or Gender ItemSpecies
                    if (brokenline[0].Contains(" @ "))
                    {
                        string[] pieces  = line.Split(new[] { " @ " }, StringSplitOptions.None);
                        string   itemstr = pieces.Last().Trim();
                        int      item    = Array.IndexOf(items, itemstr);
                        if (item < 0)
                        {
                            InvalidLines.Add($"Unknown Item: {itemstr}");
                        }
                        else
                        {
                            Item = item;
                        }

                        parseFirstLine(pieces[0]);
                    }
                    else if (brokenline[0].Contains("Nature"))
                    {
                        string naturestr = line.Split(' ')[0].Trim();
                        int    nature    = Array.IndexOf(natures, naturestr);
                        if (nature < 0)
                        {
                            InvalidLines.Add($"Unknown Nature: {naturestr}");
                        }
                        else
                        {
                            Nature = nature;
                        }
                    }
                    else     // Fallback
                    {
                        string speciesstr = line.Split('(')[0].Trim();
                        int    spec       = Array.IndexOf(species, speciesstr);
                        if (spec < 1)
                        {
                            InvalidLines.Add(speciesstr);
                        }
                        else
                        {
                            Species = spec;
                        }
                    }
                    break;
                }
                }
            }

            IVs = IVsSpeedFirst;
            EVs = EVsSpeedFirst;
        }
コード例 #12
0
ファイル: MainPK2.cs プロジェクト: Soaprman/PKHeX
        private PKM preparePK2()
        {
            PK2 pk2 = pkm as PK2;

            if (pk2 == null)
            {
                return(null);
            }

            pk2.Species           = Util.getIndex(CB_Species);
            pk2.TID               = Util.ToInt32(TB_TID.Text);
            pk2.EXP               = Util.ToUInt32(TB_EXP.Text);
            pk2.HeldItem          = Util.getIndex(CB_HeldItem);
            pk2.IsEgg             = CHK_IsEgg.Checked;
            pk2.CurrentFriendship = Util.ToInt32(TB_Friendship.Text);
            pk2.Met_Level         = Util.ToInt32(TB_MetLevel.Text);
            pk2.Met_Location      = Util.getIndex(CB_MetLocation);
            pk2.Met_TimeOfDay     = CB_MetTimeOfDay.SelectedIndex;

            pk2.EV_HP  = Util.ToInt32(TB_HPEV.Text);
            pk2.EV_ATK = Util.ToInt32(TB_ATKEV.Text);
            pk2.EV_DEF = Util.ToInt32(TB_DEFEV.Text);
            pk2.EV_SPE = Util.ToInt32(TB_SPEEV.Text);
            pk2.EV_SPC = Util.ToInt32(TB_SPAEV.Text);

            if (CHK_Nicknamed.Checked)
            {
                pk2.Nickname = TB_Nickname.Text;
            }
            else
            {
                pk2.setNotNicknamed();
            }
            pk2.Move1       = Util.getIndex(CB_Move1);
            pk2.Move2       = Util.getIndex(CB_Move2);
            pk2.Move3       = Util.getIndex(CB_Move3);
            pk2.Move4       = Util.getIndex(CB_Move4);
            pk2.Move1_PP    = Util.getIndex(CB_Move1) > 0 ? Util.ToInt32(TB_PP1.Text) : 0;
            pk2.Move2_PP    = Util.getIndex(CB_Move2) > 0 ? Util.ToInt32(TB_PP2.Text) : 0;
            pk2.Move3_PP    = Util.getIndex(CB_Move3) > 0 ? Util.ToInt32(TB_PP3.Text) : 0;
            pk2.Move4_PP    = Util.getIndex(CB_Move4) > 0 ? Util.ToInt32(TB_PP4.Text) : 0;
            pk2.Move1_PPUps = Util.getIndex(CB_Move1) > 0 ? CB_PPu1.SelectedIndex : 0;
            pk2.Move2_PPUps = Util.getIndex(CB_Move2) > 0 ? CB_PPu2.SelectedIndex : 0;
            pk2.Move3_PPUps = Util.getIndex(CB_Move3) > 0 ? CB_PPu3.SelectedIndex : 0;
            pk2.Move4_PPUps = Util.getIndex(CB_Move4) > 0 ? CB_PPu4.SelectedIndex : 0;

            pk2.IV_HP  = Util.ToInt32(TB_HPIV.Text);
            pk2.IV_ATK = Util.ToInt32(TB_ATKIV.Text);
            pk2.IV_DEF = Util.ToInt32(TB_DEFIV.Text);
            pk2.IV_SPE = Util.ToInt32(TB_SPEIV.Text);
            pk2.IV_SPA = Util.ToInt32(TB_SPAIV.Text);

            pk2.OT_Name = TB_OT.Text;

            // Toss in Party Stats
            Array.Resize(ref pk2.Data, pk2.SIZE_PARTY);
            pk2.Stat_Level     = Util.ToInt32(TB_Level.Text);
            pk2.Stat_HPCurrent = Util.ToInt32(Stat_HP.Text);
            pk2.Stat_HPMax     = Util.ToInt32(Stat_HP.Text);
            pk2.Stat_ATK       = Util.ToInt32(Stat_ATK.Text);
            pk2.Stat_DEF       = Util.ToInt32(Stat_DEF.Text);
            pk2.Stat_SPE       = Util.ToInt32(Stat_SPE.Text);
            pk2.Stat_SPA       = Util.ToInt32(Stat_SPA.Text);
            pk2.Stat_SPD       = Util.ToInt32(Stat_SPD.Text);

            if (HaX)
            {
                pk2.Stat_Level = (byte)Math.Min(Convert.ToInt32(MT_Level.Text), byte.MaxValue);
            }

            // Fix Moves if a slot is empty
            pk2.FixMoves();

            return(pk2);
        }
コード例 #13
0
ファイル: f4-RibbMedal.cs プロジェクト: kawatzaki/PKHeX
        private void setData()
        {
            pk6.SecretSuperTraining = CHK_Secret.Checked;

            pk6.Unused0 = TMedal1_0.Checked;
            pk6.Unused1 = TMedal1_1.Checked;
            pk6.ST1_SPA = TMedal1_2.Checked;
            pk6.ST1_HP  = TMedal1_3.Checked;
            pk6.ST1_ATK = TMedal1_4.Checked;
            pk6.ST1_SPD = TMedal1_5.Checked;
            pk6.ST1_SPE = TMedal1_6.Checked;
            pk6.ST1_DEF = TMedal1_7.Checked;

            pk6.ST2_SPA = TMedal2_0.Checked;
            pk6.ST2_HP  = TMedal2_1.Checked;
            pk6.ST2_ATK = TMedal2_2.Checked;
            pk6.ST2_SPD = TMedal2_3.Checked;
            pk6.ST2_SPE = TMedal2_4.Checked;
            pk6.ST2_DEF = TMedal2_5.Checked;
            pk6.ST3_SPA = TMedal2_6.Checked;
            pk6.ST3_HP  = TMedal2_7.Checked;

            pk6.ST3_ATK = TMedal3_0.Checked;
            pk6.ST3_SPD = TMedal3_1.Checked;
            pk6.ST3_SPE = TMedal3_2.Checked;
            pk6.ST3_DEF = TMedal3_3.Checked;
            pk6.ST4_1   = TMedal3_4.Checked;
            pk6.ST5_1   = TMedal3_5.Checked;
            pk6.ST5_2   = TMedal3_6.Checked;
            pk6.ST5_3   = TMedal3_7.Checked;

            pk6.ST5_4 = TMedal4_0.Checked;
            pk6.ST6_1 = TMedal4_1.Checked;
            pk6.ST6_2 = TMedal4_2.Checked;
            pk6.ST6_3 = TMedal4_3.Checked;
            pk6.ST7_1 = TMedal4_4.Checked;
            pk6.ST7_2 = TMedal4_5.Checked;
            pk6.ST7_3 = TMedal4_6.Checked;
            pk6.ST8_1 = TMedal4_7.Checked;

            pk6.Dist1 = CHK_D0.Checked;
            pk6.Dist2 = CHK_D1.Checked;
            pk6.Dist3 = CHK_D2.Checked;
            pk6.Dist4 = CHK_D3.Checked;
            pk6.Dist5 = CHK_D4.Checked;
            pk6.Dist6 = CHK_D5.Checked;

            pk6.RIB0_0 = Kalos1a_0.Checked;
            pk6.RIB0_1 = Kalos1a_1.Checked;
            pk6.RIB0_2 = Kalos1a_2.Checked;
            pk6.RIB0_3 = Kalos1a_3.Checked;
            pk6.RIB0_4 = Kalos1a_4.Checked;
            pk6.RIB0_5 = Kalos1a_5.Checked;
            pk6.RIB0_6 = Kalos1a_6.Checked;
            pk6.RIB0_7 = Kalos1a_7.Checked;

            pk6.RIB1_0 = Kalos1b_0.Checked;
            pk6.RIB1_1 = Kalos1b_1.Checked;
            pk6.RIB1_2 = Kalos1b_2.Checked;
            pk6.RIB1_3 = Kalos1b_3.Checked;
            pk6.RIB1_4 = Kalos1b_4.Checked;
            pk6.RIB1_5 = Kalos1b_5.Checked;
            pk6.RIB1_6 = Kalos1b_6.Checked;
            pk6.RIB1_7 = Kalos1b_7.Checked;

            pk6.RIB2_0 = Kalos2a_0.Checked;
            pk6.RIB2_1 = Kalos2a_1.Checked;
            pk6.RIB2_2 = Kalos2a_2.Checked;
            pk6.RIB2_3 = Kalos2a_3.Checked;
            pk6.RIB2_4 = Kalos2a_4.Checked;
            pk6.RIB2_5 = Kalos2a_5.Checked;
            pk6.RIB2_6 = Kalos2a_6.Checked;
            pk6.RIB2_7 = Kalos2a_7.Checked;

            pk6.RIB3_0 = Kalos2b_0.Checked;
            pk6.RIB3_1 = Kalos2b_1.Checked;
            pk6.RIB3_2 = Kalos2b_2.Checked;
            pk6.RIB3_3 = Kalos2b_3.Checked;
            pk6.RIB3_4 = Kalos2b_4.Checked;
            pk6.RIB3_5 = Kalos2b_5.Checked;
            pk6.RIB3_6 = Kalos2b_6.Checked;
            pk6.RIB3_7 = Kalos2b_7.Checked;

            pk6.RIB4_0 = Extra1_0.Checked;
            pk6.RIB4_1 = Extra1_1.Checked;
            pk6.RIB4_2 = Extra1_2.Checked;
            pk6.RIB4_3 = Extra1_3.Checked;
            pk6.RIB4_4 = Extra1_4.Checked;

            // Introduced in ORAS
            pk6.RIB4_7 = Extra1_7.Checked;

            pk6.RIB5_0 = ORAS_0.Checked;
            pk6.RIB5_1 = ORAS_1.Checked;
            pk6.RIB5_2 = ORAS_2.Checked;
            pk6.RIB5_3 = ORAS_3.Checked;
            pk6.RIB5_4 = ORAS_4.Checked;
            pk6.RIB5_5 = ORAS_5.Checked;

            pk6.Memory_ContestCount = Util.ToInt32(TB_PastContest.Text);
            pk6.Memory_BattleCount  = Util.ToInt32(TB_PastBattle.Text);

            pk6.TrainingBag     = CB_Bag.SelectedIndex;
            pk6.TrainingBagHits = (int)NUD_BagHits.Value;
        }
コード例 #14
0
        private PKM preparePK6()
        {
            PK6 pk6 = pkm as PK6;

            if (pk6 == null)
            {
                return(null);
            }

            // Repopulate PK6 with Edited Stuff
            if (Util.getIndex(CB_GameOrigin) < 24)
            {
                uint EC  = Util.getHEXval(TB_EC.Text);
                uint PID = Util.getHEXval(TB_PID.Text);
                uint SID = Util.ToUInt32(TB_TID.Text);
                uint TID = Util.ToUInt32(TB_TID.Text);
                uint LID = PID & 0xFFFF;
                uint HID = PID >> 16;
                uint XOR = TID ^ LID ^ SID ^ HID;

                // Ensure we don't have a shiny.
                if (XOR >> 3 == 1) // Illegal, fix. (not 16<XOR>=8)
                {
                    // Keep as shiny, so we have to mod the PID
                    PID        ^= XOR;
                    TB_PID.Text = PID.ToString("X8");
                    TB_EC.Text  = PID.ToString("X8");
                }
                else if ((XOR ^ 0x8000) >> 3 == 1 && PID != EC)
                {
                    TB_EC.Text = (PID ^ 0x80000000).ToString("X8");
                }
                else // Not Illegal, no fix.
                {
                    TB_EC.Text = PID.ToString("X8");
                }
            }

            pk6.EncryptionConstant = Util.getHEXval(TB_EC.Text);
            pk6.Checksum           = 0; // 0 CHK for now

            // Block A
            pk6.Species       = Util.getIndex(CB_Species);
            pk6.HeldItem      = Util.getIndex(CB_HeldItem);
            pk6.TID           = Util.ToInt32(TB_TID.Text);
            pk6.SID           = Util.ToInt32(TB_SID.Text);
            pk6.EXP           = Util.ToUInt32(TB_EXP.Text);
            pk6.Ability       = (byte)Array.IndexOf(abilitylist, CB_Ability.Text.Remove(CB_Ability.Text.Length - 4));
            pk6.AbilityNumber = Util.ToInt32(TB_AbilityNumber.Text);   // Number
            // pkx[0x16], pkx[0x17] are handled by the Medals UI (Hits & Training Bag)
            pk6.PID              = Util.getHEXval(TB_PID.Text);
            pk6.Nature           = (byte)Util.getIndex(CB_Nature);
            pk6.FatefulEncounter = CHK_Fateful.Checked;
            pk6.Gender           = PKX.getGender(Label_Gender.Text);
            pk6.AltForm          = (MT_Form.Enabled ? Convert.ToInt32(MT_Form.Text) : CB_Form.Enabled ? CB_Form.SelectedIndex : 0) & 0x1F;
            pk6.EV_HP            = Util.ToInt32(TB_HPEV.Text); // EVs
            pk6.EV_ATK           = Util.ToInt32(TB_ATKEV.Text);
            pk6.EV_DEF           = Util.ToInt32(TB_DEFEV.Text);
            pk6.EV_SPE           = Util.ToInt32(TB_SPEEV.Text);
            pk6.EV_SPA           = Util.ToInt32(TB_SPAEV.Text);
            pk6.EV_SPD           = Util.ToInt32(TB_SPDEV.Text);

            pk6.CNT_Cool   = Util.ToInt32(TB_Cool.Text);     // CNT
            pk6.CNT_Beauty = Util.ToInt32(TB_Beauty.Text);
            pk6.CNT_Cute   = Util.ToInt32(TB_Cute.Text);
            pk6.CNT_Smart  = Util.ToInt32(TB_Smart.Text);
            pk6.CNT_Tough  = Util.ToInt32(TB_Tough.Text);
            pk6.CNT_Sheen  = Util.ToInt32(TB_Sheen.Text);

            pk6.PKRS_Days   = CB_PKRSDays.SelectedIndex;
            pk6.PKRS_Strain = CB_PKRSStrain.SelectedIndex;
            // Already in buff (then transferred to new pkx)
            // 0x2C, 0x2D, 0x2E, 0x2F
            // 0x30, 0x31, 0x32, 0x33
            // 0x34, 0x35, 0x36, 0x37
            // 0x38, 0x39

            // Unused
            // 0x3A, 0x3B
            // 0x3C, 0x3D, 0x3E, 0x3F

            // Block B
            // Convert Nickname field back to bytes
            pk6.Nickname     = TB_Nickname.Text;
            pk6.Move1        = Util.getIndex(CB_Move1);
            pk6.Move2        = Util.getIndex(CB_Move2);
            pk6.Move3        = Util.getIndex(CB_Move3);
            pk6.Move4        = Util.getIndex(CB_Move4);
            pk6.Move1_PP     = Util.getIndex(CB_Move1) > 0 ? Util.ToInt32(TB_PP1.Text) : 0;
            pk6.Move2_PP     = Util.getIndex(CB_Move2) > 0 ? Util.ToInt32(TB_PP2.Text) : 0;
            pk6.Move3_PP     = Util.getIndex(CB_Move3) > 0 ? Util.ToInt32(TB_PP3.Text) : 0;
            pk6.Move4_PP     = Util.getIndex(CB_Move4) > 0 ? Util.ToInt32(TB_PP4.Text) : 0;
            pk6.Move1_PPUps  = Util.getIndex(CB_Move1) > 0 ? CB_PPu1.SelectedIndex : 0;
            pk6.Move2_PPUps  = Util.getIndex(CB_Move2) > 0 ? CB_PPu2.SelectedIndex : 0;
            pk6.Move3_PPUps  = Util.getIndex(CB_Move3) > 0 ? CB_PPu3.SelectedIndex : 0;
            pk6.Move4_PPUps  = Util.getIndex(CB_Move4) > 0 ? CB_PPu4.SelectedIndex : 0;
            pk6.RelearnMove1 = Util.getIndex(CB_RelearnMove1);
            pk6.RelearnMove2 = Util.getIndex(CB_RelearnMove2);
            pk6.RelearnMove3 = Util.getIndex(CB_RelearnMove3);
            pk6.RelearnMove4 = Util.getIndex(CB_RelearnMove4);
            // 0x72 - Ribbon editor sets this flag (Secret Super Training)
            // 0x73
            pk6.IV_HP       = Util.ToInt32(TB_HPIV.Text);
            pk6.IV_ATK      = Util.ToInt32(TB_ATKIV.Text);
            pk6.IV_DEF      = Util.ToInt32(TB_DEFIV.Text);
            pk6.IV_SPE      = Util.ToInt32(TB_SPEIV.Text);
            pk6.IV_SPA      = Util.ToInt32(TB_SPAIV.Text);
            pk6.IV_SPD      = Util.ToInt32(TB_SPDIV.Text);
            pk6.IsEgg       = CHK_IsEgg.Checked;
            pk6.IsNicknamed = CHK_Nicknamed.Checked;

            // Block C
            pk6.HT_Name = TB_OTt2.Text;

            // 0x90-0xAF
            pk6.HT_Gender = PKX.getGender(Label_CTGender.Text);
            // Plus more, set by MemoryAmie (already in buff)

            // Block D
            pk6.OT_Name           = TB_OT.Text;
            pk6.CurrentFriendship = Util.ToInt32(TB_Friendship.Text);

            DateTime?egg_date     = null;
            int      egg_location = 0;

            if (CHK_AsEgg.Checked)      // If encountered as an egg, load the Egg Met data from fields.
            {
                egg_date     = CAL_EggDate.Value;
                egg_location = Util.getIndex(CB_EggLocation);
            }
            // Egg Met Data
            pk6.EggMetDate   = egg_date;
            pk6.Egg_Location = egg_location;
            // Met Data
            pk6.MetDate      = CAL_MetDate.Value;
            pk6.Met_Location = Util.getIndex(CB_MetLocation);

            if (pk6.IsEgg && pk6.Met_Location == 0)    // If still an egg, it has no hatch location/date. Zero it!
            {
                pk6.MetDate = null;
            }

            // 0xD7 Unknown

            pk6.Ball          = Util.getIndex(CB_Ball);
            pk6.Met_Level     = Util.ToInt32(TB_MetLevel.Text);
            pk6.OT_Gender     = PKX.getGender(Label_OTGender.Text);
            pk6.EncounterType = Util.getIndex(CB_EncounterType);
            pk6.Version       = Util.getIndex(CB_GameOrigin);
            pk6.Country       = Util.getIndex(CB_Country);
            pk6.Region        = Util.getIndex(CB_SubRegion);
            pk6.ConsoleRegion = Util.getIndex(CB_3DSReg);
            pk6.Language      = Util.getIndex(CB_Language);
            // 0xE4-0xE7

            // Toss in Party Stats
            Array.Resize(ref pk6.Data, pk6.SIZE_PARTY);
            pk6.Stat_Level     = Util.ToInt32(TB_Level.Text);
            pk6.Stat_HPCurrent = Util.ToInt32(Stat_HP.Text);
            pk6.Stat_HPMax     = Util.ToInt32(Stat_HP.Text);
            pk6.Stat_ATK       = Util.ToInt32(Stat_ATK.Text);
            pk6.Stat_DEF       = Util.ToInt32(Stat_DEF.Text);
            pk6.Stat_SPE       = Util.ToInt32(Stat_SPE.Text);
            pk6.Stat_SPA       = Util.ToInt32(Stat_SPA.Text);
            pk6.Stat_SPD       = Util.ToInt32(Stat_SPD.Text);

            // Unneeded Party Stats (Status, Flags, Unused)
            pk6.Data[0xE8]              = pk6.Data[0xE9] = pk6.Data[0xEA] = pk6.Data[0xEB] =
                pk6.Data[0xED]          = pk6.Data[0xEE] = pk6.Data[0xEF] =
                    pk6.Data[0xFE]      = pk6.Data[0xFF] = pk6.Data[0x100] =
                        pk6.Data[0x101] = pk6.Data[0x102] = pk6.Data[0x103] = 0;

            // Hax Illegality
            if (HaX)
            {
                pk6.Ability    = (byte)Util.getIndex(DEV_Ability);
                pk6.Stat_Level = (byte)Math.Min(Convert.ToInt32(MT_Level.Text), byte.MaxValue);
            }

            // Fix Moves if a slot is empty
            pk6.FixMoves();
            pk6.FixRelearn();

            // Fix Handler (Memories & OT) -- no foreign memories for Pokemon without a foreign trainer (none for eggs)
            if (Menu_ModifyPKM.Checked)
            {
                pk6.FixMemories();
            }

            // PKX is now filled
            pk6.RefreshChecksum();
            return(pk6);
        }
コード例 #15
0
        private void save()
        {
            SAV.Game   = (byte)(CB_Game.SelectedIndex + 0x18);
            SAV.Gender = (byte)CB_Gender.SelectedIndex;

            SAV.TID           = (ushort)Util.ToUInt32(MT_TID.Text);
            SAV.SID           = (ushort)Util.ToUInt32(MT_SID.Text);
            SAV.Money         = Util.ToUInt32(MT_Money.Text);
            SAV.SubRegion     = Util.ToInt32(CB_Region.SelectedValue.ToString());
            SAV.Country       = Util.ToInt32(CB_Country.SelectedValue.ToString());
            SAV.ConsoleRegion = Util.ToInt32(CB_3DSReg.SelectedValue.ToString());
            SAV.Language      = Util.ToInt32(CB_Language.SelectedValue.ToString());

            SAV.OT = TB_OTName.Text;

            SAV.Saying1 = TB_Saying1.Text;
            SAV.Saying2 = TB_Saying2.Text;
            SAV.Saying3 = TB_Saying3.Text;
            SAV.Saying4 = TB_Saying4.Text;
            SAV.Saying5 = TB_Saying5.Text;

            // Copy Maison Data in
            for (int i = 0; i < MaisonRecords.Length; i++)
            {
                SAV.setMaisonStat(i, UInt16.Parse(MaisonRecords[i].Text));
            }

            // Copy Position
            SAV.M = (int)NUD_M.Value;
            SAV.X = (float)NUD_X.Value;
            SAV.Z = (float)NUD_M.Value;
            SAV.Y = (float)NUD_Y.Value;

            SAV.BP = UInt16.Parse(TB_BP.Text);
            // Set Current PokéMiles
            SAV.setPSSStat(0xFC / 4, Util.ToUInt32(TB_PM.Text));
            // Set Max Obtained Pokémiles
            SAV.setPSSStat(0x100 / 4, Util.ToUInt32(TB_PM.Text));
            SAV.Style = Byte.Parse(TB_Style.Text);

            // Copy Badges
            int badgeval = 0;

            CheckBox[] cba = { cb1, cb2, cb3, cb4, cb5, cb6, cb7, cb8, };
            for (int i = 0; i < 8; i++)
            {
                badgeval |= (cba[i].Checked ? 1 : 0) << i;
            }
            SAV.Badges = badgeval;

            // Save PlayTime
            SAV.PlayedHours   = UInt16.Parse(MT_Hours.Text);
            SAV.PlayedMinutes = UInt16.Parse(MT_Minutes.Text) % 60;
            SAV.PlayedSeconds = UInt16.Parse(MT_Seconds.Text) % 60;

            // Sprite
            SAV.Sprite = Convert.ToByte(CB_Multi.SelectedValue);

            // Appearance
            if (SAV.XY)
            {
                SAV.Data[SAV.TrainerCard + 0x30] = Byte.Parse(MT_14030.Text);
                SAV.Data[SAV.TrainerCard + 0x31] = (byte)(Byte.Parse(MT_HairColor.Text) + (Byte.Parse(MT_Hat.Text) << 3));
                SAV.Data[SAV.TrainerCard + 0x32] = Byte.Parse(MT_14032.Text);
                SAV.Data[SAV.TrainerCard + 0x33] = Byte.Parse(MT_14033.Text);
                SAV.Data[SAV.TrainerCard + 0x34] = Byte.Parse(MT_14034.Text);
                SAV.Data[SAV.TrainerCard + 0x35] = Byte.Parse(MT_14035.Text);
                SAV.Data[SAV.TrainerCard + 0x36] = Byte.Parse(MT_14036.Text);
                SAV.Data[SAV.TrainerCard + 0x37] = Byte.Parse(MT_14037.Text);
                SAV.Data[SAV.TrainerCard + 0x38] = Byte.Parse(MT_14038.Text);
                SAV.Data[SAV.TrainerCard + 0x39] = Byte.Parse(MT_14039.Text);
                SAV.Data[SAV.TrainerCard + 0x3A] = Byte.Parse(MT_1403A.Text);
                SAV.Data[SAV.TrainerCard + 0x3B] = Byte.Parse(MT_1403B.Text);
                SAV.Data[SAV.TrainerCard + 0x3C] = Byte.Parse(MT_1403C.Text);
                SAV.Data[SAV.TrainerCard + 0x3D] = Byte.Parse(MT_1403D.Text);
                SAV.Data[SAV.TrainerCard + 0x3E] = Byte.Parse(MT_1403E.Text);
                SAV.Data[SAV.TrainerCard + 0x3F] = Byte.Parse(MT_1403F.Text);
            }

            // Vivillon
            SAV.Vivillon = CB_Vivillon.SelectedIndex;
        }
コード例 #16
0
ファイル: MainPK4.cs プロジェクト: akoimeexx/PKHeX
        private PKM preparePK4()
        {
            PK4 pk4 = pkm as PK4;

            if (pk4 == null)
            {
                return(null);
            }

            pk4.Species  = Util.getIndex(CB_Species);
            pk4.HeldItem = Util.getIndex(CB_HeldItem);
            pk4.TID      = Util.ToInt32(TB_TID.Text);
            pk4.SID      = Util.ToInt32(TB_SID.Text);
            pk4.EXP      = Util.ToUInt32(TB_EXP.Text);
            pk4.PID      = Util.getHEXval(TB_PID.Text);
            pk4.Ability  = (byte)Array.IndexOf(abilitylist, CB_Ability.Text.Remove(CB_Ability.Text.Length - 4));

            pk4.FatefulEncounter = CHK_Fateful.Checked;
            pk4.Gender           = PKX.getGender(Label_Gender.Text);
            pk4.AltForm          = (MT_Form.Enabled ? Convert.ToInt32(MT_Form.Text) : CB_Form.Enabled ? CB_Form.SelectedIndex : 0) & 0x1F;
            pk4.EV_HP            = Util.ToInt32(TB_HPEV.Text);
            pk4.EV_ATK           = Util.ToInt32(TB_ATKEV.Text);
            pk4.EV_DEF           = Util.ToInt32(TB_DEFEV.Text);
            pk4.EV_SPE           = Util.ToInt32(TB_SPEEV.Text);
            pk4.EV_SPA           = Util.ToInt32(TB_SPAEV.Text);
            pk4.EV_SPD           = Util.ToInt32(TB_SPDEV.Text);

            pk4.CNT_Cool   = Util.ToInt32(TB_Cool.Text);
            pk4.CNT_Beauty = Util.ToInt32(TB_Beauty.Text);
            pk4.CNT_Cute   = Util.ToInt32(TB_Cute.Text);
            pk4.CNT_Smart  = Util.ToInt32(TB_Smart.Text);
            pk4.CNT_Tough  = Util.ToInt32(TB_Tough.Text);
            pk4.CNT_Sheen  = Util.ToInt32(TB_Sheen.Text);

            pk4.PKRS_Days   = CB_PKRSDays.SelectedIndex;
            pk4.PKRS_Strain = CB_PKRSStrain.SelectedIndex;
            pk4.Nickname    = TB_Nickname.Text;
            pk4.Move1       = Util.getIndex(CB_Move1);
            pk4.Move2       = Util.getIndex(CB_Move2);
            pk4.Move3       = Util.getIndex(CB_Move3);
            pk4.Move4       = Util.getIndex(CB_Move4);
            pk4.Move1_PP    = Util.getIndex(CB_Move1) > 0 ? Util.ToInt32(TB_PP1.Text) : 0;
            pk4.Move2_PP    = Util.getIndex(CB_Move2) > 0 ? Util.ToInt32(TB_PP2.Text) : 0;
            pk4.Move3_PP    = Util.getIndex(CB_Move3) > 0 ? Util.ToInt32(TB_PP3.Text) : 0;
            pk4.Move4_PP    = Util.getIndex(CB_Move4) > 0 ? Util.ToInt32(TB_PP4.Text) : 0;
            pk4.Move1_PPUps = Util.getIndex(CB_Move1) > 0 ? CB_PPu1.SelectedIndex : 0;
            pk4.Move2_PPUps = Util.getIndex(CB_Move2) > 0 ? CB_PPu2.SelectedIndex : 0;
            pk4.Move3_PPUps = Util.getIndex(CB_Move3) > 0 ? CB_PPu3.SelectedIndex : 0;
            pk4.Move4_PPUps = Util.getIndex(CB_Move4) > 0 ? CB_PPu4.SelectedIndex : 0;

            pk4.IV_HP       = Util.ToInt32(TB_HPIV.Text);
            pk4.IV_ATK      = Util.ToInt32(TB_ATKIV.Text);
            pk4.IV_DEF      = Util.ToInt32(TB_DEFIV.Text);
            pk4.IV_SPE      = Util.ToInt32(TB_SPEIV.Text);
            pk4.IV_SPA      = Util.ToInt32(TB_SPAIV.Text);
            pk4.IV_SPD      = Util.ToInt32(TB_SPDIV.Text);
            pk4.IsEgg       = CHK_IsEgg.Checked;
            pk4.IsNicknamed = CHK_Nicknamed.Checked;

            pk4.OT_Name           = TB_OT.Text;
            pk4.CurrentFriendship = Util.ToInt32(TB_Friendship.Text);

            pk4.Ball          = Util.getIndex(CB_Ball);
            pk4.Met_Level     = Util.ToInt32(TB_MetLevel.Text);
            pk4.OT_Gender     = PKX.getGender(Label_OTGender.Text);
            pk4.EncounterType = Util.getIndex(CB_EncounterType);
            pk4.Version       = Util.getIndex(CB_GameOrigin);
            pk4.Language      = Util.getIndex(CB_Language);

            // Default Dates
            DateTime?egg_date     = null;
            int      egg_location = 0;

            if (CHK_AsEgg.Checked) // If encountered as an egg, load the Egg Met data from fields.
            {
                egg_date     = CAL_EggDate.Value;
                egg_location = Util.getIndex(CB_EggLocation);
            }
            // Egg Met Data
            pk4.EggMetDate   = egg_date;
            pk4.Egg_Location = egg_location;
            // Met Data
            pk4.MetDate      = CAL_MetDate.Value;
            pk4.Met_Location = Util.getIndex(CB_MetLocation);

            if (pk4.IsEgg && pk4.Met_Location == 0)    // If still an egg, it has no hatch location/date. Zero it!
            {
                pk4.MetDate = null;
            }

            // Toss in Party Stats
            Array.Resize(ref pk4.Data, pk4.SIZE_PARTY);
            pk4.Stat_Level     = Util.ToInt32(TB_Level.Text);
            pk4.Stat_HPCurrent = Util.ToInt32(Stat_HP.Text);
            pk4.Stat_HPMax     = Util.ToInt32(Stat_HP.Text);
            pk4.Stat_ATK       = Util.ToInt32(Stat_ATK.Text);
            pk4.Stat_DEF       = Util.ToInt32(Stat_DEF.Text);
            pk4.Stat_SPE       = Util.ToInt32(Stat_SPE.Text);
            pk4.Stat_SPA       = Util.ToInt32(Stat_SPA.Text);
            pk4.Stat_SPD       = Util.ToInt32(Stat_SPD.Text);

            if (HaX)
            {
                pk4.Ability    = (byte)Util.getIndex(DEV_Ability);
                pk4.Stat_Level = (byte)Math.Min(Convert.ToInt32(MT_Level.Text), byte.MaxValue);
            }

            // Fix Moves if a slot is empty
            pk4.FixMoves();

            pk4.RefreshChecksum();
            return(pk4);
        }
コード例 #17
0
        // Parsing Utility
        public ShowdownSet(string input = null)
        {
            if (input == null)
            {
                return;
            }

            Nickname   = null;
            Species    = -1;
            Form       = null;
            Gender     = null;
            Item       = 0;
            Ability    = 0;
            Level      = 100;
            Shiny      = false;
            Friendship = 255;
            Nature     = 0;
            EVs        = new int[6];
            IVs        = new[] { 31, 31, 31, 31, 31, 31 };
            Moves      = new int[4];

            string[] lines = input.Split(new[] { "\r\n", "\n" }, StringSplitOptions.None);
            for (int i = 0; i < lines.Length; i++)
            {
                lines[i] = lines[i].Replace("'", "’").Trim();                                    // Sanitize apostrophes
            }
            if (lines.Length < 3)
            {
                return;
            }

            // Seek for start of set
            int start = -1;

            for (int i = 0; i < lines.Length; i++)
            {
                if (lines[i].Contains(" @ "))
                {
                    start = i; break;
                }
            }
            lines = lines.Skip(start).Take(lines.Length - start).ToArray();

            // Abort if no text is found
            if (start == -1)
            {
                // Try to parse the first line if it does not have any item
                string ld = lines[0];
                // Gender Detection
                string last3 = ld.Substring(ld.Length - 3);
                if (last3 == "(M)" || last3 == "(F)")
                {
                    Gender = last3.Substring(1, 1);
                    ld     = ld.Substring(0, ld.Length - 3);
                }
                // Nickname Detection
                string spec = ld;
                if (spec.Contains("("))
                {
                    int    index = spec.LastIndexOf("(", StringComparison.Ordinal);
                    string n1    = spec.Substring(0, index - 1);
                    string n2    = spec.Substring(index).Replace("(", "").Replace(")", "").Replace(" ", "");

                    bool inverted = Array.IndexOf(species, n2.Replace(" ", "")) > -1 || (Species = Array.IndexOf(species, n2.Split('-')[0])) > 0;
                    spec     = inverted ? n2 : n1;
                    Nickname = inverted ? n1 : n2;
                }
                Species = Array.IndexOf(species, spec.Replace(" ", ""));
                if (
                    (Species = Array.IndexOf(species, spec)) < 0                  // Not an Edge Case
                    &&
                    (Species = Array.IndexOf(species, spec.Replace(" ", ""))) < 0 // Has Form
                    )
                {
                    string[] tmp = spec.Split(new[] { "-" }, StringSplitOptions.None);
                    if (tmp.Length < 2)
                    {
                        return;
                    }
                    Species = Array.IndexOf(species, tmp[0].Replace(" ", ""));
                    Form    = tmp[1].Trim();
                    if (tmp.Length > 2)
                    {
                        Form += " " + tmp[2];
                    }
                }
                if (Species < -1)
                {
                    return;
                }
                lines = lines.Skip(1).Take(lines.Length - 1).ToArray();
            }
            int movectr = 0;

            // Detect relevant data
            foreach (string line in lines)
            {
                if (line.Length < 2)
                {
                    continue;
                }
                if (line.Contains("- "))
                {
                    string moveString = line.Substring(2);
                    if (moveString.Contains("Hidden Power"))
                    {
                        if (moveString.Length > 13)                                                    // Defined Hidden Power
                        {
                            string type  = moveString.Remove(0, 13).Replace("[", "").Replace("]", ""); // Trim out excess data
                            int    hpVal = Array.IndexOf(hptypes, type);                               // Get HP Type
                            if (hpVal >= 0)
                            {
                                IVs = PKX.setHPIVs(hpVal, IVs);             // Get IVs
                            }
                        }
                        moveString = "Hidden Power";
                    }
                    Moves[movectr++] = Array.IndexOf(moves, moveString);
                    if (movectr == 4)
                    {
                        break; // End of moves
                    }
                    continue;
                }

                string[] brokenline = line.Split(new[] { ": " }, StringSplitOptions.None);
                switch (brokenline[0])
                {
                case "Trait":
                case "Ability": { Ability = Array.IndexOf(abilities, brokenline[1]); break; }

                case "Level": { Level = Util.ToInt32(brokenline[1]); break; }

                case "Shiny": { Shiny = brokenline[1] == "Yes"; break; }

                case "Happiness": { Friendship = Util.ToInt32(brokenline[1]); break; }

                case "EVs":
                {
                    // Get EV list String
                    string[] evlist = brokenline[1].Replace("SAtk", "SpA").Replace("SDef", "SpD").Replace("Spd", "Spe").Split(new[] { " / ", " " }, StringSplitOptions.None);
                    for (int i = 0; i < evlist.Length / 2; i++)
                    {
                        EVs[Array.IndexOf(StatNames, evlist[1 + i * 2])] = (byte)Util.ToInt32(evlist[0 + 2 * i]);
                    }
                    break;
                }

                case "IVs":
                {
                    // Get IV list String
                    string[] ivlist = brokenline[1].Split(new[] { " / ", " " }, StringSplitOptions.None);
                    for (int i = 0; i < ivlist.Length / 2; i++)
                    {
                        IVs[Array.IndexOf(StatNames, ivlist[1 + i * 2])] = (byte)Util.ToInt32(ivlist[0 + 2 * i]);
                    }
                    break;
                }

                default:
                {
                    // Either Nature or Gender ItemSpecies
                    if (brokenline[0].Contains(" @ "))
                    {
                        string[] ld = line.Split(new[] { " @ " }, StringSplitOptions.None);
                        Item = Array.IndexOf(items, ld.Last());
                        // Gender Detection
                        string last3 = ld[0].Substring(ld[0].Length - 3);
                        if (last3 == "(M)" || last3 == "(F)")
                        {
                            Gender = last3.Substring(1, 1);
                            ld[0]  = ld[0].Substring(0, ld[ld.Length - 2].Length - 3);
                        }
                        // Nickname Detection
                        string spec = ld[0];
                        if (spec.Contains("("))
                        {
                            int    index = spec.LastIndexOf("(", StringComparison.Ordinal);
                            string n1    = spec.Substring(0, index - 1);
                            string n2    = spec.Substring(index).Replace("(", "").Replace(")", "").Replace(" ", "");

                            bool inverted = Array.IndexOf(species, n2.Replace(" ", "")) > -1 || (Species = Array.IndexOf(species, n2.Split('-')[0])) > 0;
                            spec     = inverted ? n2 : n1;
                            Nickname = inverted ? n1 : n2;
                        }
                        if (
                            (Species = Array.IndexOf(species, spec)) < 0                  // Not an Edge Case
                            &&
                            (Species = Array.IndexOf(species, spec.Replace(" ", ""))) < 0 // Has Form
                            )
                        {
                            string[] tmp = spec.Split(new[] { "-" }, StringSplitOptions.None);
                            Species = Array.IndexOf(species, tmp[0].Replace(" ", ""));
                            Form    = tmp[1].Trim();
                            if (tmp.Length > 2)
                            {
                                Form += " " + tmp[2];
                            }
                        }
                    }
                    else if (brokenline[0].Contains("Nature"))
                    {
                        Nature = Array.IndexOf(natures, line.Split(' ')[0]);
                    }
                    else         // Fallback
                    {
                        Species = Array.IndexOf(species, line.Split('(')[0]);
                    }
                }
                break;
                }
            }
        }