| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307 |
- # This Python file uses the following encoding: utf-8
- # @author runhey
- # github https://github.com/runhey
- import time
- from datetime import timedelta, datetime
- 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, page_main
- from tasks.RealmRaid.script_task import ScriptTask as RealmRaidScriptTask
- from module.logger import logger
- from module.exception import RequestHumanTakeover, TaskEnd
- from module.atom.image_grid import ImageGrid
- class ScriptTask(GeneralBattle, GameUi, SwitchSoul, ExplorationAssets):
- medal_grid: ImageGrid = None
- def run(self):
- """
- 执行
- :return:
- """
- # 探索的 config
- explorationConfig = self.config.exploration
- # 切换御魂
- if explorationConfig.switch_soul_config.enable:
- self.ui_get_current_page()
- self.ui_goto(page_shikigami_records)
- self.run_switch_soul(explorationConfig.switch_soul_config.switch_group_team)
- if explorationConfig.switch_soul_config.enable_switch_by_name:
- self.ui_get_current_page()
- self.ui_goto(page_shikigami_records)
- self.run_switch_soul_by_name(explorationConfig.switch_soul_config.group_name,
- explorationConfig.switch_soul_config.team_name)
- # 开启加成
- con = self.config.exploration.exploration_config
- if con.buff_gold_50_click or con.buff_gold_100_click or con.buff_exp_50_click or con.buff_exp_100_click:
- self.ui_get_current_page()
- self.ui_goto(page_main)
- self.open_buff()
- if con.buff_gold_50_click:
- self.gold_50()
- if con.buff_gold_100_click:
- self.gold_100()
- if con.buff_exp_50_click:
- self.exp_50()
- if con.buff_exp_100_click:
- self.exp_100()
- self.close_buff()
- self.ui_get_current_page()
- # 探索页面
- self.ui_goto(page_exploration)
- # ************************* 跳转至对应指定章节并进入 *******************
- # 默认全部解锁, 当前处于第二十八章
- # 查找指定的章节:
- if not self.open_expect_level():
- logger.critical(f'Not find {explorationConfig.exploration_config.exploration_level} or'
- f' Enter {explorationConfig.exploration_config.exploration_level} failed!')
- raise RequestHumanTakeover
- con_scrolls = self.config.exploration.scrolls
- # 判断是否绘卷模式,设置探索次数
- if con_scrolls.scrolls_on:
- exploration_count = 50
- else:
- exploration_count = explorationConfig.exploration_config.current_exploration_count
- logger.info("exploration_count:" + str(exploration_count))
- if exploration_count > 0:
- count = 0
- while count < exploration_count:
- if self.wait_until_appear(self.I_E_EXPLORATION_CLICK, wait_time=1):
- # 如果打开绘卷模式
- if con_scrolls.scrolls_on:
- if con_scrolls.scrolls_cd > 0:
- self.screenshot()
- cu, res, total = self.O_REALM_RAID_NUMBER1.ocr(self.device.image)
- # 如果突破卷超出设定数量,去打个突
- if cu >= con_scrolls.scrolls_number:
- # 设定下次探索时间
- next_run = datetime.now() + timedelta(minutes=con_scrolls.scrolls_cd)
- self.set_next_run(task='Exploration', success=False, finish=False, target=next_run)
- self.appear_then_click(self.I_RED_CLOSE)
- self.ui_goto(page_main)
- # 关闭 buff
- if con.buff_gold_50_click or con.buff_gold_100_click or con.buff_exp_50_click or con.buff_exp_100_click:
- self.open_buff()
- self.gold_50(is_open=False)
- self.gold_100(is_open=False)
- self.exp_50(is_open=False)
- self.exp_100(is_open=False)
- self.close_buff()
- # 去打个突
- RealmRaidScriptTask(config=self.config, device=self.device).run()
- self.click(self.I_E_EXPLORATION_CLICK)
- count += 1
- logger.info("exploration count :" + str(count))
- # 进入战斗环节
- self.battle_process()
- # 判断宝箱
- if self.appear(self.I_TREASURE_BOX_CLICK):
- self.click(self.I_TREASURE_BOX_CLICK)
- self.open_expect_level()
- # 判断妖气
- elif self.appear(self.I_EXPLORATION_TITLE):
- self.open_expect_level()
- if self.wait_until_appear(self.I_RED_CLOSE, wait_time=2):
- self.appear_then_click(self.I_RED_CLOSE)
- self.ui_goto(page_main)
- # 关闭 buff
- if con.buff_gold_50_click or con.buff_gold_100_click or con.buff_exp_50_click or con.buff_exp_100_click:
- self.open_buff()
- self.gold_50(is_open=False)
- self.gold_100(is_open=False)
- self.exp_50(is_open=False)
- self.exp_100(is_open=False)
- self.close_buff()
- self.set_next_run(task='Exploration', success=True, finish=False)
- raise TaskEnd
- # 查找指定的章节:
- def open_expect_level(self):
- swipeCount = 0
- while 1:
- # 探索的 config
- explorationConfig = self.config.exploration
- # 判断有无目标章节
- 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({explorationConfig.exploration_config.exploration_level})
- # 有则跳出检测
- if self.appear(self.I_E_EXPLORATION_CLICK) or 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 = explorationConfig.exploration_config.exploration_level
- if self.ocr_appear_click(self.O_E_EXPLORATION_LEVEL_NUMBER):
- self.wait_until_appear(self.I_E_EXPLORATION_CLICK, wait_time=3)
- 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()
- # 战后奖励
- if self.appear(self.I_BATTLE_REWARD) and not self.appear(self.I_GET_REWARD):
- self.click(self.I_BATTLE_REWARD)
- # boss 战
- if self.appear_then_click(self.I_BOSS_BATTLE_BUTTON):
- if self.wait_until_appear(self.I_BATTLE_START, wait_time=5):
- self.run_general_battle(self.config.exploration.general_battle_config)
- else:
- continue
- # 小怪 战
- if self.appear_then_click(self.I_NORMAL_BATTLE_BUTTON):
- if self.wait_until_appear(self.I_BATTLE_START, wait_time=5):
- self.run_general_battle(self.config.exploration.general_battle_config)
- else:
- continue
- # 滑动
- elif self.appear(self.I_E_AUTO_ROTATE_ON) or self.appear(self.I_GET_REWARD):
- self.swipe(self.S_SWIPE_BACKGROUND_RIGHT)
- # 结束流程
- if self.appear(self.I_E_EXPLORATION_CLICK) or self.appear(self.I_EXPLORATION_TITLE):
- break
- # 战斗流程
- 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()
-
- # 修复卡结算问题
- # 卡结算是因为没有设置锁定队伍,修改后无论是否锁定都不会因为没有锁定队伍而卡在结算界面
- if not self.config.exploration.general_battle_config.lock_team_enable:
- self.config.exploration.general_battle_config.lock_team_enable = True
- # 进入战斗环节
- 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()
|