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

Main beta #710

Merged
merged 11 commits into from
Oct 1, 2023
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ picture/
tmp/
plugins/
StarRailAssistant_backup/
test.py
/*test*.py
/*map*.py
map_list.json
LICENSE
picture_list.json
Expand Down
31 changes: 26 additions & 5 deletions Honkai_Star_Rail.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ def select_map(main_map):
if not options_map:
return None, _("你没下载地图,拿什么选?")
keys = list(options_map.keys())
values = list(options_map.values())+[_("返回上一级")]
values = [_(split_name[0]) + '-' + split_name[1] for split_name in (map_name.split('-') for map_name in options_map.values())]
values.append(_("返回上一级"))
option_ = questionary.select(title_, values).ask()
if option_ == _("返回上一级"):
return select_word()
Expand Down Expand Up @@ -172,17 +173,17 @@ def select_map(main_map):
def set_config(self, start = True):
global game_title
if not sra_config_obj.start or not start:
title = "请选择你游戏的运行语言:"
import utils.config
_ = utils.config._
title = _("请选择你游戏的运行语言:")
options = {
"简体中文": "zh_CN",
"繁體中文": "zh_TC",
"English": "EN"
}
option = questionary.select(title, options).ask()
sra_config_obj.language = options[option]
import utils.config
importlib.reload(utils.config)
_ = utils.config._
title = _("请选择代理地址:(不使用代理选空白选项)")
options = ['https://ghproxy.com/', 'https://ghproxy.net/', 'hub.fgit.ml', '']
url_ms = []
Expand Down Expand Up @@ -223,6 +224,26 @@ def set_config(self, start = True):
url_ms = [i.replace(" "," "*(len(max(url_ms, key=len))-len(i))) if len(i) < len(max(url_ms, key=len)) else i for i in url_ms]
option = options[url_ms.index(questionary.select(title, url_ms).ask())]
sra_config_obj.rawgithub_proxy = option
title = _("请选择API代理地址:(不使用代理选空白选项)")
options = ['https://github.srap.link/', '']
url_ms = []
pbar = tqdm.tqdm(total=len(options), desc=_('测速中'), unit_scale=True, unit_divisor=1024, colour="green")
for index,url in enumerate(options):
if url == "":
url = "https://api.github.com"
elif "https://" not in url:
url = f"https://"+url
try:
response = asyncio.run(get(url))
ms = response.elapsed.total_seconds()
except:
ms = 999
finally:
pbar.update(1)
url_ms.append(options[index]+f" {ms}ms")
url_ms = [i.replace(" "," "*(len(max(url_ms, key=len))-len(i))) if len(i) < len(max(url_ms, key=len)) else i for i in url_ms]
option = options[url_ms.index(questionary.select(title, url_ms).ask())]
sra_config_obj.apigithub_proxy = option
title = _("请选择你的仓库来源:")
options = ["Starry-Wind", "Night-stars-1"]
option = questionary.select(title, options).ask()
Expand Down Expand Up @@ -261,7 +282,7 @@ def is_updata(self):
if not asyncio.run(update_file().is_latest(type=up_data['type'], version=up_data['version'], is_log=False))[0]:
need_updata.append(name)
return need_updata

def main(self, option:str=_('大世界'),start: str=None,role_list: str=None):
"""
参数:
Expand Down
13 changes: 12 additions & 1 deletion gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Author: Night-stars-1 [email protected]
Date: 2023-05-29 16:54:51
LastEditors: Night-stars-1 [email protected]
LastEditTime: 2023-07-21 01:19:21
LastEditTime: 2023-07-25 15:25:10
Description:

Copyright (c) 2023 by Night-stars-1, All Rights Reserved.
Expand Down Expand Up @@ -293,6 +293,8 @@ def set_config(e):
github_proxy = sra_config_obj.github_proxy
rawgithub_proxy_list = ['https://ghproxy.com/', 'https://ghproxy.net/', 'raw.fgit.ml', 'raw.iqiq.io', "不设置代理"]
rawgithub_proxy = sra_config_obj.rawgithub_proxy
apigithub_proxy_list = ['https://github.srap.link/', "不设置代理"]
apigithub_proxy = sra_config_obj.apigithub_proxy
open_map = sra_config_obj.open_map
level = sra_config_obj.level

Expand All @@ -310,6 +312,13 @@ def set_config(e):
value=rawgithub_proxy,
width=200,
)
apigithub_proxy_dd = ft.Dropdown(
label=_("RAWGITHUB代理"),
hint_text=_("如果你无法下载资源,请设置此代理"),
options=[ft.dropdown.Option(i) for i in apigithub_proxy_list],
value=apigithub_proxy,
width=200,
)
level_dd = ft.Dropdown(
label=_("日志等级"),
hint_text=_("日志等级"),
Expand Down Expand Up @@ -340,6 +349,7 @@ def set_config(e):
def save(e):
sra_config_obj.github_proxy = "" if github_proxy_dd.value == "不设置代理" else github_proxy_dd.value
sra_config_obj.rawgithub_proxy = "" if rawgithub_proxy_dd.value == "不设置代理" else rawgithub_proxy_dd.value
sra_config_obj.apigithub_proxy = "" if apigithub_proxy_dd.value == "不设置代理" else apigithub_proxy_dd.value
sra_config_obj.open_map = open_map_tf.value
sra_config_obj.level = level_dd.value
sra_config_obj.language = language_dict[language_dd.value]
Expand All @@ -353,6 +363,7 @@ def save(e):
ft.Text(VER, size=20),
github_proxy_dd,
rawgithub_proxy_dd,
apigithub_proxy_dd,
level_dd,
open_map_tf,
language_dd,
Expand Down
Binary file modified locale/EN/LC_MESSAGES/sra.mo
Binary file not shown.
107 changes: 51 additions & 56 deletions utils/calculated.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
from pynput.mouse import Controller as MouseController
from pynput.keyboard import Controller as KeyboardController, Key
from typing import Dict, Optional, Any, Union, Tuple, List, Literal

from .config import sra_config_obj, CONFIG_FILE_NAME, get_file, _
from .exceptions import Exception
from .log import log
from .cv_tools import show_img, find_best_match, match_scaled
from .exceptions import Exception
from .cv_tools import CV_Tools, show_img
from .get_angle import Point

class calculated:
class calculated(CV_Tools):

def __init__(self, title=_("崩坏:星穹铁道"), det_model_name="ch_PP-OCRv3_det", rec_model_name= "densenet_lite_114-fc", number=False, start=True):
"""
Expand All @@ -35,12 +36,17 @@ def __init__(self, title=_("崩坏:星穹铁道"), det_model_name="ch_PP-OCRv3
:param number: 是否只考虑数字
:param start: 是否开始运行脚本 如果为False则不加载OCR等模型
"""
super().__init__(title)
self.title = title

self.scaling = sra_config_obj.scaling
self.DEBUG = sra_config_obj.debug
self.mouse = MouseController()
self.keyboard = KeyboardController()
self.point = Point(title)

self.pos = (100, 100)

if start:
if getattr(sys, 'frozen', None):
dir = sys._MEIPASS
Expand All @@ -50,11 +56,6 @@ def __init__(self, title=_("崩坏:星穹铁道"), det_model_name="ch_PP-OCRv3
#self.ocr = CnOcr(det_model_name='db_resnet34', rec_model_name='densenet_lite_114-fc')
self.check_list = lambda x,y: re.match(x, str(y)) != None
self.compare_lists = lambda a, b: all(x <= y for x, y in zip(a, b))
self.window = gw.getWindowsWithTitle(self.title)
if not self.window:
raise Exception(_("你游戏没开,我真服了"))
self.window = self.window[0]
self.hwnd = self.window._hWnd

# 初始化
self.attack = cv.imread("./picture/pc/attack.png")
Expand Down Expand Up @@ -189,32 +190,6 @@ def hsv_click(self, hsv_color, points=(0,0,0,0), offset=(0,0), flag=True, tolera
self.click(ret)
return True

def take_screenshot(self,points=(0,0,0,0)):
"""
说明:
返回RGB图像
参数:
:param points: 图像截取范围
"""
borderless = sra_config_obj.borderless
left_border = sra_config_obj.left_border
up_border = sra_config_obj.up_border
#points = (points[0]*1.5/scaling,points[1]*1.5/scaling,points[2]*1.5/scaling,points[3]*1.5/scaling)
if borderless:
left, top, right, bottom = self.window.left, self.window.top, self.window.right, self.window.bottom
else:
left, top, right, bottom = self.window.left+left_border, self.window.top+up_border, self.window.right-left_border, self.window.bottom-left_border
# log.info(f"{left}, {top}, {right}, {bottom}")
game_img = ImageGrab.grab((left, top, right, bottom), all_screens=True)
# game_img.save(f"logs/image/image_grab_{int(time.time())}.png", "PNG")
game_width, game_length = game_img.size
if points != (0,0,0,0):
#points = (points[0], points[1]+5, points[2], points[3]+5)
game_img = game_img.crop((game_width/100*points[0], game_length/100*points[1], game_width/100*points[2], game_length/100*points[3]))
screenshot = np.array(game_img)
screenshot = cv.cvtColor(screenshot, cv.COLOR_BGR2RGB)
return (screenshot, left, top, right, bottom, game_width, game_length)

def remove_non_white_pixels(self, image):
"""
说明:
Expand Down Expand Up @@ -272,6 +247,17 @@ def click_target(self, target_path: str, threshold, flag:bool=True, check:bool=F
picture_path = "picture\\pc\\"+target_path
temp_name = target_path.split(".")[0]
join = False # 强制进行传统模板匹配
'''
map:
type为str时点击对应文字
tyrpe为tuple时点击对应坐标
map_*_point:
type为dict时在points中点击name
其他:
type为dict时在points中点击name
type为tuple时点击百分比坐标
type为str时点击文字
'''
temp_ocr = {
"orientation_1": {
"name": _("星轨航图"),
Expand Down Expand Up @@ -303,17 +289,7 @@ def click_target(self, target_path: str, threshold, flag:bool=True, check:bool=F
"map_3-6": _("鳞渊境"),
"change_team": _("更换队伍"),
}
'''
map:
type为str时点击对应文字
tyrpe为tuple时点击对应坐标
map_*_point:
type为dict时在points中点击name
其他:
type为dict时在points中点击name
type为tuple时点击百分比坐标
type为str时点击文字
'''

if temp_name in temp_ocr:
log.info(temp_name)
if "orientation" in temp_name:
Expand Down Expand Up @@ -439,7 +415,7 @@ def fighting(self):
if not (self.compare_lists([0, 0, 225], result) and self.compare_lists(result, [0, 0, 255])):
self.wait_fight_end() # 无论是否识别到敌人都判断是否结束战斗,反正怪物袭击
return True

def check_fighting(self):
while True:
end_str = str(self.part_ocr((20,95,100,100)))
Expand Down Expand Up @@ -561,9 +537,9 @@ def mouse_move(self, x):
"""
# 该公式为不同缩放比之间的转化
scaling = sra_config_obj.scaling
dx = int(x * scaling)
dx = x * scaling
i = int(dx/200)
last = dx - i*200
last = int(dx - i*200)
for ii in range(abs(i)):
if dx >0:
win32api.mouse_event(1, 200, 0) # 进行视角移动
Expand All @@ -572,7 +548,7 @@ def mouse_move(self, x):
time.sleep(0.1)
if last != 0:
win32api.mouse_event(1, last, 0) # 进行视角移动
time.sleep(0.5)
#time.sleep(0.5)

def move(self, com: str = ["w","a","s","d","f"], sleep_time=1, map_name=""):
'''
Expand All @@ -582,6 +558,7 @@ def move(self, com: str = ["w","a","s","d","f"], sleep_time=1, map_name=""):
:param com: 键盘操作 wasdf
:param time 操作时间,单位秒
'''
loc = self.get_loc(map_name=map_name)
if type(sleep_time) == list:
set_loc = sleep_time[1]
sleep_time = sleep_time[0]
Expand Down Expand Up @@ -983,9 +960,17 @@ def get_loc(self, map_name: str="", map_id: int=None):
"城郊雪原-2": 7
},
"边缘道路": {
"边缘道路-1": 8,
"边缘道路-1": 51,
"边缘道路-2": 8
},
"工造司": {
"工造司-1": 9,
"工造司-2": 9,
"工造司-3": 9,
"工造司-4": 9,
"工造司-5": 9,
"工造司-6": 9,
},
"丹鼎司": {
"丹鼎司-1": 2,
"丹鼎司-2": 3,
Expand All @@ -1003,13 +988,23 @@ def get_loc(self, map_name: str="", map_id: int=None):
return (0, 0)
img = cv.imread(f"./picture/maps/{map_id}.png")
template = self.take_screenshot((4,8,10,20))[0]
__, max_val, max_loc, __, __ = find_best_match(img, template,(100,120,5))
#img = img[self.pos[1]-100:img.shape[0]] [124, 103, 102]
max_scale_percent, max_val, max_loc, length, width = self.find_best_match(img, template, [100,150,5])
#max_val, max_loc = match_scaled(img, template,2.09)
#cv.rectangle(img, max_loc, (max_loc[0] + 100, max_loc[1] + 100), (0, 255, 0), 2)
#show_img(img)
return (max_loc[0] + 63, max_loc[1] + 67)
else:
return (0, 0)
#log.info(max_scale_percent)
#log.info(max_val)
'''
if max_scale_percent in [102, 103]:
max_loc = (max_loc[0] + int(width/2)+17, max_loc[1] + int(length/2))
else:
max_loc = (max_loc[0] + int(width/2)+10, max_loc[1] + int(length/2))
'''
max_loc = (max_loc[0] + width//2 + 6, max_loc[1] + length//2 + 1)
cv.rectangle(img, max_loc, (max_loc[0] + 5, max_loc[1] + 5), (0, 255, 0), 2)
show_img(img, not_close=1)
#max_loc = (max_loc[0], max_loc[1] + self.pos[1]-100)
self.pos = max_loc
return max_loc

def change_team(self):
"""
Expand Down
2 changes: 2 additions & 0 deletions utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ class SRAData(metaclass=SRADataMeta):
"""github代理"""
rawgithub_proxy: str = ""
"""rawgithub代理"""
apigithub_proxy: str = ""
"""apigithub代理"""
webhook_url: str = ""
"""webhook地址"""
start: bool = False
Expand Down
Loading