diff options
Diffstat (limited to '__init__.py')
| -rw-r--r-- | __init__.py | 23 |
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 | |||
| 6 | from BaseClasses import Item, ItemClassification, Tutorial | 6 | from BaseClasses import Item, ItemClassification, Tutorial |
| 7 | from worlds.AutoWorld import WebWorld, World | 7 | from worlds.AutoWorld import WebWorld, World |
| 8 | from .datatypes import Room, RoomEntrance | 8 | from .datatypes import Room, RoomEntrance |
| 9 | from .items import ALL_ITEM_TABLE, ITEMS_BY_GROUP, LingoItem | 9 | from .items import ALL_ITEM_TABLE, ITEMS_BY_GROUP, TRAP_ITEMS, LingoItem |
| 10 | from .locations import ALL_LOCATION_TABLE, LOCATIONS_BY_GROUP | 10 | from .locations import ALL_LOCATION_TABLE, LOCATIONS_BY_GROUP |
| 11 | from .options import LingoOptions | 11 | from .options import LingoOptions |
| 12 | from .player_logic import LingoPlayerLogic | 12 | from .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 | ||
