简体   繁体   中英

Trying to fix a script for a game I play (Wizard101 Auto Farming)

I've been trying to tailor this code to work for my desktop so I can auto-farm some enemies in this game I play. Right now the code is stuck at a point where it scans the UI at a certain pixel for a certain shade of blue. if it's the correct shade, the code progresses. if not, it completely stops. I'm not sure what to do but if someone could take a look I'd greatly appreciate it. Here are some screenshots and the code:

Also, the code is broken into two pieces: the first script which allows for interaction with the game, and the second being programming automatic movement, clicking etcetera. the second piece is simple enough where it doesn't need to be put here, nor is it necessary.

First Piece (main problem is in the POSITION and COLOR part of def is_mana_low:

def is_mana_low(self):
        self.set_active()
        # Matches a pixel in the lower third of the mana globe
        POSITION = (79, 565)
        COLOR = (66, 13, 83)
        THRESHOLD = 10
        return not self.pixel_matches_color(POSITION, COLOR, threshold=THRESHOLD)

    def use_potion_if_needed(self):
        mana_low = self.is_mana_low()
        health_low = self.is_health_low()

        if mana_low:
            print('Mana is low, using potion')
        if health_low:
            print('Health is low, using potion')
        if mana_low or health_low:
            self.click(160, 590, delay=.2)

My Discord is APieceofString#5151 if you wanted to hit me up for more information or a better explanation. I really appreciate this :)

I had the same issue when setting it to a specific x,y coordinate. So here's how I resolved this:

I used pyautogui and cv2. I got a screen cap, and then created a fairly thin rectangle, right below where the yellow number showing your remaining mana is, and going from the edge of the Energy globe to the edge of the mana globe. And then while my script is running, it checks for a match of that rectangle. If there's a match, you have plenty of mana, if not, you may want to drink a potion.

I tried to do the same thing to check for mana wisps, and if it sees one on the screen, run to the wisp, and then back to the home position (but that function is kind of hinky atm and I'm trying to get it working better).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM