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

修复一些问题 #122

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
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 AutoHotkey64.exe
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不接受添加二进制可执行文件,需要以python实现

Binary file not shown.
150 changes: 150 additions & 0 deletions OneFiledispatch.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
#SingleInstance
;基于火er作品修改
;久岐忍会导致错误
;---------------------------引用贴入------------------------------

;#Include genshin.ahk


class Config {

static game_name_cn:='YuanShen.exe'
static game_name_global:='GenshinImpact.exe'
}

class Genshin {
static get_game_pos() {
if ProcessExist(Config.game_name_cn) {
WinGetClientPos(, , &width, &height, 'ahk_exe ' Config.game_name_cn)
} else if ProcessExist(Config.game_name_global) {
WinGetClientPos(, , &width, &height, 'ahk_exe ' Config.game_name_global)
} else {
width := 0
height := 0
}
return [width, height]
}

static is_game_exist() {
return ProcessExist(Config.game_name_cn) or ProcessExist(Config.game_name_global)
}

static is_game_active() {
return WinActive('ahk_exe ' Config.game_name_cn) or WinActive('ahk_exe ' Config.game_name_global)
}
}

class Point {
__New(x := '', y := '') {
this.x := x
this.y := y
this.x0 := x
this.y0 := y
}

refresh_pos(game_width, game_height) {
if this.x0 != '' {
this.x := this.x0 * game_width / 2560
}
if this.y0 != '' {
this.y := this.y0 * game_height / 1440
}
}
}



;---------------------------脚本本身代码------------------------------
class Dispatch {
static p_area_range_1 := Point(500, 160)
static p_area_range_2 := Point(1800, 1280)
static p_dispatch_button := Point(2465, 1360)
static characters := [Point(600, 240), Point(600, 384), Point(600, 528), Point(600, 672), Point(600, 816), Point(600, 960), Point(600, 1104)]
static dispatch_countries := [Point(200, 200), Point(200, 320), Point(200, 400), Point(200, 480),Point(200, 200)]
static p_dispatch_icon := Point(102, 60)
static p_choose_character_icon := Point(25, 80)
static color_off_white := '0xECE5D8'
static color_off_red := '0xDC6148'
static color_yellow_choose_character_icon := '0x263240'
static color_green_under_avatar := '0xD3E6AE'
static color_green_under_avatar2 := '0xD3E5AE'
static sleep_time := 100
static sleep_time1 := 300

static refresh_pos() {
size := Genshin.get_game_pos()
width := size[1]
height := size[2]
this.p_area_range_1.refresh_pos(width, height)
this.p_area_range_2.refresh_pos(width, height)
this.p_dispatch_button.refresh_pos(width, height)
for i in this.characters {
i.refresh_pos(width, height)
}
for i in this.dispatch_countries {
i.refresh_pos(width, height)
}
this.p_dispatch_icon.refresh_pos(width, height)
this.p_choose_character_icon.refresh_pos(width, height)
}

static dispatch() {
this.refresh_pos()
if PixelGetColor((this.p_dispatch_button.x, this.p_dispatch_button.y) = this.color_off_white or this.p_dispatch_button.x, this.p_dispatch_button.y = this.color_off_red ) and PixelGetColor(this.p_dispatch_icon.x, this.p_dispatch_icon.y) = this.color_off_white {
size := Genshin.get_game_pos()
width := size[1]
height := size[2]
for country in this.dispatch_countries {
MouseClick(, country.x, country.y)
Sleep(this.sleep_time)
i := 0
; 重试次数为5
while i < 5 and (PixelSearch(&x, &y, this.p_area_range_1.x, this.p_area_range_1.y, this.p_area_range_2.x, this.p_area_range_2.y, this.color_green_under_avatar, 5) or PixelSearch(&x, &y, this.p_area_range_1.x, this.p_area_range_1.y, this.p_area_range_2.x, this.p_area_range_2.y, this.color_green_under_avatar2, 5)) {
MouseClick(, x, y)
Sleep(this.sleep_time1)
MouseClick(, this.p_dispatch_button.x, this.p_dispatch_button.y)
Sleep(this.sleep_time1)
MouseClick(, this.p_dispatch_button.x, this.p_dispatch_button.y)
Sleep(this.sleep_time1)
MouseClick(, this.p_dispatch_button.x, this.p_dispatch_button.y)
Sleep(this.sleep_time1)
; 选人
for character in this.characters {
mouseClick(, character.x, character.y)
Sleep(this.sleep_time1)
j := 0
if PixelGetColor(this.p_choose_character_icon.x, this.p_choose_character_icon.y) != this.color_yellow_choose_character_icon {
break
}
}
i++
Sleep(this.sleep_time)
}


}

;TipOnce.tip('完成', , )
ToolTip('完成', width / 2, height / 2, 3)
;mouseClick(, this.p_area_range_2.x, this.p_area_range_2.y) ;点击测试2
Sleep(1500)
Send ("{esc}")
} else {
size := Genshin.get_game_pos()
width := size[1]
height := size[2]
ToolTip('当前不是派遣界面', width / 2, height / 2, 3)
;TipOnce.tip('当前不是派遣界面', , width / 2, height / 2)
;mouseClick(, this.p_choose_character_icon.x, this.p_choose_character_icon.y) ;这里是位置点击测试
Sleep(1500)
}
}
}

