Skip to content

Commit

Permalink
Update morg_http_client.py
Browse files Browse the repository at this point in the history
added method get_inv_item_first_indice

Returns the first index in your inventory that an item is located in
Useful for clicking on multiple items or just one when bank deposit settings are set to "all"
  • Loading branch information
WillowsDad committed Mar 14, 2023
1 parent 639c1a5 commit 5aa5269
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/utilities/api/morg_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,23 @@ def get_inv_item_indices(self, item_id: Union[List[int], int]) -> list:
return [i for i, inventory_slot in enumerate(data) if inventory_slot["id"] == item_id]
elif isinstance(item_id, list):
return [i for i, inventory_slot in enumerate(data) if inventory_slot["id"] in item_id]

def get_inv_item_first_indice(self, item_id: Union[List[int], int]) -> int:
"""
For the given item ID(s), returns the first inventory slot index that the item exists in.
e.g. [1, 1, 2, 3, 3, 3, 4, 4, 4, 4] -> [0, 2, 3, 6]
IMPORTANT ~ This does so by checking if the current item ID is the same as the previous item ID. ~
Args:
item_id: The item ID to search for (an single ID, or list of IDs).
Returns:
The first inventory slot index that the item exists in.
"""
data = self.__do_get(endpoint=self.inv_endpoint)
if isinstance(item_id, int):
return next((i for i, inventory_slot in enumerate(data) if inventory_slot["id"] == item_id), -1)
elif isinstance(item_id, list):
slot_list = [i for i, inventory_slot in enumerate(data) if inventory_slot["id"] != data[i - 1]["id"] and inventory_slot["id"] in item_id]
return slot_list or -1

def get_inv_item_stack_amount(self, item_id: Union[int, List[int]]) -> int:
"""
Expand Down

0 comments on commit 5aa5269

Please sign in to comment.