Skip to content

Commit

Permalink
Merge pull request #95 from sanmusen214/dev
Browse files Browse the repository at this point in the history
Feat: Craft and one-click update BAAH
  • Loading branch information
sanmusen214 authored Aug 2, 2024
2 parents a4e42c1 + 983c3ca commit 42d5612
Show file tree
Hide file tree
Showing 24 changed files with 383 additions and 36 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
tools/
test.spec
jsoneditor.spec
BAAH_UPDATE.spec
BAAH.spec
compact_log.txt
/*.png
Expand All @@ -10,6 +11,8 @@ compact_log.txt
/BAAH.exe
/BAAH_GUI.exe
/platform-tools-latest.zip
/DATA/update/
/BAAH*_update.zip
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
3 changes: 2 additions & 1 deletion BAAH.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ def BAAH_start_emulator():
try:
# 以列表形式传命令行参数
logging.info({"zh_CN": "启动模拟器", "en_US": "Starting the emulator"})
emulator_process = subprocess_run(config.userconfigdict['TARGET_EMULATOR_PATH'].split(" "), isasync=True)
# 不能用shell,否则得到的是shell的pid
emulator_process = subprocess_run(config.userconfigdict['TARGET_EMULATOR_PATH'], isasync=True)
logging.info({"zh_CN": "模拟器pid: " + str(emulator_process.pid),
"en_US": "The emulator pid: " + str(emulator_process.pid)})
time.sleep(5)
Expand Down
5 changes: 4 additions & 1 deletion BAAH_CONFIGS/example.json
Original file line number Diff line number Diff line change
Expand Up @@ -255,5 +255,8 @@
"POST_COMMAND": "",
"SHOP_NORMAL_SWITCH": true,
"SHOP_CONTEST_SWITCH": true,
"USER_DEF_TASKS": ""
"USER_DEF_TASKS": "",
"PUSH_NORMAL_USE_SIMPLE": false,
"PUSH_HARD_USE_SIMPLE": false,
"CRAFT_TIMES": 1
}
Binary file added DATA/assets/kayoko.ico
Binary file not shown.
5 changes: 5 additions & 0 deletions DATA/i18n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"push_main_story":"Explore Eposide",
"task_assault": "Assault",
"task_user_def_task": "User Defined Task",
"task_craft":"Craft",

"setting_emulator": "Emulator Configuration",
"setting_server": "Server Configuration",
Expand All @@ -47,6 +48,7 @@
"button_save_and_run_gui":"Save and execute (GUI, experimental)",
"button_save_and_run_terminal":"Save and execute (Terminal)",
"button_check_version": "Check for Updates and Download(Make sure BAAH is not running)",
"button_update_advance":"One Click to update to the latest version (experimental)",
"button_select_all": "Select All",
"button_select_none": "Deselect All",
"button_enable": "Enable",
Expand Down Expand Up @@ -132,6 +134,9 @@
"config_buy_ap_add_times":"Number of times to buy AP",
"config_pre_command":"Command before task start, leave blank to ignore",
"config_post_command":"Command after task end, leave blank to ignore",
"config_use_simple_explore":"Use simple explore",
"config_craft_desc":"Currently, the craft task only supports one node and does not support the priority of specified items. After the Chinese server implements one-click manufacturing, it will be supported through one-click manufacturing",
"config_craft_max_times":"Maximum times of craft",

"config_server_jp": "Japanese Server",
"config_server_cn": "Chinese Official Server",
Expand Down
5 changes: 5 additions & 0 deletions DATA/i18n/jp_JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"push_main_story": "メインストーリーの進行",
"task_assault": "総力戦",
"task_user_def_task": "ユーザー定義タスク",
"task_craft":"クラフト",

"setting_emulator": "エミュレータ設定",
"setting_server": "サーバー設定",
Expand All @@ -47,6 +48,7 @@
"button_save_and_run_gui": "保存して実行(GUI、実験的)",
"button_save_and_run_terminal": "保存して実行(ターミナル)",
"button_check_version": "更新を確認してダウンロードする(BAAHが実行されていないことを確認してください)",
"button_update_advance":"最新バージョンに一括更新(実験的)",
"button_select_all": "すべて選択",
"button_select_none": "選択解除",
"button_enable": "有効にする",
Expand Down Expand Up @@ -132,6 +134,9 @@
"config_buy_ap_add_times":"APを購入する回数",
"config_pre_command":"タスク開始前に実行するコマンド",
"config_post_command":"タスク終了後に実行するコマンド",
"config_use_simple_explore":"簡易攻略を使用する",
"config_craft_desc":"現在、クラフトタスクは1つのノードのみをサポートし、指定されたアイテムの優先順位をサポートしていません。国内サーバーがワンクリック製造を実装した後、ワンクリック製造を使用してサポートする予定です",
"config_craft_max_times":"最大製造回数",

"config_server_jp": "日本サーバー",
"config_server_cn": "中国公式サーバー",
Expand Down
5 changes: 5 additions & 0 deletions DATA/i18n/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"push_main_story":"推主线剧情",
"task_assault":"总力战",
"task_user_def_task": "自定义任务",
"task_craft":"制造",

"setting_emulator":"模拟器配置",
"setting_server":"服务器配置",
Expand All @@ -47,6 +48,7 @@
"button_save_and_run_gui":"保存并执行(GUI,实验性功能)",
"button_save_and_run_terminal":"保存并执行(终端)",
"button_check_version":"检查更新并下载(确保BAAH不在运行),下载完成后请关闭BAAH手动解压更新补丁",
"button_update_advance":"一键更新到最新版本(实验性功能)",
"button_select_all":"全选",
"button_select_none":"全不选",
"button_enable":"启用",
Expand Down Expand Up @@ -132,6 +134,9 @@
"config_buy_ap_add_times":"购买体力组数",
"config_pre_command":"任务开始前执行命令, 留空忽略",
"config_post_command":"任务结束后执行命令, 留空忽略",
"config_use_simple_explore":"使用简易攻略",
"config_craft_desc":"制造任务目前只能一个节点,且不支持指定物品的优先级,等国服实装一键制造后会通过一键制造来支持",
"config_craft_max_times":"尝试制造次数",


"config_server_jp":"日服",
Expand Down
6 changes: 6 additions & 0 deletions gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
from gui.components.run_baah_in_gui import run_baah_task
from gui.pages.Setting_BAAH import set_BAAH
from gui.pages.Setting_Craft import set_craft
from gui.pages.Setting_cafe import set_cafe
from gui.pages.Setting_emulator import set_emulator
from gui.pages.Setting_event import set_event
Expand Down Expand Up @@ -43,6 +44,7 @@ def show_GUI(load_jsonname, config, shared_softwareconfig):
"咖啡馆只摸头":config.get_text("task_cafe_deprecated"), # 为了兼容以前的配置里的咖啡馆只摸头,这里只改显示名
"课程表":config.get_text("task_timetable"),
"社团":config.get_text("task_club"),
"制造":config.get_text("task_craft"),
"商店":config.get_text("task_shop"),
"购买AP":config.get_text("task_buy_ap"),
"悬赏通缉":config.get_text("task_wanted"),
Expand Down Expand Up @@ -77,6 +79,7 @@ def show_GUI(load_jsonname, config, shared_softwareconfig):
# ui.link(config.get_text("setting_next_config"), '#NEXT_CONFIG')
ui.link(config.get_text("task_cafe"), '#CAFE')
ui.link(config.get_text("task_timetable"), '#TIME_TABLE')
ui.link(config.get_text("task_craft"), '#CRAFT')
ui.link(config.get_text("task_shop"), '#SHOP_NORMAL')
ui.link(config.get_text("task_buy_ap"), '#BUY_AP')
ui.link(config.get_text("task_wanted"), '#WANTED')
Expand Down Expand Up @@ -114,6 +117,9 @@ def show_GUI(load_jsonname, config, shared_softwareconfig):

# 课程表
set_timetable(config)

# 制造
set_craft(config)

# 商店
set_shop(config)
Expand Down
13 changes: 12 additions & 1 deletion gui/pages/Setting_BAAH.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from nicegui import ui
import subprocess
from nicegui import ui, app
from gui.components.check_update import get_newest_version

def set_BAAH(config, shared_softwareconfig):
Expand All @@ -22,8 +23,18 @@ def select_language(value):

ui.label(config.get_text("BAAH_get_version"))

# 下载更新包
ui.button(config.get_text("button_check_version"), on_click=lambda e, c=config:get_newest_version(c))

# 一键更新,唤起更新程序,结束gui进程
def update_advance():
try:
subprocess.Popen(["BAAH_UPDATE.exe"], creationflags=subprocess.CREATE_NEW_CONSOLE, close_fds=True)
app.shutdown()
except Exception as e:
ui.notify(f"Failed to start BAAH_UPDATE.exe: {e}", type="warning")
ui.button(config.get_text("button_update_advance"), on_click=update_advance)

web_url = {
"github": "https://github.com/sanmusen214/BAAH",
"bilibili":"https://space.bilibili.com/7331920"
Expand Down
17 changes: 17 additions & 0 deletions gui/pages/Setting_Craft.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from nicegui import ui

def set_craft(config):
with ui.row():
ui.link_target("CRAFT")
ui.label(config.get_text("task_craft")).style('font-size: x-large')


ui.label(config.get_text("config_craft_desc"))

ui.number(config.get_text("config_craft_max_times"),
step=1,
precision=0,
min=1,
max=3
).bind_value(config.userconfigdict, 'CRAFT_TIMES', forward=lambda v: int(v), backward=lambda v:int(v)).style('width: 400px')

1 change: 1 addition & 0 deletions gui/pages/Setting_hard.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def set_hard(config):
ui.label(config.get_text("config_explore_attention"))

with ui.card():
ui.checkbox(config.get_text("config_use_simple_explore")).bind_value(config.userconfigdict, "PUSH_HARD_USE_SIMPLE")
ui.checkbox(config.get_text("config_rainbow_teams_desc")).bind_value(config.userconfigdict, "EXPLORE_RAINBOW_TEAMS")
ui.number(config.get_text("config_push_hard_desc"), min=1, precision=0, step=1).bind_value(config.userconfigdict, "PUSH_HARD_QUEST", forward=lambda x: int(x)).style("width: 300px")
ui.number(config.get_text("config_level"), min=1, precision=0, step=1).bind_value(config.userconfigdict, "PUSH_HARD_QUEST_LEVEL", forward=lambda x:int(x)).style("width: 300px")
Expand Down
1 change: 1 addition & 0 deletions gui/pages/Setting_normal.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def set_normal(config):
ui.label(config.get_text("config_explore_attention"))

with ui.card():
ui.checkbox(config.get_text("config_use_simple_explore")).bind_value(config.userconfigdict, "PUSH_NORMAL_USE_SIMPLE")
ui.checkbox(config.get_text("config_rainbow_teams_desc")).bind_value(config.userconfigdict, "EXPLORE_RAINBOW_TEAMS")
ui.number(config.get_text("config_push_normal_desc"), min=4, precision=0, step=1).bind_value(config.userconfigdict, "PUSH_NORMAL_QUEST", forward=lambda x: int(x)).style("width: 300px")
ui.number(config.get_text("config_level"), min=1, precision=0, step=1).bind_value(config.userconfigdict, "PUSH_NORMAL_QUEST_LEVEL", forward=lambda x:int(x)).style("width: 300px")
Expand Down
2 changes: 1 addition & 1 deletion gui/pages/Setting_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def set_server(config):
"CN_BILI":config.get_text("config_server_cn_b")},
value=config.userconfigdict['SERVER_TYPE'], on_change=lambda a:set_server_info(a.value)).props('inline')

fanhexie = ui.checkbox("如果游戏开了反和谐请勾选此项").bind_value(config.userconfigdict, "FANHEXIE").bind_visibility_from(config.userconfigdict, "SERVER_TYPE", lambda x: x in ["CN", "CN_BILI"])
fanhexie = ui.checkbox('如果游戏开了反和谐请勾选此项(手机显示“momotalk”勾选,手机显示“桃信”不要勾)').bind_value(config.userconfigdict, "FANHEXIE").bind_visibility_from(config.userconfigdict, "SERVER_TYPE", lambda x: x in ["CN", "CN_BILI"])

def set_server_info(servername):
config.userconfigdict['SERVER_TYPE'] = servername
Expand Down
16 changes: 16 additions & 0 deletions modules/AllTask/InCraft/InCraft.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ def dealing_with_craft(self):
CN: "点击制造失败",
EN: "Failed to click craft button"
}))
# 没制造材料,跳过之后的制造任务
self.status=Task.STATUS_SKIP
return
# 点击开放按钮
click(self.BUTTON_CRAFT)
Expand Down Expand Up @@ -114,6 +116,7 @@ def on_run(self) -> None:
# 获取当前制造状态
status_list = self.getNowCraftStatus()
logging.info(status_list)
now_craft_number = 0
for ind, item in enumerate(status_list):
# 处理每一个位置
if item == self.STATUS_CRAFT_DOING:
Expand All @@ -134,6 +137,19 @@ def on_run(self) -> None:
lambda: not Page.is_page(PageName.PAGE_CRAFT)
)
self.dealing_with_craft()
if self.status == Task.STATUS_SKIP:
logging.warn(istr({
CN: "制造材料不足,跳过之后的制造任务",
EN: "Insufficient crafting materials, skip subsequent crafting tasks"
}))
return
now_craft_number += 1
if now_craft_number >= config.userconfigdict["CRAFT_TIMES"]:
logging.info(istr({
CN: f"制造次数已达上限 {config.userconfigdict['CRAFT_TIMES']}",
EN: f"The number of crafting has reached the upper limit {config.userconfigdict['CRAFT_TIMES']}"
}))
return



Expand Down
4 changes: 2 additions & 2 deletions modules/AllTask/InEvent/InEvent.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ def on_run(self) -> None:
logging.info({"zh_CN": "成功进入Event页面", "en_US": "Successfully entered the Event page"})
today = time.localtime().tm_mday

# 检测并跳过剧情
if config.userconfigdict["AUTO_EVENT_STORY_PUSH"]:
# 检测并跳过剧情,如果已经进入过活动一次了,就不用再跳过剧情了
if config.userconfigdict["AUTO_EVENT_STORY_PUSH"] and not config.sessiondict["HAS_ENTER_EVENT"]:
EventStory().run()
# 推图任务,如果已经进入过活动一次了,就不用再推图了
if config.userconfigdict["AUTO_PUSH_EVENT_QUEST"] and not config.sessiondict["HAS_ENTER_EVENT"]:
Expand Down
21 changes: 13 additions & 8 deletions modules/AllTask/InQuest/PushQuest.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ def on_run(self) -> None:
# 此时应该看到扫荡弹窗
# 判断是否有简易攻略tab

has_easy_tab = quest_has_easy_tab()
# 向右翻self.level_ind次
logging.info({"zh_CN": "尝试翻到关卡 {}".format(self.level_ind + 1),
"en_US": "Try flipping to level {}".format(self.level_ind + 1)})
Expand All @@ -92,6 +91,8 @@ def on_run(self) -> None:
if match_pixel(Page.MAGICPOINT, Page.COLOR_WHITE):
logging.info({"zh_CN": "关卡弹窗消失,结束此任务","en_US": "Level popup disappears, end this task"})
return
# 此时判断是否有简易攻略tab
has_easy_tab = quest_has_easy_tab()
# 当前关卡就是这次需要推图的关卡
# 国服弹窗往右偏移了50
offsetx = 0
Expand Down Expand Up @@ -144,21 +145,25 @@ def on_run(self) -> None:
# ===========正式开始推图===================
# 看到弹窗,ocr是否有S
ocr_s = ocr_area((327 + offsetx, 257 + offsety), (370 + offsetx, 288 + offsety))
# 如果有简易攻略
# 如果有简易攻略tab,有简易攻略tab存在,这个图肯定默认是格子图
if has_easy_tab:
if self.is_normal:
logging.info({"zh_CN": "使用简易攻略", "en_US": "Easy to use guide"})
if (self.is_normal and config.userconfigdict["PUSH_NORMAL_USE_SIMPLE"]) or (not self.is_normal and config.userconfigdict["PUSH_HARD_USE_SIMPLE"]):
logging.info({"zh_CN": "使用简易攻略", "en_US": "Use simple explore"})
click(easy_tab_pos_R)
click(easy_tab_pos_R)
ocr_s = "easy"
# 简易攻略的话,把ocr_s设为_,让后面不要走格子(no "S")
ocr_s = ["_", 1.0]
else:
logging.info({"zh_CN": "困难图,走格子拿钻石",
"en_US": "Difficulty diagram, walk the grid to get the diamond"})
logging.info({"zh_CN": "不使用简易攻略",
"en_US": "Do not use simple explore"})
click(center_tab_pos_L)
click(center_tab_pos_L)
# 切换到集中指挥tab后,才会出现s标签,没有必要再次识别
ocr_s = ["S", 1.0]


walk_grid = None
logging.info(ocr_s[0].upper())
logging.info("OCR: "+ocr_s[0].upper())
if "S" not in ocr_s[0].upper():
logging.info({"zh_CN": "未识别到S等级,判断为普通战斗",
"en_US": "S grade not recognized, judged as normal battle"})
Expand Down
15 changes: 11 additions & 4 deletions modules/AllTask/SubTask/FightQuest.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,21 @@ def on_run(self) -> None:
sleeptime=2
)
# 1. 如果是白色UI,进入战斗
if match_pixel((1250, 32), Page.COLOR_BUTTON_WHITE):
if match_pixel((1250, 32), Page.COLOR_BUTTON_WHITE, printit=True):
# 战斗中
logging.info({"zh_CN": "战斗中...", "en_US": "Fighting"})
break
else:
logging.info({"zh_CN": "无法匹配右上暂停", "en_US": "Cannot match the upper right fight pause"})
logging.warn({"zh_CN": "请确认游戏设置:战斗时上下黑边 为 关", "en_US": "Please confirm the game settings: Black edges during battle are off"})
# 2. 如果是剧情,跳过剧情
if match(button_pic(ButtonName.BUTTON_STORY_MENU)):
logging.info({"zh_CN": "剧情中...", "en_US": "In the plot..."})
SkipStory(pre_times=3).run()
# 跳过剧情后,重新判断是否进入了战斗
continue
else:
logging.info({"zh_CN": "无法匹配剧情按钮", "en_US": "Cannot match the story pause button"})
# 切换AUTO
logging.info({"zh_CN": "切换AUTO...", "en_US": "Toggle Auto..."})
self.run_until(
Expand Down Expand Up @@ -151,9 +156,11 @@ def on_run(self) -> None:
self.run_until(
lambda: click(Page.MAGICPOINT),
lambda: match(button_pic(ButtonName.BUTTON_FIGHT_RESULT_CONFIRMB)) or match(
button_pic(ButtonName.BUTTON_CONFIRMY) or self.backtopic(), threshold=0.8),
times=90,
sleeptime=2
button_pic(ButtonName.BUTTON_CONFIRMY),
threshold=0.8
) or self.backtopic(),
times=90,
sleeptime=2
)
if self.backtopic():
# 此处返回到backtopic,意味着错误进入了战斗
Expand Down
Loading

0 comments on commit 42d5612

Please sign in to comment.