From d5409f226d17010d12ef26d501deb419a4dded05 Mon Sep 17 00:00:00 2001 From: Jouramie <16137441+Jouramie@users.noreply.github.com> Date: Sat, 14 Dec 2024 01:23:56 -0500 Subject: [PATCH] add randomizable option set and make some option set randomized in the preset --- worlds/stardew_valley/options/options.py | 38 +++++++++++++++++------- worlds/stardew_valley/options/presets.py | 2 ++ 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/worlds/stardew_valley/options/options.py b/worlds/stardew_valley/options/options.py index 5d3b25b4da13..de93fbe1a592 100644 --- a/worlds/stardew_valley/options/options.py +++ b/worlds/stardew_valley/options/options.py @@ -1,9 +1,9 @@ +import random import sys -import typing from dataclasses import dataclass from typing import Protocol, ClassVar -from Options import Range, NamedRange, Toggle, Choice, OptionSet, PerGameCommonOptions, DeathLink, OptionList, Visibility +from Options import Range, NamedRange, Toggle, Choice, OptionSet, PerGameCommonOptions, DeathLink, Visibility from ..mods.mod_data import ModNames from ..strings.ap_names.ap_option_names import BuffOptionName, WalnutsanityOptionName from ..strings.bundle_names import all_cc_bundle_names @@ -13,6 +13,25 @@ class StardewValleyOption(Protocol): internal_name: ClassVar[str] +class RandomizableOptionSet(OptionSet): + + @classmethod + def from_text(cls, text: str): + if text == "random": + return cls.roll_random() + return super().from_text(text) + + @classmethod + def roll_random(cls): + """By default, each possible option has a 50% chance of being enabled""" + enabled_options = [] + for key in cls.valid_keys: + if random.randint(0, 1): + enabled_options.append(key) + + raise cls(enabled_options) + + class Goal(Choice): """Goal for this playthrough Community Center: Complete the Community Center @@ -573,7 +592,7 @@ class Booksanity(Choice): option_all = 3 -class Walnutsanity(OptionSet): +class Walnutsanity(RandomizableOptionSet): """Shuffle walnuts? Puzzles: Walnuts obtained from solving a special puzzle or winning a minigame Bushes: Walnuts that are in a bush and can be collected by clicking it @@ -590,13 +609,10 @@ class Walnutsanity(OptionSet): preset_all = valid_keys default = preset_none - def __eq__(self, other: typing.Any) -> bool: - if isinstance(other, OptionSet): - return set(self.value) == other.value - if isinstance(other, OptionList): - return set(self.value) == set(other.value) - else: - return typing.cast(bool, self.value == other) + @classmethod + def roll_random(cls): + choice = random.choice([[], [WalnutsanityOptionName.puzzles], cls.valid_keys]) + return cls(choice) class NumberOfMovementBuffs(Range): @@ -610,7 +626,7 @@ class NumberOfMovementBuffs(Range): # step = 1 -class EnabledFillerBuffs(OptionSet): +class EnabledFillerBuffs(RandomizableOptionSet): """Enable various permanent player buffs to roll as filler items Luck: Increase daily luck Damage: Increased Damage % diff --git a/worlds/stardew_valley/options/presets.py b/worlds/stardew_valley/options/presets.py index c2c210e5ca6e..f451dd1a8f86 100644 --- a/worlds/stardew_valley/options/presets.py +++ b/worlds/stardew_valley/options/presets.py @@ -36,7 +36,9 @@ options.Friendsanity.internal_name: "random", options.FriendsanityHeartSize.internal_name: "random", options.Booksanity.internal_name: "random", + options.Walnutsanity.internal_name: "random", options.NumberOfMovementBuffs.internal_name: "random", + options.EnabledFillerBuffs.internal_name: "random", options.ExcludeGingerIsland.internal_name: "random", options.TrapItems.internal_name: "random", options.MultipleDaySleepEnabled.internal_name: "random",