mirror of
https://github.com/MarioSpore/Grinch-AP.git
synced 2025-10-21 20:21:32 -06:00
Timespinner: migrate to new options api and correct random (#2485)
* Implemented new options system into Timespinner * Fixed typo * Fixed typo * Fixed slotdata maybe * Fixes * more fixes * Fixed failing unit tests * Implemented options backwards comnpatibility * Fixed option fallbacks * Implemented review results * Fixed logic bug * Fixed python 3.8/3.9 compatibility * Replaced one more multiworld option usage * Update worlds/timespinner/Options.py Co-authored-by: Exempt-Medic <60412657+Exempt-Medic@users.noreply.github.com> * Updated logging of options replacement to include player name and also write it to spoiler Fixed generation bug Implemented review results --------- Co-authored-by: Exempt-Medic <60412657+Exempt-Medic@users.noreply.github.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from typing import Tuple, Dict, Union, List
|
||||
from BaseClasses import MultiWorld
|
||||
from .Options import timespinner_options, is_option_enabled, get_option_value
|
||||
from random import Random
|
||||
from .Options import TimespinnerOptions
|
||||
|
||||
class PreCalculatedWeights:
|
||||
pyramid_keys_unlock: str
|
||||
@@ -21,22 +21,22 @@ class PreCalculatedWeights:
|
||||
flood_lake_serene_bridge: bool
|
||||
flood_lab: bool
|
||||
|
||||
def __init__(self, world: MultiWorld, player: int):
|
||||
if world and is_option_enabled(world, player, "RisingTides"):
|
||||
weights_overrrides: Dict[str, Union[str, Dict[str, int]]] = self.get_flood_weights_overrides(world, player)
|
||||
def __init__(self, options: TimespinnerOptions, random: Random):
|
||||
if options.rising_tides:
|
||||
weights_overrrides: Dict[str, Union[str, Dict[str, int]]] = self.get_flood_weights_overrides(options)
|
||||
|
||||
self.flood_basement, self.flood_basement_high = \
|
||||
self.roll_flood_setting(world, player, weights_overrrides, "CastleBasement")
|
||||
self.flood_xarion, _ = self.roll_flood_setting(world, player, weights_overrrides, "Xarion")
|
||||
self.flood_maw, _ = self.roll_flood_setting(world, player, weights_overrrides, "Maw")
|
||||
self.flood_pyramid_shaft, _ = self.roll_flood_setting(world, player, weights_overrrides, "AncientPyramidShaft")
|
||||
self.flood_pyramid_back, _ = self.roll_flood_setting(world, player, weights_overrrides, "Sandman")
|
||||
self.flood_moat, _ = self.roll_flood_setting(world, player, weights_overrrides, "CastleMoat")
|
||||
self.flood_courtyard, _ = self.roll_flood_setting(world, player, weights_overrrides, "CastleCourtyard")
|
||||
self.flood_lake_desolation, _ = self.roll_flood_setting(world, player, weights_overrrides, "LakeDesolation")
|
||||
self.flood_lake_serene, _ = self.roll_flood_setting(world, player, weights_overrrides, "LakeSerene")
|
||||
self.flood_lake_serene_bridge, _ = self.roll_flood_setting(world, player, weights_overrrides, "LakeSereneBridge")
|
||||
self.flood_lab, _ = self.roll_flood_setting(world, player, weights_overrrides, "Lab")
|
||||
self.roll_flood_setting(random, weights_overrrides, "CastleBasement")
|
||||
self.flood_xarion, _ = self.roll_flood_setting(random, weights_overrrides, "Xarion")
|
||||
self.flood_maw, _ = self.roll_flood_setting(random, weights_overrrides, "Maw")
|
||||
self.flood_pyramid_shaft, _ = self.roll_flood_setting(random, weights_overrrides, "AncientPyramidShaft")
|
||||
self.flood_pyramid_back, _ = self.roll_flood_setting(random, weights_overrrides, "Sandman")
|
||||
self.flood_moat, _ = self.roll_flood_setting(random, weights_overrrides, "CastleMoat")
|
||||
self.flood_courtyard, _ = self.roll_flood_setting(random, weights_overrrides, "CastleCourtyard")
|
||||
self.flood_lake_desolation, _ = self.roll_flood_setting(random, weights_overrrides, "LakeDesolation")
|
||||
self.flood_lake_serene, _ = self.roll_flood_setting(random, weights_overrrides, "LakeSerene")
|
||||
self.flood_lake_serene_bridge, _ = self.roll_flood_setting(random, weights_overrrides, "LakeSereneBridge")
|
||||
self.flood_lab, _ = self.roll_flood_setting(random, weights_overrrides, "Lab")
|
||||
else:
|
||||
self.flood_basement = False
|
||||
self.flood_basement_high = False
|
||||
@@ -52,10 +52,12 @@ class PreCalculatedWeights:
|
||||
self.flood_lab = False
|
||||
|
||||
self.pyramid_keys_unlock, self.present_key_unlock, self.past_key_unlock, self.time_key_unlock = \
|
||||
self.get_pyramid_keys_unlocks(world, player, self.flood_maw, self.flood_xarion)
|
||||
self.get_pyramid_keys_unlocks(options, random, self.flood_maw, self.flood_xarion)
|
||||
|
||||
@staticmethod
|
||||
def get_pyramid_keys_unlocks(world: MultiWorld, player: int, is_maw_flooded: bool, is_xarion_flooded: bool) -> Tuple[str, str, str, str]:
|
||||
def get_pyramid_keys_unlocks(options: TimespinnerOptions, random: Random,
|
||||
is_maw_flooded: bool, is_xarion_flooded: bool) -> Tuple[str, str, str, str]:
|
||||
|
||||
present_teleportation_gates: List[str] = [
|
||||
"GateKittyBoss",
|
||||
"GateLeftLibrary",
|
||||
@@ -80,38 +82,30 @@ class PreCalculatedWeights:
|
||||
"GateRightPyramid"
|
||||
)
|
||||
|
||||
if not world:
|
||||
return (
|
||||
present_teleportation_gates[0],
|
||||
present_teleportation_gates[0],
|
||||
past_teleportation_gates[0],
|
||||
ancient_pyramid_teleportation_gates[0]
|
||||
)
|
||||
|
||||
if not is_maw_flooded:
|
||||
past_teleportation_gates.append("GateMaw")
|
||||
|
||||
if not is_xarion_flooded:
|
||||
present_teleportation_gates.append("GateXarion")
|
||||
|
||||
if is_option_enabled(world, player, "Inverted"):
|
||||
if options.inverted:
|
||||
all_gates: Tuple[str, ...] = present_teleportation_gates
|
||||
else:
|
||||
all_gates: Tuple[str, ...] = past_teleportation_gates + present_teleportation_gates
|
||||
|
||||
return (
|
||||
world.random.choice(all_gates),
|
||||
world.random.choice(present_teleportation_gates),
|
||||
world.random.choice(past_teleportation_gates),
|
||||
world.random.choice(ancient_pyramid_teleportation_gates)
|
||||
random.choice(all_gates),
|
||||
random.choice(present_teleportation_gates),
|
||||
random.choice(past_teleportation_gates),
|
||||
random.choice(ancient_pyramid_teleportation_gates)
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_flood_weights_overrides(world: MultiWorld, player: int) -> Dict[str, Union[str, Dict[str, int]]]:
|
||||
def get_flood_weights_overrides(options: TimespinnerOptions) -> Dict[str, Union[str, Dict[str, int]]]:
|
||||
weights_overrides_option: Union[int, Dict[str, Union[str, Dict[str, int]]]] = \
|
||||
get_option_value(world, player, "RisingTidesOverrides")
|
||||
options.rising_tides_overrides.value
|
||||
|
||||
default_weights: Dict[str, Dict[str, int]] = timespinner_options["RisingTidesOverrides"].default
|
||||
default_weights: Dict[str, Dict[str, int]] = options.rising_tides_overrides.default
|
||||
|
||||
if not weights_overrides_option:
|
||||
weights_overrides_option = default_weights
|
||||
@@ -123,13 +117,13 @@ class PreCalculatedWeights:
|
||||
return weights_overrides_option
|
||||
|
||||
@staticmethod
|
||||
def roll_flood_setting(world: MultiWorld, player: int,
|
||||
all_weights: Dict[str, Union[Dict[str, int], str]], key: str) -> Tuple[bool, bool]:
|
||||
def roll_flood_setting(random: Random, all_weights: Dict[str, Union[Dict[str, int], str]],
|
||||
key: str) -> Tuple[bool, bool]:
|
||||
|
||||
weights: Union[Dict[str, int], str] = all_weights[key]
|
||||
|
||||
if isinstance(weights, dict):
|
||||
result: str = world.random.choices(list(weights.keys()), weights=list(map(int, weights.values())))[0]
|
||||
result: str = random.choices(list(weights.keys()), weights=list(map(int, weights.values())))[0]
|
||||
else:
|
||||
result: str = weights
|
||||
|
||||
|
Reference in New Issue
Block a user