Beispiel #1
0
        public static string HtmlizeDeck(ImportDeck deck)
        {
            dynamic Deck = new ExpandoObject();

            Deck.MainDeck  = new Dictionary <Card, int>();
            Deck.SideBoard = new Dictionary <Card, int>();

            foreach (var card in deck.MainDeck)
            {
                Deck.MainDeck.Add(Helpers.CardSearch.GetCardByMultiverseId(card.multiverseId.GetValueOrDefault()), card.count);
            }

            if (deck.SideBoard.Count > 0)
            {
                foreach (var card in deck.SideBoard)
                {
                    Deck.SideBoard.Add(Helpers.CardSearch.GetCardByMultiverseId(card.multiverseId.GetValueOrDefault()), card.count);
                }
            }

            return(HtmlizeWithDividers(Deck));
        }
Beispiel #2
0
        public override string ToString()
        {
            var z = this.MainDeck.GroupBy(x => x.name);

            var sortedDeck = new ImportDeck();

            sortedDeck.MainDeck  = new List <ImportCard>();
            sortedDeck.SideBoard = new List <ImportCard>();


            //Next block doesn't sort really, it just unites card with same name but different MultiverseId
            foreach (var card in this.MainDeck)
            {
                foreach (var compareCard in this.MainDeck)
                {
                    if (card != compareCard)
                    {
                        if (card.name.Equals(compareCard.name) && !card.set.Equals(compareCard.set))
                        {
                            card.count += compareCard.count;
                        }
                    }
                }

                if (!sortedDeck.MainDeck.Any(c => c.name.Equals(card.name)))
                {
                    sortedDeck.MainDeck.Add(card);
                }
            }

            foreach (var card in this.SideBoard)
            {
                foreach (var compareCard in this.SideBoard)
                {
                    if (card != compareCard)
                    {
                        if (card.name.Equals(compareCard.name) && !card.set.Equals(compareCard.set))
                        {
                            card.count += compareCard.count;
                        }
                    }
                }

                if (!sortedDeck.SideBoard.Any(c => c.name.Equals(card.name)))
                {
                    sortedDeck.SideBoard.Add(card);
                }
            }



            List <string> deckList = new List <string>();

            foreach (var importCard in sortedDeck.MainDeck)
            {
                var set = importCard.set?.Replace("(", "").Replace(")", "").Replace("DAR", "DOM");
                if (set == "NONE")
                {
                    deckList.Add(importCard.count + " " + importCard.name);
                }
                else if (!string.IsNullOrEmpty(set))
                {
                    var card = CardData.Instance.Sets.FirstOrDefault(s => s.code.Equals(set) && s.type != "promo" && s.type != "funny" && s.type != "box").cards.FirstOrDefault(c => c.number == importCard.collectorNumber.ToString());
                    if (card.name.Equals(importCard.name))
                    {
                        deckList.Add(importCard.count + " " + card.name);
                    }
                }
                else
                {
                    var card = Helpers.CardSearch.GetCardByName(importCard.name);
                    deckList.Add(importCard.count + " " + card.name);
                }
            }

            deckList.Add("\r\n");

            foreach (var importCard in this.SideBoard)
            {
                var set = importCard.set?.Replace("(", "").Replace(")", "").Replace("DAR", "DOM");
                if (!string.IsNullOrEmpty(set))
                {
                    var card = CardData.Instance.Sets.FirstOrDefault(s => s.code.Equals(set)).cards.FirstOrDefault(c => c.number == importCard.collectorNumber.ToString());
                    if (card.name.Equals(importCard.name))
                    {
                        deckList.Add(importCard.count + " " + card.name);
                    }
                }
                else
                {
                    var card = Helpers.CardSearch.GetCardByName(importCard.name);
                    deckList.Add(importCard.count + " " + card.name);
                }
            }
            var deckstr = string.Join("\r\n", deckList).Replace("\r\n\r\n\r\n", "\r\n\r\n");

            return(deckstr);
        }