; ---执行---
;WinActive('原神')
WinWaitActive('原神')
;WinWaitActive (,'ahk_exe YuanShen.exe')
Dispatch.dispatch()


24 changes: 23 additions & 1 deletion config/json_doc/General.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,28 @@ BlossomType:
select_items: [Wealth, Revelation]

DomainName:
special_index: $INPUT_VERIFY$#domain_name
select_items: [
"椛染之庭",
"砂流之庭",
"菫色之庭",
"沉眠之庭",
"华池岩岫",
"太山府",
"孤云凌霄之处",
"山脊守望",
"无妄引咎密宫",
"震雷连山密宫",
"岩中幽谷",
"仲夏庭园",
"塞西莉亚苗圃",
"忘却之峡",
"铭记之谷",
"芬德尼尔之顶",
"昏识塔",
"有顶塔",
"缘觉塔",
"赤金的城墟",
"熔铁的孤塞"
]


4 changes: 3 additions & 1 deletion source/api/pdocr_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,11 @@ def get_text_position(self,
return list(ret_position)


def get_all_texts(self, img, mode=0, per_monitor=False):
def get_all_texts(self, img, mode=0, per_monitor=False,extract_white_threshold=None):
if per_monitor:
pt=time.time()
if extract_white_threshold!=None:
img = extract_white_letters(img, threshold = extract_white_threshold)
res = self.analyze(img)
if per_monitor:
logger.info(f"ocr performance: {round(time.time()-pt,2)}")
Expand Down
94 changes: 94 additions & 0 deletions source/interaction/interaction_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,100 @@ def appear(self, obj, use_cache=False):
elif isinstance(obj, img_manager.ImgIcon): # Button is also an Icon
return self.get_img_existence(obj, use_cache=use_cache)

def appear_then_nothing(self, inputvar, is_gray=False, is_log = False):
"""appear then click

Args:
inputvar (img_manager.ImgIcon/text_manager.TextTemplate/button_manager.Button)
is_gray (bool, optional): 是否启用灰度匹配. Defaults to False.

Returns:
bool: bool,点击操作是否成功
"""

if isinstance(inputvar, button_manager.Button):
imgicon = inputvar
upper_func_name = inspect.getframeinfo(inspect.currentframe().f_back)[2]

if not inputvar.click_retry_timer.reached():
return False

if inputvar.click_fail_timer.reached_and_reset():
logger.error(t2t("appear then click fail"))
logger.info(f"{inputvar.name} {inputvar.click_position}")
return False

cap = self.capture(posi=imgicon.cap_posi, jpgmode=imgicon.jpgmode)
# min_rate = img_manager.matching_rate_dict[imgname]

if inputvar.is_bbg == False:
matching_rate, click_posi = similar_img(imgicon.image, cap, is_gray=is_gray, ret_mode=IMG_POSI)
else:
matching_rate = similar_img(imgicon.image, cap, is_gray=is_gray)

if matching_rate >= imgicon.threshold:
if imgicon.win_text != None:
from source.api.pdocr_complete import ocr
r = ocr.get_text_position(cap, imgicon.win_text)
if r==-1:
matching_rate = 0

if imgicon.is_print_log(matching_rate >= imgicon.threshold) or is_log:
logger.debug(
'imgname: ' + imgicon.name + 'matching_rate: ' + str(
matching_rate) + ' |function name: ' + upper_func_name)

if matching_rate >= imgicon.threshold:
p = imgicon.cap_posi
logger.debug(f"appear then click: True: {imgicon.name} func: {upper_func_name}")
inputvar.click_fail_timer.reset()
inputvar.click_retry_timer.reset()
return True
else:
return False

elif isinstance(inputvar, img_manager.ImgIcon):
imgicon = inputvar
upper_func_name = inspect.getframeinfo(inspect.currentframe().f_back)[2]

cap = self.capture(posi=imgicon.cap_posi, jpgmode=imgicon.jpgmode)
# min_rate = img_manager.matching_rate_dict[imgname]

matching_rate = similar_img(imgicon.image, cap, is_gray=is_gray)

if matching_rate >= imgicon.threshold:
if imgicon.win_text != None:
from source.api.pdocr_complete import ocr
r = ocr.get_text_position(cap, imgicon.win_text)
if r==-1:
matching_rate = 0

if imgicon.is_print_log(matching_rate >= imgicon.threshold) or is_log:
logger.debug('imgname: ' + imgicon.name + 'matching_rate: ' + str(matching_rate) + ' |function name: ' + upper_func_name)

if matching_rate >= imgicon.threshold:
p = imgicon.cap_posi
center_p = [(p[0] + p[2]) / 2, (p[1] + p[3]) / 2]

logger.debug(f"appear then click: True: {imgicon.name} func: {upper_func_name}")
return True
else:
return False

elif isinstance(inputvar, text_manager.TextTemplate):
from source.api.pdocr_complete import ocr
upper_func_name = inspect.getframeinfo(inspect.currentframe().f_back)[2]
p1 = ocr.get_text_position(self.capture(jpgmode=NORMAL_CHANNELS, posi=inputvar.cap_area), inputvar.text, cap_posi_leftup=inputvar.cap_area[:2])
if is_log:
logger.debug('text: ' + inputvar.text + 'position: ' + str(p1) + ' |function name: ' + upper_func_name)
if p1 != -1:
logger.debug(f"appear then click: True: {inputvar.text} func: {upper_func_name}")
return True
else:
return False



def appear_then_click(self, inputvar, is_gray=False, is_log = False):
"""appear then click

Expand Down
2 changes: 2 additions & 0 deletions source/manager/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
AreaDomainLeyLineDisorder = PosiTemplate()
AreaGeneralInteractiveItemInformation = ImgIcon()
IconGeneralTalkBubble = ImgIcon()
AreaDomainResidue = Area()
AreaDomainResidue1 = Area()

# Text
QTSX = TextTemplate(text={"zh_CN":"七天神像","en_US":"Statues of The Seven"}, cap_area = AreaBigmapChoose.position)
Expand Down
37 changes: 5 additions & 32 deletions source/task/claim_reward/claim_reward.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from source.talk.talk import Talk
from source.manager import asset
from source.assets.claim_rewards import *

import os


class ClaimRewardMission(MissionExecutor, Talk):
"""这个类以MissionExecutor的方式执行任务,因为Mission中已有许多适合该任务的函数可以直接调用。
Expand Down Expand Up @@ -36,36 +37,9 @@ def get_available_reward(self):
return rewards

def _exec_dispatch(self):
def reset_character():
while 1:
cap = itt.capture(jpgmode=NORMAL_CHANNELS)
complete_posi = match_multiple_img(cap, IconExpeditionComplete.image, ignore_close=True)
complete_posi += match_multiple_img(cap, IconExpeditionComplete2.image, ignore_close=True)
if len(complete_posi)==0:
return
chara_head_posi = np.array(complete_posi)+np.array([80,80])
for posi in chara_head_posi:
itt.move_and_click(posi)
itt.delay("2animation")
r1 = itt.appear_then_click(ButtonExpeditionClaim)
itt.delay("2animation")
itt.move_and_click(ButtonExpeditionClaim.click_position())
itt.delay("2animation")
itt.appear_then_click(ButtonExpeditionSelectCharacters)
itt.delay("2animation")
i=0
while 1:
cp = ButtonExpeditionFirstCharacter.click_position()
itt.move_and_click([cp[0],cp[1]+i])
itt.delay("2animation")
if itt.get_img_existence(IconClaimRewardExpedition):
break
i+=80
for area in [ButtonExpeditionMD, ButtonExpeditionLY, ButtonExpeditionDQ, ButtonExpeditionXM]:
r = itt.appear_then_click(area)
if not r: continue
itt.delay("2animation")
reset_character()
itt.delay(1)
cmd = "start AutoHotkey64.exe OneFiledispatch.ahk"
os.system(cmd)

def exec_mission(self):
self.available_rewards = self.get_available_reward()
Expand All @@ -81,7 +55,6 @@ def exec_mission(self):
self.talk_until_switch(self.checkup_stop_func)
self.talk_switch(DispatchCharacterOnExpedition)
self._exec_dispatch()
self.exit_talk()

class ClaimRewardTask(TaskTemplate):
def __init__(self):
Expand Down
Loading