battle.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # This Python file uses the following encoding: utf-8
  2. # @author runhey
  3. # github https://github.com/runhey
  4. import random
  5. from tasks.Component.GeneralBattle.general_battle import GeneralBattle
  6. from tasks.BondlingFairyland.assets import BondlingFairylandAssets
  7. from tasks.BondlingFairyland.config_battle import BattleConfig
  8. from module.logger import logger
  9. class BondlingBattle(GeneralBattle, BondlingFairylandAssets):
  10. def run_battle(self, battle_config: BattleConfig) -> bool:
  11. """
  12. :return: 如果结契成功返回True,否则返回False
  13. """
  14. logger.hr("General battle start", 2)
  15. self.current_count += 1
  16. logger.info(f"Current count: {self.current_count}")
  17. if self.check_load():
  18. # 首先要判断进入战斗的界面
  19. self.green_mark(battle_config.green_enable, battle_config.green_mark)
  20. # 进入战斗过程
  21. return self.catch_battle_wait(battle_config.random_click_swipt_enable)
  22. def check_load(self) -> bool:
  23. """
  24. 检查战斗时候的加载动画
  25. 如何是还在加载种,有那个要准备的按钮,就返回True
  26. 如果已经进入战斗了,就返回False
  27. :return:
  28. """
  29. while 1:
  30. self.screenshot()
  31. if self.appear(self.I_BUFF):
  32. return True
  33. if self.appear(self.I_EXIT):
  34. return False
  35. def catch_battle_wait(self, random_click_swipt_enable: bool) -> bool:
  36. """
  37. 重写一个 战斗等待
  38. :return: 如果捕获成功返回True,否则返回False
  39. """
  40. self.device.stuck_record_add('BATTLE_STATUS_S')
  41. self.device.click_record_clear()
  42. # 有时候 只会点击 获得奖励和开始战斗
  43. # 战斗过程 随机点击和滑动 防封
  44. logger.info("Start battle process")
  45. win: bool = False
  46. while 1:
  47. self.screenshot()
  48. # 如果捕获成功
  49. if self.appear_then_click(self.I_CAP_SUCCESS, action=self.C_CAP_SUCCESS, interval=1):
  50. win = True
  51. # 如果捕获失败
  52. if self.appear_then_click(self.I_CAP_FAILURE, action=self.C_CAP_SUCCESS, interval=1):
  53. win = False
  54. # 如果领奖励
  55. if self.appear(self.I_REWARD, threshold=0.6):
  56. break
  57. # 如果开启战斗过程随机滑动
  58. if random_click_swipt_enable:
  59. self.random_click_swipt()
  60. # 确定获得奖励 无论是胜利还是失败
  61. if win:
  62. logger.info("Catch success")
  63. else:
  64. logger.info("Catch failure")
  65. while 1:
  66. self.screenshot()
  67. # 如果出现领奖励
  68. action_click = random.choice([self.C_REWARD_1, self.C_REWARD_2, self.C_REWARD_3])
  69. if self.appear_then_click(self.I_REWARD, action=action_click, interval=1.5):
  70. continue
  71. if not self.appear(self.I_REWARD):
  72. break
  73. logger.info("Get reward")
  74. return win