示例#1
0
 def transferAllObjects(self, filter=None):
     if filter:
         Region(1354, 810, 44, 5).click()  # click on search region
         sleep(2)
         pyautogui.write(filter)
     Region(1248, 138, 34, 33).click()  # click transfer
     sleep(2)
     Region(1276, 178, 222, 23).click()  # click transfer visible
     dofus.INV_FIRST_SLOT_R.waitAppear(dofus.EMPTY_SLOT_INV_P)
示例#2
0
 def discharge(self):
     self.goToBank()
     self.openBank()
     Region(1469, 142, 29, 26).click()  # choose resources tab
     sleep(2)
     self.transferAllObjects()
     Region(1418, 146, 28, 15).click()  # choose consumable tab
     sleep(2)
     self.transferAllObjects("sac")
     Region(1526, 109, 52, 22).click()  # close
     sleep(1)
示例#3
0
 def goToZaap(self, zaap):
     print("moving to zaap: ", zaap['coords'])
     pyautogui.press(dofus.HAVRE_SAC_SHORTCUT)
     sleep(4)
     dofus.HAVRE_SAC_ZAAP_R.click()
     sleep(2)
     Region(1116, 230, 21, 14).click()
     pyautogui.write(zaap['name'])
     Region(910, 757, 105, 16).click()
     self.waitMapChange(*zaap['coords'], 60 * 15)
     if zaap['coords'] == (20, -29):
         Region(618, 729, 36, 24).click()
         sleep(4)
     return True
示例#4
0
文件: cell.py 项目: Me0w1ng/bot2pix
 def __init__(self, pgrid, x, y, i, j, ctype=dofus.ObjType.UNKNOWN):
     self.i = i
     self.j = j
     self.x = x
     self.y = y
     self.w = pgrid.cell_w
     self.h = pgrid.cell_h
     self.grid = pgrid
     self.extEllipse = (0.55, 0.6)
     self.type = ctype
     self.color = None
     self.rx, self.ry = self.x - self.grid.x(), self.y - self.grid.y()
     self.dotted = False
     self._r = Region(self.x - self.w / 2, self.y - self.h / 2, self.w,
                      self.h)
示例#5
0
 def goToBank(self):
     pyautogui.press(dofus.RAPPEL_POTION_SHORTCUT)
     sleep(2)
     self.updatePos()
     self.changeMap(dofus.RIGHT)
     sleep(2)
     Region(1067, 440, 25, 43).click()  # enter bank click
示例#6
0
def calculate_region_notstranded(self, dual_reader, region_file):
    calculated_region = Region()        
    readcount = 1
    for line in dual_reader:
        if not calculated_region: #first region only
            calculated_region = _region_from_dual(self, line)
            calculated_region.end += self.proximity
        else:
            new_region = _region_from_dual(self, line)
            new_region.end += self.proximity
            if calculated_region.overlap(new_region):
                calculated_region.join(new_region)
                readcount += 1
            else:
                calculated_region.end -= self.proximity
                __calc_reg_write(self, region_file, readcount, calculated_region)                 
                calculated_region = new_region.copy()
                readcount = 1

    if calculated_region:
        calculated_region.end -= self.proximity
        __calc_reg_write(self, region_file, readcount, calculated_region)                         
示例#7
0
def calculate_region_stranded(self, dual_reader, region_file):
    temp_region_file = open(self.sorted_region_path, 'wb')
    region_plus = Region()
    region_minus = Region()
    regions = []
    numreads_plus = 1
    numreads_minus = 1
    dual_reader = utils.DualSortedReader(self.current_experiment_path, self.current_control_path, self.experiment_format, self.logger)
    for line in dual_reader:
        new_region = _region_from_dual(self, line)
        new_region.end += self.proximity
        if not (region_plus and new_region.strand == PLUS_STRAND):
            region_plus = _region_from_dual(self, line)
           
        elif not (region_plus and new_region.strand == PLUS_STRAND):
            region_minus = _region_from_dual(self, line)

        else:
            if region_plus.overlap(new_region) and region_plus.strand == new_region.strand:
                region_plus.join(new_region)
                numreads_plus += 1
            elif region_minus.overlap(new_region) and region_minus.strand == new_region.strand:
                region_minus.join(new_region)
                numreads_minus += 1
            else:
                if new_region.strand == region_plus.strand:
                    region_plus.end -= self.proximity
                    self.__calc_reg_write(region_file, numreads_plus, region_plus)                      
                    region_plus = new_region.copy()  
                    numreads_plus = 1    
                else:
                    region_minus.end -= self.proximity
                    self.__calc_reg_write(region_file, numreads_minus, region_minus)         
                    region_minus = new_region.copy()  
                    numreads_minus = 1    

    if region_plus:
        region_plus.end -= self.proximity
        regions.append(region_plus)

    if region_minus:
        region_minus.end -= self.proximity
        regions.append(region_minus)

    regions.sort(key=lambda x:(x.name, x.start, x.end, x.strand))
    for region in regions:
        region_file.write(region.write())  
