Exemplo n.º 1
0
    def sync_inventory(self):
        ''' Read inventory and sinchronize it '''

        # Check we are in foreground, set otherwise
        self.is_foreground(set_foreground=True)

        # Check if stash is open, open it otherwise
        self.check_stash_open(open_otherwise=True)

        logger.info("Starting inventory sync ...")

        # Find empty slots in inventory
        empty_slots = vh.find_empty_slots_in_inventory()

        # Mark as empty
        for row, col in empty_slots:
            inventory.clear(row, col)

        full_slots = []
        # Find the non-empty slots
        for row in range(inventory.num_rows):
            for col in range(inventory.num_cols):
                if (row, col) not in empty_slots:
                    full_slots += [[row, col]]

        for slot in full_slots:
            # get item description
            item_description = self.get_text_at_position(
                inventory.to_screen_position(*slot), reset_mouse=False)

            # classify description
            (curr, ammount) = self.process_item_description(item_description)

            if curr == "" and ammount == "":
                # Empty slot
                inventory.clear(*slot)
            elif curr and ammount:
                new_stack = currency.CurrencyStack(curr, ammount)
                inventory.set(new_stack, slot[0], slot[1])
            else:
                raise CouldNotIdentifyItemException

        # Reset Mouse Position
        autogui.moveTo(1, 1)

        inventory.synchronzed = True

        logger.info("Inventory sync finished ...")
Exemplo n.º 2
0
    def sync_bank(self):
        ''' Read inventory and sinchronize it '''

        # Check we are in foreground, set otherwise
        self.is_foreground(set_foreground=True)

        # Check if stash is open, open it otherwise
        self.check_stash_open(open_otherwise=True)

        # Go to the currency stash tab
        self.go_to_tab(currency_tab, check_stash_open=False)

        logger.info("Starting bank sync ...")

        # Find currencies in stash tab
        matches = vh.find_currency_in_stash_tab(
            currency.CURRENCY_LIST, currency_tab)

        # For every currency kind
        for curr in currency.CURRENCY_LIST:

            if curr.name in matches:
                # Every location where this curr was found
                for match in matches[curr.name]:

                    item_description = self.get_text_at_position(
                        match, reset_mouse=False)

                    # classify description
                    (found_curr, found_ammount) = self.process_item_description(
                        item_description)

                    # assert(curr == found_curr)
                    # Image Capture is not 100% reliable
                    # If there is a missmtach ctrl+c wins
                    if found_curr != None and found_curr != "" and curr == found_curr:
                        temmp_stack = currency.CurrencyStack(
                            found_curr, found_ammount)

                        assert(bank.deposit(temmp_stack))

        # Reset Mouse Position
        autogui.moveTo(1, 1)

        bank.synchronzed = True
        logger.info("Bank sync finished ...")
Exemplo n.º 3
0
    def process_new_mesage(message):
        '''
        Interpret the string.
        It can follow under this categories:
            1. New trade message
            2. Trade feedback (accepted/declined)
            3. Player joined/left the area
            4. AFK ON/OFF
            5. Other
        '''

        logger.debug("Client.txt: {}".format(message))

        # match = re.search(
        #     "\[INFO Client \d+\] {}:(?P<message>.*)".format(config.PLAYER_NAME), message)
        # if match:
        #     feedback_q.put(match.group['message'])

        match = re.search(
            "@From (?:<\w+> )?(?P<player_name>\w+): Hi, I'd like to buy your (?P<give_ammount>\d+) (?P<give>.*) for my (?P<receive_ammount>\d+) (?P<receive>.*) in Delirium.?( \(stash tab \"(?P<stash_tab_name>\w+)\"; position: left (?P<left>\w+), top (?P<top>\w+)\))?", message)

        if match:

            # Match currencies
            give_curr = None
            give_ammount = int(match.group('give_ammount'))
            receive_curr = None
            receive_ammount = int(match.group('receive_ammount'))

            for curr in currency.CURRENCY_LIST:
                if re.match(curr.regex, match.group('receive')):
                    receive_curr = curr
                if re.match(curr.regex, match.group('give')):
                    give_curr = curr

            # Could not identify currency
            if not give_curr or not receive_curr:
                return

            trade_req_q.put(
                TRADE_REQ_MSG(
                    match.group('player_name'),
                    currency.CurrencyStack(give_curr, give_ammount),
                    currency.CurrencyStack(receive_curr, receive_ammount),
                    match.group('stash_tab_name'),
                    match.group('left'),
                    match.group('top')
                )
            )
            return

        # Trade accepted
        match = re.search("Trade accepted.", message)
        if match:
            trade_outcome_q.put(TRADE_OUTCOME.ACCEPTED)
            return

        # Trade declined
        match = re.search("Trade cancelled.", message)
        if match:
            trade_outcome_q.put(TRADE_OUTCOME.DECLINED)
            return

        # Player joined the area
        match = re.search(
            "\[INFO Client \d+\] : (?:<\w+> )?(?P<player_name>\w+) has joined the area.", message)
        if match:
            player_joined_q.put(
                PLAYER_JOINED_MSG(
                    match.group('player_name'),
                    PLAYER_JOINED_STATUS.JOINED
                )
            )
            return

        # Player left
        match = re.search(
            "\[INFO Client \d+\] : (?:<\w+> )?(?P<player_name>\w+) has left the area.", message)
        if match:
            player_joined_q.put(
                PLAYER_JOINED_MSG(
                    match.group('player_name'),
                    PLAYER_JOINED_STATUS.LEFT
                )
            )
            return

        # Went AFK
        match = re.search("AFK mode is now ON", message)
        if match:
            afk_mode_q.put(AFK_STATUS.ON)
            return

        # AFK off
        match = re.search("AFK mode is now OFF", message)
        if match:
            afk_mode_q.put(AFK_STATUS.OFF)
            return
