private static async Task<Deck> ImportEliteDecks(string url)
		{
			try
			{
				var doc = await GetHtmlDoc(url);
				var deck = new Deck();

				var deckName = HttpUtility.HtmlDecode(doc.DocumentNode.SelectSingleNode("//h2[contains(@class, 'dname')]").InnerText);
				deck.Name = deckName;

				var cardNodes = doc.DocumentNode.SelectNodes("//ul[@class='vminionslist' or @class='vspellslist']/li");

				foreach(var cardNode in cardNodes)
				{
					var count = int.Parse(cardNode.SelectSingleNode(".//span[@class='cantidad']").InnerText);
					var name =
						HttpUtility.HtmlDecode(
						                       cardNode.SelectSingleNode(
						                                                 ".//span[@class='nombreCarta rarity_legendary' or @class='nombreCarta rarity_epic' or @class='nombreCarta rarity_rare' or @class='nombreCarta rarity_common' or @class='nombreCarta rarity_basic']")
						                               .InnerText);
					var card = GameV2.GetCardFromName(name);
					card.Count = count;
					deck.Cards.Add(card);
					if(string.IsNullOrEmpty(deck.Class) && card.PlayerClass != "Neutral")
						deck.Class = card.PlayerClass;
				}

				return deck;
			}
			catch(Exception e)
			{
				Logger.WriteLine(e.ToString(), "DeckImporter");
				return null;
			}
		}
		private static async Task<Deck> ImportHsTopdeck_s(string url)
		{
			try
			{
				var doc = await GetHtmlDoc(url);

				var deck = new Deck();

				var deckName =
					HttpUtility.HtmlDecode(doc.DocumentNode.SelectSingleNode("//header[@class='entry-header']/h1[@class='entry-title']").InnerText);
				deck.Name = deckName;


				var cardNodes = doc.DocumentNode.SelectNodes("//ul[contains(@class,'deck-class')]/li");

				foreach(var cardNode in cardNodes)
				{
					var name = HttpUtility.HtmlDecode(cardNode.SelectSingleNode(".//a/span[@class='card-name']").InnerText);
					var count = int.Parse(HttpUtility.HtmlDecode(cardNode.SelectSingleNode(".//a/span[@class='card-count']").InnerText));

					var card = GameV2.GetCardFromName(name);
					card.Count = count;
					deck.Cards.Add(card);
					if(string.IsNullOrEmpty(deck.Class) && card.PlayerClass != "Neutral")
						deck.Class = card.PlayerClass;
				}

				return deck;
			}
			catch(Exception e)
			{
				Logger.WriteLine(e.ToString(), "DeckImporter");
				return null;
			}
		}
		private static async Task<Deck> ImportIcyVeins(string url)
		{
			try
			{
				string json;
				using(var wc = new WebClient())
					json = await wc.DownloadStringTaskAsync(url + ".json");
				var wrapper = JsonConvert.DeserializeObject<IcyVeinsWrapper>(json);
				var deck = new Deck {Name = wrapper.deck_name};
				foreach(var cardObj in wrapper.deck_cards)
				{
					var cardName = cardObj.name;
					if(cardName.EndsWith(" Naxx"))
						cardName = cardName.Replace(" Naxx", "");
					if(cardName.EndsWith(" GvG"))
						cardName = cardName.Replace(" GvG", "");
					if(cardName.EndsWith(" BrM"))
						cardName = cardName.Replace(" BrM", "");
					var card = GameV2.GetCardFromName(cardName);
					card.Count = cardObj.quantity;
					deck.Cards.Add(card);
					if(string.IsNullOrEmpty(deck.Class) && card.PlayerClass != "Neutral")
						deck.Class = card.PlayerClass;
				}
				return deck;
			}
			catch(Exception e)
			{
				Logger.WriteLine(e.ToString(), "DeckImporter");
				return null;
			}
		}
		private static async Task<Deck> ImportHearthStats(string url)
		{
			try
			{
				var doc = await GetHtmlDoc(url);
				var deck = new Deck();

				var deckName = HttpUtility.HtmlDecode(doc.DocumentNode.SelectSingleNode("//h1[contains(@class,'page-title')]").FirstChild.InnerText);
				deck.Name = deckName;

				var cardNameNodes = doc.DocumentNode.SelectNodes("//div[contains(@class,'name')]");
				var cardCountNodes = doc.DocumentNode.SelectNodes("//div[contains(@class,'qty')]");

				var cardNames = cardNameNodes.Select(cardNameNode => HttpUtility.HtmlDecode(cardNameNode.InnerText));
				var cardCosts = cardCountNodes.Select(countNode => int.Parse(countNode.InnerText));

				var cardInfo = cardNames.Zip(cardCosts, (n, c) => new {Name = n, Count = c});
				foreach(var info in cardInfo)
				{
					var card = GameV2.GetCardFromName(info.Name);
					card.Count = info.Count;
					deck.Cards.Add(card);
					if(string.IsNullOrEmpty(deck.Class) && card.PlayerClass != "Neutral")
						deck.Class = card.PlayerClass;
				}

				return deck;
			}
			catch(Exception e)
			{
				Logger.WriteLine(e.ToString(), "DeckImporter");
				return null;
			}
		}
		private static async Task<Deck> ImportHearthstoneheroes(string url)
		{
			try
			{
				var doc = await GetHtmlDoc(url);
				var deck = new Deck
				{
					Name =
						HttpUtility.HtmlDecode(doc.DocumentNode.SelectSingleNode("//header[@class='panel-heading']/h1[@class='panel-title']").InnerText)
						           .Trim()
				};
				var nodes = doc.DocumentNode.SelectNodes("//table[@class='table table-bordered table-hover table-db']/tbody/tr");

				foreach(var cardNode in nodes)
				{
					var name = HttpUtility.HtmlDecode(cardNode.SelectSingleNode(".//a").Attributes[3].Value);

					var temp = HttpUtility.HtmlDecode(cardNode.SelectSingleNode(".//a/small").InnerText[0].ToString());
					var count = int.Parse(temp);

					var card = GameV2.GetCardFromName(name);
					card.Count = count;
					deck.Cards.Add(card);
					if(string.IsNullOrEmpty(deck.Class) && card.PlayerClass != "Neutral")
						deck.Class = card.PlayerClass;
				}

				return deck;
			}
			catch(Exception e)
			{
				Logger.WriteLine(e.ToString(), "DeckImporter");
				return null;
			}
		}
		private static async Task<Deck> ImportHearthArena(string url)
		{
			try
			{
				var doc = await GetHtmlDoc(url);
				var deck = new Deck {Name = Helper.ParseDeckNameTemplate(Config.Instance.ArenaDeckNameTemplate), IsArenaDeck = true};

				var cardNodes = doc.DocumentNode.SelectSingleNode(".//ul[@class='deckList']");
				var nameNodes = cardNodes.SelectNodes(".//span[@class='name']");
				var countNodes = cardNodes.SelectNodes(".//span[@class='quantity']");
				var numberOfCards = nameNodes.Count;
				for(var i = 0; i < numberOfCards; i++)
				{
					var nameRaw = nameNodes.ElementAt(i).InnerText;
					var name = HttpUtility.HtmlDecode(nameRaw);
					var card = GameV2.GetCardFromName(name);
					card.Count = int.Parse(countNodes.ElementAt(i).InnerText);
					deck.Cards.Add(card);
					if(string.IsNullOrEmpty(deck.Class) && card.PlayerClass != "Neutral")
						deck.Class = card.PlayerClass;
				}
				if(DeckList.Instance.AllTags.Contains("Arena"))
					deck.Tags.Add("Arena");
				return deck;
			}
			catch(Exception e)
			{
				Logger.WriteLine(e.ToString(), "DeckImporter");
				return null;
			}
		}
		private static async Task<Deck> ImportHearthPwn(string url)
		{
			try
			{
				var doc = await GetHtmlDoc(url);
				var deck = new Deck();

                var deckName = HttpUtility.HtmlDecode(doc.DocumentNode.SelectSingleNode("//section[contains(@class,'deck-info')]/h2[contains(@class,'deck-title')]").InnerText);
				deck.Name = deckName;

				var cardNameNodes =
					doc.DocumentNode.SelectNodes("//td[contains(@class,'col-name')]//a[contains(@href,'/cards/') and contains(@class,'rarity')]");
				var cardCountNodes = doc.DocumentNode.SelectNodes("//td[contains(@class,'col-name')]");
				//<span class="deck-type">Midrange</span>
				var decktype = doc.DocumentNode.SelectSingleNode("//span[contains(@class,'deck-type')]").InnerText;
				if(decktype != "None" && Config.Instance.TagDecksOnImport)
				{
					if(!DeckList.Instance.AllTags.Contains(decktype))
					{
						DeckList.Instance.AllTags.Add(decktype);
						DeckList.Save();
						Helper.MainWindow.ReloadTags();
					}
					deck.Tags.Add(decktype);
				}


				var cardNames = cardNameNodes.Select(cardNameNode => HttpUtility.HtmlDecode(cardNameNode.InnerText));
				var cardCosts = cardCountNodes.Select(countNode => int.Parse(Regex.Match(countNode.LastChild.InnerText, @"\d+").Value));

				var cardInfo = cardNames.Zip(cardCosts, (n, c) => new {Name = n, Count = c});
				foreach(var info in cardInfo)
				{
					var card = GameV2.GetCardFromName(info.Name);
					card.Count = info.Count;
					deck.Cards.Add(card);
					if(string.IsNullOrEmpty(deck.Class) && card.PlayerClass != "Neutral")
						deck.Class = card.PlayerClass;
				}

				return deck;
			}
			catch(Exception e)
			{
				Logger.WriteLine(e.ToString(), "DeckImporter");
				return null;
			}
		}