示例#8
0
文件: walker.py 项目: Me0w1ng/bot2pix
 def goToZaap(self, zapCoords):
     print("moving to zaap: ", zapCoords)
     pyautogui.press(dofus.HAVRE_SAC_SHORTCUT)
     sleep(2)
     dofus.HAVRE_SAC_ZAAP_R.click()
     sleep(2)
     while dofus.ZAAP_SCROLL_BAR_END_L.getpixel(
     ) != dofus.ZAAP_END_SCROLL_C:
         print(dofus.ZAAP_SCROLL_BAR_END_L.getpixel())
         for k in range(9):
             box_h = dofus.ZAAP_COORD_R.height() / 9
             box_y = dofus.ZAAP_COORD_R.y() + k * box_h
             box_x = dofus.ZAAP_COORD_R.x()
             box_w = dofus.ZAAP_COORD_R.width()
             box_r = Region(box_x, box_y, box_w, box_h)
             image = env.capture(box_r)
             gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
             low_bound = np.array([145, 0, 0])
             upper_bound = np.array([255, 255, 14])
             bgr_img = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
             mask = cv2.inRange(bgr_img, low_bound, upper_bound)
             result = cv2.bitwise_and(gray, gray, mask=mask)
             result = cv2.threshold(result, 0, 255,
                                    cv2.THRESH_BINARY_INV)[1]
             newShape = (int(box_w * 15), int(box_h * 15))
             result = cv2.resize(result, newShape)
             result = cv2.blur(result, (5, 5))
             text = pytesseract.image_to_string(result, config='--psm 6')
             res = re.findall("(-?\s*\d+),?(-?\s*\d+)", text)
             if res:
                 coord = tuple(
                     map(lambda x: int(x.replace(' ', '')), res[0]))
                 print(coord)
                 if coord == zapCoords:
                     box_r.click()
                     sleep(0.2)
                     box_r.click()
                     self.waitMapChange(*zapCoords, 60 * 15)
                     if zapCoords == (20, -29):
                         Region(618, 729, 36, 24).click()
                     return True
         dofus.ZAAP_COORD_R.scroll(clicks=-3, delay_between_ticks=0.1)
         dofus.OUT_OF_COMBAT_R.hover()
         sleep(0.5)
     raise Exception("Zaap coords not found!")
示例#9
0
文件: zone.py 项目: Me0w1ng/bot2pix
 def loadFromFile(self, filepath, patternsDir):
     with open(filepath, 'r') as f:
         data = yaml.load(f, Loader=yaml.FullLoader)
         self.name = data['name']
         for dmap in data['maps']:
             nmap = Map(self, dmap['x'], dmap['y'])
             nmap['nbrseen'] = dmap['nbrseen']
             nmap['excludedMaps'] = dmap['excludedMaps']
             nmap['excludedSpots'] = dmap['excludedSpots']
             for spot in dmap['spots']:
                 pattern_path = os.path.join(patternsDir, spot['kind'],
                                             spot['patternId'])
                 if os.path.exists(pattern_path):
                     nmap['spots'].append({
                         'region':
                         Region(*spot['region']),
                         'pattern':
                         Pattern(spot['kind'], pattern_path,
                                 spot['patternId'])
                     })
             self[(dmap['x'], dmap['y'])] = nmap
