Skip to content

Commit

Permalink
Opt: choose the highest emotion vanguard ship
Browse files Browse the repository at this point in the history
  • Loading branch information
Air111 committed Jun 14, 2024
1 parent c46a3df commit 5bef4fb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
13 changes: 3 additions & 10 deletions module/campaign/gems_farming.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,27 +310,20 @@ def get_common_rarity_dd(self):
max_level = 70

scanner = ShipScanner(level=(max_level, max_level), emotion=(1 + EMOTION_LIMIT + self.emotion_expected_reduce, 150),
fleet=self.fleet_to_attack, status='free')
fleet=[0, self.fleet_to_attack], status='free')
scanner.disable('rarity')

self.dock_sort_method_dsc_set()

ships = scanner.scan(self.device.image)
if ships:
# Don't need to change current
return ships

scanner.set_limitation(fleet=0)
self.dock_favourite_set(self.config.GemsFarming_CommonDD == 'favourite')

if self.config.GemsFarming_CommonDD in ['any', 'favourite', 'z20_or_z21']:
return scanner.scan(self.device.image, output=False)
return scanner.scan(self.device.image)

candidates = self.find_candidates(self.get_templates(self.config.GemsFarming_CommonDD), scanner)

if candidates:
return candidates

logger.info('No specific DD was found, try reversed order.')
self.dock_sort_method_dsc_set(False)

Expand Down
26 changes: 16 additions & 10 deletions module/retire/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ class Ship:
status: str = ''
button: Any = None

def satisfy_limitation(self, limitaion) -> bool:
def satisfy_limitation(self, limitation) -> bool:
for key in self.__dict__:
value = limitaion.get(key)
value = limitation.get(key)
if self.__dict__[key] is not None and value is not None:
# str and int should be exactly equal to
if isinstance(value, (str, int)):
Expand All @@ -52,6 +52,10 @@ def satisfy_limitation(self, limitaion) -> bool:
elif isinstance(value, tuple):
if not (value[0] <= self.__dict__[key] <= value[1]):
return False
# list means should be a member
elif isinstance(value, list):
if self.__dict__[key] not in value:
return False

return True

Expand Down Expand Up @@ -297,7 +301,7 @@ def __init__(
super().__init__()
self._results = []
self.grids = CARD_GRIDS
self.limitaion: Dict[str, Union[str, int, Tuple[int, int]]] = {
self.limitation: Dict[str, Union[str, int, Tuple[int, int]]] = {
'level': (1, 125),
'emotion': (0, 150),
'rarity': 'any',
Expand Down Expand Up @@ -347,7 +351,7 @@ def _scan(self, image) -> List:
def scan(self, image, cached=False, output=True) -> Union[List, None]:
ships = super().scan(image, cached, output)
if not cached:
return [ship for ship in ships if ship.satisfy_limitation(self.limitaion)]
return [ship for ship in ships if ship.satisfy_limitation(self.limitation)]

def move(self, vector) -> None:
"""
Expand All @@ -360,14 +364,16 @@ def move(self, vector) -> None:

def limit_value(self, key, value) -> None:
if value is None:
self.limitaion[key] = None
self.limitation[key] = None
elif isinstance(value, tuple):
lower, upper = value
lower = self.sub_scanners[key].limit_value(lower)
upper = self.sub_scanners[key].limit_value(upper)
self.limitaion[key] = (lower, upper)
self.limitation[key] = (lower, upper)
elif isinstance(value, list):
self.limitation[key] = [self.sub_scanners[key].limit_value(v) for v in value]
else:
self.limitaion[key] = self.sub_scanners[key].limit_value(value)
self.limitation[key] = self.sub_scanners[key].limit_value(value)

def enable(self, *args) -> None:
"""
Expand Down Expand Up @@ -400,11 +406,11 @@ def set_limitation(self, **kwargs):
fleet (int): 0 means not in any fleet. Will be limited in range [0, 6]
status (str, list): ['any', 'commission', 'battle']
"""
for attr in self.limitaion.keys():
value = kwargs.get(attr, self.limitaion[attr])
for attr in self.limitation.keys():
value = kwargs.get(attr, self.limitation[attr])
self.limit_value(key=attr, value=value)

logger.info(f'Limitaions set to {self.limitaion}')
logger.info(f'Limitations set to {self.limitation}')


class DockScanner(ShipScanner):
Expand Down

0 comments on commit 5bef4fb

Please sign in to comment.