2022-08-15 21:52:03 +00:00
|
|
|
from worlds.generic.Rules import set_rule, add_rule
|
2023-11-22 15:20:32 +00:00
|
|
|
from BaseClasses import MultiWorld
|
|
|
|
from .locations import get_locations
|
|
|
|
from .ror2environments import environment_vanilla_orderedstages_table, environment_sotv_orderedstages_table
|
|
|
|
from typing import Set, TYPE_CHECKING
|
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
from . import RiskOfRainWorld
|
2021-08-29 18:02:02 +00:00
|
|
|
|
|
|
|
|
2023-02-05 20:51:03 +00:00
|
|
|
# Rule to see if it has access to the previous stage
|
2024-02-25 20:56:27 +00:00
|
|
|
def has_entrance_access_rule(multiworld: MultiWorld, stage: str, region: str, player: int) -> None:
|
|
|
|
rule = lambda state: state.has(region, player) and state.has(stage, player)
|
|
|
|
for entrance in multiworld.get_region(region, player).entrances:
|
|
|
|
entrance.access_rule = rule
|
2023-02-05 20:51:03 +00:00
|
|
|
|
|
|
|
|
2024-02-25 20:56:27 +00:00
|
|
|
def has_all_items(multiworld: MultiWorld, items: Set[str], region: str, player: int) -> None:
|
|
|
|
rule = lambda state: state.has_all(items, player) and state.has(region, player)
|
|
|
|
for entrance in multiworld.get_region(region, player).entrances:
|
|
|
|
entrance.access_rule = rule
|
2023-11-22 15:20:32 +00:00
|
|
|
|
|
|
|
|
2023-02-05 20:51:03 +00:00
|
|
|
# Checks to see if chest/shrine are accessible
|
2023-11-22 15:20:32 +00:00
|
|
|
def has_location_access_rule(multiworld: MultiWorld, environment: str, player: int, item_number: int, item_type: str)\
|
|
|
|
-> None:
|
2023-02-05 20:51:03 +00:00
|
|
|
if item_number == 1:
|
|
|
|
multiworld.get_location(f"{environment}: {item_type} {item_number}", player).access_rule = \
|
|
|
|
lambda state: state.has(environment, player)
|
2023-11-22 15:20:32 +00:00
|
|
|
# scavengers need to be locked till after a full loop since that is when they are capable of spawning.
|
|
|
|
# (While technically the requirement is just beating 5 stages, this will ensure that the player will have
|
|
|
|
# a long enough run to have enough director credits for scavengers and
|
|
|
|
# help prevent being stuck in the same stages until that point).
|
2023-02-05 20:51:03 +00:00
|
|
|
if item_type == "Scavenger":
|
|
|
|
multiworld.get_location(f"{environment}: {item_type} {item_number}", player).access_rule = \
|
2023-11-22 15:20:32 +00:00
|
|
|
lambda state: state.has(environment, player) and state.has("Stage 5", player)
|
2023-02-05 20:51:03 +00:00
|
|
|
else:
|
|
|
|
multiworld.get_location(f"{environment}: {item_type} {item_number}", player).access_rule = \
|
|
|
|
lambda state: check_location(state, environment, player, item_number, item_type)
|
|
|
|
|
|
|
|
|
2023-11-22 15:20:32 +00:00
|
|
|
def check_location(state, environment: str, player: int, item_number: int, item_name: str) -> bool:
|
2023-02-05 20:51:03 +00:00
|
|
|
return state.can_reach(f"{environment}: {item_name} {item_number - 1}", "Location", player)
|
|
|
|
|
|
|
|
|
|
|
|
# unlock event to next set of stages
|
2023-11-22 15:20:32 +00:00
|
|
|
def get_stage_event(multiworld: MultiWorld, player: int, stage_number: int) -> None:
|
|
|
|
if stage_number == 4:
|
|
|
|
return
|
2024-02-25 20:56:27 +00:00
|
|
|
rule = lambda state: state.has(f"Stage {stage_number + 1}", player)
|
|
|
|
for entrance in multiworld.get_region(f"OrderedStage_{stage_number + 1}", player).entrances:
|
|
|
|
entrance.access_rule = rule
|
2023-11-22 15:20:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
def set_rules(ror2_world: "RiskOfRainWorld") -> None:
|
|
|
|
player = ror2_world.player
|
|
|
|
multiworld = ror2_world.multiworld
|
|
|
|
ror2_options = ror2_world.options
|
|
|
|
if ror2_options.goal == "classic":
|
2023-02-05 20:51:03 +00:00
|
|
|
# classic mode
|
2023-11-22 15:20:32 +00:00
|
|
|
total_locations = ror2_options.total_locations.value # total locations for current player
|
2023-02-05 20:51:03 +00:00
|
|
|
else:
|
|
|
|
# explore mode
|
|
|
|
total_locations = len(
|
2023-11-22 15:20:32 +00:00
|
|
|
get_locations(
|
|
|
|
chests=ror2_options.chests_per_stage.value,
|
|
|
|
shrines=ror2_options.shrines_per_stage.value,
|
|
|
|
scavengers=ror2_options.scavengers_per_stage.value,
|
|
|
|
scanners=ror2_options.scanner_per_stage.value,
|
|
|
|
altars=ror2_options.altars_per_stage.value,
|
|
|
|
dlc_sotv=bool(ror2_options.dlc_sotv.value)
|
2023-02-05 20:51:03 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2022-03-23 21:22:31 +00:00
|
|
|
event_location_step = 25 # set an event location at these locations for "spheres"
|
|
|
|
divisions = total_locations // event_location_step
|
2023-02-05 20:51:03 +00:00
|
|
|
total_revivals = multiworld.worlds[player].total_revivals # pulling this info we calculated in generate_basic
|
|
|
|
|
2023-11-22 15:20:32 +00:00
|
|
|
if ror2_options.goal == "classic":
|
2023-02-05 20:51:03 +00:00
|
|
|
# classic mode
|
|
|
|
if divisions:
|
2023-04-29 07:07:42 +00:00
|
|
|
for i in range(1, divisions + 1): # since divisions is the floor of total_locations / 25
|
|
|
|
if i * event_location_step != total_locations:
|
|
|
|
event_loc = multiworld.get_location(f"Pickup{i * event_location_step}", player)
|
|
|
|
set_rule(event_loc,
|
2023-11-22 15:20:32 +00:00
|
|
|
lambda state, i=i: state.can_reach(f"ItemPickup{i * event_location_step - 1}",
|
|
|
|
"Location", player))
|
2023-06-27 04:47:52 +00:00
|
|
|
# we want to create a rule for each of the 25 locations per division
|
|
|
|
for n in range(i * event_location_step, (i + 1) * event_location_step + 1):
|
2023-04-29 07:07:42 +00:00
|
|
|
if n > total_locations:
|
|
|
|
break
|
2023-02-05 20:51:03 +00:00
|
|
|
if n == i * event_location_step:
|
|
|
|
set_rule(multiworld.get_location(f"ItemPickup{n}", player),
|
2023-06-27 04:47:52 +00:00
|
|
|
lambda state, event_item=event_loc.item.name: state.has(event_item, player))
|
2023-02-05 20:51:03 +00:00
|
|
|
else:
|
|
|
|
set_rule(multiworld.get_location(f"ItemPickup{n}", player),
|
2023-06-27 04:47:52 +00:00
|
|
|
lambda state, n=n: state.can_reach(f"ItemPickup{n - 1}", "Location", player))
|
2023-02-05 20:51:03 +00:00
|
|
|
set_rule(multiworld.get_location("Victory", player),
|
2023-06-27 04:47:52 +00:00
|
|
|
lambda state: state.can_reach(f"ItemPickup{total_locations}", "Location", player))
|
2023-11-22 15:20:32 +00:00
|
|
|
if total_revivals or ror2_options.start_with_revive.value:
|
2023-02-05 20:51:03 +00:00
|
|
|
add_rule(multiworld.get_location("Victory", player),
|
2023-06-27 04:47:52 +00:00
|
|
|
lambda state: state.has("Dio's Best Friend", player,
|
2023-11-22 15:20:32 +00:00
|
|
|
total_revivals + ror2_options.start_with_revive))
|
2023-02-05 20:51:03 +00:00
|
|
|
|
2023-11-22 15:20:32 +00:00
|
|
|
else:
|
|
|
|
# explore mode
|
|
|
|
chests = ror2_options.chests_per_stage.value
|
|
|
|
shrines = ror2_options.shrines_per_stage.value
|
|
|
|
newts = ror2_options.altars_per_stage.value
|
|
|
|
scavengers = ror2_options.scavengers_per_stage.value
|
|
|
|
scanners = ror2_options.scanner_per_stage.value
|
2023-02-05 20:51:03 +00:00
|
|
|
for i in range(len(environment_vanilla_orderedstages_table)):
|
|
|
|
for environment_name, _ in environment_vanilla_orderedstages_table[i].items():
|
|
|
|
# Make sure to go through each location
|
|
|
|
if scavengers == 1:
|
|
|
|
has_location_access_rule(multiworld, environment_name, player, scavengers, "Scavenger")
|
|
|
|
if scanners == 1:
|
|
|
|
has_location_access_rule(multiworld, environment_name, player, scanners, "Radio Scanner")
|
|
|
|
for chest in range(1, chests + 1):
|
|
|
|
has_location_access_rule(multiworld, environment_name, player, chest, "Chest")
|
|
|
|
for shrine in range(1, shrines + 1):
|
|
|
|
has_location_access_rule(multiworld, environment_name, player, shrine, "Shrine")
|
|
|
|
if newts > 0:
|
|
|
|
for newt in range(1, newts + 1):
|
|
|
|
has_location_access_rule(multiworld, environment_name, player, newt, "Newt Altar")
|
|
|
|
if i > 0:
|
2023-11-22 15:20:32 +00:00
|
|
|
has_entrance_access_rule(multiworld, f"Stage {i}", environment_name, player)
|
2023-02-05 20:51:03 +00:00
|
|
|
get_stage_event(multiworld, player, i)
|
|
|
|
|
2023-11-22 15:20:32 +00:00
|
|
|
if ror2_options.dlc_sotv:
|
2023-02-05 20:51:03 +00:00
|
|
|
for i in range(len(environment_sotv_orderedstages_table)):
|
|
|
|
for environment_name, _ in environment_sotv_orderedstages_table[i].items():
|
|
|
|
# Make sure to go through each location
|
|
|
|
if scavengers == 1:
|
|
|
|
has_location_access_rule(multiworld, environment_name, player, scavengers, "Scavenger")
|
|
|
|
if scanners == 1:
|
|
|
|
has_location_access_rule(multiworld, environment_name, player, scanners, "Radio Scanner")
|
|
|
|
for chest in range(1, chests + 1):
|
|
|
|
has_location_access_rule(multiworld, environment_name, player, chest, "Chest")
|
|
|
|
for shrine in range(1, shrines + 1):
|
|
|
|
has_location_access_rule(multiworld, environment_name, player, shrine, "Shrine")
|
|
|
|
if newts > 0:
|
|
|
|
for newt in range(1, newts + 1):
|
|
|
|
has_location_access_rule(multiworld, environment_name, player, newt, "Newt Altar")
|
|
|
|
if i > 0:
|
2023-11-22 15:20:32 +00:00
|
|
|
has_entrance_access_rule(multiworld, f"Stage {i}", environment_name, player)
|
|
|
|
has_entrance_access_rule(multiworld, "Hidden Realm: A Moment, Fractured", "Hidden Realm: A Moment, Whole",
|
2023-06-27 04:47:52 +00:00
|
|
|
player)
|
2023-11-22 15:20:32 +00:00
|
|
|
has_entrance_access_rule(multiworld, "Stage 1", "Hidden Realm: Bazaar Between Time", player)
|
|
|
|
has_entrance_access_rule(multiworld, "Hidden Realm: Bazaar Between Time", "Void Fields", player)
|
|
|
|
has_entrance_access_rule(multiworld, "Stage 5", "Commencement", player)
|
|
|
|
has_entrance_access_rule(multiworld, "Stage 5", "Hidden Realm: A Moment, Fractured", player)
|
2023-06-27 04:47:52 +00:00
|
|
|
has_entrance_access_rule(multiworld, "Beads of Fealty", "Hidden Realm: A Moment, Whole", player)
|
2023-11-22 15:20:32 +00:00
|
|
|
if ror2_options.dlc_sotv:
|
|
|
|
has_entrance_access_rule(multiworld, "Stage 5", "The Planetarium", player)
|
|
|
|
has_entrance_access_rule(multiworld, "Stage 5", "Void Locus", player)
|
|
|
|
if ror2_options.victory == "voidling":
|
|
|
|
has_all_items(multiworld, {"Stage 5", "The Planetarium"}, "Commencement", player)
|
|
|
|
|
2023-02-05 20:51:03 +00:00
|
|
|
# Win Condition
|
|
|
|
multiworld.completion_condition[player] = lambda state: state.has("Victory", player)
|