page.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. from itertools import compress
  2. import random
  3. import traceback
  4. from module.atom.click import RuleClick
  5. from tasks.BondlingFairyland.assets import BondlingFairylandAssets
  6. from tasks.GlobalGame.assets import GlobalGameAssets as GGA
  7. from tasks.GameUi.assets import GameUiAssets as G
  8. from tasks.KekkaiUtilize.assets import KekkaiUtilizeAssets
  9. from tasks.Restart.assets import RestartAssets
  10. from tasks.base_task import BaseTask as BT
  11. from tasks.RyouToppa.assets import RyouToppaAssets
  12. class PageRegistry:
  13. _registry = []
  14. @classmethod
  15. def register(cls, page):
  16. cls._registry.append(page)
  17. @classmethod
  18. def all(cls):
  19. return list(cls._registry)
  20. class Page:
  21. def __init__(self, check_button, links=None):
  22. if links is None:
  23. links = {}
  24. self.check_button = check_button
  25. self.links = links
  26. self.additional: list = None # 附加按钮或者是ocr检测按钮
  27. (filename, line_number, function_name, text) = traceback.extract_stack()[-2]
  28. self.name = text[:text.find('=')].strip()
  29. PageRegistry.register(self)
  30. def __eq__(self, other):
  31. return self.name == other.name
  32. def __hash__(self):
  33. return hash(self.name)
  34. def __str__(self):
  35. return self.name
  36. def link(self, button, destination):
  37. self.links[destination] = button
  38. #登录login
  39. page_login = Page(G.I_CHECK_LOGIN_FORM)
  40. # Main Home 主页
  41. page_main = Page(G.I_CHECK_MAIN)
  42. page_main.additional = [G.I_AD_CLOSE_RED, G.I_BACK_FRIENDS, RestartAssets.I_CANCEL_BATTLE,
  43. GGA.I_CHAT_CLOSE_BUTTON, G.I_CLOSE_CHAT_WINDOW,
  44. [G.I_MAIN_GOTO_SHIKIGAMI_RECORDS, RestartAssets.C_LOGIN_SCROLL_CLOSE_AREA, True]]
  45. # 召唤summon
  46. page_summon = Page(G.I_CHECK_SUMMON)
  47. page_summon.link(button=G.I_SUMMON_GOTO_MAIN, destination=page_main)
  48. page_main.link(button=G.I_MAIN_GOTO_SUMMON, destination=page_summon)
  49. # 探索exploration
  50. page_exploration = Page(G.I_CHECK_EXPLORATION)
  51. page_exploration.link(button=G.I_BACK_YOLLOW, destination=page_main)
  52. page_main.link(button=G.I_MAIN_GOTO_EXPLORATION, destination=page_exploration)
  53. # 町中town
  54. page_town = Page(G.I_CHECK_TOWN)
  55. page_town.link(button=G.I_TOWN_GOTO_MAIN, destination=page_main)
  56. page_main.link(button=G.I_MAIN_GOTO_TOWN, destination=page_town)
  57. # ************************************* 探索部分 *****************************************#
  58. # 觉醒 awake zones
  59. page_awake_zones = Page(G.I_CHECK_AWAKE)
  60. page_awake_zones.link(button=G.I_BACK_YOLLOW, destination=page_exploration)
  61. page_exploration.link(button=G.I_EXPLORATION_GOTO_AWAKE_ZONE, destination=page_awake_zones)
  62. # 御魂 soul zones
  63. page_soul_zones = Page(G.I_CHECK_SOUL_ZONES)
  64. page_soul_zones.link(button=G.I_BACK_YOLLOW, destination=page_exploration)
  65. page_exploration.link(button=G.I_EXPLORATION_GOTO_SOUL_ZONE, destination=page_soul_zones)
  66. # 结界突破 realm raid
  67. page_realm_raid = Page(G.I_CHECK_REALM_RAID)
  68. page_realm_raid.link(button=G.I_REALM_RAID_GOTO_EXPLORATION, destination=page_exploration)
  69. page_exploration.link(button=G.I_EXPLORATION_GOTO_REALM_RAID, destination=page_realm_raid)
  70. # 寮结界突破右上角 kekkai toppa
  71. page_kekkai_toppa = Page(G.I_KEKKAI_TOPPA)
  72. page_kekkai_toppa.link(button=G.I_REALM_RAID_GOTO_EXPLORATION, destination=page_exploration)
  73. page_realm_raid.link(button=RyouToppaAssets.I_RYOU_TOPPA, destination=page_kekkai_toppa)
  74. page_kekkai_toppa.link(button=G.I_RYOUTOPPA_GOTO_REALMRAID, destination=page_realm_raid)
  75. # 御灵 goryou realm
  76. page_goryou_realm = Page(G.I_CHECK_GORYOU)
  77. page_goryou_realm.link(button=G.I_BACK_YOLLOW, destination=page_exploration)
  78. page_exploration.link(button=G.I_EXPLORATION_GOTO_GORYOU_REALM, destination=page_goryou_realm)
  79. # 委派 delegation
  80. page_delegation = Page(G.I_CHECK_DELEGATION)
  81. page_delegation.link(button=G.I_BACK_YOLLOW, destination=page_exploration)
  82. page_exploration.link(button=G.I_EXPLORATION_GOTO_DELEGATION, destination=page_delegation)
  83. # 秘闻副本 SECRET zones
  84. page_secret_zones = Page(G.I_CHECK_SECRET_ZONES)
  85. page_secret_zones.link(button=G.I_BACK_YOLLOW, destination=page_exploration)
  86. page_exploration.link(button=G.I_EXPLORATION_GOTO_SECRET_ZONES, destination=page_secret_zones)
  87. # 地域鬼王 area boss
  88. page_area_boss = Page(G.I_CHECK_AREA_BOSS)
  89. page_area_boss.link(button=G.I_BACK_YOLLOW, destination=page_exploration)
  90. page_exploration.link(button=G.I_EXPLORATION_GOTO_AREA_BOSS, destination=page_area_boss)
  91. # 平安奇谭 heian kitan
  92. page_heian_kitan = Page(G.I_CHECK_HEIAN_KITAN)
  93. page_heian_kitan.link(button=G.I_CHECK_HEIAN_KITAN, destination=page_exploration)
  94. page_exploration.link(button=G.I_EXPLORATION_GOTO_HEIAN_KITAN, destination=page_heian_kitan)
  95. # 六道之门 six gates
  96. page_six_gates = Page(G.I_CHECK_SIX_GATES)
  97. page_six_gates.link(button=G.I_SIX_GATES_GOTO_EXPLORATION, destination=page_exploration)
  98. page_exploration.link(button=G.I_EXPLORATION_GOTO_SIX_GATES, destination=page_six_gates)
  99. # 契灵之境 bondling fairyland
  100. page_bondling_fairyland = Page(BondlingFairylandAssets.I_BALL_AREA)
  101. page_bondling_fairyland.link(button=G.I_BACK_YOLLOW, destination=page_exploration)
  102. page_exploration.link(button=G.I_EXPLORATION_GOTO_BONDLING_FAIRYLAND, destination=page_bondling_fairyland)
  103. # 英杰试炼 hero test
  104. page_hero_test = Page(G.I_CHECK_HERO_TEST)
  105. page_hero_test.link(button=G.I_BACK_YOLLOW, destination=page_exploration)
  106. page_exploration.link(button=G.I_EXPLORATION_GOTO_HERO_TEST, destination=page_hero_test)
  107. # ************************************* 町中部分 *****************************************#
  108. # 斗技 duel
  109. page_duel = Page(G.I_CHECK_DUEL)
  110. page_duel.link(button=G.I_BACK_YOLLOW, destination=page_town)
  111. page_town.link(button=G.I_TOWN_GOTO_DUEL, destination=page_duel)
  112. # 逢魔之时 demon_encounter
  113. page_demon_encounter = Page(G.I_CHECK_DEMON_ENCOUNTER)
  114. page_demon_encounter.link(button=G.I_BACK_YOLLOW, destination=page_town)
  115. page_town.link(button=G.I_TOWN_GOTO_DEMON_ENCOUNTER, destination=page_demon_encounter)
  116. # 逢魔之时现世逢魔 demon_encounter_realworld
  117. page_demon_encounter_realworld = Page(G.I_CHECK_DEMON_ENCOUNTER_REALWORLD)
  118. page_demon_encounter_realworld.link(button=G.I_BACK_YOLLOW, destination=page_demon_encounter)
  119. page_demon_encounter.link(button=G.I_DEMON_ENCOUNTER_REALWORLD_GOTO, destination=page_demon_encounter_realworld)
  120. # 狩猎战 hunt
  121. page_hunt = Page(G.I_CHECK_HUNT)
  122. page_hunt.link(button=G.I_BACK_YOLLOW, destination=page_town)
  123. page_town.link(button=G.I_TOWN_GOTO_HUNT, destination=page_hunt)
  124. # 狩猎战麒麟 hunt_kirin
  125. page_hunt_kirin = Page(G.I_CHECK_HUNT_KIRIN)
  126. page_hunt_kirin.link(button=G.I_BACK_YOLLOW, destination=page_town)
  127. page_town.link(button=G.I_TOWN_GOTO_HUNT, destination=page_hunt_kirin)
  128. # 协同斗技 draft_duel
  129. page_draft_duel = Page(G.I_CHECK_DRAFT_DUEL)
  130. page_draft_duel.link(button=G.I_BACK_YOLLOW, destination=page_town)
  131. page_town.link(button=G.I_TOWN_GOTO_DRAFT_DUEL, destination=page_draft_duel)
  132. # 百鬼弈 hyakkisen
  133. page_hyakkisen = Page(G.I_CHECK_HYAKKISEN)
  134. page_hyakkisen.link(button=G.I_BACK_YOLLOW, destination=page_town)
  135. page_town.link(button=G.I_TOWN_GOTO_HYAKKISEN, destination=page_hyakkisen)
  136. # 百鬼夜行
  137. page_hyakkiyakou = Page(G.I_CHECK_KYAKKIYAKOU)
  138. page_hyakkiyakou.link(button=G.I_HYAKKIYAKOU_CLOSE, destination=page_town)
  139. page_town.link(button=G.I_TOWN_GOTO_HYAKKIYAKOU, destination=page_hyakkiyakou)
  140. # ************************************* 庭院部分 *****************************************#
  141. # 式神录 shikigami_records
  142. page_shikigami_records = Page(G.I_CHECK_RECORDS)
  143. page_shikigami_records.additional = [G.I_AD_DISAPPEAR, G.I_RECORDS_CLOSE, GGA.I_UI_CANCEL_SAMLL]
  144. page_shikigami_records.link(button=G.I_BACK_Y, destination=page_main)
  145. page_main.link(button=G.I_MAIN_GOTO_SHIKIGAMI_RECORDS, destination=page_shikigami_records)
  146. # 阴阳术 onmyodo
  147. page_onmyodo = Page(G.I_CHECK_ONMYODO)
  148. page_onmyodo.link(button=G.I_BACK_Y, destination=page_main)
  149. page_main.link(button=G.I_MAIN_GOTO_ONMYODO, destination=page_onmyodo)
  150. # 好友 friends
  151. page_friends = Page(G.I_CHECK_FRIENDS)
  152. page_friends.link(button=G.I_BACK_Y, destination=page_main)
  153. page_main.link(button=G.I_MAIN_GOTO_FRIENDS, destination=page_friends)
  154. # 花合战 daily
  155. page_daily = Page(G.I_CHECK_DAILY)
  156. # page_daily.additional = [G.O_CLICK_CLOSE_1, G.O_CLICK_CLOSE_2]
  157. page_daily.link(button=G.I_BACK_Y, destination=page_main)
  158. page_main.link(button=G.I_MAIN_GOTO_DAILY, destination=page_daily)
  159. from tasks.DailyTrifles.assets import DailyTriflesAssets
  160. # 商店 mall
  161. page_mall = Page(check_button=[G.I_CHECK_MALL, DailyTriflesAssets.I_ROOM_GIFT])
  162. page_mall.additional = [G.I_AD_CLOSE_RED, GGA.I_UI_CANCEL_SAMLL, G.I_BACK_Y]
  163. page_mall.link(button=G.I_BACK_YOLLOW, destination=page_main)
  164. page_main.link(button=G.I_MAIN_GOTO_MALL, destination=page_mall)
  165. # 阴阳寮 guild
  166. page_guild = Page(G.I_CHECK_GUILD)
  167. page_guild.additional = [KekkaiUtilizeAssets.I_PLANT_TREE_CLOSE, G.I_CLOSE_CHAT_WINDOW]
  168. page_guild.link(button=G.I_BACK_Y, destination=page_main)
  169. page_main.link(button=G.I_MAIN_GOTO_GUILD, destination=page_guild)
  170. # 组队 team
  171. page_team = Page(G.I_CHECK_TEAM)
  172. page_team.link(button=G.I_BACK_Y, destination=page_main)
  173. page_main.link(button=G.I_MAIN_GOTO_TEAM, destination=page_team)
  174. # 收集 collection
  175. page_collection = Page(G.I_CHECK_COLLECTION)
  176. page_collection.additional = [GGA.I_UI_CANCEL_SAMLL]
  177. page_collection.link(button=G.I_BACK_Y, destination=page_main)
  178. page_main.link(button=G.I_MAIN_GOTO_COLLECTION, destination=page_collection)
  179. # 珍旅居
  180. page_travel = Page(G.I_CHECK_TRAVEL)
  181. page_travel.link(button=G.I_BACK_Y, destination=page_main)
  182. page_main.link(button=G.I_MAIN_GOTO_TRAVEL, destination=page_travel)
  183. # 道馆
  184. from tasks.Component.GeneralBattle.assets import GeneralBattleAssets
  185. from tasks.Dokan.assets import DokanAssets
  186. page_dokan = Page(DokanAssets.I_RYOU_DOKAN_CHECK)
  187. page_dokan.additional = [GeneralBattleAssets.I_EXIT, DokanAssets.I_RYOU_DOKAN_EXIT_ENSURE, G.I_BACK_BLUE]
  188. page_dokan.link(button=G.I_BACK_Y, destination=page_main)
  189. # ************************************* 战斗部分 *****************************************#
  190. # 战斗界面
  191. # page_battle = Page(GeneralBattleAssets.I_BATTLE_INFO)
  192. #
  193. #
  194. def random_click(low: int = None, high: int = None, ltrb: tuple = (True, False, True, False)) -> RuleClick | list[RuleClick]:
  195. """
  196. 随机生成RuleClick, 不传入参数则返回1个RuleClick, 传入参数则生成范围内的click数组
  197. :return: RuleClick或者RuleClick的数组
  198. """
  199. from tasks.Component.GeneralBattle.assets import GeneralBattleAssets as GBA
  200. click_area_list = [GBA.C_REWARD_1, GBA.C_REWARD_2, GBA.C_REWARD_3]
  201. click = random.choice(list(compress(click_area_list, ltrb)))
  202. click.name = "SAFE_RANDOM_CLICK"
  203. if low is None or high is None:
  204. return click
  205. return [click for _ in range(random.randint(low, high))]
  206. #
  207. #
  208. # # 奖励界面
  209. # page_reward = Page(check_button=[GeneralBattleAssets.I_REWARD_PURPLE_SNAKE_SKIN, GeneralBattleAssets.I_REWARD,
  210. # GeneralBattleAssets.I_REWARD_EXP_SOUL_4, GeneralBattleAssets.I_WIN,
  211. # GeneralBattleAssets.I_REWARD_GOLD, GeneralBattleAssets.I_REWARD_GOLD_SNAKE_SKIN,
  212. # GeneralBattleAssets.I_REWARD_SOUL_5, GeneralBattleAssets.I_REWARD_SOUL_6,
  213. # GGA.I_UI_REWARD, ])
  214. # page_reward.additional = [random_click()]
  215. # # 失败界面
  216. # page_failed = Page(GeneralBattleAssets.I_FALSE)
  217. # page_failed.additional = [random_click()]