Merge pull request #19 from SemjonKerner/interaction_jitter

Feature: Add Random Delay to Interactions
This commit is contained in:
Adam Saudagar 2020-12-15 05:36:59 +05:30 committed by GitHub
commit 3bfe7da5ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 2 deletions

View File

@ -16,6 +16,7 @@ import keyboard
from fishy.helper.config import config
import random
class FishEvent:
fishCaught = 0
@ -24,6 +25,7 @@ class FishEvent:
fish_times = []
hole_start_time = 0
FishingStarted = False
jitter = False
previousState = State.IDLE
# initialize these
@ -32,9 +34,17 @@ class FishEvent:
uid = None
sound = False
def _fishing_sleep(waittime, lower_limit_ms = 16, upper_limit_ms = 2500):
reaction = 0.0
if FishEvent.jitter and upper_limit_ms > lower_limit_ms:
reaction = float( random.randrange(lower_limit_ms, upper_limit_ms) )/1000.0
max_wait_t = waittime+reaction if waittime+reaction <= 2.5 else 2.5
time.sleep(max_wait_t)
def init():
subscribe()
FishEvent.jitter = config.get("jitter", False)
FishEvent.action_key = config.get("action_key", 'e')
FishEvent.collect_key = config.get("collect_key", 'r')
FishEvent.collect_allow_auto = config.get("collect_allow_auto", False)
@ -77,9 +87,10 @@ def on_hook():
keyboard.press_and_release(FishEvent.action_key)
if FishEvent.collect_allow_auto:
time.sleep(0.1)
_fishing_sleep(0.1)
keyboard.press_and_release('r')
time.sleep(0.1)
_fishing_sleep(0.1)
_fishing_sleep(0.0)
def on_look():

View File

@ -53,6 +53,7 @@ def start_semifisher_config(gui: 'GUI'):
gui.config.set("collect_key", collect_key_entry.get(), False)
gui.config.set("collect_allow_auto", collect_allow_auto.instate(['selected']), False)
gui.config.set("borderless", borderless.instate(['selected']), False)
gui.config.set("jitter", jitter.instate(['selected']), False)
gui.config.set("sound_notification", sound.instate(['selected']), False)
gui.config.save_config()
@ -107,5 +108,9 @@ def start_semifisher_config(gui: 'GUI'):
sound = Checkbutton(controls_frame, var=BooleanVar(value=config.get("sound_notification")))
sound.grid(row=5, column=1)
Label(controls_frame, text="Human-Like Delay: ").grid(row=6, column=0, pady=(5, 5))
jitter = Checkbutton(controls_frame, var=BooleanVar(value=config.get("jitter")))
jitter.grid(row=6, column=1)
controls_frame.pack(padx=(5, 5), pady=(5, 5))
top.start()