Avoid redundant cache chest visits
This commit is contained in:
@@ -20,7 +20,7 @@ class CacheItemsStates:
|
||||
return None
|
||||
|
||||
def init(self):
|
||||
self.skip_slots = []
|
||||
self.skip_inventory_slots = set()
|
||||
self.skip_items = []
|
||||
self.failed_transfer_slots = set()
|
||||
self.pending_transfer = None
|
||||
@@ -30,8 +30,8 @@ class CacheItemsStates:
|
||||
self.container_item_ids = None
|
||||
|
||||
num_stacks = self.g.game.count_inventory_slots()
|
||||
minimum = getattr(
|
||||
self, 'minimum', self.g.get('minimum_cache_slots', 27))
|
||||
minimum = self.__dict__.pop(
|
||||
'minimum', self.g.get('minimum_cache_slots', 27))
|
||||
print('Inventory amount:', num_stacks)
|
||||
if num_stacks == 0:
|
||||
self.state = self.cleanup
|
||||
@@ -79,8 +79,7 @@ class CacheItemsStates:
|
||||
if key in self.checked_labeled_chests:
|
||||
continue
|
||||
self.checked_labeled_chests.add(key)
|
||||
if not any(item.present and item.item_id in container['item_ids']
|
||||
for item in self.g.inv.values()):
|
||||
if not self._has_transferable_item(container['item_ids']):
|
||||
continue
|
||||
|
||||
self.area = container['position']
|
||||
@@ -97,6 +96,7 @@ class CacheItemsStates:
|
||||
self.opening = opening_position
|
||||
self.open_interaction = opening
|
||||
self.g.path = navpath
|
||||
self.g.look_at = None
|
||||
self.state = self.going_to_trapped_chest
|
||||
return
|
||||
self.bad_openings.add(opening_position)
|
||||
@@ -128,6 +128,7 @@ class CacheItemsStates:
|
||||
self.opening = opening_position
|
||||
self.open_interaction = opening
|
||||
self.g.path = navpath
|
||||
self.g.look_at = None
|
||||
self.state = self.going_to_trapped_chest
|
||||
return
|
||||
self.bad_openings.add(opening_position)
|
||||
@@ -140,6 +141,8 @@ class CacheItemsStates:
|
||||
self.g.look_at = self.open_interaction['look_at']
|
||||
self.wait_time = 0.5
|
||||
self.state = self.turn_to_trapped_chest
|
||||
else:
|
||||
self.g.look_at = None
|
||||
|
||||
def turn_to_trapped_chest(self):
|
||||
self.g.look_at = self.open_interaction['look_at']
|
||||
@@ -191,6 +194,7 @@ class CacheItemsStates:
|
||||
return
|
||||
|
||||
self.g.path = navpath
|
||||
self.g.look_at = None
|
||||
self.state = self.going_to_area
|
||||
|
||||
def going_to_area(self):
|
||||
@@ -198,6 +202,8 @@ class CacheItemsStates:
|
||||
self.g.look_at = self.open_interaction['look_at']
|
||||
self.wait_time = 0.5
|
||||
self.state = self.turn_to_cache_spot
|
||||
else:
|
||||
self.g.look_at = None
|
||||
|
||||
def turn_to_cache_spot(self):
|
||||
self.g.look_at = self.open_interaction['look_at']
|
||||
@@ -255,6 +261,24 @@ class CacheItemsStates:
|
||||
keep.add(max(stacks, key=lambda pair: pair[1].item_count)[0])
|
||||
return keep
|
||||
|
||||
def _has_transferable_item(self, item_ids):
|
||||
item_ids = set(item_ids)
|
||||
needed_slots = self._needed_inventory_slots_to_keep()
|
||||
planned_skip_items = set(self.skip_items)
|
||||
for inventory_slot, item in self.g.inv.items():
|
||||
if (not item.present or item.item_id not in item_ids or
|
||||
inventory_slot in self.skip_inventory_slots):
|
||||
continue
|
||||
if (item.item_id in items.NEEDED_ITEMS and
|
||||
inventory_slot in needed_slots):
|
||||
continue
|
||||
if (item.item_id in items.WANTED_ITEMS and
|
||||
item.item_id not in planned_skip_items):
|
||||
planned_skip_items.add(item.item_id)
|
||||
continue
|
||||
return True
|
||||
return False
|
||||
|
||||
def _window_player_slot(self, window_slot):
|
||||
offset = window_slot - self.g.window.container_slots
|
||||
if 0 <= offset < 27:
|
||||
@@ -333,7 +357,8 @@ class CacheItemsStates:
|
||||
elif slot.item_id in items.NEEDED_ITEMS:
|
||||
continue
|
||||
|
||||
if (slot_num in self.skip_slots or
|
||||
inventory_slot = self._window_player_slot(slot_num)
|
||||
if (inventory_slot in self.skip_inventory_slots or
|
||||
slot_num in self.failed_transfer_slots):
|
||||
continue
|
||||
|
||||
@@ -344,7 +369,9 @@ class CacheItemsStates:
|
||||
for slot_num, slot in slot_list:
|
||||
if slot.item_id in items.WANTED_ITEMS and slot.item_id not in self.skip_items:
|
||||
print('skipping wanted item', slot)
|
||||
self.skip_slots.append(slot_num)
|
||||
inventory_slot = self._window_player_slot(slot_num)
|
||||
if inventory_slot is not None:
|
||||
self.skip_inventory_slots.add(inventory_slot)
|
||||
self.skip_items.append(slot.item_id)
|
||||
continue
|
||||
|
||||
@@ -393,7 +420,7 @@ class CacheItemsStates:
|
||||
|
||||
self.silent = False
|
||||
|
||||
self.skip_slots = []
|
||||
self.skip_inventory_slots = set()
|
||||
self.failed_transfer_slots = set()
|
||||
self.pending_transfer = None
|
||||
self.transferred_to_labeled_chest = False
|
||||
|
||||
Reference in New Issue
Block a user