Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
ZYX committed Jul 2, 2024
1 parent 897f65a commit 25e5996
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 67 deletions.
9 changes: 6 additions & 3 deletions actions/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,12 @@
{
"press": "esc"
},
{
"sleep": "1"
},
{
"position": [1177, 672]
},
{
"sleep": "2"
},
Expand Down Expand Up @@ -429,9 +435,6 @@
},
{
"position": [1680, 527]
},
{
"sleep": 1
}
]
},
Expand Down
17 changes: 10 additions & 7 deletions actions/event.csv
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
�¼�����,��ˢѡ��,����ѡ��,�ر�ѡ��
ռ��,����ܷ���,�����Σ��,�ó̻�˳��
�泲,��Ҫ����Ѻע,,����泲
����֮��,"����-��ȥ","����-��ȥ",ս��
����,"����-��","����-��",ս��
��������,�Ҽ�������-����Ƭ,�Ҽ�������-����Ƭ,
���ӹ���Ƶ��,����50������Ƭ-�뿪����,����100������Ƭ-�㲻����Ȥ,��ʧ40��ǰ����ֵ
��������ս,�߿�,�߿�,����
Expand Down Expand Up @@ -60,16 +60,19 @@
�Ǽʺ�ƽ��˾��ְ�����,�ɶ�-����-��ѵ,,
�Ǽʺ�ƽ��˾��ְ������,�Ǽ��ݽ�,�Ǽ��ݽ�,
�Ǽʺ�ƽ��˾��ְ������,���2��1�Ƿ���,200-�޾�Ȩ��,
����Ǽʺ�ƽ������һ,�߿�,100,
����Ǽʺ�ƽ�������,ȡ��-�߿�,�߿�,
�Ǽʺ�ƽ������һ,�߿�,100,
�Ǽʺ�ƽ�������,ȡ��-�߿�,�߿�,
�¶�̫������ģ��������һ,����100-ף��,,����
�¶�̫������ģ���������,����,�������,�ܾ�
�������һ,ȫ����ɫ������ʧ,ȫ����ɫ������ʧ,����1������
��������,����,����,
���������,���������,���������,
������һ,ȫ����ɫ������ʧ,ȫ����ɫ������ʧ,����1������
�������,����,����,
��������,���������,���������,
�����һ,ȫ����ɫ������ʧ,ȫ����ɫ������ʧ,����1������
������,����,����,
�������,���������,���������,
����������һ,100,,�߿�
���Ӻ������,50,200,�߿�
���Ӻ�������,10,,�߿�
��÷,����-��������,��Ҫ�ܶ�Ǯ,
��÷���,����-��������,����-��������,
��÷����,һ��ͻ��������-����˿��ķ,һ��ͻ��������-����˿��ķ,
��÷����,������-����˿,������-����˿,
110 changes: 62 additions & 48 deletions diver.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ def __init__(self, debug=0, nums=-1, speed=0):
self.floor = 0
self.allow_e = 1
self.count = self.my_cnt = 0
if not hasattr(self, 'hot_init'):
self.debug = debug
self.nums = nums
self.speed = speed
self.debug = debug
self.nums = nums
self.speed = speed
self.init_tm = time.time()
self.area_now = None
self.action_history = []
Expand Down Expand Up @@ -190,7 +189,7 @@ def read_csv(self, file_path, name):
return data

def clean_text(self, text, char=1):
symbols = r"[!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~—“”‘’«»„…·¿¡£¥€©®™°±÷׶§‰],。!?;:()【】「」《》、¥"
symbols = r"[!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~—“”‘’«»„…·¿¡£¥€©®™°±÷׶§‰],。!?;:()【】「」《》、¥ "
if char:
symbols += r"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
translator = str.maketrans('', '', symbols)
Expand Down Expand Up @@ -228,11 +227,13 @@ def select_save(self):

