page.py 11 KB

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