diff --git a/kotonebot/tasks/acquire_presents.py b/kotonebot/tasks/acquire_presents.py index 8d1c8e1..298754b 100644 --- a/kotonebot/tasks/acquire_presents.py +++ b/kotonebot/tasks/acquire_presents.py @@ -35,5 +35,7 @@ if __name__ == '__main__': logging.basicConfig(level=logging.INFO, format='[%(asctime)s] [%(levelname)s] [%(name)s] [%(funcName)s] [%(lineno)d] %(message)s') logger.setLevel(logging.DEBUG) init_context() - acquire_presents() + # acquire_presents() + print(image.find(R.Common.ButtonIconArrowShort, colored=True)) + print(image.find(R.Common.ButtonIconArrowShortDisabled, colored=True)) diff --git a/kotonebot/tasks/common.py b/kotonebot/tasks/common.py index 9b008f2..78afad3 100644 --- a/kotonebot/tasks/common.py +++ b/kotonebot/tasks/common.py @@ -1,5 +1,6 @@ from enum import IntEnum class Priority(IntEnum): - DEFAULT = 0 START_GAME = 1 + DEFAULT = 0 + CLAIM_MISSION_REWARD = -1 diff --git a/kotonebot/tasks/mission_reward.py b/kotonebot/tasks/mission_reward.py new file mode 100644 index 0000000..a7cdb57 --- /dev/null +++ b/kotonebot/tasks/mission_reward.py @@ -0,0 +1,146 @@ +"""领取任务奖励""" +from time import sleep +import logging + +from kotonebot import device, image, color, task, action +from .actions.scenes import at_home, goto_home +from .common import Priority +from . import R +from .actions.loading import wait_loading_end +logger = logging.getLogger(__name__) + +@action('检查任务') +def check_and_goto_mission() -> bool: + """ + 检查任务。如果需要领取, + 则前往任务页面,并返回 True。 + 否则返回 False。 + + :return: 是否需要领取任务奖励 + """ + rect = image.expect_wait(R.Daily.ButtonMission, timeout=1).rect + # 向上、向右扩展 50px + color_rect = (rect[0], rect[1] - 50, rect[2] + 50, rect[3] + 50) + if not color.find_rgb('#ff1249', rect=color_rect): + logger.info('No mission reward to claim.') + return False + # 点击任务奖励图标 + logger.debug('Clicking mission reward icon.') + device.click() + sleep(0.5) + # 加载 + wait_loading_end() + return True + +@action('任务奖励') +def claim_mission_reward(name: str): + """领取任务奖励""" + # [screenshots/mission/daily.png] + if image.find(R.Common.ButtonIconArrowShort, colored=True): + logger.info(f'Claiming {name} mission reward.') + device.click() + sleep(0.5) + while not image.find(R.Common.ButtonIconArrowShortDisabled, colored=True): + if image.find(R.Common.ButtonIconClose): + logger.debug('Closing popup dialog.') + device.click() + sleep(1) + sleep(0.5) + else: + logger.info(f'No {name} mission reward to claim.') + +@action('领取任务页面奖励') +def claim_mission_rewards(): + """领取任务奖励""" + # [screenshots/mission/daily.png] + # デイリー Daily + claim_mission_reward('デイリー') + # ウィークリー Weekly + device.swipe_scaled(0.8, 0.5, 0.2, 0.5) + sleep(0.5) + claim_mission_reward('ウィークリー') + # ノーマル Normal + device.swipe_scaled(0.8, 0.5, 0.2, 0.5) + sleep(0.5) + claim_mission_reward('ノーマル') + # 期間限定 + device.swipe_scaled(0.8, 0.5, 0.2, 0.5) + sleep(0.5) + claim_mission_reward('期間限定') + + +@action('通行证奖励') +def claim_pass_reward(): + """领取通行证奖励""" + # [screenshots/mission/daily.png] + pass_rect = image.expect_wait(R.Daily.ButtonIconPass, timeout=1).rect + # 向右扩展 150px,向上扩展 35px + color_rect = (pass_rect[0], pass_rect[1] - 35, pass_rect[2] + 150, pass_rect[3] + 35) + if not color.find_rgb('#ff1249', rect=color_rect): + logger.info('No pass reward to claim.') + return + logger.info('Claiming pass reward.') + logger.debug('Clicking パス button.') + device.click() + sleep(0.5) + # [screenshots/mission/pass.png] + # 对话框 [screenshots/mission/pass_dialog.png] + while not image.find(R.Daily.IconTitlePass): + if image.find(R.Common.ButtonIconClose): + logger.debug('Closing popup dialog.') + device.click() + sleep(1) + sleep(0.5) + logger.debug('Pass screen loaded.') + while image.find(R.Daily.ButtonPassClaim, colored=True): + logger.debug('Clicking 受取 button.') + device.click() + sleep(1.5) + while not image.find(R.Daily.ButtonPassClaim): + if image.find(R.Common.ButtonIconClose): + logger.debug('Closing popup dialog.') + device.click() + sleep(1) + sleep(0.5) + sleep(1.5) + logger.info('All pass rewards claimed.') + + +@action('活动奖励') +def claim_event_reward(): + """领取活动奖励""" + # TODO: 领取活动奖励 + pass + +@task('领取任务奖励', priority=Priority.CLAIM_MISSION_REWARD) +def mission_reward(): + """ + 领取任务奖励 + """ + logger.info('Claiming mission rewards.') + if not at_home(): + goto_home() + if not check_and_goto_mission(): + return + sleep(0.7) + claim_mission_rewards() + sleep(0.5) + claim_pass_reward() + logger.info('All mission rewards claimed.') + + +if __name__ == '__main__': + from kotonebot.backend.context import init_context + import logging + logging.basicConfig(level=logging.INFO, format='[%(asctime)s] [%(levelname)s] [%(name)s] [%(funcName)s] [%(lineno)d] %(message)s') + logging.getLogger('kotonebot').setLevel(logging.DEBUG) + logger.setLevel(logging.DEBUG) + init_context() + + # if image.find(R.Common.CheckboxUnchecked): + # logger.debug('Checking skip all.') + # device.click() + # sleep(0.5) + # device.click(image.expect(R.Daily.ButtonIconSkip, colored=True, transparent=True, threshold=0.999)) + # mission_reward() + claim_pass_reward() diff --git a/res/sprites/jp/common/button_icon_arrow_short.png b/res/sprites/jp/common/button_icon_arrow_short.png new file mode 100644 index 0000000..843e1ba Binary files /dev/null and b/res/sprites/jp/common/button_icon_arrow_short.png differ diff --git a/res/sprites/jp/common/button_icon_arrow_short_disabled.png b/res/sprites/jp/common/button_icon_arrow_short_disabled.png new file mode 100644 index 0000000..fde488b Binary files /dev/null and b/res/sprites/jp/common/button_icon_arrow_short_disabled.png differ diff --git a/res/sprites/jp/daily/button_icon_pass.png b/res/sprites/jp/daily/button_icon_pass.png new file mode 100644 index 0000000..85e71e4 Binary files /dev/null and b/res/sprites/jp/daily/button_icon_pass.png differ diff --git a/res/sprites/jp/daily/button_pass_claim.png b/res/sprites/jp/daily/button_pass_claim.png new file mode 100644 index 0000000..c556dc5 Binary files /dev/null and b/res/sprites/jp/daily/button_pass_claim.png differ diff --git a/res/sprites/jp/daily/icon_title_pass.png b/res/sprites/jp/daily/icon_title_pass.png new file mode 100644 index 0000000..349b2ae Binary files /dev/null and b/res/sprites/jp/daily/icon_title_pass.png differ diff --git a/screenshots/mission/daily.png b/screenshots/mission/daily.png new file mode 100644 index 0000000..6c7aba8 Binary files /dev/null and b/screenshots/mission/daily.png differ diff --git a/screenshots/mission/pass.png b/screenshots/mission/pass.png new file mode 100644 index 0000000..1ab8837 Binary files /dev/null and b/screenshots/mission/pass.png differ diff --git a/screenshots/mission/pass_dialog.png b/screenshots/mission/pass_dialog.png new file mode 100644 index 0000000..2c6c234 Binary files /dev/null and b/screenshots/mission/pass_dialog.png differ