def close_and_exit(self, click=True):
self.press('esc')
if self.debug:
if self.debug and self.floor < 13:
with open('test.txt', 'a') as f:
format_string = "%H:%M:%S"
formatted_time = time.strftime(format_string, time.localtime())
f.write(formatted_time + '\n')
while 1:
time.sleep(1)
time.sleep(2.5)
self.init_floor()
if not click:
Expand Down Expand Up @@ -302,21 +303,20 @@ def find_portal(self, type=None):
prefer_portal.update({'首领':4, '休整':4})
tm = time.time()
text = self.ts.find_with_box([0,1920,0,540], forward=1, mode=2)
portal = {'score':-1,'nums':0}
portal = {'score':0,'nums':0,'type':''}
for i in text:
if ('区' in i['raw_text'] or '域' in i['raw_text']) and (i['box'][0] > 400 or i['box'][2] > 60):
portal_type = self.get_text_type(i['raw_text'], prefer_portal)
if portal_type is not None:
i.update({'score':prefer_portal[portal_type]+10*(portal_type==type), 'type':portal_type, 'nums':portal['nums']+1})
if i['score'] > portal['score']:
portal = i
elif '冒险' in i['raw_text']:
portal['nums'] += 1
ocr_time = time.time() - tm
self.ocr_time_list = self.ocr_time_list[-5:] + [ocr_time]
print(f'识别时间:{int(ocr_time*1000)}ms', text, portal)
if portal['score'] == -1:
return None
else:
return portal
return portal

def sleep(self, tm=2):
time.sleep(tm)
Expand All @@ -334,10 +334,12 @@ def aim_portal(self, portal):
return portal
time.sleep(0.2)
portal_after = self.find_portal(portal['type'])
if portal_after is None:
return portal
else:
portal = portal_after
if portal_after['score'] == 0:
self.press('w', 1)
portal_after = self.find_portal(portal['type'])
if portal_after['score'] == 0:
return portal
portal = portal_after
return portal

def forward_until(self, text_list=[], timeout=5, moving=0):
Expand All @@ -356,6 +358,7 @@ def forward_until(self, text_list=[], timeout=5, moving=0):
self.press('f')
return 1
else:
tm += 0.7
keyops.keyDown('w')
time.sleep(0.5)
keyops.keyUp('w')
Expand All @@ -368,7 +371,7 @@ def portal_opening_days(self, aimed=0, static=0, deep=0):
return
if deep == 0:
self.portal_cnt += 1
portal = None
portal = {'score':0,'nums':0,'type':''}
moving = 0
if static:
# win32api.mouse_event(win32con.MOUSEEVENTF_MOVE, 0, int(100 * self.multi * self.scale))
Expand All @@ -377,10 +380,10 @@ def portal_opening_days(self, aimed=0, static=0, deep=0):
self.mouse_move(angle)
time.sleep(0.2)
portal = self.find_portal()
if portal is not None:
if portal['score']:
break
if self.floor in [1,2,4,5,6,7,9,10]:
if portal is not None and portal['nums'] == 1 and portal['score'] < 2:
if portal['nums'] == 1 and portal['score'] < 2:
portal_pre = portal
portal_type = portal['type']
bias = 0
Expand All @@ -389,24 +392,24 @@ def portal_opening_days(self, aimed=0, static=0, deep=0):
bias += angles[i]
time.sleep(0.2)
portal_after = self.find_portal()
if portal_after is not None and portal_type != portal_after['type']:
if portal_after['score'] and portal_type != portal_after['type']:
portal = portal_after
break
if portal['type'] == portal_type:
portal = portal_pre
self.mouse_move(-bias)
tm = time.time()
while time.time() - tm < 5 + 2 * (portal is not None):
while time.time() - tm < 5 + 2 * (portal['score'] != 0):
if aimed == 0:
if portal is None:
if portal['score'] == 0:
portal = self.find_portal()
else:
if self.forward_until([portal['type'] if portal else '区域'], timeout=3, moving=moving):
if self.forward_until([portal['type'] if portal['score'] else '区域'], timeout=3, moving=moving):
self.init_floor()
return
else:
moving = 0
if portal is not None and not aimed:
if portal['score'] and not aimed:
if moving:
print('stop moving')
keyops.keyUp('w')
Expand All @@ -416,15 +419,15 @@ def portal_opening_days(self, aimed=0, static=0, deep=0):
else:
print('aiming...')
tmp_portal = self.aim_portal(portal)
if tmp_portal is None:
if tmp_portal['score'] == 0:
self.portal_opening_days(aimed=0, static=1, deep=deep+1)
return
else:
portal = tmp_portal
aimed = 1
moving = 1
keyops.keyDown('w')
elif portal is None:
elif portal['score'] == 0:
if not moving:
keyops.keyDown('w')
moving = 1
Expand All @@ -446,13 +449,18 @@ def event(self):
tm = time.time()
while time.time() - tm < 20:
title_text = self.merge_text(self.ts.find_with_box([170, 850, 900, 1020], redundancy=0), char=0)
print(title_text)
if event_id[0] == -1:
for i, e in enumerate(self.event_prior):
if e in title_text and len(e) > len(event_id[1]):
event_id = (i, e)
start = self.now_event == event_id[1]
self.now_event = event_id[1]
print('event_id:', event_id)
if self.debug and event_id[0] == -1:
print(self.ts.res)
while 1:
time.sleep(1)
if '事件' not in self.merge_text(self.ts.find_with_box([92, 195, 54, 88])):
return

