Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
ok-oldking committed Apr 28, 2024
1 parent 9aa559f commit 7a2717f
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 26 deletions.
1 change: 0 additions & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
<p>Github下载和源码地址:</p>
<p><a href="https://github.com/ok-oldking/ok_baijing">https://github.com/ok-oldking/ok_baijing</a></p>
""",
'click_screenshots_folder': "click_screenshots", # debug用 点击后截图文件夹
'screenshots_folder': "screenshots",
'gui_title': 'OK白荆漫巡', # Optional
'capture_window_title': r'^白荆回廊\[[0-9.]+\]$', # required when using windows capture
Expand Down
1 change: 1 addition & 0 deletions main_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@

config = config
config['debug'] = True
config['click_screenshots_folder'] = "click_screenshots" # debug用 点击后截图文件夹]
ok = OK(config)
ok.start()
47 changes: 30 additions & 17 deletions task/AoSkillManXunTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ class AoSkillManXunTask(ManXunTask):
def __init__(self):
super().__init__()
self.route = None
self.name = "自动漫巡凹技能"
self.description = """主界面开始, 凹指定角色指定技能, 达不到要求就自动跳过战斗结束
self.name = "循环漫巡凹技能"
self.description = """主界面开始, 凹指定角色指定技能, 刷不到指定技能就自动跳过战斗结束
"""
self.super_config = self.default_config
del self.super_config['无法直接胜利, 自动投降跳过']
del self.super_config['投降跳过战斗']
self.default_config = {'角色名': '岑缨', '路线': '空想王国', '循环次数': 5,
'目标技能': ['职业联动', '针对打击'], '目标技能个数': 2}
'目标技能': ['职业联动', '针对打击', '奉献'], '目标技能个数': 3}
self.default_config = {**self.default_config, **self.super_config}
self.config_description["目标技能"] = "部分匹配, 最好不要加标点符号"
self.pause_combat_message = "成功刷到目标技能, 暂停"

@override
def run(self):
Expand Down Expand Up @@ -47,8 +49,8 @@ def loop_manxun(self):
self.screenshot("必须从主界面或漫巡界面开始")
return False
if is_main or self.route:
self.enter_manxun()
self.start_manxun()
if not self.enter_manxun():
self.start_manxun()
while True:
try:
self.loop()
Expand Down Expand Up @@ -92,8 +94,10 @@ def check_skills(self):
skills[skill] = skills.get(skill, 0) + 1
if current_count != self.info.get('已获得目标技能个数', 0):
self.info['已获得目标技能个数'] = current_count
self.info['已获取的目标技能'] = current_skills
self.info['已获取的目标技能'] = skills
self.notification(f"已经获取到 {current_count}个目标技能 {skills}")
if current_count >= self.config['目标技能个数']:
self.pause()

def select_char(self):
char_name = self.wait_until(
Expand Down Expand Up @@ -129,18 +133,27 @@ def enter_manxun(self):
self.click_box(self.route)
self.wait_click_box(
lambda: self.ocr(self.right_button_zone, match='前往回廊漫巡'))
start_manxun = self.wait_click_box(
lambda: self.ocr(self.star_combat_zone, match='开始新漫巡'))
self.sleep(1)
boxes = self.ocr(self.box_of_screen(0.2, 0.5, 0.3, 0.3, "精神改善剂检测区域"), re.compile(r'^可回复精神力'))
if len(boxes) == 1:
self.click_box(boxes[0], relative_y=-4)
continue_manxun = self.ocr(self.dialog_zone, match='继续漫巡')
if continue_manxun:
self.click_box(continue_manxun)
self.wait_click_box(
lambda: self.ocr(self.right_button_zone, match='确认使用'))
self.sleep(0.5)
self.click_relative(0.95, 0.5)
self.sleep(3)
self.click_box(start_manxun)
lambda: self.ocr(self.dialog_zone, match='确认'))
return True
else:
start_manxun = self.wait_click_box(
lambda: self.ocr(self.star_combat_zone, '开始新漫巡'))
self.sleep(1)
boxes = self.ocr(self.box_of_screen(0.2, 0.5, 0.3, 0.3, "精神改善剂检测区域"), re.compile(r'^可回复精神力'))
if len(boxes) == 1:
self.click_box(boxes[0], relative_y=-4)
self.wait_click_box(
lambda: self.ocr(self.right_button_zone, match='确认使用'))
self.sleep(0.5)
self.click_relative(0.95, 0.5)
self.sleep(3)
self.click_box(start_manxun)
return False

@property
def right_button_zone(self):
Expand Down
2 changes: 1 addition & 1 deletion task/BJTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def __init__(self):

@property
def star_combat_zone(self):
return self.box_of_screen(0.8, 0.8, 0.2, 0.2)
return self.box_of_screen(0.8, 0.8, 0.2, 0.2, name="star_combat_zone")

@property
def main_menu_zone(self):
Expand Down
65 changes: 58 additions & 7 deletions task/ManXunTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,31 @@ class ManXunTask(BJTask):

