2023-02-26 19:19:15 -05:00
|
|
|
import random
|
|
|
|
import unittest
|
2024-03-15 15:05:14 +03:00
|
|
|
from typing import Set
|
2023-02-26 19:19:15 -05:00
|
|
|
|
2024-03-15 15:05:14 +03:00
|
|
|
from BaseClasses import get_seed
|
2025-05-13 03:58:03 -04:00
|
|
|
from .bases import SVTestCase
|
2024-12-08 21:00:30 -05:00
|
|
|
from .options.utils import fill_dataclass_with_default
|
2024-11-30 21:52:07 -05:00
|
|
|
from .. import create_content
|
Stardew Valley 6.x.x: The Content Update (#3478)
Focus of the Update: Compatibility with Stardew Valley 1.6 Released on March 19th 2024
This includes randomization for pretty much all of the new content, including but not limited to
- Raccoon Bundles
- Booksanity
- Skill Masteries
- New Recipes, Craftables, Fish, Maps, Farm Type, Festivals and Quests
This also includes a significant reorganisation of the code into "Content Packs", to allow for easier modularity of various game mechanics between the settings and the supported mods. This improves maintainability quite a bit.
In addition to that, a few **very** requested new features have been introduced, although they weren't the focus of this update
- Walnutsanity
- Player Buffs
- More customizability in settings, such as shorter special orders, ER without farmhouse
- New Remixed Bundles
2024-07-07 16:04:25 +03:00
|
|
|
from ..options import EntranceRandomization, ExcludeGingerIsland, SkillProgression
|
2024-03-15 15:05:14 +03:00
|
|
|
from ..regions import vanilla_regions, vanilla_connections, randomize_connections, RandomizationFlag, create_final_connections_and_regions
|
|
|
|
from ..strings.entrance_names import Entrance as EntranceName
|
|
|
|
from ..strings.region_names import Region as RegionName
|
2023-02-26 19:19:15 -05:00
|
|
|
|
2023-07-19 14:26:38 -04:00
|
|
|
connections_by_name = {connection.name for connection in vanilla_connections}
|
|
|
|
regions_by_name = {region.name for region in vanilla_regions}
|
2023-02-26 19:19:15 -05:00
|
|
|
|
|
|
|
|
|
|
|
class TestRegions(unittest.TestCase):
|
|
|
|
def test_region_exits_lead_somewhere(self):
|
2023-07-19 14:26:38 -04:00
|
|
|
for region in vanilla_regions:
|
2023-02-26 19:19:15 -05:00
|
|
|
with self.subTest(region=region):
|
|
|
|
for exit in region.exits:
|
2023-07-19 14:26:38 -04:00
|
|
|
self.assertIn(exit, connections_by_name,
|
|
|
|
f"{region.name} is leading to {exit} but it does not exist.")
|
2023-02-26 19:19:15 -05:00
|
|
|
|
|
|
|
def test_connection_lead_somewhere(self):
|
2023-07-19 14:26:38 -04:00
|
|
|
for connection in vanilla_connections:
|
2023-02-26 19:19:15 -05:00
|
|
|
with self.subTest(connection=connection):
|
2023-07-19 14:26:38 -04:00
|
|
|
self.assertIn(connection.destination, regions_by_name,
|
|
|
|
f"{connection.name} is leading to {connection.destination} but it does not exist.")
|
2023-02-26 19:19:15 -05:00
|
|
|
|
|
|
|
|
2024-03-15 15:05:14 +03:00
|
|
|
def explore_connections_tree_up_to_blockers(blocked_entrances: Set[str], connections_by_name, regions_by_name):
|
|
|
|
explored_entrances = set()
|
|
|
|
explored_regions = set()
|
|
|
|
entrances_to_explore = set()
|
|
|
|
current_node_name = "Menu"
|
|
|
|
current_node = regions_by_name[current_node_name]
|
|
|
|
entrances_to_explore.update(current_node.exits)
|
|
|
|
while entrances_to_explore:
|
|
|
|
current_entrance_name = entrances_to_explore.pop()
|
|
|
|
current_entrance = connections_by_name[current_entrance_name]
|
|
|
|
current_node_name = current_entrance.destination
|
|
|
|
|
|
|
|
explored_entrances.add(current_entrance_name)
|
|
|
|
explored_regions.add(current_node_name)
|
|
|
|
|
|
|
|
if current_entrance_name in blocked_entrances:
|
|
|
|
continue
|
|
|
|
|
|
|
|
current_node = regions_by_name[current_node_name]
|
|
|
|
entrances_to_explore.update({entrance for entrance in current_node.exits if entrance not in explored_entrances})
|
|
|
|
return explored_regions
|
|
|
|
|
|
|
|
|
|
|
|
class TestEntranceRando(SVTestCase):
|
2023-02-26 19:19:15 -05:00
|
|
|
|
2023-07-19 14:26:38 -04:00
|
|
|
def test_entrance_randomization(self):
|
2024-03-15 15:05:14 +03:00
|
|
|
for option, flag in [(EntranceRandomization.option_pelican_town, RandomizationFlag.PELICAN_TOWN),
|
|
|
|
(EntranceRandomization.option_non_progression, RandomizationFlag.NON_PROGRESSION),
|
Stardew Valley 6.x.x: The Content Update (#3478)
Focus of the Update: Compatibility with Stardew Valley 1.6 Released on March 19th 2024
This includes randomization for pretty much all of the new content, including but not limited to
- Raccoon Bundles
- Booksanity
- Skill Masteries
- New Recipes, Craftables, Fish, Maps, Farm Type, Festivals and Quests
This also includes a significant reorganisation of the code into "Content Packs", to allow for easier modularity of various game mechanics between the settings and the supported mods. This improves maintainability quite a bit.
In addition to that, a few **very** requested new features have been introduced, although they weren't the focus of this update
- Walnutsanity
- Player Buffs
- More customizability in settings, such as shorter special orders, ER without farmhouse
- New Remixed Bundles
2024-07-07 16:04:25 +03:00
|
|
|
(EntranceRandomization.option_buildings_without_house, RandomizationFlag.BUILDINGS),
|
2024-03-15 15:05:14 +03:00
|
|
|
(EntranceRandomization.option_buildings, RandomizationFlag.BUILDINGS)]:
|
2024-12-08 21:00:30 -05:00
|
|
|
sv_options = fill_dataclass_with_default({
|
2024-03-15 15:05:14 +03:00
|
|
|
EntranceRandomization.internal_name: option,
|
Stardew Valley 6.x.x: The Content Update (#3478)
Focus of the Update: Compatibility with Stardew Valley 1.6 Released on March 19th 2024
This includes randomization for pretty much all of the new content, including but not limited to
- Raccoon Bundles
- Booksanity
- Skill Masteries
- New Recipes, Craftables, Fish, Maps, Farm Type, Festivals and Quests
This also includes a significant reorganisation of the code into "Content Packs", to allow for easier modularity of various game mechanics between the settings and the supported mods. This improves maintainability quite a bit.
In addition to that, a few **very** requested new features have been introduced, although they weren't the focus of this update
- Walnutsanity
- Player Buffs
- More customizability in settings, such as shorter special orders, ER without farmhouse
- New Remixed Bundles
2024-07-07 16:04:25 +03:00
|
|
|
ExcludeGingerIsland.internal_name: ExcludeGingerIsland.option_false,
|
|
|
|
SkillProgression.internal_name: SkillProgression.option_progressive_with_masteries,
|
2024-03-15 15:05:14 +03:00
|
|
|
})
|
2024-11-30 21:52:07 -05:00
|
|
|
content = create_content(sv_options)
|
2024-03-15 15:05:14 +03:00
|
|
|
seed = get_seed()
|
|
|
|
rand = random.Random(seed)
|
2023-07-19 14:26:38 -04:00
|
|
|
with self.subTest(flag=flag, msg=f"Seed: {seed}"):
|
2024-03-15 15:05:14 +03:00
|
|
|
entrances, regions = create_final_connections_and_regions(sv_options)
|
2024-11-30 21:52:07 -05:00
|
|
|
_, randomized_connections = randomize_connections(rand, sv_options, content, regions, entrances)
|
2023-07-19 14:26:38 -04:00
|
|
|
|
|
|
|
for connection in vanilla_connections:
|
|
|
|
if flag in connection.flag:
|
|
|
|
connection_in_randomized = connection.name in randomized_connections
|
|
|
|
reverse_in_randomized = connection.reverse in randomized_connections
|
2024-03-15 15:05:14 +03:00
|
|
|
self.assertTrue(connection_in_randomized, f"Connection {connection.name} should be randomized but it is not in the output.")
|
|
|
|
self.assertTrue(reverse_in_randomized, f"Connection {connection.reverse} should be randomized but it is not in the output.")
|
2023-07-19 14:26:38 -04:00
|
|
|
|
|
|
|
self.assertEqual(len(set(randomized_connections.values())), len(randomized_connections.values()),
|
2024-03-15 15:05:14 +03:00
|
|
|
f"Connections are duplicated in randomization.")
|
2023-07-19 14:26:38 -04:00
|
|
|
|
|
|
|
def test_entrance_randomization_without_island(self):
|
2024-03-15 15:05:14 +03:00
|
|
|
for option, flag in [(EntranceRandomization.option_pelican_town, RandomizationFlag.PELICAN_TOWN),
|
|
|
|
(EntranceRandomization.option_non_progression, RandomizationFlag.NON_PROGRESSION),
|
Stardew Valley 6.x.x: The Content Update (#3478)
Focus of the Update: Compatibility with Stardew Valley 1.6 Released on March 19th 2024
This includes randomization for pretty much all of the new content, including but not limited to
- Raccoon Bundles
- Booksanity
- Skill Masteries
- New Recipes, Craftables, Fish, Maps, Farm Type, Festivals and Quests
This also includes a significant reorganisation of the code into "Content Packs", to allow for easier modularity of various game mechanics between the settings and the supported mods. This improves maintainability quite a bit.
In addition to that, a few **very** requested new features have been introduced, although they weren't the focus of this update
- Walnutsanity
- Player Buffs
- More customizability in settings, such as shorter special orders, ER without farmhouse
- New Remixed Bundles
2024-07-07 16:04:25 +03:00
|
|
|
(EntranceRandomization.option_buildings_without_house, RandomizationFlag.BUILDINGS),
|
2024-03-15 15:05:14 +03:00
|
|
|
(EntranceRandomization.option_buildings, RandomizationFlag.BUILDINGS)]:
|
|
|
|
|
2024-12-08 21:00:30 -05:00
|
|
|
sv_options = fill_dataclass_with_default({
|
2024-03-15 15:05:14 +03:00
|
|
|
EntranceRandomization.internal_name: option,
|
Stardew Valley 6.x.x: The Content Update (#3478)
Focus of the Update: Compatibility with Stardew Valley 1.6 Released on March 19th 2024
This includes randomization for pretty much all of the new content, including but not limited to
- Raccoon Bundles
- Booksanity
- Skill Masteries
- New Recipes, Craftables, Fish, Maps, Farm Type, Festivals and Quests
This also includes a significant reorganisation of the code into "Content Packs", to allow for easier modularity of various game mechanics between the settings and the supported mods. This improves maintainability quite a bit.
In addition to that, a few **very** requested new features have been introduced, although they weren't the focus of this update
- Walnutsanity
- Player Buffs
- More customizability in settings, such as shorter special orders, ER without farmhouse
- New Remixed Bundles
2024-07-07 16:04:25 +03:00
|
|
|
ExcludeGingerIsland.internal_name: ExcludeGingerIsland.option_true,
|
|
|
|
SkillProgression.internal_name: SkillProgression.option_progressive_with_masteries,
|
2024-03-15 15:05:14 +03:00
|
|
|
})
|
2024-11-30 21:52:07 -05:00
|
|
|
content = create_content(sv_options)
|
2024-03-15 15:05:14 +03:00
|
|
|
seed = get_seed()
|
|
|
|
rand = random.Random(seed)
|
|
|
|
with self.subTest(option=option, flag=flag, seed=seed):
|
|
|
|
entrances, regions = create_final_connections_and_regions(sv_options)
|
2024-11-30 21:52:07 -05:00
|
|
|
_, randomized_connections = randomize_connections(rand, sv_options, content, regions, entrances)
|
2023-02-26 19:19:15 -05:00
|
|
|
|
2023-07-19 14:26:38 -04:00
|
|
|
for connection in vanilla_connections:
|
2023-02-26 19:19:15 -05:00
|
|
|
if flag in connection.flag:
|
2023-07-19 14:26:38 -04:00
|
|
|
if RandomizationFlag.GINGER_ISLAND in connection.flag:
|
|
|
|
self.assertNotIn(connection.name, randomized_connections,
|
2024-03-15 15:05:14 +03:00
|
|
|
f"Connection {connection.name} should not be randomized but it is in the output.")
|
2023-07-19 14:26:38 -04:00
|
|
|
self.assertNotIn(connection.reverse, randomized_connections,
|
2024-03-15 15:05:14 +03:00
|
|
|
f"Connection {connection.reverse} should not be randomized but it is in the output.")
|
2023-07-19 14:26:38 -04:00
|
|
|
else:
|
|
|
|
self.assertIn(connection.name, randomized_connections,
|
2024-03-15 15:05:14 +03:00
|
|
|
f"Connection {connection.name} should be randomized but it is not in the output.")
|
2023-07-19 14:26:38 -04:00
|
|
|
self.assertIn(connection.reverse, randomized_connections,
|
2024-03-15 15:05:14 +03:00
|
|
|
f"Connection {connection.reverse} should be randomized but it is not in the output.")
|
2023-02-26 19:19:15 -05:00
|
|
|
|
2023-07-19 14:26:38 -04:00
|
|
|
self.assertEqual(len(set(randomized_connections.values())), len(randomized_connections.values()),
|
2024-03-15 15:05:14 +03:00
|
|
|
f"Connections are duplicated in randomization.")
|
|
|
|
|
|
|
|
def test_cannot_put_island_access_on_island(self):
|
2024-12-08 21:00:30 -05:00
|
|
|
sv_options = fill_dataclass_with_default({
|
2024-03-15 15:05:14 +03:00
|
|
|
EntranceRandomization.internal_name: EntranceRandomization.option_buildings,
|
Stardew Valley 6.x.x: The Content Update (#3478)
Focus of the Update: Compatibility with Stardew Valley 1.6 Released on March 19th 2024
This includes randomization for pretty much all of the new content, including but not limited to
- Raccoon Bundles
- Booksanity
- Skill Masteries
- New Recipes, Craftables, Fish, Maps, Farm Type, Festivals and Quests
This also includes a significant reorganisation of the code into "Content Packs", to allow for easier modularity of various game mechanics between the settings and the supported mods. This improves maintainability quite a bit.
In addition to that, a few **very** requested new features have been introduced, although they weren't the focus of this update
- Walnutsanity
- Player Buffs
- More customizability in settings, such as shorter special orders, ER without farmhouse
- New Remixed Bundles
2024-07-07 16:04:25 +03:00
|
|
|
ExcludeGingerIsland.internal_name: ExcludeGingerIsland.option_false,
|
|
|
|
SkillProgression.internal_name: SkillProgression.option_progressive_with_masteries,
|
2024-03-15 15:05:14 +03:00
|
|
|
})
|
2024-11-30 21:52:07 -05:00
|
|
|
content = create_content(sv_options)
|
2024-03-15 15:05:14 +03:00
|
|
|
|
|
|
|
for i in range(0, 100 if self.skip_long_tests else 10000):
|
|
|
|
seed = get_seed()
|
|
|
|
rand = random.Random(seed)
|
|
|
|
with self.subTest(msg=f"Seed: {seed}"):
|
|
|
|
entrances, regions = create_final_connections_and_regions(sv_options)
|
2024-11-30 21:52:07 -05:00
|
|
|
randomized_connections, randomized_data = randomize_connections(rand, sv_options, content, regions, entrances)
|
2024-03-15 15:05:14 +03:00
|
|
|
connections_by_name = {connection.name: connection for connection in randomized_connections}
|
|
|
|
|
|
|
|
blocked_entrances = {EntranceName.use_island_obelisk, EntranceName.boat_to_ginger_island}
|
|
|
|
required_regions = {RegionName.wizard_tower, RegionName.boat_tunnel}
|
|
|
|
self.assert_can_reach_any_region_before_blockers(required_regions, blocked_entrances, connections_by_name, regions)
|
|
|
|
|
|
|
|
def assert_can_reach_any_region_before_blockers(self, required_regions, blocked_entrances, connections_by_name, regions_by_name):
|
|
|
|
explored_regions = explore_connections_tree_up_to_blockers(blocked_entrances, connections_by_name, regions_by_name)
|
|
|
|
self.assertTrue(any(region in explored_regions for region in required_regions))
|
2023-07-19 19:20:52 -04:00
|
|
|
|
|
|
|
|
2023-10-28 00:18:33 +02:00
|
|
|
class TestEntranceClassifications(SVTestCase):
|
2023-07-19 19:20:52 -04:00
|
|
|
|
|
|
|
def test_non_progression_are_all_accessible_with_empty_inventory(self):
|
2024-03-15 15:05:14 +03:00
|
|
|
for option, flag in [(EntranceRandomization.option_pelican_town, RandomizationFlag.PELICAN_TOWN),
|
|
|
|
(EntranceRandomization.option_non_progression, RandomizationFlag.NON_PROGRESSION)]:
|
|
|
|
world_options = {
|
|
|
|
EntranceRandomization.internal_name: option
|
|
|
|
}
|
|
|
|
with self.solo_world_sub_test(world_options=world_options, flag=flag) as (multiworld, sv_world):
|
2023-07-19 19:20:52 -04:00
|
|
|
ap_entrances = {entrance.name: entrance for entrance in multiworld.get_entrances()}
|
|
|
|
for randomized_entrance in sv_world.randomized_entrances:
|
|
|
|
if randomized_entrance in ap_entrances:
|
|
|
|
ap_entrance_origin = ap_entrances[randomized_entrance]
|
|
|
|
self.assertTrue(ap_entrance_origin.access_rule(multiworld.state))
|
|
|
|
if sv_world.randomized_entrances[randomized_entrance] in ap_entrances:
|
|
|
|
ap_entrance_destination = multiworld.get_entrance(sv_world.randomized_entrances[randomized_entrance], 1)
|
|
|
|
self.assertTrue(ap_entrance_destination.access_rule(multiworld.state))
|
2024-03-15 15:05:14 +03:00
|
|
|
|
|
|
|
def test_no_ginger_island_entrances_when_excluded(self):
|
|
|
|
world_options = {
|
|
|
|
EntranceRandomization.internal_name: EntranceRandomization.option_disabled,
|
|
|
|
ExcludeGingerIsland.internal_name: ExcludeGingerIsland.option_true
|
|
|
|
}
|
|
|
|
with self.solo_world_sub_test(world_options=world_options) as (multiworld, _):
|
|
|
|
ap_entrances = {entrance.name: entrance for entrance in multiworld.get_entrances()}
|
|
|
|
entrance_data_by_name = {entrance.name: entrance for entrance in vanilla_connections}
|
|
|
|
for entrance_name in ap_entrances:
|
|
|
|
entrance_data = entrance_data_by_name[entrance_name]
|
|
|
|
with self.subTest(f"{entrance_name}: {entrance_data.flag}"):
|
|
|
|
self.assertFalse(entrance_data.flag & RandomizationFlag.GINGER_ISLAND)
|