Beispiel #3
0
        public static ImportDeck StringToDeck(string text, ApplicationUser owner)
        {
            var deck = new ImportDeck();

            deck.Owner     = owner;
            deck.MainDeck  = new List <ImportCard>();
            deck.SideBoard = new List <ImportCard>();
            bool side = false;

            if (text.Contains("(") && text.Contains(")")) //treat as magic arena import
            {
                text = text.Replace("\n", "\r\n");
                foreach (var myString in text.Split(new string[] { "\r\n" }, StringSplitOptions.None))
                {
                    ImportCard card = new ImportCard();

                    if (myString.Trim().Length > 1)
                    {
                        try
                        {
                            var   cardData = myString.Split(" ");
                            Regex exp      = new Regex(@"(\d+)x?\s+?(.*\s?)\s+(\(.+\))?\s+(\d+)?");
                            var   matches  = exp.Matches(myString);

                            int.TryParse(matches[0].Groups[1].Value, out card.count);
                            card.name = matches[0].Groups[2].Value;
                            card.set  = matches[0].Groups[3].Value.Replace("(DAR)", "(DOM)");
                            int.TryParse(matches[0].Groups[4].Value, out card.collectorNumber);

                            var tempCard = Helpers.CardSearch.GetCardByName(card.name, card.set);
                            if (tempCard != null)
                            {
                                card.multiverseId = tempCard.multiverseId;
                                card.scryfallId   = tempCard.scryfallId;
                            }

                            if (side)
                            {
                                deck.SideBoard.Add(card);
                            }
                            else
                            {
                                deck.MainDeck.Add(card);
                            }
                        }
                        catch
                        {
                            Console.WriteLine("|||||||||||||||Yep, error is somewhere here");
                        }
                    }

                    else
                    {
                        side = true;
                    }
                }
            }
            else
            {
                bool sideBoard = false;
                var  deckArray = text.Replace("sideboard", "\r\n\r\n", StringComparison.CurrentCultureIgnoreCase)
                                 .Split(new string[] { "\r\n\r\n" },
                                        StringSplitOptions.RemoveEmptyEntries);
                if (deckArray.Length > 1)
                {
                    sideBoard = true;
                }

                Regex rx      = new Regex(@"(\d+)x?\s+([^\(^\d]*)\s*", RegexOptions.Multiline);
                var   matches = rx.Matches(deckArray[0]);
                foreach (Match match in matches)
                {
                    ImportCard importCard = new ImportCard();
                    importCard.name  = match.Groups[2].Value.Trim();
                    importCard.count = int.Parse(match.Groups[1].Value.Trim());

                    var tempCard = Helpers.CardSearch.GetCardByName(importCard.name);
                    if (tempCard == null)
                    {
                        importCard.multiverseId    = 0;
                        importCard.collectorNumber = 0;
                        importCard.set             = "NONE";
                    }
                    else
                    {
                        var set = CardData.Instance.Sets.FirstOrDefault(s => tempCard.printings.Contains(s.code) && s.type != "promo" && s.type != "funny" && s.type != "box");
                        importCard.set             = set.code;
                        importCard.collectorNumber = int.Parse(tempCard.number);
                        importCard.multiverseId    = tempCard.multiverseId;
                    }

                    deck.MainDeck.Add(importCard);
                }

                if (sideBoard)
                {
                    var matchesSB = rx.Matches(deckArray[1]);
                    foreach (Match match in matchesSB)
                    {
                        ImportCard importCard = new ImportCard();
                        importCard.name  = match.Groups[2].Value.Trim();
                        importCard.count = int.Parse(match.Groups[1].Value.Trim());

                        var tempCard = Helpers.CardSearch.GetCardByName(importCard.name);
                        if (tempCard == null)
                        {
                            importCard.multiverseId    = 0;
                            importCard.collectorNumber = 0;
                            importCard.set             = "NONE";
                        }
                        else
                        {
                            var set = CardData.Instance.Sets.FirstOrDefault(s => tempCard.printings.Contains(s.code) && s.type != "promo" && s.type != "funny" && s.type != "box");
                            importCard.set = set.code;
                            try
                            {
                                importCard.collectorNumber = int.Parse(tempCard.number);
                            }
                            catch
                            {
                                importCard.collectorNumber = 0;
                            }
                            importCard.multiverseId = tempCard.multiverseId;
                        }

                        deck.SideBoard.Add(importCard);
                    }
                }
            }

            return(deck);
        }