/// <summary> /// Don't leave this method until after we've ascended /// </summary> /// <param name="ph"></param> /// <param name="curMoney"></param> public static void Ascend(ParsedHeroes ph, double curMoney) { Point AscendButton = GameEngine.GetAscendButton(); // use candy height and width cuz it's close enough int candyHeight = GameEngine.GetCandyHeight(); int candyWidth = GameEngine.GetCandyWidth(); Rectangle c = new Rectangle(AscendButton.X - candyWidth / 2, AscendButton.Y - candyHeight / 2, candyWidth, candyHeight); while (true) { using (Bitmap bitmap = GameEngine.GetImage(c)) { if (OCREngine.GetBlobDensity(bitmap, new Rectangle(0, 0, bitmap.Width - 1, bitmap.Height - 1), new Color[] { Color.FromArgb(68, 215, 35) }) > 0.10) { AddAction(new Action(AscendButton, 0)); Thread.Sleep(1000); return; } } TryUpgradeHero(ph, 19, 3, curMoney); Thread.Sleep(1000); ph = GameEngine.GetHeroes(); curMoney = GameEngine.GetMoney(); } }
/// <summary> /// Don't leave this method until after we've ascended /// </summary> /// <param name="ph"></param> /// <param name="curMoney"></param> public static void Ascend(ParsedHeroes ph, double curMoney) { TrashRelics(); Point AscendButton = GameEngine.GetAscendButton(); // use candy height and width cuz it's close enough int candyHeight = GameEngine.GetCandyHeight(); int candyWidth = GameEngine.GetCandyWidth(); Rectangle c = new Rectangle(AscendButton.X - candyWidth / 2, AscendButton.Y - candyHeight / 2, candyWidth, candyHeight); while (true) { using (Bitmap bitmap = new Bitmap(c.Width, c.Height)) { using (Graphics g = Graphics.FromImage(bitmap)) { g.CopyFromScreen(new Point(c.Left, c.Top), Point.Empty, c.Size); } if (OCREngine.GetBlobDensity(bitmap, new Rectangle(0, 0, bitmap.Width - 1, bitmap.Height - 1), new Color[] { Color.FromArgb(68, 215, 35) }) > 0.10) { AddAction(new Action(AscendButton, 0)); Thread.Sleep(1000); return; } } TryUpgradeHero(ph, 19, 3, curMoney); Thread.Sleep(1000); ph = GameEngine.GetHeroes(); curMoney = GameEngine.GetMoney(); } }
/// <summary> /// Tries to buy a given hero upgrade, if there is enough money. /// </summary> /// <param name="heroIndex"></param> /// <param name="desiredUpgrade"></param> /// <param name="currentMoney"></param> /// <returns></returns> public static bool TryUpgradeHero(ParsedHeroes ph, int heroIndex, int desiredUpgrade, double currentMoney) { if (ph.FirstHeroIndex > heroIndex) { AddAction(new Action(GameEngine.GetScrollbarUpPoint(), 0), 3); return(false); } else if (ph.LastHeroIndex < heroIndex) { AddAction(new Action(GameEngine.GetScrollbarDownPoint(), 0), 3); return(false); } int adjustedIndex = heroIndex - ph.FirstHeroIndex; HeroStats hs = ph.HeroStats[adjustedIndex]; int upgradeStatus = hs.HasUpgrade(desiredUpgrade); if (upgradeStatus == 1) { return(true); } else if (upgradeStatus == -1) { AddAction(new Action(GameEngine.GetScrollbarDownPoint(), 0), 3); return(false); } else { Point upgradeButton; if (hs.Hero.Upgrades[desiredUpgrade].Cost < currentMoney && hs.GetUpgradeButton(out upgradeButton, desiredUpgrade)) { AddAction(new Action(upgradeButton, 0)); return(false); } } return(false); }
private void clickyclicky_Tick(object sender, EventArgs e) { Stopwatch t = new Stopwatch(); t.Start(); double money = GameEngine.GetMoney(); ParsedHeroes ph = GameEngine.GetHeroes(); if (ph != null) { if (Properties.Settings.Default.useTaskList) { label14.Text = PlayerEngine.TryNextTask(ph, money); } else { label14.Text = "None, tasks turned off"; } StringBuilder sb = new StringBuilder(); if (ph.HeroStats != null) { foreach (HeroStats ss in ph.HeroStats) { sb.AppendLine(string.Format("{0}: Lvl {1} Upgrades {2}", ss.Hero.Name, ss.Level, Convert.ToString(ss.UpgradeBitfield, 2))); } } curHeroesTxt.Text = sb.ToString(); } else { curHeroesTxt.Text = string.Empty; } label9.Text = money.ToString(); if (Properties.Settings.Default.logging && DateTime.Now > TimeToNextLog) { Stopwatch imgsw = new Stopwatch(); imgsw.Start(); sw.WriteLine(string.Format("{0},{1}", DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss"), money)); Rectangle playableArea = GameEngine.GetPlayableArea(); using (Bitmap bitmap = new Bitmap(playableArea.Width, playableArea.Height)) { using (Graphics g = Graphics.FromImage(bitmap)) { g.CopyFromScreen(new Point(playableArea.Left, playableArea.Top), Point.Empty, playableArea.Size); } bitmap.Save(string.Format("{0}\\{1}\\screenshots\\{2}.png", loggingDirectory, currentLoggingString, DateTime.Now.ToString("MM-dd-yyyy HH mm ss"))); } TimeToNextLog = TimeToNextLog.AddMinutes(1); imgsw.Stop(); label15.Text = string.Format("Image captured at {0} in {1} ms", DateTime.Now.ToString("hh:mm:ss"), imgsw.ElapsedMilliseconds); } else if (!Properties.Settings.Default.logging) { label15.Text = "Logging turned off"; } t.Stop(); label8.Text = string.Format("{0} ms", t.ElapsedMilliseconds); }
/// <summary> /// The main function which drives autoplaying. It will iterate through the task list sequentially, /// performing each task as necessary. When it reaches the Ascend task, it will restart from the beginning. /// </summary> /// <param name="ph">The parsed heroes obtained from the GameEngine</param> /// <param name="curMoney">The current money</param> /// <returns>A string giving a human-readable representation of the next task</returns> public static string TryNextTask(ParsedHeroes ph, double curMoney) { if (nextTaskToPerform >= Tasks.Count()) { return(string.Empty); } Task nextTask = Tasks[nextTaskToPerform]; // Iris -- after ascending, we may potentially jump many levels into the game, but we don't have any money to buy any heroes. // To get around this, we do what human players do. We click candies when (and only when) we're on the very first task (aka // immediately after we've ascended). // Also sets the maximum time the run has to end, as a fail safe if the app gets stuck (example, faulty OCR money read) if (nextTaskToPerform == 0) { Point[] pts = GameEngine.GetCandyButtons(); foreach (Point p in pts) { AddAction(new Action(p, Modifiers.NONE)); } maxEndTime = DateTime.Now.AddMinutes(Properties.Settings.Default.maxRunDuration); } // Check if the max run time has been reached if (DateTime.Now > maxEndTime && nextTaskToPerform < Tasks.Count() - 3) { nextTaskToPerform = Tasks.Count() - 3; } if (nextTask is AscendTask) { Ascend(ph, curMoney); nextTaskToPerform = 0; return("Ascending"); } if (nextTask is BuyAllÙpgradesTask) { BuyAllUpgrades(); nextTaskToPerform++; return("Buying all upgrades"); } if (nextTask is ActiveTask) { autoClick = true; useSkils = true; nextTaskToPerform++; return("Going Active"); } if (nextTask is IdleTask) { autoClick = false; useSkils = false; nextTaskToPerform++; return("Going Idle"); } if (nextTask is ReloadBrowserTask) { ReloadBrowser(); nextTaskToPerform++; return("Reloading browser window"); } VerifyTask vt = nextTask as VerifyTask; string retStr = string.Empty; if (!TryLevelHero(ph, nextTask.HeroIndex, nextTask.Level, curMoney, nextTask.Wait)) { if (vt != null) { vt.verifyCount = 0; } retStr = string.Format("Level {0} to {1}", GameEngine.HeroList[nextTask.HeroIndex].Name, nextTask.Level); return(retStr); } if (nextTask.Upgrade != -1) { for (int i = 0; i <= nextTask.Upgrade; i++) { if (!TryUpgradeHero(ph, nextTask.HeroIndex, i, curMoney)) { if (vt != null) { vt.verifyCount = 0; } retStr = string.Format("Get upgrade {0} for {1}", nextTask.Upgrade + 1, GameEngine.HeroList[nextTask.HeroIndex].Name); return(retStr); } } } if (vt != null) { vt.verifyCount++; if (vt.verifyCount == 5) { nextTaskToPerform++; vt.verifyCount = 0; return(TryNextTask(ph, curMoney)); } return(string.Format("Verify that {0} is properly leveled and upgraded", GameEngine.HeroList[nextTask.HeroIndex].Name)); } nextTaskToPerform++; return(TryNextTask(ph, curMoney)); }
/// <summary> /// Tries to level a given hero to a desired level, if there is enough money. /// </summary> /// <param name="heroIndex">The hero to level</param> /// <param name="desiredLevel">The level desired</param> /// <param name="currentMoney">The current amount of money</param> /// <returns>True if and only if the hero is currently already at that level</returns> public static bool TryLevelHero(ParsedHeroes ph, int heroIndex, int desiredLevel, double currentMoney, bool wait) { if (ph.FirstHeroIndex > heroIndex) { AddAction(new Action(GameEngine.GetScrollbarUpPoint(), 0), 3); return(false); } else if (ph.LastHeroIndex < heroIndex) { AddAction(new Action(GameEngine.GetScrollbarDownPoint(), 0), 3); return(false); } int adjustedIndex = heroIndex - ph.FirstHeroIndex; HeroStats hs = ph.HeroStats[adjustedIndex]; if (hs.Level == -1) { AddAction(new Action(GameEngine.GetScrollbarDownPoint(), 0), 3); return(false); } int heroLevel = hs.Level; if (heroLevel >= desiredLevel) { return(true); } if (wait && hs.Hero.GetCostToLevel(desiredLevel, heroLevel) > currentMoney) { return(false); } Point pt; if (hs.GetBuyButton(out pt)) { while (hs.Hero.GetCostToLevel(heroLevel + 1, heroLevel) < currentMoney && desiredLevel > heroLevel) { if (desiredLevel - heroLevel >= 100 && hs.Hero.GetCostToLevel(heroLevel + 100, heroLevel) < currentMoney) { AddAction(new Action(pt, Modifiers.CTRL)); currentMoney -= hs.Hero.GetCostToLevel(heroLevel + 100, heroLevel); heroLevel += 100; } else if (desiredLevel - heroLevel >= 25 && hs.Hero.GetCostToLevel(heroLevel + 25, heroLevel) < currentMoney) { AddAction(new Action(pt, Modifiers.Z)); currentMoney -= hs.Hero.GetCostToLevel(heroLevel + 25, heroLevel); heroLevel += 25; } else if (desiredLevel - heroLevel >= 10 && hs.Hero.GetCostToLevel(heroLevel + 10, heroLevel) < currentMoney) { AddAction(new Action(pt, Modifiers.SHIFT)); currentMoney -= hs.Hero.GetCostToLevel(heroLevel + 10, heroLevel); heroLevel += 10; } else { AddAction(new Action(pt, 0)); currentMoney -= hs.Hero.GetCostToLevel(heroLevel + 1, heroLevel); heroLevel++; } } return(false); } else { AddAction(new Action(GameEngine.GetScrollbarDownPoint(), 0), 3); return(false); } }
/// <summary> /// Tries to level a given hero to a desired level, if there is enough money. /// </summary> /// <param name="heroIndex">The hero to level</param> /// <param name="desiredLevel">The level desired</param> /// <param name="currentMoney">The current amount of money</param> /// <returns>True if and only if the hero is currently already at that level</returns> public static bool TryLevelHero(ParsedHeroes ph, int heroIndex, int desiredLevel, double currentMoney, bool wait) { if (GameEngine.GetCachedLevel(heroIndex) >= desiredLevel) { return(true); } if (ph.FirstHeroIndex > heroIndex) { AddAction(new Action(GameEngine.GetScrollbarUpPoint(), 0), 3); return(false); } else if (ph.LastHeroIndex < heroIndex) { AddAction(new Action(GameEngine.GetScrollbarDownPoint(), 0), 3); return(false); } // Check for stepping out of bounds (happens when part of the view is blocked while attempting to do certain actions) int adjustedIndex = heroIndex - ph.FirstHeroIndex; if (adjustedIndex >= ph.HeroStats.Count) { return(false); } HeroStats hs = ph.HeroStats[adjustedIndex]; if (hs.Level == -1) { AddAction(new Action(GameEngine.GetScrollbarDownPoint(), 0), 3); return(false); } int heroLevel = hs.Level; if (heroLevel >= desiredLevel) { return(true); } if (wait && hs.Hero.GetCostToLevel(desiredLevel, heroLevel) > currentMoney) { return(false); } Point pt; if (hs.GetBuyButton(out pt)) { while (hs.Hero.GetCostToLevel(heroLevel + 1, heroLevel) < currentMoney && desiredLevel > heroLevel) { if (desiredLevel - heroLevel >= 100 && hs.Hero.GetCostToLevel(heroLevel + 100, heroLevel) < currentMoney) { AddAction(new Action(pt, Modifiers.CTRL)); currentMoney -= hs.Hero.GetCostToLevel(heroLevel + 100, heroLevel); heroLevel += 100; } else if (desiredLevel - heroLevel >= 25 && hs.Hero.GetCostToLevel(heroLevel + 25, heroLevel) < currentMoney) { AddAction(new Action(pt, Modifiers.Z)); currentMoney -= hs.Hero.GetCostToLevel(heroLevel + 25, heroLevel); heroLevel += 25; } else if (desiredLevel - heroLevel >= 10 && hs.Hero.GetCostToLevel(heroLevel + 10, heroLevel) < currentMoney) { AddAction(new Action(pt, Modifiers.SHIFT)); currentMoney -= hs.Hero.GetCostToLevel(heroLevel + 10, heroLevel); heroLevel += 10; } else { AddAction(new Action(pt, 0)); currentMoney -= hs.Hero.GetCostToLevel(heroLevel + 1, heroLevel); heroLevel++; } } return(false); } else { AddAction(new Action(GameEngine.GetScrollbarDownPoint(), 0), 3); return(false); } }
private void clickyclicky_Tick(object sender, EventArgs e) { Stopwatch t = new Stopwatch(); t.Start(); double money = GameEngine.GetMoney(); ParsedHeroes ph = GameEngine.GetHeroes(); //string dps = GameEngine.GetDamagePerSecond(); // ooze var oozePopupActive = GameEngine.IsRelicOozePopupActive(); lblIsOozeActive.Text = oozePopupActive?"YES":"NO"; if (oozePopupActive) { AddLogMessage("A", "Ooze popup is active, trying to close"); PlayerEngine.TryCloseOozePopup(); } // Progressmode handling var progressMode = GameEngine.IsProgressModeOn(); lblProgressMode.Text = progressMode?"ON":"OFF"; if (progressModeWas != progressMode) { AddLogMessage("A", "Progress mode was " + (progressMode ? "Enabled" : "Disabled")); if (!progressMode) { lastProgressDisabled = DateTime.Now; } } progressModeWas = progressMode; if (!progressMode && Properties.Settings.Default.autoEnableProgress) { var timeSinceDisabled = Math.Round(DateTime.Now.Subtract(lastProgressDisabled).TotalSeconds); lblProgressModeExtra.Text = String.Format("Disabled for {0}s, enabling in {1}s", timeSinceDisabled, (Properties.Settings.Default.enableProgressDelay - timeSinceDisabled)); if (timeSinceDisabled > Properties.Settings.Default.enableProgressDelay) { PlayerEngine.ToggleProgressMode(); AddLogMessage("A", String.Format("Time since progress mode was disabled: {0}, enabling again", timeSinceDisabled)); } } else { lblProgressModeExtra.Text = ""; } if (ph != null) { if (Properties.Settings.Default.useTaskList) { var newTask = PlayerEngine.TryNextTask(ph, money); if (newTask != lblCurrGoal.Text) { AddLogMessage("T", newTask); lblCurrGoal.Text = newTask; } } else { lblCurrGoal.Text = "None, tasks turned off"; } StringBuilder sb = new StringBuilder(); if (ph.HeroStats != null) { foreach (HeroStats ss in ph.HeroStats) { sb.AppendLine(string.Format("{0}: Lvl {1} Upgrades {2}", ss.Hero.Name, ss.Level, Convert.ToString(ss.UpgradeBitfield, 2))); } } curHeroesTxt.Text = sb.ToString(); } else { curHeroesTxt.Text = string.Empty; } lblCurrMoney.Text = money.ToString(); //lblCurrentDamagePerSecond.Text = dps.ToString(); //pictureBox1.Image = GameEngine.GetDamagePerSecondBMP(); if (Properties.Settings.Default.logging && DateTime.Now > TimeToNextLog) { Stopwatch imgsw = new Stopwatch(); imgsw.Start(); sw.WriteLine(string.Format("{0},{1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), money)); Rectangle playableArea = GameEngine.GetPlayableArea(); using (Bitmap bitmap = new Bitmap(playableArea.Width, playableArea.Height)) { using (Graphics g = Graphics.FromImage(bitmap)) { g.CopyFromScreen(new Point(playableArea.Left, playableArea.Top), Point.Empty, playableArea.Size); } bitmap.Save(string.Format("{0}\\{1}\\screenshots\\{2}.png", loggingDirectory, currentLoggingString, DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss"))); } TimeToNextLog = TimeToNextLog.AddMinutes(1); imgsw.Stop(); AddLogMessage("I", string.Format("Screenshot & log @ {0} in {1} ms", DateTime.Now.ToString("HH:mm:ss"), imgsw.ElapsedMilliseconds)); } else if (!Properties.Settings.Default.logging) { lblMiscInfo.Text = "Logging turned off"; } t.Stop(); lblParseTime.Text = string.Format("{0} ms", t.ElapsedMilliseconds); }