Skip to content

Commit

Permalink
Raft: Fix item prefilling (ArchipelagoMW#1878)
Browse files Browse the repository at this point in the history
  • Loading branch information
SunnyBat authored Jun 20, 2023
1 parent a75159b commit afe9e12
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions worlds/raft/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,16 @@ def create_items(self):
maximumResourcePackAmount = max(minRPSpecified, maxRPSpecified)
# Generate item pool
pool = []
frequencyItems = []
for item in item_table:
raft_item = self.create_item_replaceAsNecessary(item["name"])
if "Frequency" in item["name"]:
frequencyItems.append(raft_item)
pool.append(raft_item)
if self.multiworld.island_frequency_locations[self.player].value <= 3:
if not hasattr(self.multiworld, "raft_frequencyItemsPerPlayer"):
self.multiworld.raft_frequencyItemsPerPlayer = {}
self.multiworld.raft_frequencyItemsPerPlayer[self.player] = frequencyItems

extraItemNamePool = []
extras = len(location_table) - len(item_table) - 1 # Victory takes up 1 unaccounted-for slot
Expand All @@ -66,6 +73,16 @@ def create_items(self):
dupeItemPool = item_table.copy()
# Remove frequencies if necessary
if self.multiworld.island_frequency_locations[self.player].value != 5: # Not completely random locations
# If we let frequencies stay in with progressive-frequencies, the progressive-frequency item
# will be included 7 times. This is a massive flood of progressive-frequency items, so we
# instead add progressive-frequency as its own item a smaller amount of times to prevent
# flooding the duplicate item pool with them.
if self.multiworld.island_frequency_locations[self.player].value == 4:
for _ in range(2):
# Progressives are not in item_pool, need to create faux item for duplicate item pool
# This can still be filtered out later by duplicate_items setting
dupeItemPool.append({ "name": "progressive-frequency", "progression": True }) # Progressive frequencies need to be included
# Always remove non-progressive Frequency items
dupeItemPool = (itm for itm in dupeItemPool if "Frequency" not in itm["name"])

# Remove progression or non-progression items if necessary
Expand Down Expand Up @@ -129,15 +146,15 @@ def collect_item(self, state, item, remove=False):
return super(RaftWorld, self).collect_item(state, item, remove)

def pre_fill(self):
if self.multiworld.island_frequency_locations[self.player] == 0:
if self.multiworld.island_frequency_locations[self.player] == 0: # Vanilla
self.setLocationItem("Radio Tower Frequency to Vasagatan", "Vasagatan Frequency")
self.setLocationItem("Vasagatan Frequency to Balboa", "Balboa Island Frequency")
self.setLocationItem("Relay Station quest", "Caravan Island Frequency")
self.setLocationItem("Caravan Island Frequency to Tangaroa", "Tangaroa Frequency")
self.setLocationItem("Tangaroa Frequency to Varuna Point", "Varuna Point Frequency")
self.setLocationItem("Varuna Point Frequency to Temperance", "Temperance Frequency")
self.setLocationItem("Temperance Frequency to Utopia", "Utopia Frequency")
elif self.multiworld.island_frequency_locations[self.player] == 1:
elif self.multiworld.island_frequency_locations[self.player] == 1: # Random on island
self.setLocationItemFromRegion("RadioTower", "Vasagatan Frequency")
self.setLocationItemFromRegion("Vasagatan", "Balboa Island Frequency")
self.setLocationItemFromRegion("BalboaIsland", "Caravan Island Frequency")
Expand Down Expand Up @@ -173,9 +190,9 @@ def pre_fill(self):
else:
currentLocation = availableLocationList[0] # Utopia (only one left in list)
availableLocationList.remove(currentLocation)
if self.multiworld.island_frequency_locations[self.player] == 2:
if self.multiworld.island_frequency_locations[self.player] == 2: # Random island order
self.setLocationItem(locationToVanillaFrequencyLocationMap[previousLocation], locationToFrequencyItemMap[currentLocation])
elif self.multiworld.island_frequency_locations[self.player] == 3:
elif self.multiworld.island_frequency_locations[self.player] == 3: # Random on island random order
self.setLocationItemFromRegion(previousLocation, locationToFrequencyItemMap[currentLocation])
previousLocation = currentLocation

Expand All @@ -184,12 +201,14 @@ def pre_fill(self):
RaftItem("Victory", ItemClassification.progression, None, player=self.player))

def setLocationItem(self, location: str, itemName: str):
itemToUse = next(filter(lambda itm: itm.name == itemName, self.multiworld.itempool))
itemToUse = next(filter(lambda itm: itm.name == itemName, self.multiworld.raft_frequencyItemsPerPlayer[self.player]))
self.multiworld.raft_frequencyItemsPerPlayer[self.player].remove(itemToUse)
self.multiworld.itempool.remove(itemToUse)
self.multiworld.get_location(location, self.player).place_locked_item(itemToUse)

def setLocationItemFromRegion(self, region: str, itemName: str):
itemToUse = next(filter(lambda itm: itm.name == itemName, self.multiworld.itempool))
itemToUse = next(filter(lambda itm: itm.name == itemName, self.multiworld.raft_frequencyItemsPerPlayer[self.player]))
self.multiworld.raft_frequencyItemsPerPlayer[self.player].remove(itemToUse)
self.multiworld.itempool.remove(itemToUse)
location = random.choice(list(loc for loc in location_table if loc["region"] == region))
self.multiworld.get_location(location["name"], self.player).place_locked_item(itemToUse)
Expand Down

0 comments on commit afe9e12

Please sign in to comment.