mirror of
https://github.com/sui-feng-cb/AzurLaneAutoScript1.git
synced 2026-08-19 20:55:05 +08:00
Fix: island production and restaurant should keep task target items
This commit is contained in:
@@ -300,6 +300,14 @@ def get_stuck_season_order_requirements(stuck_order_id):
|
|||||||
return dict(requirements)
|
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):
|
def normalize_stuck_season_order_id(stuck_order_id):
|
||||||
try:
|
try:
|
||||||
stuck_order_id = int(stuck_order_id)
|
stuck_order_id = int(stuck_order_id)
|
||||||
|
|||||||
@@ -21,9 +21,8 @@ from module.island.utils import (
|
|||||||
load_hard_floor_items,
|
load_hard_floor_items,
|
||||||
load_item_mapping,
|
load_item_mapping,
|
||||||
load_reserve_items,
|
load_reserve_items,
|
||||||
merge_item_needs,
|
merge_task_target_stuck_order_items,
|
||||||
normalize_item_keys,
|
normalize_item_keys,
|
||||||
normalize_item_needs,
|
|
||||||
parse_item_need_deadlines,
|
parse_item_need_deadlines,
|
||||||
)
|
)
|
||||||
from module.island_handler.assets import *
|
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']))
|
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):
|
def get_target_stock_weight(stock, target_stock, hard_floor, reserve):
|
||||||
if stock >= target_stock or target_stock <= 0:
|
if stock >= target_stock or target_stock <= 0:
|
||||||
return 0
|
return 0
|
||||||
@@ -349,6 +358,20 @@ class IslandRecipe(IslandExchange, IslandShop):
|
|||||||
yaml_text = self.config.cross_get("IslandProduction.IslandProduction.ReserveItems", "")
|
yaml_text = self.config.cross_get("IslandProduction.IslandProduction.ReserveItems", "")
|
||||||
return normalize_item_keys(load_reserve_items(yaml_text))
|
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(
|
def get_recipe_id_sequence_to_run(
|
||||||
self,
|
self,
|
||||||
daily_buffer_items_dict=None,
|
daily_buffer_items_dict=None,
|
||||||
@@ -372,21 +395,8 @@ class IslandRecipe(IslandExchange, IslandShop):
|
|||||||
reserve_items_dict = self.reserve_items
|
reserve_items_dict = self.reserve_items
|
||||||
else:
|
else:
|
||||||
reserve_items_dict = normalize_item_keys(reserve_items_dict)
|
reserve_items_dict = normalize_item_keys(reserve_items_dict)
|
||||||
if task_target_items_dict is None:
|
task_target_items_dict = self.get_task_target_items(task_target_items_dict)
|
||||||
yaml_text = self.config.cross_get("IslandSeasonTask.IslandSeasonTask.TaskTarget", "{}")
|
self.task_target_items = task_target_items_dict
|
||||||
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,
|
|
||||||
)
|
|
||||||
if idle_accumulating_items_dict is None:
|
if idle_accumulating_items_dict is None:
|
||||||
yaml_text = self.config.cross_get("IslandProduction.IslandProduction.IdleAccumulatingItems", "")
|
yaml_text = self.config.cross_get("IslandProduction.IslandProduction.IdleAccumulatingItems", "")
|
||||||
if yaml_text is None:
|
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.
|
# since ranch recipes may have boosted ingredient requirement for higher batch production.
|
||||||
counters = self.get_recipe_ingredient_counters()
|
counters = self.get_recipe_ingredient_counters()
|
||||||
recipe_cost = DIC_ISLAND_RECIPE[recipe_id]['commission_cost']
|
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:
|
if counters is None:
|
||||||
logger.warning(f'Unable to read ingredient counters for recipe {recipe_id}')
|
logger.warning(f'Unable to read ingredient counters for recipe {recipe_id}')
|
||||||
return False, 0
|
return False, 0
|
||||||
@@ -564,11 +577,12 @@ class IslandRecipe(IslandExchange, IslandShop):
|
|||||||
for ingredient_key, counter in zip(recipe_cost, counters):
|
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):
|
if ingredient_key in DIC_ISLAND_SHOP_ITEM_TO_RECIPE or ingredient_key in (2521, 2522):
|
||||||
continue
|
continue
|
||||||
available_stock = max(
|
task_target_reserve = task_target_items.get(ingredient_key, {}).get('total_need_count', 0)
|
||||||
counter[0]
|
available_stock = get_ingredient_available_stock(
|
||||||
- self.hard_floor_items.get(ingredient_key, 0)
|
counter[0],
|
||||||
- self.reserve_items.get(ingredient_key, 0),
|
self.hard_floor_items.get(ingredient_key, 0),
|
||||||
0,
|
self.reserve_items.get(ingredient_key, 0),
|
||||||
|
task_target_reserve,
|
||||||
)
|
)
|
||||||
count = available_stock // counter[1] if counter[1] > 0 else float('inf')
|
count = available_stock // counter[1] if counter[1] > 0 else float('inf')
|
||||||
if count < max_count:
|
if count < max_count:
|
||||||
@@ -586,7 +600,10 @@ class IslandRecipe(IslandExchange, IslandShop):
|
|||||||
for ingredient_key, counter, button in zip(recipe_cost, counters, ingredient_buttons):
|
for ingredient_key, counter, button in zip(recipe_cost, counters, ingredient_buttons):
|
||||||
hard_floor = self.hard_floor_items.get(ingredient_key, 0)
|
hard_floor = self.hard_floor_items.get(ingredient_key, 0)
|
||||||
reserve = self.reserve_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 available_stock < real_count * counter[1]:
|
||||||
if ingredient_key in (2521, 2522):
|
if ingredient_key in (2521, 2522):
|
||||||
if ingredient_key in failed_buy_items:
|
if ingredient_key in failed_buy_items:
|
||||||
@@ -639,7 +656,8 @@ class IslandRecipe(IslandExchange, IslandShop):
|
|||||||
else:
|
else:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
f'Ingredient {ingredient_key} cannot be bought from shop, '
|
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
|
real_count = min(real_count, available_stock // counter[1]) if counter[1] > 0 else 0
|
||||||
success = False
|
success = False
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ from module.island.data import DIC_ISLAND_ITEM, DIC_ISLAND_RESTAURANT_MENU_TO_RE
|
|||||||
from module.island.utils import (
|
from module.island.utils import (
|
||||||
get_stuck_season_order_requirements,
|
get_stuck_season_order_requirements,
|
||||||
load_hard_floor_items,
|
load_hard_floor_items,
|
||||||
|
load_item_mapping,
|
||||||
|
merge_task_target_stuck_order_items,
|
||||||
normalize_item_keys,
|
normalize_item_keys,
|
||||||
)
|
)
|
||||||
from module.island_handler.assets import *
|
from module.island_handler.assets import *
|
||||||
@@ -277,8 +279,9 @@ class IslandRestaurant(IslandDock):
|
|||||||
item for item in items
|
item for item in items
|
||||||
if item.id in menu
|
if item.id in menu
|
||||||
# Sell one full waitress-capacity tranche while preserving manual
|
# Sell one full waitress-capacity tranche while preserving manual
|
||||||
# hard floors and remaining season-order requirements. Reserves and
|
# hard floors, task targets, and remaining season-order
|
||||||
# daily buffers are soft and may be consumed by restaurants.
|
# requirements. Reserves and daily buffers are soft and may be
|
||||||
|
# consumed by restaurants.
|
||||||
and has_sellable_capacity(item)
|
and has_sellable_capacity(item)
|
||||||
]
|
]
|
||||||
surplus_items = [
|
surplus_items = [
|
||||||
@@ -303,13 +306,18 @@ class IslandRestaurant(IslandDock):
|
|||||||
stuck_season_order_id = self.config.cross_get(
|
stuck_season_order_id = self.config.cross_get(
|
||||||
"IslandOrder.IslandOrder.StuckSeasonOrderId", 0
|
"IslandOrder.IslandOrder.StuckSeasonOrderId", 0
|
||||||
)
|
)
|
||||||
season_order_items = normalize_item_keys(
|
task_target_items = load_item_mapping(
|
||||||
get_stuck_season_order_requirements(stuck_season_order_id)
|
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 {
|
return {
|
||||||
item_id: max(hard_floor_items.get(item_id, 0), 0)
|
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
|
for item_id in item_ids
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user