-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpAndDown.py
More file actions
219 lines (158 loc) · 5.9 KB
/
UpAndDown.py
File metadata and controls
219 lines (158 loc) · 5.9 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
import Common.WindowOperations as WO
import Common.ImageDetectionOperations as IDO
import Common.MovementOperations as MO
import random
import time
import Common.FileUnpacker as FU
def DecisionController(player, monsters, playerMap):
"""
Controls what decision the player should make
:param target: a tuple (x,y)
:param player: a tuple (x,y)
"""
print('Decision Start')
Movement(playerMap)
if len(monsters) > 0:
Fire(player, monsters)
else:
UpOrDown(playerMap)
print('Decision End')
def UpOrDown(player):
# top level
if player[1] < 95:
MO.DoubleKeyPress('alt', 'down', random.uniform(0.15, 0.3))
# middle Level
if 95 < player[1] < 117:
r = random.randrange(0,2)
if r == 0:
MO.DoubleKeyPress('alt', 'down', random.uniform(0.15, 0.3))
else:
MO.DoubleKeyPress('alt', 'up', random.uniform(0.25, 0.35))
time.sleep(random.uniform(0.07, 0.11))
MO.DoubleKeyPress('alt', 'up', random.uniform(0.15, 0.3))
# Bot Level
if 117 < player[1]:
MO.DoubleKeyPress('alt', 'up', random.uniform(0.15, 0.3))
time.sleep(random.uniform(0.07, 0.11))
MO.DoubleKeyPress('alt', 'up', random.uniform(0.15, 0.3))
time.sleep(random.uniform(1.3, 1.6))
def Movement(player):
"""
Controls the movement of the player
Still needs some work
:param target: a tuple (x,y)
:param player: a tuple (x,y)
"""
print('Move Start')
target = 86
print(player[0])
xDist = abs(player[0] - target)
xTime = (xDist / 294) + 0.1
time.sleep(0.1)
if player[0] - target > 0:
MO.KeyPress('left', xTime)
if player[0] - target < 0:
MO.KeyPress('right', xTime)
print('Move End')
def Fire(player, monster):
"""
Controls the attacking of the player
:param target: a tuple (x,y)
:param player: a tuple (x,y)
"""
direction = 0
for p in monster:
direction += (p[0] - player[0])
print(direction)
print('Fire Start')
if direction < 0:
MO.KeyPress('left', random.uniform(0.08, 0.22))
else:
MO.KeyPress('right', random.uniform(0.08, 0.22))
MO.KeyPress('q', random.uniform(0.15, 0.27))
print('Fire End')
def CheckHealthAndMana(im, x, y):
"""
Will use a mana or health potion if health or mana drops too low
:param im: numpy image
:param x: length of window
:param y: height of window
"""
# two options
# - check for gray pixels in a known location
# - template match for transition between gray and mp / hp
life = im[1154][1010]
mana = im[1170][936]
# low life or low mana
if 90 < life[0] < 120 or 100 < mana[0] < 110 and 95 < mana[1] < 105:
MO.KeyPress('a', random.uniform(0.8, 1.3))
def CheckForRopeStick():
print('stuck on rope')
MO.DoubleKeyPress('left', 'alt', random.uniform(0.2, 0.4))
def main(player, playerClass, map):
"""
Starts the farming loop
:param player: numpy image of the player to be found
:param map: The name of the map the player is on
"""
data, im1, im2 = FU.Unpack(map)
ROI = [data['ROI'][1]['y'], data['ROI'][3]['y1'], data['ROI'][0]['x'], data['ROI'][2]['x1']]
timeKeeping = False
xa, ya, x1a, y1a = WO.GetWindowPos('MapleStory')
count = 0
# height . width
# ROI = [0, 158, 0, 175]
pastPos = (0, 0)
while 1:
a = time.perf_counter()
im, x, y, x1, y1 = WO.GetWindowScreenshot('MapleStory', xa, ya, x1a, y1a)
b = time.perf_counter()
if timeKeeping:
print('Screenshot: ' + str((b - a)))
if im is not None:
a = time.perf_counter()
miniMapRoi = im[ROI[0]:ROI[1], ROI[2]:ROI[3]]
monsterLoc, w, h = IDO.LocateTemplate(im, 'Resources/Maps/DarkEreve/Bird.png', 0.75, True, 150)
monsterLocFlip, w, h = IDO.LocateTemplate(im, 'Resources/Maps/DarkEreve/BirdFlip.png', 0.75, True, 150)
playerMap, w1, h1 = IDO.LocateTemplate(miniMapRoi, 'Resources/Player/MapIcon.png', 0.8, False)
playerLoc, w1, h1 = IDO.LocateTemplate(im, 'Resources/Player/TryKillBoss.png', 0.8, False)
b = time.perf_counter()
if timeKeeping:
print('Template Match: ' + str((b - a)))
for cords in monsterLocFlip:
monsterLoc.append(cords)
if len(monsterLoc) > 0:
img = IDO.DrawImages(im, monsterLoc, w, h)
if playerLoc and len(monsterLoc) > 0:
playerLocList = [playerLoc] # Todo: Fix this - create a player list because of how code elsewhere works
img = IDO.DrawImages(img, playerLocList, w1, h1)
monsters = []
if playerLoc:
# find closest baddie
for i, pts in enumerate(monsterLoc):
if pts[1] - 100 < playerLoc[1] < pts[1] + 100:
monsters.append(pts)
img = IDO.DrawLines(img, playerLoc, monsterLoc)
IDO.DisplayImage(img, 'resize', 800, 600)
DecisionController(playerLoc, monsters, playerMap)
CheckHealthAndMana(im, x - x1, y - y1)
if pastPos == playerLoc:
CheckForRopeStick()
count += 1
# Cool down skill One
if count % 40 == 0:
MO.KeyPress('e', random.uniform(0.13, 0.21))
# Buff skills macro
if count % 80 == 0:
MO.KeyPress('r', random.uniform(0.13, 0.21))
time.sleep(2)
# Big cooldown
if count % 75 == 0:
MO.KeyPress('2', random.uniform(0.13, 0.21))
if count % 130 == 0:
MO.KeyPress('3', random.uniform(0.13, 0.21))
if count % 140 == 0:
MO.KeyPress('1', random.uniform(0.13, 0.21))
pastPos = playerLoc
if __name__ == '__main__':
main()