def __init__(self):
super().__init__()
self.name = "自动漫巡任务"
self.name = "执行一次自动漫巡"
self.description = """自动漫巡, 必须进入漫巡后开始, 并开启追踪
"""
self.click_no_brainer = ["直接胜利", "属性提升", "前进", "通过", "继续", "收下", "跳过", "开始强化",
re.compile(r"^解锁技能:"), re.compile(r"^精神负荷降低"), "漫巡推进"]
self.default_config = {
"无法直接胜利, 自动投降跳过": False,
"投降跳过战斗": False,
"唤醒属性优先级": ["终端", "专精", "体质", "攻击", "防御"],
"深度等级最多提升到": 12,
"低深度选项优先级": ["风险区", "烙痕唤醒", "记忆强化", "高维同调", "研习区", "休整区"],
"高深度选项优先级": ["风险区", "烙痕唤醒", "高维同调", "记忆强化", "研习区", "休整区"],
"高低深度分界": 6,
"烙痕唤醒黑名单": ["幕影重重", "谎言之下", "馆中遗影"],
"跳过战斗": ["鱼叉将军-日光浅滩E"],
}
self.config_description = {
"投降跳过战斗": "如果无法直接胜利, 自动投降跳过",
"深度等级最多提升到": "海底图建议12",
"高低深度分界": "比如可以配置低深度优先记忆强化, 高深度优先高维同调",
"烙痕唤醒黑名单": "可以使用烙痕名称或者核心技能名称, 部分匹配即可",
"跳过战斗": "不打的战斗, 比如鱼叉将军",
}
self.destination = None
self.stats_up_re = re.compile(r"([\u4e00-\u9fff]+)\+(\d+)(?:~(\d+))?")
self.pause_combat_message = "未开启自动战斗, 无法继续漫巡, 暂停中, 请手动完成战斗或开启自动跳过后继续"

def end(self, message, result=False):
self.log_info(f"执行结束:{message}")
Expand Down Expand Up @@ -117,8 +126,9 @@ def loop(self, choice=-1):
return self.do_handle_dialog(choice)
self.wait_until(lambda: self.do_handle_dialog(choice), wait_until_before_delay=1.5)

def do_handle_dialog(self, choice, retry=0):
boxes = self.ocr(self.dialog_zone)
def do_handle_dialog(self, choice, retry=0, boxes=None):
if boxes is None:
boxes = self.ocr(self.dialog_zone)
if self.find_depth(boxes) > 0:
self.log_info(f"没有弹窗, 进行下一步")
return True
Expand Down Expand Up @@ -166,8 +176,7 @@ def do_handle_dialog(self, choice, retry=0):
self.click_box(stat_combat)
self.auto_skip_combat()
else:
message = "未开启自动战斗, 无法继续漫巡, 暂停中, 请手动完成战斗或开启自动跳过后继续"
self.log_info(message, True)
self.log_info(self.pause_combat_message, True)
self.pause()
elif no_brain_box := self.click_box_if_name_match(boxes, self.click_no_brainer):
self.log_info(f"点击固定对话框: {no_brain_box.name}")
Expand All @@ -186,7 +195,7 @@ def confirm_generate(self):
return False

def if_skip_battle(self):
return self.config.get("无法直接胜利, 自动投降跳过")
return self.config.get("投降跳过战斗")

def find_stats_up(self, boxes):
for box in boxes:
Expand Down Expand Up @@ -254,6 +263,9 @@ def click_choice(self, index=-1):
'高低深度分界'] else \
self.config[
'高深度选项优先级']
clicked, c, i = self.try_handle_laohen_choices(choices, index, priority)
if clicked:
return c, c[i]
if choices[index].name == "深度等级提升":
depth = self.find_depth()
self.log_info(f"提升深度, {depth} 目前是第{abs(index)}个选项, 共有{len(choices)}选项")
Expand All @@ -270,6 +282,38 @@ def click_choice(self, index=-1):
f"点击选项:{choices[index]}, 使用优先级 {priority}, index {index}, {choices}")
return choices, choices[index]

def try_handle_laohen_choices(self, choices, index, priority):
laohen_count = 0
laohen_priority = find_index("烙痕唤醒", priority)
last_laohen_index = index
for i in range(index, -len(choices) - 1, -1):
if choices[i].name == "烙痕唤醒":
laohen_count += 1
last_laohen_index = i
elif choice_index := find_index(choices[i].name, priority):
if choice_index <= laohen_priority: # 有比烙痕唤醒高优先级的, 不点击
return False, choices, index
if laohen_count < 2:
return False, choices, index
black_list = self.config["烙痕唤醒黑名单"] + [re.compile("核心技能已解锁满级")]
for i in range(index, last_laohen_index - 1, -1):
if i == last_laohen_index:
self.click_box(choices[i])
self.log_debug("最后一个烙痕唤醒选项, 点击")
return True, choices, i
if choices[i].name == "烙痕唤醒":
self.click_box(choices[i])
self.wait_until(lambda: self.ocr(self.dialog_zone, match="烙痕唤醒"))
boxes = self.ocr(match=black_list)
if boxes:
self.log_debug(f"烙痕唤醒在黑名单, 跳过 {boxes}")
self.click_relative(0.5, 0.1)
self.sleep(3)
continue
else:
self.log_debug("烙痕不在黑名单, 点击")
return True, choices, i

def do_find_choices(self):
boxes = self.ocr(self.choice_zone)
choices = find_boxes_by_name(boxes, re.compile(r"^通往"))
Expand Down Expand Up @@ -406,6 +450,13 @@ def find_priority_string(input_list, priority_list, start_index=-1):
return start_index


def find_index(element, lst):
try:
return lst.index(element)
except ValueError:
return -1


gray_percent_per_line = 0.03660270078 * 100
yellow_percent_per_line = 0.02821869488 * 100

Expand Down

0 comments on commit 7a2717f

Please sign in to comment.