Exemplo n.º 1
0
        public static async Task ClearManaFilter(ExportingInfo info)
        {
            Logger.WriteLine("Clearing \"Zero\" crystal...", "DeckExporter");

            // First, ensure mana filters are cleared
            var crystalPoint = new Point((int)Helper.GetScaledXPos(Config.Instance.ExportZeroButtonX, info.HsRect.Width, info.Ratio),
                                         (int)(Config.Instance.ExportZeroButtonY * info.HsRect.Height));

            if (ExportingHelper.IsZeroCrystalSelected(info.HsHandle, info.Ratio, info.HsRect.Width, info.HsRect.Height))
            {
                // deselect it
                await MouseActions.ClickOnPoint(info.HsHandle, crystalPoint);
            }
            else
            {
                // select it and then unselect it (in case other crystals are on)
                await MouseActions.ClickOnPoint(info.HsHandle, crystalPoint);

                await MouseActions.ClickOnPoint(info.HsHandle, crystalPoint);
            }
        }
        public static async Task SetDeckName(Deck deck, ExportingInfo info)
        {
            if (Config.Instance.ExportSetDeckName && !deck.TagList.ToLower().Contains("brawl"))
            {
                var name = Regex.Replace(deck.Name, @"[\(\)\{\}]", "");
                if (name != deck.Name)
                {
                    Logger.WriteLine("Removed parenthesis/braces from deck name. New name: " + name, "DeckExporter");
                }
                if (Config.Instance.ExportAddDeckVersionToName)
                {
                    var version = " " + deck.SelectedVersion.ShortVersionString;
                    if (name.Length + version.Length > MaxLengthDeckName)
                    {
                        name = name.Substring(0, MaxLengthDeckName - version.Length);
                    }
                    name += version;
                }

                Logger.WriteLine("Setting deck name...", "DeckExporter");
                var nameDeckPos = new Point((int)Helper.GetScaledXPos(Config.Instance.ExportNameDeckX, info.HsRect.Width, info.Ratio),
                                            (int)(Config.Instance.ExportNameDeckY * info.HsRect.Height));
                await MouseActions.ClickOnPoint(info.HsHandle, nameDeckPos);

                //send enter and second click to make sure the current name gets selected
                SendKeys.SendWait("{ENTER}");
                await MouseActions.ClickOnPoint(info.HsHandle, nameDeckPos);

                if (Config.Instance.ExportPasteClipboard)
                {
                    Clipboard.SetText(name);
                    SendKeys.SendWait("^v");
                }
                else
                {
                    SendKeys.SendWait(name);
                }
                SendKeys.SendWait("{ENTER}");
            }
        }
        public static async Task ClearDeck(ExportingInfo info)
        {
            if (!Config.Instance.AutoClearDeck)
            {
                return;
            }
            var count = 0;

            Logger.WriteLine("Clearing deck...", "DeckExporter");
            while (!ExportingHelper.IsDeckEmpty(info.HsHandle, info.HsRect.Width, info.HsRect.Height, info.Ratio))
            {
                await
                MouseActions.ClickOnPoint(info.HsHandle,
                                          new Point((int)Helper.GetScaledXPos(Config.Instance.ExportClearX, info.HsRect.Width, info.Ratio),
                                                    (int)(Config.Instance.ExportClearY *info.HsRect.Height)));

                if (count++ > 35)
                {
                    break;
                }
            }
        }
        ///<summary>
        /// Returns -1 if Hearthstone loses focus
        /// </summary>
        public static async Task <int> AddCardToDeck(Card card, ExportingInfo info)
        {
            if (!User32.IsHearthstoneInForeground())
            {
                Core.MainWindow.ShowMessage("Exporting aborted", "Hearthstone window lost focus.");
                Logger.WriteLine("Exporting aborted, window lost focus", "DeckExporter");
                return(-1);
            }

            if (Config.Instance.ExportForceClear)
            {
                await ClearSearchBox(info.HsHandle, info.SearchBoxPos);
            }

            await MouseActions.ClickOnPoint(info.HsHandle, info.SearchBoxPos);

            if (Config.Instance.ExportPasteClipboard)
            {
                Clipboard.SetText(ExportingHelper.GetSearchString(card));
                SendKeys.SendWait("^v");
            }
            else
            {
                SendKeys.SendWait(ExportingHelper.GetSearchString(card));
            }
            SendKeys.SendWait("{ENTER}");

            Logger.WriteLine("try to export card: " + card, "DeckExporter");
            await Task.Delay(Config.Instance.DeckExportDelay * 2);

            if (await ExportingHelper.CheckForSpecialCases(card, info.CardPosX + 50, info.Card2PosX + 50, info.CardPosY + 50, info.HsHandle))
            {
                return(0);
            }

            //Check if Card exist in collection
            if (ExportingHelper.CardExists(info.HsHandle, (int)info.CardPosX, (int)info.CardPosY, info.HsRect.Width, info.HsRect.Height))
            {
                //Check if a golden exist
                if (Config.Instance.PrioritizeGolden &&
                    ExportingHelper.CardExists(info.HsHandle, (int)info.Card2PosX, (int)info.CardPosY, info.HsRect.Width, info.HsRect.Height))
                {
                    await MouseActions.ClickOnPoint(info.HsHandle, new Point((int)info.Card2PosX + 50, (int)info.CardPosY + 50));

                    if (card.Count == 2)
                    {
                        await MouseActions.ClickOnPoint(info.HsHandle, new Point((int)info.Card2PosX + 50, (int)info.CardPosY + 50));

                        await MouseActions.ClickOnPoint(info.HsHandle, new Point((int)info.CardPosX + 50, (int)info.CardPosY + 50));
                    }
                }
                else
                {
                    await MouseActions.ClickOnPoint(info.HsHandle, new Point((int)info.CardPosX + 50, (int)info.CardPosY + 50));

                    if (card.Count == 2)
                    {
                        //Check if two card are not available
                        await Task.Delay(200 - Config.Instance.DeckExportDelay);

                        if (ExportingHelper.CardHasLock(info.HsHandle, (int)(info.CardPosX + info.HsRect.Width * 0.048),
                                                        (int)(info.CardPosY + info.HsRect.Height * 0.287), info.HsRect.Width, info.HsRect.Height))
                        {
                            if (ExportingHelper.CardExists(info.HsHandle, (int)info.Card2PosX, (int)info.CardPosY, info.HsRect.Width, info.HsRect.Height))
                            {
                                await MouseActions.ClickOnPoint(info.HsHandle, new Point((int)info.Card2PosX + 50, (int)info.CardPosY + 50));

                                return(0);
                            }
                            Logger.WriteLine("Only one copy found: " + card.Name, "DeckExporter");
                            return(1);
                        }

                        await MouseActions.ClickOnPoint(info.HsHandle, new Point((int)info.CardPosX + 50, (int)info.CardPosY + 50));
                    }
                }
            }
            else
            {
                return(card.Count);
            }
            return(0);
        }
