Пример #1
0
        public Hero clone()
        {
            try
            {
                Hero second = new Hero();
                foreach (System.Reflection.PropertyInfo pf in this.GetType().GetProperties())
                {
                    pf.SetValue(second, pf.GetValue(this, null), null);
                }

                return second;
            }
            catch //(Exception ex)
            {
                return null;
                //System.Windows.Forms.MessageBox.Show(ex.ToString());
                throw;
            }
        }
Пример #2
0
        public bool compare(Hero second)
        {
            try
            {
                string name;
                foreach (System.Reflection.PropertyInfo pf in this.GetType().GetProperties())
                {
                    name = pf.Name;
                    if ((pf.GetValue(this, null) == null) && (pf.GetValue(second, null) != null))
                    {
                        return false;
                    }
                    else if ((pf.GetValue(this, null) == null) && (pf.GetValue(second, null) == null))
                    {
                        //Do nothing
                    }
                    else if (!pf.GetValue(this, null).Equals(pf.GetValue(second, null)))
                    {
                        return false;
                    }
                }

                return true;
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.ToString());
                throw;
            }
        }
        private void heroUpdates()
        {
            // Stop the timer while updates are being parsed
            bool statsAndInfoLoaded = false;
            _timer.Stop();
            _timer.Enabled = false;

            try
            {
                if (webBrowser1.Document != null)
                {
                    if (isSmall)
                    {
                        lblEncourage.Visible = true;
                        lblPunish.Visible = true;
                    }
                    else
                    {
                        lblEncourage.Visible = false;
                        lblPunish.Visible = false;
                    }

                    // Try to make sure the whole page is loaded... there is probably a much better way,
                    // but this seems to work for the most part.
                    if (webBrowser1.Document.Body.InnerHtml.IndexOf("Remote Control", StringComparison.InvariantCultureIgnoreCase) > 0
                        & webBrowser1.Document.Body.InnerHtml.IndexOf("Hero's Diary", StringComparison.InvariantCultureIgnoreCase) > 0
                        )
                    {
                        //GetTurboLight(webBrowser1.Document.All["turbo_icon"].GetAttribute("class"));

                        int start = webBrowser1.Document.Body.InnerHtml.IndexOf("Greetings, ", StringComparison.InvariantCultureIgnoreCase) + 11;
                        int end = webBrowser1.Document.Body.InnerHtml.IndexOf("</b>", start, StringComparison.InvariantCultureIgnoreCase) - 1;
                        hero.GodName = webBrowser1.Document.Body.InnerHtml.Substring(start, end - start);

                        foreach (HtmlElement item in webBrowser1.Document.GetElementsByTagName("DIV"))
                        {
                            if (item.ClassName() == "gp_val")
                            {
                                hero.GodPower = int.Parse(item.InnerText.Replace("%", "").Replace("Nan", "0"));
                                break;
                            }
                        }

                        foreach (HtmlElement tag in webBrowser1.Document.GetElementsByTagName("SPAN"))
                        {
                            if (tag.InnerText != null)
                            {
                                if (tag.InnerText.Equals("Encourage", StringComparison.InvariantCultureIgnoreCase))
                                {
                                    lnkEncourage = tag;
                                    lblEncourage.Enabled = true;
                                }
                                else if (tag.InnerText.Equals("Punish", StringComparison.InvariantCultureIgnoreCase))
                                {
                                    lnkPunish = tag;
                                    lblPunish.Enabled = true;
                                }
                                else if (tag.InnerText.Equals("Restore", StringComparison.InvariantCultureIgnoreCase))
                                {
                                    lnkRestoreGodPower = tag;
                                }
                                else if (tag.InnerText.Equals("Send to Arena", StringComparison.InvariantCultureIgnoreCase))
                                {
                                    lnkSendToArena = tag;
                                }
                                else if (tag.InnerText.Equals("Make a Miracle", StringComparison.InvariantCultureIgnoreCase))
                                {
                                    lnkMakeMiracle = tag;
                                }
                                else if (tag.InnerText.Equals("Challenge Friend", StringComparison.InvariantCultureIgnoreCase))
                                {
                                    lnkChallengeFriend = tag;
                                }
                                if (tag.ClassName() == "acc_val")
                                {
                                    hero.Charges = int.Parse((tag.InnerText ?? "").Trim() == "" ? "0" : tag.InnerText);
                                }
                            }
                        }

                        statsAndInfoLoaded = heroInfo();

                        petInfo();
                        Application.DoEvents();

                        pantheonStatus();
                        Application.DoEvents();

                        earthlyNews();
                        Application.DoEvents();

                        heroDiary();
                        Application.DoEvents();

                        heroInventory();
                        Application.DoEvents();

                        heroEquipment();
                        Application.DoEvents();

                        heroSkills();
                        Application.DoEvents();

                        if (statsAndInfoLoaded)
                        {
                            // Update the miniature Summary UI
                            if (!String.IsNullOrEmpty(hero.TownName))
                                this.Text = String.Format("Godville: {0} - {1} ({2})", hero.GodName, hero.Name, hero.TownName);
                            else
                                this.Text = String.Format("Godville: {0} - {1} (Adventuring)", hero.GodName, hero.Name);
                            lblHero.Text = String.Format("H: {0}%  GP: {1}%  G: {2} coins  Q: {3}%  Mi: {4}", (hero.Health * 100 / hero.MaxHealth), hero.GodPower, hero.Gold, hero.QuestPercent, hero.MilestonesPassed);
                            lblHero.Refresh();
                            lblDiary.Enabled = true;
                            lblRules.Enabled = true;
                            Application.DoEvents();

                            // If the hero has any updated info, then update the db and clone the current copy
                            if (!hero.compare(oldHero))
                            {
                                oldHero = hero.clone();
                                hero.saveHero();
                            }
                            executeRules();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                throw;
            }
            finally
            {
                // Start the timer backup.  If the stats have not been loaded,
                // then the page is still loading via AJAX, so keep the timer going
                // at 5 seconds, otherwise switch to 30 seconds
                if (!_timer.Enabled)
                {
                    _timer.Enabled = true;
                    _timer.Tick += new EventHandler(_timer_Tick);
                    _timer.Interval = (statsAndInfoLoaded ? 30 : 5) * 1000;
                    _timer.Start();
                }
            }
        }