Track reopened supply chests and fix API snapshots
This commit is contained in:
@@ -204,6 +204,28 @@ class GrabSuppliesStates:
|
||||
self.ground_position = None
|
||||
self.state = self.find_ground_items
|
||||
|
||||
@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.remove(key)
|
||||
self.checked_supply_chests.discard(key)
|
||||
print('Supply chest was opened by another player; checking it again:',
|
||||
position)
|
||||
self._processed_chest_open_events.intersection_update(current_events)
|
||||
|
||||
def find_supply_chests(self):
|
||||
print('Finding chests labeled for this bot\'s supplies...')
|
||||
p = utils.pint(self.g.pos)
|
||||
@@ -215,10 +237,11 @@ class GrabSuppliesStates:
|
||||
def choose_supply_chest(self):
|
||||
print('Choosing a supply-labeled chest...')
|
||||
for container in self.supply_chests:
|
||||
key = container['positions']
|
||||
if key in self.checked_supply_chests:
|
||||
key = tuple(container['positions'])
|
||||
if key in self.useless_chests or key in self.checked_supply_chests:
|
||||
continue
|
||||
self.checked_supply_chests.add(key)
|
||||
self.current_supply_chest_key = key
|
||||
self.chest = container['position']
|
||||
self.area = self.chest
|
||||
print('Chose supply chest:', self.chest)
|
||||
@@ -286,6 +309,9 @@ class GrabSuppliesStates:
|
||||
return
|
||||
|
||||
print('No matching items in this supply chest')
|
||||
key = getattr(self, 'current_supply_chest_key', None)
|
||||
if key is not None and key not in self.useless_chests:
|
||||
self.useless_chests.append(key)
|
||||
self.state = self.close_supply_chest
|
||||
|
||||
def grab_items(self):
|
||||
@@ -355,6 +381,12 @@ class GrabSuppliesStates:
|
||||
self.supplies = self.default_supplies()
|
||||
self.supply_chests = []
|
||||
self.checked_supply_chests = set()
|
||||
self.useless_chests = []
|
||||
self._processed_chest_open_events = {
|
||||
self._chest_event_key(event)
|
||||
for event in self.g.get('chest_open_events', ())
|
||||
}
|
||||
self.current_supply_chest_key = None
|
||||
self.supply_chest = None
|
||||
self.checked_supplies = []
|
||||
self.target_items = None
|
||||
@@ -365,4 +397,5 @@ class GrabSuppliesStates:
|
||||
self.wait_time = 0
|
||||
|
||||
def run(self):
|
||||
self._refresh_useless_chests()
|
||||
self.state()
|
||||
|
||||
Reference in New Issue
Block a user