From 6c9293e4f65e8efc5f3388d219942ee2c3a24804 Mon Sep 17 00:00:00 2001 From: alwaysintreble Date: Tue, 7 Sep 2021 17:14:20 -0500 Subject: [PATCH] Added a dynamicallly loaded item weight pool with presets. --- worlds/ror2/Items.py | 122 +++++++++++++++++++++++++++++++++++++++- worlds/ror2/Options.py | 45 +++++++++++---- worlds/ror2/Rules.py | 3 +- worlds/ror2/__init__.py | 15 +++-- 4 files changed, 164 insertions(+), 21 deletions(-) diff --git a/worlds/ror2/Items.py b/worlds/ror2/Items.py index 35992e1f..104540d8 100644 --- a/worlds/ror2/Items.py +++ b/worlds/ror2/Items.py @@ -1,6 +1,6 @@ from BaseClasses import Item import typing - +from random import randint class RiskOfRainItem(Item): game: str = "Risk of Rain 2" @@ -26,7 +26,7 @@ item_table = { "Beat Level Five": None, } -junk_weights = { +default_weights = { "Item Scrap, Green": 16, "Item Scrap, Red": 4, "Item Scrap, Yellow": 1, @@ -36,7 +36,123 @@ junk_weights = { "Legendary Item": 8, "Boss Item": 4, "Lunar Item": 16, - "Equipment": 32, + "Equipment": 32 +} + +new_weights = { + "Item Scrap, Green": 15, + "Item Scrap, Red": 5, + "Item Scrap, Yellow": 1, + "Item Scrap, White": 30, + "Common Item": 75, + "Uncommon Item": 40, + "Legendary Item": 10, + "Boss Item": 5, + "Lunar Item": 15, + "Equipment": 25 +} + +uncommon_weights = { + "Item Scrap, Green": 15, + "Item Scrap, Red": 5, + "Item Scrap, Yellow": 1, + "Item Scrap, White": 30, + "Common Item": 45, + "Uncommon Item": 100, + "Legendary Item": 10, + "Boss Item": 5, + "Lunar Item": 15, + "Equipment": 25 +} + +legendary_weights = { + "Item Scrap, Green": 15, + "Item Scrap, Red": 5, + "Item Scrap, Yellow": 1, + "Item Scrap, White": 30, + "Common Item": 50, + "Uncommon Item": 25, + "Legendary Item": 100, + "Boss Item": 5, + "Lunar Item": 15, + "Equipment": 25 +} + +lunartic_weights = { + "Item Scrap, Green": 0, + "Item Scrap, Red": 0, + "Item Scrap, Yellow": 0, + "Item Scrap, White": 0, + "Common Item": 0, + "Uncommon Item": 0, + "Legendary Item": 0, + "Boss Item": 0, + "Lunar Item": 100, + "Equipment": 0 +} + +no_scraps_weights = { + "Item Scrap, Green": 0, + "Item Scrap, Red": 0, + "Item Scrap, Yellow": 0, + "Item Scrap, White": 0, + "Common Item": 80, + "Uncommon Item": 30, + "Legendary Item": 15, + "Boss Item": 5, + "Lunar Item": 10, + "Equipment": 25 +} + +even_weights = { + "Item Scrap, Green": 1, + "Item Scrap, Red": 1, + "Item Scrap, Yellow": 1, + "Item Scrap, White": 1, + "Common Item": 1, + "Uncommon Item": 1, + "Legendary Item": 1, + "Boss Item": 1, + "Lunar Item": 1, + "Equipment": 1 +} + +chaos_weights = { + "Item Scrap, Green": randint(0, 100), + "Item Scrap, Red": randint(0, 100), + "Item Scrap, Yellow": randint(0, 80), + "Item Scrap, White": randint(0, 100), + "Common Item": randint(0, 100), + "Uncommon Item": randint(0, 70), + "Legendary Item": randint(0, 25), + "Boss Item": randint(0, 10), + "Lunar Item": randint(0, 40), + "Equipment": randint(0, 40) +} + +scraps_only_weights = { + "Item Scrap, Green": 80, + "Item Scrap, Red": 40, + "Item Scrap, Yellow": 10, + "Item Scrap, White": 100, + "Common Item": 0, + "Uncommon Item": 0, + "Legendary Item": 0, + "Boss Item": 0, + "Lunar Item": 0, + "Equipment": 0 +} + +item_pool_weights: typing.Dict[int, typing.Dict[str, int]] = { + 0: default_weights, + 1: new_weights, + 2: uncommon_weights, + 3: legendary_weights, + 4: lunartic_weights, + 5: chaos_weights, + 6: no_scraps_weights, + 7: even_weights, + 8: scraps_only_weights } lookup_id_to_name: typing.Dict[int, str] = {id: name for name, id in item_table.items() if id} diff --git a/worlds/ror2/Options.py b/worlds/ror2/Options.py index f8b109b6..2af4ca75 100644 --- a/worlds/ror2/Options.py +++ b/worlds/ror2/Options.py @@ -1,5 +1,5 @@ import typing -from Options import Option, DefaultOnToggle, Range, OptionList +from Options import Option, DefaultOnToggle, Range, Choice class TotalLocations(Range): @@ -7,7 +7,7 @@ class TotalLocations(Range): displayname = "Total Locations" range_start = 10 range_end = 50 - default = 15 + default = 20 class TotalRevivals(Range): @@ -25,7 +25,7 @@ class ItemPickupStep(Range): displayname = "Item Pickup Step" range_start = 0 range_end = 5 - default = 1 + default = 2 class AllowLunarItems(DefaultOnToggle): @@ -43,7 +43,7 @@ class GreenScrap(Range): displayname = "Green Scraps" range_start = 0 range_end = 100 - default = 15 + default = 16 class RedScrap(Range): @@ -51,7 +51,7 @@ class RedScrap(Range): displayname = "Red Scraps" range_start = 0 range_end = 100 - default = 5 + default = 4 class YellowScrap(Range): @@ -67,7 +67,7 @@ class WhiteScrap(Range): displayname = "White Scraps" range_start = 0 range_end = 100 - default = 30 + default = 32 class CommonItem(Range): @@ -75,7 +75,7 @@ class CommonItem(Range): displayname = "Common Items" range_start = 0 range_end = 100 - default = 75 + default = 64 class UncommonItem(Range): @@ -83,7 +83,7 @@ class UncommonItem(Range): displayname = "Uncommon Items" range_start = 0 range_end = 100 - default = 40 + default = 32 class LegendaryItem(Range): @@ -91,7 +91,7 @@ class LegendaryItem(Range): displayname = "Legendary Items" range_start = 0 range_end = 100 - default = 10 + default = 8 class BossItem(Range): @@ -99,7 +99,7 @@ class BossItem(Range): displayname = "Boss Items" range_start = 0 range_end = 100 - default = 5 + default = 4 class LunarItem(Range): @@ -107,7 +107,7 @@ class LunarItem(Range): displayname = "Lunar Items" range_start = 0 range_end = 100 - default = 15 + default = 16 class Equipment(Range): @@ -115,9 +115,28 @@ class Equipment(Range): displayname = "Equipment" range_start = 0 range_end = 100 - default = 25 + default = 32 +class ItemPoolPresetToggle(DefaultOnToggle): + """Will use the item weight presets when set to true, otherwise will use the custom set item pool weights.""" + displayname = "Item Weight Presets" + +class ItemWeights(Choice): + """Preset choices for determining the weights of the item pool. + Only used if custom weights are unmodified or deleted.""" + displayname = "Item Weights" + option_default = 0 + option_new = 1 + option_uncommon = 2 + option_legendary = 3 + option_lunartic = 4 + option_chaos = 5 + option_no_scraps = 6 + option_even = 7 + option_scraps_only = 8 + +#define a dictionary for the weights of the generated item pool. ror2_weights: typing.Dict[str, type(Option)] = { "green_scrap": GreenScrap, "red_scrap": RedScrap, @@ -137,5 +156,7 @@ ror2_options: typing.Dict[str, type(Option)] = { "start_with_revive": StartWithRevive, "item_pickup_step": ItemPickupStep, "enable_lunar": AllowLunarItems, + "item_weights": ItemWeights, + "item_pool_presets": ItemPoolPresetToggle, **ror2_weights } \ No newline at end of file diff --git a/worlds/ror2/Rules.py b/worlds/ror2/Rules.py index c1992be5..3653f047 100644 --- a/worlds/ror2/Rules.py +++ b/worlds/ror2/Rules.py @@ -6,7 +6,8 @@ from ..generic.Rules import set_rule class RiskOfRainLogic(LogicMixin): def _ror_has_items(self, player: int, amount: int) -> bool: count: int = self.item_count("Common Item", player) + self.item_count("Uncommon Item", player) + \ - self.item_count("Legendary Item", player) + self.item_count("Boss Item", player) + self.item_count("Legendary Item", player) + self.item_count("Boss Item", player) + \ + self.item_count("Lunar Item", player) + self.item_count("Equipment", player) return count >= amount diff --git a/worlds/ror2/__init__.py b/worlds/ror2/__init__.py index c3d2b7fc..394cdbe0 100644 --- a/worlds/ror2/__init__.py +++ b/worlds/ror2/__init__.py @@ -1,10 +1,10 @@ import string -from .Items import RiskOfRain2Item, item_table, junk_weights +from .Items import RiskOfRainItem, item_table, item_pool_weights from .Locations import location_table, RiskOfRainLocation, base_location_table from .Rules import set_rules from BaseClasses import Region, Entrance, Item, MultiWorld -from .Options import ror2_options, ror2_weights +from .Options import ror2_options from ..AutoWorld import World client_version = 1 @@ -31,7 +31,8 @@ class RiskOfRainWorld(World): if self.world.start_with_revive[self.player].value: self.world.push_precollected(self.world.create_item("Dio's Best Friend", self.player)) - junk_pool ={ + # fills junk_pool with yaml weight values + junk_pool = { "Item Scrap, Green": self.world.green_scrap[self.player].value, "Item Scrap, Red": self.world.red_scrap[self.player].value, "Item Scrap, Yellow": self.world.yellow_scrap[self.player].value, @@ -44,6 +45,10 @@ class RiskOfRainWorld(World): "Equipment": self.world.equipment[self.player].value } + # if presets are enabled generate junk_pool from the selected preset + if self.world.item_pool_presets[self.player].value: + pool_option = self.world.item_weights[self.player].value + junk_pool = item_pool_weights[pool_option] # Generate item pool itempool = [] @@ -58,7 +63,7 @@ class RiskOfRainWorld(World): # Fill remaining items with randomly generated junk itempool += self.world.random.choices(list(junk_pool.keys()), weights=list(junk_pool.values()), k=self.world.total_locations[self.player] - - self.world.total_revivals[self.player]) + self.world.total_revivals[self.player] - self.world.start_with_revive[self.player].value) # Convert itempool into real items itempool = [item for item in map(lambda name: self.create_item(name), itempool)] @@ -82,7 +87,7 @@ class RiskOfRainWorld(World): def create_item(self, name: str) -> Item: item_id = item_table[name] - item = RiskOfRain2Item(name, True, item_id, self.player) + item = RiskOfRainItem(name, True, item_id, self.player) return item