mirror of
https://github.com/sui-feng-cb/AzurLaneAutoScript1.git
synced 2026-08-15 19:43:28 +08:00
Add: island production planner
This commit is contained in:
@@ -12,7 +12,12 @@ from module.base.utils import color_similarity_2d
|
||||
from module.island.assets import *
|
||||
from module.island.data import DIC_ISLAND_ITEM, DIC_ISLAND_SEASON_ORDER
|
||||
from module.island.ui import IslandUI
|
||||
from module.island.utils import load_hard_floor_items, load_reserve_items, normalize_item_keys
|
||||
from module.island.utils import (
|
||||
get_order_effective_stock,
|
||||
load_hard_floor_items,
|
||||
load_reserve_items,
|
||||
normalize_item_keys,
|
||||
)
|
||||
from module.island_handler.recipe import IslandReversedDigitCounter
|
||||
from module.logger import logger
|
||||
from module.map_detection.utils import Points
|
||||
@@ -174,21 +179,21 @@ class IslandOrder(IslandUI):
|
||||
)
|
||||
return normalize_item_keys(reserve_items_text)
|
||||
|
||||
def is_order_satisfied(self, order_requirements, is_urgent=False):
|
||||
def is_order_satisfied(self, order_requirements, is_urgent=False, is_season=False):
|
||||
for item, counter in order_requirements.items():
|
||||
stock, required, _ = counter
|
||||
if not is_urgent:
|
||||
hard_floor = self.hard_floor.get(item, 0)
|
||||
reserve = self.reserve.get(item, 0)
|
||||
effective_stock = stock - hard_floor - reserve
|
||||
else:
|
||||
hard_floor = 0
|
||||
reserve = 0
|
||||
effective_stock = stock
|
||||
hard_floor = self.hard_floor.get(item, 0)
|
||||
priority = is_urgent or is_season
|
||||
effective_stock = get_order_effective_stock(
|
||||
stock,
|
||||
hard_floor,
|
||||
reserve=self.reserve.get(item, 0),
|
||||
priority=priority,
|
||||
)
|
||||
if required > effective_stock:
|
||||
logger.warning(
|
||||
f'Item {item} does not meet the requirement: stock {stock}, '
|
||||
f'hard floor {hard_floor}, reserve {reserve}, '
|
||||
f'hard floor {hard_floor}, reserve {self.reserve.get(item, 0)}, '
|
||||
f'effective stock {effective_stock}, required {required}'
|
||||
)
|
||||
return False
|
||||
@@ -276,6 +281,7 @@ class IslandOrder(IslandUI):
|
||||
return cooldown_remain_time
|
||||
|
||||
next_runtime = []
|
||||
update_production_plan = False
|
||||
|
||||
def update_stuck_season_order(self, order_id):
|
||||
order_id = order_id or EMPTY_SEASON_ORDER_ID
|
||||
@@ -283,6 +289,7 @@ class IslandOrder(IslandUI):
|
||||
if order_id != previous_id:
|
||||
logger.info(f'Updating stuck season order id from {previous_id} to {order_id}')
|
||||
self.config.cross_set("IslandOrder.IslandOrder.StuckSeasonOrderId", order_id)
|
||||
self.update_production_plan = True
|
||||
|
||||
def execute_order(self, order_button, is_urgent=False, is_season=False):
|
||||
"""
|
||||
@@ -299,7 +306,7 @@ class IslandOrder(IslandUI):
|
||||
self.next_runtime.append(next_runtime)
|
||||
return False
|
||||
requirements = self.scan_current_order_requirements()
|
||||
if self.is_order_satisfied(requirements, is_urgent=is_urgent):
|
||||
if self.is_order_satisfied(requirements, is_urgent=is_urgent, is_season=is_season):
|
||||
return self.submit_order(is_urgent=is_urgent)
|
||||
else:
|
||||
logger.warning('Order requirements not satisfied due to low stock')
|
||||
@@ -370,6 +377,7 @@ class IslandOrder(IslandUI):
|
||||
def run(self):
|
||||
self.ui_ensure(page_island_order)
|
||||
self.next_runtime = []
|
||||
self.update_production_plan = False
|
||||
for _ in self.loop():
|
||||
self.detect_all_orders()
|
||||
if self.run_any_order():
|
||||
@@ -379,6 +387,11 @@ class IslandOrder(IslandUI):
|
||||
break
|
||||
if not self.season_orders:
|
||||
self.update_stuck_season_order(EMPTY_SEASON_ORDER_ID)
|
||||
if self.update_production_plan:
|
||||
logger.info('Production plan needs to be updated due to stuck season order change')
|
||||
from module.island_handler.production_planner import IslandProductionPlanner
|
||||
IslandProductionPlanner(self.config, self.device).run()
|
||||
self.update_production_plan = False
|
||||
for order in self.regular_cooldown_orders:
|
||||
remain_time = self.get_order_remain_time(order)
|
||||
if remain_time == timedelta(0):
|
||||
|
||||
@@ -306,6 +306,10 @@ class IslandProduction(IslandRecipe, IslandDock):
|
||||
slot_finish_time = self.config.cross_get("IslandProduction.Storage.Storage.SlotFinishTime", default={})
|
||||
self.slot_finish_time = {int(k): datetime.fromisoformat(v) for k, v in slot_finish_time.items()}
|
||||
self.claim_all_rewards()
|
||||
yaml_text = self.config.cross_get("IslandProduction.IslandProduction.DailyBufferItems", "")
|
||||
if not yaml_text or yaml_text == "{}":
|
||||
logger.critical('No daily buffer items found in config, please run Island Production Planner first')
|
||||
raise RequestHumanTakeover('No daily buffer items found in config, please run Island Production Planner first')
|
||||
self.dispatch_all()
|
||||
next_run_time = list(self.slot_finish_time.values())
|
||||
with self.config.multi_set():
|
||||
|
||||
@@ -232,4 +232,6 @@ class IslandSeasonTask(IslandUI):
|
||||
if new_target != old_target:
|
||||
yaml_text = item_mapping_to_yaml(new_target, use_item_name=True)
|
||||
self.config.cross_set("IslandSeasonTask.IslandSeasonTask.TaskTarget", yaml_text)
|
||||
from module.island_handler.production_planner import IslandProductionPlanner
|
||||
IslandProductionPlanner(self.config, self.device).run()
|
||||
self.config.task_delay(server_update=True)
|
||||
|
||||
Reference in New Issue
Block a user