def floor2action(): controller.move_mouse(controller.get_position(), (755,186), delta=0.0) controller.click() time.sleep(controller.add_time_noise(8)) controller.move_mouse(controller.get_position(), (533,348), delta=0.0) controller.click() time.sleep(controller.add_time_noise(8))
def roof1stuckaction(): controller.move_mouse(controller.get_position(), (690,116), delta=0.0) controller.click() time.sleep(controller.add_time_noise(3.2)) controller.move_mouse(controller.get_position(), (378,308)) controller.click() time.sleep(controller.add_time_noise(4.55))
def roof3tokenaction(): controller.move_mouse(controller.get_position(), (352,369),delta=0.0) controller.click() time.sleep(controller.add_time_noise(2.1)) controller.move_mouse(controller.get_position(), (308,352), delta=0.0) controller.click() time.sleep(controller.add_time_noise(4.6))
def roof1tokenaction(): controller.move_mouse(controller.get_position(), (387,280)) controller.click() time.sleep(controller.add_time_noise(1.85)) controller.move_mouse(controller.get_position(), (380,277)) controller.click() time.sleep(controller.add_time_noise(3.7))
def roof2tokenaction(): controller.move_mouse(controller.get_position(), (370,311)) controller.click() time.sleep(controller.add_time_noise(1.1)) controller.move_mouse(controller.get_position(), (310,340)) controller.click() time.sleep(controller.add_time_noise(4.2))
def roof4tokenaction(): controller.move_mouse(controller.get_position(), (366,364),delta=0.0) controller.click() time.sleep(controller.add_time_noise(1.8)) controller.move_mouse(controller.get_position(), (382,394)) controller.click() time.sleep(controller.add_time_noise(3.8))
def get_bonus(self): for i in range(2): # 消抖 while self.get_state() == "st_getting_bonus": random_sleep(0.5, 0.1) click(self.coord_leaving, tired_check=False) random_sleep(0.5, 0.1)
def roof5tokenaction(): controller.move_mouse(controller.get_position(), (384,351), delta=0.0) controller.click() time.sleep(controller.add_time_noise(1.4)) controller.move_mouse(controller.get_position(), (416,340 ), delta=1) controller.click() time.sleep(controller.add_time_noise(6.9))
def roof6stuckaction(): controller.move_mouse(controller.get_position(), (745,153), delta=0.0) controller.click() time.sleep(controller.add_time_noise(5.2)) controller.move_mouse(controller.get_position(), (410,320), delta=0.0) controller.click() time.sleep(controller.add_time_noise(3.0))
def get_ready(self): for i in range(2): # 消抖 while self.get_state() == "st_getting_ready": random_sleep(0.5, 0.5) click(self.coord_entry, tired_check=False) random_sleep(0.5, 0.5)
def as_leader(batter_name): while 1: battle = Combat(batter_name) battle.start(auto_ready=True) time.sleep(2) start_loc = wait_for_color(PartyColor.StartFight) utilities.random_sleep(0.5, 2) click(start_loc, random_range=3, tired_check=True)
def start(self, auto_ready=False): if myFindColor(UtilColor.OutofSushi): escape() exit(0) if not auto_ready: ready_loc = wait_for_color(CombatColor.Ready) click(ready_loc, random_range=10, tired_check=False) #TODO: AUTO DETECT READY return self.get_result()
def start(self): enter_yulin() while self.get_remain_chance(): fight_loc = wait_for_color(YuLinColor.ReadyFightYuLinChi, max_time=10) click(fight_loc, random_range=5, tired_check=True) this_fight = combat.Combat('御灵', combat_time_limit=60 * 5 + random.randint(40, 80)) combat_result = this_fight.start(auto_ready=True)
def choose_boss(self): for i in range(2): # 消抖 while self.get_state() == "st_choosing_boss": # 选择鬼王 ind = np.random.randint(0, 3) click(self.coord_bosses[ind], tired_check=False) random_sleep(0.5, 0.5) # 点击“开始” click(self.coord_ok, tired_check=False) random_sleep(0.5, 0.5)
def on_press(key): if hasattr(key, 'char'): if key.char == 'z': controller.right_click() controller.move_mouse_relative(0,90, duration = 0.009) controller.click() controller.move_mouse_relative(0,-90, duration = 0.009) if key.char == 'x': controller.right_click() controller.move_mouse_relative(0,60, duration = 0.009) controller.click() controller.move_mouse_relative(0,-60, duration = 0.009)
def on_press(key): if hasattr(key, 'char'): if key.char == 'z': controller.right_click() controller.move_mouse_relative(0, 40, duration=0.001) controller.click() if key.char == 'x': curr = controller.get_position() curr = (curr[0], curr[1] - 40) controller.move_mouse_to(wilder, duration=.0001) controller.click() controller.move_mouse_to(curr, duration=.0001)
def as_leader(batter_name, chaoguiwang=False): while 1: if chaoguiwang: battle = Combat(batter_name, combat_time_limit=99999) else: battle = Combat(batter_name) battle.start(auto_ready=True) if chaoguiwang: time.sleep(5) else: time.sleep(2) logging.debug("waiting for start combat") start_loc = wait_for_color(PartyColor.StartFight, max_time=99999) utilities.random_sleep(0.5, 2) click(start_loc, random_range=3, tired_check=True)
def main_yaoqi(times, target_monster): count = 0 while count < times: yaoqi_loc = wait_for_state(img.party_img.YAOQIFENGYIN) click(yaoqi_loc) refresh_location = wait_for_state(img.party_img.REFRESH) parties.yaoqifengyin.find_monster(target_monster, refresh_location) combat = Combat('妖气封印') combat_result = combat.start() party_loc = wait_for_state(img.party_img.MAIN_PARTY, 15) time.sleep(1) click_to_leaving_state(img.party_img.MAIN_PARTY, rand_offset=10, location=party_loc) count += 1
def start(self): enter_yeyuanhuo() while self.get_remain_chance(): fight_loc = wait_for_color(YeyuanhuoColor.ReadyFightYeyuanhuoChi, max_time=10) click(fight_loc, random_range=5, tired_check=True) utilities.random_sleep(90, 60 * 3) wait_for_color(CombatColor.Damo, max_time=60 * 5) leaving_test = 0 while leaving_test < 3: utilities.random_sleep(0.2, 0.5) wait_for_leaving_color(CombatColor.Damo, max_waiting_time=15, max_click_time=8, clicking=True, clicking_gap=0.2, location=(57, 940), rand_offset=20) leaving_test += 1
def do_mamemaki(self): self.logger.info("Entered pseudo-state st_doing_mamemaki") random_sleep(5) # 等待先头部队出场 # 背景剪除 # there are quite many background removing functions provided by OpenCV # try some fast ones? bg_substractor = cv2.createBackgroundSubtractorMOG2( detectShadows=False) while self.get_state() not in BaiguiyexingStateDecision.states: # 只要没到其他状态就认为砸豆子还在继续 img_grabbed = grab_screen(region=self.win_region, use_channel_rgb=False) fg_mask = bg_substractor.apply(img_grabbed) # 消除孤立的细小轮廓 kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3, 3)) fg_mask = cv2.morphologyEx(fg_mask, cv2.MORPH_OPEN, kernel) # cv2.imwrite("fg_mask.jpg", fg_mask) # 调试用 contours, hierarchy = cv2.findContours(fg_mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) hit_coord = [] # 保存候选点击坐标 for c in contours: # 求轮廓的中心点 m = cv2.moments(c) if abs(m['m00']) < 10000: # 面积太小则跳过 continue x = int(m['m10'] / m['m00']) + constants.WINDOW_ATTRIBUTES["x_offset"] y = int(m['m01'] / m['m00']) + constants.WINDOW_ATTRIBUTES["y_offset"] hit_coord.append((x, y)) # print(f"hit_coord is {hit_coord}") if len(hit_coord) > 0: # 随机选取hit_coord中的一个点进行点击 ind = np.random.randint(0, len(hit_coord)) click(hit_coord[ind], tired_check=False) random_sleep(0.5, 0.1)
import pyscreenshot import numpy as np from PIL import Image import cv2 import sys sys.path.insert(0, '/Users/yingliu/Desktop/rsbot') import controller import time while True: controller.move_mouse(controller.get_position(), (742, 289)) controller.click() time.sleep(controller.add_time_noise(0.5)) controller.move_mouse(controller.get_position(), (731, 271)) controller.click() time.sleep(controller.add_time_noise(0.9)) controller.move_mouse(controller.get_position(), (692, 289)) controller.click() time.sleep(controller.add_time_noise(2.4))
def roof7action(): controller.move_mouse(controller.get_position(), (385,230)) controller.click() time.sleep(controller.add_time_noise(4.4))
def roof6action(): controller.move_mouse(controller.get_position(), (618,323)) controller.click() time.sleep(controller.add_time_noise(7.05))
def start(self, auto_ready=False): if not auto_ready: ready_loc = wait_for_color(CombatColor.Ready) click(ready_loc, random_range=10, tired_check=False) #TODO: AUTO DETECT READY return self.get_result()
def exist(self): click((63, 90), tired_check=False, need_convert=True) confirm_loc = wait_for_state(img.utilities_img.CONFIRM) click(confirm_loc, tired_check=False) self.get_result()
def get_result(self): # wait_for_color(CombatColor.InCombat) win_loc = myFindColor(CombatColor.Win) lose_loc = myFindColor(CombatColor.Lose) cur_time = datetime.datetime.now() while not win_loc and not lose_loc: win_loc = myFindColor(CombatColor.Win) lose_loc = myFindColor(CombatColor.Lose) # self.logger.debug(f'win_loc: {win_loc}; lose_loc: {lose_loc}') if (datetime.datetime.now() - cur_time).seconds > self.combat_time_limit: self.logger.debug('time out ending combat.') if myFindColor(CombatColor.Damo): leaving_test = 0 while leaving_test < 3: utilities.random_sleep(0.2, 0.5) wait_for_leaving_color(CombatColor.Damo, max_waiting_time=15, max_click_time=8, clicking=True, clicking_gap=0.2, location=(57, 940), rand_offset=20) leaving_test += 1 return CombatResult.WIN else: raise TimeoutError if win_loc: click((798, 337), random_range=30, tired_check=False, need_convert=True) wait_for_leaving_color(CombatColor.Win, max_waiting_time=15, max_click_time=8, clicking=False, clicking_gap=0.3, location=(798, 337), rand_offset=30) result = None while not result: click((57, 940), random_range=3, tired_check=False, need_convert=True) utilities.random_sleep(0.2, 0.5) result = myFindColor(CombatColor.Damo) leaving_test = 0 while leaving_test < 3: utilities.random_sleep(0.2, 0.5) wait_for_leaving_color(CombatColor.Damo, max_waiting_time=15, max_click_time=8, clicking=True, clicking_gap=0.2, location=(57, 940), rand_offset=20) leaving_test += 1 return CombatResult.WIN elif lose_loc: click((798, 337), random_range=30, tired_check=False, need_convert=True) wait_for_leaving_color(CombatColor.Lose, max_waiting_time=15, max_click_time=3, clicking=True, clicking_gap=0.2, location=(798, 337), rand_offset=30) utilities.random_sleep(1, 0.5) return CombatResult.LOSE else: self.exist() return CombatResult.LOSE
def floor3action(): controller.move_mouse(controller.get_position(), (400,165), delta=0.0) controller.click() time.sleep(controller.add_time_noise(10))
def floor1action(): controller.move_mouse(controller.get_position(), (350,255)) controller.click() time.sleep(controller.add_time_noise(7.0))