Skip to content

Commit

Permalink
bug fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
AcademicDog committed Jun 21, 2019
1 parent 3e7a9e1 commit f2ff308
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 33 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
2、完善点怪操作。

# 更新说明
20190619--抛弃dll插件,用win32api,同时用图像识别替代简单找色
v1.0.0.0619--抛弃dll插件,用win32api,同时用图像识别替代简单找色。
v1.0.0.0621--修改了完成战斗后,等待时间重复计算的bug,同时移除了不必要的参数设置。

# 协议 (License)

Expand Down
11 changes: 6 additions & 5 deletions fighter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,32 @@

class Fighter:

def __init__(self, emyc=0):
def __init__(self, name = '', emyc = 0):
# 初始参数
self.emyc = emyc
self.name = name

# 启动日志
self.log = logsystem.WriteLog()

# 绑定窗口
self.yys = game_ctl.GameControl(u'阴阳师-网易游戏')
self.log.writeinfo('registration successful')
self.log.writeinfo(self.name + 'Registration successful')

# 激活窗口
self.yys.activate_window()
self.log.writeinfo('Activation successful')
self.log.writeinfo(self.name + 'Activation successful')
utilities.mysleep(500)

def check_battle(self):
# 检测是否进入战斗
self.yys.wait_game_img('img\\ZI-DONG.png')
self.log.writeinfo('Already in battle')
self.log.writeinfo(self.name + 'Already in battle')

def check_end(self):
# 检测是否打完
self.yys.wait_game_img('img\\JIE-SU.png')
self.log.writeinfo("Battle finished")
self.log.writeinfo(self.name + "Battle finished")

def click_monster(self):
# 点击怪物
Expand Down
8 changes: 4 additions & 4 deletions fighter_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
class DriverFighter(fighter.Fighter):
'''御魂战斗司机程序,参数mode, emyc'''

def __init__(self, mode, done, emyc=0):
def __init__(self, done = 1, emyc = 0):
# 初始化
fighter.Fighter.__init__(self, emyc)
fighter.Fighter.__init__(self, 'Driver:', emyc)

def start(self):
'''单人御魂司机'''
Expand All @@ -22,7 +22,7 @@ def start(self):
# 司机点击开始战斗,需要锁定御魂阵容
self.yys.wait_game_img('img\\KAI-SHI-ZHAN-DOU.png')
mood1.moodsleep()
self.yys.mouse_click_bg((850, 509), (1002, 558))
self.yys.mouse_click_bg((857, 515), (998, 556))
self.log.writeinfo('Driver: clicked KAI-SHI-ZHAN-DOU!')

# 检测是否进入战斗
Expand All @@ -37,10 +37,10 @@ def start(self):

# 在战斗结算页面
self.yys.mouse_click_bg(utilities.firstposition())
mood3.moodsleep()
start_time = time.time()
while time.time() - start_time <= 10:
# 点击结算
mood3.moodsleep()
self.yys.mouse_click_bg(utilities.secondposition())
if(self.yys.wait_game_img('img\\KAI-SHI-ZHAN-DOU.png', mood3.get1mood()/1000, False)):
self.log.writeinfo('Driver: in team')
Expand Down
8 changes: 4 additions & 4 deletions fighter_passenger.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
class FighterPassenger(fighter.Fighter):
'''御魂战斗乘客程序,参数mode, emyc'''

def __init__(self, mode, done, emyc=0):
def __init__(self, done = 1, emyc = 0):
# 初始化
fighter.Fighter.__init__(self, emyc)
fighter.Fighter.__init__(self, 'Passenger:', emyc)

def start(self):
'''单人御魂乘客'''
Expand All @@ -30,10 +30,10 @@ def start(self):

# 在战斗结算页面
self.yys.mouse_click_bg(utilities.firstposition())
mood3.moodsleep()
start_time = time.time()
while time.time() - start_time <= 10:
# 点击结算
mood3.moodsleep()
self.yys.mouse_click_bg(utilities.secondposition())
if(self.yys.wait_game_img('img\\LI-KAI-DUI-WU.png', mood3.get1mood()/1000, False)):
self.log.writeinfo('Passenger: in team')
Expand All @@ -45,6 +45,6 @@ def start(self):
self.log.writeinfo('Passenger: auto accepted')

# 点击普通接受邀请
if(self.yys.wait_game_img('img\\JIE-SHOU.png', 0.1, False)):
elif(self.yys.wait_game_img('img\\JIE-SHOU.png', 0.1, False)):
self.yys.mouse_click_bg((125, 230))
self.log.writeinfo('Passenger: accepted')
4 changes: 2 additions & 2 deletions game_ctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,15 @@ def mouse_drag_bg(self,pos1,pos2):
time.sleep(0.01)
win32gui.SendMessage(self.hwnd,win32con.WM_LBUTTONUP,0,win32api.MAKELONG(pos2[0],pos2[1]))

