| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- # This Python file uses the following encoding: utf-8
- # @author runhey
- # github https://github.com/runhey
- import time
- from tasks.Component.SwitchSoul.switch_soul import SwitchSoul
- from tasks.Exploration.assets import ExplorationAssets
- from tasks.Exploration.config import ChooseRarity, AutoRotate, AttackNumber
- from tasks.Component.GeneralBattle.general_battle import GeneralBattle
- from tasks.GameUi.game_ui import GameUi
- from tasks.GameUi.page import page_exploration, page_shikigami_records
- from module.logger import logger
- from module.exception import RequestHumanTakeover
- from module.atom.image_grid import ImageGrid
- class ScriptTask(GeneralBattle, GameUi, SwitchSoul, ExplorationAssets):
- medal_grid: ImageGrid = None
- def run(self):
- """
- 执行
- :return:
- """
- # 探索的 config
- config = self.config.exploration
- # 切换御魂
- if config.switch_soul_config.enable:
- self.ui_get_current_page()
- self.ui_goto(page_shikigami_records)
- self.run_switch_soul(config.switch_soul_config.switch_group_team)
- if config.switch_soul_config.enable_switch_by_name:
- self.ui_get_current_page()
- self.ui_goto(page_shikigami_records)
- self.run_switch_soul_by_name(config.switch_soul_config.group_name, config.switch_soul_config.team_name)
- self.ui_get_current_page()
- # 探索页面
- self.ui_goto(page_exploration)
- # ************************* 跳转至对应指定章节并进入 *******************
- # 默认全部解锁, 当前处于第二十八章
- # 查找指定的章节:
- if not self.open_expect_level():
- logger.critical(f'Not find {config.exploration_config.exploration_level} or'
- f' Enter {config.exploration_config.exploration_level} failed!')
- raise RequestHumanTakeover
- # 只探索7次
- if config.exploration_config.attack_number == AttackNumber.SEVEN:
- count = 0
- while count < 7:
- self.screenshot()
- if self.appear_then_click(self.I_E_EXPLORATION_CLICK):
- count += 1
- # 进入战斗环节
- self.battle_process()
- if self.appear_then_click(self.I_EXPLORATION_TITLE):
- self.open_expect_level()
- # 查找指定的章节:
- def open_expect_level(self):
- swipeCount = 0
- while 1:
- # 判断有无目标章节
- self.screenshot()
- # 获取当前章节名
- results = self.O_E_EXPLORATION_LEVEL_NUMBER.detect_and_ocr(self.device.image)
- text1 = [result.ocr_text for result in results]
- # 判断当前章节有无目标章节
- result = set(text1).intersection({config.exploration.exploration_config.exploration_level})
- # 有则跳出检测
- if result and len(result) > 0:
- break
- self.device.click_record_clear()
- self.swipe(self.S_SWIPE_LEVEL_UP)
- swipeCount += 1
- if swipeCount >= 25:
- return False
- # 选中对应章节
- while 1:
- self.screenshot()
- self.O_E_EXPLORATION_LEVEL_NUMBER.keyword = config.exploration.exploration_config.exploration_level
- if self.ocr_appear_click(self.O_E_EXPLORATION_LEVEL_NUMBER):
- self.wait_until_appear(self.I_E_EXPLORATION_CLICK)
- if self.appear(self.I_E_EXPLORATION_CLICK):
- break
- return True
- # 候补:
- def enter_settings_and_do_operations(self):
- # 打开设置
- self.click(self.C_CLICK_SETTINGS)
- while 1:
- self.screenshot()
- if self.appear(self.I_E_OPEN_SETTINGS):
- break
- else:
- self.click(self.C_CLICK_SETTINGS)
- if self.wait_until_appear(self.I_E_OPEN_SETTINGS):
- break
- # 候补出战数量识别
- self.screenshot()
- cu, res, total = self.O_E_ALTERNATE_NUMBER.ocr(self.device.image)
- if cu >= 40:
- self.appear_then_click(self.I_E_SURE_BUTTON)
- return
- else:
- self.add_shiki()
- # 添加式神
- def add_shiki(self):
- self.screenshot()
- # 点击展开式神稀有度选择界面
- self.click(self.C_CLICK_ALL_SHIKI)
- while 1:
- self.screenshot()
- # 成功进入稀有度选择界面
- if self.appear(self.I_E_ENTER_CHOOSE_RARITY):
- if self.config.exploration.exploration_config.choose_rarity == ChooseRarity.N:
- # N 卡
- self.click(self.C_CLICK_N_SHIKI)
- else:
- # 素材卡
- self.appear_then_click(self.I_E_ENTER_CHOOSE_RARITY)
- self.screenshot()
- if self.appear(self.I_E_N_RARITY):
- # 进入N卡添加界面 退出
- break
- if self.appear(self.I_E_S_RARITY):
- # 进入素材添加界面 退出
- break
- # 选中候补出战框
- self.click(self.C_CLICK_STANDBY_TEAM)
- # 移动至未候补的狗粮
- while 1:
- # 慢一点
- time.sleep(0.5)
- self.screenshot()
- if self.appear(self.I_E_RATATE_EXSIT):
- self.swipe(self.S_SWIPE_SHIKI_TO_LEFT)
- else:
- break
- while 1:
- # 候补出战数量识别
- self.screenshot()
- cu, res, total = self.O_E_ALTERNATE_NUMBER.ocr(self.device.image)
- if cu >= 40:
- break
- self.swipe(self.S_SWIPE_SHIKI_TO_LEFT_ONE)
- # 慢一点
- time.sleep(0.5)
- self.screenshot()
- self.click(self.C_CLICK_ROTATE_1)
- self.device.click_record_clear()
- self.appear_then_click(self.I_E_SURE_BUTTON)
- # 探索战斗流程
- def do_battle(self):
- while 1:
- self.screenshot()
- # boss 战
- if self.appear_then_click(self.I_BOSS_BATTLE_BUTTON):
- self.run_general_battle(self.config.exploration.general_battle_config)
- self.screenshot()
- if self.wait_until_appear(self.I_E_SETTINGS_BUTTON):
- while 1:
- self.screenshot()
- if self.appear_then_click(self.I_BATTLE_REWARD):
- self.screenshot()
- self.click(self.C_CLICK_ROTATE_1)
- time.sleep(0.5)
- if self.appear(self.I_EXPLORATION_TITLE):
- break
- if self.appear(self.I_E_EXPLORATION_CLICK):
- break
- if self.appear(self.I_E_EXPLORATION_CLICK) or self.appear(self.I_EXPLORATION_TITLE):
- break
- # 小怪 战
- if self.appear_then_click(self.I_NORMAL_BATTLE_BUTTON):
- self.run_general_battle(self.config.exploration.general_battle_config)
- self.screenshot()
- while self.appear(self.I_BATTLE_REWARD):
- self.screenshot()
- self.appear_then_click(self.I_BATTLE_REWARD)
- self.screenshot()
- else:
- self.swipe(self.S_SWIPE_BACKGROUND_RIGHT)
- # 战斗流程
- def battle_process(self):
- # 进入指定章节
- self.screenshot()
- if self.appear_then_click(self.I_E_EXPLORATION_CLICK):
- self.appear_then_click(self.I_E_SETTINGS_BUTTON)
- # ************************* 进入设置并操作 *******************
- # 候补以及自动轮换打开:
- # 自动轮换功能打开
- while 1:
- self.screenshot()
- # 自动轮换开着 则跳过
- if self.appear(self.I_E_AUTO_ROTATE_ON):
- break
- # 自动轮换关着 则打开
- if self.appear_then_click(self.I_E_AUTO_ROTATE_OFF):
- if self.appear(self.I_E_AUTO_ROTATE_ON):
- break
- # 自动添加候补式神
- if self.config.exploration.exploration_config.auto_rotate == AutoRotate.yes:
- self.enter_settings_and_do_operations()
- # 进入战斗环节
- self.do_battle()
- if __name__ == "__main__":
- from module.config.config import Config
- from module.device.device import Device
- config = Config('oas1')
- device = Device(config)
- t = ScriptTask(config, device)
- t.config.exploration.exploration_config.exploration_level = '第二十八章'
- t.run()
- # t.battle_process()
- # t.enter_settings_and_do_operations()
|