summary refs log tree commit diff stats
path: root/__init__.py
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2024-03-22 15:28:41 -0500
committerGitHub <noreply@github.com>2024-03-22 21:28:41 +0100
commit9c6e33c7869d28b8fa1b3349c9a59a40aa8c1526 (patch)
tree2476ec2b334184139bb536337d1d9bd7a7b3591c /__init__.py
parentf17c4acbe9364178787888a91a6e40f8216363e8 (diff)
downloadlingo-apworld-9c6e33c7869d28b8fa1b3349c9a59a40aa8c1526.tar.gz
lingo-apworld-9c6e33c7869d28b8fa1b3349c9a59a40aa8c1526.tar.bz2
lingo-apworld-9c6e33c7869d28b8fa1b3349c9a59a40aa8c1526.zip
Lingo: Add trap weights option (#2837)
Diffstat (limited to '__init__.py')
-rw-r--r--__init__.py23
1 files changed, 18 insertions, 5 deletions
diff --git a/__init__.py b/__init__.py index c92e530..b749418 100644 --- a/__init__.py +++ b/__init__.py
@@ -6,7 +6,7 @@ from logging import warning
6from BaseClasses import Item, ItemClassification, Tutorial 6from BaseClasses import Item, ItemClassification, Tutorial
7from worlds.AutoWorld import WebWorld, World 7from worlds.AutoWorld import WebWorld, World
8from .datatypes import Room, RoomEntrance 8from .datatypes import Room, RoomEntrance
9from .items import ALL_ITEM_TABLE, ITEMS_BY_GROUP, LingoItem 9from .items import ALL_ITEM_TABLE, ITEMS_BY_GROUP, TRAP_ITEMS, LingoItem
10from .locations import ALL_LOCATION_TABLE, LOCATIONS_BY_GROUP 10from .locations import ALL_LOCATION_TABLE, LOCATIONS_BY_GROUP
11from .options import LingoOptions 11from .options import LingoOptions
12from .player_logic import LingoPlayerLogic 12from .player_logic import LingoPlayerLogic
@@ -91,10 +91,23 @@ class LingoWorld(World):
91 pool.append(self.create_item("Puzzle Skip")) 91 pool.append(self.create_item("Puzzle Skip"))
92 92
93 if traps: 93 if traps:
94 traps_list = ["Slowness Trap", "Iceland Trap", "Atbash Trap"] 94 total_weight = sum(self.options.trap_weights.values())
95 95
96 for i in range(0, traps): 96 if total_weight == 0:
97 pool.append(self.create_item(traps_list[i % len(traps_list)])) 97 raise Exception("Sum of trap weights must be at least one.")
98
99 trap_counts = {name: int(weight * traps / total_weight)
100 for name, weight in self.options.trap_weights.items()}
101
102 trap_difference = traps - sum(trap_counts.values())
103 if trap_difference > 0:
104 allowed_traps = [name for name in TRAP_ITEMS if self.options.trap_weights[name] > 0]
105 for i in range(0, trap_difference):
106 trap_counts[allowed_traps[i % len(allowed_traps)]] += 1
107
108 for name, count in trap_counts.items():
109 for i in range(0, count):
110 pool.append(self.create_item(name))
98 111
99 self.multiworld.itempool += pool 112 self.multiworld.itempool += pool
100 113