Ejemplo n.º 1
0
        private CardWithExtraInfo GenerateCard(string text)
        {
            IDictionary <string, string> infos = new Dictionary <string, string>();

            //Parsing
            using (XmlTextReader xmlReader = new XmlTextReader(new StringReader(SpecialXMLCorrection(text))))
            {
                while (xmlReader.Read())
                {
                    if (xmlReader.NodeType != XmlNodeType.Element)
                    {
                        continue;
                    }

                    IAwareXmlTextReader   reader = new AwareXmlTextReader(xmlReader);
                    ICardInfoParserWorker worker = CardInfoParserWorkerFactory.Instance.CreateParserWorker(reader);

                    if (worker == null)
                    {
                        continue;
                    }

                    infos.AddRange(ParseElement(reader, worker));
                }
            }
            //Check parsing result
            CheckInfos(infos);

            //Generate result class
            CardWithExtraInfo cardWithExtraInfo = new CardWithExtraInfo
            {
                Name        = RemoveParentheses(infos.GetOrDefault(NameKey)),
                CastingCost = infos.GetOrDefault(ManaCostKey),
                Text        = infos.GetOrDefault(TextKey),
                Type        = infos.GetOrDefault(TypeKey),
                PictureUrl  = infos.GetOrDefault(ImageKey),
                Rarity      = infos.GetOrDefault(RarityKey)
            };

            if (MagicRules.IsCreature(cardWithExtraInfo.Type) || MagicRules.IsVehicle(cardWithExtraInfo.Type))
            {
                string htmlTrim = infos.GetOrDefault(PTKey).HtmlTrim();
                cardWithExtraInfo.Power     = GetPower(htmlTrim);
                cardWithExtraInfo.Toughness = GetToughness(htmlTrim);
            }
            if (MagicRules.IsPlaneswalker(cardWithExtraInfo.Type))
            {
                string htmlTrim = infos.GetOrDefault(PTKey).HtmlTrim();
                //Possible see CheckInfos for more info
                if (!string.IsNullOrWhiteSpace(htmlTrim))
                {
                    htmlTrim = htmlTrim.ToUpper();
                    //Special case for:
                    //  Nissa, Steward of Elements with loyalty to X
                    //  B.O.B. (Bevy of Beebles) with loyalty to *
                    if (htmlTrim == "X" || htmlTrim == "*")
                    {
                        cardWithExtraInfo.Loyalty = htmlTrim;
                    }
                    else
                    {
                        cardWithExtraInfo.Loyalty = int.Parse(htmlTrim).ToString();
                    }
                }
            }
            string variations = infos.GetOrDefault(VariationsKey);

            if (!string.IsNullOrWhiteSpace(variations))
            {
                foreach (string variation in variations.Split(new[] { VariationsWorker.Separator }, System.StringSplitOptions.RemoveEmptyEntries))
                {
                    if (int.TryParse(variation, out int gatherid))
                    {
                        cardWithExtraInfo.Add(gatherid);
                    }
                }
            }
            cardWithExtraInfo.Type = infos.GetOrDefault(TypeKey);
            return(cardWithExtraInfo);
        }
Ejemplo n.º 2
0
 public RowWorker(IAwareXmlTextReader xmlReader)
 {
     _innerWorker = CardInfoParserWorkerFactory.Instance.CreateParserRowSubWorker(xmlReader);
 }
Ejemplo n.º 3
0
        private IDictionary <string, string> ParseElement(IAwareXmlTextReader xmlReader, ICardInfoParserWorker worker)
        {
            IDictionary <string, string> parsedInfo = new Dictionary <string, string>();
            bool readOk = worker.WorkOnCurrentAtStart || xmlReader.Read();

            while (readOk)
            {
                if (xmlReader.NodeType == XmlNodeType.Element)
                {
                    IDictionary <string, string> workOnElement = worker.WorkOnElement(new AwareXmlTextReader(xmlReader));
                    parsedInfo.AddRange(workOnElement);
                }
                readOk = xmlReader.Read();
            }

            return(parsedInfo);
        }