forked from qlvbrknp/maple-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
97 lines (84 loc) · 2.73 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import time
import random
from rune_solver import find_arrow_directions
from interception import *
from game import Game
from player import Player
def bind(context):
context.set_filter(interception.is_keyboard, interception_filter_key_state.INTERCEPTION_FILTER_KEY_ALL.value)
print("Click any key on your keyboard.")
device = None
while True:
device = context.wait()
if interception.is_keyboard(device):
print(f"Bound to keyboard: {context.get_HWID(device)}.")
c.set_filter(interception.is_keyboard, 0)
break
return device
def solve_rune(g, p, target):
"""
Given the (x, y) location of a rune, the bot will attempt to move the player to the rune and solve it.
"""
while True:
print("Pathing towards rune...")
p.go_to(target)
# Activate the rune.
time.sleep(1)
p.press("SPACE")
# Take a picture of the rune.
time.sleep(1)
img = g.get_rune_image()
print("Attempting to solve rune...")
directions = find_arrow_directions(img)
if len(directions) == 4:
print(f"Directions: {directions}.")
for d, _ in directions:
p.press(d)
# The player dot will be blocking the rune dot, attempt to move left/right to unblock it.
p.hold("LEFT")
time.sleep(random.uniform(0.5, 1.25))
p.release("LEFT")
p.hold("RIGHT")
time.sleep(random.uniform(0.5, 1.25))
p.release("RIGHT")
rune_location = g.get_rune_location()
if rune_location is None:
print("Rune has been solved.")
break
else:
print("Trying again...")
if __name__ == "__main__":
# This setup is required for Interception to mimic your keyboard.
c = interception()
d = bind(c)
# Example Script for Hayato @ SS4.
g = Game((5, 60, 180, 130))
p = Player(c, d, g)
target = (97, 32.5)
while True:
other_location = g.get_other_location()
if other_location > 0:
print("A player has entered your map.")
rune_location = g.get_rune_location()
if rune_location is not None:
print("A rune has appeared.")
solve_rune(g, p, rune_location)
print("Running...")
p.go_to(target)
p.press("Q")
time.sleep(0.5)
p.press("W")
time.sleep(3)
p.go_to(target)
p.press("LEFT")
time.sleep(0.5)
p.hold("E")
time.sleep(0.5)
p.release("E")
p.go_to(target)
p.press("RIGHT")
time.sleep(0.5)
p.hold("E")
time.sleep(0.5)
p.release("E")
time.sleep(3)