0


三国杀钓鱼自动化

三国杀钓鱼脚本

前言

本来是想做必杀的,但是后来测试了大约400钓发现纯靠连点没有漏掉的鱼,所以必杀功能就舍弃了。
我pyinstaller打包后运行.exe居然黑屏了???可能是多进程报错处理没写好,反正还是用vscode运行python吧。这样最起码可以保证不死机。

环境配置

python 3.12.7
Visual Studio Code 任何版本
雷电模拟器9
Win11 23H2

雷电模拟器安装

通过官网

  1. https://www.ldmnq.com

下载。这个没啥好说的,没有网络问题,直接下一步下一步就行了。
说一下问题我运行vivo端的游戏商店或者三国杀时,发现不能使用。最后查阅信息有一个解决方法是将模拟器的手机型号设置为除了vivo以外的任意一款手机型号。

python 安装

通过官网

  1. https://www.python.org/downloads/release/python-3127

找到下面

  1. Windows installer (64-bit)

下载。
链接为

  1. https://www.python.org/ftp/python/3.12.7/python-3.12.7-amd64.exe

,可以点击此处直接下载
之后,安装python,安装步骤这里不是重点。推荐一位bilibili的up主的视频,根据他的安装即可,后面会讲。

Visual Studio Code 安装

通过官网

  1. https://code.visualstudio.com

找到Download for Windows下载即可。
同样安装步骤,后面会讲。

如何安装?

  1. https://www.bilibili.com/video/BV1w7411N7Ti

这个up主的

  1. BV1w7411N7Ti

视频可以很好的讲解。记得Visual Studio Code 需要加插件,别忘了看文档安装一下。

脚本

脚本代码-python

