Ejemplo n.º 1
0
def find_best_waypoint_route(routes: List[List[Position]], position: Position):
    best = (position.calculate_distance_from(routes[0][0]), 0)

    for i, route in enumerate(routes):
        distance = position.calculate_distance_from(route[0])

        if distance < best[0]:
            best = (distance, i)

    return best[1]
Ejemplo n.º 2
0
    def test_turn_left(self):
        fake_controller = FakeController()
        storage = PositionStorage()
        storage.parse([(0, 2)])
        move = MoveState(fake_controller, None, storage)
        fake_character = FakeCharacter()
        fake_character.position = Position(0, 0)

        move.interpret(fake_character, None)
        fake_character.position = Position(1, 1)
        move.interpret(fake_character, None)

        self.assertEqual(math.ceil(pi / 2 / move.RAD_PER_TURN),
                         fake_controller.val)
Ejemplo n.º 3
0
    def test_stop_on_transition_when_too_far_away(self):
        character = FakeCharacter()
        character.position = Position(50, 50)
        self.storage.parse([(20, 20)])

        with self.assertRaises(PrerequisiteException) as e:
            self.start.transition(character, None)
Ejemplo n.º 4
0
    def test_turn_right_to_waypoint(self):
        character = FakeCharacter()
        character.position = Position(50, 50)
        self.storage.parse([(92, 33)])

        self.start.interpret(character, None)

        self.assertEqual(Direction.right, self.controller.turn)
Ejemplo n.º 5
0
    def test_point(self):
        character = FakeCharacter()
        character.position = Position(530.0566, -432.1322)
        character.facing = 1.4452323
        self.storage.parse([(529.1963, -434.5789)])

        self.start.interpret(character, None)
        time.sleep(2)
        character.facing = 2.345232
        self.storage.parse([(529.1963, -430.5789)])
        self.start.interpret(character, None)
        time.sleep(2)
Ejemplo n.º 6
0
    def record(self, record_data: Dict[str, str]):
        self.waypoints = {'format': record_data['wp_format'], 'waypoints': []}

        signal.signal(signal.SIGINT,
                      lambda *args: self.screen.stop_capturing())
        signal.signal(signal.SIGTERM,
                      lambda *args: self.screen.stop_capturing())

        try:
            for screen in self.screen.capture():
                data = self.extractor.extract_data_from_screen(screen)
                self._data_sanitizer.sanitize_data(data)

                current_position = Position(data.player_position[0],
                                            data.player_position[1])
                if not self.waypoints['waypoints']:
                    self.waypoints['waypoints'].append(data.player_position)
                else:
                    last_recorded_coordinates = self.waypoints['waypoints'][
                        len(self.waypoints['waypoints']) - 1]
                    last_recorded_position = Position(
                        last_recorded_coordinates[0],
                        last_recorded_coordinates[1])
                    if current_position.calculate_distance_from(
                            last_recorded_position
                    ) >= GlobalConfig.config.core.difference_between_two_waypoints:
                        Logger.info('Recording position: ' +
                                    str(data.player_position))
                        self.waypoints['waypoints'].append(
                            data.player_position)
        finally:
            Logger.info('Saving file to: {}'.format(
                record_data.get('waypoint', 'NO PATH')))

            file = Path(record_data['waypoint'])
            if file.is_file():
                self._save_if_file_exist(record_data)
            else:
                self._save_if_file_not_exist(record_data)
Ejemplo n.º 7
0
    def test_calculate_trajectory(self):
        p1 = Position(2, -2)
        a1 = pi / 3
        a2 = 2 * pi / 3
        a3 = 4 * pi / 3
        a4 = 5 * pi / 3

        v1 = calculate_trajectory(p1, a1)
        v2 = calculate_trajectory(p1, a2)
        v3 = calculate_trajectory(p1, a3)
        v4 = calculate_trajectory(p1, a4)

        print(v1, v2, v3, v4)
Ejemplo n.º 8
0
 def update(self, data: ExtractedData):
     self.hp = data.player_health
     self.resource = data.player_resource
     self.position = Position(data.player_position[0],
                              data.player_position[1])
     self.is_in_combat = data.combat
     self.facing = normalize_facing(data.facing)
     self.last_ability = data.last_ability
     self.casting = data.casting
     self.is_inventory_full = data.is_inventory_full
     self.has_pet = data.player_has_pet
     self.first_class_resource = data.player_first_resource_available
     self.pet_hp = data.pet_health
     self.pet_mana = data.pet_mana