Expand Down Expand Up @@ -523,9 +531,11 @@ def find_event_text(self, save=0):
print('event_text:', text)
for i in text:
box = i['box']
if 'ms' in i['raw_text'] or '状态效' in i['raw_text'] or len(i['raw_text']) < 2 \
if 'ms' in i['raw_text'] or '状态效' in i['raw_text'] or len(i['raw_text']) < 2 or (box[0] > 1470 and box[2] < 75)\
or (box[0] > 1800 and box[2] < 120) or (box[0] > 1600 and box[2] > 290) or (box[1] < 400 and box[3] < 160):
continue
if '?' not in i['raw_text'] and '?' not in i['raw_text'] and len(self.clean_text(i['raw_text'], 1)) == 0:
continue
w, h = box[1] - box[0], box[3] - box[2]
if w < 40 or h > 40:
continue
Expand Down Expand Up @@ -553,17 +563,24 @@ def align_event(self, key, deep=0):
if self.check_f(is_in=['事件','奖励','遭遇','交易']):
self.press('f')
return
elif self.check_f(is_in=['混沌','药箱']):
self.press('f')
time.sleep(2.5)
self.run_static(action_list=['混沌药箱'], skip_check=1)
tm = time.time()
while time.time() - tm < 3:
self.ts.forward(self.get_screen())
res = self.run_static(action_list=['点击空白处关闭'])
if len(res):
tm = time.time()
return
# elif self.check_f(is_in=['混沌','药箱']):
# self.press('f')
# time.sleep(2.5)
# self.run_static(action_list=['混沌药箱'], skip_check=1)
# tm = time.time()
# while time.time() - tm < 3:
# self.ts.forward(self.get_screen())
# res = self.run_static(action_list=['点击空白处关闭'])
# if len(res):
# tm = time.time()
# time.sleep(2)
# if deep == 0:
# self.align_event(key, deep+1)
# return

if not event_text and key == 'a':
event_text = 950

