/// <summary> /// Pauses the game. /// </summary> public void Pause() { cg.updateScreen(); // Check if the pause text is there. If not, toggle pause. if (cg.CompareColor(441, 268, new int[] { 187, 138, 79 }, 10) == false) { TogglePause(); } }
// Selects an option in the slot menu. internal bool SelectMenuOption(Point point) { cg.Cursor = point; // Select the option Thread.Sleep(100); // <image url="$(ProjectDir)\ImageComments\Interact.cs\OptionSelect.png" scale="0.7" /> cg.updateScreen(); if (cg.CompareColor(point.X, point.Y, new int[] { 83, 133, 155 }, 20)) // Detects if the blue color of the selected option is there, clicks then returns true { cg.LeftClick(point.X, point.Y, 0); cg.ResetMouse(); return(true); } return(false); }
/// <summary> /// Gets a list of players who died. /// </summary> /// <param name="noUpdate"></param> /// <returns>List of players who are dead.</returns> public List <int> PlayersDead(bool noUpdate = false) { // Returns which players that are dead by checking the killed marker locations for a red 'X'. // <image url="$(ProjectDir)\ImageComments\GetInfo.cs\DeadPlayers.png" scale="1.3" /> if (!noUpdate) { cg.updateScreen(); } List <int> playersDead = new List <int>(); for (int i = 0; i < 12; i++) { if (cg.CompareColor(KilledPlayerMarkerLocations[i], 98, CALData.DeadPlayerColor, CALData.DeadPlayerFade) && !HasHealthBar(i, true)) { playersDead.Add(i); } } return(playersDead); }
/// <summary> /// Send message to chat. /// </summary> /// <param name="text">Text to send.</param> public void Chat(string text) { if (ChatPrefix != null) { text = ChatPrefix + " " + text; } //if (!cg.OpenChatIsDefault) OpenChat(); cg.updateScreen(); // To prevent abuse, make sure that the channel is not general. if (!cg.CompareColor(ChatLocation.X, ChatLocation.Y, GeneralChatColor, 20) || !BlockGeneralChat) { cg.TextInput(text); } cg.KeyPress(Keys.Return); if (cg.OpenChatIsDefault) { Thread.Sleep(250); OpenChat(); } cg.ResetMouse(); }
/// <summary> /// Loads a preset saved in Overwatch, 0 being the first saved preset. /// </summary> /// <param name="preset">Preset to load.</param> // Loads a preset in Overwatch Custom Games public void LoadPreset(int preset) { if (preset < 0) { throw new ArgumentOutOfRangeException("preset", preset, "Argument preset must be greater than 0."); } int x = 0; int y = 155; // Number of presets in a row is 4. while (preset > 3) { preset = preset - 4; y = y + 33; // Increment row by 1. Space between rows is 33 pixels. } if (preset == 0) { x = 146; // Column 1 } else if (preset == 1) { x = 294; // Column 2 } else if (preset == 2) { x = 440; // Column 3 } else if (preset == 3) { x = 590; // Column 4 } cg.GoToSettings(); cg.LeftClick(103, 183, 2000); // Clicks "Preset" button cg.updateScreen(); while (cg.CompareColor(91, 174, new int[] { 188, 143, 77 }, 10)) { cg.updateScreen(); Thread.Sleep(100); } cg.LeftClick(x, y); // Clicks the preset cg.LeftClick(480, 327); // Clicks confirm // Go back to lobby cg.GoBack(2); }
/// <summary> /// Gets the difficulty of the AI in the input slot. /// <para>If the input slot is not an AI, returns null. /// If checking an AI's difficulty in the queue, it will always return easy, or null if it is a player.</para> /// </summary> /// <param name="slot">Slot to check</param> /// <param name="noUpdate"></param> /// <returns>Returns a value in the Difficulty enum if the difficulty is found. Returns null if the input slot is not an AI.</returns> /// <exception cref="InvalidSlotException">Thrown when slot is out of range.</exception> public Difficulty?GetAIDifficulty(int slot, bool noUpdate = false) { if (!cg.IsSlotValid(slot)) { throw new InvalidSlotException(string.Format("Slot {0} is out of range of possible slots to check for AI.", slot)); } if (slot == 5 && cg.OpenChatIsDefault) { cg.Chat.CloseChat(); } if (!noUpdate) { cg.updateScreen(); } if (cg.IsSlotBlue(slot) || cg.IsSlotRed(slot)) { bool draw = cg.debugmode; // For debug mode List <int> rl = new List <int>(); // Likelyhood in percent for difficulties. List <Difficulty> dl = new List <Difficulty>(); // Difficulty bool foundWhite = false; int foundWhiteIndex = 0; int maxWhite = 3; // For each check length in IsAILocations for (int xi = 0; xi < DifficultyLocations[slot, 2] && foundWhiteIndex < maxWhite; xi++) { if (foundWhite) { foundWhiteIndex++; } Color cc = cg.GetPixelAt(DifficultyLocations[slot, 0] + xi, DifficultyLocations[slot, 1]); // Check for white color of text if (cg.CompareColor(DifficultyLocations[slot, 0] + xi, DifficultyLocations[slot, 1], CALData.WhiteColor, 110) && (slot > 5 || cc.B - cc.R < 20)) { foundWhite = true; // For each difficulty markup for (int b = 0; b < DifficultyMarkups.Length; b++) { Bitmap tmp = null; if (draw) { tmp = cg.BmpClone(0, 0, cg.bmp.Width, cg.bmp.Height); } // Check if bitmap matches checking area double success = 0; double total = 0; for (int x = 0; x < DifficultyMarkups[b].Width; x++) { for (int y = DifficultyMarkups[b].Height - 1; y >= 0; y--) { // If the color pixel of the markup is not white, check if valid. Color pc = DifficultyMarkups[b].GetPixel(x, y); if (pc != Color.FromArgb(255, 255, 255, 255)) { // tc is true if the pixel is black, false if it is red. bool tc = pc == Color.FromArgb(255, 0, 0, 0); total++; // Indent the total // If the checking color in the bmp bitmap is equal to the pc color, add to success. if (cg.CompareColor(DifficultyLocations[slot, 0] + xi + x, DifficultyLocations[slot, 1] - Extensions.InvertNumber(y, DifficultyMarkups[b].Height - 1), CALData.WhiteColor, 50) == tc) { success++; if (draw) { if (tc) { tmp.SetPixel(DifficultyLocations[slot, 0] + xi + x, DifficultyLocations[slot, 1] - Extensions.InvertNumber(y, DifficultyMarkups[b].Height - 1), Color.Blue); } else { tmp.SetPixel(DifficultyLocations[slot, 0] + xi + x, DifficultyLocations[slot, 1] - Extensions.InvertNumber(y, DifficultyMarkups[b].Height - 1), Color.Lime); } } } else if (draw) { if (tc) { tmp.SetPixel(DifficultyLocations[slot, 0] + xi + x, DifficultyLocations[slot, 1] - Extensions.InvertNumber(y, DifficultyMarkups[b].Height - 1), Color.Red); } else { tmp.SetPixel(DifficultyLocations[slot, 0] + xi + x, DifficultyLocations[slot, 1] - Extensions.InvertNumber(y, DifficultyMarkups[b].Height - 1), Color.Orange); } } if (draw) { tmp.SetPixel(DifficultyLocations[slot, 0] + xi + x, DifficultyLocations[slot, 1] - DifficultyMarkups[b].Height * 2 + y, DifficultyMarkups[b].GetPixel(x, y)); cg.g.DrawImage(tmp, new Rectangle(0, -750, tmp.Width * 3, tmp.Height * 3)); Thread.Sleep(1); } } } } // Get the result double result = (success / total) * 100; rl.Add((int)result); dl.Add((Difficulty)b); if (draw) { tmp.SetPixel(DifficultyLocations[slot, 0] + xi, DifficultyLocations[slot, 1], Color.MediumPurple); cg.g.DrawImage(tmp, new Rectangle(0, -750, tmp.Width * 3, tmp.Height * 3)); Console.WriteLine((Difficulty)b + " " + result); Thread.Sleep(1000); } } } } if (slot == 5 && cg.OpenChatIsDefault) { cg.Chat.OpenChat(); } // Return the difficulty that is most possible. if (rl.Count > 0) { int max = rl.Max(); if (max >= 75) { return(dl[rl.IndexOf(max)]); } else { return(null); } } else { return(null); } } else if (cg.QueueCount > 0) { int y = DifficultyLocationsQueue[slot - Queueid]; for (int x = DifficultyLocationQueueX; x < 150 + DifficultyLocationQueueX; x++) { if (cg.CompareColor(x, y, new int[] { 180, 186, 191 }, 10)) { return(null); } } return(Difficulty.Easy); } else { return(null); } }
/// <summary> /// Loads a preset saved in Overwatch, 0 being the first saved preset. /// </summary> /// <param name="preset">Preset to load.</param> /// <param name="maxWaitTime">Maximum time to wait for the preset to show up.</param> // Loads a preset in Overwatch Custom Games public bool LoadPreset(int preset, int maxWaitTime = 5000) { if (preset < 0) { throw new ArgumentOutOfRangeException("preset", preset, "Argument preset must be equal or greater than 0."); } Point presetLocation = GetPresetLocation(preset); cg.GoToSettings(); cg.LeftClick(103, 183, 2000); // Clicks "Preset" button Stopwatch wait = new Stopwatch(); wait.Start(); if (numPresets == null) { while (true) { cg.updateScreen(); if (cg.CompareColor(presetLocation.X, presetLocation.Y, new int[] { 126, 128, 134 }, 40)) { break; } else if (wait.ElapsedMilliseconds >= maxWaitTime) { cg.GoBack(2); cg.ResetMouse(); return(false); } Thread.Sleep(100); } } else { Point finalPresetLocation = GetPresetLocation(numPresets); while (true) { cg.updateScreen(); if (cg.CompareColor(finalPresetLocation.X, finalPresetLocation.Y, new int[] { 126, 128, 134 }, 40)) { break; } else if (wait.ElapsedMilliseconds >= maxWaitTime) { cg.GoBack(2); cg.ResetMouse(); return(false); } Thread.Sleep(100); } } Thread.Sleep(250); cg.LeftClick(presetLocation.X, presetLocation.Y); // Clicks the preset cg.LeftClick(480, 327); // Clicks confirm // Go back to lobby cg.GoBack(2); cg.ResetMouse(); return(true); }
/// <summary> /// Determines if the game is paused. /// </summary> public bool IsPaused() { cg.updateScreen(); // Check if the pause text is there. return(cg.CompareColor(441, 268, new int[] { 187, 138, 79 }, 10)); }