Ejemplo n.º 9
0
 def __init__(self, resource_type: Resource = Resource.MANA):
     self.hp = 0
     self.resource = 0
     self.position = Position(0, 0)
     self.resource_type = resource_type
     self.is_moving = False
     self.is_in_combat = False
     self.current_waypoint = 0
     self.facing = 0
     self.casting = CastingState.IDLE
     self.last_ability = LastAbilityExecution.SUCCESS
     self.is_inventory_full = False
     self.has_pet = False
     self.first_class_resource = False
     self.pet_hp = 0
     self.pet_mana = 0
Ejemplo n.º 10
0
    def __init__(self,
                 controller: CharacterController,
                 behavior: CharacterBehavior,
                 waypoints: PositionStorage = None,
                 transition_state: BaseState = None,
                 transition: TransitionType = TransitionType.SAME_LEVEL):
        super().__init__(controller, behavior, waypoints, transition_state,
                         transition)
        self._released = False

        closest_waypoint_route = find_best_waypoint_route(
            [[Position(w[0], w[1]) for w in wp['waypoints']]
             for wp in GlobalConfig.config.waypoint['ghost']],
            transition_state.persistent_state['last_position'])
        self.waypoints.parse(GlobalConfig.config.waypoint['ghost']
                             [closest_waypoint_route]['waypoints'])

        self.create_sub_state(MoveState)
Ejemplo n.º 11
0
    def interpret(self, frame: Frame):
        self._positions.append(frame.character.position)

        if len(self._positions.data) >= self.LAST_N_POSITION + 1:
            # distance_from_last_position = self._positions.data[-1].calculate_distance_from(self._positions.data[-2])
            x_avg = 0
            y_avg = 0
            for i in range(
                    len(self._positions.data) - 1,
                    len(self._positions.data) - self.LAST_N_POSITION - 1, -1):
                x_avg += self._positions.data[i].x
                y_avg += self._positions.data[i].y

            x_avg = x_avg / self.LAST_N_POSITION
            y_avg = y_avg / self.LAST_N_POSITION

            avg_point = Position(x_avg, y_avg)
            distance_from_last_position = self._positions.data[
                -1].calculate_distance_from(avg_point)

            if self._direction:
                self.controller.turn(
                    self._direction,
                    random.uniform(
                        GlobalConfig.config.movement.stuck_turn_range[0],
                        GlobalConfig.config.movement.stuck_turn_range[1]))
            elif self._jumps >= GlobalConfig.config.movement.stuck_first_level_threshold:
                self._direction = Direction(random.randint(0, 1))

            if distance_from_last_position <= GlobalConfig.config.movement.stuck_threshold:
                self.log("Character is stuck, pressing space.")
                self.controller.cast_spell('space')
                self._jumps += 1
            else:
                self._jumps = 0
                self._direction = None
Ejemplo n.º 12
0
 def add(self, waypoint: (float, float)):
     self.waypoints.append(Position(waypoint[0], waypoint[1]))
Ejemplo n.º 13
0
 def parse(self, points: List[Tuple[float, float]]):
     self.waypoints = []
     self.waypoints.extend([Position(x, y) for x, y in points])
Ejemplo n.º 14
0
def calculate_trajectory(point: Position, facing: float) -> Trajectory:
    projected_x = point.point.x + 1 * math.cos(facing)
    projected_y = point.point.y + 1 * math.sin(facing)

    return Trajectory(point, Position(projected_x, projected_y), facing)
Ejemplo n.º 15
0
    def test_position_close_to(self):
        p = Position(441.1396, -337.4077)
        p2 = Position(438.636, -340.0971)

        print(p.is_close_to(p2, 0.01))
Ejemplo n.º 16
0
 def __init__(self):
     self.position = Position(0, 0)
     self.current_waypoint = 0
     self.is_moving = False
     self.facing = 0
Ejemplo n.º 17
0
    def test_calculate_angle(self):
        a = Position(2, -2)
        b = Position(1, -3)
        line = Trajectory(a, b)

        print(line)