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:
4
alas.py
4
alas.py
@@ -443,6 +443,10 @@ class AzurLaneAutoScript:
|
|||||||
from module.eventstory.eventstory import EventStory
|
from module.eventstory.eventstory import EventStory
|
||||||
EventStory(config=self.config, device=self.device, task="EventStory").run()
|
EventStory(config=self.config, device=self.device, task="EventStory").run()
|
||||||
|
|
||||||
|
def island_production_planner(self):
|
||||||
|
from module.island_handler.production_planner import IslandProductionPlanner
|
||||||
|
IslandProductionPlanner(config=self.config, device=self.device, task="IslandProductionPlanner").run()
|
||||||
|
|
||||||
def azur_lane_uncensored(self):
|
def azur_lane_uncensored(self):
|
||||||
from module.daemon.uncensored import AzurLaneUncensored
|
from module.daemon.uncensored import AzurLaneUncensored
|
||||||
AzurLaneUncensored(config=self.config, device=self.device, task="AzurLaneUncensored").run()
|
AzurLaneUncensored(config=self.config, device=self.device, task="AzurLaneUncensored").run()
|
||||||
|
|||||||
@@ -12,7 +12,12 @@ from module.base.utils import color_similarity_2d
|
|||||||
from module.island.assets import *
|
from module.island.assets import *
|
||||||
from module.island.data import DIC_ISLAND_ITEM, DIC_ISLAND_SEASON_ORDER
|
from module.island.data import DIC_ISLAND_ITEM, DIC_ISLAND_SEASON_ORDER
|
||||||
from module.island.ui import IslandUI
|
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.island_handler.recipe import IslandReversedDigitCounter
|
||||||
from module.logger import logger
|
from module.logger import logger
|
||||||
from module.map_detection.utils import Points
|
from module.map_detection.utils import Points
|
||||||
@@ -174,21 +179,21 @@ class IslandOrder(IslandUI):
|
|||||||
)
|
)
|
||||||
return normalize_item_keys(reserve_items_text)
|
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():
|
for item, counter in order_requirements.items():
|
||||||
stock, required, _ = counter
|
stock, required, _ = counter
|
||||||
if not is_urgent:
|
|
||||||
hard_floor = self.hard_floor.get(item, 0)
|
hard_floor = self.hard_floor.get(item, 0)
|
||||||
reserve = self.reserve.get(item, 0)
|
priority = is_urgent or is_season
|
||||||
effective_stock = stock - hard_floor - reserve
|
effective_stock = get_order_effective_stock(
|
||||||
else:
|
stock,
|
||||||
hard_floor = 0
|
hard_floor,
|
||||||
reserve = 0
|
reserve=self.reserve.get(item, 0),
|
||||||
effective_stock = stock
|
priority=priority,
|
||||||
|
)
|
||||||
if required > effective_stock:
|
if required > effective_stock:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
f'Item {item} does not meet the requirement: stock {stock}, '
|
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}'
|
f'effective stock {effective_stock}, required {required}'
|
||||||
)
|
)
|
||||||
return False
|
return False
|
||||||
@@ -276,6 +281,7 @@ class IslandOrder(IslandUI):
|
|||||||
return cooldown_remain_time
|
return cooldown_remain_time
|
||||||
|
|
||||||
next_runtime = []
|
next_runtime = []
|
||||||
|
update_production_plan = False
|
||||||
|
|
||||||
def update_stuck_season_order(self, order_id):
|
def update_stuck_season_order(self, order_id):
|
||||||
order_id = order_id or EMPTY_SEASON_ORDER_ID
|
order_id = order_id or EMPTY_SEASON_ORDER_ID
|
||||||
@@ -283,6 +289,7 @@ class IslandOrder(IslandUI):
|
|||||||
if order_id != previous_id:
|
if order_id != previous_id:
|
||||||
logger.info(f'Updating stuck season order id from {previous_id} to {order_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.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):
|
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)
|
self.next_runtime.append(next_runtime)
|
||||||
return False
|
return False
|
||||||
requirements = self.scan_current_order_requirements()
|
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)
|
return self.submit_order(is_urgent=is_urgent)
|
||||||
else:
|
else:
|
||||||
logger.warning('Order requirements not satisfied due to low stock')
|
logger.warning('Order requirements not satisfied due to low stock')
|
||||||
@@ -370,6 +377,7 @@ class IslandOrder(IslandUI):
|
|||||||
def run(self):
|
def run(self):
|
||||||
self.ui_ensure(page_island_order)
|
self.ui_ensure(page_island_order)
|
||||||
self.next_runtime = []
|
self.next_runtime = []
|
||||||
|
self.update_production_plan = False
|
||||||
for _ in self.loop():
|
for _ in self.loop():
|
||||||
self.detect_all_orders()
|
self.detect_all_orders()
|
||||||
if self.run_any_order():
|
if self.run_any_order():
|
||||||
@@ -379,6 +387,11 @@ class IslandOrder(IslandUI):
|
|||||||
break
|
break
|
||||||
if not self.season_orders:
|
if not self.season_orders:
|
||||||
self.update_stuck_season_order(EMPTY_SEASON_ORDER_ID)
|
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:
|
for order in self.regular_cooldown_orders:
|
||||||
remain_time = self.get_order_remain_time(order)
|
remain_time = self.get_order_remain_time(order)
|
||||||
if remain_time == timedelta(0):
|
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={})
|
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.slot_finish_time = {int(k): datetime.fromisoformat(v) for k, v in slot_finish_time.items()}
|
||||||
self.claim_all_rewards()
|
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()
|
self.dispatch_all()
|
||||||
next_run_time = list(self.slot_finish_time.values())
|
next_run_time = list(self.slot_finish_time.values())
|
||||||
with self.config.multi_set():
|
with self.config.multi_set():
|
||||||
|
|||||||
@@ -232,4 +232,6 @@ class IslandSeasonTask(IslandUI):
|
|||||||
if new_target != old_target:
|
if new_target != old_target:
|
||||||
yaml_text = item_mapping_to_yaml(new_target, use_item_name=True)
|
yaml_text = item_mapping_to_yaml(new_target, use_item_name=True)
|
||||||
self.config.cross_set("IslandSeasonTask.IslandSeasonTask.TaskTarget", yaml_text)
|
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)
|
self.config.task_delay(server_update=True)
|
||||||
|
|||||||
1247
module/island_handler/production_planner.py
Normal file
1247
module/island_handler/production_planner.py
Normal file
File diff suppressed because it is too large
Load Diff
@@ -18,6 +18,7 @@ def get_available_func():
|
|||||||
'Daemon',
|
'Daemon',
|
||||||
'OpsiDaemon',
|
'OpsiDaemon',
|
||||||
'EventStory',
|
'EventStory',
|
||||||
|
'IslandProductionPlanner',
|
||||||
'AzurLaneUncensored',
|
'AzurLaneUncensored',
|
||||||
'Benchmark',
|
'Benchmark',
|
||||||
'GameManager',
|
'GameManager',
|
||||||
|
|||||||
Reference in New Issue
Block a user