-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmap_module.py
More file actions
82 lines (70 loc) · 2.42 KB
/
map_module.py
File metadata and controls
82 lines (70 loc) · 2.42 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
import pyautogui
import re
import config
import time
from mytypes import Position
from bot_controller import Bot
from loguru import logger
import sys
def process_item(item_info: str) -> tuple[list[str], list[str]]:
info = item_info.split("--------")
if not info or len(info) < 3:
return tuple()
mods = [mod for mod in info[-3].strip().split("\n") if not mod.startswith("(")]
implicits = info[1].strip().split("\n")
return mods, implicits
CONST_IMPLICITS = (
"Item Quantity",
"Item Rarity",
"Monster Pack Size",
"More Maps",
"More Scarabs",
"More Currency",
)
def filter_implicits(item_implicits: list[str], expected_implicits: dict) -> bool:
matched = {}
for implicit in CONST_IMPLICITS:
for mod in item_implicits:
r = re.search(rf"{implicit}: \+(\d+)%", mod)
if r:
matched[implicit] = int(r.group(1))
return all(
matched.get(_type, 0) >= value
for _type, value in expected_implicits.items()
if value > 0
)
def filter_mods_by_regex(regex_count: int, mods: list[str], regexes: list[str]) -> bool:
matched = 0
for modtext in mods:
for regex in regexes:
if re.search(regex, modtext):
matched += 1
return matched == regex_count
def craft_map(regexes: list[str], regex_count: int, expected_implicits: dict) -> None:
method_pos: Position | None = config.get_value_as_position("currency", "chaos")
map_pos: Position = Bot.get_global("map-item")
if not method_pos or not map_pos:
logger.info("Method pos or Map pos not set")
return
while not Bot.get_killswitch_state():
item_info: str = Bot.get_item_info(map_pos)
processed = process_item(item_info)
if not processed:
continue
mods: list[str] = processed[0]
implicits: list[str] = processed[1]
if not mods:
logger.info("Could not find processed mods")
return
if filter_mods_by_regex(regex_count, mods, regexes) and filter_implicits(
implicits, expected_implicits
):
logger.info("Regexes matched")
return
pyautogui.moveTo(method_pos.x, method_pos.y)
pyautogui.rightClick()
pyautogui.moveTo(map_pos.x, map_pos.y)
pyautogui.leftClick()
logger.add(
sys.stderr, format="{time} {level} {message}", filter="map_module", level="INFO"
)