diff --git a/config/filter_aspects.yaml b/config/filter_aspects.yaml index 4de1f0eb..9146c83f 100644 --- a/config/filter_aspects.yaml +++ b/config/filter_aspects.yaml @@ -6,7 +6,7 @@ Aspects: # General - [accelerating_aspect, 24] - [aspect_of_might, 5.5] - - [aspect_of_disobedience, 1.1] + - [aspect_of_disobedience, 0.9] - [aspect_of_inner_calm, 10] - [aspect_of_retribution, 20] - [aspect_of_the_expectant, 10] diff --git a/src/cam.py b/src/cam.py index b47b052e..4688642f 100644 --- a/src/cam.py +++ b/src/cam.py @@ -97,4 +97,5 @@ def window_to_abs_window(self, window_coord: np.ndarray) -> np.ndarray: @convert_args_to_numpy def abs_window_to_monitor(self, abs_window_coord: np.ndarray) -> np.ndarray: - return self.window_to_monitor(self.abs_window_to_window(abs_window_coord)) + window_coord = self.abs_window_to_window(abs_window_coord) + return self.window_to_monitor(window_coord) diff --git a/src/loot_filter.py b/src/loot_filter.py index 5cc095db..51c0e12f 100644 --- a/src/loot_filter.py +++ b/src/loot_filter.py @@ -81,12 +81,12 @@ def run_loot_filter(): for i in range(check_tabs): chest.switch_to_tab(i) check_items(chest) - elif not inv.is_open(): - inv.open() - if not inv.is_open(): - screenshot("inventory_not_open", img=Cam().grab()) - Logger.error("Inventory did not open up") - return - check_items(inv) + check_items(inv) + else: + if not inv.open(): + screenshot("inventory_not_open", img=Cam().grab()) + Logger.error("Inventory did not open up") + return + check_items(inv) mouse.move(*Cam().abs_window_to_monitor((0, 0))) Logger().info("Loot Filter done") diff --git a/src/overlay.py b/src/overlay.py index 173b6c0b..4a219f06 100644 --- a/src/overlay.py +++ b/src/overlay.py @@ -8,6 +8,7 @@ import logging from scripts.rogue_tb import run_rogue_tb from config import Config +from cam import Cam class ListboxHandler(logging.Handler): @@ -41,9 +42,11 @@ def __init__(self): self.maximized_height = int(self.initial_height * 3.4) self.maximized_width = int(self.initial_width * 5) + self.screen_off_x = Cam().window_roi["left"] + self.screen_off_y = Cam().window_roi["top"] self.canvas = tk.Canvas(self.root, bg="black", height=self.initial_height, width=self.initial_width, highlightthickness=0) self.root.geometry( - f"{self.initial_width}x{self.initial_height}+{self.screen_width//2 - self.initial_width//2}+{self.screen_height - self.initial_height}" + f"{self.initial_width}x{self.initial_height}+{self.screen_width//2 - self.initial_width//2 + self.screen_off_x}+{self.screen_height - self.initial_height + self.screen_off_y}" ) self.canvas.pack() @@ -110,12 +113,12 @@ def toggle_size(self): if not self.is_minimized: self.canvas.config(height=self.initial_height, width=self.initial_width) self.root.geometry( - f"{self.initial_width}x{self.initial_height}+{self.screen_width//2 - self.initial_width//2}+{self.screen_height - self.initial_height}" + f"{self.initial_width}x{self.initial_height}+{self.screen_width//2 - self.initial_width//2 + self.screen_off_x}+{self.screen_height - self.initial_height + self.screen_off_y}" ) else: self.canvas.config(height=self.maximized_height, width=self.maximized_width) self.root.geometry( - f"{self.maximized_width}x{self.maximized_height}+{self.screen_width//2 - self.maximized_width//2}+{self.screen_height - self.maximized_height}" + f"{self.maximized_width}x{self.maximized_height}+{self.screen_width//2 - self.maximized_width//2 + self.screen_off_x}+{self.screen_height - self.maximized_height + self.screen_off_y}" ) self.is_minimized = not self.is_minimized move_window_to_foreground() diff --git a/src/ui/inventory_base.py b/src/ui/inventory_base.py index f927d695..2ade8921 100644 --- a/src/ui/inventory_base.py +++ b/src/ui/inventory_base.py @@ -49,8 +49,8 @@ def get_item_slots(self, img: Optional[np.ndarray] = None) -> tuple[list[ItemSlo for _, slot_roi in enumerate(grid): slot_img = crop(img, slot_roi) hsv_image = cv2.cvtColor(slot_img, cv2.COLOR_BGR2HSV) - mean_value_of_high = np.mean(hsv_image[:, :, 2]) - if mean_value_of_high > 53: + mean_value = np.mean(hsv_image[:, :, 2]) + if mean_value > 37: occupied_slots.append(ItemSlot(bounding_box=slot_roi, center=get_center(slot_roi))) else: empty_slots.append(ItemSlot(bounding_box=slot_roi, center=get_center(slot_roi))) diff --git a/src/utils/window.py b/src/utils/window.py index 644e1cd3..e4b79653 100644 --- a/src/utils/window.py +++ b/src/utils/window.py @@ -78,8 +78,8 @@ def detect_window(window_spec: WindowSpec = D4_WINDOW): def find_and_set_window_position(window_spec: WindowSpec = D4_WINDOW): hwnd = get_window_spec_id(window_spec) if hwnd is not None: - position = GetWindowRect(hwnd) - Cam().update_window_pos(*position) + pos = GetWindowRect(hwnd) + Cam().update_window_pos(pos[0], pos[1], pos[2] - pos[0], pos[3] - pos[1]) wait(0.5) diff --git a/test/smoke_test.py b/test/smoke_test.py new file mode 100644 index 00000000..8085ebf0 --- /dev/null +++ b/test/smoke_test.py @@ -0,0 +1,30 @@ +import cv2 +import time +from item.find_descr import find_descr +from item.read_descr import read_descr +from item.filter import should_keep +from item.data.rarity import ItemRarity +from cam import Cam +from config import Config +from template_finder import stored_templates + + +def test_smoke(): + res = (2560, 1440) + anchor = (1723, 1012) + Cam().update_window_pos(0, 0, *res) + Config().load_data() + stored_templates.cache_clear() + img = cv2.imread("test/assets/item/find_descr_legendary_2560x1440_2_inv.png") + start = time.time() + found, _, rarity, cropped_descr = find_descr(img, anchor) + print("Runtime (detect): ", time.time() - start) + assert found + if rarity == ItemRarity.Unique: + return + if rarity in [ItemRarity.Common, ItemRarity.Magic]: + return + item_descr = read_descr(rarity, cropped_descr) + assert item_descr is not None + keep = should_keep(item_descr) + print("Runtime (full): ", time.time() - start, keep)