Пример #1
0
 def get_center_ponit(self):
     if self.i == 1:
         return Point((self.line1.start.x + self.line1.end.x) / 2,
                      (self.line1.start.y + self.line1.end.y) / 2)
     else:
         return Point((self.line2.start.x + self.line2.end.x) / 2,
                      (self.line2.start.y + self.line2.end.y) / 2)
Пример #2
0
 def __init__(self, area, i=1):
     super().__init__()
     self.line1 = Line(
         Point(area["leftTop"][0], area["leftTop"][1]),
         Point(area["rightBottom"][0], area["rightBottom"][1]))
     self.line2 = Line(Point(area["leftBottom"][0], area["leftBottom"][1]),
                       Point(area["rightTop"][0], area["rightTop"][1]))
     self.area = area
     self.i = i
Пример #3
0
 def leftOrRightByVector(self, startPos: Point, nowPos: Point, targetPos: Point):
     X = nowPos.x
     Y = nowPos.y
     ST = Point(targetPos.x - startPos.x, targetPos.y - startPos.y)  # 起始点到目标点向量
     SN = Point(nowPos.x - startPos.x, nowPos.y - startPos.y)  # 起始点到当前点向量
     ds = (ST.x * SN.y) - (SN.x * ST.y)  # 向量叉积
     if ds > 0:  # 在直线左边
         if Y < targetPos.y:
             return "left"
         return "right"
     elif ds < 0:  # 在直线右边
         if Y < targetPos.y:
             return "right"
         return "left"
     else:  # 在直线上
         return "on the line"
Пример #4
0
 def divide_line(self, cut):
     if self.i == 1:
         if cut <= 1:
             return [self.line1.start, self.line1.end]
         ret = []
         for i in range(cut):
             x = self.line1.start.x + (self.line1.end.x -
                                       self.line1.start.x) / cut * i
             y = self.line1.start.y + (self.line1.end.y -
                                       self.line1.start.y) / cut * i
             ret.append(Point(x, y))
         return ret
     else:
         if cut <= 1:
             return [self.line2.start, self.line2.end]
         ret = []
         for i in range(cut):
             x = self.line2.start.x + (self.line2.end.x -
                                       self.line2.start.x) / cut * i
             y = self.line2.start.y + (self.line1.end.y -
                                       self.line2.start.y) / cut * i
             ret.append(Point(x, y))
         return ret
Пример #5
0
    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
Пример #6
0
 def counterClockWiseSpin(self, point: Point, degree):
     x = point.x * math.cos(math.radians(degree)) - point.y * math.sin(math.radians(degree))
     y = point.y * math.cos(math.radians(degree)) + point.x * math.sin(math.radians(degree))
     return Point(x, y)
Пример #7
0
 def __init__(self, x, y):
     Point.__init__(self, x, y)