import random
from operator import itemgetter
from time import time
import cv2 as cv
from hsvfilter import HsvFilter
import pydirectinput
from utils import dig_point
from game_base_class import GameBase
from window_capture import WindowCapture

EMITTER_MAIN = "main"
EMITTER_MUSH = "mushroom"
EMITTER_AMU = "amulett"
EMITTER_SWORD = "sword"
EMITTER_STAFF = "staff"
EMITTER_WAND = "wand"
EMITTER_RING = "ring"
EMITTER_MULTI = "multi"

HSV_DEFAULT = HsvFilter(0, 0, 0, 179, 255, 255, 0, 0, 0, 0)


class Equipment(GameBase):

    def __init__(self, overlay):
        super().__init__(overlay)

        self.needles = []
        self.hsvs = []
        self.tresholds = []
        self.masks = []
        self.emitters = []

        # initialize the StunWindowCapture class
        self.capture_window = WindowCapture(None, "equip", self.config)

        self.EMITTER_TO_USE = str(overlay.emitter_use.get())
        self.SPAWN_COUNT = int(overlay.spawn_use.get())
        self.ENERGY_TO_USE = int(overlay.energy_use.get())

        if self.EMITTER_TO_USE == EMITTER_MULTI:
            self.emitters.append(EMITTER_RING)
            self.emitters.append(EMITTER_WAND)
            self.emitters.append(EMITTER_SWORD)
            self.emitters.append(EMITTER_AMU)
            self.emitters.append(EMITTER_STAFF)
        else:
            self.emitters.append(self.EMITTER_TO_USE)

        for emitter in self.emitters:
            if emitter == EMITTER_MUSH:
                self.include_books()
                self.include_mushs()
                self.include_pots()
                self.include_bags()
            elif emitter == EMITTER_AMU:
                self.include_books()
                self.include_amus()
                self.include_bags()
            elif emitter == EMITTER_MAIN:
                self.include_books()
                self.include_chests()
                self.include_keys()
                self.include_pots()
                self.include_bags()
                self.include_coins()
                self.include_runes()
            elif emitter == EMITTER_SWORD:
                self.include_books()
                self.include_swords()
                self.include_bags()
            elif emitter == EMITTER_STAFF:
                self.include_books()
                self.include_staffs()
                self.include_bags()
            elif emitter == EMITTER_RING:
                self.include_books()
                self.include_rings()
                self.include_bags()
            elif emitter == EMITTER_WAND:
                self.include_books()
                self.include_wands()
                self.include_bags()

        self.c_needle = cv.imread("equip/chests/chest_4_32.jpg", cv.IMREAD_UNCHANGED)
        self.c_mask = cv.imread("equip/chests/chest_4_32-mask.png", cv.IMREAD_COLOR)
        self.k_needle = cv.imread("equip/keys/key_4_32.jpg", cv.IMREAD_UNCHANGED)
        self.k_mask = cv.imread("equip/keys/key_4_32-mask.png", cv.IMREAD_COLOR)
        self.dig_button = cv.imread("dig/ok_button.jpg", cv.IMREAD_UNCHANGED)

        self.energy_counter = 0

    def execute_main_loop(self):
        for emitter in self.emitters:
            while True:
                if self.overlay.run_mode == 'paused':
                    cv.waitKey(1)
                    continue
                elif self.overlay.run_mode == 'stopped':
                    break

                # get an updated image of the game
                screenshot = self.capture_window.get_screenshot()

                # cv.imshow("screenshot", screenshot)
                # cv.waitKey(150)
                # continue
                if self.energy_counter >= self.ENERGY_TO_USE:
                    self.energy_counter = 0
                    break

                spawn_1 = self.find_emitter(emitter, screenshot, 1)
                if len(spawn_1) == 1:
                    points = self.vision_stun.get_click_points(spawn_1)
                    for i in range(0, self.SPAWN_COUNT, 1):
                        self.click_point(points[0][0], points[0][1])
                        self.energy_counter = self.energy_counter + 1
                        self.overlay.update_status_label(emitter + ": " + str(self.ENERGY_TO_USE - self.energy_counter))
                        if self.overlay.run_mode == 'stopped' or self.overlay.run_mode == 'paused':
                            break
                else:
                    spawn_0 = self.find_emitter(emitter, screenshot, 0)
                    points = self.vision_stun.get_click_points(spawn_0)
                    for point in points:
                        self.click_point(points[0][0], points[0][1])

                        if self.overlay.run_mode == 'stopped' or self.overlay.run_mode == 'paused':
                            break
                    continue

                cv.waitKey(500)

                if emitter == EMITTER_MAIN:
                    while True:
                        screenshot = self.capture_window.get_screenshot()
                        c_rectangles = self.vision_stun.find(screenshot, self.c_needle, 0.95, 1, True, self.c_mask)
                        k_rectangles = self.vision_stun.find(screenshot, self.k_needle, 0.95, 1, True, self.k_mask)
                        if (len(c_rectangles) == 1) and (len(k_rectangles) == 1):
                            c_point = self.vision_stun.get_click_points(c_rectangles)[0]
                            k_point = self.vision_stun.get_click_points(k_rectangles)[0]
                            self.move_tile(k_point, c_point)
                        else:
                            break

                for rer in range(0, len(self.needles), 1):
                    loop_time = time()
                    while True:
                        if (time() - loop_time) >= 60:
                            break
                        screenshot = self.capture_window.get_screenshot_by_area(self.config.returnOKWindowPos())
                        rectangles = self.vision_stun.find(screenshot, self.dig_button, 0.5, 1)
                        if len(rectangles) == 1:
                            pointis = self.vision_stun.get_click_points(rectangles)
                            for pointi in pointis:
                                dig_point(pointi[0] + self.config.returnOKWindowPos()[2],
                                          pointi[1] + self.config.returnOKWindowPos()[3], 150)
                                cv.waitKey(60000)
                                continue
                        # do object detection
                        screenshot = self.capture_window.get_screenshot()
                        # processed_screenshot = self.vision_stun.apply_hsv_filter(screenshot, self.hsvs[rer])
                        # processed_needle = self.vision_stun.apply_hsv_filter(self.needles[rer], self.hsvs[rer])

                        rectangles = self.vision_stun.find_by_mask_and_validate(screenshot, self.needles[rer],
                                                                                self.masks[rer], 5)
                        # draw the detection results onto the original image
                        # output_image = self.vision_stun.draw_rectangles(screenshot, rectangles)
                        # cv.imshow("output_image", output_image)
                        # cv.waitKey(150)

                        if len(rectangles) is not 5:
                            break
                        if self.overlay.run_mode == 'stopped' or self.overlay.run_mode == 'paused':
                            break

                        # sort rectangles by top
                        rectangles = sorted(rectangles, key=itemgetter(1))

                        points = self.vision_stun.get_click_points(rectangles)

                        move_breaker = self.check_and_move_tile([70, 70, rectangles[0][0] + 70, rectangles[0][1]],
                                                                self.needles[rer],
                                                                points[1], [points[0][0] + 70, points[0][1]])
                        if move_breaker:
                            break
                        if self.overlay.run_mode == 'stopped' or self.overlay.run_mode == 'paused':
                            break
                        move_breaker = self.check_and_move_tile([70, 70, rectangles[0][0], rectangles[0][1] + 70],
                                                                self.needles[rer],
                                                                points[2], [points[0][0], points[0][1] + 70])
                        if move_breaker:
                            break
                        if self.overlay.run_mode == 'stopped' or self.overlay.run_mode == 'paused':
                            break
                        move_breaker = self.check_and_move_tile([70, 70, rectangles[0][0] + 70, rectangles[0][1] + 70],
                                                                self.needles[rer],
                                                                points[3], [points[0][0] + 70, points[0][1] + 70])
                        if move_breaker:
                            break
                        self.move_tile(points[4], [points[0][0], points[0][1]])
                        if self.overlay.run_mode == 'stopped' or self.overlay.run_mode == 'paused':
                            break
                    if self.overlay.run_mode == 'stopped' or self.overlay.run_mode == 'paused':
                        break
                cv.waitKey(150)
                if self.overlay.run_mode == 'stopped':
                    break
            if self.overlay.run_mode == 'stopped':
                break
        self.overlay.run_mode = 'finished'

    def check_and_move_tile(self, rect, needl, point_source, point_dest):
        screenshot_p = self.capture_window.get_screenshot()
        screenshot_p_w = screenshot_p.shape[1]
        screenshot_p_h = screenshot_p.shape[0]
        w = rect[0]
        h = rect[1]
        x = rect[2]
        y = rect[3]
        if h >= screenshot_p_h or w >= screenshot_p_w:
            return True

        screenshot_pos = screenshot_p[y:y + h, x:x + w]  # (w, h, x+w, y+h)
        # processed_screenshot = visio.apply_hsv_filter(screenshot_pos, hsv)
        # processed_needle = visio.apply_hsv_filter(needl, hsv)
        result2 = cv.matchTemplate(screenshot_pos, needl, cv.TM_CCOEFF_NORMED)
        _min_val2, _max_val2, min_loc2, max_loc2 = cv.minMaxLoc(result2, None)
        # rectangles2 = visio.find(screenshot_pos, needl, tresh, 1, True, mask)
        # output_by_area = self.vision_stun.draw_rectangles(screenshot_pos2, rectangles)
        # cv.imshow("output_image_by_area", screenshot_pos)
        # cv.waitKey(150)
        # print("thresh in movecheck:" + str(_maxVal2))
        if _max_val2 <= 0.9:
            self.move_tile(point_source, point_dest)

        return False

    def click_point(self, x, y):
        offset_left = self.config.returnEquipmentWindowPos()[2]
        offset_down = self.config.returnEquipmentWindowPos()[3]
        pydirectinput.moveTo(x + offset_left, y + offset_down)
        pydirectinput.mouseDown()
        w = random.randint(1, 50)
        cv.waitKey(30 + w)
        pydirectinput.mouseUp()

    def move_tile(self, point_source, point_dest):
        offset_left = self.config.returnEquipmentWindowPos()[2]
        offset_down = self.config.returnEquipmentWindowPos()[3]
        pydirectinput.moveTo(point_source[0] + offset_left, point_source[1] + offset_down)
        pydirectinput.mouseDown()
        w = random.randint(25, 50)
        cv.waitKey(100 + w)
        pydirectinput.moveTo(point_dest[0] + offset_left, point_dest[1] + offset_down)
        pydirectinput.mouseUp()
        cv.waitKey(400 + w)

    def find_emitter(self, emitter_to_use, screen, layer):
        if self.EMITTER_TO_USE == EMITTER_MUSH:
            if layer == 0:
                needle = cv.imread("equip/emitters/mush_e_32.jpg", cv.IMREAD_UNCHANGED)
                mask = cv.imread("equip/emitters/mush_e_32-mask.png", cv.IMREAD_COLOR)
                return self.vision_stun.find(screen, needle, 0.95, 1, True, mask)
            else:
                needle = cv.imread("equip/emitters/mush_e2_32.jpg", cv.IMREAD_UNCHANGED)
                mask = cv.imread("equip/emitters/mush_e2_32-mask.png", cv.IMREAD_COLOR)
                return self.vision_stun.find(screen, needle, 0.98, 1, True, mask)
        elif emitter_to_use == EMITTER_AMU:
            if layer == 0:
                needle = cv.imread("equip/emitters/amu_e_32.jpg", cv.IMREAD_UNCHANGED)
                mask = cv.imread("equip/emitters/amu_e_32-mask.png", cv.IMREAD_COLOR)
                return self.vision_stun.find(screen, needle, 0.95, 1, True, mask)
            else:
                needle = cv.imread("equip/emitters/amu_e2_32.jpg", cv.IMREAD_UNCHANGED)
                mask = cv.imread("equip/emitters/amu_e2_32-mask.png", cv.IMREAD_COLOR)
                return self.vision_stun.find(screen, needle, 0.95, 1, True, mask)
        elif emitter_to_use == EMITTER_MAIN:
            if layer == 0:
                needle = cv.imread("equip/emitters/main_e1_32.jpg", cv.IMREAD_UNCHANGED)
                mask = cv.imread("equip/emitters/main_e1_32-mask.png", cv.IMREAD_COLOR)
                return self.vision_stun.find(screen, needle, 0.95, 1, True, mask)
            else:
                needle = cv.imread("equip/emitters/main_e2_32.jpg", cv.IMREAD_UNCHANGED)
                mask = cv.imread("equip/emitters/main_e2_32-mask.png", cv.IMREAD_COLOR)
                return self.vision_stun.find(screen, needle, 0.95, 1, True, mask)
        elif emitter_to_use == EMITTER_SWORD:
            if layer == 0:
                needle = cv.imread("equip/emitters/sword_e1_32.jpg", cv.IMREAD_UNCHANGED)
                mask = cv.imread("equip/emitters/sword_e1_32-mask.png", cv.IMREAD_COLOR)
                return self.vision_stun.find(screen, needle, 0.95, 1, True, mask)
            else:
                needle = cv.imread("equip/emitters/sword_e2_32.jpg", cv.IMREAD_UNCHANGED)
                mask = cv.imread("equip/emitters/sword_e2_32-mask.png", cv.IMREAD_COLOR)
                return self.vision_stun.find(screen, needle, 0.98, 1, True, mask)
        elif emitter_to_use == EMITTER_STAFF:
            if layer == 0:
                needle = cv.imread("equip/emitters/staff_e1_32.jpg", cv.IMREAD_UNCHANGED)
                mask = cv.imread("equip/emitters/staff_e1_32-mask.png", cv.IMREAD_COLOR)
                return self.vision_stun.find(screen, needle, 0.95, 1, True, mask)
            else:
                needle = cv.imread("equip/emitters/staff_e2_32.jpg", cv.IMREAD_UNCHANGED)
                mask = cv.imread("equip/emitters/staff_e2_32-mask.png", cv.IMREAD_COLOR)
                return self.vision_stun.find(screen, needle, 0.99, 1, True, mask)
        elif emitter_to_use == EMITTER_RING:
            if layer == 0:
                needle = cv.imread("equip/emitters/ring_e1_32.jpg", cv.IMREAD_UNCHANGED)
                mask = cv.imread("equip/emitters/ring_e1_32-mask.png", cv.IMREAD_COLOR)
                return self.vision_stun.find(screen, needle, 0.95, 1, True, mask)
            else:
                needle = cv.imread("equip/emitters/ring_e2_32.jpg", cv.IMREAD_UNCHANGED)
                mask = cv.imread("equip/emitters/ring_e2_32-mask.png", cv.IMREAD_COLOR)
                return self.vision_stun.find(screen, needle, 0.95, 1, True, mask)
        elif emitter_to_use == EMITTER_WAND:
            if layer == 0:
                needle = cv.imread("equip/emitters/wand_e1_32.jpg", cv.IMREAD_UNCHANGED)
                mask = cv.imread("equip/emitters/wand_e1_32-mask.png", cv.IMREAD_COLOR)
                return self.vision_stun.find(screen, needle, 0.95, 1, True, mask)
            else:
                needle = cv.imread("equip/emitters/wand_e2_32.jpg", cv.IMREAD_UNCHANGED)
                mask = cv.imread("equip/emitters/wand_e2_32-mask.png", cv.IMREAD_COLOR)
                return self.vision_stun.find(screen, needle, 0.96, 1, True, mask)

    def include_chests(self):
        self.needles.append(cv.imread("equip/chests/chest_1_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.95)
        self.masks.append(cv.imread("equip/chests/chest_1_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/chests/chest_2_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.95)
        self.masks.append(cv.imread("equip/chests/chest_2_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/chests/chest_3_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.91)
        self.masks.append(cv.imread("equip/chests/chest_3_32-mask.png", cv.IMREAD_COLOR))

    def include_books(self):
        self.needles.append(cv.imread("equip/books/book_1_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.91)
        self.masks.append(cv.imread("equip/books/book_1_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/books/book_2_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.9)
        self.masks.append(cv.imread("equip/books/book_2_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/books/book_3_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.87)
        self.masks.append(cv.imread("equip/books/book_3_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/books/book_4_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.93)
        self.masks.append(cv.imread("equip/books/book_4_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/books/book_5_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.91)
        self.masks.append(cv.imread("equip/books/book_5_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/books/book_6_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.9)
        self.masks.append(cv.imread("equip/books/book_6_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/books/book_7_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.91)
        self.masks.append(cv.imread("equip/books/book_7_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/books/book_8_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.91)
        self.masks.append(cv.imread("equip/books/book_8_32-mask.png", cv.IMREAD_COLOR))

    def include_keys(self):
        self.needles.append(cv.imread("equip/keys/key_1_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.91)
        self.masks.append(cv.imread("equip/keys/key_1_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/keys/key_2_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.91)
        self.masks.append(cv.imread("equip/keys/key_2_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/keys/key_3_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.91)
        self.masks.append(cv.imread("equip/keys/key_3_32-mask.png", cv.IMREAD_COLOR))

    def include_pots(self):
        self.needles.append(cv.imread("equip/pots/pot_1_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.91)
        self.masks.append(cv.imread("equip/pots/pot_1_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/pots/pot_2_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.91)
        self.masks.append(cv.imread("equip/pots/pot_2_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/pots/pot_3_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.94)
        self.masks.append(cv.imread("equip/pots/pot_3_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/pots/pot_4_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.91)
        self.masks.append(cv.imread("equip/pots/pot_4_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/pots/pot_5_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.91)
        self.masks.append(cv.imread("equip/pots/pot_5_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/pots/pot_6_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.91)
        self.masks.append(cv.imread("equip/pots/pot_6_32-mask.png", cv.IMREAD_COLOR))

    def include_bags(self):
        self.needles.append(cv.imread("equip/bags/bag_1_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.91)
        self.masks.append(cv.imread("equip/bags/bag_1_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/bags/bag_2_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.88)
        self.masks.append(cv.imread("equip/bags/bag_2_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/bags/bag_3_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.91)
        self.masks.append(cv.imread("equip/bags/bag_3_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/bags/bag_4_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.91)
        self.masks.append(cv.imread("equip/bags/bag_4_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/bags/bag_5_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.91)
        self.masks.append(cv.imread("equip/bags/bag_5_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/bags/bag_6_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.91)
        self.masks.append(cv.imread("equip/bags/bag_6_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/bags/bag_7_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.91)
        self.masks.append(cv.imread("equip/bags/bag_7_32-mask.png", cv.IMREAD_COLOR))

    def include_coins(self):
        self.needles.append(cv.imread("equip/coins/coin_1_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.91)
        self.masks.append(cv.imread("equip/coins/coin_1_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/coins/coin_2_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.91)
        self.masks.append(cv.imread("equip/coins/coin_2_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/coins/coin_3_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.91)
        self.masks.append(cv.imread("equip/coins/coin_3_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/coins/coin_4_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.91)
        self.masks.append(cv.imread("equip/coins/coin_4_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/coins/coin_5_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.91)
        self.masks.append(cv.imread("equip/coins/coin_5_32-mask.png", cv.IMREAD_COLOR))

    def include_runes(self):
        self.needles.append(cv.imread("equip/runes/rune_1_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.91)
        self.masks.append(cv.imread("equip/runes/rune_1_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/runes/rune_2_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.91)
        self.masks.append(cv.imread("equip/runes/rune_2_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/runes/rune_3_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.91)
        self.masks.append(cv.imread("equip/runes/rune_3_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/runes/rune_4_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.91)
        self.masks.append(cv.imread("equip/runes/rune_4_32-mask.png", cv.IMREAD_COLOR))

    def include_mushs(self):
        self.needles.append(cv.imread("equip/mushrooms/mush_1_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.93)
        self.masks.append(cv.imread("equip/mushrooms/mush_1_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/mushrooms/mush_2_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.93)
        self.masks.append(cv.imread("equip/mushrooms/mush_2_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/mushrooms/mush_3_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.93)
        self.masks.append(cv.imread("equip/mushrooms/mush_3_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/mushrooms/mush_4_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.93)
        self.masks.append(cv.imread("equip/mushrooms/mush_4_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/mushrooms/mush_5_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.93)
        self.masks.append(cv.imread("equip/mushrooms/mush_5_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/mushrooms/mush_6_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.93)
        self.masks.append(cv.imread("equip/mushrooms/mush_6_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/mushrooms/mush_7_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.93)
        self.masks.append(cv.imread("equip/mushrooms/mush_7_32-mask.png", cv.IMREAD_COLOR))

    def include_amus(self):
        self.needles.append(cv.imread("equip/amus/amu_1_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.9)
        self.masks.append(cv.imread("equip/amus/amu_1_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/amus/amu_2_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.9)
        self.masks.append(cv.imread("equip/amus/amu_2_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/amus/amu_3_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.93)
        self.masks.append(cv.imread("equip/amus/amu_3_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/amus/amu_4_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.93)
        self.masks.append(cv.imread("equip/amus/amu_4_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/amus/amu_5_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.93)
        self.masks.append(cv.imread("equip/amus/amu_5_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/amus/amu_6_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.93)
        self.masks.append(cv.imread("equip/amus/amu_6_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/amus/amu_7_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.93)
        self.masks.append(cv.imread("equip/amus/amu_7_32-mask.png", cv.IMREAD_COLOR))

    def include_swords(self):
        self.needles.append(cv.imread("equip/swords/sword_1_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.93)
        self.masks.append(cv.imread("equip/swords/sword_1_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/swords/sword_2_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.93)
        self.masks.append(cv.imread("equip/swords/sword_2_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/swords/sword_3_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.93)
        self.masks.append(cv.imread("equip/swords/sword_3_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/swords/sword_4_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.93)
        self.masks.append(cv.imread("equip/swords/sword_4_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/swords/sword_5_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.93)
        self.masks.append(cv.imread("equip/swords/sword_5_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/swords/sword_6_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.93)
        self.masks.append(cv.imread("equip/swords/sword_6_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/swords/sword_7_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.93)
        self.masks.append(cv.imread("equip/swords/sword_7_32-mask.png", cv.IMREAD_COLOR))

    def include_staffs(self):
        self.needles.append(cv.imread("equip/staffs/staff_1_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.93)
        self.masks.append(cv.imread("equip/staffs/staff_1_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/staffs/staff_2_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.93)
        self.masks.append(cv.imread("equip/staffs/staff_2_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/staffs/staff_3_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.93)
        self.masks.append(cv.imread("equip/staffs/staff_3_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/staffs/staff_4_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.93)
        self.masks.append(cv.imread("equip/staffs/staff_4_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/staffs/staff_5_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.93)
        self.masks.append(cv.imread("equip/staffs/staff_5_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/staffs/staff_6_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.93)
        self.masks.append(cv.imread("equip/staffs/staff_6_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/staffs/staff_7_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.93)
        self.masks.append(cv.imread("equip/staffs/staff_7_32-mask.png", cv.IMREAD_COLOR))

    def include_rings(self):
        self.needles.append(cv.imread("equip/rings/ring_1_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.925)
        self.masks.append(cv.imread("equip/rings/ring_1_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/rings/ring_2_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.94)
        self.masks.append(cv.imread("equip/rings/ring_2_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/rings/ring_3_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.93)
        self.masks.append(cv.imread("equip/rings/ring_3_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/rings/ring_4_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.91)
        self.masks.append(cv.imread("equip/rings/ring_4_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/rings/ring_5_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.93)
        self.masks.append(cv.imread("equip/rings/ring_5_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/rings/ring_6_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.91)
        self.masks.append(cv.imread("equip/rings/ring_6_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/rings/ring_7_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.93)
        self.masks.append(cv.imread("equip/rings/ring_7_32-mask.png", cv.IMREAD_COLOR))

    def include_wands(self):
        self.needles.append(cv.imread("equip/wands/wand_1_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.93)
        self.masks.append(cv.imread("equip/wands/wand_1_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/wands/wand_2_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.93)
        self.masks.append(cv.imread("equip/wands/wand_2_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/wands/wand_3_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.93)
        self.masks.append(cv.imread("equip/wands/wand_3_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/wands/wand_4_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.93)
        self.masks.append(cv.imread("equip/wands/wand_4_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/wands/wand_5_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.93)
        self.masks.append(cv.imread("equip/wands/wand_5_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/wands/wand_6_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.93)
        self.masks.append(cv.imread("equip/wands/wand_6_32-mask.png", cv.IMREAD_COLOR))

        self.needles.append(cv.imread("equip/wands/wand_7_32.jpg", cv.IMREAD_UNCHANGED))
        self.hsvs.append(HSV_DEFAULT)
        self.tresholds.append(0.93)
        self.masks.append(cv.imread("equip/wands/wand_7_32-mask.png", cv.IMREAD_COLOR))
