Пример #1
0
        public async Task GetArmors(string address)
        {
            var config  = Configuration.Default.WithDefaultLoader();
            var context = BrowsingContext.New(config);
            var page    = await context.OpenAsync(address);

            var rows     = page.QuerySelector(".table").QuerySelectorAll("tr.table-active");
            int throttle = 3;
            await db.CreateTablesAsync <Armor, ArmorSkill, ArmorCraftItem, ArmorScrapReward, ArmorUpgradeItem>();

            List <Task> tasks = new List <Task>();

            foreach (var row in rows)
            {
                string addr = ((IHtmlAnchorElement)row.NextElementSibling.FirstElementChild.FirstElementChild).Href;
                tasks.Add(GetArmor(addr));

                if (tasks.Count == throttle)
                {
                    Task completed = await Task.WhenAny(tasks);

                    tasks.Remove(completed);
                }
            }
            await Task.WhenAll(tasks);

            ConsoleWriters.CompletionMessage($"\nFinished with page! ({address}).\n");
        }
Пример #2
0
        public async Task <PalicoArmor> GetPalicoArmor(string address)
        {
            var page = await context.OpenAsync(address);

            var    basicinfo   = page.QuerySelector("[itemprop=\"gameItem\"]");
            string name        = basicinfo.FirstElementChild.TextContent;
            string description = basicinfo.Children[1].TextContent;

            ConsoleWriters.StartingPageMessage($"Started on the {name} palico armor.");
            var leads  = page.QuerySelectorAll(".lead");
            int rarity = leads[0].TextContent.ToInt();
            int price  = leads[1].TextContent.ToInt();

            int[]       defense_info = page.QuerySelector(".table").Children[1].QuerySelectorAll("td").Select(d => d.TextContent.ToInt()).ToArray();
            PalicoArmor armor        = new PalicoArmor()
            {
                pa_name        = name,
                pa_description = description,
                pa_rarity      = rarity,
                pa_price       = price,
                pa_defense     = defense_info[0],
                pa_fire        = defense_info[1],
                pa_water       = defense_info[2],
                pa_thunder     = defense_info[3],
                pa_ice         = defense_info[4],
                pa_dragon      = defense_info[5],
                craft_items    = new List <PalicoCraftItem>()
            };
            var craft_table = page.QuerySelector(".table-sm").FirstElementChild.QuerySelectorAll("td");

            armor.craft_items = GetPalicoCrafts(craft_table, armor.pa_name, "armor");
            ConsoleWriters.CompletionMessage($"Finished adding the {name} palico armor!");
            return(armor);
        }
Пример #3
0
        public async Task GetArmor(string address)
        {
            IConfiguration   config  = Configuration.Default.WithDefaultLoader(l => l.IsResourceLoadingEnabled = true).WithCss();
            IBrowsingContext context = BrowsingContext.New(config);
            var page = await context.OpenAsync(address);

            SetInfo setinfo = GetSetInfo(page);

            ConsoleWriters.StartingPageMessage($"Starting the {setinfo.armor_set} set.");
            var tables        = page.QuerySelectorAll(".table");
            var defense_trs   = tables[0].QuerySelectorAll("tbody tr").SkipLast(1);
            var skill_table   = tables[1].Children[1].Children.ToArray();
            var create_table  = tables[2].Children[1].Children.ToArray();
            var upgrade_table = tables[4].Children[1].Children.ToArray();

            // Skip the last tr, because that is the total
            foreach (var tr in defense_trs)
            {
                DefenseInfo    definfo  = GetArmorPieceDefenseInfo(tr);
                int            tr_index = tr.ParentElement.Children.Index(tr);
                ArmorSkillInfo asi      = GetArmorSkills(skill_table[tr_index]);
                Armor          piece    = new Armor()
                {
                    armor_name        = definfo.armor_name,
                    armor_set         = setinfo.armor_set,
                    armor_description = setinfo.piece_descriptions[tr_index],
                    rarity            = setinfo.rarity,
                    max_upgrade       = setinfo.max_upgrade,
                    monster_id        = setinfo.monster_id,
                    is_blademaster    = setinfo.is_blademaster,
                    is_gunner         = setinfo.is_gunner,
                    is_male           = setinfo.is_male,
                    is_female         = setinfo.is_female,
                    min_armor_defense = definfo.min_defense,
                    max_armor_defense = definfo.max_defense,
                    fire_def          = definfo.fire_defense,
                    water_def         = definfo.water_defense,
                    thunder_def       = definfo.thunder_defense,
                    ice_def           = definfo.ice_defense,
                    dragon_def        = definfo.dragon_def,
                    slots             = asi.slots,
                };
                await db.InsertAsync(piece);

                foreach (ArmorSkill skill in asi.skills)
                {
                    skill.armor_id = piece.armor_id;
                }
                await Task.WhenAll(
                    db.InsertAllAsync(asi.skills),
                    db.InsertAllAsync(GetArmorScraps(create_table[tr_index], "create", piece.armor_id)),
                    db.InsertAllAsync(GetArmorScraps(upgrade_table[tr_index], "upgrade", piece.armor_id)),
                    db.InsertAllAsync(GetArmorCrafts(create_table[tr_index], piece.armor_id)),
                    db.InsertAllAsync(GetArmorUpgradeItems(upgrade_table[tr_index], piece.armor_id))
                    );
            }
            ConsoleWriters.CompletionMessage($"Finished with the {setinfo.armor_set} set!");
        }
