mirror of
https://github.com/LmeSzinc/StarRailCopilot.git
synced 2024-11-23 00:52:22 +00:00
Add: 增加选择敌人类型
- 更改enemy_type为enemy_genre
This commit is contained in:
parent
eb2a58d7f5
commit
aa0e38a28c
@ -87,11 +87,11 @@ class Campaign(CampaignBase):
|
||||
if self.battle_count >= self.config.C124_AMMO_PICK_UP:
|
||||
self.pick_up_ammo()
|
||||
|
||||
if self.clear_enemy(scale=(3,)):
|
||||
if self.clear_enemy(scale=(3,), genre=['light', 'carrier']):
|
||||
self.s3_enemy_count += 1
|
||||
self.non_s3_enemy_count = 0
|
||||
return True
|
||||
if self.clear_enemy(scale=(2,)):
|
||||
if self.clear_enemy(scale=[2, 1]):
|
||||
self.non_s3_enemy_count += 1
|
||||
return True
|
||||
if not self.map.select(is_enemy=True, may_boss=False):
|
||||
|
@ -74,6 +74,10 @@ class Campaign(CampaignBase):
|
||||
def battle_0(self):
|
||||
if self.clear_siren():
|
||||
return True
|
||||
if self.clear_enemy(scale=(2, 1)):
|
||||
return True
|
||||
if self.clear_enemy(genre=['light', 'main']):
|
||||
return True
|
||||
|
||||
return self.battle_default()
|
||||
|
||||
|
@ -43,7 +43,7 @@ class GridInfo:
|
||||
is_siren = False # SI
|
||||
|
||||
enemy_scale = 0
|
||||
enemy_type = None # Light, Main, Carrier, Treasure, Enemy(unknown)
|
||||
enemy_genre = None # Light, Main, Carrier, Treasure, Enemy(unknown)
|
||||
|
||||
is_cleared = False
|
||||
is_ambush_save = False
|
||||
@ -83,10 +83,10 @@ class GridInfo:
|
||||
return key
|
||||
|
||||
if self.is_siren:
|
||||
return ''.join([text[0] for text in self.enemy_type.split('_')]).upper() if self.enemy_type else 'SU'
|
||||
return ''.join([text[0] for text in self.enemy_genre.split('_')]).upper() if self.enemy_genre else 'SU'
|
||||
|
||||
if self.is_enemy:
|
||||
return '%s%s' % (self.enemy_scale, self.enemy_type[0].upper()) if self.enemy_type else '0E'
|
||||
return '%s%s' % (self.enemy_scale, self.enemy_genre[0].upper()) if self.enemy_genre else '0E'
|
||||
|
||||
dic = {
|
||||
'FL': 'is_current_fleet',
|
||||
@ -146,7 +146,7 @@ class GridInfo:
|
||||
self.__setattr__('is_' + item, True)
|
||||
# self.is_enemy = True
|
||||
# self.enemy_scale = 0
|
||||
self.enemy_type = info.enemy_type
|
||||
self.enemy_genre = info.enemy_genre
|
||||
return True
|
||||
else:
|
||||
logger.info(f'Wrong Prediction. Grid: {self}, Attr: is_{item}')
|
||||
@ -161,7 +161,7 @@ class GridInfo:
|
||||
if flag:
|
||||
self.is_enemy = True
|
||||
self.enemy_scale = info.enemy_scale
|
||||
self.enemy_type = info.enemy_type
|
||||
self.enemy_genre = info.enemy_genre
|
||||
if self.may_siren:
|
||||
self.is_siren = True
|
||||
return True
|
||||
@ -190,7 +190,7 @@ class GridInfo:
|
||||
"""
|
||||
self.is_enemy = False
|
||||
self.enemy_scale = 0
|
||||
self.enemy_type = None
|
||||
self.enemy_genre = None
|
||||
self.is_mystery = False
|
||||
self.is_boss = False
|
||||
self.is_ammo = False
|
||||
|
@ -11,7 +11,7 @@ class GridPredictor:
|
||||
ENEMY_SCALE_IMAGE_SIZE = (50, 50)
|
||||
ENEMY_PERSPECTIVE_IMAGE_SIZE = (50, 50)
|
||||
RED_BORDER_IGNORE_TOP = 10
|
||||
DIC_ENEMY_TYPE = {
|
||||
DIC_ENEMY_GENRE = {
|
||||
# 'Siren_1': TEMPLATE_SIREN_1,
|
||||
# 'Siren_2': TEMPLATE_SIREN_2,
|
||||
# 'Siren_3': TEMPLATE_SIREN_3,
|
||||
@ -56,7 +56,7 @@ class GridPredictor:
|
||||
self.image_transform = self.image.transform(self.ENEMY_PERSPECTIVE_IMAGE_SIZE, Image.PERSPECTIVE, self._perspective)
|
||||
|
||||
self.enemy_scale = self.predict_enemy_scale()
|
||||
self.enemy_type = self.predict_enemy_type()
|
||||
self.enemy_genre = self.predict_enemy_genre()
|
||||
|
||||
self.is_mystery = self.predict_mystery()
|
||||
self.is_fleet = self.predict_fleet()
|
||||
@ -67,20 +67,20 @@ class GridPredictor:
|
||||
if self.config.MAP_HAS_DYNAMIC_RED_BORDER:
|
||||
if not self.is_enemy and not self.is_mystery:
|
||||
if self.predict_dynamic_red_border():
|
||||
self.enemy_type = 'Siren_unknown'
|
||||
self.enemy_genre = 'Siren_unknown'
|
||||
if self.config.MAP_HAS_MOVABLE_ENEMY:
|
||||
self.is_caught_by_siren = self.predict_siren_caught()
|
||||
|
||||
if self.enemy_type:
|
||||
if self.enemy_genre:
|
||||
self.is_enemy = True
|
||||
if self.enemy_scale:
|
||||
self.is_enemy = True
|
||||
if not self.is_enemy:
|
||||
self.is_enemy = self.predict_static_red_border()
|
||||
if self.is_enemy and not self.enemy_type:
|
||||
self.enemy_type = 'Enemy'
|
||||
if self.is_enemy and not self.enemy_genre:
|
||||
self.enemy_genre = 'Enemy'
|
||||
if self.config.MAP_HAS_SIREN:
|
||||
if self.enemy_type is not None and self.enemy_type.startswith('Siren'):
|
||||
if self.enemy_genre is not None and self.enemy_genre.startswith('Siren'):
|
||||
self.is_siren = True
|
||||
self.enemy_scale = 0
|
||||
|
||||
@ -254,14 +254,14 @@ class GridPredictor:
|
||||
image = self.get_relative_image((-1, -1.5, 1, 0.5), output_shape=(120, 120))
|
||||
return TEMPLATE_CAUGHT_BY_SIREN.match(image, similarity=0.6)
|
||||
|
||||
def predict_enemy_type(self):
|
||||
def predict_enemy_genre(self):
|
||||
image = self.get_relative_image((-1, -1, 1, 0), output_shape=(120, 60))
|
||||
if not self.SIREN_TEMPLATE_LOADED:
|
||||
for name in self.config.MAP_SIREN_TEMPLATE:
|
||||
self.DIC_ENEMY_TYPE[f'Siren_{name}'] = globals().get(f'TEMPLATE_SIREN_{name}')
|
||||
self.DIC_ENEMY_GENRE[f'Siren_{name}'] = globals().get(f'TEMPLATE_SIREN_{name}')
|
||||
self.SIREN_TEMPLATE_LOADED = True
|
||||
|
||||
for name, template in self.DIC_ENEMY_TYPE.items():
|
||||
for name, template in self.DIC_ENEMY_GENRE.items():
|
||||
if not self.config.MAP_HAS_SIREN and name.startswith('Siren'):
|
||||
continue
|
||||
if template.match(image):
|
||||
|
@ -59,14 +59,15 @@ class Map(Fleet):
|
||||
self.fleet_ammo += recover
|
||||
|
||||
@staticmethod
|
||||
def select_grids(grids, nearby=False, is_accessible=True, scale=(), strongest=False, weakest=False, cost=True,
|
||||
weight=True, ignore=None):
|
||||
def select_grids(grids, nearby=False, is_accessible=True, scale=(), genre=(), strongest=False, weakest=False,
|
||||
cost=True, weight=True, ignore=None):
|
||||
"""
|
||||
Args:
|
||||
grids (SelectedGrids):
|
||||
nearby (bool):
|
||||
is_accessible (bool):
|
||||
scale (tuple[int]):
|
||||
scale (tuple[int], list[int]): Tuple: select out of order, list: select in order.
|
||||
genre (tuple[str], list[str]): light, main, carrier, treasure. (Case insensitive).
|
||||
strongest (bool):
|
||||
weakest (bool):
|
||||
cost (bool):
|
||||
@ -86,6 +87,15 @@ class Map(Fleet):
|
||||
enemy = SelectedGrids([])
|
||||
for enemy_scale in scale:
|
||||
enemy = enemy.add(grids.select(enemy_scale=enemy_scale))
|
||||
if isinstance(scale, list) and enemy:
|
||||
break
|
||||
grids = enemy
|
||||
if len(genre):
|
||||
enemy = SelectedGrids([])
|
||||
for enemy_genre in genre:
|
||||
enemy = enemy.add(grids.select(enemy_genre=enemy_genre.capitalize()))
|
||||
if isinstance(genre, list) and enemy:
|
||||
break
|
||||
grids = enemy
|
||||
if strongest:
|
||||
for scale in [3, 2, 1, 0]:
|
||||
@ -385,4 +395,3 @@ class Map(Fleet):
|
||||
for grid in self.map:
|
||||
grid.is_caught_by_siren = False
|
||||
return True
|
||||
|
||||
|
@ -76,7 +76,8 @@ class SelectedGrids:
|
||||
for grid in self:
|
||||
flag = True
|
||||
for k, v in kwargs.items():
|
||||
if grid.__getattribute__(k) != v:
|
||||
grid_v = grid.__getattribute__(k)
|
||||
if type(grid_v) != type(v) or grid_v != v:
|
||||
flag = False
|
||||
if flag:
|
||||
result.append(grid)
|
||||
|
Loading…
Reference in New Issue
Block a user