def strategy_random(self, got): step = UserConfig.move_step if UserConfig.move_step > 0 else random.randint(1, 3) if self.move_count % step == 0 and got.value == 0: # 没怪换角度 i = random.randint(0, 2) self.control.driver.turn_left() if i == 0 else self.control.driver.turn_right() # self.control.driver.tap_key("tab") else: right_click_pos = PixelData.get_another_resolution_point(SysConfig.move_click_pos).confoundPoint(UserConfig.point_confound_rang) if UserConfig.find_enemy_move_type == 0 and got.value == 0: self.control.driver.move_click_right(right_click_pos, 1) # x向前走两步 # self.control.driver.tap_key("tab") else: start = time.time() tick = 0 self.control.driver.tap_key_up("w") self.control.driver.tap_key_down("w") while tick < UserConfig.move_step * 3 and not Target().isEnemy(self.player.getLevel()): # self.control.driver.tap_key("tab") if got.value == 0: time.sleep(random.uniform(1.0, 3.0)) if got.value == 0: self.random_behavior() if got.value == 0: self.control.driver.turn_random() tick = time.time() - start self.control.driver.tap_key_up("w") if random.randint(0, 2) == 1: self.control.driver.tap_str(" ") # 空格是跳
def baopi(self): self.control.driver.tap_key(";") targetStatus = Target().getStatus() # 如果上一个目标没有死亡,那说明这个目标有问题 if targetStatus["dead"] == 0: self.clear_target() return False self.control.driver.tap_key("'", 3.2) return True
def tab_thread(got): if hasattr(UserConfig,"use_name_finder") and UserConfig.use_name_finder: from lib.NameFinder.NpcNameFinder import NpcNameFinder finder = NpcNameFinder() while not Target().isEnemy(Player().getLevel()) and Player().getStatus()['dead'] == 0: Pyinput().tap_key("tab") time.sleep(random.uniform(0.1, 0.3)) if hasattr(UserConfig, "use_name_finder") and UserConfig.use_name_finder: finder.findAndClick() got.value = 1 print("find enemy, process tab end .............")
def loot(self): # from lib.NameFinder.NpcNameFinder import NpcNameFinder # finder = NpcNameFinder(needCpture=False) # finder.circleLoot(1) # print("使用圆圈方式拾取") self.control.driver.tap_key(";") targetStatus = Target().getStatus() # 如果上一个目标没有死亡,那说明这个目标有问题 if targetStatus["dead"] == 0: self.clear_target() return False self.control.driver.tap_key("'", 1.5) print("使用上一个目标方式拾取") return True
def castSpell(self, slot, delay=0, inSure=True,autoTurn=False): if slot < min(self.slots) or slot > max(self.slots): raise Exception("slot is not in range") while self.castingHander.isCastingOrChanneld(): print("casting... wait 0.1") time.sleep(0.1) key = UserConfig.slot_to_key[slot] self.control.driver.tap_key(key, delay) time.sleep(0.5) start = time.time() while not self.castingHander.isCastingOrChanneld() and autoTurn and Target().getUUID() != 0 and time.time() - start < 10: print("转向敌人") self.control.driver.turn_right() self.control.driver.tap_key(key, delay) time.sleep(0.5) if inSure: self.castingHander.insureCasting()
def strategy_finder_path(self, got): from lib.navigation.StragegyFinderpath import StrageyFinderpath s = StrageyFinderpath(self.control, self.player) near_pos = s.get_nearst_pos() print("最近的路点:") print(near_pos.toString()) checkMount = True if hasattr(UserConfig,"use_name_finder") and UserConfig.use_name_finder: checkMount = False s.walk(targetPos=near_pos, sleep=0.3, combat_exit=True, checkMount=checkMount,targetIsEnemy_exit=True) count = 0 turn_degree = 30 turn_time = 2 / 360 * turn_degree while count < 360 / turn_degree and not Target().isEnemy(self.player.getLevel()): self.control.driver.turn_right(turn_time) time.sleep(0.3) count = count + 1 if got.value == 0: next_pos = s.get_next_pos() print("下一个路点:") print(next_pos.toString()) s.walk(targetPos=next_pos, sleep=0.3, combat_exit=True, checkMount=checkMount,targetIsEnemy_exit=True)
def walk(self, targetPos: Point, move_type=0, sleep=0.5, precision=0.3, last=0, combat_exit=False,alive_exit=False,checkMount=False,targetIsEnemy_exit=False): print("\r\n", file=self.hander) # 初始化起始位置和当前位置相同 startPos = self.getNowPos() nowPos = startPos tx = targetPos.x ty = targetPos.y # 解决路点第一个点和人物重合,人物会再返回第一个点的问题 d = self.get_distance_off_tow_pos(targetPos, nowPos) if d <= precision: print("起始点就是目标点,循环次数:0,X误差:" + str(abs(tx - nowPos.x)) + ",Y误差:" + str(abs(ty - nowPos.y)), file=self.hander) return True self.control.driver.tap_key_down("w") # 开始持续移动 self.w_down = 1 # w是否按下标志位 count = 0 start = time.time() while True: if time.time() - start > 60: # 超过一段时间还没有到达下一额点 self.unStuck() start = time.time() if targetIsEnemy_exit and Target().isEnemy(self.player.getLevel()): if self.w_down == 1: self.control.driver.tap_key_up("w") return False if combat_exit is True and self.player.getStatus()["combat"] == 1: if self.w_down == 1: self.control.driver.tap_key_up("w") return False if checkMount and self.player.getStatus()['mounted'] == 0 and self.player.getStatus()['combat'] == 0: if self.w_down == 1: self.control.driver.tap_key_up("w") self.player.mounted() self.control.driver.tap_key_down("w") # 开始持续移动 self.w_down = 1 # w是否按下标志位 if alive_exit is True and self.player.getStatus()['dead'] == 0: if self.w_down == 1: self.control.driver.tap_key_up("w") return False print("开始" + str(count), file=self.hander) if time.time() - start > last > 0: if self.w_down == 1: self.control.driver.tap_key_up("w") return False if self.w_down == 0: self.control.driver.tap_key_down("w") self.w_down = 1 startPos = nowPos # 变更起始位置为上次当前位置 time.sleep(sleep) nowPos = self.getNowPos() print(startPos.toString(), nowPos.toString(), targetPos.toString(), file=self.hander) distance_to_target = self.get_distance_off_tow_pos(nowPos, targetPos) print("与目标距离:" + str(distance_to_target), file=self.hander) if distance_to_target > precision: degree = self.posToDegree(startPos, nowPos, targetPos) while degree == 9999: if self.w_down == 0: self.control.driver.tap_key_down("w") # 开始持续移动 self.w_down = 1 self.control.driver.turn_right() self.control.driver.tap_str(" ") # 跳 print("寻路跳") print("跳", file=self.hander) degree = self.posToDegree(startPos, self.getNowPos(), targetPos) t = self.degreeToTime(degree) print("转向时间 t = " + str(t), file=self.hander) if t > 0: turn = self.leftOrRight(startPos, nowPos, targetPos) print("turn = " + turn, file=self.hander) if move_type == 1 or t >= sleep: # 如果move_type == 1 或者转向角度较大,停下来转,否则行走中转 self.control.driver.tap_key_up("w") # 转向期间停止移动 self.w_down = 0 if turn == 'left': self.control.driver.turn_left(t) else: self.control.driver.turn_right(t) count = count + 1 else: self.control.driver.tap_key_up("w") # 停止移动 print("到达目标点,循环次数:" + str(count) + ",X误差:" + str(abs(tx - nowPos.x)) + ",Y误差:" + str(abs(ty - nowPos.y)), file=self.hander) return True
def __init__(self, i): Target.__init__(self) if i < 1 or i > 4: raise Exception("队友只能是1-4") self.i = i self.rang = self.__get_party_slots()
def find_enemy(self): self.player.before_findenemy() print("begin find enemy") from run.record.path_data.DynamicConfig import DynamicConfig start = time_without_enemy = time.time() playerLevel = self.player.getLevel() got = multiprocessing.Value("d", 0) # 多进程共享变量 # 寻怪进程 p = multiprocessing.Process(target=tab_thread, args=(got,)) p.start() while True: if self.player.getStatus()['dead'] == 1: return Target() if Target().isEnemy(playerLevel): print("end find enemy 1") return Target() Player.someBodyWihsperMe(self.player.getName()) playerStatus = self.player.getStatus() if playerStatus["dead"] == 1 or playerStatus["is_ghost"] == 1: print("end find enemy 2") return Target() if playerStatus["combat"] == 1: time.sleep(0.5) # 等待自动选中敌人 if Target().isEnemy(playerLevel): print("end find enemy 3") return Target() # 区域打怪判断 if DynamicConfig.area_fighting_pos != 0: AreaFighting(control=self.control, player=self.player, area_pos=DynamicConfig.area_fighting_pos).goto_area() if time.time() - time_without_enemy > UserConfig.time_without_enemy: sendmail(UserConfig.email, self.player.getName() + " more than " + str(UserConfig.time_without_enemy), "", self.screenshot("time_without_enemy")) time_without_enemy = time.time() spend = time.time() - start if spend > 60: # 如果1分钟都还没有找到敌人,那么很有可能卡地形了,则转身,重置循环条件 print("超过60秒没有找到敌人,判定为卡地形,转身,重置查找时间") self.turn_back() start = time.time() # self.control.driver.tap_key("tab") # 先用tab在寻怪 target = Target() if target.isEnemy(playerLevel): print("end find enemy 4") return target if UserConfig.check_touch_by_other == 1 and target.isTouchByAnoter() is True: self.clear_target() # 寻怪策略 if UserConfig.find_enemy_strategy == 1 and DynamicConfig.area_fighting_pos != 0: self.strategy_circle_involute(DynamicConfig.area_fighting_pos, got) elif UserConfig.find_enemy_strategy == 2 and DynamicConfig.area_fighting_pos != 0: self.strategy_square_involute(DynamicConfig.area_fighting_pos, got) elif UserConfig.find_enemy_strategy == 3 and DynamicConfig.area_fighting_pos != 0: self.strategy_diagonal(DynamicConfig.area_fighting_pos, got) elif UserConfig.find_enemy_strategy == 4 \ and hasattr(DynamicConfig, "finder_path") \ and DynamicConfig.finder_path != [] \ and DynamicConfig.finder_path != 0 \ and DynamicConfig.finder_path is not None: self.strategy_finder_path(got) elif UserConfig.find_enemy_strategy == 999 and DynamicConfig.area_fighting_pos != 0: rand = random.randint(0, 1) if rand == 0: self.strategy_random(got) elif rand == 1: self.strategy_circle_involute(DynamicConfig.area_fighting_pos, got) elif rand == 2: self.strategy_square_involute(DynamicConfig.area_fighting_pos, got) elif rand == 3: self.strategy_random(got) else: self.strategy_random(got) self.move_count = self.move_count + 1