Skip to content

Commit

Permalink
Optimize fountain hunt calculation for slot data
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePhar committed Oct 15, 2024
1 parent 75152db commit db24c51
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 28 deletions.
56 changes: 28 additions & 28 deletions worlds/rogue_legacy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,48 +44,48 @@ class RogueLegacyWorld(World):
web = RogueLegacyWebWorld()

boss_order: list[str]
piece_requirement: int

def generate_early(self) -> None:
self.boss_order = self.options.boss_shuffle.generate_boss_order(self)
self.piece_requirement = self.options.fountain_hunt.generate_requirement(self)

def fill_slot_data(self) -> dict[str, Any]:
# In theory, I could use self.options.as_dict, but I want more control over the value types.
slot_data: dict[str, Any] = {
# fmt: off

# Easy flag to check for updates.
"world_version": WORLD_VERSION,
"world_version": WORLD_VERSION,

# Game options relevant to client.
"children": self.options.children.value,
"level_limit": bool(self.options.level_limit.value),
"shuffle_blacksmith": bool(self.options.shuffle_blacksmith.value),
"shuffle_enchantress": bool(self.options.shuffle_enchantress.value),
"chests_brown": self.options.chests_brown.value,
"chests_silver": self.options.chests_silver.value,
"chests_gold": self.options.chests_gold.value,
"chests_fairy": self.options.chests_fairy.value,
"diary_entries": self.options.diary_entries.value,
"neo_bosses": self.options.neo_bosses.current_key,
"additional_challenges": bool(self.options.additional_challenges.value),
"enemy_scaling": self.options.enemy_scaling.value / 100.0,
"castle_scaling": self.options.castle_scaling.value / 100.0,
"ngplus_requirement": self.options.ngplus_requirement.value,
"gold_gain": self.options.gold_gain.value / 100.0,
"charon": bool(self.options.charon.value),
"fountain_hunt": bool(self.options.fountain_hunt.value),
"fountain_pieces_available": self.options.fountain_pieces_available.value,
"fountain_pieces_required": self.options.fountain_pieces_required.value / 100.0,
"character_names_sir": self.options.character_names_sir.value,
"character_names_lady": self.options.character_names_lady.value,
"max_health": self.options.max_health.value,
"max_mana": self.options.max_mana.value,
"max_attack": self.options.max_attack.value,
"max_magic_damage": self.options.max_magic_damage.value,
"death_link": self.options.death_link.current_key,
"children": self.options.children.value,
"level_limit": bool(self.options.level_limit.value),
"shuffle_blacksmith": bool(self.options.shuffle_blacksmith.value),
"shuffle_enchantress": bool(self.options.shuffle_enchantress.value),
"chests_brown": self.options.chests_brown.value,
"chests_silver": self.options.chests_silver.value,
"chests_gold": self.options.chests_gold.value,
"chests_fairy": self.options.chests_fairy.value,
"diary_entries": self.options.diary_entries.value,
"neo_bosses": self.options.neo_bosses.current_key,
"additional_challenges": bool(self.options.additional_challenges.value),
"enemy_scaling": self.options.enemy_scaling.value / 100.0,
"castle_scaling": self.options.castle_scaling.value / 100.0,
"ngplus_requirement": self.options.ngplus_requirement.value,
"gold_gain": self.options.gold_gain.value / 100.0,
"charon": bool(self.options.charon.value),
"character_names_sir": self.options.character_names_sir.value,
"character_names_lady": self.options.character_names_lady.value,
"max_health": self.options.max_health.value,
"max_mana": self.options.max_mana.value,
"max_attack": self.options.max_attack.value,
"max_magic_damage": self.options.max_magic_damage.value,
"death_link": self.options.death_link.current_key,

# Computed data.
"boss_order": self.boss_order,
"boss_order": self.boss_order,
"fountain_pieces_required": self.piece_requirement,
}

# fmt: on
Expand Down
9 changes: 9 additions & 0 deletions worlds/rogue_legacy/options.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from dataclasses import dataclass
from math import floor
from typing import TYPE_CHECKING

from Options import (
Expand Down Expand Up @@ -346,6 +347,14 @@ class FountainHunt(Toggle):

display_name = "Fountain Hunt"

def generate_requirement(self, world: RogueLegacyWorld) -> int:
if not self: # If disabled
return 0

available = world.options.fountain_pieces_available.value
required_factor = world.options.fountain_pieces_required.value / 100.0
return min(1, floor(available * required_factor))


class FountainPiecesAvailable(Range):
"""Determines the number of Fountain Pieces available, if Fountain Hunt is enabled."""
Expand Down

0 comments on commit db24c51

Please sign in to comment.