def wait_game_img(self, img_path, max_time = 30, quit=True):
def wait_game_img(self, img_path, max_time = 100, quit=True):
"""
等待游戏图像
:param img_path: 图片路径
:param max_time=30: 超时时间
:param quit=True: 超时后是否退出
:return: 成功返回True,失败返回False
"""
self.rejectbounty()
start_time=time.time()
while time.time()-start_time<=max_time:
maxVal,maxLoc=self.find_img(img_path)
Expand Down Expand Up @@ -290,7 +291,6 @@ def rejectbounty(self):
:return: 拒绝成功返回True,其他情况返回False
'''
maxVal, maxLoc = self.find_img('img\\XUAN-SHANG.png')
print(maxVal, maxLoc)
if maxVal>0.97:
self.mouse_click_bg((757,460))
return True
Expand Down
24 changes: 12 additions & 12 deletions onmyoji.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,25 @@ def init():

try:
# 模式选择
mode=int(input('\n选择游戏模式(Ctrl-C跳过并单刷):\n0-单刷\n1-本地双开\n2-组队司机\n3-组队打手\n'))
mode=int(input('\n选择游戏模式(Ctrl-C跳过并单刷):\n0-单刷\n2-组队司机\n3-组队打手\n'))
if(mode==1):
log.writewarning('未开发,告辞!')
os._exit(0)
elif(mode != 2 and mode != 0 and mode != 3):
mode=0

# 点怪设置
emyc=int(input('\n是否点怪?\n0-不点怪\n1-点中间怪\n2-点右边怪\n'))
if((emyc!=0) and (emyc!=1) and (emyc!=2)):
emyc=0
# emyc=int(input('\n是否点怪?\n0-不点怪\n1-点中间怪\n2-点右边怪\n'))
# if((emyc!=0) and (emyc!=1) and (emyc!=2)):
# emyc=0

# 结束设置
done=int(input('\n结束后如何处理?\n0-退出\n1-关机\n'))
if not ((done == 0) or (done == 1)):
done = 0
# done=int(input('\n结束后如何处理?\n0-退出\n1-关机\n'))
# if not ((done == 0) or (done == 1)):
# done = 0
log.writeinfo('Mode = %d',mode)
log.writeinfo('Emyc = %d',emyc)
log.writeinfo('Postoperation = %d',done)
# log.writeinfo('Emyc = %d',emyc)
# log.writeinfo('Postoperation = %d',done)
except:
mode=0
emyc=0
Expand All @@ -63,17 +63,17 @@ def yuhun():
'''御魂战斗'''
if mode == 0:
# 单刷
fight = single_fight.SingleFight(done, emyc)
fight = single_fight.SingleFight()
fight.start()

if mode == 2:
# 司机
fight = fighter_driver.DriverFighter(mode, done, emyc)
fight = fighter_driver.DriverFighter()
fight.start()

if mode == 3:
# 乘客
fight = fighter_passenger.FighterPassenger(mode, done, emyc)
fight = fighter_passenger.FighterPassenger()
fight.start()

if __name__ == "__main__":
Expand Down
8 changes: 5 additions & 3 deletions single_fight.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
class SingleFight(fighter.Fighter):
'''单人御魂战斗,参数done, emyc'''

def __init__(self, done, emyc):
def __init__(self, done = 1, emyc = 0):
# 初始化
fighter.Fighter.__init__(self, emyc)
fighter.Fighter.__init__(self, '', emyc)

def start(self):
'''单人战斗主循环'''
mood1 = utilities.Mood()
mood2 = utilities.Mood()
mood3 = utilities.Mood()
mood3 = utilities.Mood(3)
while True:
# 在御魂主选单,点击“挑战”按钮, 需要使用“阵容锁定”!
self.yys.wait_game_img('img\\TIAO-ZHAN.png')
Expand All @@ -34,6 +34,8 @@ def start(self):
mood2.moodsleep()

# 在战斗结算页面
self.yys.mouse_click_bg(utilities.firstposition())
mood3.moodsleep()
start_time = time.time()
while time.time() - start_time <= 10:
self.yys.mouse_click_bg(utilities.secondposition())
Expand Down
4 changes: 2 additions & 2 deletions utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def firstposition():
w = 1136
h = 640
while True:
position = (random.randint(0, w), random.randint(0,h))
position = (random.randint(0, w), random.randint(50, h))
if position[0] < 332 or position[0] > 931:
return position
elif position[1] < 350 or position[1] > 462:
Expand All @@ -63,7 +63,7 @@ def secondposition():
w = 1136
h = 640
while True:
position = (random.randint(0, w), random.randint(50,h))
position = (random.randint(0, w), random.randint(50, h-40))
if position[0] < 210 or position[0] > 952:
return position
elif position[1] < 112 or position[1] > 490:
Expand Down

0 comments on commit f2ff308

Please sign in to comment.