Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Retry after fails #369 #382

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added assets/images/zh_CN/fight/fight_fail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 30 additions & 14 deletions tasks/power/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@

class Instance:
@staticmethod
def run(instance_type, instance_name, power_need, runs):
def run(instance_type, instance_name, power_need, runs, from_failure = False, runs_completed = 0):
if not Instance.validate_instance(instance_type, instance_name):
return False

log.hr(f"开始刷{instance_type} - {instance_name},总计{runs}次", 2)

if cfg.instance_team_enable and "饰品提取" not in instance_type:
Team.change_to(cfg.instance_team_number)

# 若是任务失败后的重新运行, 则改变运行逻辑
if from_failure:
log.hr(f"复活后重新进入副本{instance_type} - {instance_name},剩余{runs-runs_completed}次", 2)
else:
log.hr(f"开始刷{instance_type} - {instance_name},总计{runs}次", 2)
if cfg.instance_team_enable and "饰品提取" not in instance_type:
Team.change_to(cfg.instance_team_number)

if not Instance.prepare_instance(instance_type, instance_name):
return False
Expand All @@ -28,16 +31,25 @@ def run(instance_type, instance_name, power_need, runs):
return False

try:
for i in range(runs - 1):
Instance.wait_fight(i + 1)
Instance.start_instance_again(instance_type)
Instance.wait_fight(runs)
for i in range(runs_completed, runs):
fight_result = Instance.wait_fight(i + 1)

# 如果战斗失败则重新运行, 并记录成功运行次数
if not fight_result:
auto.click_element("./assets/images/zh_CN/fight/fight_fail.png", "image", 0.9, max_retries=10)
Instance.run(instance_type, instance_name, power_need, runs, from_failure = True, runs_completed = i)
break

if i < runs-1:
Instance.start_instance_again(instance_type)
except RuntimeError:
return False

Instance.complete_run(instance_type)

log.info("副本任务完成")

# 若是任务失败后的重新运行, 则不再重复这些逻辑
if not from_failure:
Instance.complete_run(instance_type)
log.info("副本任务完成")

return True

@staticmethod
Expand Down Expand Up @@ -226,6 +238,10 @@ def wait_fight(num, timeout=1800):
log.info("战斗完成")
log.info(f"第{num}次副本完成")
return True
elif auto.find_element("./assets/images/zh_CN/fight/fight_fail.png", "image", 0.9):
log.info("战斗失败")
log.info(f"重新开始第{num}次副本")
return False
elif cfg.auto_battle_detect_enable and auto.find_element("./assets/images/share/base/not_auto.png", "image", 0.9, crop=(0.0 / 1920, 903.0 / 1080, 144.0 / 1920, 120.0 / 1080)):
log.info("尝试开启自动战斗")
auto.press_key("v")
Expand Down
Loading