Ejemplo n.º 1
0
        public async Task GetBow(string address)
        {
            var config  = Configuration.Default.WithDefaultLoader(l => l.IsResourceLoadingEnabled = true).WithCss();
            var context = BrowsingContext.New(config);
            var page    = await context.OpenAsync(address);

            string[] flav         = Weapons.GetFlavorText(page);
            string   bow_set_name = page.QuerySelector("title").TextContent.Split('/')[0].Trim();

            var crafting_table    = page.QuerySelectorAll(".table")[1].QuerySelector("tbody");
            int current_wpn_index = 0;

            foreach (var tr in page.QuerySelector(".table").QuerySelectorAll("tr"))
            {
                string weapon_name   = tr.FirstElementChild.TextContent;
                int    weapon_damage = Convert.ToInt32(tr.Children[1].TextContent);

                List <ElementDamage> elements = new List <ElementDamage>();
                int affinity = 0;
                foreach (var small in tr.Children[2].QuerySelectorAll("small"))
                {
                    if (small.TextContent.Any(char.IsLetter))
                    {
                        elements.Add(Weapons.GetElement(small));
                    }
                    else
                    {
                        affinity = Convert.ToInt32(intsOnly.Replace(small.TextContent.Trim(), ""));
                    }
                }

                string[] bow_shots          = GetBowShots(tr);
                string   supported_coatings = GetBowCoatings(tr);
                int      slots = tr.Children[5].FirstElementChild.TextContent.Count(c => c == '◯');

                int monsterid = -1;
                if (page.QuerySelectorAll(".lead").Count() == 3)
                {
                    monsterid = (await Monsters.GetMonsterFromDB(page.QuerySelectorAll(".lead")[2].TextContent.Trim())).id;
                }

                Bow bow = new Bow()
                {
                    monster_id         = monsterid,
                    bow_set_name       = bow_set_name,
                    bow_name           = weapon_name,
                    bow_damage         = weapon_damage,
                    affinity           = affinity,
                    arc_type           = bow_shots[0].Split(":")[1].Trim(),
                    level_one_charge   = bow_shots[1],
                    level_two_charge   = bow_shots[2],
                    level_three_charge = bow_shots[3],
                    level_four_charge  = bow_shots[4],
                    supported_coatings = supported_coatings,
                    slots       = slots,
                    rarity      = Convert.ToInt32(flav[4]),
                    description = weapon_name.Contains(flav[0]) ? flav[2] : flav[3]
                };
                await db.InsertAsync(bow);

                List <CraftItem> craftitems = Weapons.GetCraftItems(crafting_table.Children[current_wpn_index]);
                foreach (CraftItem item in craftitems)
                {
                    item.creation_id   = bow.bow_id;
                    item.creation_type = "Bow";
                }
                foreach (ElementDamage element in elements)
                {
                    element.weapon_id = bow.bow_id;
                }
                await db.InsertAllAsync(craftitems);

                current_wpn_index++;
            }
        }
Ejemplo n.º 2
0
        public async Task GetBowgun(string address)
        {
            var config  = Configuration.Default.WithDefaultLoader(l => l.IsResourceLoadingEnabled = true).WithCss();
            var context = BrowsingContext.New(config);
            var page    = await context.OpenAsync(address);

            string[] flav        = Weapons.GetFlavorText(page);
            string   title       = page.QuerySelector("title").TextContent;
            string   bg_set_name = title.Split('/')[0].Trim();
            string   bg_type     = "Heavy Bowgun";

            if (address.Contains("lightbowgun"))
            {
                bg_type = "Light Bowgun";
            }

            var crafting_table    = page.QuerySelectorAll(".table")[1].QuerySelector("tbody");
            int current_wpn_index = 0;

            foreach (var tr in page.QuerySelector(".table").QuerySelectorAll("tr"))
            {
                string weapon_name   = tr.FirstElementChild.TextContent;
                int    weapon_damage = Convert.ToInt32(tr.Children[1].TextContent);

                List <ElementDamage> elements = new List <ElementDamage>();
                int affinity = 0;
                foreach (var small in tr.Children[2].QuerySelectorAll("small").Skip(1))
                {
                    if (small.TextContent.Any(char.IsLetter))
                    {
                        elements.Add(Weapons.GetElement(small));
                    }
                    else
                    {
                        affinity = Convert.ToInt32(intsOnly.Replace(small.TextContent.Trim(), ""));
                    }
                }

                string[] gun_characteristics = GetBowgunInformation(tr);
                int      slots = tr.Children[5].FirstElementChild.TextContent.Count(c => c == '◯');

                int monsterid = -1;
                if (page.QuerySelectorAll(".lead").Count() == 3)
                {
                    monsterid = (await Monsters.GetMonsterFromDB(page.QuerySelectorAll(".lead")[2].TextContent.Trim())).id;
                }

                Bowgun bowgun = new Bowgun()
                {
                    monster_id   = monsterid,
                    bg_set_name  = bg_set_name,
                    bg_type      = bg_type,
                    bg_name      = weapon_name,
                    bg_damage    = weapon_damage,
                    affinity     = affinity,
                    slots        = slots,
                    rarity       = Convert.ToInt32(flav[4]),
                    reload_speed = gun_characteristics[0],
                    recoil       = gun_characteristics[1],
                    deviation    = gun_characteristics[2],
                    description  = weapon_name.Contains(flav[0]) ? flav[2] : flav[3]
                };
                await db.InsertAsync(bowgun);

                BowgunAmmo ba = GetBowgunAmmo(tr);
                ba.bowgun_id = bowgun.bg_id;
                await db.InsertAsync(ba);

                List <InternalBowgunAmmo> iba = GetInternalAmmo(tr);
                foreach (InternalBowgunAmmo ammo in iba)
                {
                    ammo.bowgun_id = bowgun.bg_id;
                }
                await db.InsertAllAsync(iba);

                List <SpecialBowgunAmmo> sba = GetSpecialAmmo(tr);
                foreach (SpecialBowgunAmmo ammo in sba)
                {
                    ammo.bowgun_id = bowgun.bg_id;
                }
                await db.InsertAllAsync(sba);

                List <CraftItem> craftitems = Weapons.GetCraftItems(crafting_table.Children[current_wpn_index]);
                foreach (CraftItem item in craftitems)
                {
                    item.creation_id   = bowgun.bg_id;
                    item.creation_type = "Bowgun";
                }
                foreach (ElementDamage element in elements)
                {
                    element.weapon_id = bowgun.bg_id;
                }
                await db.InsertAllAsync(craftitems);

                current_wpn_index++;
            }
        }