[英]Trying to fix a script for a game I play (Wizard101 Auto Farming)
I've been trying to tailor this code to work for my desktop so I can auto-farm some enemies in this game I play.我一直在尝试调整这段代码以适用于我的桌面,这样我就可以在我玩的这个游戏中自动种植一些敌人。 Right now the code is stuck at a point where it scans the UI at a certain pixel for a certain shade of blue.现在,代码卡在某个点上,它在某个像素处扫描 UI 以获得某种蓝色阴影。 if it's the correct shade, the code progresses.如果它是正确的阴影,则代码会继续。 if not, it completely stops.如果没有,它会完全停止。 I'm not sure what to do but if someone could take a look I'd greatly appreciate it.我不知道该怎么做,但如果有人可以看一看,我将不胜感激。 Here are some screenshots and the code:下面是一些截图和代码:
Also, the code is broken into two pieces: the first script which allows for interaction with the game, and the second being programming automatic movement, clicking etcetera.此外,代码分为两部分:第一个脚本允许与游戏进行交互,第二个是编写自动移动、单击等。 the second piece is simple enough where it doesn't need to be put here, nor is it necessary.第二块很简单,不需要放在这里,也没有必要。
First Piece (main problem is in the POSITION and COLOR part of def is_mana_low: First Piece(主要问题在于 def is_mana_low 的 POSITION 和 COLOR 部分:
def is_mana_low(self):
self.set_active()
# Matches a pixel in the lower third of the mana globe
POSITION = (79, 565)
COLOR = (66, 13, 83)
THRESHOLD = 10
return not self.pixel_matches_color(POSITION, COLOR, threshold=THRESHOLD)
def use_potion_if_needed(self):
mana_low = self.is_mana_low()
health_low = self.is_health_low()
if mana_low:
print('Mana is low, using potion')
if health_low:
print('Health is low, using potion')
if mana_low or health_low:
self.click(160, 590, delay=.2)
My Discord is APieceofString#5151 if you wanted to hit me up for more information or a better explanation.我的 Discord 是 APieceofString#5151,如果您想联系我以获取更多信息或更好的解释。 I really appreciate this :)我真的很感激这个:)
I had the same issue when setting it to a specific x,y coordinate.将其设置为特定的 x,y 坐标时,我遇到了同样的问题。 So here's how I resolved this:所以这就是我解决这个问题的方法:
I used pyautogui and cv2.我使用了 pyautogui 和 cv2。 I got a screen cap, and then created a fairly thin rectangle, right below where the yellow number showing your remaining mana is, and going from the edge of the Energy globe to the edge of the mana globe.我得到了一个屏幕帽,然后创建了一个相当薄的矩形,就在显示剩余法力值的黄色数字的正下方,从能量球的边缘到法力球的边缘。 And then while my script is running, it checks for a match of that rectangle.然后当我的脚本运行时,它会检查那个矩形的匹配。 If there's a match, you have plenty of mana, if not, you may want to drink a potion.如果有比赛,你有足够的法力,如果没有,你可能想喝一瓶药水。
I tried to do the same thing to check for mana wisps, and if it sees one on the screen, run to the wisp, and then back to the home position (but that function is kind of hinky atm and I'm trying to get it working better).我尝试做同样的事情来检查法力小火,如果它在屏幕上看到一个,跑到小火,然后回到原位(但那个功能有点像 hinky atm,我试图得到它工作得更好)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.