def __init__(self): self.config = Config() self.config.enable() self.roundFrequency = 30 self.window = Window() self.roundStart = self.window.center() self.rountEnd = self.roundStart[0] + 100, self.roundStart[1]
def go_to_dungeon(self, party): if party: d = Detector(config.OkButton.path, Window()).detect() x, y, w, h = d x, y = Window().relative((x, y)) Rect((x, y, w, h)).click().make_click() Click(x, y).make_click() Navigator.touch_npc(config.DungeonNpc) Wait(1).delay() HandleNpc().select_menu(config.CircusDungeonMenu) Wait(1).delay() x, y, w, h = config.StarIcon.roi x, y = Window().relative((x, y)) Wait(1).delay() Detector(config.StarIcon.menu, Window()).detect() Rect((x, y, w, h)).click().make_click() npc = get_npc(config.CircusNpc) Navigator.click_at_npc(npc, config.CircusNpc) Wait(1).delay() npc_menu = HandleNpc().select_menu(config.CircusNpcMenu, quality='threshold') if not npc_menu: return None Wait(1).delay() npc_menu = HandleNpc().select_menu(config.FirstCircus) return npc_menu
def menu_region_recognize(): window = Window() center = window.center() @timerfunc def recognize(): region = (int(center[0]), int(center[1]), int(window.width / 2), int(window.height / 2)) Recognizer(__asset_path(buff_config, 'menu'), region).recognize() recognize()
def select_menu(self, config, quality='minmax'): Wait(DELAY).delay() e = Extruder(screenshot(Window().rect)) template = cv2.imread(config.path) menu = e.match_by_template(template, roi=config.roi, method=quality) if not menu: return None point = Rect(menu).center() x, y = Window().relative(point) Click(x, y).make_click() return x, y
def __init__(self, actions, timings): self.action_params = actions self.frequences = timings self.config = Config() self.config.enable() self.roundFrequency = 10 self.generate_actions() self.init_skills_state() self.init_actions_time() print(self.actions, self.action_params, timings) self.window = Window() self.roundStart = self.window.center() self.rountEnd = self.roundStart[0] + 100, self.roundStart[1]
def draw_corners(times=10): window = Window() rx, ry, w, h = StartPointConfig.roi for i in range(times): # image = cv2.imread('assets/data/after_turn_around/' + str(i) + '.png') image = np.array(screenshot(window.rect)) e = Extruder(image) roi = e.threshold(StartPointConfig) show_image(roi) roi = e.clear(roi) corners = e.corners(roi) # if corners is not None: # # search start point # plain_corners = [c.ravel() for c in corners] # plain_corners.sort(key = lambda x: x[0], reverse=True) # right = plain_corners[0] # plain_corners.sort(key = lambda x: x[1], reverse=True) # bottom = plain_corners[0] # print(right, bottom) # # for c in corners: # # x,y = c.ravel() # # print(x,y) # # image = cv2.circle(image, (rx+x,ry+y), 3, 255, -1) # cv2.circle(image, (window.x + rx + right[0], window.y + ry + right[1]), 3, 150, -1) from shapes.rect import Rect cx, cy = Rect(StartPointConfig.roi).center() Click(window.x + cx, window.y + cy).make_click()
class CircusHandler: def __init__(self): self.window = Window() def get_quest(self): obs = Observer(observe_angle, observe_height) obs.observe() Navigator.touch_npc(config.CharTitleConfig) HandleNpc().select_menu(config.QuestMenu) Wait(0.3).delay() HandleNpc().select_menu(config.AcceptQuest) Wait(0.3).delay() Navigator.turn_around() Wait(0.3).delay() center = Rect(config.StartPointConfig.roi).center() x, y = self.window.relative(center) Click(x, y).make_click() Wait(3).delay() def go_to_dungeon(self, party): if party: d = Detector(config.OkButton.path, Window()).detect() x, y, w, h = d x, y = Window().relative((x, y)) Rect((x, y, w, h)).click().make_click() Click(x, y).make_click() Navigator.touch_npc(config.DungeonNpc) Wait(1).delay() HandleNpc().select_menu(config.CircusDungeonMenu) Wait(1).delay() x, y, w, h = config.StarIcon.roi x, y = Window().relative((x, y)) Wait(1).delay() Detector(config.StarIcon.menu, Window()).detect() Rect((x, y, w, h)).click().make_click() npc = get_npc(config.CircusNpc) Navigator.click_at_npc(npc, config.CircusNpc) Wait(1).delay() npc_menu = HandleNpc().select_menu(config.CircusNpcMenu, quality='threshold') if not npc_menu: return None Wait(1).delay() npc_menu = HandleNpc().select_menu(config.FirstCircus) return npc_menu
def move_to_npc(times=10, imagepath='assets/data/npc_extruded_by_char_color/'): template = cv2.imread(TEMPLATE) window = Window() for i in range(times): image = u.screenshot(region=window.rect) extruded = Extruder(image) title_roi = extruded.match_by_template( template, image=extruded.filtredImgByColor(CharTitleConfig)) print(title_roi) Navigator.move_to_npc(title_roi)
def _go_to_selector(self): mode = self._setup_buff_mode() if mode: wx, wy = Window().center() Wait(0.5).delay() Click(wx, wy).make_click() dx, dy = self.config['markers']['confirm_logout_point'] dx, dy = wx + int(dx), wy + int(dy) Wait(1).delay() Click(dx, dy).make_click() return Recognizer(self.selector, None).recognize()
def get_tempalate_roi(config, image=None): rect = Window().rect if not image: image = screenshot(rect) extruder = Extruder(image) # roi = extruder.get_template_rect(config) # import cv2 # from utils.cv2_utils import show_image # import numpy as np # rected = np.array(image) # rected = cv2.cvtColor(rected, cv2.COLOR_RGB2BGR) # rected = cv2.rectangle(rected, roi[:2], (roi[0] + roi[2], roi[1] + roi[3]), 255,2) # show_image(rected) return extruder.get_template_rect(config)
def fetch_window(times, delay=2, dir='assets/data/screens/'): window = Window() id = 0 while id < times: time.sleep(delay) @timerfunc def screen(): return screenshot(window.rect) screen() @timerfunc def save(): img = np.array(screen()) cv2.imwrite(dir + str(id) + '.png', cv2.cvtColor(img, cv2.COLOR_BGR2RGB)) save() id = id + 1
class Taming: def __init__(self): self.config = Config() self.config.enable() self.roundFrequency = 30 self.window = Window() self.roundStart = self.window.center() self.rountEnd = self.roundStart[0] + 100, self.roundStart[1] def run(self): startTime = time.time() while self.config.isWorks(): Key('2').press() time.sleep(3) Key('1').press() time.sleep(13) currentTime = time.time() if startTime + self.roundFrequency < currentTime: startTime = currentTime Move().fromTo(self.roundStart, self.rountEnd)
def init_window(): return Window()
def run(times=10): # make_extruder_env() window = Window() config = Config() config.initialize_configs('navigator.config.yml') CircusHandler().go_to_dungeon()
def turn_around(): x, y = Window().center() Move().fromTo((x, y), (x + TURN_AROUND_DISTANCE, y))
class Farming: # TODO invistigate asyncio # frequences = [ # 2, # 0.3, # 0.3, # 15, # 15, # 40, # 40, # 40, # 5 # ] # action_params = [ # '1', # ['c', '6'], # ['c', '7'], # ['s', '2'], # ['s', '3'], # ['a', '5'], # alt + 1 # ['a', '4'], # ['a', '1'], # '_' # ] def __init__(self, actions, timings): self.action_params = actions self.frequences = timings self.config = Config() self.config.enable() self.roundFrequency = 10 self.generate_actions() self.init_skills_state() self.init_actions_time() print(self.actions, self.action_params, timings) self.window = Window() self.roundStart = self.window.center() self.rountEnd = self.roundStart[0] + 100, self.roundStart[1] def run(self): startTime = time.time() while self.config.isWorks(): # print('[While iteration]') for i, a in enumerate(self.actions): itime = time.time() if itime > self.skills_state[i]: f = getattr(self, a) f(self.action_params[i]) print(a, self.action_params[i], self.frequences[i]) self.skills_state[i] = itime + self.frequences[i] def init_actions_time(self): itime = time.time() for a in range(len(self.actions)): self.skills_state[a] = itime def generate_actions(self): self.actions = [] for key in self.action_params: method = self.get_method_name(key) self.actions.append(method) def init_skills_state(self): self.skills_state = [0] * len(self.frequences) def key(self, params): if type(params) == list: print('list key call') Key(params[1], pressed=params[0]).combination() else: Key(params).press() Wait(0.4).delay() def turn(self, _): print('turn') Move().fromTo(self.roundStart, self.rountEnd) return None def get_method_name(self, key): if key is '_': return 'turn' return 'key'
def __init__(self, xChecker, yChecker): self.move = Move() self.xChecker = xChecker self.yChecker = yChecker self.window = Window().center()
def click_at_npc(npc_roi, npc): npc_x, npc_y = circus_npc_point(npc_roi) wx, wy = Window().position() Click(wx + npc_x + npc.click_x_shift, wy + npc_y + npc.click_y_shift, process='dclick').make_click()
def __init__(self): self.window = Window()
def test_center(self): result = Window().center() self.assertEqual(result, (940, 765))
def test_position(self): result = Window().position() self.assertEqual(result, (100, 240))
def test_init(self): result = Window() self.assertIsInstance(result, Window)
import logging from processes.click import Click from shapes.window import Window from utils.cv2_utils import screenshot from jobs.helpers.extruder import Extruder from utils.config import Config from processes.wait import Wait from processes.move import Move from shapes.rect import Rect Y_OFFSET_FROM_START_POSITION = 70 TURN_AROUND_DISTANCE = 500 window = Window() config = Config() log = logging.getLogger('navigator') class Navigator: @staticmethod def move_to_npc(npc_roi, npc=None): npc_x, npc_y = circus_npc_point(npc_roi) wx, wy = Window().position() Click(wx + npc_x + npc.nav_x_shift, wy + npc_y + npc.nav_y_shift, process='dclick').make_click() @staticmethod def click_at_npc(npc_roi, npc): npc_x, npc_y = circus_npc_point(npc_roi)
def camera_height(npc): npcC = _center(npc) return Window().relative_center()[1] - 10 - npcC[1]
def camera_angle_width(npc): npcC = _center(npc) screenC = Window().relative_center() return npcC[0] - screenC[0] + 15 # calibrate coef
def test_relative(self): result = Window().relative((100, 100)) self.assertEqual(result, (200, 340))
def move_to_npc(npc_roi, npc=None): npc_x, npc_y = circus_npc_point(npc_roi) wx, wy = Window().position() Click(wx + npc_x + npc.nav_x_shift, wy + npc_y + npc.nav_y_shift, process='dclick').make_click()