Exemplo n.º 5
0
        public async Task SetDeckName()
        {
            if (Config.Instance.ExportSetDeckName && !_deck.TagList.ToLower().Contains("brawl"))
            {
                var name = Regex.Replace(_deck.Name, @"[\(\)\{\}]", "");
                if (name != _deck.Name)
                {
                    Log.Info("Removed parenthesis/braces from deck name. New name: " + name);
                }
                if (Reflection.GetEditedDeck()?.Name == _deck.Name)
                {
                    Log.Info("Deck already has the correct name");
                    return;
                }
                if (Config.Instance.ExportAddDeckVersionToName)
                {
                    var version = " " + _deck.SelectedVersion.ShortVersionString;
                    if (name.Length + version.Length > MaxLengthDeckName)
                    {
                        name = name.Substring(0, MaxLengthDeckName - version.Length);
                    }
                    name += version;
                }

                Log.Info("Setting deck name...");
                await _mouse.ClickOnPoint(_deckNamePoint);

                //send enter and second click to make sure the current name gets selected
                SendKeys.SendWait("{ENTER}");
                await _mouse.ClickOnPoint(_deckNamePoint);

                if (Config.Instance.ExportPasteClipboard)
                {
                    Clipboard.SetText(name);
                    SendKeys.SendWait("^{v}");
                }
                else
                {
                    SendKeys.SendWait(name);
                }
                SendKeys.SendWait("{ENTER}");
            }
        }