这是一段python代码,复制到文本文件更改后缀名为py,即可运行。也可以继续观看B站up的视频稍微学习一点点怎么运行代码。

  1. from PIL import ImageGrab
  2. import multiprocessing
  3. import pygetwindow
  4. import pyautogui
  5. import keyboard
  6. import numpy
  7. import json
  8. import time
  9. classCustomError(Exception):def__init__(self,message):
  10. self.message=message
  11. classFishing():
  12. standWidth=1962
  13. standHeight=1115def__init__(self,window):
  14. self.window= window
  15. self.left=window.left
  16. self.top=window.top
  17. self.jsonDir="./position.json"
  18. self.config=None
  19. self.GameInit()defWindowJudge(self,window):return(window.width,window.height)==(Fishing.standWidth,Fishing.standHeight)defGameInit(self):ifnot self.WindowJudge(self.window):raise CustomError("window size is not match!")else:
  20. self.config=dict(json.loads(self.__read(self.jsonDir)))defClick(self,position):
  21. pyautogui.click(self.left+position[0],self.top+position[1])defDragTo(self,position,speed):
  22. pyautogui.dragTo(self.left+position[0],self.top+position[1],speed,button="left")def__read(self,file):
  23. f=open(file,'r',encoding="utf-8")
  24. res=f.read()
  25. f.close()return res
  26. defStateFishing(CodeRun):while CodeRun.value:#不可更改!if keyboard.is_pressed('esc'):
  27. CodeRun.value=False
  28. exit(0)defFishingRun(codeRun,runTime,slow,stink,again,queue,queueNumber):
  29. window = pygetwindow.getWindowsWithTitle('雷电模拟器')[0]
  30. fishingGame=Fishing(window)
  31. queueNumber.value=0
  32. queue.put((window.left,window.top))
  33. queue.put(fishingGame.config['slowColor'])
  34. queue.put(fishingGame.config['WatchRange'])
  35. time.sleep(0.1)
  36. queueNumber.value=1
  37. queue.put((window.left,window.top))
  38. queue.put(fishingGame.config['stinkColor'])
  39. queue.put(fishingGame.config['stinkOffset'])
  40. queue.put(fishingGame.config['StinkyRange'])
  41. time.sleep(0.1)
  42. queueNumber.value=2
  43. queue.put((window.left,window.top))
  44. queue.put(fishingGame.config['againColor'])
  45. queue.put(fishingGame.config['AgainRange'])
  46. time.sleep(0.1)
  47. queueNumber.value=3
  48. queue.put((window.left,window.top))
  49. queue.put(fishingGame.config['energyColor'])
  50. queue.put(fishingGame.config['EnergyRange'])
  51. time.sleep(0.1)while runTime>0and codeRun.value:
  52. runTime-=1print("剩余%d次垂钓"%runTime)
  53. time.sleep(0.5)
  54. fishingGame.Click(fishingGame.config['beginButton'])
  55. time.sleep(0.5)
  56. fishingGame.DragTo(fishingGame.config['dragToPosition'],0.3)
  57. time.sleep(5.3)
  58. startTime=time.time()whilenot stink.value and codeRun:if time.time()-startTime>2:break
  59. fishingGame.Click(fishingGame.config['liftingPosition'])
  60. stink.value=Falsewhile codeRun.value:if slow.value :
  61. fishingGame.Click(fishingGame.config['fishingButton'])if again.value:
  62. fishingGame.Click(fishingGame.config['againButton'])break
  63. codeRun.value=False
  64. exit(0)defWatchSpeed(codeRun,slow,queue,queueNumber):while queueNumber.value!=0:pass
  65. window=queue.get()
  66. slowColor=queue.get()
  67. watchRange=queue.get()
  68. left,top=watchRange["position1"]
  69. right,down=watchRange["position2"]while codeRun.value:
  70. screenshot =numpy.array( ImageGrab.grab(bbox=(window[0]+left, window[1]+top, window[0]+right, window[1]+down)))
  71. screenshotShape=screenshot.shape
  72. cnt=0for i inrange(screenshotShape[0]):for j inrange(screenshotShape[1]):
  73. temp=screenshot[i][j]if((int(temp[0])-slowColor[0])**2+(int(temp[1])-slowColor[1])**2+(int(temp[2])-slowColor[2])**2)**0.5>5:
  74. cnt+=1
  75. slow.value= cnt/(screenshotShape[0]*screenshotShape[1])<0.6
  76. exit(0)defWatchStinky(codeRun,stink,queue,queueNumber):while queueNumber.value!=1:pass
  77. window=queue.get()
  78. stinkColor=queue.get()
  79. stinkOffset=queue.get()
  80. watchRange=queue.get()
  81. left,top=watchRange["position1"]
  82. right,down=watchRange["position2"]
  83. top+=stinkOffset
  84. down+=stinkOffset
  85. while codeRun.value:
  86. screenshot =numpy.array( ImageGrab.grab(bbox=(window[0]+left, window[1]+top, window[0]+right, window[1]+down)))
  87. screenshotShape=screenshot.shape
  88. cnt=0for i inrange(screenshotShape[0]):for j inrange(screenshotShape[1]):
  89. temp=screenshot[i][j]if((int(temp[0])-stinkColor[0])**2+(int(temp[1])-stinkColor[1])**2+(int(temp[2])-stinkColor[2])**2)**0.5<50:
  90. cnt+=1
  91. stink.value= cnt/(screenshotShape[0]*screenshotShape[1])>0.1
  92. exit(0)defWatchAgain(codeRun,again,queue,queueNumber):while queueNumber.value!=2:pass
  93. window=queue.get()
  94. againColor=queue.get()
  95. watchRange=queue.get()
  96. left,top=watchRange["position1"]
  97. right,down=watchRange["position2"]while codeRun.value:
  98. screenshot =numpy.array( ImageGrab.grab(bbox=(window[0]+left, window[1]+top, window[0]+right, window[1]+down)))
  99. screenshotShape=screenshot.shape
  100. cnt=0for i inrange(screenshotShape[0]):for j inrange(screenshotShape[1]):
  101. temp=screenshot[i][j]if((int(temp[0])-againColor[0])**2+(int(temp[1])-againColor[1])**2+(int(temp[2])-againColor[2])**2)**0.5<50:
  102. cnt+=1
  103. again.value= cnt/(screenshotShape[0]*screenshotShape[1])>0.8
  104. exit(0)defWatchEnergy(codeRun,energy,queue,queueNumber):while queueNumber.value!=3:pass
  105. window=queue.get()
  106. energyColor=queue.get()
  107. watchRange=queue.get()
  108. left,top=watchRange["position1"]
  109. right,down=watchRange["position2"]while codeRun.value:
  110. screenshot =numpy.array( ImageGrab.grab(bbox=(window[0]+left, window[1]+top, window[0]+right, window[1]+down)))
  111. screenshotShape=screenshot.shape
  112. cnt=0for i inrange(screenshotShape[0]):for j inrange(screenshotShape[1]):
  113. temp=screenshot[i][j]if((int(temp[0])-energyColor[0])**2+(int(temp[1])-energyColor[1])**2+(int(temp[2])-energyColor[2])**2)**0.5<50:
  114. cnt+=1
  115. energy.value= cnt/(screenshotShape[0]*screenshotShape[1])>0.8if __name__ =='__main__':
  116. runTime=999# 运行次数
  117. codeRun = multiprocessing.Value('b',True)
  118. queueNumber = multiprocessing.Value('i',-1)
  119. slow = multiprocessing.Value('b',True)
  120. stink= multiprocessing.Value('b',True)
  121. again= multiprocessing.Value('b',False)
  122. queue=multiprocessing.Queue(20)
  123. processList=[]
  124. processList.append(multiprocessing.Process(target=StateFishing, args=(codeRun,)))
  125. processList.append(multiprocessing.Process(target=FishingRun, args=(codeRun,runTime,slow,stink,again,queue,queueNumber)))
  126. processList.append(multiprocessing.Process(target=WatchSpeed,args=(codeRun,slow,queue,queueNumber)))
  127. processList.append(multiprocessing.Process(target=WatchStinky,args=(codeRun,stink,queue,queueNumber)))
  128. processList.append(multiprocessing.Process(target=WatchAgain,args=(codeRun,again,queue,queueNumber)))for each in processList:
  129. each.start()for each in processList:
  130. each.join()