Пример #4
0
        public PalicoSkill GetPalicoSkill(IElement tr)
        {
            string name = tr.Children[0].TextContent;

            ConsoleWriters.StartingPageMessage($"Retrieving the palico skill {name}.");
            string type = "";

            switch (tr.Children[1].FirstElementChild.ClassList[2])
            {
            case "text-danger":
                type = "offensive";
                break;

            case "text-info":
                type = "defensive";
                break;

            case "text-warning":
                type = "passive";
                break;
            }
            int memory = 0;

            foreach (var span in tr.Children[1].Children)
            {
                memory += 1;
            }
            int    level       = tr.Children[2].TextContent.ToInt();
            string description = tr.Children[3].TextContent;

            ConsoleWriters.CompletionMessage($"Finished with the palico skill {name}!");
            return(new PalicoSkill()
            {
                ps_description = description,
                ps_learn_level = level,
                ps_memory_req = memory,
                ps_name = name,
                ps_type = type
            });
        }
Пример #5
0
        public async Task <PalicoWeapon> GetPalicoWeapon(string address, string weapon_type, string weapon_damage_type)
        {
            var page = await context.OpenAsync(address);

            var    basicinfo   = page.QuerySelector("[itemprop=\"gameItem\"]");
            string name        = basicinfo.FirstElementChild.TextContent;
            string description = basicinfo.Children[1].TextContent;

            ConsoleWriters.StartingPageMessage($"Started on the {name} palico weapon.");
            var leads  = page.QuerySelectorAll(".lead");
            int rarity = leads[0].TextContent.ToInt();
            int price  = leads[1].TextContent.ToInt();

            var damage_tr = page.QuerySelector(".table").QuerySelectorAll("tr")[1];

            var    melee_data        = damage_tr.FirstElementChild.QuerySelectorAll("div");
            int    melee_dmg         = melee_data[0].TextContent.ToInt();
            int    melee_affinity    = melee_data[1].TextContent.ToInt();
            string sharpness         = damage_tr.QuerySelector("span").ClassName;
            string melee_element     = "none";
            int    melee_elem_amount = 0;

            if (damage_tr.Children[2].TextContent.Replace(" ", "") != "")
            {
                melee_element     = damage_tr.Children[2].TextContent.Trim().Split(' ')[1];
                melee_elem_amount = damage_tr.Children[2].TextContent.ToInt();
            }

            var    boom_data        = damage_tr.Children[3].QuerySelectorAll("div");
            int    boom_dmg         = boom_data[0].TextContent.ToInt();
            int    boom_affinity    = boom_data[1].TextContent.ToInt();
            string boom_element     = "none";
            int    boom_elem_amount = 0;

            if (damage_tr.Children[4].TextContent.Replace(" ", "") != "")
            {
                boom_element     = damage_tr.Children[4].TextContent.Trim().Split(' ')[1];
                boom_elem_amount = damage_tr.Children[4].TextContent.ToInt();
            }
            int defense = damage_tr.LastElementChild.TextContent.ToInt();

            PalicoWeapon weapon = new PalicoWeapon()
            {
                pw_name                  = name,
                pw_description           = description,
                pw_affinity              = melee_affinity,
                pw_boomerang_affinity    = boom_affinity,
                pw_boomerang_damage      = boom_dmg,
                pw_boomerang_element     = boom_element,
                pw_boomerang_element_amt = boom_elem_amount,
                pw_damage                = melee_dmg,
                pw_damage_type           = weapon_damage_type,
                pw_defense               = defense,
                pw_element               = melee_element,
                pw_element_amt           = melee_elem_amount,
                pw_price                 = price,
                pw_rarity                = rarity,
                pw_sharpness             = sharpness,
                pw_type                  = weapon_type
            };

            var craft_table = page.QuerySelector(".table-sm").FirstElementChild.QuerySelectorAll("td");

            weapon.craft_items = GetPalicoCrafts(craft_table, name, "weapon");
            ConsoleWriters.CompletionMessage($"Finished adding the {name} palico weapon!");
            return(weapon);
        }