Beispiel #8
0
        public Card ToCard(bool localizedName)
        {
            Card card = null;

            if (!string.IsNullOrEmpty(Id))
            {
                card = GameV2.GetCardFromId(Id);
            }
            else if (!string.IsNullOrEmpty(Name))
            {
                card = GameV2.GetCardFromName(Name, localizedName);
            }
            if (card != null)
            {
                card.Count = Count;
            }
            return(card);
        }
		private static async Task<Deck> ImportTempostorm(string url)
		{
			try
			{
				// check url looks correct
				var pattern = "/decks/([^/]+)$";
				var match = Regex.Match(url, pattern);
				// get deck name from url, and post the json request
				if(match.Success && match.Groups.Count == 2)
				{
					var slug = match.Groups[1].ToString();
					var data = await PostJson("https://tempostorm.com/deck", "{\"slug\": \"" + slug + "\"}");
					// parse json
					var jsonObject = JsonConvert.DeserializeObject<dynamic>(data);
					if(jsonObject.success.ToObject<Boolean>())
					{
						var deck = new Deck();

						deck.Name = jsonObject.deck.name.ToString();
						//deck.Class = jsonObject.deck.playerClass.ToString();
						var cards = jsonObject.deck.cards;

						foreach(var item in cards)
						{
							var card = GameV2.GetCardFromName(item.card.name.ToString());
							card.Count = item.qty.ToString().Equals("2") ? 2 : 1;
							deck.Cards.Add(card);
							if(string.IsNullOrEmpty(deck.Class) && card.PlayerClass != "Neutral")
								deck.Class = card.PlayerClass;
						}

						return deck;
					}
					throw new Exception("JSON request failed for '" + slug + "'.");
				}
				throw new Exception("The url (" + url + ") is not a vaild TempoStorm deck.");
			}
			catch(Exception e)
			{
				Logger.WriteLine(e.ToString(), "DeckImporter");
				return null;
			}
		}
		private static async Task<Deck> ImportHearthstonePlayers(string url)
		{
			try
			{
				var doc = await GetHtmlDoc(url);
				var deck = new Deck();

				var deckName = HttpUtility.HtmlDecode(doc.DocumentNode.SelectSingleNode("//*[@id='deck-list-title']").InnerText);
				deck.Name = deckName;

				var cardNodes = doc.DocumentNode.SelectNodes("//div[contains(@class,'guide-deck-list')]/div/div[contains(@class,'card')]");
				foreach(var cardNode in cardNodes)
				{
					//silly names contain right-single quotation mark
					var cardName =
						cardNode.SelectSingleNode(".//span[contains(@class, 'card-title')]")
						        .InnerText.Replace("&#8217", "&#39")
						        .Replace("&#8216", "&#39");

					var name = HttpUtility.HtmlDecode(cardName);

					//no count there if count == 1
					var countNode = cardNode.SelectSingleNode(".//span[contains(@class, 'card-count')]");
					var count = 1;
					if(countNode != null)
						count = int.Parse(countNode.InnerText);

					var card = GameV2.GetCardFromName(name);
					if(string.IsNullOrEmpty(deck.Class) && card.PlayerClass != "Neutral")
						deck.Class = card.PlayerClass;
					card.Count = count;
					deck.Cards.Add(card);
				}
				return deck;
			}
			catch(Exception e)
			{
				Logger.WriteLine(e.ToString(), "DeckImporter");
				return null;
			}
		}
		private static async Task<Deck> ImportHearthBuilder(string url)
		{
			try
			{
				var doc = await GetHtmlDoc(url);
				var deck = new Deck();

				var deckName =
					HttpUtility.HtmlDecode(doc.DocumentNode.SelectSingleNode("//div[contains(@class, 'single-deck-title-wrap')]/h2").InnerText);
				deck.Name = deckName;

				var cardNodes = doc.DocumentNode.SelectNodes("//div[@data-card-load]");

				foreach(var cardNode in cardNodes)
				{
					var nameString = HttpUtility.HtmlDecode(cardNode.InnerText);
					var match = Regex.Match(nameString, @"^\s*(.*)\s*(x 2)?\s*$");

					if(match.Success)
					{
						var name = match.Groups[1].Value;
						var count = match.Groups[2].Value;

						var card = GameV2.GetCardFromName(name);
						card.Count = String.IsNullOrEmpty(count) ? 1 : 2;
						deck.Cards.Add(card);
						if(string.IsNullOrEmpty(deck.Class) && card.PlayerClass != "Neutral")
							deck.Class = card.PlayerClass;
					}
				}
				return deck;
			}
			catch(Exception e)
			{
				Logger.WriteLine(e.ToString(), "DeckImporter");
				return null;
			}
		}
		private static async Task<Deck> ImportHearthHead(string url)
		{
			try
			{
				if(!url.Contains("http://www."))
					url = "http://www." + url.Split('.').Skip(1).Aggregate((c, n) => c + "." + n);

				var doc = await GetHtmlDocJs(url);
				var deck = new Deck();

				var deckName = HttpUtility.HtmlDecode(doc.DocumentNode.SelectSingleNode("//*[@id='deckguide-name']").InnerText);
				deck.Name = deckName;


				var cardNodes = doc.DocumentNode.SelectNodes("//*[contains(@class,'deckguide-cards-type')]//ul//li");

				foreach(var cardNode in cardNodes)
				{
					var nameRaw = cardNode.SelectSingleNode(".//a").InnerText;
					var name = HttpUtility.HtmlDecode(nameRaw);
					var count = cardNode.InnerText.Remove(0, nameRaw.Length - 1).Contains("2") ? 2 : 1;
					var card = GameV2.GetCardFromName(name);
					card.Count = count;
					deck.Cards.Add(card);
					if(string.IsNullOrEmpty(deck.Class) && card.PlayerClass != "Neutral")
						deck.Class = card.PlayerClass;
				}

				return deck;
			}
			catch(Exception e)
			{
				Logger.WriteLine(e.ToString(), "DeckImporter");
				return null;
			}
		}
