fix(*): 修复培育与商店购买的部分 bug
1. 修复培育禁用时保存 2. 修复 DispatcherContext 未正确初始化的问题
This commit is contained in:
parent
432823755f
commit
322f565a2b
|
@ -85,8 +85,8 @@ def dispatcher(
|
|||
启用后,被装饰函数将会只执行依次,
|
||||
而不会一直循环到 ctx.finish() 被调用。
|
||||
"""
|
||||
ctx = DispatcherContext()
|
||||
def wrapper(*args: P.args, **kwargs: P.kwargs):
|
||||
ctx = DispatcherContext()
|
||||
while not ctx.finished:
|
||||
from kotonebot import device
|
||||
device.update_screenshot()
|
||||
|
@ -94,6 +94,7 @@ def dispatcher(
|
|||
ctx._first_run = False
|
||||
return ret
|
||||
def fragment_wrapper(*args: P.args, **kwargs: P.kwargs):
|
||||
ctx = DispatcherContext()
|
||||
from kotonebot import device
|
||||
device.update_screenshot()
|
||||
return func(ctx, *args, **kwargs)
|
||||
|
@ -107,3 +108,19 @@ def dispatcher(
|
|||
|
||||
else:
|
||||
return wrapper
|
||||
|
||||
if __name__ == '__main__':
|
||||
from .context.task_action import action
|
||||
from .context import init_context
|
||||
init_context()
|
||||
@action('inner', dispatcher=True)
|
||||
def inner(ctx: DispatcherContext):
|
||||
print('inner')
|
||||
ctx.finish()
|
||||
|
||||
@action('test', dispatcher=True)
|
||||
def test(ctx: DispatcherContext):
|
||||
print('test')
|
||||
inner()
|
||||
ctx.finish()
|
||||
test()
|
||||
|
|
|
@ -105,9 +105,6 @@ def do_produce(idol: PIdol | None = None):
|
|||
|
||||
:param idol: 要培育的偶像。如果为 None,则使用配置文件中的偶像。
|
||||
"""
|
||||
if not conf().produce.enabled:
|
||||
logger.info('Produce is disabled.')
|
||||
return
|
||||
if not at_home():
|
||||
goto_home()
|
||||
# [screenshots/produce/home.png]
|
||||
|
@ -179,6 +176,9 @@ def produce_task(count: Optional[int] = None, idols: Optional[list[PIdol]] = Non
|
|||
:param idols:
|
||||
要培育的偶像。若为 None,则从配置文件中读入。
|
||||
"""
|
||||
if not conf().produce.enabled:
|
||||
logger.info('Produce is disabled.')
|
||||
return
|
||||
import time
|
||||
if count is None:
|
||||
count = conf().produce.produce_count
|
||||
|
|
|
@ -85,7 +85,7 @@ def dispatch_purchase_dialog(ctx: DispatcherContext):
|
|||
"""
|
||||
确认购买
|
||||
|
||||
前置条件:购买确认对话框\n
|
||||
前置条件:点击某个商品后的瞬间\n
|
||||
结束状态:对话框关闭后原来的界面
|
||||
"""
|
||||
# 前置条件:[screenshots\shop\dialog.png]
|
||||
|
@ -94,43 +94,11 @@ def dispatch_purchase_dialog(ctx: DispatcherContext):
|
|||
device.click()
|
||||
elif image.find(R.Common.ButtonConfirm):
|
||||
logger.debug('Confirming purchase...')
|
||||
# device.click()
|
||||
device.click(image.expect(R.InPurodyuusu.ButtonCancel))
|
||||
device.click()
|
||||
ctx.finish()
|
||||
elif image.find(R.Daily.TextShopPurchased):
|
||||
logger.info('Item sold out.')
|
||||
ctx.finish()
|
||||
|
||||
@deprecated('改用 `money_items2`')
|
||||
@action('购买 Money 物品')
|
||||
def money_items():
|
||||
"""
|
||||
购买マニー物品
|
||||
|
||||
前置条件:位于商店页面的マニー Tab
|
||||
"""
|
||||
logger.info(f'Purchasing マニー items.')
|
||||
# [screenshots\shop\money1.png]
|
||||
results = image.find_all(R.Daily.TextShopRecommended)
|
||||
# device.click(results[0])
|
||||
index = 1
|
||||
for index, result in enumerate(results, 1):
|
||||
# [screenshots\shop\dialog.png]
|
||||
logger.info(f'Purchasing #{index} item.')
|
||||
device.click(result)
|
||||
sleep(0.5)
|
||||
with cropped(device, y1=0.3):
|
||||
purchased = image.wait_for(R.Daily.TextShopPurchased, timeout=1)
|
||||
if purchased is not None:
|
||||
logger.info(f'AP item #{index} already purchased.')
|
||||
continue
|
||||
comfirm = image.expect_wait(R.Common.ButtonConfirm, timeout=2)
|
||||
# 如果数量不是最大,调到最大
|
||||
while image.find(R.Daily.ButtonShopCountAdd, colored=True):
|
||||
logger.debug('Adjusting quantity(+1)...')
|
||||
device.click()
|
||||
sleep(0.3)
|
||||
logger.debug(f'Confirming purchase...')
|
||||
device.click(comfirm)
|
||||
sleep(1.5)
|
||||
logger.info(f'Purchasing マニー items completed. {index} items purchased.')
|
||||
|
||||
@action('购买 AP 物品')
|
||||
def ap_items():
|
||||
|
@ -211,4 +179,4 @@ if __name__ == '__main__':
|
|||
import logging
|
||||
logging.basicConfig(level=logging.INFO, format='[%(asctime)s] [%(levelname)s] [%(name)s] [%(funcName)s] [%(lineno)d] %(message)s')
|
||||
logger.setLevel(logging.DEBUG)
|
||||
dispatch_recommended_items()
|
||||
purchase()
|
||||
|
|
Loading…
Reference in New Issue