# Path: bot/modes/Events.py
# class Signal(object):
#     def __init__(self):
#         self.callbacks = []
#         self.r_lock = threading.RLock()
# 
#     def connect(self, callback):
#         with self.r_lock:
#             callback = weak_ref(callback)
#             self.callbacks.append(callback)
# 
#     def disconnect(self, callback):
#         with self.r_lock:
#             for index, weakref_callback in enumerate(self.callbacks):
#                 if callback == weakref_callback():
#                     del self.callbacks[index]
#                     break
# 
#     def emit(self, *args, **kwargs):
#         if len(self.callbacks) == 0:
#             return
#         with self.r_lock:
#             for index, weakref_callback in enumerate(self.callbacks):
#                 callback = weakref_callback()
#                 if callback is not None:
#                     callback(*args, **kwargs)
#                 else:  # lost reference
#                     del self.callbacks[index]
# 
# Path: bot/common.py
# def crop_image(img, left=0, top=0, width=0, height=0):
#     left, top, width, height = tuple(np.asanyarray([left, top, width, height], np.uint64).tolist())
#     crop_img = img[top:(top + height), left:(left + width)].copy()
#     return crop_img
# 
# Path: bot/shared.py
# HIGH_CORR = 3
# LOW_CORR = 2
# def look_up_translation_correlation(corr):
# def tupletodict(top, left, height, width):


import re
from abc import abstractmethod
from enum import Enum
from bot.modes.Events import Signal
from bot.common import crop_image
from bot.shared import LOW_CORR, alpha_numeric
        self.provider.wait_for('NEXT', True)
        self.provider.wait_for_ui(.3)
        self.provider.tap(*self.provider.predefined.button_duel)
        self.provider.wait_for_white_bottom(True)
        self.provider.wait_for_ui(.5)
        self.provider.tapnsleep(self.provider.predefined.button_duel, .1)
        dialog = True
        while dialog:
            dialog = self.provider.check_if_battle(self.provider.get_img_from_screen_shot())
            if dialog:
                self.provider.tap(*self.provider.predefined.button_duel)
        self.provider.wait_for_ui(.5)
        self.provider.scan_for_ok(LOW_CORR)
        self.provider.wait_for_ui(.1)
        self.provider.scan_for_ok(LOW_CORR)
        self.signalers[CheckPoints.afterEnding].emit(info)

    def check_battle(self, info, img):
        """Will Always return true since this is the last possible battle mode available"""
        img = crop_image(img, **self.provider.predefined.duelist_name_area)
        name = self.provider.img_to_string(img, alpha_numeric).lower()
        info.name = name
        return True


class VagabondBattle(NPCBattle):
    sort_value = 2

    def check_battle(self, info, img):
        img = crop_image(img, **self.provider.predefined.duelist_name_area)

# Path: bot/modes/Events.py
# class Signal(object):
#     def __init__(self):
#         self.callbacks = []
#         self.r_lock = threading.RLock()
# 
#     def connect(self, callback):
#         with self.r_lock:
#             callback = weak_ref(callback)
#             self.callbacks.append(callback)
# 
#     def disconnect(self, callback):
#         with self.r_lock:
#             for index, weakref_callback in enumerate(self.callbacks):
#                 if callback == weakref_callback():
#                     del self.callbacks[index]
#                     break
# 
#     def emit(self, *args, **kwargs):
#         if len(self.callbacks) == 0:
#             return
#         with self.r_lock:
#             for index, weakref_callback in enumerate(self.callbacks):
#                 callback = weakref_callback()
#                 if callback is not None:
#                     callback(*args, **kwargs)
#                 else:  # lost reference
#                     del self.callbacks[index]
# 
# Path: bot/common.py
# def crop_image(img, left=0, top=0, width=0, height=0):
#     left, top, width, height = tuple(np.asanyarray([left, top, width, height], np.uint64).tolist())
#     crop_img = img[top:(top + height), left:(left + width)].copy()
#     return crop_img
# 
# Path: bot/shared.py
# HIGH_CORR = 3
# LOW_CORR = 2
# def look_up_translation_correlation(corr):
# def tupletodict(top, left, height, width):


# Path: bot/modes/Battle.py
import re
from abc import abstractmethod
from enum import Enum
from bot.modes.Events import Signal
from bot.common import crop_image
from bot.shared import LOW_CORR, alpha_numeric

        self.provider.wait_for('NEXT', True)
        self.provider.wait_for_ui(.3)
        self.provider.tap(*self.provider.predefined.button_duel)
        self.provider.wait_for_white_bottom(True)
        self.provider.wait_for_ui(.5)
        self.provider.tapnsleep(self.provider.predefined.button_duel, .1)
        dialog = True
        while dialog:
            dialog = self.provider.check_if_battle(self.provider.get_img_from_screen_shot())
            if dialog:
                self.provider.tap(*self.provider.predefined.button_duel)
        self.provider.wait_for_ui(.5)
        self.provider.scan_for_ok(LOW_CORR)
        self.provider.wait_for_ui(.1)
        self.provider.scan_for_ok(LOW_CORR)
        self.signalers[CheckPoints.afterEnding].emit(info)

    def check_battle(self, info, img):
        """Will Always return true since this is the last possible battle mode available"""
        img = crop_image(img, **self.provider.predefined.duelist_name_area)
        name = self.provider.img_to_string(img, alpha_numeric).lower()
        info.name = name
        return True


class VagabondBattle(NPCBattle):
    sort_value = 2

    def check_battle(self, info, img):
        img = crop_image(img, **self.provider.predefined.duelist_name_area)

        name = self.provider.img_to_string(img, alpha_numeric).lower()