navbar.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. # This Python file uses the following encoding: utf-8
  2. # @author runhey
  3. # github https://github.com/runhey
  4. import re
  5. import time
  6. from module.logger import logger
  7. from tasks.GameUi.page import page_main, page_guild, page_mall
  8. from tasks.GameUi.game_ui import GameUi
  9. from tasks.Component.Buy.buy import Buy
  10. from tasks.RichMan.assets import RichManAssets
  11. class MallNavbar(GameUi, RichManAssets):
  12. def _enter_consignment(self):
  13. """
  14. 进入寄售屋
  15. :return:
  16. """
  17. self.ui_click(self.I_MALL_CONSIGNMENT, self.I_MALL_CONSIGNMENT_CHECK)
  18. def _enter_scales(self):
  19. """
  20. 进入密卷屋 蛇皮
  21. :return:
  22. """
  23. self.ui_click(self.I_MALL_SCCALES, self.I_MALL_SCCALES_CHECK)
  24. def _enter_bondlings(self):
  25. """
  26. 进入契灵
  27. :return:
  28. """
  29. self._enter_scales()
  30. self.ui_click(self.I_MALL_BONDLINGS_SURE, self.I_MALL_BONDLINGS_ON)
  31. def _enter_sundry(self):
  32. """
  33. 进入杂货铺
  34. :return:
  35. """
  36. self.ui_click(self.I_MALL_SUNDRY, self.I_MALL_SUNDRY_CHECK)
  37. def _enter_special(self):
  38. """
  39. 进入特殊
  40. :return:
  41. """
  42. self._enter_sundry()
  43. self.ui_click(self.I_SIDE_SURE_SPECIAL, self.I_SIDE_CHECK_SPECIAL)
  44. def _enter_honor(self):
  45. """
  46. 进入荣誉 屋
  47. :return:
  48. """
  49. self._enter_sundry()
  50. self.ui_click(self.I_SIDE_SUER_HONOR, self.I_SIDE_CHECK_HONOR)
  51. def _enter_friendship(self):
  52. """
  53. 友情点
  54. :return:
  55. """
  56. self._enter_sundry()
  57. self.ui_click(self.I_SIDE_SURE_FRIENDS, self.I_SIDE_CHECK_FRIENDS)
  58. def _enter_medal(self):
  59. """
  60. 勋章
  61. :return:
  62. """
  63. self._enter_sundry()
  64. self.ui_click(self.I_SIDE_SURE_MEDAL, self.I_SIDE_CHECK_MEDAL, interval=3, timeout=15)
  65. def _enter_charisma(self):
  66. """
  67. 魅力
  68. :return:
  69. """
  70. self._enter_sundry()
  71. self.ui_click(self.I_SIDE_SURE_CHARISMA, self.I_SIDE_CHECK_CHARISMA)
  72. def back_mall(self):
  73. """
  74. 返回商城
  75. :return:
  76. """
  77. self.goto_page(page_mall, skip_first_screenshot=False, timeout=6)
  78. def mall_resource(self, index: int) -> int:
  79. """
  80. 获取商城资源,
  81. :param index: 从左开始数
  82. :return:
  83. """
  84. match = {
  85. 1: self.O_MALL_RESOURCE_1,
  86. 2: self.O_MALL_RESOURCE_2,
  87. 3: self.O_MALL_RESOURCE_3,
  88. 4: self.O_MALL_RESOURCE_4,
  89. 5: self.O_MALL_RESOURCE_5,
  90. 6: self.O_MALL_RESOURCE_6,
  91. 7: self.O_MALL_RESOURCE_7,
  92. }
  93. self.screenshot()
  94. result = match[index].ocr(self.device.image)
  95. # match = re.search(r'\d+', result)
  96. # result = int(match.group())
  97. if not isinstance(result, int):
  98. logger.warning(f'Get mall resource {index} error, result: {result}')
  99. if result == 0:
  100. logger.warning(f'Get mall resource {index} error, result: {result}')
  101. return result
  102. def mall_check_money(self, index: int, least: int) -> bool:
  103. return self.mall_resource(index) >= least
  104. #add legacy check money method for compatibility, for consignment task
  105. def mall_check_money_legacy(self, index: int, least: int) -> bool:
  106. """
  107. Legacy implementation.
  108. 旧版商城资源判断逻辑(包含资源获取 + 校验)用于插画屋和寄售屋任务
  109. :param index: 从左开始数 1-4 对应第1-4个资源 least 最少多少
  110. :return: bool
  111. """
  112. match = {
  113. 1: self.O_LEGACY_MALL_RESOURCE_1,
  114. 2: self.O_LEGACY_MALL_RESOURCE_2,
  115. 3: self.O_LEGACY_MALL_RESOURCE_3,
  116. 4: self.O_LEGACY_MALL_RESOURCE_4,
  117. }
  118. self.screenshot()
  119. result = match[index].ocr(self.device.image)
  120. if not isinstance(result, int):
  121. logger.warning(f'Get mall resource {index} error, result: {result}')
  122. return False
  123. if result == 0:
  124. logger.warning(f'Get mall resource {index} error, result: {result}')
  125. return False
  126. return result >= least
  127. if __name__ == '__main__':
  128. from module.config.config import Config
  129. from module.device.device import Device
  130. c = Config('oas1')
  131. d = Device(c)
  132. t = MallNavbar(c, d)