|
@@ -2,489 +2,329 @@
|
|
|
# @author runhey
|
|
# @author runhey
|
|
|
# github https://github.com/runhey
|
|
# github https://github.com/runhey
|
|
|
from time import sleep
|
|
from time import sleep
|
|
|
-from datetime import time, datetime, timedelta
|
|
|
|
|
|
|
|
|
|
-import cv2
|
|
|
|
|
-import numpy as np
|
|
|
|
|
-from module.atom.ocr import RuleOcr
|
|
|
|
|
|
|
+import random
|
|
|
|
|
+from datetime import time, datetime, timedelta
|
|
|
|
|
|
|
|
from module.logger import logger
|
|
from module.logger import logger
|
|
|
from module.exception import TaskEnd
|
|
from module.exception import TaskEnd
|
|
|
from module.base.timer import Timer
|
|
from module.base.timer import Timer
|
|
|
|
|
|
|
|
from tasks.Component.GeneralBattle.general_battle import GeneralBattle
|
|
from tasks.Component.GeneralBattle.general_battle import GeneralBattle
|
|
|
-from tasks.Component.GeneralBattle.config_general_battle import GreenMarkType
|
|
|
|
|
|
|
+from tasks.Component.SwitchOnmyoji.switch_onmyoji import SwitchOnmyoji
|
|
|
from tasks.GameUi.game_ui import GameUi
|
|
from tasks.GameUi.game_ui import GameUi
|
|
|
-from tasks.Duel.config import Duel, Onmyoji
|
|
|
|
|
|
|
+from tasks.GameUi.page import page_duel, page_onmyodo, random_click
|
|
|
|
|
+from tasks.Duel.config import Duel
|
|
|
from tasks.Duel.assets import DuelAssets
|
|
from tasks.Duel.assets import DuelAssets
|
|
|
from tasks.Component.SwitchSoul.switch_soul import SwitchSoul
|
|
from tasks.Component.SwitchSoul.switch_soul import SwitchSoul
|
|
|
-from tasks.GameUi.page import page_main, page_duel, page_onmyodo, page_shikigami_records
|
|
|
|
|
-import os
|
|
|
|
|
-from module.atom.image import RuleImage
|
|
|
|
|
-from tasks.GlobalGame.assets import GlobalGameAssets as GGA
|
|
|
|
|
|
|
+from tasks.GameUi.page import page_main, page_shikigami_records
|
|
|
|
|
+
|
|
|
""" 斗技 """
|
|
""" 斗技 """
|
|
|
|
|
|
|
|
|
|
|
|
|
-class ScriptTask(GameUi, GeneralBattle, SwitchSoul, DuelAssets):
|
|
|
|
|
- battle_count = 0
|
|
|
|
|
|
|
+class ScriptTask(GameUi, GeneralBattle, SwitchSoul, DuelAssets, SwitchOnmyoji):
|
|
|
battle_win_count = 0
|
|
battle_win_count = 0
|
|
|
battle_lose_count = 0
|
|
battle_lose_count = 0
|
|
|
current_score = 0
|
|
current_score = 0
|
|
|
- battle_win_copy=battle_win_count
|
|
|
|
|
- battle_lose_copy=battle_lose_count
|
|
|
|
|
- def run(self):
|
|
|
|
|
|
|
+ pre_battle_win_cnt = battle_win_count
|
|
|
|
|
+ pre_battle_lose_cnt = battle_lose_count
|
|
|
|
|
+ is_celeb: bool = False # 是否是名仕
|
|
|
|
|
+ conf: Duel = None
|
|
|
|
|
|
|
|
|
|
+ def run(self):
|
|
|
current_time = datetime.now().time()
|
|
current_time = datetime.now().time()
|
|
|
if not (time(12, 00) <= current_time < time(23, 00)):
|
|
if not (time(12, 00) <= current_time < time(23, 00)):
|
|
|
self.set_next_run(task='Duel', success=True, finish=False)
|
|
self.set_next_run(task='Duel', success=True, finish=False)
|
|
|
raise TaskEnd('Duel')
|
|
raise TaskEnd('Duel')
|
|
|
-
|
|
|
|
|
- con = self.config.duel
|
|
|
|
|
- # 切换御魂
|
|
|
|
|
- if con.switch_soul.enable:
|
|
|
|
|
- self.ui_get_current_page()
|
|
|
|
|
- self.ui_goto(page_shikigami_records)
|
|
|
|
|
- self.run_switch_soul(con.switch_soul.switch_group_team)
|
|
|
|
|
-
|
|
|
|
|
- if con.switch_soul.enable_switch_by_name:
|
|
|
|
|
- self.ui_get_current_page()
|
|
|
|
|
- self.ui_goto(page_shikigami_records)
|
|
|
|
|
- self.run_switch_soul_by_name(con.switch_soul.group_name,con.switch_soul.team_name)
|
|
|
|
|
-
|
|
|
|
|
- con = self.config.duel.duel_config
|
|
|
|
|
- celeb_con = self.config.duel.duel_celeb_config
|
|
|
|
|
- self.current_score = celeb_con.initial_score
|
|
|
|
|
- limit_time = con.limit_time
|
|
|
|
|
|
|
+ self.conf = self.config.duel
|
|
|
|
|
+ limit_time = self.conf.duel_config.limit_time
|
|
|
self.limit_time: timedelta = timedelta(hours=limit_time.hour, minutes=limit_time.minute,
|
|
self.limit_time: timedelta = timedelta(hours=limit_time.hour, minutes=limit_time.minute,
|
|
|
seconds=limit_time.second)
|
|
seconds=limit_time.second)
|
|
|
-
|
|
|
|
|
- self.ui_get_current_page()
|
|
|
|
|
- self.ui_goto(page_main)
|
|
|
|
|
- # 切换阴阳师
|
|
|
|
|
- if con.switch_enabled:
|
|
|
|
|
- self.ui_get_current_page()
|
|
|
|
|
- self.ui_goto(page_onmyodo)
|
|
|
|
|
- # 清明
|
|
|
|
|
- if con.switch_onmyoji == Onmyoji.Qm:
|
|
|
|
|
- self.switch_kagura(con, self.C_QM_ZHAN, self.I_QM_ZHAN)
|
|
|
|
|
- # 神乐
|
|
|
|
|
- elif con.switch_onmyoji == Onmyoji.Sl:
|
|
|
|
|
- self.switch_kagura(con, self.C_SL_ZHAN, self.I_SL_ZHAN)
|
|
|
|
|
- # 源博雅
|
|
|
|
|
- elif con.switch_onmyoji == Onmyoji.Yby:
|
|
|
|
|
- self.switch_kagura(con, self.C_YBY_ZHAN, self.I_YBY_ZHAN)
|
|
|
|
|
- # 八百比丘尼
|
|
|
|
|
- elif con.switch_onmyoji == Onmyoji.Bbbqn:
|
|
|
|
|
- self.switch_kagura(con, self.C_BBBQN_ZHAN, self.I_BBBQN_ZHAN)
|
|
|
|
|
- # 源赖光
|
|
|
|
|
- elif con.switch_onmyoji == Onmyoji.Ylg:
|
|
|
|
|
- self.switch_yorimitsu()
|
|
|
|
|
-
|
|
|
|
|
- self.ui_get_current_page()
|
|
|
|
|
- self.ui_goto(page_duel)
|
|
|
|
|
- # 切换御魂
|
|
|
|
|
- if con.switch_all_soul:
|
|
|
|
|
- self.switch_all_soul()
|
|
|
|
|
-
|
|
|
|
|
- # 循环
|
|
|
|
|
- duel_week_over = False
|
|
|
|
|
- while 1:
|
|
|
|
|
|
|
+ self.prepare_duel()
|
|
|
|
|
+ while True:
|
|
|
self.screenshot()
|
|
self.screenshot()
|
|
|
- # 关闭恭喜晋升段位页面
|
|
|
|
|
- if self.appear_then_click(GGA.I_UI_BACK_RED):
|
|
|
|
|
- continue
|
|
|
|
|
- if self.appear_then_click(self.I_REWARD):
|
|
|
|
|
- continue
|
|
|
|
|
- if self.appear_then_click(self.I_WIN):
|
|
|
|
|
- continue
|
|
|
|
|
|
|
+ self.check_and_get_reward()
|
|
|
if not self.duel_main():
|
|
if not self.duel_main():
|
|
|
|
|
+ self.ui_goto_page(page_duel)
|
|
|
continue
|
|
continue
|
|
|
- # 检查分数
|
|
|
|
|
- current_score = self.check_score()
|
|
|
|
|
-
|
|
|
|
|
- # if current_score == 3000 and self.check_honor():
|
|
|
|
|
- # # 3000分和满荣誉退出,退出
|
|
|
|
|
- # logger.info('Duel task is over score')
|
|
|
|
|
- # duel_week_over = True
|
|
|
|
|
- # break
|
|
|
|
|
-
|
|
|
|
|
- if datetime.now() - self.start_time >= self.limit_time:
|
|
|
|
|
- # 任务执行时间超过限制时间,退出
|
|
|
|
|
- logger.info('Duel task is over time')
|
|
|
|
|
- break
|
|
|
|
|
-
|
|
|
|
|
- # 不开启名仕战斗,到达名士直接退出
|
|
|
|
|
- if not celeb_con.celeb_battle:
|
|
|
|
|
- if self.appear(self.I_D_CELEB_STAR) or self.appear(self.I_D_CELEB_HONOR):
|
|
|
|
|
- logger.info('You are already a celeb(名仕)')
|
|
|
|
|
- current_score = "名仕"
|
|
|
|
|
- duel_week_over = True
|
|
|
|
|
- break
|
|
|
|
|
- # 练习
|
|
|
|
|
- if self.appear(self.I_BATTLE_WITH_TRAIN) or self.appear(self.I_BATTLE_WITH_TRAIN2):
|
|
|
|
|
- break
|
|
|
|
|
-
|
|
|
|
|
- if con.honor_full_exit and self.check_honor():
|
|
|
|
|
- # 荣誉满了,退出
|
|
|
|
|
- logger.info('Duel task is over honor')
|
|
|
|
|
- break
|
|
|
|
|
-
|
|
|
|
|
- # 当前分数跟目标分数比较
|
|
|
|
|
- if current_score >= con.target_score:
|
|
|
|
|
- # 分数够了
|
|
|
|
|
- logger.info('Duel task is over score')
|
|
|
|
|
|
|
+ if not self.can_start_duel():
|
|
|
break
|
|
break
|
|
|
-
|
|
|
|
|
- # 进行一次斗技
|
|
|
|
|
- self.duel_one(current_score, con.green_enable, con.green_mark, celeb_con.ban_name)
|
|
|
|
|
-
|
|
|
|
|
|
|
+ self.start_duel()
|
|
|
logger.info('Duel battle end')
|
|
logger.info('Duel battle end')
|
|
|
- # 记得退回去到町中
|
|
|
|
|
- self.ui_click(self.I_UI_BACK_YELLOW, self.I_CHECK_TOWN)
|
|
|
|
|
-
|
|
|
|
|
- if duel_week_over:
|
|
|
|
|
- self.set_next_run(task='Duel', success=True, finish=True)
|
|
|
|
|
- else:
|
|
|
|
|
- self.set_next_run(task='Duel', success=True, finish=False)
|
|
|
|
|
-
|
|
|
|
|
|
|
+ self.set_next_run(task='Duel', success=True, finish=True)
|
|
|
|
|
+ self.ui_goto_page(page_main)
|
|
|
# 调起花合战
|
|
# 调起花合战
|
|
|
self.set_next_run(task='TalismanPass', target=datetime.now())
|
|
self.set_next_run(task='TalismanPass', target=datetime.now())
|
|
|
raise TaskEnd('Duel')
|
|
raise TaskEnd('Duel')
|
|
|
|
|
|
|
|
- def duel_main(self, screenshot=False) -> bool:
|
|
|
|
|
- """
|
|
|
|
|
- 判断是否斗技主界面
|
|
|
|
|
- :return:
|
|
|
|
|
- """
|
|
|
|
|
- if screenshot:
|
|
|
|
|
- self.screenshot()
|
|
|
|
|
- return self.appear(self.I_D_HELP) or self.appear(self.I_D_CELEB_STAR) or self.appear(self.I_D_CELEB_HONOR)
|
|
|
|
|
|
|
+ def prepare_duel(self):
|
|
|
|
|
+ """斗技准备工作(切换御魂or阴阳师...), 最后回到斗技主界面"""
|
|
|
|
|
+ self.ui_goto_page(page_main)
|
|
|
|
|
+ self.switch_soul()
|
|
|
|
|
+ if self.conf.duel_config.switch_enabled:
|
|
|
|
|
+ self.ui_goto_page(page_onmyodo)
|
|
|
|
|
+ self.switch_onmyoji(self.conf.duel_config.switch_onmyoji)
|
|
|
|
|
+ self.ui_goto_page(page_duel)
|
|
|
|
|
+ self.switch_all_soul()
|
|
|
|
|
+ self.current_score = self.conf.duel_celeb_config.initial_score
|
|
|
|
|
+
|
|
|
|
|
+ def can_start_duel(self) -> bool:
|
|
|
|
|
+ """是否可以运行斗技"""
|
|
|
|
|
+ # 任务执行时间超过限制时间,退出
|
|
|
|
|
+ if datetime.now() - self.start_time >= self.limit_time:
|
|
|
|
|
+ logger.info('Duel task is over time')
|
|
|
|
|
+ return False
|
|
|
|
|
+ # 当前分数跟目标分数比较, 判断分数是否已经满足条件
|
|
|
|
|
+ if self.get_and_update_cur_score() >= self.conf.duel_config.target_score:
|
|
|
|
|
+ logger.info('Duel task is over score')
|
|
|
|
|
+ return False
|
|
|
|
|
+ # 若不开启名仕战斗, 则到达名士直接退出
|
|
|
|
|
+ if not self.conf.duel_celeb_config.celeb_battle and self.is_celeb:
|
|
|
|
|
+ logger.info('You are already a celeb(名仕)')
|
|
|
|
|
+ return False
|
|
|
|
|
+ # 练习
|
|
|
|
|
+ if self.appear(self.I_BATTLE_WITH_TRAIN) or self.appear(self.I_BATTLE_WITH_TRAIN2):
|
|
|
|
|
+ return False
|
|
|
|
|
+ # 荣誉满了,退出
|
|
|
|
|
+ if self.conf.duel_config.honor_full_exit and self.check_honor():
|
|
|
|
|
+ logger.info('Duel task is over honor')
|
|
|
|
|
+ return False
|
|
|
|
|
+ return True
|
|
|
|
|
+
|
|
|
|
|
+ def start_duel(self):
|
|
|
|
|
+ """进行一次斗技"""
|
|
|
|
|
+ logger.hr('Duel battle', 2)
|
|
|
|
|
+ self.current_count += 1
|
|
|
|
|
+ self.enter_battle()
|
|
|
|
|
+ self.battle_prepare()
|
|
|
|
|
+ battle_ret = self.wait_battle()
|
|
|
|
|
+ if battle_ret:
|
|
|
|
|
+ self.pre_battle_win_cnt = self.battle_win_count
|
|
|
|
|
+ self.battle_win_count += 1
|
|
|
|
|
+ else:
|
|
|
|
|
+ self.pre_battle_lose_cnt = self.battle_lose_count
|
|
|
|
|
+ self.battle_lose_count += 1
|
|
|
|
|
+ task_run_time_seconds = timedelta(seconds=int((datetime.now() - self.start_time).total_seconds()))
|
|
|
|
|
+ logger.info(f'battle result: {battle_ret}')
|
|
|
|
|
+ logger.info(f'battle count:{self.current_count} | win:{self.battle_win_count} failure:{self.battle_lose_count}')
|
|
|
|
|
+ logger.info(f'battle time: {task_run_time_seconds} / {self.limit_time}')
|
|
|
|
|
+ self.ui_goto_page(page_duel)
|
|
|
|
|
|
|
|
- def switch_all_soul(self):
|
|
|
|
|
- """
|
|
|
|
|
- 一键切换所有御魂
|
|
|
|
|
- :return:
|
|
|
|
|
- """
|
|
|
|
|
- click_count = 0 # 计数
|
|
|
|
|
- while 1:
|
|
|
|
|
|
|
+ def enter_battle(self):
|
|
|
|
|
+ """点击开始战斗(一直到出现战斗准备界面)"""
|
|
|
|
|
+ logger.hr('duel battle matching')
|
|
|
|
|
+ while not self.is_in_battle_prepare():
|
|
|
self.screenshot()
|
|
self.screenshot()
|
|
|
- if click_count >= 4:
|
|
|
|
|
|
|
+ # 战斗按钮
|
|
|
|
|
+ self.ui_click_until_disappear(self.I_D_BATTLE, interval=1.2)
|
|
|
|
|
+ self.ui_click_until_disappear(self.I_D_BATTLE2, interval=1.2)
|
|
|
|
|
+ # 战斗带保护的按钮
|
|
|
|
|
+ self.ui_click_until_disappear(self.I_D_BATTLE_PROTECT, interval=1.2)
|
|
|
|
|
+
|
|
|
|
|
+ def battle_prepare(self):
|
|
|
|
|
+ """选式神准备斗技阶段"""
|
|
|
|
|
+ logger.hr('duel battle preparing')
|
|
|
|
|
+ not_in_prepare_cnt, max_retry = 0, 3
|
|
|
|
|
+ while True:
|
|
|
|
|
+ if not_in_prepare_cnt >= max_retry: # max_retry次识别不到任何阶段元素(准备,战斗,结算), 退出
|
|
|
break
|
|
break
|
|
|
-
|
|
|
|
|
- if self.appear_then_click(self.I_D_TEAM, interval=1):
|
|
|
|
|
|
|
+ self.screenshot()
|
|
|
|
|
+ if self.is_battle_end() or self.is_in_real_battle(): # 战斗已经结束或已经开始战斗
|
|
|
|
|
+ break
|
|
|
|
|
+ if not self.is_in_battle_prepare(): # 一般不会出现这种情况(不在准备,战斗,结束界面), 但是处理一下
|
|
|
|
|
+ not_in_prepare_cnt += 1
|
|
|
|
|
+ sleep(random.uniform(1.2, 2.4))
|
|
|
continue
|
|
continue
|
|
|
- if self.appear_then_click(self.I_UI_CONFIRM, interval=0.6):
|
|
|
|
|
|
|
+ not_in_prepare_cnt = 0
|
|
|
|
|
+ # 再次检查是否是名仕(若斗技主界面识别名仕失效的话)
|
|
|
|
|
+ if self.appear_then_click(self.I_BAN, interval=1.2):
|
|
|
|
|
+ self.is_celeb = True
|
|
|
continue
|
|
continue
|
|
|
- if self.appear_then_click(self.I_D_TEAM_SWTICH, interval=1):
|
|
|
|
|
- click_count += 1
|
|
|
|
|
|
|
+ # 名仕不开启自动上阵, 根据最后一个式神的名字是否改变来检查自己式神是否被ban
|
|
|
|
|
+ if not self.appear(self.I_D_CHECK_BAN, interval=0.8) and self.is_celeb:
|
|
|
|
|
+ ocr_name = self.O_D_BAN_NAME.ocr(self.device.image)
|
|
|
|
|
+ shikigami_banned = ocr_name != '' and not any(
|
|
|
|
|
+ char in ocr_name for char in self.conf.duel_celeb_config.ban_name)
|
|
|
|
|
+ logger.info(f'Check self shikigami is banned:{shikigami_banned}')
|
|
|
|
|
+ if shikigami_banned:
|
|
|
|
|
+ self.duel_exit_battle()
|
|
|
|
|
+ continue
|
|
|
|
|
+ self.click(self.C_DUEL_CLICK_5, interval=random.uniform(0.7, 1.4))
|
|
|
|
|
+ sleep(random.uniform(1.5, 3)) # 降低点击频率和ocr识别频率
|
|
|
continue
|
|
continue
|
|
|
- logger.info('Souls Switch is complete')
|
|
|
|
|
- self.ui_click(self.I_UI_BACK_YELLOW, self.I_D_TEAM)
|
|
|
|
|
-
|
|
|
|
|
- def switch_kagura(self,con, target1, target2):
|
|
|
|
|
- click_count = 0 # 计数
|
|
|
|
|
- while 1:
|
|
|
|
|
|
|
+ # 点击自动上阵或准备
|
|
|
|
|
+ if self.appear_then_click(self.I_D_AUTO_ENTRY, interval=1.2) or \
|
|
|
|
|
+ self.appear_then_click(self.I_D_PREPARE, interval=1.2):
|
|
|
|
|
+ self.reset_device('PREPARE_BEFORE_BATTLE')
|
|
|
|
|
+
|
|
|
|
|
+ def wait_battle(self) -> bool:
|
|
|
|
|
+ """等待战斗结束, 返回战斗结果, 最后会退出到斗技主界面"""
|
|
|
|
|
+ logger.hr('duel battle waiting')
|
|
|
|
|
+ battle_operated = False
|
|
|
|
|
+ battle_timeout_timer = Timer(270).start()
|
|
|
|
|
+ ret_timer = Timer(5)
|
|
|
|
|
+ battle_timeout_cnt, max_timeout_cnt = 0, 3
|
|
|
|
|
+ ret = None
|
|
|
|
|
+ while True:
|
|
|
self.screenshot()
|
|
self.screenshot()
|
|
|
- if click_count >= 4:
|
|
|
|
|
|
|
+ self.check_and_get_reward()
|
|
|
|
|
+ if self.appear(self.I_CHECK_DUEL, interval=0.6) and self.appear(self.I_D_HELP, interval=0.6): # 斗技主界面
|
|
|
break
|
|
break
|
|
|
- if self.appear(self.I_YINYANGSHUOK, interval=1):
|
|
|
|
|
- break
|
|
|
|
|
- if self.appear_then_click(self.I_YINYANGSHU, interval=1):
|
|
|
|
|
- click_count += 1
|
|
|
|
|
|
|
+ if self.appear_then_click(self.I_UI_BACK_RED, interval=1.2): # 关闭段位上升页面
|
|
|
|
|
+ ret_timer.reset()
|
|
|
continue
|
|
continue
|
|
|
- click_count = 0 # 计数
|
|
|
|
|
- while 1:
|
|
|
|
|
- self.screenshot()
|
|
|
|
|
- if click_count >= 4:
|
|
|
|
|
|
|
+ if ret_timer.started() and ret_timer.reached(): # 兜底逻辑, 已经结算了但是还没有到斗技主界面
|
|
|
|
|
+ self.ui_goto_page(page_duel)
|
|
|
break
|
|
break
|
|
|
- if self.appear(self.I_YYSJIOAHUAN, interval=1):
|
|
|
|
|
- break
|
|
|
|
|
- if self.appear_then_click(self.I_JIAOTI, interval=1):
|
|
|
|
|
|
|
+ if self.is_battle_win():
|
|
|
|
|
+ ret = True
|
|
|
|
|
+ ret_timer.start()
|
|
|
|
|
+ self.click(random_click(ltrb=(True, True, False, True)), interval=1.2)
|
|
|
continue
|
|
continue
|
|
|
- if self.appear_then_click(self.I_YINGJIE, interval=1):
|
|
|
|
|
- click_count += 1
|
|
|
|
|
|
|
+ if self.is_battle_lose():
|
|
|
|
|
+ ret = False
|
|
|
|
|
+ ret_timer.start()
|
|
|
|
|
+ self.click(random_click(ltrb=(True, True, False, True)), interval=1.2)
|
|
|
continue
|
|
continue
|
|
|
- click_count = 0 # 计数
|
|
|
|
|
- while 1:
|
|
|
|
|
- self.screenshot()
|
|
|
|
|
- if click_count >= 4:
|
|
|
|
|
- break
|
|
|
|
|
- if self.appear(target2, interval=1):
|
|
|
|
|
- break
|
|
|
|
|
- if self.appear_then_click(self.I_JIAOTI, interval=1):
|
|
|
|
|
|
|
+ if battle_timeout_cnt >= max_timeout_cnt:
|
|
|
|
|
+ logger.warning('Duel battle timeout[>15 minutes], exit')
|
|
|
|
|
+ self.duel_exit_battle()
|
|
|
continue
|
|
continue
|
|
|
- if self.click(target1, interval=1):
|
|
|
|
|
- click_count += 1
|
|
|
|
|
|
|
+ if ret is None and not battle_operated: # 进行战斗前的操作
|
|
|
|
|
+ self.ui_click(self.O_D_HAND, self.O_D_AUTO, interval=0.8)
|
|
|
|
|
+ self.green_mark(self.conf.duel_config.green_enable, self.conf.duel_config.green_mark)
|
|
|
|
|
+ battle_operated = True
|
|
|
|
|
+ self.reset_device('BATTLE_STATUS_S')
|
|
|
continue
|
|
continue
|
|
|
- self.ui_get_current_page()
|
|
|
|
|
- self.ui_goto(page_main)
|
|
|
|
|
|
|
+ if battle_timeout_timer.reached_and_reset():
|
|
|
|
|
+ battle_timeout_cnt += 1
|
|
|
|
|
+ self.reset_device('BATTLE_STATUS_S')
|
|
|
|
|
+ logger.warning("battle' time is too long, increase wait time")
|
|
|
|
|
+ return ret
|
|
|
|
|
|
|
|
- def switch_yorimitsu(self):
|
|
|
|
|
- click_count = 0 # 计数
|
|
|
|
|
|
|
+ def duel_exit_battle(self):
|
|
|
while 1:
|
|
while 1:
|
|
|
self.screenshot()
|
|
self.screenshot()
|
|
|
- if click_count >= 4:
|
|
|
|
|
- break
|
|
|
|
|
- if self.appear(self.I_YINYANGSHUOK, interval=1):
|
|
|
|
|
- break
|
|
|
|
|
- if self.appear_then_click(self.I_YINYANGSHU, interval=1):
|
|
|
|
|
- click_count += 1
|
|
|
|
|
|
|
+ if self.appear(self.I_D_FAIL) or self.appear(self.I_FALSE):
|
|
|
|
|
+ return
|
|
|
|
|
+ if self.appear_then_click(self.I_EXIT_ENSURE):
|
|
|
continue
|
|
continue
|
|
|
- click_count = 0 # 计数
|
|
|
|
|
- while 1:
|
|
|
|
|
- self.screenshot()
|
|
|
|
|
- if click_count >= 4:
|
|
|
|
|
- break
|
|
|
|
|
- if self.appear(self.I_YINGJIE, interval=1):
|
|
|
|
|
- break
|
|
|
|
|
- if self.appear_then_click(self.I_YINYANGSHI, interval=1):
|
|
|
|
|
- click_count += 1
|
|
|
|
|
|
|
+ # 选式神界面退出或战斗内退出
|
|
|
|
|
+ if self.appear_then_click(self.I_DUEL_EXIT, interval=1) or self.appear_then_click(self.I_EXIT, interval=1):
|
|
|
continue
|
|
continue
|
|
|
- self.ui_get_current_page()
|
|
|
|
|
- self.ui_goto(page_main)
|
|
|
|
|
|
|
|
|
|
def check_honor(self) -> bool:
|
|
def check_honor(self) -> bool:
|
|
|
- """
|
|
|
|
|
- 检查荣誉是否满了
|
|
|
|
|
- :return:
|
|
|
|
|
- """
|
|
|
|
|
|
|
+ """检查荣誉是否满了"""
|
|
|
|
|
+ if not self.appear(self.I_DUEL_HONOR):
|
|
|
|
|
+ return False
|
|
|
|
|
+ roi_x = self.I_DUEL_HONOR.roi_front[0] + self.I_DUEL_HONOR.roi_front[2]
|
|
|
|
|
+ roi_y = self.I_DUEL_HONOR.roi_front[1]
|
|
|
|
|
+ roi_w = 110
|
|
|
|
|
+ roi_h = self.I_DUEL_HONOR.roi_front[3]
|
|
|
|
|
+ self.O_D_HONOR.roi = [roi_x, roi_y, roi_w, roi_h]
|
|
|
current, remain, total = self.O_D_HONOR.ocr(self.device.image)
|
|
current, remain, total = self.O_D_HONOR.ocr(self.device.image)
|
|
|
- if current == total and remain == 0:
|
|
|
|
|
- return True
|
|
|
|
|
- return False
|
|
|
|
|
|
|
+ return current == total and remain == 0
|
|
|
|
|
|
|
|
- def check_score(self) -> int or None:
|
|
|
|
|
|
|
+ def get_and_update_cur_score(self, skip_screenshot: bool = True) -> int:
|
|
|
"""
|
|
"""
|
|
|
- 检查是否达到目标分数
|
|
|
|
|
- :param target: 目标分数
|
|
|
|
|
- :return:
|
|
|
|
|
|
|
+ 获取并更新当前斗技分数, 要求处于斗技主界面, 同时更新名仕状态
|
|
|
|
|
+ :param skip_screenshot: 是否跳过截图
|
|
|
|
|
+ :return: 当前斗技分数
|
|
|
"""
|
|
"""
|
|
|
- while 1:
|
|
|
|
|
|
|
+ self.maybe_screenshot(skip_screenshot)
|
|
|
|
|
+ score = self.current_score
|
|
|
|
|
+ self.is_celeb = False
|
|
|
|
|
+ if self.appear(self.I_D_CELEB_STAR) or self.appear(self.I_D_CELEB_HONOR):
|
|
|
|
|
+ self.is_celeb = True
|
|
|
|
|
+ if self.battle_win_count - self.pre_battle_win_cnt == 1:
|
|
|
|
|
+ self.pre_battle_win_cnt = self.battle_win_count
|
|
|
|
|
+ score += 100
|
|
|
|
|
+ elif self.battle_lose_count - self.pre_battle_lose_cnt == 1:
|
|
|
|
|
+ self.pre_battle_lose_cnt = self.battle_lose_count
|
|
|
|
|
+ score -= 100
|
|
|
|
|
+ else:
|
|
|
|
|
+ score, remain, total = self.O_D_SCORE.ocr(self.device.image)
|
|
|
|
|
+ if score > 10000:
|
|
|
|
|
+ # 识别错误分数超过一万, 去掉最高位
|
|
|
|
|
+ logger.warning('Recognition error, score is too high')
|
|
|
|
|
+ score = int(str(score)[1:])
|
|
|
|
|
+ logger.info(f'battle score: {score}')
|
|
|
|
|
+ self.current_score = score
|
|
|
|
|
+ return self.current_score
|
|
|
|
|
+
|
|
|
|
|
+ def switch_soul(self):
|
|
|
|
|
+ """从式神录界面切换御魂"""
|
|
|
|
|
+ if self.conf.switch_soul.enable:
|
|
|
|
|
+ self.ui_get_current_page()
|
|
|
|
|
+ self.ui_goto(page_shikigami_records)
|
|
|
|
|
+ self.run_switch_soul(self.conf.switch_soul.switch_group_team)
|
|
|
|
|
+ if self.conf.switch_soul.enable_switch_by_name:
|
|
|
|
|
+ self.ui_get_current_page()
|
|
|
|
|
+ self.ui_goto(page_shikigami_records)
|
|
|
|
|
+ self.run_switch_soul_by_name(self.conf.switch_soul.group_name, self.conf.switch_soul.team_name)
|
|
|
|
|
+
|
|
|
|
|
+ def duel_main(self, screenshot=False) -> bool:
|
|
|
|
|
+ """判断是否在斗技主界面"""
|
|
|
|
|
+ if screenshot:
|
|
|
self.screenshot()
|
|
self.screenshot()
|
|
|
- if self.appear(self.I_D_CELEB_STAR) or self.appear(self.I_D_CELEB_HONOR):
|
|
|
|
|
- if self.battle_win_count - self.battle_win_copy == 1:
|
|
|
|
|
- self.battle_win_copy = self.battle_win_count
|
|
|
|
|
- self.current_score += 100
|
|
|
|
|
- elif self.battle_lose_count - self.battle_lose_copy == 1:
|
|
|
|
|
- self.battle_lose_copy = self.battle_lose_count
|
|
|
|
|
- self.current_score -= 100
|
|
|
|
|
- else:
|
|
|
|
|
- self.current_score = self.current_score
|
|
|
|
|
- else:
|
|
|
|
|
- self.current_score = self.O_D_SCORE.ocr(self.device.image)
|
|
|
|
|
- if self.current_score > 10000:
|
|
|
|
|
- # 识别错误分数超过一万, 去掉最高位
|
|
|
|
|
- logger.warning('Recognition error, score is too high')
|
|
|
|
|
- self.current_score = int(str(self.current_score)[1:])
|
|
|
|
|
- logger.info(f'battle score: {self.current_score}')
|
|
|
|
|
- return self.current_score
|
|
|
|
|
|
|
+ return self.appear(self.I_D_HELP) or self.appear(self.I_CHECK_DUEL) or \
|
|
|
|
|
+ self.appear(self.I_D_CELEB_STAR) or self.appear(self.I_D_CELEB_HONOR)
|
|
|
|
|
|
|
|
- def duel_one(self, current_score: int, enable: bool = False,
|
|
|
|
|
- mark_mode: GreenMarkType = GreenMarkType.GREEN_MAIN, ban_name: str = '') -> bool:
|
|
|
|
|
- """
|
|
|
|
|
- 进行一次斗技, 返回输赢结果
|
|
|
|
|
- :param mark_mode:
|
|
|
|
|
- :param enable:
|
|
|
|
|
- :param current_score: 当前分数, 不同的分数有不同的战斗界面
|
|
|
|
|
- :return:
|
|
|
|
|
- """
|
|
|
|
|
- logger.hr('Duel battle', 2)
|
|
|
|
|
- self.battle_count += 1
|
|
|
|
|
- # 是否名士
|
|
|
|
|
- celeb_status = False
|
|
|
|
|
|
|
+ def switch_all_soul(self):
|
|
|
|
|
+ """在斗技式神备选界面一键切换所有御魂"""
|
|
|
|
|
+ if not self.conf.duel_config.switch_all_soul:
|
|
|
|
|
+ return
|
|
|
|
|
+ click_count = 0 # 计数
|
|
|
while 1:
|
|
while 1:
|
|
|
self.screenshot()
|
|
self.screenshot()
|
|
|
- # 如果对方直接秒退,那自己就是赢的
|
|
|
|
|
- if self.appear(self.I_D_VICTORY):
|
|
|
|
|
- self.ui_click_until_disappear(self.I_D_VICTORY)
|
|
|
|
|
- self.battle_win_copy = self.battle_win_count
|
|
|
|
|
- self.battle_win_count += 1
|
|
|
|
|
- return
|
|
|
|
|
- if self.appear(self.I_D_AUTO_ENTRY) or self.appear(self.I_D_PREPARE):
|
|
|
|
|
|
|
+ if click_count >= 3:
|
|
|
break
|
|
break
|
|
|
- # 名士以上禁用
|
|
|
|
|
- if self.appear_then_click(self.I_BAN, interval=1):
|
|
|
|
|
- celeb_status = True
|
|
|
|
|
|
|
+ if self.appear_then_click(self.I_D_TEAM, interval=1):
|
|
|
continue
|
|
continue
|
|
|
- # 战斗按钮
|
|
|
|
|
- if self.appear_then_click(self.I_D_BATTLE, interval=1) or self.appear_then_click(self.I_D_BATTLE2, interval=1):
|
|
|
|
|
|
|
+ if self.appear_then_click(self.I_UI_CONFIRM, interval=0.6):
|
|
|
continue
|
|
continue
|
|
|
- # 战斗带保护的按钮
|
|
|
|
|
- if self.appear_then_click(self.I_D_BATTLE_PROTECT, interval=1.6):
|
|
|
|
|
|
|
+ if self.appear_then_click(self.I_D_TEAM_SWTICH, interval=1):
|
|
|
|
|
+ click_count += 1
|
|
|
continue
|
|
continue
|
|
|
- # 斗技模式(普通)
|
|
|
|
|
- # if self.appear_then_click(self.I_BATTLE_TYPE_COMMON, interval=1):
|
|
|
|
|
- # continue
|
|
|
|
|
- # 练习
|
|
|
|
|
- # if self.appear_then_click(self.I_BATTLE_WITH_TRAIN, interval=1) or self.appear_then_click(self.I_BATTLE_WITH_TRAIN2, interval=1):
|
|
|
|
|
- # continue
|
|
|
|
|
-
|
|
|
|
|
- # 点击斗技 开始匹配对手
|
|
|
|
|
- logger.hr('Duel start match')
|
|
|
|
|
- while 1:
|
|
|
|
|
- self.screenshot()
|
|
|
|
|
- # 出现自动上阵
|
|
|
|
|
- if self.appear(self.I_D_AUTO_ENTRY):
|
|
|
|
|
- ban_check_success = True
|
|
|
|
|
- if celeb_status:
|
|
|
|
|
- # 检查禁选式神
|
|
|
|
|
- name_timer = Timer(5)
|
|
|
|
|
- name_timer.start()
|
|
|
|
|
- ban_check_success = False
|
|
|
|
|
- while 1:
|
|
|
|
|
- if name_timer.reached():
|
|
|
|
|
- break
|
|
|
|
|
- self.click(self.C_DUEL_CLICK_5)
|
|
|
|
|
- sleep(0.5)
|
|
|
|
|
- self.screenshot()
|
|
|
|
|
- # 如果对方直接秒退,那自己就是赢的
|
|
|
|
|
- if self.appear(self.I_D_VICTORY):
|
|
|
|
|
- self.ui_click_until_disappear(self.I_D_VICTORY)
|
|
|
|
|
- self.battle_win_copy = self.battle_win_count
|
|
|
|
|
- self.battle_win_count += 1
|
|
|
|
|
- return
|
|
|
|
|
- ocr_ban_name = self.O_D_BAN_NAME.ocr(self.device.image)
|
|
|
|
|
- if ocr_ban_name == '':
|
|
|
|
|
- continue
|
|
|
|
|
- if any(char in ocr_ban_name for char in ban_name):
|
|
|
|
|
- ban_check_success = True
|
|
|
|
|
- break
|
|
|
|
|
- else:
|
|
|
|
|
- break
|
|
|
|
|
|
|
+ logger.info('Souls Switch is complete')
|
|
|
|
|
+ self.ui_click(self.I_UI_BACK_YELLOW, self.I_D_TEAM)
|
|
|
|
|
|
|
|
- # 处理检查结果
|
|
|
|
|
- if not ban_check_success:
|
|
|
|
|
- self.duel_exit_battle()
|
|
|
|
|
- if self.appear(self.I_D_FAIL):
|
|
|
|
|
- # 输了
|
|
|
|
|
- self.ui_click_until_disappear(self.I_D_FAIL)
|
|
|
|
|
- self.battle_lose_copy = self.battle_lose_count
|
|
|
|
|
- self.battle_lose_count += 1
|
|
|
|
|
- return
|
|
|
|
|
|
|
+ def check_and_get_reward(self):
|
|
|
|
|
+ """检查并收获奖励"""
|
|
|
|
|
+ if self.appear(self.I_REWARD, interval=0.6) or self.appear(self.I_UI_REWARD, interval=0.6):
|
|
|
|
|
+ self.click(random_click(ltrb=(True, True, False, True)))
|
|
|
|
|
+ logger.info('get reward')
|
|
|
|
|
|
|
|
- # 等待自动上阵消失
|
|
|
|
|
- self.ui_click_until_disappear(self.I_D_AUTO_ENTRY)
|
|
|
|
|
- self.device.stuck_record_clear()
|
|
|
|
|
- self.device.stuck_record_add('BATTLE_STATUS_S')
|
|
|
|
|
- self.wait_until_disappear(self.I_D_WORD_BATTLE)
|
|
|
|
|
- break
|
|
|
|
|
- if self.appear(self.I_D_PREPARE):
|
|
|
|
|
- # 低段位有的准备
|
|
|
|
|
- self.ui_click_until_disappear(self.I_D_PREPARE)
|
|
|
|
|
- logger.info('Duel prepare')
|
|
|
|
|
- break
|
|
|
|
|
- # 如果对方直接秒退,那自己就是赢的
|
|
|
|
|
- if self.appear(self.I_D_VICTORY):
|
|
|
|
|
- self.ui_click_until_disappear(self.I_D_VICTORY)
|
|
|
|
|
- self.battle_win_copy = self.battle_win_count
|
|
|
|
|
- self.battle_win_count += 1
|
|
|
|
|
- return
|
|
|
|
|
- timer = Timer(15)
|
|
|
|
|
- timer.start()
|
|
|
|
|
- while 1:
|
|
|
|
|
- if timer.reached():
|
|
|
|
|
- break
|
|
|
|
|
- # 此处必须是真正战斗界面,否则低段位进去就是战斗界面会直接跳过该循环
|
|
|
|
|
- if self.is_in_real_battle():
|
|
|
|
|
- break
|
|
|
|
|
- while 1:
|
|
|
|
|
- self.screenshot()
|
|
|
|
|
- if self.ocr_appear(self.O_D_AUTO, interval=0.4):
|
|
|
|
|
- break
|
|
|
|
|
- if self.ocr_appear_click(self.O_D_HAND, interval=1):
|
|
|
|
|
- continue
|
|
|
|
|
- # 如果对方直接秒退,那自己就是赢的
|
|
|
|
|
- if self.appear(self.I_D_VICTORY):
|
|
|
|
|
- self.ui_click_until_disappear(self.I_D_VICTORY)
|
|
|
|
|
- self.battle_win_copy = self.battle_win_count
|
|
|
|
|
- self.battle_win_count += 1
|
|
|
|
|
- return
|
|
|
|
|
- if self.appear(self.I_D_FAIL):
|
|
|
|
|
- # 输了
|
|
|
|
|
- self.ui_click_until_disappear(self.I_D_FAIL)
|
|
|
|
|
- self.battle_lose_copy = self.battle_lose_count
|
|
|
|
|
- self.battle_lose_count += 1
|
|
|
|
|
- return
|
|
|
|
|
- # 绿标
|
|
|
|
|
- self.green_mark(enable, mark_mode)
|
|
|
|
|
- # 等待结果
|
|
|
|
|
- logger.info('Duel wait result')
|
|
|
|
|
- self.device.stuck_record_add('BATTLE_STATUS_S')
|
|
|
|
|
- self.device.click_record_clear()
|
|
|
|
|
- battle_win = True
|
|
|
|
|
- swipe_count = 0
|
|
|
|
|
- swipe_timer = Timer(270)
|
|
|
|
|
- swipe_timer.start()
|
|
|
|
|
- while 1:
|
|
|
|
|
- self.screenshot()
|
|
|
|
|
- # 收取奖励
|
|
|
|
|
- if self.ui_reward_appear_click(True):
|
|
|
|
|
- continue
|
|
|
|
|
- if self.appear_then_click(self.I_D_BATTLE_DATA, action=self.C_D_BATTLE_DATA, interval=0.6):
|
|
|
|
|
- continue
|
|
|
|
|
- if self.appear(self.I_FALSE):
|
|
|
|
|
- # 打输了
|
|
|
|
|
- self.ui_click_until_disappear(self.I_FALSE)
|
|
|
|
|
- battle_win = False
|
|
|
|
|
- break
|
|
|
|
|
- if self.appear(self.I_D_FAIL):
|
|
|
|
|
- # 输了
|
|
|
|
|
- self.ui_click_until_disappear(self.I_D_FAIL)
|
|
|
|
|
- battle_win = False
|
|
|
|
|
- break
|
|
|
|
|
- if self.appear(self.I_WIN):
|
|
|
|
|
- # 打赢了
|
|
|
|
|
- self.ui_click_until_disappear(self.I_WIN)
|
|
|
|
|
- battle_win = True
|
|
|
|
|
- break
|
|
|
|
|
- if self.appear(self.I_D_VICTORY):
|
|
|
|
|
- # 打赢了
|
|
|
|
|
- self.ui_click_until_disappear(self.I_D_VICTORY)
|
|
|
|
|
- battle_win = True
|
|
|
|
|
- break
|
|
|
|
|
|
|
+ def is_in_battle_prepare(self, skip_screenshot=True) -> bool:
|
|
|
|
|
+ """是否在战斗准备界面"""
|
|
|
|
|
+ self.maybe_screenshot(skip_screenshot)
|
|
|
|
|
+ return self.appear(self.I_D_PREPARE) or \
|
|
|
|
|
+ self.appear(self.I_D_AUTO_ENTRY) or \
|
|
|
|
|
+ self.appear(self.I_BAN) or \
|
|
|
|
|
+ self.appear(self.I_D_WORD_BATTLE) or \
|
|
|
|
|
+ self.appear(self.I_D_CHECK_BAN)
|
|
|
|
|
|
|
|
- if swipe_timer.reached():
|
|
|
|
|
- swipe_timer.reset()
|
|
|
|
|
- if swipe_count >= 2:
|
|
|
|
|
- # 记三次,十五分钟没有结束也没谁了
|
|
|
|
|
- logger.info('Duel battle timeout')
|
|
|
|
|
- battle_win = False
|
|
|
|
|
- break
|
|
|
|
|
- swipe_count += 1
|
|
|
|
|
- logger.warning('Duel battle stuck, swipe')
|
|
|
|
|
- self.device.stuck_record_clear()
|
|
|
|
|
- self.device.stuck_record_add('BATTLE_STATUS_S')
|
|
|
|
|
|
|
+ def is_battle_win(self) -> bool:
|
|
|
|
|
+ return self.appear(self.I_WIN) or self.appear(self.I_D_VICTORY)
|
|
|
|
|
|
|
|
- if battle_win:
|
|
|
|
|
- self.battle_win_copy = self.battle_win_count
|
|
|
|
|
- self.battle_win_count += 1
|
|
|
|
|
- else:
|
|
|
|
|
- self.battle_lose_copy = self.battle_lose_count
|
|
|
|
|
- self.battle_lose_count += 1
|
|
|
|
|
|
|
+ def is_battle_lose(self) -> bool:
|
|
|
|
|
+ return self.appear(self.I_FALSE) or self.appear(self.I_D_FAIL)
|
|
|
|
|
|
|
|
- task_run_time = datetime.now() - self.start_time
|
|
|
|
|
- # 格式化时间,只保留整数部分的秒
|
|
|
|
|
- task_run_time_seconds = timedelta(seconds=int(task_run_time.total_seconds()))
|
|
|
|
|
|
|
+ def is_battle_end(self) -> bool:
|
|
|
|
|
+ return self.is_battle_win() or self.is_battle_lose() or \
|
|
|
|
|
+ self.appear(self.I_REWARD) or self.appear(self.I_UI_REWARD)
|
|
|
|
|
|
|
|
- logger.info(f'battle result: {battle_win}')
|
|
|
|
|
- logger.info(f'battle count: {self.battle_count} | win: {self.battle_win_count} failure: {self.battle_lose_count}')
|
|
|
|
|
- logger.info(f'battle time: {task_run_time_seconds} / {self.limit_time}')
|
|
|
|
|
- return battle_win
|
|
|
|
|
|
|
+ def reset_device(self, status: str):
|
|
|
|
|
+ self.device.click_record_clear()
|
|
|
|
|
+ self.device.stuck_record_clear()
|
|
|
|
|
+ self.device.stuck_record_add(status)
|
|
|
|
|
|
|
|
- def duel_exit_battle(self):
|
|
|
|
|
- while 1:
|
|
|
|
|
- self.screenshot()
|
|
|
|
|
- if self.appear(self.I_D_FAIL) or self.appear(self.I_FALSE):
|
|
|
|
|
- return
|
|
|
|
|
- if self.appear_then_click(self.I_EXIT_ENSURE):
|
|
|
|
|
- continue
|
|
|
|
|
- if self.appear_then_click(self.I_DUEL_EXIT, interval=1):
|
|
|
|
|
- continue
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if __name__ == '__main__':
|
|
|
from module.config.config import Config
|
|
from module.config.config import Config
|
|
|
from module.device.device import Device
|
|
from module.device.device import Device
|
|
|
- c = Config('oas2')
|
|
|
|
|
|
|
+
|
|
|
|
|
+ c = Config('oas3')
|
|
|
d = Device(c)
|
|
d = Device(c)
|
|
|
t = ScriptTask(c, d)
|
|
t = ScriptTask(c, d)
|
|
|
|
|
|