The Witness: Allow specifying custom trap weights (#2835)

* Trap weights

* Slightly change the way the option works

* Wording one more time

* Non optional to bring in line with Ixrec's implementation

* Be clear that it's not an absolute amount, but a weight

* E x c l a m a t i o n   p o i n t

* Update worlds/witness/items.py

Co-authored-by: Exempt-Medic <60412657+Exempt-Medic@users.noreply.github.com>

* Wait I can just do this now lol

---------

Co-authored-by: Exempt-Medic <60412657+Exempt-Medic@users.noreply.github.com>
This commit is contained in:
NewSoupVi 2024-02-29 07:40:08 +01:00 committed by GitHub
parent 7a85ee7ed1
commit 564ec8c32e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 40 additions and 8 deletions

View File

@ -44,10 +44,6 @@ class WitnessWorld(World):
""" """
game = "The Witness" game = "The Witness"
topology_present = False topology_present = False
StaticWitnessLogic()
StaticWitnessLocations()
StaticWitnessItems()
web = WitnessWebWorld() web = WitnessWebWorld()
options_dataclass = TheWitnessOptions options_dataclass = TheWitnessOptions

View File

@ -176,9 +176,14 @@ class WitnessPlayerItems:
# Read trap configuration data. # Read trap configuration data.
trap_weight = self._world.options.trap_percentage / 100 trap_weight = self._world.options.trap_percentage / 100
filler_weight = 1 - trap_weight trap_items = self._world.options.trap_weights.value
if not sum(trap_items.values()):
trap_weight = 0
# Add filler items to the list. # Add filler items to the list.
filler_weight = 1 - trap_weight
filler_items: Dict[str, float] filler_items: Dict[str, float]
filler_items = {name: data.definition.weight if isinstance(data.definition, WeightedItemDefinition) else 1 filler_items = {name: data.definition.weight if isinstance(data.definition, WeightedItemDefinition) else 1
for (name, data) in self.item_data.items() if data.definition.category is ItemCategory.FILLER} for (name, data) in self.item_data.items() if data.definition.category is ItemCategory.FILLER}
@ -187,8 +192,6 @@ class WitnessPlayerItems:
# Add trap items. # Add trap items.
if trap_weight > 0: if trap_weight > 0:
trap_items = {name: data.definition.weight if isinstance(data.definition, WeightedItemDefinition) else 1
for (name, data) in self.item_data.items() if data.definition.category is ItemCategory.TRAP}
filler_items.update({name: base_weight * trap_weight / sum(trap_items.values()) filler_items.update({name: base_weight * trap_weight / sum(trap_items.values())
for name, base_weight in trap_items.items() if base_weight > 0}) for name, base_weight in trap_items.items() if base_weight > 0})
@ -267,3 +270,6 @@ class WitnessPlayerItems:
output[item.ap_code] = [StaticWitnessItems.item_data[child_item].ap_code output[item.ap_code] = [StaticWitnessItems.item_data[child_item].ap_code
for child_item in item.definition.child_item_names] for child_item in item.definition.child_item_names]
return output return output
StaticWitnessItems()

View File

@ -569,3 +569,6 @@ class WitnessPlayerLocations:
entity_hex = StaticWitnessLogic.ENTITIES_BY_NAME[entity_name]["entity_hex"] entity_hex = StaticWitnessLogic.ENTITIES_BY_NAME[entity_name]["entity_hex"]
self.CHECK_LOCATION_TABLE[entity_hex] = entity_name self.CHECK_LOCATION_TABLE[entity_hex] = entity_name
self.CHECK_PANELHEX_TO_ID[entity_hex] = StaticWitnessLocations.get_id(entity_hex) self.CHECK_PANELHEX_TO_ID[entity_hex] = StaticWitnessLocations.get_id(entity_hex)
StaticWitnessLocations()

View File

@ -1,5 +1,10 @@
from dataclasses import dataclass from dataclasses import dataclass
from Options import Toggle, DefaultOnToggle, Range, Choice, PerGameCommonOptions
from schema import Schema, And, Optional
from Options import Toggle, DefaultOnToggle, Range, Choice, PerGameCommonOptions, OptionDict
from worlds.witness.static_logic import WeightedItemDefinition, ItemCategory, StaticWitnessLogic
class DisableNonRandomizedPuzzles(Toggle): class DisableNonRandomizedPuzzles(Toggle):
@ -172,6 +177,24 @@ class TrapPercentage(Range):
default = 20 default = 20
class TrapWeights(OptionDict):
"""Specify the weights determining how many copies of each trap item will be in your itempool.
If you don't want a specific type of trap, you can set the weight for it to 0 (Do not delete the entry outright!).
If you set all trap weights to 0, you will get no traps, bypassing the "Trap Percentage" option."""
display_name = "Trap Weights"
schema = Schema({
trap_name: And(int, lambda n: n >= 0)
for trap_name, item_definition in StaticWitnessLogic.all_items.items()
if isinstance(item_definition, WeightedItemDefinition) and item_definition.category is ItemCategory.TRAP
})
default = {
trap_name: item_definition.weight
for trap_name, item_definition in StaticWitnessLogic.all_items.items()
if isinstance(item_definition, WeightedItemDefinition) and item_definition.category is ItemCategory.TRAP
}
class PuzzleSkipAmount(Range): class PuzzleSkipAmount(Range):
"""Adds this number of Puzzle Skips into the pool, if there is room. Puzzle Skips let you skip one panel. """Adds this number of Puzzle Skips into the pool, if there is room. Puzzle Skips let you skip one panel.
Works on most panels in the game - The only big exception is The Challenge.""" Works on most panels in the game - The only big exception is The Challenge."""
@ -237,6 +260,7 @@ class TheWitnessOptions(PerGameCommonOptions):
early_caves: EarlyCaves early_caves: EarlyCaves
elevators_come_to_you: ElevatorsComeToYou elevators_come_to_you: ElevatorsComeToYou
trap_percentage: TrapPercentage trap_percentage: TrapPercentage
trap_weights: TrapWeights
puzzle_skip_amount: PuzzleSkipAmount puzzle_skip_amount: PuzzleSkipAmount
hint_amount: HintAmount hint_amount: HintAmount
area_hint_percentage: AreaHintPercentage area_hint_percentage: AreaHintPercentage

View File

@ -295,3 +295,6 @@ class StaticWitnessLogic:
self.EP_TO_OBELISK_SIDE.update(self.sigma_normal.EP_TO_OBELISK_SIDE) self.EP_TO_OBELISK_SIDE.update(self.sigma_normal.EP_TO_OBELISK_SIDE)
self.ENTITY_ID_TO_NAME.update(self.sigma_normal.ENTITY_ID_TO_NAME) self.ENTITY_ID_TO_NAME.update(self.sigma_normal.ENTITY_ID_TO_NAME)
StaticWitnessLogic()