def convert_local_to_global(self, location): """ If self.map doesn't contain this location, camera might be wrong, correct camera and re-convert it. Args: location: Grid instance in self.view Returns: Grid: Grid instance in self.map """ location = location_ensure(location) global_ = np.array(location) + self.camera - self.view.center_loca logger.info( 'Global %s (camera=%s) <- Local %s (center=%s)' % (location2node(global_), location2node(self.camera), location2node(location), location2node(self.view.center_loca))) if global_ in self.map: return self.map[global_] else: logger.warning('Convert local to global Failed.') self.ensure_edge_insight(reverse=True) global_ = np.array(location) + self.camera - self.view.center_loca return self.map[global_]
def convert_map_to_grid(self, location): """If self.grids doesn't contain this location, focus camera on the location and re-convert it. Args: location: Grid instance in self.map. Returns: Grid: Grid instance in self.grids. """ location = location_ensure(location) local = np.array(location) - self.camera + self.view.center_loca logger.info('Global %s (camera=%s) -> Local %s (center=%s)' % ( location2node(location), location2node(self.camera), location2node(local), location2node(self.view.center_loca) )) if local in self.view: return self.view[local] else: logger.warning('Convert global to local Failed.') self.focus_to(location) local = np.array(location) - self.camera + self.view.center_loca return self.view[local]
def convert_radar_to_local(self, location): """ Converts the coordinate on radar to the coordinate of local map view, also handles a rare game bug. Usually, OPSI camera focus on current fleet, which is (5, 4) in local view. The convert should be `local = view[np.add(radar, view.center_loca)]` However, Azur Lane may bugged, not focusing current. In this case, the convert should base on fleet position. Args: location: (x, y), Position on radar. Returns: OSGrid: Grid instance in self.view """ location = location_ensure(location) fleets = self.view.select(is_current_fleet=True) if fleets.count == 1: center = fleets[0].location elif fleets.count > 1: logger.warning( f'Convert radar to local, but found multiple current fleets: {fleets}' ) distance = np.linalg.norm( np.subtract(fleets.location, self.view.center_loca)) center = fleets.grids[np.argmin(distance)].location logger.warning( f'Assuming the nearest fleet to camera canter is current fleet: {location2node(center)}' ) else: logger.warning( f'Convert radar to local, but current fleet not found. ' f'Assuming camera center is current fleet: {location2node(self.view.center_loca)}' ) center = self.view.center_loca try: local = self.view[np.add(location, center)] except KeyError: logger.warning( f'Convert radar to local, but target grid not in local view. ' f'Assuming camera center is current fleet: {location2node(self.view.center_loca)}' ) center = self.view.center_loca local = self.view[np.add(location, center)] logger.info('Radar %s -> Local %s (fleet=%s)' % (str(location), location2node( local.location), location2node(center))) return local
def in_sight(self, location, sight=None): """Make sure location in camera sight Args: location: sight (tuple): Such as (-3, -1, 3, 2). """ location = location_ensure(location) logger.info('In sight: %s' % location2node(location)) if sight is None: sight = self.map.camera_sight diff = np.array(location) - self.camera if diff[1] > sight[3]: y = diff[1] - sight[3] elif diff[1] < sight[1]: y = diff[1] - sight[1] else: y = 0 if diff[0] > sight[2]: x = diff[0] - sight[2] elif diff[0] < sight[0]: x = diff[0] - sight[0] else: x = 0 self.focus_to((self.camera[0] + x, self.camera[1] + y))
def show_fleet(self): fleets = [] for n in [1, 2]: fleet = self.__getattribute__('fleet_%s_location' % n) if len(fleet): text = 'Fleet_%s: %s' % (n, location2node(fleet)) if self.fleet_current_index == n: text = '[%s]' % text fleets.append(text) logger.info(' '.join(fleets))
def focus_to(self, location, swipe_limit=(4, 3)): """Focus camera on a grid Args: location: grid swipe_limit(tuple): (x, y). Limit swipe in (-x, -y, x, y). """ location = location_ensure(location) logger.info('Focus to: %s' % location2node(location)) while 1: vector = np.array(location) - self.camera swipe = tuple(np.min([np.abs(vector), swipe_limit], axis=0) * np.sign(vector)) self.map_swipe(swipe) if np.all(np.abs(vector) <= 0): break
def focus_to(self, location, swipe_limit=(3, 2)): """Focus camera on a grid Args: location: grid swipe_limit(tuple): (x, y). Limit swipe in (-x, -y, x, y). """ location = location_ensure(location) logger.info('Focus to: %s' % location2node(location)) vector = np.array(location) - self.camera vector, sign = np.abs(vector), np.sign(vector) while 1: swipe = ( vector[0] if vector[0] < swipe_limit[0] else swipe_limit[0], vector[1] if vector[1] < swipe_limit[1] else swipe_limit[1]) self.map_swipe(tuple(sign * swipe)) vector -= swipe if np.all(np.abs(vector) <= 0): break
def show_camera(self): logger.attr_align('Camera', location2node(self.camera))
def show_camera(self): logger.info(' Camera: %s' % location2node(self.camera))