Exemplo n.º 4
0
    def transfer_currency_stash_inv(self, curr, ammount, from_tab):
        '''
            Takes a list of currencies to be transfered into the inventory.
            Will take care of ammounts that are not aligned with stack size.
        '''

        # Check we are in foreground, set otherwise
        self.is_foreground(set_foreground=True)

        # Check if stash is open, open it otherwise
        self.check_stash_open(open_otherwise=True)

        # Go to the currency stash tab
        self.go_to_tab(from_tab, check_stash_open=False)

        # Find the position of this currency in stash
        matches = vh.find_currency_in_stash_tab([curr], currency_tab)
        matches = matches[curr.name]

        # Check if it is possible
        if not bank.withdraw(currency.CurrencyStack(curr, ammount)):
            raise Exception

        t_ammount_left = ammount

        for match in matches:

            # Read at that position
            (found_curr, f_ammount_left) = self.process_item_description(
                self.get_text_at_position(match, reset_mouse=False))

            if found_curr != curr:
                logger.error(
                    "Find mismatch ! Expected {} found {}".format(curr, found_curr))
                raise Exception

            # While we didnt finish or we didn't run out of currency here
            while (t_ammount_left > 0) and (f_ammount_left > 0):

                transfer_size = 0
                # Eg 5c left here and need to transfer 6c (stack size is 10)
                # Eg 11c left here and need to transfer 16c (stack size is 10) - Wouldn't work
                if (f_ammount_left < t_ammount_left) and (f_ammount_left < curr.stack_size):
                    transfer_size = f_ammount_left
                # Eg 50c left here and need to transfer 60c (stack size is 10)
                elif t_ammount_left > curr.stack_size:
                    transfer_size = curr.stack_size
                # Eg 50c left here and need to transfer 6c (stack size is 10)
                elif t_ammount_left <= curr.stack_size:
                    transfer_size = t_ammount_left

                # The transfer function will asume that if we are transfering less than a full stack
                # we will do it 'by hand' and not by control + click. Since it
                # This is the case most of the time. There is a corner case where we are transfering
                # less than a full stack and exactly the ammount left on the stash. In that case we have to
                # ctrl + click.
                force_ctrl_click = (transfer_size == f_ammount_left)
                (result, new_cell) = inventory.transfer(
                    currency.CurrencyStack(found_curr, transfer_size), force_ctrl_click=force_ctrl_click)

                if not result:
                    print(result)
                    print(new_cell)
                    print(inventory.dump())
                    print(bank.contents)
                    raise Exception

                # Can ctrl+click to transfer full stack
                if transfer_size == curr.stack_size or transfer_size == f_ammount_left:
                    # Transfer found_ammount of found_curr into inv
                    autogui.moveTo(*match)
                    autogui.keyDown('ctrl')
                    autogui.click()
                    autogui.keyUp('ctrl')
                # Need to split the stack
                else:
                    autogui.moveTo(*match)
                    autogui.keyDown('shift')
                    autogui.click()
                    autogui.keyUp('shift')

                    time.sleep(0.2)
                    # Split currency
                    autogui.typewrite(str(transfer_size))
                    time.sleep(0.2)
                    # Confirm
                    autogui.press('enter')

                    # Find next empty slot
                    autogui.moveTo(
                        *inventory.to_screen_position(*new_cell))

                    # Drop the currency
                    autogui.click()

                # Update remaining
                t_ammount_left -= transfer_size

        if t_ammount_left != 0:
            raise Exception
Exemplo n.º 5
0
    def transfer(self, currency_stack, force_ctrl_click=False):
        '''
            Transfer a currency stack
        '''

        curr = currency_stack.curr
        ammount = currency_stack.ammount

        # If transfering less than a full stack it needs to be done by hand
        # Give the cell where the currency should be put
        #################################################################################
        # Unless they are the last orbs in the stash, so they need to be ctrl + clicked
        # force_ctrl_click comes in then
        #################################################################################
        if ammount < curr.stack_size and not force_ctrl_click:

            (row, col) = self.next_emtpy_cell()

            if row is None or col is None:
                # Inventory full or something went wrong
                return False, None
            else:
                self.set(currency_stack, row, col)
                return True, (row, col)

        # Check if currency can be distributed among non-complete stacks of the same currency
        for col in range(self.num_cols):
            for row in range(self.num_rows):

                cell = self.get(row, col)
                # Look for a non-complete stack of the same currency
                if cell is not None and cell.curr == curr and cell.ammount < curr.stack_size:

                    # Orbs currently in that position
                    current = cell.ammount
                    # Orbs to a full stack
                    remaining = curr.stack_size - \
                        cell.ammount

                    if ammount <= remaining:
                        self.add(currency.CurrencyStack(curr, ammount), row,
                                 col)
                        ammount = 0
                    else:
                        self.add(currency.CurrencyStack(curr, remaining), row,
                                 col)
                        ammount -= remaining

                if ammount == 0:
                    break
            if ammount == 0:
                break

        # It was not possible to distribute currency, it must take a new slot
        if ammount > 0:
            (row, col) = self.next_emtpy_cell()

            if row is None or col is None:
                # Inventory full or something went wrong
                return False, None

            self.set(currency.CurrencyStack(curr, ammount), row, col)

            return True, (row, col)
        else:
            return True, (None, None)