Esempio n. 1
0
    void ConstructPlayerCardDatabase(JsonData CardData, List <Card> Database)
    {
        for (int i = 0; i < CardData.Count; i++)
        {
            int      id       = (int)CardData[i]["id"];
            string   title    = CardData[i]["title"].ToString();
            Faction  faction  = (Faction)System.Enum.Parse(typeof(Faction), CardData[i]["faction"].ToString(), true);
            CardType cardType = (CardType)System.Enum.Parse(typeof(CardType), CardData[i]["type"].ToString(), true);
            string   slug     = CardData[i]["slug"].ToString();

            if (cardType == CardType.Special)
            {
                Ability   magicCardAbility = (Ability)System.Enum.Parse(typeof(Ability), CardData[i]["ability"].ToString(), true);
                AffectRow rowToAffect      = (AffectRow)System.Enum.Parse(typeof(AffectRow), CardData[i]["affects"].ToString(), true);
                string    description      = CardData[i]["desc"].ToString();
                MagicCardFactory = new MagicCardFactory();
                //Add magic card to database
                Database.Add(MagicCardFactory.CreateMagicCard(id, title, cardType, faction, slug, magicCardAbility, rowToAffect, description));
            }
            else
            {
                int     attackValue = (int)CardData[i]["attackValue"];
                Ability cardAbility = (Ability)System.Enum.Parse(typeof(Ability), CardData[i]["ability"].ToString(), true);
                UnitCardFactory = new UnitCardFactory();
                //Add monster card to database
                Database.Add(UnitCardFactory.CreateUnitCard(id, title, cardType, faction, slug, attackValue, cardAbility));
            }
        }
    }
Esempio n. 2
0
        /// <summary>
        /// Generate card data from files
        /// </summary>
        /// <param name="setList"></param>
        private void GenerateCards(ref Dictionary <int, string> setList)
        {
            ArchivistDatabase adb = new ArchivistDatabase();

            string currentCardName = string.Empty;
            string paraCardName = string.Empty, paraCost = string.Empty, paraPowTgh = string.Empty, paraRulesText = string.Empty, paraType = string.Empty;
            string paraCardExtCID = string.Empty, paraCardExtRar = string.Empty, paraMultiverseidString = string.Empty;
            int /*paraCardExtEID,*/ paraMultiverseid = 0;
            int id = 1;
            int extId = setList.Count + 1;

            foreach (KeyValuePair <int, string> ext in setList)
            {
                string extoutfile = String.Format("{0}\\{1}.dat", tempDirectory, System.Web.HttpUtility.UrlEncode(ext.Value));
                UpdateListText(String.Format("Analyzing extension file for {0}...", ext.Value));

                if (!System.IO.File.Exists(extoutfile))
                {
                    UpdateListText("File not found. Skipping.");
                    continue;
                }

                HtmlAgilityPack.HtmlWeb      web             = new HtmlAgilityPack.HtmlWeb();
                HtmlAgilityPack.HtmlDocument doc             = web.Load(extoutfile);
                HtmlAgilityPack.HtmlNode     textspoilerNode = doc.DocumentNode.SelectSingleNode("//div[@class=\"textspoiler\"]/table");

                foreach (HtmlAgilityPack.HtmlNode rows in textspoilerNode.SelectNodes("tr"))
                {
                    HtmlAgilityPack.HtmlNodeCollection cols = rows.SelectNodes("td");
                    if (cols.Count == 2)
                    {
                        string key   = cols[0].InnerText.Replace(":", "").Trim();
                        string value = cols[1].InnerText.TrimStart().TrimEnd();

                        if (key == "Name")
                        {
                            currentCardName = value;
                            paraCardName    = value;
                            string href = cols[1].SelectSingleNode("a").GetAttributeValue("href", "");                      //../Card/Details.aspx?multiverseid=201281
                            paraMultiverseidString = href.Substring(href.LastIndexOf("=") + 1);                             //201281
                            paraMultiverseid       = Convert.ToInt32(paraMultiverseidString);
                        }
                        if (key == "Cost")
                        {
                            paraCost = value;
                        }
                        if (key == "Type")
                        {
                            paraType = value.Replace("—", "-").Replace("  ", " ");
                        }
                        if (key == "Pow/Tgh")
                        {
                            paraPowTgh = value;
                        }
                        if (key == "Rules Text")
                        {
                            paraRulesText = value;
                        }
                        if (key == "Set/Rarity")
                        {
                            paraCardExtRar = value.Replace("\"", "&quot;");
                        }
                    }
                    else
                    {
                        if (currentCardName != "")
                        {
                            string[] setrlist = paraCardExtRar.Split(',');
                            string   cid      = string.Empty;
                            foreach (string setr in setrlist)
                            {
                                if (setr.Contains(ext.Value))
                                {
                                    string set    = ext.Value.Replace("&quot;", "\"").Trim();
                                    string rarity = setr.Replace(ext.Value, "").Trim(); // Might be Common/Uncomm/Rare/Mythic Rare

                                    Card card = MagicCardFactory.BuildCard(paraCardName, paraCost, paraPowTgh, paraRulesText, paraType, rarity, set, paraMultiverseid);
                                    cid = adb.InsertCard(card);
                                    break;
                                }
                            }

                            if (string.IsNullOrEmpty(cid))
                            {
                                UpdateListText("Error inserting card: " + currentCardName);
                            }
                        }

                        // New card
                        paraCardName           = null; paraCost = null; paraType = null;
                        paraPowTgh             = null; paraRulesText = null; paraCardExtRar = null;
                        paraMultiverseidString = null;
                        currentCardName        = "";
                    }
                }

                UpdateTotalStatus(setList.Count + id + 1, 2 * setList.Count + 2);
                id++;
            }
        }