Esempio n. 1
0
        public Ingredient[] BuildIngredients(string url)
        {
            var web = new HtmlWeb();
            var doc = web.Load(url);

            var rows = doc.DocumentNode.SelectSingleNode("//table[@class='wikitable']").SelectNodes("tr");

            var ings = new List <Ingredient>();

            var        newIng = true;
            Ingredient ing    = null;

            foreach (var row in rows.Skip(1))
            {
                var colIndex = 0;
                int defaultDlcCode;
                switch (url)
                {
                default:
                case UrlIngredientsMain: defaultDlcCode = 0; break;

                case UrlIngredientsDragonborn: defaultDlcCode = 3; break;
                }
                if (newIng)
                {
                    ing = new Ingredient {
                        DLC = defaultDlcCode
                    }
                }
                ;
                foreach (HtmlNode cell in row.SelectNodes("th|td"))
                {
                    var text = cell.InnerText;
                    if (newIng)
                    {
                        switch (colIndex)
                        {
                        case 0:
                            break;

                        case 1:
                            var parts = text.Split('\n');
                            ing.Name = parts[0];
                            if (ing.Name.Contains("DG"))
                            {
                                ing.Name = ing.Name.Replace("DG", "");
                                ing.DLC  = 1;
                            }
                            else if (ing.Name.Contains("HF"))
                            {
                                ing.Name = ing.Name.Replace("HF", "");
                                ing.DLC  = 2;
                            }
                            ing.ID = parts[1].ToUpper();
                            break;

                        case 2: ing.Description = text; break;
                        }
                    }
                    else
                    {
                        switch (colIndex)
                        {
                        case 0:
                        case 1:
                        case 2:
                        case 3:
                            if (text.Contains(";"))
                            {
                                text = text.Split(';')[1];
                            }
                            var prop = new Property
                            {
                                IngID = ing.ID,
                                EfID  = Effects.Values.First(ef => text.Split(new[] { " (" }, StringSplitOptions.None)[0].Equals(ef.Name)).ID
                            };
                            Properties.Add(prop);
                            break;

                        case 4: ing.Value = Int32.Parse(text); break;

                        case 5: ing.Weight = Single.Parse(text); break;

                        case 6:     // Merchant Avail.
                        case 7:     // Garden
                        default:
                            break;
                        }
                    }
                    colIndex++;
                }
                newIng = !newIng;
                if (!ings.Any(ingr => ingr.ID.Equals(ing.ID)))
                {
                    ings.Add(ing);
                }
            }
            return(ings.ToArray());
        }
Esempio n. 2
0
        public Ingredient[] BuildIngredients(string url)
        {
            var web = new HtmlWeb();
            var doc = web.Load(url);

            var rows = doc.DocumentNode.SelectSingleNode("//table[@class='wikitable']").SelectNodes("tr");

            var ings = new List<Ingredient>();

            var newIng = true;
            Ingredient ing = null;
            foreach (var row in rows.Skip(1))
            {
                var colIndex = 0;
                int defaultDlcCode;
                switch (url)
                {
                    default:
                    case UrlIngredientsMain: defaultDlcCode = 0; break;
                    case UrlIngredientsDragonborn: defaultDlcCode = 3; break;
                }
                if (newIng) ing = new Ingredient { DLC = defaultDlcCode };
                foreach (HtmlNode cell in row.SelectNodes("th|td"))
                {
                    var text = cell.InnerText;
                    if (newIng)
                    {
                        switch (colIndex)
                        {
                            case 0:
                                break;
                            case 1:
                                var parts = text.Split('\n');
                                ing.Name = parts[0];
                                if (ing.Name.Contains("DG"))
                                {
                                    ing.Name = ing.Name.Replace("DG", "");
                                    ing.DLC = 1;
                                }
                                else if (ing.Name.Contains("HF"))
                                {
                                    ing.Name = ing.Name.Replace("HF", "");
                                    ing.DLC = 2;
                                }
                                ing.ID = parts[1].ToUpper();
                                break;
                            case 2: ing.Description = text; break;
                        }
                    }
                    else
                    {
                        switch (colIndex)
                        {
                            case 0:
                            case 1:
                            case 2:
                            case 3:
                                if (text.Contains(";")) text = text.Split(';')[1];
                                var prop = new Property
                                {
                                    IngID = ing.ID,
                                    EfID = Effects.Values.First(ef => text.Split(new[] { " (" }, StringSplitOptions.None)[0].Equals(ef.Name)).ID
                                };
                                Properties.Add(prop);
                                break;
                            case 4: ing.Value = Int32.Parse(text); break;
                            case 5: ing.Weight = Single.Parse(text); break;
                            case 6: // Merchant Avail.
                            case 7: // Garden
                            default:
                                break;
                        }
                    }
                    colIndex++;
                }
                newIng = !newIng;
                if (!ings.Any(ingr => ingr.ID.Equals(ing.ID))) ings.Add(ing);
            }
            return ings.ToArray();
        }