2020-03-28 17:22:46 +00:00
|
|
|
from module.logger import logger
|
|
|
|
from module.map.fleet import Fleet
|
|
|
|
from module.map.grid_info import GridInfo
|
|
|
|
from module.map.map_grids import SelectedGrids, RoadGrids
|
|
|
|
|
|
|
|
|
|
|
|
class Map(Fleet):
|
2020-03-30 04:27:18 +00:00
|
|
|
def clear_chosen_enemy(self, grid, expected=''):
|
2020-03-28 17:22:46 +00:00
|
|
|
"""
|
|
|
|
Args:
|
|
|
|
grid (GridInfo):
|
2020-04-07 05:49:31 +00:00
|
|
|
expected (str):
|
2020-03-28 17:22:46 +00:00
|
|
|
"""
|
|
|
|
logger.info('Clear enemy: %s' % grid)
|
2020-03-31 17:41:17 +00:00
|
|
|
expected = f'combat_{expected}' if expected else 'combat'
|
2020-03-28 17:22:46 +00:00
|
|
|
self.show_fleet()
|
2020-04-06 17:52:47 +00:00
|
|
|
if self.config.ENABLE_EMOTION_REDUCE and self.config.ENABLE_MAP_FLEET_LOCK:
|
|
|
|
self.emotion.wait(fleet=self.fleet_current_index)
|
2020-03-31 17:41:17 +00:00
|
|
|
self.goto(grid, expected=expected)
|
2020-03-28 17:22:46 +00:00
|
|
|
|
2020-04-24 15:45:33 +00:00
|
|
|
self.full_scan()
|
|
|
|
self.find_path_initial()
|
2020-04-07 05:49:31 +00:00
|
|
|
self.map.show_cost()
|
2020-03-28 17:22:46 +00:00
|
|
|
|
|
|
|
def clear_chosen_mystery(self, grid):
|
|
|
|
"""
|
|
|
|
Args:
|
|
|
|
grid (GridInfo):
|
|
|
|
"""
|
|
|
|
logger.info('Clear mystery: %s' % grid)
|
|
|
|
self.show_fleet()
|
|
|
|
self.goto(grid, expected='mystery')
|
|
|
|
# self.mystery_count += 1
|
2020-04-07 05:49:31 +00:00
|
|
|
self.map.show_cost()
|
2020-03-28 17:22:46 +00:00
|
|
|
|
|
|
|
def pick_up_ammo(self, grid=None):
|
|
|
|
"""
|
|
|
|
Args:
|
|
|
|
grid (GridInfo):
|
|
|
|
"""
|
|
|
|
if grid is None:
|
|
|
|
grid = self.map.select(may_ammo=True)
|
|
|
|
if not grid:
|
2020-04-21 15:10:58 +00:00
|
|
|
logger.info('Map has no ammo.')
|
2020-04-18 16:49:33 +00:00
|
|
|
return False
|
2020-03-28 17:22:46 +00:00
|
|
|
grid = grid[0]
|
|
|
|
|
2020-04-21 15:10:58 +00:00
|
|
|
if self.ammo_count > 0 and grid.is_accessible:
|
2020-03-28 17:22:46 +00:00
|
|
|
logger.info('Pick up ammo: %s' % grid)
|
|
|
|
self.goto(grid, expected='')
|
|
|
|
self.ensure_no_info_bar()
|
|
|
|
|
|
|
|
# self.ammo_count -= 5 - self.battle_count
|
|
|
|
recover = 5 - self.fleet_ammo
|
|
|
|
recover = 3 if recover > 3 else recover
|
|
|
|
logger.attr('Got ammo', recover)
|
|
|
|
|
|
|
|
self.ammo_count -= recover
|
|
|
|
self.fleet_ammo += recover
|
|
|
|
|
2020-04-07 05:49:31 +00:00
|
|
|
@staticmethod
|
|
|
|
def select_grids(grids, nearby=False, is_accessible=True, scale=(), strongest=False, weakest=False, cost=True,
|
2020-04-13 08:07:32 +00:00
|
|
|
weight=True, ignore=None):
|
2020-03-28 17:22:46 +00:00
|
|
|
"""
|
|
|
|
Args:
|
|
|
|
grids (SelectedGrids):
|
2020-04-07 05:49:31 +00:00
|
|
|
nearby (bool):
|
|
|
|
is_accessible (bool):
|
|
|
|
scale (tuple[int]):
|
|
|
|
strongest (bool):
|
|
|
|
weakest (bool):
|
|
|
|
cost (bool):
|
|
|
|
weight (bool):
|
|
|
|
ignore (SelectedGrids):
|
2020-03-28 17:22:46 +00:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
SelectedGrids:
|
|
|
|
"""
|
|
|
|
if nearby:
|
|
|
|
grids = grids.select(is_nearby=True)
|
|
|
|
if is_accessible:
|
|
|
|
grids = grids.select(is_accessible=True)
|
|
|
|
if ignore is not None:
|
|
|
|
grids = grids.delete(grids=ignore)
|
|
|
|
if len(scale):
|
|
|
|
enemy = SelectedGrids([])
|
|
|
|
for enemy_scale in scale:
|
|
|
|
enemy = enemy.add(grids.select(enemy_scale=enemy_scale))
|
|
|
|
grids = enemy
|
|
|
|
if strongest:
|
|
|
|
for scale in [3, 2, 1, 0]:
|
|
|
|
enemy = grids.select(enemy_scale=scale)
|
|
|
|
if enemy:
|
|
|
|
grids = enemy
|
|
|
|
break
|
|
|
|
if weakest:
|
|
|
|
for scale in [1, 2, 3, 0]:
|
|
|
|
enemy = grids.select(enemy_scale=scale)
|
|
|
|
if enemy:
|
|
|
|
grids = enemy
|
|
|
|
break
|
|
|
|
|
|
|
|
if grids:
|
|
|
|
grids = grids.sort(cost=cost, weight=weight)
|
|
|
|
|
|
|
|
return grids
|
|
|
|
|
2020-04-07 05:49:31 +00:00
|
|
|
@staticmethod
|
|
|
|
def show_select_grids(grids, **kwargs):
|
|
|
|
length = 3
|
|
|
|
keys = list(kwargs.keys())
|
|
|
|
for index in range(0, len(keys), length):
|
2020-04-18 19:42:12 +00:00
|
|
|
text = [f'{key}={kwargs[key]}' for key in keys[index:index + length]]
|
|
|
|
text = ', '.join(text)
|
2020-04-07 05:49:31 +00:00
|
|
|
logger.info(text)
|
2020-03-28 17:22:46 +00:00
|
|
|
|
2020-04-07 05:49:31 +00:00
|
|
|
logger.info(f'Grids: {grids}')
|
2020-03-28 17:22:46 +00:00
|
|
|
|
2020-04-07 05:49:31 +00:00
|
|
|
def clear_all_mystery(self, **kwargs):
|
|
|
|
"""Methods to pick up all mystery.
|
2020-03-28 17:22:46 +00:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
bool: False, because didn't clear any enemy.
|
|
|
|
"""
|
|
|
|
while 1:
|
2020-04-07 05:49:31 +00:00
|
|
|
grids = self.map.select(is_mystery=True)
|
|
|
|
grids = self.select_grids(grids, **kwargs)
|
|
|
|
|
2020-03-28 17:22:46 +00:00
|
|
|
if not grids:
|
|
|
|
break
|
|
|
|
|
|
|
|
logger.hr('Clear all mystery')
|
2020-04-07 05:49:31 +00:00
|
|
|
self.show_select_grids(grids, **kwargs)
|
2020-03-28 17:22:46 +00:00
|
|
|
self.clear_chosen_mystery(grids[0])
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
2020-04-07 05:49:31 +00:00
|
|
|
def clear_enemy(self, **kwargs):
|
|
|
|
"""Methods to clear a enemy. May not do anything if no suitable enemy.
|
2020-03-28 17:22:46 +00:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
bool: True if clear an enemy.
|
|
|
|
"""
|
2020-04-18 16:49:33 +00:00
|
|
|
grids = self.map.select(is_enemy=True, is_boss=False)
|
2020-04-07 05:49:31 +00:00
|
|
|
grids = self.select_grids(grids, **kwargs)
|
2020-03-28 17:22:46 +00:00
|
|
|
|
|
|
|
if grids:
|
|
|
|
logger.hr('Clear enemy')
|
2020-04-07 05:49:31 +00:00
|
|
|
self.show_select_grids(grids, **kwargs)
|
2020-03-28 17:22:46 +00:00
|
|
|
self.clear_chosen_enemy(grids[0])
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
2020-04-07 05:49:31 +00:00
|
|
|
def clear_roadblocks(self, roads, **kwargs):
|
2020-03-28 17:22:46 +00:00
|
|
|
"""Clear roadblocks.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
roads(list[RoadGrids]):
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
bool: True if clear an enemy.
|
|
|
|
"""
|
|
|
|
grids = SelectedGrids([])
|
|
|
|
for road in roads:
|
|
|
|
grids = grids.add(road.roadblocks())
|
|
|
|
|
2020-04-07 05:49:31 +00:00
|
|
|
grids = self.select_grids(grids, **kwargs)
|
2020-03-28 17:22:46 +00:00
|
|
|
|
|
|
|
if grids:
|
|
|
|
logger.hr('Clear roadblock')
|
2020-04-07 05:49:31 +00:00
|
|
|
self.show_select_grids(grids, **kwargs)
|
2020-03-28 17:22:46 +00:00
|
|
|
self.clear_chosen_enemy(grids[0])
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
def clear_potential_roadblocks(self, roads, **kwargs):
|
|
|
|
"""Avoid roadblock that only has one grid empty.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
roads(list[RoadGrids]):
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
bool: True if clear an enemy.
|
|
|
|
"""
|
|
|
|
grids = SelectedGrids([])
|
|
|
|
for road in roads:
|
|
|
|
grids = grids.add(road.potential_roadblocks())
|
|
|
|
|
2020-04-07 05:49:31 +00:00
|
|
|
grids = self.select_grids(grids, **kwargs)
|
2020-03-28 17:22:46 +00:00
|
|
|
|
|
|
|
if grids:
|
|
|
|
logger.hr('Avoid potential roadblock')
|
2020-04-07 05:49:31 +00:00
|
|
|
self.show_select_grids(grids, **kwargs)
|
2020-03-28 17:22:46 +00:00
|
|
|
self.clear_chosen_enemy(grids[0])
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
2020-04-07 05:49:31 +00:00
|
|
|
def clear_grids_for_faster(self, grids, **kwargs):
|
2020-03-28 17:22:46 +00:00
|
|
|
"""Clear some grids to walk a shorter distance.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
grids(SelectedGrids):
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
bool: True if clear an enemy.
|
|
|
|
"""
|
|
|
|
|
2020-04-07 05:49:31 +00:00
|
|
|
grids = grids.select(is_enemy=True)
|
|
|
|
grids = self.select_grids(grids, **kwargs)
|
2020-03-28 17:22:46 +00:00
|
|
|
|
|
|
|
if grids:
|
|
|
|
logger.hr('Clear grids for faster')
|
2020-04-07 05:49:31 +00:00
|
|
|
self.show_select_grids(grids, **kwargs)
|
2020-03-28 17:22:46 +00:00
|
|
|
self.clear_chosen_enemy(grids[0])
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
def clear_boss(self):
|
|
|
|
"""Clear BOSS.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
bool:
|
|
|
|
"""
|
|
|
|
grids = self.map.select(is_boss=True, is_accessible=True)
|
|
|
|
logger.info('Is boss: %s' % self.map.select(is_boss=True))
|
2020-04-18 19:42:12 +00:00
|
|
|
if not grids.count:
|
|
|
|
grids = grids.add(self.map.select(may_boss=True, is_enemy=True, is_accessible=True))
|
|
|
|
logger.warning('Boss not detected, using may_boss grids.')
|
|
|
|
logger.info('May boss: %s' % self.map.select(may_boss=True))
|
|
|
|
logger.info('May boss and is enemy: %s' % self.map.select(may_boss=True, is_enemy=True))
|
2020-03-28 17:22:46 +00:00
|
|
|
|
|
|
|
if grids:
|
|
|
|
logger.hr('Clear BOSS')
|
|
|
|
grids = grids.sort(cost=True, weight=True)
|
|
|
|
logger.info('Grids: %s' % str(grids))
|
2020-04-24 15:20:34 +00:00
|
|
|
self.clear_chosen_enemy(grids[0])
|
2020-03-28 17:22:46 +00:00
|
|
|
|
2020-04-06 17:52:47 +00:00
|
|
|
logger.warning('BOSS not detected, trying all boss spawn point.')
|
2020-05-07 11:55:06 +00:00
|
|
|
return self.clear_potential_boss()
|
2020-03-28 17:22:46 +00:00
|
|
|
|
2020-04-06 17:52:47 +00:00
|
|
|
def clear_potential_boss(self):
|
|
|
|
"""
|
|
|
|
Method to step on all boss spawn point when boss not detected.
|
|
|
|
"""
|
|
|
|
grids = self.map.select(may_boss=True, is_accessible=True)
|
|
|
|
logger.info('May boss: %s' % self.map.select(may_boss=True))
|
2020-05-07 11:55:06 +00:00
|
|
|
battle_count = self.battle_count
|
2020-04-06 17:52:47 +00:00
|
|
|
|
|
|
|
for grid in grids:
|
2020-05-07 11:55:06 +00:00
|
|
|
logger.hr('Clear potential BOSS')
|
2020-04-06 17:52:47 +00:00
|
|
|
grids = grids.sort(cost=True, weight=True)
|
|
|
|
logger.info('Grid: %s' % str(grid))
|
2020-04-22 17:58:35 +00:00
|
|
|
self.clear_chosen_enemy(grid)
|
2020-05-22 20:42:31 +00:00
|
|
|
if self.battle_count > battle_count:
|
|
|
|
logger.info('Boss guessing correct.')
|
2020-05-07 11:55:06 +00:00
|
|
|
return True
|
|
|
|
else:
|
|
|
|
logger.info('Boss guessing incorrect.')
|
|
|
|
|
|
|
|
return False
|
2020-04-06 17:52:47 +00:00
|
|
|
|
2020-04-21 15:10:58 +00:00
|
|
|
def brute_clear_boss(self):
|
|
|
|
"""
|
|
|
|
Method to clear boss, using brute-force to find roadblocks.
|
|
|
|
"""
|
|
|
|
boss = self.map.select(is_boss=True)
|
|
|
|
if boss:
|
|
|
|
logger.info('Brute clear BOSS')
|
2020-04-27 11:32:58 +00:00
|
|
|
fleet = 2 if self.config.FLEET_BOSS == 2 and self.config.FLEET_2 else 1
|
|
|
|
grids = self.brute_find_roadblocks(boss[0], fleet=fleet)
|
2020-04-21 15:10:58 +00:00
|
|
|
if grids:
|
2020-04-28 06:37:13 +00:00
|
|
|
if self.brute_fleet_meet():
|
|
|
|
return True
|
2020-04-21 15:10:58 +00:00
|
|
|
logger.info('Brute clear BOSS roadblocks')
|
|
|
|
grids = grids.sort(cost=True, weight=True)
|
|
|
|
logger.info('Grids: %s' % str(grids))
|
|
|
|
self.clear_chosen_enemy(grids[0])
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return self.fleet_boss.clear_boss()
|
|
|
|
else:
|
2020-05-07 11:55:06 +00:00
|
|
|
logger.warning('BOSS not detected, trying all boss spawn point.')
|
|
|
|
return self.clear_potential_boss()
|
2020-04-21 15:10:58 +00:00
|
|
|
|
2020-04-21 15:52:04 +00:00
|
|
|
def brute_fleet_meet(self):
|
|
|
|
"""
|
|
|
|
Method to clear roadblocks between fleets, using brute-force to find roadblocks.
|
|
|
|
"""
|
2020-04-24 07:26:11 +00:00
|
|
|
if not self.config.FLEET_2 or not self.fleet_2_location:
|
2020-04-21 15:52:04 +00:00
|
|
|
return False
|
|
|
|
grids = self.brute_find_roadblocks(self.map[self.fleet_2_location], fleet=1)
|
|
|
|
if grids:
|
|
|
|
logger.info('Brute clear roadblocks between fleets.')
|
|
|
|
grids = grids.sort(cost=True, weight=True)
|
|
|
|
logger.info('Grids: %s' % str(grids))
|
|
|
|
self.clear_chosen_enemy(grids[0])
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
2020-04-07 05:49:31 +00:00
|
|
|
def clear_siren(self, **kwargs):
|
|
|
|
"""
|
|
|
|
Returns:
|
|
|
|
bool: True if clear an enemy.
|
|
|
|
"""
|
2020-04-24 07:26:11 +00:00
|
|
|
if not self.config.MAP_HAS_SIREN:
|
|
|
|
return False
|
|
|
|
|
2020-03-30 04:27:18 +00:00
|
|
|
logger.info('May siren: %s' % self.map.select(may_siren=True))
|
|
|
|
logger.info('May siren and is enemy: %s' % self.map.select(may_siren=True, is_enemy=True))
|
2020-04-25 10:04:05 +00:00
|
|
|
grids = self.map.select(may_siren=True, is_enemy=True)
|
|
|
|
|
2020-03-30 04:27:18 +00:00
|
|
|
logger.info('Is siren: %s' % self.map.select(is_siren=True))
|
2020-04-25 10:04:05 +00:00
|
|
|
grids = grids.add(self.map.select(is_siren=True))
|
|
|
|
|
|
|
|
if self.config.POOR_MAP_DATA or not self.is_map_green:
|
|
|
|
logger.info('Is 0 scale enemy: %s' % self.map.select(is_enemy=True, enemy_scale=0))
|
|
|
|
grids = grids.add(self.map.select(is_enemy=True, enemy_scale=0))
|
|
|
|
|
2020-04-24 07:26:11 +00:00
|
|
|
logger.info('Delete is boss: %s' % self.map.select(is_boss=True))
|
2020-04-25 10:04:05 +00:00
|
|
|
grids = grids.delete(self.map.select(is_boss=True))
|
2020-03-28 17:22:46 +00:00
|
|
|
|
2020-04-07 05:49:31 +00:00
|
|
|
grids = self.select_grids(grids, **kwargs)
|
|
|
|
|
2020-03-28 17:22:46 +00:00
|
|
|
if grids:
|
|
|
|
logger.hr('Clear siren')
|
2020-04-07 05:49:31 +00:00
|
|
|
self.show_select_grids(grids, **kwargs)
|
2020-03-30 04:27:18 +00:00
|
|
|
self.clear_chosen_enemy(grids[0], expected='siren')
|
2020-03-28 17:22:46 +00:00
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
def fleet_2_step_on(self, grids, roadblocks):
|
|
|
|
"""Fleet step on a grid which can reduce the ambush frequency another fleet.
|
|
|
|
Of course, you can simply use 'self.fleet_2.goto(grid)' and do the same thing.
|
|
|
|
However, roads can be block by enemy and this method can handle that.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
grids (SelectedGrids):
|
|
|
|
roadblocks (list[RoadGrids]):
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
bool: if clear an enemy.
|
|
|
|
"""
|
|
|
|
for grid in grids:
|
|
|
|
if self.fleet_at(grid=grid, fleet=2):
|
|
|
|
return False
|
|
|
|
|
2020-04-18 08:19:31 +00:00
|
|
|
logger.info('Fleet 2 step on')
|
2020-03-28 17:22:46 +00:00
|
|
|
for grid in grids:
|
2020-04-18 08:19:31 +00:00
|
|
|
if grid.is_enemy or grid.is_cleared:
|
2020-03-28 17:22:46 +00:00
|
|
|
continue
|
|
|
|
if self.check_accessibility(grid=grid, fleet=2):
|
|
|
|
logger.info('Fleet_2 step on %s' % grid)
|
|
|
|
self.fleet_2.goto(grid)
|
|
|
|
self.fleet_1.switch_to()
|
|
|
|
return False
|
|
|
|
|
2020-04-19 03:53:11 +00:00
|
|
|
logger.info('Fleet_2 step on got roadblocks.')
|
2020-04-18 08:19:31 +00:00
|
|
|
self.fleet_1.clear_roadblocks(roadblocks)
|
|
|
|
self.fleet_1.clear_all_mystery()
|
|
|
|
return True
|
2020-05-23 06:30:07 +00:00
|
|
|
|
|
|
|
def fleet_2_break_siren_caught(self):
|
|
|
|
if not self.config.MAP_HAS_SIREN or not self.config.MAP_HAS_MOVABLE_ENEMY:
|
|
|
|
return False
|
|
|
|
if not self.map.select(is_caught_by_siren=True):
|
|
|
|
logger.info('No fleet caught by siren.')
|
|
|
|
return False
|
|
|
|
if not self.fleet_2_location or not self.map[self.fleet_2_location].is_caught_by_siren:
|
|
|
|
logger.warning('Appear caught by siren, but not fleet_2.')
|
|
|
|
for grid in self.map:
|
|
|
|
grid.is_caught_by_siren = False
|
|
|
|
return False
|
|
|
|
|
|
|
|
logger.info(f'Break siren caught, fleet_2: {self.fleet_2_location}')
|
|
|
|
self.fleet_2.switch_to()
|
|
|
|
self.ensure_edge_insight(reverse=True)
|
|
|
|
self.clear_chosen_enemy(self.map[self.fleet_2_location])
|
|
|
|
self.fleet_1.switch_to()
|
|
|
|
for grid in self.map:
|
|
|
|
grid.is_caught_by_siren = False
|
|
|
|
return True
|
|
|
|
|