if event_text:
if abs(event_text - 950) > 40:
self.press(key,0.2)
Expand All @@ -585,10 +602,8 @@ def align_event(self, key, deep=0):
for _ in range(-sub):
self.press('a',0.2)
time.sleep(0.1)
self.forward_until(['事件','奖励','遭遇','交易'], timeout=3, moving=0)
self.forward_until(['事件','奖励','遭遇','交易'], timeout=2.5, moving=0)
else:
if key == 'a':
return
if deep < 3:
self.press('w',[0,0.3,0.5][deep])
self.align_event(key, deep+1)
Expand Down Expand Up @@ -698,10 +713,10 @@ def area(self):
pyautogui.click()
time.sleep(0.8)
keyops.keyDown('w')
time.sleep(1.3)
time.sleep(1.6)
self.press('d',0.4)
keyops.keyUp('w')
time.sleep(1)
time.sleep(0.6)
self.portal_opening_days(static=1)
elif area_now == '首领':
if self.floor == 13 and self.area_state > 0:
Expand All @@ -711,8 +726,8 @@ def area(self):
if self.area_state == 0:
self.press('w',3)
for c in config.skill_char:
if c in self.team_member and self.allow_e:
self.press(str(self.team_member[c]+1))
if (c in self.team_member or c.isdigit()) and self.allow_e:
self.press(int(c) if c.isdigit() else str(self.team_member[c]+1))
time.sleep(0.8)
self.check_dead()
self.skill()
Expand Down Expand Up @@ -775,7 +790,7 @@ def area(self):
self.press('w', 0.5)
self.portal_opening_days(static=1)
elif area_now == '财富':
self.press('w',3)
self.press('w',2.7)
pyautogui.click()
time.sleep(0.6)
keyops.keyDown('w')
Expand All @@ -784,7 +799,8 @@ def area(self):
self.press('a', 0.5)
time.sleep(0.35)
keyops.keyUp('w')
if self.find_portal() is None:
time.sleep(0.6)
if self.find_portal()['score'] == 0:
self.press('a', 0.4)
self.press('s', 0.7)
self.press('w', 0.5)
Expand Down Expand Up @@ -930,8 +946,6 @@ def on_key_press(self, event):
self.stop()

def start(self):
self.hot_init = 1
self.__init__()
self._stop = False
keyboard.on_press(self.on_key_press)
self.keys = KeyController(self)
Expand Down
8 changes: 4 additions & 4 deletions info_example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ config:
# 传送门优先级,1-3,3代表优先级最高,1代表优先级最低
# 如需自定义请将enable_portal_prior设为1
# 只能修改数字,不要修改名称
enable_portal_prior: 1
enable_portal_prior: 0
portal_prior:
商店: 1
财富: 1
战斗: 1
遭遇: 1
战斗: 2
遭遇: 2
奖励: 3
事件: 1
事件: 3

key_mapping:
# 交互键,只能是单个字母
Expand Down
3 changes: 3 additions & 0 deletions utils/diver/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ def update_skill(self, skill: List[str]):
i = self.match[i]
if i in self.all_list:
self.skill_char.append(i)
elif i in ['1', '2', '3', '4']:
self.skill_char.append(i)


def read(self):
if os.path.exists(os.path.join(self.abspath, self.text)):
Expand Down
8 changes: 4 additions & 4 deletions utils/diver/ocr.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ def box_contain(self, box_out, box_in, redundancy):
def find_with_box(self, box=None, redundancy=10, forward=0, mode=0):
if forward and box is not None:
self.forward(self.filter_non_white(self.father.get_screen()[box[2]:box[3],box[0]:box[1]], mode=mode))
# if box[3]==540 or box[3] == 350:
# tm = str(int(time.time()*100)%1000000)
# cv.imwrite('img/'+tm+'.jpg',self.father.screen[box[2]:box[3],box[0]:box[1]])
# cv.imwrite('img/'+tm+'w.jpg',self.filter_non_white(self.father.screen[box[2]:box[3],box[0]:box[1]]))
if box[3]==540 or box[3] == 350 and self.father.debug:
tm = str(int(time.time()*100)%1000000)
cv.imwrite('img/'+tm+'.jpg',self.father.screen[box[2]:box[3],box[0]:box[1]])
cv.imwrite('img/'+tm+'w.jpg',self.filter_non_white(self.father.screen[box[2]:box[3],box[0]:box[1]]))
ans = []
for res in self.res:
if box is None:
Expand Down
Loading

0 comments on commit 25e5996

Please sign in to comment.