Skip full cache chests until reopened
This commit is contained in:
1 parent
5197c1ece7
commit
1b4dc21ea4
2 files changed
+150
-4
No files matched your search
@@ -19,6 +19,36 @@ class CacheItemsStates:
|
||||
def idle(self):
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def _chest_event_key(event):
|
||||
return (event.get('timestamp'), tuple(event.get('position', ())))
|
||||
|
||||
def _refresh_useless_chests(self):
|
||||
events = self.g.get('chest_open_events', ())
|
||||
current_events = {self._chest_event_key(event) for event in events}
|
||||
for event in events:
|
||||
event_key = self._chest_event_key(event)
|
||||
if event_key in self._processed_chest_open_events:
|
||||
continue
|
||||
self._processed_chest_open_events.add(event_key)
|
||||
position = tuple(event.get('position', ()))
|
||||
reopened = [key for key in self.useless_chests
|
||||
if position in key]
|
||||
for key in reopened:
|
||||
self.useless_chests.discard(key)
|
||||
self.checked_labeled_chests.discard(key)
|
||||
print('Cache chest was opened by another player; checking it again:',
|
||||
position)
|
||||
self._processed_chest_open_events.intersection_update(current_events)
|
||||
|
||||
def _chest_positions(self, chest):
|
||||
finder = getattr(self.g.world, '_double_chest_positions', None)
|
||||
if finder:
|
||||
positions = finder(tuple(chest))
|
||||
if positions:
|
||||
return tuple(tuple(position) for position in positions)
|
||||
return (tuple(chest),)
|
||||
|
||||
def _has_compatible_labeled_chest_near(self, bed, distance=16):
|
||||
world = self.g.get('world')
|
||||
if world is None:
|
||||
@@ -49,6 +79,8 @@ class CacheItemsStates:
|
||||
self.bad_openings = set()
|
||||
self.is_labeled_container = False
|
||||
self.container_item_ids = None
|
||||
self.current_container_key = None
|
||||
self.container_was_full_on_open = None
|
||||
|
||||
num_stacks = self.g.game.count_inventory_slots()
|
||||
has_override = 'minimum' in self.__dict__
|
||||
@@ -103,14 +135,18 @@ class CacheItemsStates:
|
||||
p = utils.pint(self.g.pos)
|
||||
|
||||
for container in self.labeled_chests:
|
||||
key = container['positions']
|
||||
if key in self.checked_labeled_chests:
|
||||
key = tuple(tuple(position) for position in
|
||||
(container.get('positions') or
|
||||
(container['position'],)))
|
||||
if (key in self.checked_labeled_chests or
|
||||
key in self.useless_chests):
|
||||
continue
|
||||
self.checked_labeled_chests.add(key)
|
||||
if not self._has_transferable_item(container['item_ids']):
|
||||
continue
|
||||
|
||||
self.area = container['position']
|
||||
self.current_container_key = key
|
||||
self.container_item_ids = container['item_ids']
|
||||
self.is_labeled_container = True
|
||||
for opening in w.find_cache_openings(self.area, p):
|
||||
@@ -130,6 +166,11 @@ class CacheItemsStates:
|
||||
self.bad_openings.add(opening_position)
|
||||
print('No path to labeled chest', self.area)
|
||||
|
||||
while (self.trapped_chests and
|
||||
self._chest_positions(self.trapped_chests[0]) in
|
||||
self.useless_chests):
|
||||
self.trapped_chests.pop(0)
|
||||
|
||||
if not len(self.trapped_chests):
|
||||
self.is_labeled_container = False
|
||||
self.container_item_ids = None
|
||||
@@ -145,6 +186,7 @@ class CacheItemsStates:
|
||||
self.container_item_ids = None
|
||||
chest = self.trapped_chests[0]
|
||||
self.area = chest
|
||||
self.current_container_key = self._chest_positions(chest)
|
||||
|
||||
for opening in w.find_cache_openings(chest, p):
|
||||
opening_position = tuple(opening['position'])
|
||||
@@ -246,6 +288,7 @@ class CacheItemsStates:
|
||||
|
||||
def open_chest(self):
|
||||
print('Opening chest')
|
||||
self.container_was_full_on_open = None
|
||||
self.failed_transfer_slots.clear()
|
||||
self.pending_transfer = None
|
||||
self.g.game.open_container(
|
||||
@@ -353,8 +396,16 @@ class CacheItemsStates:
|
||||
w_inventory_slots = range(w.container_slots, len(w.contents))
|
||||
|
||||
used_slots = self.g.game.count_window_slots()
|
||||
print('used:', used_slots, 'total:', len(w_container_slots))
|
||||
if used_slots >= len(w_container_slots):
|
||||
capacity = len(w_container_slots)
|
||||
print('used:', used_slots, 'total:', capacity)
|
||||
if self.container_was_full_on_open is None:
|
||||
self.container_was_full_on_open = used_slots >= capacity
|
||||
if used_slots >= capacity:
|
||||
if (self.container_was_full_on_open and
|
||||
self.current_container_key is not None):
|
||||
self.useless_chests.add(self.current_container_key)
|
||||
print('Chest was full when first opened; skipping until another player opens it:',
|
||||
self.current_container_key)
|
||||
print('Container is too full, aborting')
|
||||
self.g.game.close_window()
|
||||
self.g.look_at = None
|
||||
@@ -456,6 +507,13 @@ class CacheItemsStates:
|
||||
|
||||
self.labeled_chests = []
|
||||
self.checked_labeled_chests = set()
|
||||
self.useless_chests = set()
|
||||
self._processed_chest_open_events = {
|
||||
self._chest_event_key(event)
|
||||
for event in self.g.get('chest_open_events', ())
|
||||
}
|
||||
self.current_container_key = None
|
||||
self.container_was_full_on_open = None
|
||||
self.is_labeled_container = False
|
||||
self.container_item_ids = None
|
||||
self.area = None
|
||||
@@ -466,4 +524,5 @@ class CacheItemsStates:
|
||||
self.wait_time = 0
|
||||
|
||||
def run(self):
|
||||
self._refresh_useless_chests()
|
||||
self.state()
|
||||
Reference in new issue
Block a user