Skip to content

Commit

Permalink
Core: recontextualize CollectionState.collect (#3723)
Browse files Browse the repository at this point in the history
* Core: renamed `CollectionState.collect` arg from `event` to `prevent_sweep` and remove forced collection

* Update TestDungeon.py

---------

Co-authored-by: NewSoupVi <57900059+NewSoupVi@users.noreply.github.com>
alwaysintreble and NewSoupVi authored Aug 13, 2024
1 parent dcaa2f7 commit 96d48a9
Showing 19 changed files with 146 additions and 150 deletions.
8 changes: 2 additions & 6 deletions BaseClasses.py
Original file line number Diff line number Diff line change
@@ -863,19 +863,15 @@ def count_group_unique(self, item_name_group: str, player: int) -> int:
)

# Item related
def collect(self, item: Item, event: bool = False, location: Optional[Location] = None) -> bool:
def collect(self, item: Item, prevent_sweep: bool = False, location: Optional[Location] = None) -> bool:
if location:
self.locations_checked.add(location)

changed = self.multiworld.worlds[item.player].collect(self, item)

if not changed and event:
self.prog_items[item.player][item.name] += 1
changed = True

self.stale[item.player] = True

if changed and not event:
if changed and not prevent_sweep:
self.sweep_for_events()

return changed
2 changes: 1 addition & 1 deletion test/bases.py
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ def get_state(self, items):
state = CollectionState(self.multiworld)
for item in items:
item.classification = ItemClassification.progression
state.collect(item, event=True)
state.collect(item, prevent_sweep=True)
state.sweep_for_events()
state.update_reachable_regions(1)
self._state_cache[self.multiworld, tuple(items)] = state
4 changes: 2 additions & 2 deletions worlds/alttp/test/dungeons/TestDungeon.py
Original file line number Diff line number Diff line change
@@ -54,7 +54,7 @@ def run_tests(self, access_pool):

for item in items:
item.classification = ItemClassification.progression
state.collect(item, event=True) # event=True prevents running sweep_for_events() and picking up
state.collect(item, prevent_sweep=True) # prevent_sweep=True prevents running sweep_for_events() and picking up
state.sweep_for_events() # key drop keys repeatedly