示例#10
0
文件: walker.py 项目: Me0w1ng/bot2pix
 def discharge(self):
     pyautogui.press(dofus.RAPPEL_POTION_SHORTCUT)
     sleep(2)
     self.updatePos()
     self.changeMap(dofus.RIGHT)
     sleep(2)
     Region(1067, 440, 25, 43).click()  # enter bank click
     dofus.BANK_MAN_R.waitAppear(dofus.BANK_MAN_P)
     dofus.BANK_MAN_R.click()  # click on bank man
     dofus.BANK_MAN_TALK_R.waitAppear(dofus.BANK_MAN_TALK_P)
     Region(771, 737, 272, 40).click()  # click first choice
     dofus.INV_OPEN_R.waitAppear(dofus.INVENTAIRE_P)
     Region(1469, 142, 29, 26).click()  # choose resources tab
     sleep(2)
     self.transferAllObjects()
     Region(1418, 146, 28, 15).click()  # choose consumable tab
     sleep(2)
     Region(1354, 810, 44, 5).click()  # click on search region
     sleep(2)
     pyautogui.write("sac")
     self.transferAllObjects()
     Region(1526, 109, 52, 22).click()  # close
     sleep(1)
示例#11
0
import random
import threading
from time import sleep
import cv2
from core import utils
from core.bot import Fighter
from core import env, Region

env.focusDofusWindow()

rcenter = Region(1185, 466, 80, 71)
rup = Region(1066, 538, 34, 19)
rout = Region(1126, 264, 41, 40)

resource_r = Region(1166, 338, 127, 118)

spots = [
    Region(1166, 339, 40, 73),
    Region(1215, 362, 32, 67),
    Region(1255, 385, 38, 64)
]

empty_spot_ptrn = [
    cv2.imread(f"empty_spot{idx}.png", cv2.IMREAD_GRAYSCALE)
    for idx in range(3)
]

am = {"range": 2, "nbr": 2, "shortcut": "r"}


class AntiSaveScreen(threading.Thread):
示例#12
0
from core.bot import Walker
from core import Region
from time import sleep
import pyautogui
from core import dofus, env

env.focusDofusWindow()
work_dir = os.path.dirname(os.path.abspath(__file__))

bot = Walker(work_dir, "John shooter")
bot.mapChangeTimeOut = 60

for k in range(5):
    bot.goToBank()
    bot.openBank()
    Region(1469, 142, 29, 26).click()  # choose resources tab
    sleep(2)
    bot.transferAllObjects()

    Region(382, 802, 30, 22).click() # craftable
    sleep(1)

    Region(1137,299,19,15).click() #first
    sleep(2)

    pyautogui.write("57") #quantity
    sleep(1)

    Region(1253,250,45,20).click() #ok
    sleep(2)
示例#13
0
文件: walker.py 项目: Me0w1ng/bot2pix
 def transferAllObjects(self):
     Region(1248, 138, 34, 33).click()  # click transfer
     sleep(2)
     Region(1276, 178, 222, 23).click()  # click transfer visible
     dofus.INV_FIRST_SLOT_R.waitAppear(dofus.EMPTY_SLOT_INV_P)
