battle.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. # 战斗过程 随机点击和滑动 防封
  42. logger.info("Start battle process")
  43. win: bool = False
  44. while 1:
  45. self.screenshot()
  46. # 如果捕获成功
  47. if self.appear_then_click(self.I_CAP_SUCCESS, action=self.C_CAP_SUCCESS, interval=1):
  48. win = True
  49. # 如果捕获失败
  50. if self.appear_then_click(self.I_CAP_FAILURE, action=self.C_CAP_SUCCESS, interval=1):
  51. win = False
  52. # 如果领奖励
  53. if self.appear(self.I_REWARD, threshold=0.6):
  54. break
  55. # 如果开启战斗过程随机滑动
  56. if random_click_swipt_enable:
  57. self.random_click_swipt()
  58. # 确定获得奖励 无论是胜利还是失败
  59. if win:
  60. logger.info("Catch success")
  61. else:
  62. logger.info("Catch failure")
  63. while 1:
  64. self.screenshot()
  65. # 如果出现领奖励
  66. action_click = random.choice([self.C_REWARD_1, self.C_REWARD_2, self.C_REWARD_3])
  67. if self.appear_then_click(self.I_REWARD, action=action_click, interval=1.5):
  68. continue
  69. if not self.appear(self.I_REWARD):
  70. break
  71. logger.info("Get reward")
  72. return win