コード例 #1
0
ファイル: whack.py プロジェクト: balrok/pythonstuff
def main():
    w = Window()
    start = time.time()
    while True:
        print "search game area"
        w.getScreenShot()
        w.current_screen.save("test.png")
        gameWin = findGameArea(w)
        if gameWin is not None:
            print "found area"
            break
    gameWin.getScreenShot()
    gameWin.current_screen.save("whack1.png", "png")
    whack = Whack(gameWin)
    area = whack.getArea()
    area.getScreenShot()
    area.current_screen.save("whack2.png", "png")
    i=0
    while True:
        if whack.hasArea():
            break
        time.sleep(0.3)
    ignoreUntilNextClick = (9999,9999)
    resetIgnore = 0
    while True:
        if resetIgnore < time.time():
            print "reset",resetIgnore, time.time()
            resetIgnore = time.time() + 100
            ignoreUntilNextClick = (9999,9999)
        i+=1
        print i
        print "search button"
        coords = whack.findClicks(i)
        if len(coords) < 1:
            continue
        if len(coords) > 7:
            return
        c=0
        last = (9999, 9999)
        for coord in coords:
            c+=1
            y,x = coord
            print "coord",coord
            if y > ignoreUntilNextClick[0] - 90 and y < ignoreUntilNextClick[0] + 90 and x == ignoreUntilNextClick[1]:
                print "ignore", ignoreUntilNextClick
                continue
            #tmp = SubWindow(area, x-10, y-10, 30, 30)
            #tmp.getScreenShot()
            #tmp.current_screen.save("click"+str(i)+str(c)+".png")
            area.mouseMove(x, y)
            area.mouseClick()
            gameWin.mouseMove(10, 10)
            last = coord
        if last[0] != 9999:
            print "last",last
            ignoreUntilNextClick = last
            resetIgnore = time.time() + 0.6
    print time.time()-start
コード例 #2
0
ファイル: run.py プロジェクト: balrok/pythonstuff
def main():
    w = Window()
    while True:
        print "search game area"
        w.getScreenShot()
        gameWin = findGameArea(w)
        if gameWin is not None:
            print "found area"
            break
    gameWin.getScreenShot()
    gameWin.current_screen.save("game1.png", "png")
    healthbar = HealthBar(gameWin, constants)
    healthbar.saveScreenshot('health')

    healthpot = HealthPot(gameWin, constants)
    healthpot.saveScreenshot('healthpotmoney')
    manapot = ManaPot(gameWin, constants)
    manapot.saveScreenshot('manapotmoney')

    inventory = InventoryWindow(gameWin, constants)
    inventory.saveScreenshot('inventory')
    loot = LootWindow(gameWin, constants)
    loot.saveScreenshot('loot')

    if not healthpot.hasPot():
        print "no health pots"
    if not manapot.hasPot():
        print "no mana pots"

    i=0
    checknextHealth = 0
    checknextLoot = 9999990
    nextSpell = 0
    healthHistory = []
    while True:
        time.sleep(0.05)
        i+=1
        print i
        if i > checknextLoot:
            if loot.hasLoot():
                coords = loot.getLootPositions()
                loot.saveScreenshot('loot%d'%i)
                if coords != []:
                    x, y = autopy.mouse.get_pos()
                    for coord in coords:
                        print "foundloot"
                        loot.window.mouseMove(coord[0], coord[1])
                        loot.window.mouseClick()
                        loot.window.mouseClick()
                    autopy.mouse.move(x, y)
            checknextLoot = i+80
        if i > checknextHealth:
            full = healthbar.getPercentFull()
            if full < 50:
                #healthbar.saveScreenshot("bartakepot%d"% i)
                print "50% health lost"
                # can take pot, when has at least one
                canTakePot = healthpot.hasPot()
                # can take pot, when not in last 40*0.05=2seconds two pots were taken
                if len(healthHistory) > 1 and healthHistory[-2] > i-40:
                    canTakePot = False
                # can take pot, when more than 25%
                if full>25 and canTakePot:
                    checknextHealth = i+10
                    #healthpot.saveScreenshot("takepot%d"% i)
                    healthbar.saveScreenshot("bartakepot%d"% i)
                    print "send f"
                    autopy.key.tap('f')
                    healthHistory.append(i)

                else:
                    checknextHealth = i+200
                    # no healthpot left - going home
                    print "send g"
                    autopy.key.tap('g')
            elif full < 80:
                if nextSpell < i:
                    autopy.key.tap(' ')
                    print "space"
                    nextSpell=i+20
コード例 #3
0
ファイル: run.py プロジェクト: balrok/pythonstuff
def main():
    w = Window()
    start = time.time()
    while True:
        print "search game area"
        w.getScreenShot()
        w.current_screen.save("test.png")
        gameWin = findGameArea(w)
        if gameWin is not None:
            print "found area"
            break
    gameWin.getScreenShot()
    gameWin.current_screen.save("game1.png", "png")
    but = Button(gameWin)
    but.getBgArea()
    but.findShopAndRepair()
    i=0
    broken = 0
    while True:
        time.sleep(0.02)
        i+=1
        #if i==200:
        #    break
        if but.isBroken():
            broken += 1
            if broken == 5:
                broken = 0
                print "BROKEN"
                x = but.repairButton[0]
                y = but.repairButton[1]
                gameWin.mouseMove(x, y)
                gameWin.mouseClick()
                #break
        else:
            broken = 0
        print "search button"
        gameWin.getScreenShot()
        x,y = but.findCenter()
        butWin = SubWindow(gameWin, x-5, y-5, 15, 15)
        butWin.getScreenShot()
        butWin.current_screen.save("butwin.png", "png")
        print x, y
        print but.width
        print but.height
        if but.width < 10 or but.height < 10: # not found
            continue
        print (x,y)
        gameWin.mouseMove(x, y)
        gameWin.mouseClick()

        #x1,y1,x2,y2 = but.area
        #butWin = SubWindow(gameWin, x1, y1, abs(x1-x2), abs(y1-y2))
        #butWin.getScreenShot()
        #butWin.current_screen.save("button%d.png"%i, "png")
        #time.sleep(0.2)
        #if time.time()-start > 60:
        #    sys.exit()

        print but

        #print but
        #if but[0] > -1:
        #    mouse.move(left+but[0], top+but[1])
    print time.time()-start