public static void Update() { // Don't do anything if not in a game if (API.Game.IsInMenu || !API.Game.IsRunning) { return; } System.Windows.Point firstCardInHand = new System.Windows.Point(0.0d, 0.0d); firstCardInHand = Hearthstone_Deck_Tracker.Windows.OverlayWindow.GetPlayerCardPosition(1, 1); int count = API.Game.Entities.Count; int[] playerMinionPositions = { 0, 0, 0, 0, 0, 0, 0 }; for (int i = 0; i < count; i++) { if (API.Game.Entities[0].IsPlayer) { } } // Compare with old value and update with new value simultaneously // Print to debug log if changed and if program is in debug mode if (playerHandCount != (playerHandCount = API.Game.Player.HandCount) && debug) { Logger.WriteLine("Player now has " + playerHandCount + " in hand."); } if (playerMinionCount != (playerMinionCount = API.Game.PlayerMinionCount) && debug) { Logger.WriteLine("Player now has " + playerMinionCount + " minions."); } if (opponentHandCount != (opponentHandCount = API.Game.Opponent.HandCount) && debug) { Logger.WriteLine("Opponent now has " + opponentHandCount + " in hand."); } if (opponentMinionCount != (opponentMinionCount = API.Game.OpponentMinionCount) && debug) { Logger.WriteLine("Opponent now has " + opponentMinionCount + " minions."); } /* * TODO * - * * NOTES * - if player.goingFirst mulligancards = 4 * - else mulligancards = 3 */ }
public static void PlayerSetAside(string id) { Game.SetAsideCards.Add(id); Logger.WriteLine("set aside: " + id); }
#pragma warning restore 4014 private static void LogEvent(string type, string id = "", int turn = 0, int from = -1) { Logger.WriteLine(string.Format("{0} (id:{1} turn:{2} from:{3})", type, id, turn, from), "LogReader"); }
public static void HandleGameStart(string playerHero) { //avoid new game being started when jaraxxus is played if (!Game.IsInMenu) { return; } Game.PlayingAs = playerHero; Logger.WriteLine("Game start"); if (Config.Instance.FlashHsOnTurnStart) { User32.FlashHs(); } if (Config.Instance.BringHsToForeground) { User32.BringHsToForeground(); } if (Config.Instance.KeyPressOnGameStart != "None" && Helper.MainWindow.EventKeys.Contains(Config.Instance.KeyPressOnGameStart)) { SendKeys.SendWait("{" + Config.Instance.KeyPressOnGameStart + "}"); Logger.WriteLine("Sent keypress: " + Config.Instance.KeyPressOnGameStart); } var selectedDeck = Helper.MainWindow.DeckPickerList.SelectedDeck; if (selectedDeck != null) { Game.SetPremadeDeck((Deck)selectedDeck.Clone()); } Game.IsInMenu = false; Game.Reset(); //select deck based on hero if (!string.IsNullOrEmpty(playerHero)) { if (!Game.IsUsingPremade || !Config.Instance.AutoDeckDetection) { return; } if (selectedDeck == null || selectedDeck.Class != Game.PlayingAs) { var classDecks = Helper.MainWindow.DeckList.DecksList.Where(d => d.Class == Game.PlayingAs).ToList(); if (classDecks.Count == 0) { Logger.WriteLine("Found no deck to switch to", "HandleGameStart"); } else if (classDecks.Count == 1) { Helper.MainWindow.DeckPickerList.SelectDeck(classDecks[0]); Logger.WriteLine("Found deck to switch to: " + classDecks[0].Name, "HandleGameStart"); } else if (Helper.MainWindow.DeckList.LastDeckClass.Any(ldc => ldc.Class == Game.PlayingAs)) { var lastDeckName = Helper.MainWindow.DeckList.LastDeckClass.First(ldc => ldc.Class == Game.PlayingAs).Name; Logger.WriteLine("Found more than 1 deck to switch to - last played: " + lastDeckName, "HandleGameStart"); var deck = Helper.MainWindow.DeckList.DecksList.FirstOrDefault(d => d.Name == lastDeckName); if (deck != null) { Helper.MainWindow.DeckPickerList.SelectDeck(deck); Helper.MainWindow.UpdateDeckList(deck); Helper.MainWindow.UseDeck(deck); } } } } }
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; } }
private static async Task<Deck> ImportArenaValue(string url) { try { var deck = new Deck {Name = Helper.ParseDeckNameTemplate(Config.Instance.ArenaDeckNameTemplate), IsArenaDeck = true}; const string baseUrl = @"http://www.arenavalue.com/deckpopout.php?id="; var newUrl = baseUrl + url.Split(new[] {'/'}, StringSplitOptions.RemoveEmptyEntries).Last(); HtmlNodeCollection nodes = null; using(var wb = new WebBrowser()) { var done = false; wb.Navigate(newUrl + "#" + DateTime.Now.Ticks); wb.DocumentCompleted += (sender, args) => done = true; while(!done) await Task.Delay(50); for(var i = 0; i < 20; i++) { var doc = new HtmlDocument(); doc.Load(wb.DocumentStream); if((nodes = doc.DocumentNode.SelectNodes("//*[@id='deck']/div[@class='deck screenshot']")) != null) { try { if(nodes.Sum(x => int.Parse(x.Attributes["data-count"].Value)) == 30) break; } catch { } } await Task.Delay(500); } } if(nodes == null) return null; foreach(var node in nodes) { var cardId = node.Attributes["data-original"].Value; int count; int.TryParse(node.Attributes["data-count"].Value, out count); var card = GameV2.GetCardFromId(cardId); card.Count = count; deck.Cards.Add(card); if(string.IsNullOrEmpty(deck.Class) && card.GetPlayerClass != "Neutral") deck.Class = card.PlayerClass; } return deck; } catch(Exception e) { Logger.WriteLine(e.ToString(), "DeckImporter"); return null; } }
public async Task GetCardCounts(Deck deck) { var hsHandle = User32.GetHearthstoneWindow(); if(!User32.IsHearthstoneInForeground()) { //restore window and bring to foreground User32.ShowWindow(hsHandle, User32.SwRestore); User32.SetForegroundWindow(hsHandle); //wait it to actually be in foreground, else the rect might be wrong await Task.Delay(500); } if(!User32.IsHearthstoneInForeground()) { MessageBox.Show("Can't find Hearthstone window."); Logger.WriteLine("Can't find Hearthstone window.", "ArenaImport"); return; } await Task.Delay(1000); Overlay.ForceHidden = true; Overlay.UpdatePosition(); const double xScale = 0.013; const double yScale = 0.017; const int targetHue = 53; const int hueMargin = 3; const int numVisibleCards = 21; var hsRect = User32.GetHearthstoneRect(false); var ratio = (4.0 / 3.0) / ((double)hsRect.Width / hsRect.Height); var posX = (int)DeckExporter.GetXPos(0.92, hsRect.Width, ratio); var startY = 71.0/768.0 * hsRect.Height; var strideY = 29.0/768.0 * hsRect.Height; int width = (int)Math.Round(hsRect.Width * xScale); int height = (int)Math.Round(hsRect.Height * yScale); for(var i = 0; i < Math.Min(numVisibleCards, deck.Cards.Count); i++) { var posY = (int)(startY + strideY * i); var capture = Helper.CaptureHearthstone(new System.Drawing.Point(posX, posY), width, height, hsHandle); if(capture != null) { var yellowPixels = 0; for(int x = 0; x < width; x++) { for(int y = 0; y < height; y++) { var pixel = capture.GetPixel(x, y); if(Math.Abs(pixel.GetHue() - targetHue) < hueMargin) yellowPixels++; } } //Console.WriteLine(yellowPixels + " of " + width * height + " - " + yellowPixels / (double)(width * height)); //capture.Save("arenadeckimages/" + i + ".png"); var yellowPixelRatio = yellowPixels / (double)(width * height); if(yellowPixelRatio > 0.25 && yellowPixelRatio < 50) deck.Cards[i].Count = 2; } } if(deck.Cards.Count > numVisibleCards) { const int scrollClicksPerCard = 4; const int scrollDistance = 120; var clientPoint = new System.Drawing.Point(posX, (int)startY); var previousPos = System.Windows.Forms.Cursor.Position; User32.ClientToScreen(hsHandle, ref clientPoint); System.Windows.Forms.Cursor.Position = new System.Drawing.Point(clientPoint.X, clientPoint.Y); for(int j = 0; j < scrollClicksPerCard * (deck.Cards.Count - numVisibleCards); j++) { User32.mouse_event((uint)User32.MouseEventFlags.Wheel, 0, 0, -scrollDistance, UIntPtr.Zero); await Task.Delay(30); } System.Windows.Forms.Cursor.Position = previousPos; await Task.Delay(100); var remainingCards = deck.Cards.Count - numVisibleCards; startY = 76.0 / 768.0 * hsRect.Height + (numVisibleCards - remainingCards) * strideY; for(int i = 0; i < remainingCards ; i++) { var posY = (int)(startY + strideY * i); var capture = Helper.CaptureHearthstone(new System.Drawing.Point(posX, posY), width, height, hsHandle); if(capture != null) { var yellowPixels = 0; for(int x = 0; x < width; x++) { for(int y = 0; y < height; y++) { var pixel = capture.GetPixel(x, y); if(Math.Abs(pixel.GetHue() - targetHue) < hueMargin) yellowPixels++; } } //Console.WriteLine(yellowPixels + " of " + width * height + " - " + yellowPixels / (double)(width * height)); //capture.Save("arenadeckimages/" + i + 21 + ".png"); var yellowPixelRatio = yellowPixels / (double)(width * height); if(yellowPixelRatio > 0.25 && yellowPixelRatio < 50) deck.Cards[numVisibleCards + i].Count = 2; } } System.Windows.Forms.Cursor.Position = new System.Drawing.Point(clientPoint.X, clientPoint.Y); for(int j = 0; j < scrollClicksPerCard * (deck.Cards.Count - 21); j++) { User32.mouse_event((uint)User32.MouseEventFlags.Wheel, 0, 0, scrollDistance, UIntPtr.Zero); await Task.Delay(30); } System.Windows.Forms.Cursor.Position = previousPos; } Overlay.ForceHidden = false; Overlay.UpdatePosition(); ActivateWindow(); }