diff --git a/assets/tw/coalition/HORROR_COALITION_CHECK.png b/assets/tw/coalition/HORROR_COALITION_CHECK.png index b758551d2..09c1b742e 100644 Binary files a/assets/tw/coalition/HORROR_COALITION_CHECK.png and b/assets/tw/coalition/HORROR_COALITION_CHECK.png differ diff --git a/module/coalition/assets.py b/module/coalition/assets.py index 6934be5e4..04c646855 100644 --- a/module/coalition/assets.py +++ b/module/coalition/assets.py @@ -60,7 +60,7 @@ FROSTFALL_SWITCH_SINGLE = Button(area={'cn': (968, 449, 1098, 478), 'en': (968, FROSTFALL_TC1 = Button(area={'cn': (304, 320, 330, 332), 'en': (304, 320, 330, 332), 'jp': (304, 320, 330, 332), 'tw': (304, 320, 330, 332)}, color={'cn': (204, 162, 254), 'en': (204, 162, 254), 'jp': (204, 162, 254), 'tw': (188, 137, 254)}, button={'cn': (304, 320, 330, 332), 'en': (304, 320, 330, 332), 'jp': (304, 320, 330, 332), 'tw': (304, 320, 330, 332)}, file={'cn': './assets/cn/coalition/FROSTFALL_TC1.png', 'en': './assets/en/coalition/FROSTFALL_TC1.png', 'jp': './assets/jp/coalition/FROSTFALL_TC1.png', 'tw': './assets/tw/coalition/FROSTFALL_TC1.png'}) FROSTFALL_TC2 = Button(area={'cn': (631, 160, 658, 173), 'en': (631, 160, 658, 173), 'jp': (631, 160, 658, 173), 'tw': (631, 160, 658, 173)}, color={'cn': (186, 136, 252), 'en': (186, 136, 252), 'jp': (186, 136, 252), 'tw': (186, 136, 252)}, button={'cn': (631, 160, 658, 173), 'en': (631, 160, 658, 173), 'jp': (631, 160, 658, 173), 'tw': (631, 160, 658, 173)}, file={'cn': './assets/cn/coalition/FROSTFALL_TC2.png', 'en': './assets/en/coalition/FROSTFALL_TC2.png', 'jp': './assets/jp/coalition/FROSTFALL_TC2.png', 'tw': './assets/tw/coalition/FROSTFALL_TC2.png'}) FROSTFALL_TC3 = Button(area={'cn': (810, 362, 835, 373), 'en': (810, 362, 835, 373), 'jp': (810, 362, 835, 373), 'tw': (810, 362, 835, 373)}, color={'cn': (197, 153, 255), 'en': (197, 153, 255), 'jp': (197, 153, 255), 'tw': (197, 153, 255)}, button={'cn': (810, 362, 835, 373), 'en': (810, 362, 835, 373), 'jp': (810, 362, 835, 373), 'tw': (810, 362, 835, 373)}, file={'cn': './assets/cn/coalition/FROSTFALL_TC3.png', 'en': './assets/en/coalition/FROSTFALL_TC3.png', 'jp': './assets/jp/coalition/FROSTFALL_TC3.png', 'tw': './assets/tw/coalition/FROSTFALL_TC3.png'}) -HORROR_COALITION_CHECK = Button(area={'cn': (204, 49, 250, 70), 'en': (182, 40, 238, 65), 'jp': (204, 50, 250, 67), 'tw': (186, 24, 223, 57)}, color={'cn': (142, 142, 164), 'en': (161, 158, 163), 'jp': (136, 137, 159), 'tw': (146, 146, 157)}, button={'cn': (204, 49, 250, 70), 'en': (182, 40, 238, 65), 'jp': (204, 50, 250, 67), 'tw': (186, 24, 223, 57)}, file={'cn': './assets/cn/coalition/HORROR_COALITION_CHECK.png', 'en': './assets/en/coalition/HORROR_COALITION_CHECK.png', 'jp': './assets/jp/coalition/HORROR_COALITION_CHECK.png', 'tw': './assets/tw/coalition/HORROR_COALITION_CHECK.png'}) +HORROR_COALITION_CHECK = Button(area={'cn': (204, 49, 250, 70), 'en': (182, 40, 238, 65), 'jp': (204, 50, 250, 67), 'tw': (186, 24, 222, 57)}, color={'cn': (142, 142, 164), 'en': (161, 158, 163), 'jp': (136, 137, 159), 'tw': (148, 147, 158)}, button={'cn': (204, 49, 250, 70), 'en': (182, 40, 238, 65), 'jp': (204, 50, 250, 67), 'tw': (186, 24, 222, 57)}, file={'cn': './assets/cn/coalition/HORROR_COALITION_CHECK.png', 'en': './assets/en/coalition/HORROR_COALITION_CHECK.png', 'jp': './assets/jp/coalition/HORROR_COALITION_CHECK.png', 'tw': './assets/tw/coalition/HORROR_COALITION_CHECK.png'}) HORROR_EASY = Button(area={'cn': (863, 425, 890, 464), 'en': (863, 425, 890, 464), 'jp': (863, 425, 890, 464), 'tw': (863, 425, 890, 464)}, color={'cn': (76, 76, 96), 'en': (76, 76, 96), 'jp': (76, 76, 96), 'tw': (76, 76, 96)}, button={'cn': (863, 425, 890, 464), 'en': (863, 425, 890, 464), 'jp': (863, 425, 890, 464), 'tw': (863, 425, 890, 464)}, file={'cn': './assets/cn/coalition/HORROR_EASY.png', 'en': './assets/cn/coalition/HORROR_EASY.png', 'jp': './assets/cn/coalition/HORROR_EASY.png', 'tw': './assets/cn/coalition/HORROR_EASY.png'}) HORROR_EX = Button(area={'cn': (172, 410, 200, 448), 'en': (172, 410, 200, 448), 'jp': (172, 410, 200, 448), 'tw': (172, 410, 200, 448)}, color={'cn': (150, 101, 105), 'en': (150, 101, 105), 'jp': (150, 101, 105), 'tw': (150, 101, 105)}, button={'cn': (172, 410, 200, 448), 'en': (172, 410, 200, 448), 'jp': (172, 410, 200, 448), 'tw': (172, 410, 200, 448)}, file={'cn': './assets/cn/coalition/HORROR_EX.png', 'en': './assets/cn/coalition/HORROR_EX.png', 'jp': './assets/cn/coalition/HORROR_EX.png', 'tw': './assets/cn/coalition/HORROR_EX.png'}) HORROR_FLEET_PREPARATION = Button(area={'cn': (1026, 514, 1139, 542), 'en': (1039, 516, 1125, 538), 'jp': (1042, 514, 1124, 542), 'tw': (1026, 514, 1139, 542)}, color={'cn': (146, 132, 183), 'en': (158, 149, 194), 'jp': (135, 117, 173), 'tw': (146, 132, 183)}, button={'cn': (1026, 514, 1139, 542), 'en': (1039, 516, 1125, 538), 'jp': (1042, 514, 1124, 542), 'tw': (1026, 514, 1139, 542)}, file={'cn': './assets/cn/coalition/HORROR_FLEET_PREPARATION.png', 'en': './assets/en/coalition/HORROR_FLEET_PREPARATION.png', 'jp': './assets/jp/coalition/HORROR_FLEET_PREPARATION.png', 'tw': './assets/cn/coalition/HORROR_FLEET_PREPARATION.png'}) diff --git a/module/island/production.py b/module/island/production.py index 3176c8014..4129a904b 100644 --- a/module/island/production.py +++ b/module/island/production.py @@ -229,6 +229,8 @@ class IslandProduction(IslandRecipe, IslandDock): logger.warning(f'Failed to select character {worker} for slot {slot_id}, try to select manjuu instead') worker = 'manjuu' self.ensure_dock_page_at_top() + else: + self.island_dock_select_one(character.button) if worker == 'manjuu': self.island_dock_select_manjuu() self.island_dock_select_confirm(self.is_in_recipe_menu) diff --git a/module/island/utils.py b/module/island/utils.py index 993d3df7e..60361df55 100644 --- a/module/island/utils.py +++ b/module/island/utils.py @@ -300,6 +300,14 @@ def get_stuck_season_order_requirements(stuck_order_id): return dict(requirements) +def merge_task_target_stuck_order_items(task_target_items, stuck_order_items): + """Normalize and merge configured tasks with remaining stuck-order needs.""" + return merge_item_needs( + normalize_item_needs(task_target_items, default_period=10), + normalize_item_needs(stuck_order_items, default_period=10), + ) + + def normalize_stuck_season_order_id(stuck_order_id): try: stuck_order_id = int(stuck_order_id) diff --git a/module/island_handler/dock.py b/module/island_handler/dock.py index 51ba2d5cc..9a92185a7 100644 --- a/module/island_handler/dock.py +++ b/module/island_handler/dock.py @@ -97,13 +97,17 @@ class IslandDock(IslandUI): def ensure_dock_page_at_top(self): ISLAND_DOCK_DETECT.load_color(self.device.image) ISLAND_DOCK_DETECT._match_init = True + drag_count = 0 for _ in self.loop(timeout=10): self.prev_dock_page() + drag_count += 1 if self.appear(ISLAND_DOCK_DETECT, offset=(20, 20)): - logger.warning('Reached top of dock page') - return True + if drag_count >= 2: + logger.info('Reached top of dock page') + return True else: ISLAND_DOCK_DETECT.load_color(self.device.image) + drag_count = 0 return False def island_dock_select_one(self, button, skip_first=False): @@ -137,6 +141,7 @@ class IslandDock(IslandUI): def island_dock_select_manjuu(self): self.island_dock_sort_method_dsc_set(enable=False, wait_loading=True) + # self.ensure_dock_page_at_top() # not necessary for now since usually Manjuu is searched first scanner = CharacterScanner(self.dock_grid, identity=['Manjuu'], status='free') candidates = scanner.scan(self.device.image) if candidates: @@ -147,9 +152,11 @@ class IslandDock(IslandUI): return False def island_dock_find_character(self, identity): + self.ensure_dock_page_at_top() self.island_dock_sort_method_dsc_set(enable=True) ISLAND_DOCK_DETECT.load_color(self.device.image) ISLAND_DOCK_DETECT._match_init = True + drag_count = 0 for _ in self.loop(timeout=40, skip_first=False): # dock_grid needs refresh after each page swipe, so we need to get a new scanner each time scanner = CharacterScanner(self.dock_grid, identity=identity, status=None) @@ -159,19 +166,24 @@ class IslandDock(IslandUI): continue return candidate self.next_dock_page() + drag_count += 1 if self.appear(ISLAND_DOCK_DETECT, offset=(20, 20)): - logger.warning('Reached end of dock page') - break + if drag_count >= 2: + logger.warning('Reached end of dock page') + break else: ISLAND_DOCK_DETECT.load_color(self.device.image) + drag_count = 0 else: logger.warning('Failed to find all requested characters') return None - def island_dock_select_character_with_blacklist(self, blacklist): + def island_dock_find_character_with_blacklist(self, blacklist): + self.ensure_dock_page_at_top() self.island_dock_sort_method_dsc_set(enable=True) ISLAND_DOCK_DETECT.load_color(self.device.image) ISLAND_DOCK_DETECT._match_init = True + drag_count = 0 for _ in self.loop(timeout=40, skip_first=False): # dock_grid needs refresh after each page swipe, so we need to get a new scanner each time scanner = CharacterScanner(self.dock_grid, identity='any', status='free') @@ -191,13 +203,15 @@ class IslandDock(IslandUI): elif self.is_button_selected(candidate.button, color=(19, 181, 231)): continue else: - self.island_dock_select_one(candidate.button) - return candidate.identity + return candidate self.next_dock_page() + drag_count += 1 if self.appear(ISLAND_DOCK_DETECT, offset=(20, 20)): - logger.warning('Reached end of dock page') - break + if drag_count >= 2: + logger.warning('Reached end of dock page') + break else: ISLAND_DOCK_DETECT.load_color(self.device.image) + drag_count = 0 logger.warning('Failed to find any character not in blacklist') return None diff --git a/module/island_handler/recipe.py b/module/island_handler/recipe.py index 895730b18..71d810335 100644 --- a/module/island_handler/recipe.py +++ b/module/island_handler/recipe.py @@ -21,9 +21,8 @@ from module.island.utils import ( load_hard_floor_items, load_item_mapping, load_reserve_items, - merge_item_needs, + merge_task_target_stuck_order_items, normalize_item_keys, - normalize_item_needs, parse_item_need_deadlines, ) from module.island_handler.assets import * @@ -122,6 +121,16 @@ def get_recipe_product_id(recipe_id): return next(iter(DIC_ISLAND_RECIPE[recipe_id]['commission_product'])) +def get_ingredient_available_stock(stock, hard_floor, reserve, task_target_reserve): + return max( + stock + - max(hard_floor, 0) + - max(reserve, 0) + - max(task_target_reserve, 0), + 0, + ) + + def get_target_stock_weight(stock, target_stock, hard_floor, reserve): if stock >= target_stock or target_stock <= 0: return 0 @@ -349,6 +358,20 @@ class IslandRecipe(IslandExchange, IslandShop): yaml_text = self.config.cross_get("IslandProduction.IslandProduction.ReserveItems", "") return normalize_item_keys(load_reserve_items(yaml_text)) + def get_task_target_items(self, task_target_items=None): + if task_target_items is None: + task_target_items = load_item_mapping( + self.config.cross_get("IslandSeasonTask.IslandSeasonTask.TaskTarget", "{}"), + config_name='TaskTarget', + ) + stuck_season_order_id = self.config.cross_get( + "IslandOrder.IslandOrder.StuckSeasonOrderId", 0 + ) + return merge_task_target_stuck_order_items( + task_target_items, + get_stuck_season_order_requirements(stuck_season_order_id), + ) + def get_recipe_id_sequence_to_run( self, daily_buffer_items_dict=None, @@ -372,21 +395,8 @@ class IslandRecipe(IslandExchange, IslandShop): reserve_items_dict = self.reserve_items else: reserve_items_dict = normalize_item_keys(reserve_items_dict) - if task_target_items_dict is None: - yaml_text = self.config.cross_get("IslandSeasonTask.IslandSeasonTask.TaskTarget", "{}") - task_target_items_dict = load_item_mapping(yaml_text, config_name='TaskTarget') - task_target_items_dict = normalize_item_needs(task_target_items_dict, default_period=10) - stuck_season_order_id = self.config.cross_get( - "IslandOrder.IslandOrder.StuckSeasonOrderId", 0 - ) - stuck_season_order_items = normalize_item_needs( - get_stuck_season_order_requirements(stuck_season_order_id), - default_period=10, - ) - task_target_items_dict = merge_item_needs( - task_target_items_dict, - stuck_season_order_items, - ) + task_target_items_dict = self.get_task_target_items(task_target_items_dict) + self.task_target_items = task_target_items_dict if idle_accumulating_items_dict is None: yaml_text = self.config.cross_get("IslandProduction.IslandProduction.IdleAccumulatingItems", "") if yaml_text is None: @@ -556,6 +566,9 @@ class IslandRecipe(IslandExchange, IslandShop): # since ranch recipes may have boosted ingredient requirement for higher batch production. counters = self.get_recipe_ingredient_counters() recipe_cost = DIC_ISLAND_RECIPE[recipe_id]['commission_cost'] + task_target_items = getattr(self, 'task_target_items', None) + if task_target_items is None: + task_target_items = self.get_task_target_items() if counters is None: logger.warning(f'Unable to read ingredient counters for recipe {recipe_id}') return False, 0 @@ -564,11 +577,12 @@ class IslandRecipe(IslandExchange, IslandShop): for ingredient_key, counter in zip(recipe_cost, counters): if ingredient_key in DIC_ISLAND_SHOP_ITEM_TO_RECIPE or ingredient_key in (2521, 2522): continue - available_stock = max( - counter[0] - - self.hard_floor_items.get(ingredient_key, 0) - - self.reserve_items.get(ingredient_key, 0), - 0, + task_target_reserve = task_target_items.get(ingredient_key, {}).get('total_need_count', 0) + available_stock = get_ingredient_available_stock( + counter[0], + self.hard_floor_items.get(ingredient_key, 0), + self.reserve_items.get(ingredient_key, 0), + task_target_reserve, ) count = available_stock // counter[1] if counter[1] > 0 else float('inf') if count < max_count: @@ -586,7 +600,10 @@ class IslandRecipe(IslandExchange, IslandShop): for ingredient_key, counter, button in zip(recipe_cost, counters, ingredient_buttons): hard_floor = self.hard_floor_items.get(ingredient_key, 0) reserve = self.reserve_items.get(ingredient_key, 0) - available_stock = max(counter[0] - hard_floor - reserve, 0) + task_target_reserve = task_target_items.get(ingredient_key, {}).get('total_need_count', 0) + available_stock = get_ingredient_available_stock( + counter[0], hard_floor, reserve, task_target_reserve + ) if available_stock < real_count * counter[1]: if ingredient_key in (2521, 2522): if ingredient_key in failed_buy_items: @@ -639,7 +656,8 @@ class IslandRecipe(IslandExchange, IslandShop): else: logger.warning( f'Ingredient {ingredient_key} cannot be bought from shop, ' - f'insufficient ingredient for recipe production after hard floor {hard_floor} and reserve {reserve}' + f'insufficient ingredient for recipe production after hard floor {hard_floor}, ' + f'reserve {reserve}, and task target {task_target_reserve}' ) real_count = min(real_count, available_stock // counter[1]) if counter[1] > 0 else 0 success = False diff --git a/module/island_handler/restaurant.py b/module/island_handler/restaurant.py index 44fbfe6ab..af445b1d5 100644 --- a/module/island_handler/restaurant.py +++ b/module/island_handler/restaurant.py @@ -15,6 +15,8 @@ from module.island.data import DIC_ISLAND_ITEM, DIC_ISLAND_RESTAURANT_MENU_TO_RE from module.island.utils import ( get_stuck_season_order_requirements, load_hard_floor_items, + load_item_mapping, + merge_task_target_stuck_order_items, normalize_item_keys, ) from module.island_handler.assets import * @@ -277,8 +279,9 @@ class IslandRestaurant(IslandDock): item for item in items if item.id in menu # Sell one full waitress-capacity tranche while preserving manual - # hard floors and remaining season-order requirements. Reserves and - # daily buffers are soft and may be consumed by restaurants. + # hard floors, task targets, and remaining season-order + # requirements. Reserves and daily buffers are soft and may be + # consumed by restaurants. and has_sellable_capacity(item) ] surplus_items = [ @@ -303,13 +306,18 @@ class IslandRestaurant(IslandDock): stuck_season_order_id = self.config.cross_get( "IslandOrder.IslandOrder.StuckSeasonOrderId", 0 ) - season_order_items = normalize_item_keys( - get_stuck_season_order_requirements(stuck_season_order_id) + task_target_items = load_item_mapping( + self.config.cross_get("IslandSeasonTask.IslandSeasonTask.TaskTarget", "{}"), + config_name='TaskTarget', ) - item_ids = set(hard_floor_items) | set(season_order_items) + protected_target_items = merge_task_target_stuck_order_items( + task_target_items, + get_stuck_season_order_requirements(stuck_season_order_id), + ) + item_ids = set(hard_floor_items) | set(protected_target_items) return { item_id: max(hard_floor_items.get(item_id, 0), 0) - + max(season_order_items.get(item_id, 0), 0) + + max(protected_target_items.get(item_id, {}).get('total_need_count', 0), 0) for item_id in item_ids } @@ -397,19 +405,21 @@ class IslandRestaurant(IslandDock): | selected_waitresses | all_named_waitresses ) - selected = self.island_dock_select_character_with_blacklist(fallback_blacklist) - if selected is None: + candidate = self.island_dock_find_character_with_blacklist(fallback_blacklist) + if candidate is None: success = False else: - selected_waitresses.add(selected) + self.island_dock_select_one(candidate.button) + selected_waitresses.add(candidate.identity) for _ in range(active_waitresses.count(WAITRESS_ANY)): blacklist = unavailable_waitress_list | selected_waitresses | all_named_waitresses - selected = self.island_dock_select_character_with_blacklist(blacklist) - if selected is None: + candidate = self.island_dock_find_character_with_blacklist(blacklist) + if candidate is None: success = False else: - selected_waitresses.add(selected) + self.island_dock_select_one(candidate.button) + selected_waitresses.add(candidate.identity) if not success: logger.warning("Failed to choose waitress") self.ui_back(check_button=self.is_in_island_restaurant)