mirror of
https://github.com/MarioSpore/Grinch-AP.git
synced 2025-10-21 20:21:32 -06:00
RoR2: code cleanup and styling consistency (#833)
* build locations dict dynamically from the TotalLocations option. Minor styling cleanup * Minor items styling cleanup. remove unused event items * minor options cleanup. clarify preset toggle slightly better * make items.py more readable. add chaos weights dict to use as reference point for generation * small rules styling and consistency cleanup * create less regions and other init cleanup * move region creation to less function calls and move revivals calculation * typing * use enum instead of hardcoded ints. fix bug i introduced * better typing
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import string
|
||||
from typing import Dict, List
|
||||
from .Items import RiskOfRainItem, item_table, item_pool_weights
|
||||
from .Locations import location_table, RiskOfRainLocation, base_location_table
|
||||
from .Locations import RiskOfRainLocation, item_pickups
|
||||
from .Rules import set_rules
|
||||
|
||||
from BaseClasses import Region, RegionType, Entrance, Item, ItemClassification, MultiWorld, Tutorial
|
||||
from .Options import ror2_options
|
||||
from .Options import ror2_options, ItemWeights
|
||||
from worlds.AutoWorld import World, WebWorld
|
||||
|
||||
client_version = 1
|
||||
@@ -32,34 +33,31 @@ class RiskOfRainWorld(World):
|
||||
topology_present = False
|
||||
|
||||
item_name_to_id = item_table
|
||||
location_name_to_id = location_table
|
||||
location_name_to_id = item_pickups
|
||||
|
||||
data_version = 3
|
||||
data_version = 4
|
||||
forced_auto_forfeit = True
|
||||
web = RiskOfWeb()
|
||||
total_revivals: int
|
||||
|
||||
def generate_basic(self):
|
||||
def generate_early(self) -> None:
|
||||
# figure out how many revivals should exist in the pool
|
||||
self.total_revivals = int(self.world.total_revivals[self.player].value / 100 *
|
||||
self.world.total_locations[self.player].value)
|
||||
|
||||
def generate_basic(self) -> None:
|
||||
# shortcut for starting_inventory... The start_with_revive option lets you start with a Dio's Best Friend
|
||||
if self.world.start_with_revive[self.player].value:
|
||||
self.world.push_precollected(self.world.create_item("Dio's Best Friend", self.player))
|
||||
|
||||
# if presets are enabled generate junk_pool from the selected preset
|
||||
pool_option = self.world.item_weights[self.player].value
|
||||
if self.world.item_pool_presets[self.player].value:
|
||||
junk_pool: Dict[str, int] = {}
|
||||
if self.world.item_pool_presets[self.player]:
|
||||
# generate chaos weights if the preset is chosen
|
||||
if pool_option == 5:
|
||||
junk_pool = {
|
||||
"Item Scrap, Green": self.world.random.randint(0, 80),
|
||||
"Item Scrap, Red": self.world.random.randint(0, 45),
|
||||
"Item Scrap, Yellow": self.world.random.randint(0, 30),
|
||||
"Item Scrap, White": self.world.random.randint(0, 100),
|
||||
"Common Item": self.world.random.randint(0, 100),
|
||||
"Uncommon Item": self.world.random.randint(0, 70),
|
||||
"Legendary Item": self.world.random.randint(0, 30),
|
||||
"Boss Item": self.world.random.randint(0, 20),
|
||||
"Lunar Item": self.world.random.randint(0, 60),
|
||||
"Equipment": self.world.random.randint(0, 40)
|
||||
}
|
||||
if pool_option == ItemWeights.option_chaos:
|
||||
for name, max_value in item_pool_weights[pool_option].items():
|
||||
junk_pool[name] = self.world.random.randint(0, max_value)
|
||||
else:
|
||||
junk_pool = item_pool_weights[pool_option].copy()
|
||||
else: # generate junk pool from user created presets
|
||||
@@ -77,37 +75,43 @@ class RiskOfRainWorld(World):
|
||||
}
|
||||
|
||||
# remove lunar items from the pool if they're disabled in the yaml unless lunartic is rolled
|
||||
if not self.world.enable_lunar[self.player]:
|
||||
if not pool_option == 4:
|
||||
junk_pool.pop("Lunar Item")
|
||||
if not (self.world.enable_lunar[self.player] or pool_option == ItemWeights.option_lunartic):
|
||||
junk_pool.pop("Lunar Item")
|
||||
|
||||
# Generate item pool
|
||||
itempool = []
|
||||
|
||||
itempool: List = []
|
||||
# Add revive items for the player
|
||||
itempool += ["Dio's Best Friend"] * int(self.world.total_revivals[self.player] / 100 * self.world.total_locations[self.player])
|
||||
itempool += ["Dio's Best Friend"] * self.total_revivals
|
||||
|
||||
# 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] -
|
||||
int(self.world.total_revivals[self.player] / 100 * self.world.total_locations[self.player]))
|
||||
k=self.world.total_locations[self.player].value - self.total_revivals)
|
||||
|
||||
# Convert itempool into real items
|
||||
itempool = list(map(lambda name: self.create_item(name), itempool))
|
||||
|
||||
self.world.itempool += itempool
|
||||
|
||||
def set_rules(self):
|
||||
def set_rules(self) -> None:
|
||||
set_rules(self.world, self.player)
|
||||
|
||||
def create_regions(self):
|
||||
create_regions(self.world, self.player)
|
||||
create_events(self.world, self.player, int(self.world.total_locations[self.player]))
|
||||
def create_regions(self) -> None:
|
||||
menu = create_region(self.world, self.player, "Menu")
|
||||
petrichor = create_region(self.world, self.player, "Petrichor V",
|
||||
[f"ItemPickup{i + 1}" for i in range(self.world.total_locations[self.player].value)])
|
||||
|
||||
connection = Entrance(self.player, "Lobby", menu)
|
||||
menu.exits.append(connection)
|
||||
connection.connect(petrichor)
|
||||
|
||||
self.world.regions += [menu, petrichor]
|
||||
|
||||
create_events(self.world, self.player)
|
||||
|
||||
def fill_slot_data(self):
|
||||
return {
|
||||
"itemPickupStep": self.world.item_pickup_step[self.player].value,
|
||||
"seed": "".join(self.world.slot_seeds[self.player].choice(string.digits) for i in range(16)),
|
||||
"seed": "".join(self.world.slot_seeds[self.player].choice(string.digits) for _ in range(16)),
|
||||
"totalLocations": self.world.total_locations[self.player].value,
|
||||
"totalRevivals": self.world.total_revivals[self.player].value,
|
||||
"startWithDio": self.world.start_with_revive[self.player].value,
|
||||
@@ -116,49 +120,39 @@ class RiskOfRainWorld(World):
|
||||
|
||||
def create_item(self, name: str) -> Item:
|
||||
item_id = item_table[name]
|
||||
item = RiskOfRainItem(name, ItemClassification.filler, item_id, self.player)
|
||||
if name == "Dio's Best Friend":
|
||||
item.classification = ItemClassification.progression
|
||||
classification = ItemClassification.progression
|
||||
elif name in {"Equipment", "Legendary Item"}:
|
||||
item.classification = ItemClassification.useful
|
||||
classification = ItemClassification.useful
|
||||
else:
|
||||
classification = ItemClassification.filler
|
||||
item = RiskOfRainItem(name, classification, item_id, self.player)
|
||||
return item
|
||||
|
||||
|
||||
def create_events(world: MultiWorld, player: int, total_locations: int):
|
||||
def create_events(world: MultiWorld, player: int) -> None:
|
||||
total_locations = world.total_locations[player].value
|
||||
num_of_events = total_locations // 25
|
||||
if total_locations / 25 == num_of_events:
|
||||
num_of_events -= 1
|
||||
world_region = world.get_region("Petrichor V", player)
|
||||
|
||||
for i in range(num_of_events):
|
||||
event_loc = RiskOfRainLocation(player, f"Pickup{(i + 1) * 25}", None, world.get_region('Petrichor V', player))
|
||||
event_loc = RiskOfRainLocation(player, f"Pickup{(i + 1) * 25}", None, world_region)
|
||||
event_loc.place_locked_item(RiskOfRainItem(f"Pickup{(i + 1) * 25}", ItemClassification.progression, None, player))
|
||||
event_loc.access_rule(lambda state, i=i: state.can_reach(f"ItemPickup{((i + 1) * 25) - 1}", player))
|
||||
world.get_region('Petrichor V', player).locations.append(event_loc)
|
||||
world_region.locations.append(event_loc)
|
||||
|
||||
victory_event = RiskOfRainLocation(player, "Victory", None, world_region)
|
||||
victory_event.place_locked_item(RiskOfRainItem("Victory", ItemClassification.progression, None, player))
|
||||
world_region.locations.append(victory_event)
|
||||
|
||||
|
||||
# generate locations based on player setting
|
||||
def create_regions(world, player: int):
|
||||
world.regions += [
|
||||
create_region(world, player, 'Menu', None, ['Lobby']),
|
||||
create_region(world, player, 'Petrichor V',
|
||||
[location for location in base_location_table] +
|
||||
[f"ItemPickup{i}" for i in range(1, 1 + world.total_locations[player])])
|
||||
]
|
||||
|
||||
world.get_entrance("Lobby", player).connect(world.get_region("Petrichor V", player))
|
||||
world.get_location("Victory", player).place_locked_item(RiskOfRainItem("Victory", ItemClassification.progression,
|
||||
None, player))
|
||||
|
||||
|
||||
def create_region(world: MultiWorld, player: int, name: str, locations=None, exits=None):
|
||||
ret = Region(name, RegionType.Generic, name, player)
|
||||
ret.world = world
|
||||
def create_region(world: MultiWorld, player: int, name: str, locations: List[str] = None) -> Region:
|
||||
ret = Region(name, RegionType.Generic, name, player, world)
|
||||
if locations:
|
||||
for location in locations:
|
||||
loc_id = location_table[location]
|
||||
loc_id = item_pickups[location]
|
||||
location = RiskOfRainLocation(player, location, loc_id, ret)
|
||||
ret.locations.append(location)
|
||||
if exits:
|
||||
for exit in exits:
|
||||
ret.exits.append(Entrance(player, exit, ret))
|
||||
|
||||
return ret
|
||||
|
||||
Reference in New Issue
Block a user