Skip to content

Commit

Permalink
Fixed afk movement and using faster screenshotting library
Browse files Browse the repository at this point in the history
  • Loading branch information
Qfc9 committed Dec 11, 2021
1 parent 8f21be1 commit fb171fb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ Make sure you have a pet Python - https://www.python.org/
Make sure you pip install the following packages
```
pip install PyAutoGUI
pip install PyDirectInput
pip install Pillow
pip install opencv-python
pip install numpy
pip install mss
```

New World must be installed and running..... But you know this already right?
Expand Down
32 changes: 23 additions & 9 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import pyautogui
import pydirectinput
import time
import random
import mss
import numpy as np
from PIL import Image
import gc

def main():
Expand All @@ -15,9 +17,9 @@ def main():
castingRandom = .4

# Base reeling time it will always do
reelingBaseTime = .3
reelingBaseTime = .4
# Max random amount of time to add to the base
reelingRandom = .2
reelingRandom = .4

# Adding randomness to the wait times for the animations
animationSleepTime = .1 + (.1 * random.random())
Expand Down Expand Up @@ -48,9 +50,14 @@ def main():
time.sleep(animationSleepTime)

# Selecting the middle 3rd of the New World Window
region = (newWorldWindow.left + round(newWorldWindow.width/3), newWorldWindow.top, round(newWorldWindow.width/3), newWorldWindow.height)
mssRegion = {"mon": 1, "top": newWorldWindow.top, "left": newWorldWindow.left + round(newWorldWindow.width/3), "width": round(newWorldWindow.width/3), "height": newWorldWindow.height}

# Starting screenshotting object
sct = mss.mss()

while True:
# Screenshot
sctImg = Image.fromarray(np.array(sct.grab(mssRegion)))
# Calculating those times
castingTime = castingBaseTime + (castingRandom * random.random())
reelingTime = reelingBaseTime + (reelingRandom * random.random())
Expand All @@ -62,32 +69,39 @@ def main():
pyautogui.mouseUp()

# Looking for the fish icon, doing forced garbage collection
while pyautogui.locateOnScreen("imgs/fishIcon.png", grayscale=True, confidence=.6, region=region) is None:
while pyautogui.locate("imgs/fishIcon.png", sctImg, grayscale=True, confidence=.6) is None:
gc.collect()
# Screenshot
sctImg = Image.fromarray(np.array(sct.grab(mssRegion)))

# Hooking the fish
print("Fish Hooked")
pyautogui.click()
time.sleep(animationSleepTime)

# Keeps reeling into "HOLD Cast" text shows on screen
while pyautogui.locateOnScreen("imgs/holdCast.png", grayscale=True, confidence=.55, region=region) is None:
while pyautogui.locate("imgs/holdCast.png", sctImg, grayscale=True, confidence=.55) is None:
print("Reeling....")
pyautogui.mouseDown()
time.sleep(reelingTime)
pyautogui.mouseUp()

# Uses a lot of memory if you don't force collection
gc.collect()
# Screenshot
sctImg = Image.fromarray(np.array(sct.grab(mssRegion)))

# Uncomment below if you want more randomness in your reeling rest periods
# time.sleep(animationSleepTime)
# Reel down time
time.sleep(animationSleepTime)

print("Caught Fish")

# 20% chance to move to avoid AFK timer
if random.randint(1, 5) == 5:
pyautogui.press(moveDirection[random.randint(0, 1)])
key = moveDirection[random.randint(0, 1)]
pyautogui.keyDown(key)
time.sleep(.1)
pyautogui.keyUp(key)

time.sleep(animationSleepTime)

Expand Down

0 comments on commit fb171fb

Please sign in to comment.