forked from zxcvqwerasdf/TFT-OCR-BOT
-
Notifications
You must be signed in to change notification settings - Fork 2
/
game_functions.py
131 lines (108 loc) · 4.18 KB
/
game_functions.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
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
"""
Functions used by the Game class to retrieve relevant data
"""
from time import sleep
from random import randint
from PIL import ImageGrab
import game_assets
import mk_functions
import ocr
import screen_coords
def get_round() -> list[str, int]:
"""Gets the current game round"""
screen_capture = ImageGrab.grab(bbox=screen_coords.ROUND_POS.get_coords())
round_three = screen_capture.crop(screen_coords.ROUND_POS_THREE.get_coords())
game_round: str = ocr.get_text_from_image(image=round_three, whitelist=ocr.ROUND_WHITELIST)
if game_round in game_assets.ROUNDS:
return [game_round, 3]
round_two = screen_capture.crop(screen_coords.ROUND_POS_TWO.get_coords())
game_round: str = ocr.get_text_from_image(
image=round_two, whitelist=ocr.ROUND_WHITELIST
)
if game_round in game_assets.ROUNDS:
return [game_round, 2]
round_one = screen_capture.crop(screen_coords.ROUND_POS_ONE.get_coords())
game_round: str = ocr.get_text_from_image(
image=round_one, whitelist=ocr.ROUND_WHITELIST
)
if game_round in game_assets.ROUNDS:
return [game_round, 1]
return ["999-999",0]
def check_encounter_round() -> list[str]:
"""Get the game round list by checking round text for encounter add rounds"""
round_list: list = []
for positions in screen_coords.ROUND_ENCOUNTER_ICON_POS:
mk_functions.move_mouse(positions[0].get_coords())
round_message: str = ocr.get_text(
screenxy=positions[1].get_coords(),
scale=3,
psm=7,
whitelist=(ocr.ALPHABET_WHITELIST + " "),
)
if any(keyword in round_message for keyword in ["Carousel"]):
round_list.append("carousel")
elif any(keyword in round_message for keyword in ["Get pulled into an Encounter"]):
round_list.append("encounter")
elif any(keyword in round_message for keyword in ["Krugs", "Murk Wolves", "Raptors", "Elder Dragon"]):
round_list.append("pve")
else:
round_list.append("pvp")
mk_functions.move_mouse(screen_coords.DEFAULT_LOC.get_coords())
return round_list
def pickup_items() -> (
None
): # Refacor this function to make it more clear whats happening
"""Picks up items from the board after PVP round"""
for index, coords in enumerate(screen_coords.ITEM_PICKUP_LOC):
mk_functions.right_click(coords.get_coords())
if index == 7: # Don't need to sleep on final click
return
if index == 0:
sleep(1.2)
if index % 2 == 0:
sleep(2.0)
else:
sleep(1.2)
def get_champ_carousel(tft_round: str) -> None:
"""Gets a champion from the carousel"""
# carousel_coords = randint(0, 2)
while tft_round == get_round()[0]:
mk_functions.right_click(screen_coords.CAROUSEL_LOC[randint(0, 2)].get_coords())
sleep(3.7)
sleep(3)
def check_alive() -> bool: # Refactor this function to use API
"""Checks the screen to see if player is still alive"""
if (
ocr.get_text(screenxy=screen_coords.EXIT_NOW_POS.get_coords(), scale=3, psm=7)
== "EXIT NOW"
):
return False
return (
ocr.get_text(screenxy=screen_coords.VICTORY_POS.get_coords(), scale=3, psm=7)
!= "CONTINUE"
)
def exit_game() -> None:
"""Exits the game"""
mk_functions.left_click(screen_coords.EXIT_NOW_LOC.get_coords())
mk_functions.left_click(screen_coords.EXIT_NOW_LOC.get_coords())
sleep(8)
def default_pos() -> None:
"""Moves the mouse to a default position to ensure no data is being blocked from OCR"""
mk_functions.left_click(screen_coords.DEFAULT_LOC.get_coords())
def forfeit() -> None:
"""Forfeits the game"""
mk_functions.press_enter()
sleep(0.2)
mk_functions.press_slash()
sleep(0.2)
mk_functions.press_f()
sleep(0.2)
mk_functions.press_f()
sleep(0.2)
mk_functions.press_enter()
sleep(0.1)
mk_functions.left_click(screen_coords.SURRENDER_TWO_LOC.get_coords())
sleep(1)
def default_tactician_pos() -> None:
"""Moves the mouse to the default tactician position"""
mk_functions.right_click(screen_coords.DEFAULT_TACTICIAN_LOC.get_coords())