Ejemplo n.º 1
0
        public void UpdateUc()
        {
            var acc = GetSelectedAcc();

            buyAdventuresCheckBox.Checked        = acc.Hero.Settings.BuyAdventures;
            checkBoxAutoSendToAdventures.Checked = acc.Hero.Settings.AutoSendToAdventure;
            minHeroHealthUpDown.Value            = acc.Hero.Settings.MinHealth;
            autoReviveHero.Checked = acc.Hero.Settings.AutoReviveHero;
            refreshInfo.Checked    = acc.Hero.Settings.AutoRefreshInfo;
            helmetSwitcher.Checked = acc.Hero.Settings.AutoSwitchHelmets;
            autoEquip.Checked      = acc.Hero.Settings.AutoEquip;

            var heroUpgrade = acc.Hero.Settings.Upgrades;

            strength.Value  = 0;
            offBonus.Value  = 0;
            deffBonus.Value = 0;
            resources.Value = 0;
            strength.Value  = heroUpgrade[0];
            offBonus.Value  = heroUpgrade[1];
            deffBonus.Value = heroUpgrade[2];
            resources.Value = heroUpgrade[3];

            autoSetHeroPoints.Checked = acc.Hero.Settings.AutoSetPoints;
            maxDistanceUpDown.Value   = acc.Hero.Settings.MaxDistance;
            LimitHeroPoints();

            maxInterval.Value = acc.Hero.Settings.MaxUpdate;
            minInterval.Value = acc.Hero.Settings.MinUpdate;

            SupplyResVillageComboBox.Items.Clear();
            foreach (var vill in acc.Villages)
            {
                SupplyResVillageComboBox.Items.Add(vill.Name);
            }
            if (SupplyResVillageComboBox.Items.Count > 0)
            {
                SupplyResVillageComboBox.SelectedIndex = 0;
                SupplyResVillageSelected.Text          = "Selected: " + AccountHelper.GetHeroReviveVillage(acc).Name;
            }

            if (acc.Hero.Items == null)
            {
                return;
            }

            heroItemsList.Items.Clear();
            if (acc.Hero.Items.Count > 0)
            {
                foreach (var item in acc.Hero.Items)
                {
                    var viewItem = new ListViewItem();

                    var attr = item.Item.ToString().Split('_');

                    viewItem.SubItems[0].Text = attr[0];
                    viewItem.SubItems.Add(attr[1]);
                    viewItem.SubItems.Add(attr[2] == "0" ? "" : attr[2]);
                    viewItem.SubItems.Add(item.Count.ToString());

                    heroItemsList.Items.Add(viewItem);
                }
            }

            equiptList.Items.Clear();
            if (acc.Hero.Equipt == null)
            {
                acc.Hero.Equipt = new System.Collections.Generic.Dictionary <Classificator.HeroItemCategory, Classificator.HeroItemEnum>();
            }
            foreach (var pair in acc.Hero.Equipt)
            {
                var viewItem = new ListViewItem();

                var attr = pair.Value.ToString().Split('_');

                viewItem.SubItems[0].Text = attr[0];
                viewItem.SubItems.Add(attr[1]);
                viewItem.SubItems.Add(attr[2] == "0" ? "" : attr[2]);

                equiptList.Items.Add(viewItem);
            }

            // Update hero info
            string heroInfoStr = $"Health: {acc.Hero.HeroInfo.Health}\n";

            heroInfoStr  += $"Hero Status: {acc.Hero.Status}\n";
            heroInfoStr  += $"Hero home village: {HeroHelper.GetHeroHomeVillage(acc)?.Name ?? "UNKNOWN"}\n";
            heroInfoStr  += $"Hero Arrival: {acc.Hero.HeroArrival}\n";
            heroInfoStr  += $"Level: {acc.Hero.HeroInfo.Level}\n";
            heroInfoStr  += $"Experience: {acc.Hero.HeroInfo.Experience}\n";
            heroInfoStr  += $"Attack points: {acc.Hero.HeroInfo.FightingStrengthPoints}\n";
            heroInfoStr  += $"Off Bonus points: {acc.Hero.HeroInfo.OffBonusPoints}\n";
            heroInfoStr  += $"Deff Bonus points: {acc.Hero.HeroInfo.DeffBonusPoints}\n";
            heroInfoStr  += $"Resources points: {acc.Hero.HeroInfo.ResourcesPoints}\n";
            heroInfoStr  += $"Number of adventures: {acc.Hero.AdventureNum}";
            heroInfo.Text = heroInfoStr;

            //Adventures
            var advStr = new List <string>();

            foreach (var adv in acc.Hero.Adventures)
            {
                advStr.Add(adv.Coordinates.ToString() + " - " + adv.Difficulty.ToString() + " adventure");
            }
            adventures.Text = string.Join("\n", advStr);
        }
Ejemplo n.º 2
0
        public override async Task <TaskRes> Execute(Account acc)
        {
            var wb = acc.Wb.Driver;

            await VersionHelper.Navigate(acc, "/hero.php?t=3", "/hero/adventures");

            acc.Hero.Adventures = AdventureParser.GetAdventures(acc.Wb.Html, acc.AccInfo.ServerVersion);

            HeroHelper.UpdateHeroVillage(acc);

            if (acc.Hero.Adventures == null || acc.Hero.Adventures.Count == 0 || UpdateOnly)
            {
                return(TaskRes.Executed);
            }

            var adventures = acc.Hero.Adventures
                             .Where(x =>
                                    MapHelper.CalculateDistance(acc, x.Coordinates, HeroHelper.GetHeroHomeVillage(acc).Coordinates) <= acc.Hero.Settings.MaxDistance
                                    )
                             .ToList();

            if (adventures.Count == 0)
            {
                return(TaskRes.Executed);
            }

            var adventure = adventures.FirstOrDefault(x => x.Difficulty == Classificator.DifficultyEnum.Normal);

            if (adventure == null)
            {
                adventure = adventures.FirstOrDefault();
            }

            acc.Hero.NextHeroSend = DateTime.Now.AddSeconds(adventure.DurationSeconds * 2);

            switch (acc.AccInfo.ServerVersion)
            {
            case Classificator.ServerVersionEnum.T4_4:
                await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/{adventure.Ref}");

                var startButton = acc.Wb.Html.GetElementbyId("start");
                if (startButton == null)
                {
                    //Hero is probably out of the village.
                    this.NextExecute = DateTime.Now.AddMinutes(10);
                    return(TaskRes.Executed);
                }
                wb.ExecuteScript("document.getElementById('start').click()");
                break;

            case Classificator.ServerVersionEnum.T4_5:
                string script = $"var div = document.getElementById('{adventure.AdventureId}');";
                script += $"div.children[0].submit();";
                await DriverHelper.ExecuteScript(acc, script);

                // Check hero outgoing time
                var outTime = HeroParser.GetHeroArrival(acc.Wb.Html);
                // At least 1.5x longer (if hero has Large map)
                acc.Hero.NextHeroSend = DateTime.Now + TimeSpan.FromTicks((long)(outTime.Ticks * 1.5));
                break;
            }

            return(TaskRes.Executed);
        }