Skip to content

Commit eefad96

Browse files
committed
Made the behavior use to filter items such that it corresponds to number of locations an opion.
1 parent cc7ec2b commit eefad96

File tree

2 files changed

+36
-17
lines changed

2 files changed

+36
-17
lines changed

worlds/enderlilies/Options.py

+13
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ class StartingSpirit(Choice):
3838
option_any = 2
3939
default = option_vanilla
4040

41+
class ItemFilterBehavior(Choice):
42+
"""Defines how items are filtered to ensure that the number of items provided by the world match its number of locations.
43+
44+
filler: Only items classified as filler will be considered. (i.e. lore)
45+
nonProgressive: All items that are not progressive will be considered. (i.e. useful + filler)
46+
nothing: Do not remove any items prior letting the multiworld choose what it keeps. """
47+
display_name = "Item filter behavior"
48+
option_filler = 0
49+
option_nonProgressive = 1
50+
option_nothing = 2
51+
default = option_filler
52+
4153
el_options: Dict[str, type(Option)] = {
4254
# # Not added since not sure if the client can read it right now.
4355
# "shuffle_slots": ShuffleSlots,
@@ -48,6 +60,7 @@ class StartingSpirit(Choice):
4860
# "mini_boss_incrememnts_chapter": MiniBossIncrementsChapter,
4961
# "shuffle_upgrades": ShuffleUpgrades,
5062
"starting_spirit": StartingSpirit,
63+
"item_filter_behavior": ItemFilterBehavior,
5164
}
5265

5366

worlds/enderlilies/__init__.py

+23-17
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def create_item(self, item: str) -> EnderLiliesItem:
3838
def create_items(self) -> None:
3939
starting_item = assign_starting_item(self.multiworld, self.player, items)
4040

41-
filter_items_to_locations_number(self.multiworld, items)
41+
filter_items_to_locations_number(self.multiworld, self.player, items)
4242

4343
for item, data in items.items():
4444
if item != starting_item:
@@ -98,22 +98,28 @@ def fill_slot_data(self) -> Dict[str, Any]:
9898
slot_data[location.name] = f"AP.{location.address}"
9999
return slot_data
100100

101-
def filter_items_to_locations_number(multiworld: MultiWorld, items):
102-
# Not sure how to differ locations with item and entrance. Using address for now...
103-
nb_locations_items = len([x for x in locations if locations[x].address is not None])
104-
nb_items = sum([items[x].count for x in items])
105-
nb_excedant_items = nb_items - nb_locations_items
106-
if nb_excedant_items > 0:
107-
items_valid_to_discard = sorted(x for x in items if items[x].classification == ItemClassification.filler)
108-
for i in range(nb_excedant_items):
109-
discard_candidate = multiworld.random.choice(items_valid_to_discard)
110-
if items[discard_candidate].count == 1:
111-
del items[discard_candidate]
112-
items_valid_to_discard.remove(discard_candidate)
113-
else:
114-
items[discard_candidate] = ItemData(code=items[discard_candidate].code,
115-
count=items[discard_candidate].count - 1,
116-
classification=items[discard_candidate].classification)
101+
def filter_items_to_locations_number(multiworld: MultiWorld, player: int, items):
102+
val = get_option_value(multiworld, player, "item_filter_behavior")
103+
if val != 2:
104+
# Not sure how to differ locations with item and entrance. Using address for now...
105+
nb_locations_items = len([x for x in locations if locations[x].address is not None])
106+
nb_items = sum([items[x].count for x in items])
107+
nb_excedant_items = nb_items - nb_locations_items
108+
if nb_excedant_items > 0:
109+
if val == 0:
110+
discard_candidates = sorted(x for x in items if items[x].classification == ItemClassification.filler)
111+
elif val == 1:
112+
discard_candidates = sorted(x for x in items if (items[x].classification == ItemClassification.filler
113+
or items[x].classification == ItemClassification.useful))
114+
for i in range(nb_excedant_items):
115+
curr_candidate = multiworld.random.choice(discard_candidates)
116+
if items[curr_candidate].count == 1:
117+
del items[curr_candidate]
118+
discard_candidates.remove(curr_candidate)
119+
else:
120+
items[curr_candidate] = ItemData(code=items[curr_candidate].code,
121+
count=items[curr_candidate].count - 1,
122+
classification=items[curr_candidate].classification)
117123

118124
def assign_starting_item(multiworld: MultiWorld, player: int, items) -> str:
119125
non_local_items = multiworld.non_local_items[player].value

0 commit comments

Comments
 (0)