Skip to content

Commit

Permalink
Merge branch 'main' into wargroove2
Browse files Browse the repository at this point in the history
  • Loading branch information
FlySniper authored Aug 16, 2024
2 parents 24fcb0f + 56aabe5 commit 121a74a
Show file tree
Hide file tree
Showing 30 changed files with 367 additions and 364 deletions.
10 changes: 3 additions & 7 deletions BaseClasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1427,7 +1423,7 @@ def get_path(state: CollectionState, region: Region) -> List[Union[Tuple[str, st
# Maybe move the big bomb over to the Event system instead?
if any(exit_path == 'Pyramid Fairy' for path in self.paths.values()
for (_, exit_path) in path):
if multiworld.mode[player] != 'inverted':
if multiworld.worlds[player].options.mode != 'inverted':
self.paths[str(multiworld.get_region('Big Bomb Shop', player))] = \
get_path(state, multiworld.get_region('Big Bomb Shop', player))
else:
Expand Down
19 changes: 13 additions & 6 deletions Fill.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@


class FillError(RuntimeError):
pass
def __init__(self, *args: typing.Union[str, typing.Any], **kwargs) -> None:
if "multiworld" in kwargs and isinstance(args[0], str):
placements = (args[0] + f"\nAll Placements:\n" +
f"{[(loc, loc.item) for loc in kwargs['multiworld'].get_filled_locations()]}")
args = (placements, *args[1:])
super().__init__(*args)


def _log_fill_progress(name: str, placed: int, total_items: int) -> None:
Expand Down Expand Up @@ -212,7 +217,7 @@ def fill_restrictive(multiworld: MultiWorld, base_state: CollectionState, locati
f"Unfilled locations:\n"
f"{', '.join(str(location) for location in locations)}\n"
f"Already placed {len(placements)}:\n"
f"{', '.join(str(place) for place in placements)}")
f"{', '.join(str(place) for place in placements)}", multiworld=multiworld)

item_pool.extend(unplaced_items)

Expand Down Expand Up @@ -299,7 +304,7 @@ def remaining_fill(multiworld: MultiWorld,
f"Unfilled locations:\n"
f"{', '.join(str(location) for location in locations)}\n"
f"Already placed {len(placements)}:\n"
f"{', '.join(str(place) for place in placements)}")
f"{', '.join(str(place) for place in placements)}", multiworld=multiworld)

itempool.extend(unplaced_items)

Expand Down Expand Up @@ -506,7 +511,8 @@ def mark_for_locking(location: Location):
if progitempool:
raise FillError(
f"Not enough locations for progression items. "
f"There are {len(progitempool)} more progression items than there are available locations."
f"There are {len(progitempool)} more progression items than there are available locations.",
multiworld=multiworld,
)
accessibility_corrections(multiworld, multiworld.state, defaultlocations)

Expand All @@ -523,7 +529,8 @@ def mark_for_locking(location: Location):
if excludedlocations:
raise FillError(
f"Not enough filler items for excluded locations. "
f"There are {len(excludedlocations)} more excluded locations than filler or trap items."
f"There are {len(excludedlocations)} more excluded locations than filler or trap items.",
multiworld=multiworld,
)

restitempool = filleritempool + usefulitempool
Expand Down Expand Up @@ -589,7 +596,7 @@ def flood_items(multiworld: MultiWorld) -> None:
if candidate_item_to_place is not None:
item_to_place = candidate_item_to_place
else:
raise FillError('No more progress items left to place.')
raise FillError('No more progress items left to place.', multiworld=multiworld)

# find item to replace with progress item
location_list = multiworld.get_reachable_locations()
Expand Down
2 changes: 1 addition & 1 deletion Launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def _on_drop_file(self, window: Window, filename: bytes, x: int, y: int) -> None
if file and component:
run_component(component, file)
else:
logging.warning(f"unable to identify component for {filename}")
logging.warning(f"unable to identify component for {file}")

def _stop(self, *largs):
# ran into what appears to be https://groups.google.com/g/kivy-users/c/saWDLoYCSZ4 with PyCharm.
Expand Down
5 changes: 3 additions & 2 deletions Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

import worlds
from BaseClasses import CollectionState, Item, Location, LocationProgressType, MultiWorld, Region
from Fill import balance_multiworld_progression, distribute_items_restrictive, distribute_planned, flood_items
from Fill import FillError, balance_multiworld_progression, distribute_items_restrictive, distribute_planned, \
flood_items
from Options import StartInventoryPool
from Utils import __version__, output_path, version_tuple, get_settings
from settings import get_settings
Expand Down Expand Up @@ -346,7 +347,7 @@ def precollect_hint(location):
output_file_futures.append(pool.submit(write_multidata))
if not check_accessibility_task.result():
if not multiworld.can_beat_game():
raise Exception("Game appears as unbeatable. Aborting.")
raise FillError("Game appears as unbeatable. Aborting.", multiworld=multiworld)
else:
logger.warning("Location Accessibility requirements not fulfilled.")

Expand Down
2 changes: 1 addition & 1 deletion WebHostLib/templates/weightedOptions/macros.html
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
id="{{ option_name }}-{{ key }}"
name="{{ option_name }}||{{ key }}"
value="1"
checked="{{ "checked" if key in option.default else "" }}"
{{ "checked" if key in option.default }}
/>
<label for="{{ option_name }}-{{ key }}">
{{ key }}
Expand Down
2 changes: 1 addition & 1 deletion test/bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions test/multiworld/test_multiworlds.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_fills(self) -> None:
all_worlds = list(AutoWorldRegister.world_types.values())
self.multiworld = setup_multiworld(all_worlds, ())
for world in self.multiworld.worlds.values():
world.options.accessibility.value = Accessibility.option_locations
world.options.accessibility.value = Accessibility.option_full
self.assertSteps(gen_steps)
with self.subTest("filling multiworld", seed=self.multiworld.seed):
distribute_items_restrictive(self.multiworld)
Expand All @@ -66,8 +66,8 @@ def test_fills(self) -> None:
class TestTwoPlayerMulti(MultiworldTestBase):
def test_two_player_single_game_fills(self) -> None:
"""Tests that a multiworld of two players for each registered game world can generate."""
for world in AutoWorldRegister.world_types.values():
self.multiworld = setup_multiworld([world, world], ())
for world_type in AutoWorldRegister.world_types.values():
self.multiworld = setup_multiworld([world_type, world_type], ())
for world in self.multiworld.worlds.values():
world.options.accessibility.value = Accessibility.option_full
self.assertSteps(gen_steps)
Expand Down
4 changes: 2 additions & 2 deletions worlds/alttp/test/dungeons/TestDungeon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion worlds/oot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions worlds/stardew_valley/logic/fishing_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from ..options import SpecialOrderLocations
from ..stardew_rule import StardewRule, True_, False_
from ..strings.ap_names.mods.mod_items import SVEQuestItem
from ..strings.craftable_names import Fishing
from ..strings.fish_names import SVEFish
from ..strings.machine_names import Machine
from ..strings.quality_names import FishQuality
Expand Down Expand Up @@ -74,16 +75,18 @@ def can_start_extended_family_quest(self) -> StardewRule:
def can_catch_quality_fish(self, fish_quality: str) -> StardewRule:
if fish_quality == FishQuality.basic:
return True_()
rod_rule = self.logic.tool.has_fishing_rod(2)
if fish_quality == FishQuality.silver:
return rod_rule
return self.logic.tool.has_fishing_rod(2)
if fish_quality == FishQuality.gold:
return rod_rule & self.logic.skill.has_level(Skill.fishing, 4)
return self.logic.skill.has_level(Skill.fishing, 4) & self.can_use_tackle(Fishing.quality_bobber)
if fish_quality == FishQuality.iridium:
return rod_rule & self.logic.skill.has_level(Skill.fishing, 10)
return self.logic.skill.has_level(Skill.fishing, 10) & self.can_use_tackle(Fishing.quality_bobber)

raise ValueError(f"Quality {fish_quality} is unknown.")

def can_use_tackle(self, tackle: str) -> StardewRule:
return self.logic.tool.has_fishing_rod(4) & self.logic.has(tackle)

def can_catch_every_fish(self) -> StardewRule:
rules = [self.has_max_fishing()]

Expand Down
8 changes: 4 additions & 4 deletions worlds/stardew_valley/test/TestCrops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion worlds/stardew_valley/test/TestLogic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 4 additions & 4 deletions worlds/stardew_valley/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions worlds/stardew_valley/test/assertion/world_assert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading

0 comments on commit 121a74a

Please sign in to comment.