脚本代码-json

此处需要创建在你的上述python脚本文件的同一目录下,命名为

  1. position.json

,注意扩展名为

  1. json

。此处由于电脑性能不同需要手动调节一下stinkOffset,负号代表检测区间向上方偏移像素。由于本脚本设计原理是通过监控并对进程通信实现的,所以由于电脑性能问题需要平移一定距离以留充足反应。如果刺鱼点太靠上,数值应当由-32适当调大,如果太靠下应当由-32适当调小。防呆小tips:-40比-32小。

  1. {"stinkOffset":-32,"beginButton":[1625,880],"dragToPosition":[1625,630],"liftingPosition":[1625,880],"fishingButton":[1625,880],"againButton":[1420,950],"WatchRange":{"position1":[1195,135],"position2":[1305,140]},"AgainRange":{"position1":[1250,920],"position2":[1290,960]},"StinkyRange":{"position1":[626,530],"position2":[629,600]},"EnergyRange":{"position1":[1366,189],"position2":[1367,209]},"stinkColor":[239,199,107],"slowColor":[99,77,66],"againColor":[255,199,99],"energyColor":[255,170,90]}

安装库

复制下面的命令,在命令框中输入即可自动安装清华镜像下的依赖库。如果不会安装,还是去看一下上文B站up的视频,会有讲解pip指令的教程,这里也只是需要知道在哪里输入就可以了。或者去搜一下别人的文档,只要能确定在那里输入就可以。

  1. pip install -i https://pypi.tuna.tsinghua.edu.cn/simple keyboard pillow pyautogui pygetwindow numpy

说明

  1. 脚本是针对雷电模拟器做的适配,因此最好不要换模拟器,而且甚至版本都不要变。
  2. 窗口分辨率设置为平板版 > 1920x1080(dpi 280)。代码中做了窗口检测,而且需要做到像素匹配。这里代码中像素匹配是1962x1115,设置分辨率后应该就是这个尺寸,不要缩放,如果缩放了,改成其他分辨率后再改回来。
  3. 再runTime中输入此次运行次数,如果不写就会按照我的代码默认参数999次去运行下去了。且换鱼饵是要重开的。
  4. 脚本是模拟鼠标操作,所以不要让任何可能影响点击的操作置于模拟器前,运行脚本时模拟器必须处于显示的状态,而不是最小化。
  5. 可以按下esc退出,如果前10秒左右按下,其他功能会终止,由于代码中的延迟语句的缘故,代码整体会等一会才能终止。10秒左右之后,可以立即终止。
  6. 运行时要先进入开始垂钓的界面中运行脚本。
  7. 本脚本中所有用到的位置信息全部存放在position.json中,可以根据自己的需求进行更改。但是需要注意的是分辨率的更改可能会引起操作、监控位置以及阈值信息的改变,需要手动测试。

By-Round Moon

后继

这个脚本没有对其他电脑做过测试,我的电脑比较好的OMEN,所以运行流畅,但是我的脚本是基于监控信息加进程通信实现的,有可能不同电脑性能不一样导致无法运行,而且刺鱼操作需要调试,但是基本无妨。
另外最近脚本交易盛行,有可能会被他人使用,这里标识一下我的创作日期是2024年10月19日晚22点,为了完成2024年的1024任务所以等到1024当天再发布。本脚本完全开源,欢迎大家交流,且未经本人允许禁止转载。


本文转载自: https://blog.csdn.net/qq_35339563/article/details/143084984
版权归原作者 落雪幻念 所有, 如有侵权,请联系我们删除。

“三国杀钓鱼自动化”的评论:

还没有评论