コード例 #1
0
ファイル: gameobjects.py プロジェクト: balrok/pythonstuff
class LootWindow(ItemWindow):
    type="loot"
    def __init__(self, window, constants):
        ItemWindow.__init__(self, window, constants)
        self.bottom_right = autopy.bitmap.Bitmap.open(os.path.join('img', 'loot_bottom_right.png'))
        # to speed up detection use a 1x1 pixel to detect if loot is available
        self.singlePixel = SubWindow(self.window, constants['lootWindowOpen'][0], constants['lootWindowOpen'][1], 1, 1)
        self.lootColor = constants['lootColor']
        self.lootItems = []
        for i in constants['lootItems']:
            bmp =  autopy.bitmap.Bitmap.open(os.path.join('img', 'items', i+'_rescale.png'))
            self.lootItems.append(bmp)

    def hasLoot(self):
        self.singlePixel.getScreenShot()
        if self.singlePixel.getPixel(0,0) == self.lootColor:
            self.window.getScreenShot()
            coord = self.window.current_screen.find_bitmap(self.bottom_right, 0.1, None, 0)
            return coord is not None

    def getLootPositions(self):
        coords = []
        for item in self.lootItems:
            coord = self.window.current_screen.find_bitmap(item, 0.1, None, 0)
            if coord is not None:
                coords.append(coord)
        return coords
コード例 #2
0
ファイル: gameobjects.py プロジェクト: balrok/pythonstuff
class Bar(WindowObject):
    type='default'
    bgcolor=''
    barcolor=''
    width=0

    def __init__(self, window, constants):
        if not self.type+"bar" in constants:
            constants[self.type+'bar'] = self.findWindow(window, constants[self.type+"barColor"])
        x1, y1, x2, y2 = constants[self.type+'bar']
        self.window = SubWindow(window, x1, y1, abs(y1-y2), abs(x1-x2))
        WindowObject.__init__(self, self.window, window)
        self.bgcolor = constants['barBGColor']
        self.barcolor = constants[self.type+"barColor"]
        self.width=abs(y1-y2)

    def findWindow(self, window, color):
        x1,y1,x2,y2 = findColorArea(window, color, 1)
        return (x1,y1,x2,y2)

    def getPercentFull(self):
        # scan for bgcolor
        self.window.getScreenShot()
        x,y = findColor(self.window, self.bgcolor)
        if y>-1:
            x2,y2 = findColor(self.window, self.barcolor)
            # when hovering over items in a trade it will cover the bar
            # which causes to first display background and then healthbar
            if y2==0:
                return float(y)/self.width*100
            # we found bg - so not 100 full
        return 100
コード例 #3
0
ファイル: gameobjects.py プロジェクト: balrok/pythonstuff
class Pot(WindowObject):
    type='default'
    window=None
    moneyColor=''
    def __init__(self, window, constants):
        self.moneyColor = constants['moneyColor']
        x1, y1 = constants[self.type+'potMoney']
        self.window = SubWindow(window, x1, y1, 1, 1)
        WindowObject.__init__(self, self.window, window)

    def hasPot(self):
        self.window.getScreenShot()
        return self.window.getPixel(0,0) != self.moneyColor
コード例 #4
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