|
@@ -7,6 +7,8 @@ from time import sleep
|
|
|
from datetime import datetime, timedelta, time
|
|
from datetime import datetime, timedelta, time
|
|
|
from typing import Union
|
|
from typing import Union
|
|
|
|
|
|
|
|
|
|
+from dev_tools.decorator import usage_time
|
|
|
|
|
+
|
|
|
from module.config.utils import convert_to_underscore
|
|
from module.config.utils import convert_to_underscore
|
|
|
from module.atom.image import RuleImage
|
|
from module.atom.image import RuleImage
|
|
|
from module.atom.click import RuleClick
|
|
from module.atom.click import RuleClick
|
|
@@ -61,6 +63,53 @@ class BaseTask(GlobalGameAssets, CostumeBase):
|
|
|
# 战斗次数相关
|
|
# 战斗次数相关
|
|
|
self.current_count = 0 # 战斗次数
|
|
self.current_count = 0 # 战斗次数
|
|
|
|
|
|
|
|
|
|
+ def _burst(self) -> bool:
|
|
|
|
|
+ """
|
|
|
|
|
+ 游戏界面突发异常检测
|
|
|
|
|
+ :return: 没有出现返回False, 其他True
|
|
|
|
|
+ """
|
|
|
|
|
+ image = self.device.image
|
|
|
|
|
+ # appear_invitation = self.appear(self.I_G_ACCEPT)
|
|
|
|
|
+ appear_invitation = False
|
|
|
|
|
+ if not appear_invitation:
|
|
|
|
|
+ return False
|
|
|
|
|
+ logger.info('Invitation appearing')
|
|
|
|
|
+ invite_type = self.config.global_game.emergency.friend_invitation
|
|
|
|
|
+ detect_record = self.device.detect_record
|
|
|
|
|
+ match invite_type:
|
|
|
|
|
+ case FriendInvitation.ACCEPT:
|
|
|
|
|
+ logger.info(f"Accept friend invitation")
|
|
|
|
|
+ click_button = self.I_G_ACCEPT
|
|
|
|
|
+ case FriendInvitation.REJECT:
|
|
|
|
|
+ logger.info(f"Reject friend invitation")
|
|
|
|
|
+ click_button = self.I_G_REJECT
|
|
|
|
|
+ case FriendInvitation.ONLY_JADE:
|
|
|
|
|
+ # 勾协
|
|
|
|
|
+ logger.info(f"Only accept jade invitation")
|
|
|
|
|
+ if self.appear(self.I_G_JADE):
|
|
|
|
|
+ click_button = self.I_G_ACCEPT
|
|
|
|
|
+ else:
|
|
|
|
|
+ click_button = self.I_G_IGNORE
|
|
|
|
|
+ case FriendInvitation.JADE_AND_FOOD:
|
|
|
|
|
+ # 如果是接受勾协和粮协
|
|
|
|
|
+ logger.info(f"Accept jade and food invitation")
|
|
|
|
|
+ if self.appear(self.I_G_JADE) or self.appear(self.I_G_CAT_FOOD) or self.appear(self.I_G_DOG_FOOD):
|
|
|
|
|
+ click_button = self.I_G_ACCEPT
|
|
|
|
|
+ else:
|
|
|
|
|
+ click_button = self.I_G_IGNORE
|
|
|
|
|
+ case FriendInvitation.IGNORE:
|
|
|
|
|
+ # 如果是忽略
|
|
|
|
|
+ logger.info(f"Ignore friend invitation")
|
|
|
|
|
+ click_button = self.I_G_IGNORE
|
|
|
|
|
+ case _:
|
|
|
|
|
+ raise ScriptError(f'Unknown friend invitation type: {invite_type}')
|
|
|
|
|
+ if not click_button:
|
|
|
|
|
+ raise ScriptError(f'Unknown click button type: {invite_type}')
|
|
|
|
|
+ self.ui_click_until_disappear(click_button)
|
|
|
|
|
+ # 有的时候长战斗 点击后会取消战斗状态
|
|
|
|
|
+ self.device.detect_record = detect_record
|
|
|
|
|
+ return True
|
|
|
|
|
+
|
|
|
def screenshot(self):
|
|
def screenshot(self):
|
|
|
"""
|
|
"""
|
|
|
截图 引入中间函数的目的是 为了解决如协作的这类突发的事件
|
|
截图 引入中间函数的目的是 为了解决如协作的这类突发的事件
|
|
@@ -68,76 +117,19 @@ class BaseTask(GlobalGameAssets, CostumeBase):
|
|
|
"""
|
|
"""
|
|
|
self.device.screenshot()
|
|
self.device.screenshot()
|
|
|
# 判断勾协
|
|
# 判断勾协
|
|
|
- if self.friend_timer and self.friend_timer.reached():
|
|
|
|
|
- self.friend_timer.reset()
|
|
|
|
|
- invite = self.appear(self.I_G_ACCEPT)
|
|
|
|
|
- detect_record = self.device.detect_record
|
|
|
|
|
- # 如果是全部接受
|
|
|
|
|
- if invite and self.config.global_game.emergency.friend_invitation == FriendInvitation.ACCEPT:
|
|
|
|
|
- # 如果是接受邀请
|
|
|
|
|
- logger.info(f"Accept friend invitation")
|
|
|
|
|
- while 1:
|
|
|
|
|
- self.device.screenshot()
|
|
|
|
|
- if self.appear_then_click(self.I_G_ACCEPT, interval=1):
|
|
|
|
|
- continue
|
|
|
|
|
- if not self.appear(self.I_G_ACCEPT):
|
|
|
|
|
- break
|
|
|
|
|
- # 如果是全部拒绝
|
|
|
|
|
- elif invite and self.config.global_game.emergency.friend_invitation == FriendInvitation.REJECT:
|
|
|
|
|
- logger.info(f"Reject friend invitation")
|
|
|
|
|
- while 1:
|
|
|
|
|
- self.device.screenshot()
|
|
|
|
|
- if self.appear_then_click(self.I_G_REJECT, interval=1):
|
|
|
|
|
- continue
|
|
|
|
|
- if not self.appear(self.I_G_REJECT):
|
|
|
|
|
- break
|
|
|
|
|
- # 如果是仅接受勾协
|
|
|
|
|
- elif invite and self.config.global_game.emergency.friend_invitation == FriendInvitation.ONLY_JADE:
|
|
|
|
|
- logger.info(f"Accept jade invitation")
|
|
|
|
|
- while 1:
|
|
|
|
|
- self.device.screenshot()
|
|
|
|
|
- if self.appear(self.I_G_JADE):
|
|
|
|
|
- if self.appear_then_click(self.I_G_ACCEPT, interval=1):
|
|
|
|
|
- continue
|
|
|
|
|
- elif self.appear_then_click(self.I_G_IGNORE, interval=1):
|
|
|
|
|
- continue
|
|
|
|
|
- if not self.appear(self.I_G_ACCEPT):
|
|
|
|
|
- break
|
|
|
|
|
- # 如果是接受勾协和粮协
|
|
|
|
|
- elif invite and self.config.global_game.emergency.friend_invitation == FriendInvitation.JADE_AND_FOOD:
|
|
|
|
|
- logger.info(f"Accept jade and food invitation")
|
|
|
|
|
- while 1:
|
|
|
|
|
- self.device.screenshot()
|
|
|
|
|
- if self.appear(self.I_G_JADE) or self.appear(self.I_G_CAT_FOOD) or self.appear(self.I_G_DOG_FOOD):
|
|
|
|
|
- if self.appear_then_click(self.I_G_ACCEPT, interval=1):
|
|
|
|
|
- continue
|
|
|
|
|
- elif self.appear_then_click(self.I_G_IGNORE, interval=1):
|
|
|
|
|
- continue
|
|
|
|
|
- if not self.appear(self.I_G_ACCEPT):
|
|
|
|
|
- break
|
|
|
|
|
- # 如果是全部忽略
|
|
|
|
|
- elif invite and self.config.global_game.emergency.friend_invitation == FriendInvitation.IGNORE:
|
|
|
|
|
- logger.info(f"Ignore friend invitation")
|
|
|
|
|
- while 1:
|
|
|
|
|
- self.device.screenshot()
|
|
|
|
|
- if self.appear_then_click(self.I_G_IGNORE, interval=1):
|
|
|
|
|
- continue
|
|
|
|
|
- if not self.appear(self.I_G_IGNORE):
|
|
|
|
|
- break
|
|
|
|
|
- # 有的时候长战斗 点击后会取消战斗状态
|
|
|
|
|
- self.device.detect_record = detect_record
|
|
|
|
|
- # 判断网络异常
|
|
|
|
|
- if self.appear(self.I_NETWORK_ABNORMAL):
|
|
|
|
|
- logger.warning(f"Network abnormal")
|
|
|
|
|
- raise GameStuckError
|
|
|
|
|
-
|
|
|
|
|
- # 判断网络错误
|
|
|
|
|
- if self.appear(self.I_NETWORK_ERROR):
|
|
|
|
|
- logger.warning(f"Network error")
|
|
|
|
|
- raise GameStuckError
|
|
|
|
|
|
|
+ self._burst()
|
|
|
|
|
+
|
|
|
|
|
+ # # 判断网络异常
|
|
|
|
|
+ # if self.appear(self.I_NETWORK_ABNORMAL):
|
|
|
|
|
+ # logger.warning(f"Network abnormal")
|
|
|
|
|
+ # raise GameStuckError
|
|
|
|
|
+ #
|
|
|
|
|
+ # # 判断网络错误
|
|
|
|
|
+ # if self.appear(self.I_NETWORK_ERROR):
|
|
|
|
|
+ # logger.warning(f"Network error")
|
|
|
|
|
+ # raise GameStuckError
|
|
|
|
|
|
|
|
return self.device.image
|
|
return self.device.image
|
|
|
- # 返回截图
|
|
|
|
|
|
|
|
|
|
def appear(self, target: RuleImage, interval: float = None, threshold: float = None):
|
|
def appear(self, target: RuleImage, interval: float = None, threshold: float = None):
|
|
|
"""
|
|
"""
|