feat(task): 新增领取任务奖励
|
@ -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))
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from enum import IntEnum
|
||||
|
||||
class Priority(IntEnum):
|
||||
DEFAULT = 0
|
||||
START_GAME = 1
|
||||
DEFAULT = 0
|
||||
CLAIM_MISSION_REWARD = -1
|
||||
|
|
|
@ -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()
|
After Width: | Height: | Size: 662 B |
After Width: | Height: | Size: 609 B |
After Width: | Height: | Size: 307 B |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 622 B |
After Width: | Height: | Size: 265 KiB |
After Width: | Height: | Size: 467 KiB |
After Width: | Height: | Size: 386 KiB |