def special_settle_phase(self): """ 没有战斗数据按钮的结算流程 :return: """ for battle_round in range(0, 10): # 当镜头旋转结束,出现结算达摩,则视为进入结算界面 catch_img = ImageGrab.grab(self.rewardobj.scan_area) img_hash = get_hash(catch_img) r1, r2 = hamming(img_hash, self.rewardobj.hash, 40) if self.debug: logging( '[%s]round%s %s:%s:%s' % ('special_settle_phase1', battle_round, img_hash, r1, r2)) if r1: break else: # 在右侧边缘范围内随机移动鼠标位置,并随机点击1-3次 self.rewardobj.area_click(int(random.uniform(1, 3))) time.sleep(round(random.uniform(0.5, 1.0), 2)) for battle_round in range(0, 10): catch_img = ImageGrab.grab(self.rewardobj.scan_area) img_hash = get_hash(catch_img) # 当结算达摩消失时,视为结算结束 r1, r2 = hamming(img_hash, self.rewardobj.hash, 40) if self.debug: logging( '[%s]round%s %s:%s:%s' % ('special_settle_phase2', battle_round, img_hash, r1, r2)) if not r1: break else: # 在右侧边缘范围内随机移动鼠标位置,并随机点击1-3次,直到结算结束 self.rewardobj.area_click(int(random.uniform(1, 3))) time.sleep(round(random.uniform(0.5, 1.0), 2))
def click_boss_notice(self, mode, queue): """ 点击发现超鬼王提示 :param mode: :param queue: 队列对象 :return: """ num = 1 while True: if not queue.empty(): self._running = queue.get() if self._running == 1: catch_img = ImageGrab.grab(self.bossobj.scan_area) img_hash = get_hash(catch_img) num += 1 r1 = False if mode == 1: r1, r2 = hamming(img_hash, self.bossobj.hash[0], 15) if self.debug: logging('%s boss %s:%s:%s' % (num, img_hash, r1, r2)) elif mode == 2: r11, r21 = hamming(img_hash, self.bossobj.hash[0], 15) r21, r22 = hamming(img_hash, self.bossobj.hash[1], 15) if r11 or r21: r1 = True if r1: queue.put(0) self.bossobj.custom_click(0) return time.sleep(1) elif self._running == 0: return
def settle_phase(self, queue): """ 战斗结算阶段 :param queue: 队列对象 :return: """ battle_buttun_is_appear = False for battle_round in range(0, 20): if not queue.empty(): self._running = queue.get() if self._running == 1: # 当出现战斗数据按钮时,则视为进入结算界面 catch_img = ImageGrab.grab(self.battledataobj.scan_area) img_hash = get_hash(catch_img) r1, r2 = hamming(img_hash, self.battledataobj.hash, 40) if self.debug: logging('[%s]round%s %s:%s:%s' % ('settle_phase', battle_round, img_hash, r1, r2)) if r1: battle_buttun_is_appear = True # 在右侧边缘范围内随机移动鼠标位置,并随机点击1-3次 self.rewardobj.area_click(int(random.uniform(1, 3))) elif not r1: if battle_buttun_is_appear: time.sleep(2) break else: self.special_settle_phase() break elif self._running == 0: break time.sleep(round(random.uniform(0.5, 1.0), 2))
def index_test(): # resp = make_response(render_template('index.html')) # resp.set_cookie('userID', 'testID') # ------------------------------------------------------------------------ # Get 인 경우에 # if cookie 가 없으면 redirect -> login.html # cookie 가 있으면 index.html 로 가는데 거기서 js 에서 쿠키로 user정보가져옴 if request.method == 'GET': login_hash = request.cookies.get('login_hash') if login_hash is None: return redirect(url_for('login')) user = UserLogin.query.filter(UserLogin.login_hash == login_hash).first() if user is None: return redirect(url_for('login')) # naver에 서 받아와봄 userinfo = utilities.get_userinfo(user) if userinfo is None: return redirect(url_for('login')) return render_template('index.html') # Post 인 경우에는 # token이 날라올거기 때문에 # 내부에 ip, token, hash 를 저장하고 hash를 쿠키에 담아서 날려줌 # cookie 가 있으므로 index.html로 거기서 js 에서 쿠키로 user정보가져옴 elif request.method == 'POST': access_token = request.json['token'] ip = request.remote_addr login_hash = utilities.get_hash(access_token, ip) user = UserLogin.query.filter(UserLogin.access_token == access_token).first() timestamp = str(datetime.datetime.utcnow()) provider = 'naver' if user is None: user = UserLogin(login_hash, access_token, provider, timestamp) db_session.add(user) else: user.access_token = access_token user.login_hash = login_hash user.provider = provider user.timestamp = timestamp db_session.commit() else: return redirect(url_for('login')) return render_template('index.html')
def check_fullrepo_alert(self, queue): """ 处理满仓提示 :param queue: 队列对象 :return: """ while True: if not queue.empty(): self._running = queue.get() if self._running == 1: catch_img = ImageGrab.grab(self.fullrepobj.scan_area) r1, r2 = hamming(get_hash(catch_img), self.fullrepobj.hash, 30) if r1: self.fullrepobj.custom_click(0) time.sleep(1.3) elif self._running == 0: return
def check_offer(self, offer_mode, queue): """ 处理悬赏协助询问 :param offer_mode: 悬赏协助处理模式 :param queue: 队列对象 :return: """ while True: if not queue.empty(): self._running = queue.get() if self._running == 1: catch_img = ImageGrab.grab(self.offerobj.scan_area) r1, r2 = hamming(get_hash(catch_img), self.offerobj.hash, 30) if r1: if offer_mode == "接受": self.offerobj.custom_click(0) elif offer_mode == "拒绝": self.offerobj.custom_click(1) click_left_cur() time.sleep(1.3) elif self._running == 0: return
def wait_fight_finish_phase(self, mode, clear_time, queue): """ 等待战斗结束阶段 :param mode: 组队模式 :param clear_time: 平均通关时间 :param queue: 队列对象 :return: """ if mode == '乘客': clear_time = clear_time - 3 t = 0 while t < clear_time: if not queue.empty(): self._running = queue.get() if self._running == 1: time.sleep(1) t = t + 1 elif self._running == 0: break while True: if not queue.empty(): self._running = queue.get() if self._running == 1: catch_img = ImageGrab.grab(self.exitobj.scan_area) img_hash = get_hash(catch_img) # 当退出战斗按钮消失时,视为战斗结束 r1, r2 = hamming(img_hash, self.exitobj.hash, 30) if self.debug: logging( '[%s]%s %s:%s:%s' % ('wait_fight_finish_phase', mode, img_hash, r1, r2)) if r1: pass else: break elif self._running == 0: return time.sleep(0.5)
def form_team_phase(self, mode, fight_num, queue): """ 组队阶段控制方法 :param mode: 组队模式 :param fight_num: 车队人数 :param queue: 队列对象 :return: """ if mode == '单刷': # 移动到挑战按钮并点击 每次移动在按钮范围内加入随机坐标位移 if self.debug: logging('[%s]%s' % ('form_team_phase', mode)) self.singleobj.area_click() return elif mode == '司机': # 检测是否进入组队界面 while True: if not queue.empty(): self._running = queue.get() if self._running == 1: catch_img = ImageGrab.grab(self.formteamobj.scan_area) img_hash = get_hash(catch_img) r1, r2 = hamming(img_hash, self.formteamobj.hash, 30) if self.debug: logging('[%s]%s %s:%s:%s' % ('form_team_phase1', mode, img_hash, r1, r2)) if r1: break time.sleep(0.5) elif self._running == 0: return # 检测队伍人数,符合预期再点开始战斗 while True: if not queue.empty(): self._running = queue.get() if self._running == 1: num = 0 for i in range(1, 3): catch_img = ImageGrab.grab( self.mutipleobj.scan_area[i]) img_hash = get_hash(catch_img) r1, r2 = hamming(img_hash, self.mutipleobj.hashes[i], 10) if self.debug: logging('[%s]%s 乘客%s %s:%s:%s' % ('form_team_phase2', num, mode, img_hash, r1, r2)) if not r1: num = num + 1 if num == fight_num - 1: break time.sleep(0.5) elif self._running == 0: return # 移动到开始战斗按钮并点击 每次移动在按钮范围内加入随机坐标位移 self.mutipleobj.area_click(2) elif mode == '乘客': # 检测是否进入战斗状态 while True: if not queue.empty(): self._running = queue.get() if self._running == 1: catch_img = ImageGrab.grab(self.exitobj.scan_area) img_hash = get_hash(catch_img) r1, r2 = hamming(img_hash, self.exitobj.hash, 30) if self.debug: logging('[%s]%s %s:%s:%s' % ('form_team_phase', mode, img_hash, r1, r2)) if r1: break time.sleep(0.5) elif self._running == 0: return