Avoid redundant cache chest visits

This commit is contained in:
Tanner
2026-11-07 22:14:46 +00:00
parent c65705fef8
commit a16b297db7
2 changed files with 89 additions and 8 deletions
+54
View File
@@ -30,6 +30,39 @@ class CacheItemsTests(unittest.TestCase):
'Found 11 labeled chests; found 0 trapped chests: []',
output.getvalue())
def test_wanted_single_stack_is_not_considered_transferable(self):
wanted_id = items.WHEAT_SEEDS_ID
old_wanted = items.WANTED_ITEMS
items.WANTED_ITEMS = set(old_wanted) | {wanted_id}
try:
state = CacheItemsStates(Munch(inv={
9: Munch(present=True, item_id=wanted_id, item_count=56),
}))
self.assertFalse(state._has_transferable_item({wanted_id}))
state.g.inv[10] = Munch(
present=True, item_id=wanted_id, item_count=12)
self.assertTrue(state._has_transferable_item({wanted_id}))
finally:
items.WANTED_ITEMS = old_wanted
def test_manual_cache_threshold_override_is_consumed_once(self):
class FakeGame:
@staticmethod
def count_inventory_slots():
return 5
state = CacheItemsStates(Munch(
game=FakeGame(), minimum_cache_slots=27))
state.minimum = 0
state.init()
self.assertIs(state.state.__func__, state.find_trapped_chests.__func__)
self.assertNotIn('minimum', state.__dict__)
state.init()
self.assertIs(state.state.__func__, state.cleanup.__func__)
def test_successful_labeled_transfer_skips_placing_another_cache_chest(self):
item_id = items.get_id('stone')
stack = Munch(present=True, item_id=item_id, item_count=16)
@@ -133,6 +166,27 @@ class CacheItemsTests(unittest.TestCase):
self.assertFalse(state._opening_in_bad_region(FakeWorld(), candidate))
self.assertNotIn(candidate, state.bad_openings)
def test_cache_travel_looks_along_path_then_turns_to_chest(self):
opening = (5, 64, 8)
chest_look = (4.9, 64.1, 7.8)
state = CacheItemsStates(Munch(
pos=(2.5, 64, 2.5), look_at=(1, 64, 1)))
state.opening = opening
state.open_interaction = {'look_at': chest_look}
state.going_to_trapped_chest()
self.assertIsNone(state.g.look_at)
state.g.pos = opening
state.going_to_trapped_chest()
self.assertEqual(state.g.look_at, chest_look)
self.assertIs(state.state.__func__, state.turn_to_trapped_chest.__func__)
state.g.pos = (2.5, 64, 2.5)
state.g.look_at = (1, 64, 1)
state.going_to_area()
self.assertIsNone(state.g.look_at)
def test_cache_chest_placement_sneaks_to_avoid_opening_support_container(self):
calls = []