Esempio n. 1
0
        private void btnImport_Click(object sender, EventArgs e)
        {
            if (cbWoWVersion.SelectedItem == null)
            {
                ShowErrorMessage("WoW Version not selected");
                return;
            }

            // Check learning order
            int[] ls = null;
            if (tbLearningOrder.Text.Equals(""))
            {
                ls = new int[] { 1, 2, 3 }
            }
            ;
            else
            {
                string[] lorder = tbLearningOrder.Text.Split(',');
                int      ll     = lorder.Length;
                if (ll > 3)
                {
                    ShowErrorMessage("Invalid learning sequence '" + tbLearningOrder.Text +
                                     "'. Number of tabs exceed 3");
                    return;
                }

                // convert each tab to int
                ls = new int[ll];

                try
                {
                    for (int i = 0; i < ll; i++)
                    {
                        ls[i] = Convert.ToInt32(lorder[i]);
                    }
                } catch {
                    ShowErrorMessage("Invalid Tab Id parameter in learning sequence '" +
                                     tbLearningOrder.Text + "'");
                    return;
                }
            }

            // Finally process URL
            try
            {
                string url = tbTalentURL.Text;
                // Check for class id
                Match m = trex.Match(url);

                if (m.Success && (m.Groups.Count == 3))
                {
                    string s   = m.Groups[1].ToString();
                    byte   cid = Convert.ToByte(s);
                    string ts  = m.Groups[2].ToString();

                    // string response = ReadURL(url);

                    // Find class
                    WoWVersion cur_version = (WoWVersion)cbWoWVersion.SelectedItem;
                    CharClass  cc          = cur_version.Classes.FindClassByArmoryId(cid);

                    // Check if Class defined
                    if (cc == null)
                    {
                        ShowErrorMessage("Unable find class for Armory ID " + cid);
                        return;
                    }

                    // Check size of talents
                    int cc_total = cc.TotalTalentSum;
                    if (cc_total != ts.Length)
                    {
                        ShowErrorMessage("Length of talent's URL parameter " + ts.Length +
                                         " different from class parameter length " + cc_total +
                                         " configured in WoWData.xml");
                        return;
                    }


                    byte[] tabs_len = cc.Tabs;

                    // Convert talent list to byte array
                    byte[] tlist = new byte[cc_total];
                    for (int i = 0; i < cc_total; i++)
                    {
                        tlist[i] = Convert.ToByte(ts.Substring(i, 1));
                    }

                    byte num = cur_version.TalentConfig.StartLevel;

                    // Select class
                    cbClass.SelectedItem = cc;
                    cbClass.Enabled      = false;

                    // Clear CurTalents
                    if (CurTalents == null)
                    {
                        CurTalents = new Talents();
                    }
                    else
                    {
                        btnReset_Click(sender, e);
                    }

                    BindLevels();

                    for (int i = 0; i < ls.Length; i++)
                    {
                        int cur_tab_id = ls[i];
                        int offset     = 0;
                        for (int j = 0; j < cur_tab_id - 1; j++)
                        {
                            offset += tabs_len[j];
                        }

                        int cur_tab_len = tabs_len[cur_tab_id - 1];
                        for (int j = 0; j < cur_tab_len; j++)
                        {
                            byte ct = tlist[offset + j];
                            // Added current talent with all ranks
                            for (int k = 1; k <= ct; k++)
                            {
                                CurTalents.AddLevel(new Level(num, cur_tab_id, j + 1, k));
                                num++;
                                RefreshLevelList();
                            }
                        }
                    }
                }
                else
                {
                    ShowErrorMessage(string.Format(
                                         "Invalid URL. '{0}' excpected", trex.ToString()));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable read URL: " + ex.Message);
            }
        }