Esempio n. 1
0
        private void CheckInfos(IDictionary <string, string> infos)
        {
            if (!infos.ContainsKey(NameKey))
            {
                throw new ParserException("No name found");
            }

            if (!infos.ContainsKey(TypeKey))
            {
                throw new ParserException("No type found");
            }

            if (!infos.ContainsKey(RarityKey))
            {
                throw new ParserException("No rarity found");
            }

            string type        = infos.GetOrDefault(TypeKey);
            string castingcost = infos.GetOrDefault(ManaCostKey);

            //Add check on casting cost because of second face of Garruk, the Veil-Cursed which has no loyalty counter
            if ((MagicRules.IsCreature(type) || MagicRules.IsPlaneswalker(type) || MagicRules.IsVehicle(type)) && !infos.ContainsKey(PTKey) && !string.IsNullOrWhiteSpace(castingcost))
            {
                throw new ParserException("No PT/Loyalty found");
            }
        }
Esempio n. 2
0
 public bool IsSpecial(ICardAllDbInfo cai)
 {
     if (MagicRules.IsSpecial(cai.Card.Type))
     {
         return(true);
     }
     return(IsSplitted(cai.Card) && MagicRules.IsSpecial(cai.CardPart2.Type));
 }
Esempio n. 3
0
        public CardType GetCardType(ICardAllDbInfo cai)
        {
            CardType type = MagicRules.GetCardType(cai.Card.Type, cai.Card.CastingCost);

            if (IsSplitted(cai.Card))
            {
                type |= MagicRules.GetCardType(cai.CardPart2.Type, cai.CardPart2.CastingCost);
            }
            return(type);
        }
Esempio n. 4
0
        public CardSubType GetCardSubType(ICardAllDbInfo cai)
        {
            CardSubType subType = MagicRules.GetCardSubType(cai.Card.Type);

            if (IsSplitted(cai.Card))
            {
                subType |= MagicRules.GetCardSubType(cai.CardPart2.Type);
            }

            return(subType);
        }
Esempio n. 5
0
        public ShardColor GetColor(ICardAllDbInfo cai)
        {
            ShardColor color = MagicRules.GetColor(cai.Card.CastingCost);

            if (IsSplitted(cai.Card))
            {
                color |= MagicRules.GetColor(cai.CardPart2.CastingCost);
            }

            return(color);
        }
Esempio n. 6
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);
        }