Exemplo n.º 1
0
        bool EditAI(int slot, AIHero?setToHero, Difficulty?setToDifficulty, bool x)
        {
            if (!CustomGame.IsSlotValid(slot))
            {
                throw new InvalidSlotException(slot);
            }

            // Make sure there is a player or AI in selected slot, or if they are a valid slot to select in queue.
            if (cg.PlayerSlots.Contains(slot) || (slot >= CustomGame.Queueid && slot - (CustomGame.Queueid) < cg.QueueCount))
            {
                // Click the slot of the selected slot.
                var slotlocation = cg.Interact.FindSlotLocation(slot);
                cg.LeftClick(slotlocation.X, slotlocation.Y);
                // Check if Edit AI window has opened by checking if the confirm button exists.
                cg.updateScreen();
                if (cg.CompareColor(Points.EDIT_AI_CONFIRM, Colors.CONFIRM, 20))
                {
                    var sim = new List <Keys>();
                    // Set hero if setToHero does not equal null.
                    if (setToHero != null)
                    {
                        // Open hero menu
                        sim.Add(Keys.Space);
                        // <image url="$(ProjectDir)\ImageComments\AI.cs\EditAIHero.png" scale="0.5" />
                        // Select the topmost hero option
                        for (int i = 0; i < Enum.GetNames(typeof(AIHero)).Length; i++)
                        {
                            sim.Add(Keys.Up);
                        }
                        // Select the hero in selectHero.
                        for (int i = 0; i < (int)setToHero; i++)
                        {
                            sim.Add(Keys.Down);
                        }
                        sim.Add(Keys.Space);
                    }
                    sim.Add(Keys.Down); // Select difficulty option
                                        // Set difficulty if setToDifficulty does not equal null.
                    if (setToDifficulty != null)
                    {
                        // Open difficulty menu
                        sim.Add(Keys.Space);
                        // <image url="$(ProjectDir)\ImageComments\AI.cs\EditAIDifficulty.png" scale="0.6" />
                        // Select the topmost difficulty
                        for (int i = 0; i < Enum.GetNames(typeof(Difficulty)).Length; i++)
                        {
                            sim.Add(Keys.Up);
                        }
                        // Select the difficulty in selectDifficulty.
                        for (int i = 0; i < (int)setToDifficulty; i++)
                        {
                            sim.Add(Keys.Down);
                        }
                        sim.Add(Keys.Space);
                    }
                    // Confirm the changes
                    sim.Add(Keys.Return);

                    // Send the keypresses.
                    cg.KeyPress(sim.ToArray());

                    cg.ResetMouse();
                    return(true);
                }
                else
                {
                    cg.ResetMouse();
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 2
0
 internal LockHandler(CustomGame cg)
 {
     this.cg = cg;
 }
Exemplo n.º 3
0
 internal AI(CustomGame cg) : base(cg)
 {
 }
Exemplo n.º 4
0
        /// <summary>
        /// Checks if the input slot is an AI.
        /// </summary>
        /// <param name="slot">Slot to check.</param>
        /// <param name="noUpdate">Determines if the captured screen should be updated before scanning.</param>
        /// <returns>Returns true if slot is AI.</returns>
        /// <include file='docs.xml' path='doc/exceptions/invalidslot/exception'/>
        public bool IsAI(int slot, bool noUpdate = false)
        {
            // Look for the commendation icon for the slot chosen.

            // If the slot is not valid, throw an exception.
            if (!CustomGame.IsSlotValid(slot))
            {
                throw new InvalidSlotException(slot);
            }

            if (CustomGame.IsSlotSpectator(slot) || // Since AI cannot join spectator, return false if the slot is a spectator slot.
                !cg.TotalPlayerSlots.Contains(slot))    // Return false if the slot is empty.
            {
                return(false);
            }

            // The chat covers blue slot 5. Close the chat so the scanning will work accurately.
            if (slot == 5)
            {
                cg.Chat.CloseChat();
            }

            if (!noUpdate)
            {
                cg.updateScreen();
            }

            int[] checkY       = new int[0]; // The potential Y locations of the commendation icon
            int   checkX       = 0;          // Where to start scanning on the X axis for the commendation icon
            int   checkXLength = 0;          // How many pixels to scan on the X axis for the commendation icon

            if (CustomGame.IsSlotBlue(slot) || CustomGame.IsSlotRed(slot))
            {
                int checkslot = slot;
                if (CustomGame.IsSlotRed(checkslot))
                {
                    checkslot -= 6;
                }

                // Find the potential Y locations of the commendation icon.
                // 248 is the Y location of the first commendation icon of the player in the first slot of red and blue. 28 is how many pixels it is to the next commendation icon on the next slot.
                int y1 = 248 + (checkslot * 28),
                    y2 = y1 + 9; // The second potential Y location is 9 pixels under the first potential spot.
                checkY = new int[] { y1, y2 };

                if (CustomGame.IsSlotBlue(slot))
                {
                    checkX = 74; // The start of the blue slots on the X axis
                }
                else if (CustomGame.IsSlotRed(slot))
                {
                    checkX = 399;   // The start of the red slots on the X axis
                }
                checkXLength = 195; // The length of the slots.
            }
            else if (CustomGame.IsSlotInQueue(slot))
            {
                int checkslot = slot - CustomGame.Queueid;

                // 245 is the Y location of the first commendation icon of the player in the first slot in queue. 14 is how many pixels it is to the next commendation icon on the next slot.
                int y = 245 + (checkslot * 14);
                checkY = new int[] { y };

                checkX       = 707; // The start of the queue slots on this X axis
                checkXLength = 163; // The length of the queue slots.
            }

            bool isAi = true;

            for (int x = checkX; x < checkX + checkXLength; x++)
            {
                for (int yi = 0; yi < checkY.Length; yi++)
                {
                    int y = checkY[yi];
                    // Check for the commendation icon.
                    if (cg.CompareColor(x, y, new int[] { 85, 140, 140 }, new int[] { 115, 175, 175 }))
                    {
                        isAi = false;
                        break;
                    }
                }
            }

            if (slot == 5 && cg.OpenChatIsDefault)
            {
                cg.Chat.OpenChat();
            }

            return(isAi);
        }
Exemplo n.º 5
0
 internal Pause(CustomGame cg) : base(cg)
 {
 }
Exemplo n.º 6
0
        /// <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 the if the difficulty is found. Returns null if the input slot is not an AI.</returns>
        /// <include file='docs.xml' path='doc/exceptions/invalidslot/exception'/>
        public Difficulty?GetAIDifficulty(int slot, bool noUpdate = false)
        {
            if (!CustomGame.IsSlotValid(slot))
            {
                throw new InvalidSlotException(slot);
            }

            if (slot == 5 && cg.OpenChatIsDefault)
            {
                cg.Chat.CloseChat();
            }

            if (!noUpdate)
            {
                cg.updateScreen();
            }

            if (CustomGame.IsSlotBlue(slot) || CustomGame.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], Colors.WHITE, 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();
                            }

                            // 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), Colors.WHITE, 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 - CustomGame.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);
            }
        }
Exemplo n.º 7
0
 internal abstract void Navigate(CustomGame cg);
 internal CG_PlayerInfo(CustomGame cg)
 {
     this.cg = cg;
 }
 internal CG_Chat(CustomGame cg)
 {
     this.cg = cg;
 }
Exemplo n.º 10
0
        internal void SetSettings(CustomGame cg)
        {
            Navigate(cg);

            object[] values = this.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance).Select(v => v.GetValue(this)).ToArray();

            int waitTime = 10;

            for (int i = 0; i < values.Length; i++)
            {
                if (values[i] != null)
                {
                    if (values[i] is bool)
                    {
                        bool option = (bool)values[i];
                        bool value  = (bool)cg.GetHighlightedSettingValue(true);
                        if (option != value)
                        {
                            cg.KeyPress(Keys.Space);
                            Thread.Sleep(waitTime);
                        }
                    }
                    else if (values[i] is int)
                    {
                        var set = cg.GetNumberKeys((int)values[i]);

                        for (int k = 0; k < set.Length; k++)
                        {
                            cg.KeyDown(set[k]);
                            Thread.Sleep(waitTime);
                        }
                        cg.KeyDown(Keys.Enter);
                        Thread.Sleep(waitTime);
                    }
                    else if (values[i] is Enum)
                    {
                        int set    = (int)values[i];
                        int length = Enum.GetNames(values[i].GetType()).Length;

                        cg.KeyPress(Keys.Space);
                        Thread.Sleep(waitTime);
                        for (int a = 0; a < length; a++)
                        {
                            cg.KeyPress(Keys.Up);
                            Thread.Sleep(waitTime);
                        }
                        for (int a = 0; a < set; a++)
                        {
                            cg.KeyPress(Keys.Down);
                            Thread.Sleep(waitTime);
                        }
                        cg.KeyPress(Keys.Space);
                        Thread.Sleep(waitTime);
                    }
                }

                cg.KeyPress(Keys.Down);
                Thread.Sleep(waitTime);
            }

            Return(cg);
        }
Exemplo n.º 11
0
 internal Interact(CustomGame cg) : base(cg)
 {
 }
 internal CG_Maps(CustomGame cg)
 {
     this.cg = cg;
 }
Exemplo n.º 13
0
 internal Chat(CustomGame cg) : base(cg)
 {
 }
Exemplo n.º 14
0
 internal CG_AI(CustomGame cg)
 {
     this.cg = cg;
 }
Exemplo n.º 15
0
 internal abstract void Return(CustomGame cg);
Exemplo n.º 16
0
 public DebugMenu(CustomGame cg)
 {
     this.cg = cg;
     InitializeComponent();
     ResetDebugImage();
 }
Exemplo n.º 17
0
 internal Settings(CustomGame cg) : base(cg)
 {
 }
Exemplo n.º 18
0
 internal override void Return(CustomGame cg)
 {
     cg.GoBack(3, 0);
 }
Exemplo n.º 19
0
 internal CG_Pause(CustomGame cg)
 {
     this.cg = cg;
 }