def open_inventory_if_closed():
    inventory = Mouse.get_on_screen(PanelIcons.ICON_INVENTORY_SELECTED, 0.991)
    if inventory is None:
        inventory = Mouse.get_on_screen(PanelIcons.ICON_INVENTORY_UNSELECTED,
                                        0.991)
        if inventory is None:
            sys.exit('Could not find inventory icon, exiting script')
        else:
            Mouse.move_humanly_mouse_random_location_in_box(inventory)
            Mouse.click(200)
            Mouse.sleep_with_countdown(400, 450, 450)
def find_and_guzzle_rock_cake():
    cake_location = Mouse.get_on_screen(Items.ITEM_ROCK_CAKE, 0.991)
    if cake_location is None:
        sys.exit('Could not find rock cake, exiting script')
    else:
        random_location = cake_location[0] + Mouse.get_rand_int(
            0, 16), cake_location[1] + Mouse.get_rand_int(0, 1)
        Mouse.move_humanly_mouse_to_location(random_location[0],
                                             random_location[1])
        guzzle_rock_cake_uncached()
def guzzle_rock_cake_uncached():
    i = 0  # fail-safe check
    while True:
        i += 1
        hp_1_location = Mouse.get_on_screen(UI.UI_ICON_HP, 0.995)
        if hp_1_location is None:
            log.info('Guzzling if hp is not 1')
            guzzle_rock_cake()
            if i == 50:
                sys.exit('Something went wrong with guzzling rock cake!')
        else:
            break
    log.info('HP is 1')