示例#14
0
文件: cell.py 项目: Me0w1ng/bot2pix
class Cell:
    def __init__(self, pgrid, x, y, i, j, ctype=dofus.ObjType.UNKNOWN):
        self.i = i
        self.j = j
        self.x = x
        self.y = y
        self.w = pgrid.cell_w
        self.h = pgrid.cell_h
        self.grid = pgrid
        self.extEllipse = (0.55, 0.6)
        self.type = ctype
        self.color = None
        self.rx, self.ry = self.x - self.grid.x(), self.y - self.grid.y()
        self.dotted = False
        self._r = Region(self.x - self.w / 2, self.y - self.h / 2, self.w,
                         self.h)

    def getpixel(self, x, y, from_grid=True):
        rx = x - self.grid.x()
        ry = y - self.grid.y()
        if from_grid:
            return self.grid.getpixel(rx, ry)
        else:
            return self._r.getpixel(x - self._r.x(), y - self._r.y())

    def parse(self, from_grid=True):
        hist = {}
        max_key = (0, 0, 0)
        max_val = 0.

        if not from_grid:
            self._r.capture()

        for x, y in self.iterTopCorner():
            rgb = self.getpixel(x, y, from_grid)
            if rgb not in hist:
                hist[rgb] = 0
            hist[rgb] += 1
            if hist[rgb] > max_val:
                max_val = hist[rgb]
                max_key = rgb
            if max_val > 5:
                break

        color = QColor(*max_key)
        self.color = color
        self.type = dofus.findObject(color)

        return self.type

    def iterTopCorner(self):
        a = 0.4
        b = 0.5
        c = 0.7
        ox = self.x
        oy = self.y - (self.h / 4) * (b + c)
        w = a * self.w / 2
        h = b * self.h / 2
        return iterParallelogram(ox, oy, w, h)

    def highlight(self, secs, mode=CellOverlay.VizMode.Border):
        app = QApplication(sys.argv)
        overlay = CellOverlay(self)
        overlay.highlight(secs, mode)
        sys.exit(app.exec_())

    def highlightTopCorner(self, secs):
        # sys.excepthook = except_hook
        app = QApplication(sys.argv)
        top_corner_it = self.iterTopCorner()
        overlay = CellOverlay(self)
        overlay.highlight(secs,
                          mode=CellOverlay.VizMode.Shape,
                          shape=top_corner_it)
        sys.exit(app.exec_())

    def click(self):
        self._r.click()

    def hover(self):
        self._r.hover()

    def nearBy(self, w, h):
        return self._r.nearBy(w, h)

    def neighbors(self):
        if self.i % 2 == 0:
            vicinity = [(-1, 0), (1, -1), (1, 0), (-1, -1)]
        else:
            vicinity = [(-1, 1), (-1, 0), (1, 0), (1, 1)]
        for di, dj in vicinity:
            if self.grid.inside(self.i + di, self.j + dj):
                yield self.grid[self.i + di][self.j + dj]

    def inLDV(self, tgt, po):
        return self.grid.inLDV(self, tgt, po)

    def occupied(self):
        return self.type != dofus.ObjType.FREE and self.type != dofus.ObjType.REACHABLE

    def waitAppear(self, kind, timeout=3):
        start = perf_counter()
        while perf_counter() - start < timeout:
            self.parse(from_grid=False)
            if self.type == kind:
                return True
        return False

    def waitAnimation(self, timeout=3):
        return self._r.waitAnimationEnd(timeout)

    def reachable(self):
        return self.type == dofus.ObjType.REACHABLE

    def opaque(self):
        return self.type == dofus.ObjType.OBSTACLE or \
               self.type == dofus.ObjType.MOB or \
               self.type == dofus.ObjType.INVOKE

    def indexes(self):
        return self.i, self.j
示例#15
0
文件: dofus.py 项目: Me0w1ng/bot2pix
import os
import cv2
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QColor
from core import Region, Location

patterns_dir = r"C:\Users\khalid.majdoub\PycharmProjects\bot2pix\src\patterns"


def loadPattern(name):
    return cv2.imread(os.path.join(patterns_dir, name))


RESIGN_POPUP_R = Region(698, 442, 533, 173)
DEFEAT_POPUP_R = Region(762, 696, 415, 141)
COMBAT_R = Region(335, 29, 1253, 885)
MINIMAP_R = Region(62, 876, 190, 122)
PM_R = Region(793, 993, 27, 34)
PA_R = Region(729, 983, 55, 42)
COMBAT_ENDED_POPUP_R = Region(841, 701, 244, 66)
READY_R = Region(1312, 925, 145, 66)
COMBAT_ENDED_POPUP_CLOSE_R = Region(1231, 721, 22, 18)
MY_TURN_CHECK_R = Region(841, 1009, 17, 8)
OUT_OF_COMBAT_R = Region(104, 749, 37, 37)
CREATURE_MODE_R = Region(1339, 993, 27, 25)
MAP_COORDS_R = Region(0, 28, 298, 98)
CONNECT_R = Region(666, 88, 572, 531)
RECONNECT_BUTTON_R = Region(880, 381, 161, 57)
PLAY_GAME_BUTTON_R = Region(993, 652, 452, 260)
BANK_MAN_R = Region(935, 465, 121, 126)
BANK_MAN_TALK_R = Region(465, 601, 999, 236)
示例#16
0
 def openBank():
     dofus.BANK_MAN_R.waitAppear(dofus.BANK_MAN_P)
     dofus.BANK_MAN_R.click()  # click on bank man
     dofus.BANK_MAN_TALK_R.waitAppear(dofus.BANK_MAN_TALK_P)
     Region(771, 737, 272, 40).click()  # click first choice
     dofus.INV_OPEN_R.waitAppear(dofus.INVENTAIRE_P)