F
F
fife2021-02-28 18:30:07
Java
fife, 2021-02-28 18:30:07

Can the robot not have time to complete its actions, and move on to the next task?

Hello, I am writing a bot for the game, for this I create three threads, one reads the log (messages that the bot must process come there), the second processes the message (decides what to do) and puts it in the queue, and the third takes the processed message from the queue, and starts its execution, and along the way, other tasks are added to the queue.
In the third thread, I actively use the Robot class to set the cursor to the desired coordinates and perform actions.

public static void dropToStashFromInventory(){
        try {
            closeAllWindows();//закрывает открытые окна в игре
            Robot robot = new Robot();

            robot.mouseMove(977, 486); //открывает сундук
            robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
            robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
            //x=1316, y=588 1 inventory slot
            for (int i = 0;i<12;i++){//тут бежит по всем слотам инвентаря 12х5
                robot.mouseMove(1316 + (50 *i), 578);
                for (int j = 0; j<5;j++){
                    robot.mouseMove(1316 + (50 * i), 578 + (50 * j));
                    robot.keyPress(KeyEvent.VK_CONTROL);//зажимая control и кликая на слот
                    robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
                    robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
                    robot.keyRelease(KeyEvent.VK_CONTROL);
                }
            }
        } catch (AWTException e) {
            e.printStackTrace();
        }
    }


The fact is that sometimes before moving on to the next inventory cell, he does not have time to release control, and it turns out that instead of quickly dropping into the chest (with control), he takes the item under the cursor, of course, this breaks the logic of the bot.

How do I fix this / what alternatives can I use?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Cheypnow, 2021-02-28
@fife

As an option, use the method waitForIdle()or set a delay for some time to wait until the desired logic has worked.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question