Beispiel #13
0
        private Deck ParseCardString(string cards, bool localizedNames = false)
        {
            try
            {
                var deck  = new Deck();
                var lines = cards.Split('\n');
                foreach (var line in lines)
                {
                    var   count    = 1;
                    var   cardName = line.Trim();
                    Match match    = null;
                    if (_cardLineRegexCountFirst.IsMatch(cardName))
                    {
                        match = _cardLineRegexCountFirst.Match(cardName);
                    }
                    else if (_cardLineRegexCountLast.IsMatch(cardName))
                    {
                        match = _cardLineRegexCountLast.Match(cardName);
                    }
                    else if (_cardLineRegexCountLast2.IsMatch(cardName))
                    {
                        match = _cardLineRegexCountLast2.Match(cardName);
                    }
                    if (match != null)
                    {
                        var tmpCount = match.Groups["count"];
                        if (tmpCount.Success)
                        {
                            count = int.Parse(tmpCount.Value);
                        }
                        cardName = match.Groups["cardname"].Value.Trim();
                    }

                    var card = GameV2.GetCardFromName(cardName, localizedNames);
                    if (card == null || string.IsNullOrEmpty(card.Name))
                    {
                        continue;
                    }
                    card.Count = count;

                    if (string.IsNullOrEmpty(deck.Class) && card.PlayerClass != "Neutral")
                    {
                        deck.Class = card.PlayerClass;
                    }

                    if (deck.Cards.Contains(card))
                    {
                        var deckCard = deck.Cards.First(c => c.Equals(card));
                        deck.Cards.Remove(deckCard);
                        deckCard.Count += count;
                        deck.Cards.Add(deckCard);
                    }
                    else
                    {
                        deck.Cards.Add(card);
                    }
                }
                return(deck);
            }
            catch (Exception ex)
            {
                Logger.WriteLine("Error parsing card string: " + ex, "Import");
                return(null);
            }
        }
		private static async Task<Deck> ImportHsTopdeck(string url)
		{
			try
			{
				var doc = await GetHtmlDoc(url);

				//<div id="leftbar"><div class="headbar"><div style="float:left">ViaGame House Cup #3</div>
				var tournament = HttpUtility.HtmlDecode(doc.DocumentNode.SelectSingleNode("//div[@id='leftbar']/div[contains(@class, 'headbar')]/div").InnerText);

				// <div class="headbar"><div style="float:left">#5 - Hunter Face -<a href="search.php?q=ThijsNL&filter=current">ThijsNL</a>
				var deckName = HttpUtility.HtmlDecode(doc.DocumentNode.SelectSingleNode("//div[@id='center']/div[@class='headbar']/div").InnerText.Trim());

				var deck = new Deck();
				deck.Name = tournament + " - " + deckName;

				//<div class="cardname" ... <span class="basic">2 Abusive Sergeant</span>
				var cards = doc.DocumentNode.SelectNodes("//div[contains(@class, 'cardname')]/span");

				//<span class="midlarge"><span class="hunter">Hunter</span>-<span class="aggro">Aggro</span></span>
				var deckInfo = doc.DocumentNode.SelectSingleNode("//div[@id='contentfr']/div[@id='infos']").SelectNodes("//span[contains(@class, 'midlarge')]/span");
				if (deckInfo.Count == 2)
				{
					deck.Class = HttpUtility.HtmlDecode(deckInfo[0].InnerText).Trim();

					var decktype = HttpUtility.HtmlDecode(deckInfo[1].InnerText).Trim();
					if(!String.IsNullOrEmpty(decktype) && decktype != "None" && Config.Instance.TagDecksOnImport)
					{
						if(!DeckList.Instance.AllTags.Contains(decktype))
						{
							DeckList.Instance.AllTags.Add(decktype);
							DeckList.Save();
							Helper.MainWindow.ReloadTags();
						}
						deck.Tags.Add(decktype);
					}
				}

				foreach(var cardNode in cards)
				{
					var nameString = HttpUtility.HtmlDecode(cardNode.InnerText);
					var match = Regex.Match(nameString, @"^\s*(\d+)\s+(.*)\s*$");

					if(match.Success)
					{
						var count = match.Groups[1].Value;
						var name = match.Groups[2].Value;

						var card = GameV2.GetCardFromName(name);
						card.Count = count.Equals("2") ? 2 : 1;
						deck.Cards.Add(card);
						if(string.IsNullOrEmpty(deck.Class) && card.PlayerClass != "Neutral")
							deck.Class = card.PlayerClass;
					}
				}

				return deck;
			}
			catch(Exception e)
			{
				Logger.WriteLine(e.ToString(), "DeckImporter");
				return null;
			}
		}