self.assertEqual(self.multiworld.get_location(location, 1).can_reach(state), access, f"failed {self.multiworld.get_location(location, 1)} with: {item_pool}")
self.assertEqual(self.multiworld.get_location(location, 1).can_reach(state), access, f"failed {self.multiworld.get_location(location, 1)} with: {item_pool}")
2 changes: 1 addition & 1 deletion worlds/oot/EntranceShuffle.py
Original file line number Diff line number Diff line change
@@ -796,7 +796,7 @@ def validate_world(ootworld, entrance_placed, locations_to_ensure_reachable, all

if ootworld.shuffle_interior_entrances or ootworld.shuffle_overworld_entrances or ootworld.spawn_positions:
time_travel_state = none_state.copy()
time_travel_state.collect(ootworld.create_item('Time Travel'), event=True)
time_travel_state.collect(ootworld.create_item('Time Travel'), prevent_sweep=True)
time_travel_state._oot_update_age_reachable_regions(player)

# Unless entrances are decoupled, we don't want the player to end up through certain entrances as the wrong age
2 changes: 1 addition & 1 deletion worlds/oot/__init__.py
Original file line number Diff line number Diff line change
@@ -1388,7 +1388,7 @@ def get_state_with_complete_itempool(self):
self.multiworld.worlds[item.player].collect(all_state, item)
# If free_scarecrow give Scarecrow Song
if self.free_scarecrow:
all_state.collect(self.create_item("Scarecrow Song"), event=True)
all_state.collect(self.create_item("Scarecrow Song"), prevent_sweep=True)
all_state.stale[self.player] = True

return all_state
8 changes: 4 additions & 4 deletions worlds/stardew_valley/test/TestCrops.py
Original file line number Diff line number Diff line change
@@ -11,10 +11,10 @@ def test_need_greenhouse_for_cactus(self):
harvest_cactus = self.world.logic.region.can_reach_location("Harvest Cactus Fruit")
self.assert_rule_false(harvest_cactus, self.multiworld.state)

self.multiworld.state.collect(self.world.create_item("Cactus Seeds"), event=False)
self.multiworld.state.collect(self.world.create_item("Shipping Bin"), event=False)
self.multiworld.state.collect(self.world.create_item("Desert Obelisk"), event=False)
self.multiworld.state.collect(self.world.create_item("Cactus Seeds"), prevent_sweep=False)
self.multiworld.state.collect(self.world.create_item("Shipping Bin"), prevent_sweep=False)
self.multiworld.state.collect(self.world.create_item("Desert Obelisk"), prevent_sweep=False)
self.assert_rule_false(harvest_cactus, self.multiworld.state)

self.multiworld.state.collect(self.world.create_item("Greenhouse"), event=False)
self.multiworld.state.collect(self.world.create_item("Greenhouse"), prevent_sweep=False)
self.assert_rule_true(harvest_cactus, self.multiworld.state)
34 changes: 17 additions & 17 deletions worlds/stardew_valley/test/TestDynamicGoals.py
Original file line number Diff line number Diff line change
@@ -12,29 +12,29 @@

def collect_fishing_abilities(tester: SVTestBase):
for i in range(4):
tester.multiworld.state.collect(tester.world.create_item(APTool.fishing_rod), event=False)
tester.multiworld.state.collect(tester.world.create_item(APTool.pickaxe), event=False)
tester.multiworld.state.collect(tester.world.create_item(APTool.axe), event=False)
tester.multiworld.state.collect(tester.world.create_item(APWeapon.weapon), event=False)
tester.multiworld.state.collect(tester.world.create_item(APTool.fishing_rod), prevent_sweep=False)
tester.multiworld.state.collect(tester.world.create_item(APTool.pickaxe), prevent_sweep=False)
tester.multiworld.state.collect(tester.world.create_item(APTool.axe), prevent_sweep=False)
tester.multiworld.state.collect(tester.world.create_item(APWeapon.weapon), prevent_sweep=False)
for i in range(10):
tester.multiworld.state.collect(tester.world.create_item("Fishing Level"), event=False)
tester.multiworld.state.collect(tester.world.create_item("Combat Level"), event=False)
tester.multiworld.state.collect(tester.world.create_item("Mining Level"), event=False)
tester.multiworld.state.collect(tester.world.create_item("Fishing Level"), prevent_sweep=False)
tester.multiworld.state.collect(tester.world.create_item("Combat Level"), prevent_sweep=False)
tester.multiworld.state.collect(tester.world.create_item("Mining Level"), prevent_sweep=False)
for i in range(17):
tester.multiworld.state.collect(tester.world.create_item("Progressive Mine Elevator"), event=False)
tester.multiworld.state.collect(tester.world.create_item("Spring"), event=False)
tester.multiworld.state.collect(tester.world.create_item("Summer"), event=False)
tester.multiworld.state.collect(tester.world.create_item("Fall"), event=False)
tester.multiworld.state.collect(tester.world.create_item("Winter"), event=False)
tester.multiworld.state.collect(tester.world.create_item(Transportation.desert_obelisk), event=False)
tester.multiworld.state.collect(tester.world.create_item("Railroad Boulder Removed"), event=False)
tester.multiworld.state.collect(tester.world.create_item("Island North Turtle"), event=False)
tester.multiworld.state.collect(tester.world.create_item("Island West Turtle"), event=False)
tester.multiworld.state.collect(tester.world.create_item("Progressive Mine Elevator"), prevent_sweep=False)
tester.multiworld.state.collect(tester.world.create_item("Spring"), prevent_sweep=False)
tester.multiworld.state.collect(tester.world.create_item("Summer"), prevent_sweep=False)
tester.multiworld.state.collect(tester.world.create_item("Fall"), prevent_sweep=False)
tester.multiworld.state.collect(tester.world.create_item("Winter"), prevent_sweep=False)
tester.multiworld.state.collect(tester.world.create_item(Transportation.desert_obelisk), prevent_sweep=False)
tester.multiworld.state.collect(tester.world.create_item("Railroad Boulder Removed"), prevent_sweep=False)
tester.multiworld.state.collect(tester.world.create_item("Island North Turtle"), prevent_sweep=False)
tester.multiworld.state.collect(tester.world.create_item("Island West Turtle"), prevent_sweep=False)


def create_and_collect(tester: SVTestBase, item_name: str) -> StardewItem:
item = tester.world.create_item(item_name)
tester.multiworld.state.collect(item, event=False)
tester.multiworld.state.collect(item, prevent_sweep=False)
return item


2 changes: 1 addition & 1 deletion worlds/stardew_valley/test/TestLogic.py
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@

def collect_all(mw):
for item in mw.get_items():
mw.state.collect(item, event=True)
mw.state.collect(item, prevent_sweep=True)


class LogicTestBase(RuleAssertMixin, TestCase):
8 changes: 4 additions & 4 deletions worlds/stardew_valley/test/__init__.py
Original file line number Diff line number Diff line change
@@ -257,16 +257,16 @@ def run_default_tests(self) -> bool:
return super().run_default_tests

def collect_lots_of_money(self):
self.multiworld.state.collect(self.world.create_item("Shipping Bin"), event=False)
self.multiworld.state.collect(self.world.create_item("Shipping Bin"), prevent_sweep=False)
required_prog_items = int(round(self.multiworld.worlds[self.player].total_progression_items * 0.25))
for i in range(required_prog_items):
self.multiworld.state.collect(self.world.create_item("Stardrop"), event=False)
self.multiworld.state.collect(self.world.create_item("Stardrop"), prevent_sweep=False)

def collect_all_the_money(self):
self.multiworld.state.collect(self.world.create_item("Shipping Bin"), event=False)
self.multiworld.state.collect(self.world.create_item("Shipping Bin"), prevent_sweep=False)
required_prog_items = int(round(self.multiworld.worlds[self.player].total_progression_items * 0.95))
for i in range(required_prog_items):
self.multiworld.state.collect(self.world.create_item("Stardrop"), event=False)
self.multiworld.state.collect(self.world.create_item("Stardrop"), prevent_sweep=False)

def collect_everything(self):
non_event_items = [item for item in self.multiworld.get_items() if item.code]
4 changes: 2 additions & 2 deletions worlds/stardew_valley/test/assertion/world_assert.py
Original file line number Diff line number Diff line change
@@ -33,14 +33,14 @@ def assert_item_was_necessary_for_victory(self, item: StardewItem, multiworld: M
self.assert_can_reach_victory(multiworld)
multiworld.state.remove(item)
self.assert_cannot_reach_victory(multiworld)
multiworld.state.collect(item, event=False)
multiworld.state.collect(item, prevent_sweep=False)
self.assert_can_reach_victory(multiworld)

def assert_item_was_not_necessary_for_victory(self, item: StardewItem, multiworld: MultiWorld):
self.assert_can_reach_victory(multiworld)
multiworld.state.remove(item)
self.assert_can_reach_victory(multiworld)
multiworld.state.collect(item, event=False)
multiworld.state.collect(item, prevent_sweep=False)
self.assert_can_reach_victory(multiworld)

def assert_can_win(self, multiworld: MultiWorld):
52 changes: 26 additions & 26 deletions worlds/stardew_valley/test/rules/TestArcades.py
Original file line number Diff line number Diff line change
@@ -19,28 +19,28 @@ def test_prairie_king(self):
life = self.create_item("JotPK: Extra Life")
drop = self.create_item("JotPK: Increased Drop Rate")

self.multiworld.state.collect(boots, event=True)
self.multiworld.state.collect(gun, event=True)
self.multiworld.state.collect(boots, prevent_sweep=True)
self.multiworld.state.collect(gun, prevent_sweep=True)
self.assertTrue(self.world.logic.region.can_reach("JotPK World 1")(self.multiworld.state))
self.assertFalse(self.world.logic.region.can_reach("JotPK World 2")(self.multiworld.state))
self.assertFalse(self.world.logic.region.can_reach("JotPK World 3")(self.multiworld.state))
self.assertFalse(self.world.logic.region.can_reach_location("Journey of the Prairie King Victory")(self.multiworld.state))
self.remove(boots)
self.remove(gun)

self.multiworld.state.collect(boots, event=True)
self.multiworld.state.collect(boots, event=True)
self.multiworld.state.collect(boots, prevent_sweep=True)
self.multiworld.state.collect(boots, prevent_sweep=True)
self.assertTrue(self.world.logic.region.can_reach("JotPK World 1")(self.multiworld.state))
self.assertFalse(self.world.logic.region.can_reach("JotPK World 2")(self.multiworld.state))
self.assertFalse(self.world.logic.region.can_reach("JotPK World 3")(self.multiworld.state))
self.assertFalse(self.world.logic.region.can_reach_location("Journey of the Prairie King Victory")(self.multiworld.state))
self.remove(boots)
self.remove(boots)

self.multiworld.state.collect(boots, event=True)
self.multiworld.state.collect(gun, event=True)
self.multiworld.state.collect(ammo, event=True)
self.multiworld.state.collect(life, event=True)
self.multiworld.state.collect(boots, prevent_sweep=True)
self.multiworld.state.collect(gun, prevent_sweep=True)
self.multiworld.state.collect(ammo, prevent_sweep=True)
self.multiworld.state.collect(life, prevent_sweep=True)
self.assertTrue(self.world.logic.region.can_reach("JotPK World 1")(self.multiworld.state))
self.assertTrue(self.world.logic.region.can_reach("JotPK World 2")(self.multiworld.state))
self.assertFalse(self.world.logic.region.can_reach("JotPK World 3")(self.multiworld.state))
@@ -50,13 +50,13 @@ def test_prairie_king(self):
self.remove(ammo)
self.remove(life)

self.multiworld.state.collect(boots, event=True)
self.multiworld.state.collect(gun, event=True)
self.multiworld.state.collect(gun, event=True)
self.multiworld.state.collect(ammo, event=True)
self.multiworld.state.collect(ammo, event=True)
self.multiworld.state.collect(life, event=True)
self.multiworld.state.collect(drop, event=True)
self.multiworld.state.collect(boots, prevent_sweep=True)
self.multiworld.state.collect(gun, prevent_sweep=True)
self.multiworld.state.collect(gun, prevent_sweep=True)
self.multiworld.state.collect(ammo, prevent_sweep=True)
self.multiworld.state.collect(ammo, prevent_sweep=True)
self.multiworld.state.collect(life, prevent_sweep=True)
self.multiworld.state.collect(drop, prevent_sweep=True)
self.assertTrue(self.world.logic.region.can_reach("JotPK World 1")(self.multiworld.state))
self.assertTrue(self.world.logic.region.can_reach("JotPK World 2")(self.multiworld.state))
self.assertTrue(self.world.logic.region.can_reach("JotPK World 3")(self.multiworld.state))
@@ -69,17 +69,17 @@ def test_prairie_king(self):
self.remove(life)
self.remove(drop)

self.multiworld.state.collect(boots, event=True)
self.multiworld.state.collect(boots, event=True)
self.multiworld.state.collect(gun, event=True)
self.multiworld.state.collect(gun, event=True)
self.multiworld.state.collect(gun, event=True)
self.multiworld.state.collect(gun, event=True)
self.multiworld.state.collect(ammo, event=True)
self.multiworld.state.collect(ammo, event=True)
self.multiworld.state.collect(ammo, event=True)
self.multiworld.state.collect(life, event=True)
self.multiworld.state.collect(drop, event=True)
self.multiworld.state.collect(boots, prevent_sweep=True)
self.multiworld.state.collect(boots, prevent_sweep=True)
self.multiworld.state.collect(gun, prevent_sweep=True)
self.multiworld.state.collect(gun, prevent_sweep=True)
self.multiworld.state.collect(gun, prevent_sweep=True)
self.multiworld.state.collect(gun, prevent_sweep=True)
self.multiworld.state.collect(ammo, prevent_sweep=True)
self.multiworld.state.collect(ammo, prevent_sweep=True)
self.multiworld.state.collect(ammo, prevent_sweep=True)
self.multiworld.state.collect(life, prevent_sweep=True)
self.multiworld.state.collect(drop, prevent_sweep=True)
self.assertTrue(self.world.logic.region.can_reach("JotPK World 1")(self.multiworld.state))
self.assertTrue(self.world.logic.region.can_reach("JotPK World 2")(self.multiworld.state))
self.assertTrue(self.world.logic.region.can_reach("JotPK World 3")(self.multiworld.state))
14 changes: 7 additions & 7 deletions worlds/stardew_valley/test/rules/TestBuildings.py
Original file line number Diff line number Diff line change
@@ -23,25 +23,25 @@ def test_big_coop_blueprint(self):
self.assertFalse(big_coop_blueprint_rule(self.multiworld.state),
f"Rule is {repr(self.multiworld.get_location('Big Coop Blueprint', self.player).access_rule)}")

self.multiworld.state.collect(self.create_item("Can Construct Buildings"), event=True)
self.multiworld.state.collect(self.create_item("Can Construct Buildings"), prevent_sweep=True)
self.assertFalse(big_coop_blueprint_rule(self.multiworld.state),
f"Rule is {repr(self.multiworld.get_location('Big Coop Blueprint', self.player).access_rule)}")

self.multiworld.state.collect(self.create_item("Progressive Coop"), event=False)
self.multiworld.state.collect(self.create_item("Progressive Coop"), prevent_sweep=False)
self.assertTrue(big_coop_blueprint_rule(self.multiworld.state),
f"Rule is {repr(self.multiworld.get_location('Big Coop Blueprint', self.player).access_rule)}")

def test_deluxe_coop_blueprint(self):
self.assertFalse(self.world.logic.region.can_reach_location("Deluxe Coop Blueprint")(self.multiworld.state))

self.collect_lots_of_money()
self.multiworld.state.collect(self.create_item("Can Construct Buildings"), event=True)
self.multiworld.state.collect(self.create_item("Can Construct Buildings"), prevent_sweep=True)
self.assertFalse(self.world.logic.region.can_reach_location("Deluxe Coop Blueprint")(self.multiworld.state))

self.multiworld.state.collect(self.create_item("Progressive Coop"), event=True)
self.multiworld.state.collect(self.create_item("Progressive Coop"), prevent_sweep=True)
self.assertFalse(self.world.logic.region.can_reach_location("Deluxe Coop Blueprint")(self.multiworld.state))

self.multiworld.state.collect(self.create_item("Progressive Coop"), event=True)
self.multiworld.state.collect(self.create_item("Progressive Coop"), prevent_sweep=True)
self.assertTrue(self.world.logic.region.can_reach_location("Deluxe Coop Blueprint")(self.multiworld.state))

def test_big_shed_blueprint(self):
@@ -53,10 +53,10 @@ def test_big_shed_blueprint(self):
self.assertFalse(big_shed_rule(self.multiworld.state),
f"Rule is {repr(self.multiworld.get_location('Big Shed Blueprint', self.player).access_rule)}")

self.multiworld.state.collect(self.create_item("Can Construct Buildings"), event=True)
self.multiworld.state.collect(self.create_item("Can Construct Buildings"), prevent_sweep=True)
self.assertFalse(big_shed_rule(self.multiworld.state),
f"Rule is {repr(self.multiworld.get_location('Big Shed Blueprint', self.player).access_rule)}")

self.multiworld.state.collect(self.create_item("Progressive Shed"), event=True)
self.multiworld.state.collect(self.create_item("Progressive Shed"), prevent_sweep=True)
self.assertTrue(big_shed_rule(self.multiworld.state),
f"Rule is {repr(self.multiworld.get_location('Big Shed Blueprint', self.player).access_rule)}")
Loading

0 comments on commit 96d48a9

Please sign in to comment.