Skip to content

Commit

Permalink
add randomizable option set and make some option set randomized in th…
Browse files Browse the repository at this point in the history
…e preset
  • Loading branch information
Jouramie committed Dec 14, 2024
1 parent ccea6bc commit d5409f2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
38 changes: 27 additions & 11 deletions worlds/stardew_valley/options/options.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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 %
Expand Down
2 changes: 2 additions & 0 deletions worlds/stardew_valley/options/presets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit d5409f2

Please sign in to comment.