Skip to content

Commit

Permalink
Add world parameter to logic calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Alchav committed Jun 22, 2024
1 parent bb6a5d0 commit 14af74b
Show file tree
Hide file tree
Showing 5 changed files with 225 additions and 227 deletions.
2 changes: 1 addition & 1 deletion worlds/pokemon_rb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def stage_fill_hook(cls, multiworld, progitempool, usefulitempool, filleritempoo
if loc.item:
continue
itempool = progitempool + usefulitempool + filleritempool
self.random.shuffle(itempool)
multiworld.random.shuffle(itempool)
unplaced_items = []
for i, item in enumerate(itempool):
if item.player == loc.player and loc.can_fill(multiworld.state, item, False):
Expand Down
72 changes: 35 additions & 37 deletions worlds/pokemon_rb/logic.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,47 @@
from . import poke_data


def can_surf(state, player):
return (((state.has("HM03 Surf", player) and can_learn_hm(state, "Surf", player))
or state.has("Flippers", player)) and (state.has("Soul Badge", player) or
state.has(state.multiworld.worlds[player].extra_badges.get("Surf"), player)
or state.multiworld.worlds[player].options.badges_needed_for_hm_moves.value == 0))
def can_surf(state, world, player):
return (((state.has("HM03 Surf", player) and can_learn_hm(state, world, "Surf", player))) and (state.has("Soul Badge", player) or
state.has(world.extra_badges.get("Surf"), player)
or world.options.badges_needed_for_hm_moves.value == 0))


def can_cut(state, player):
return ((state.has("HM01 Cut", player) and can_learn_hm(state, "Cut", player) or state.has("Master Sword", player))
and (state.has("Cascade Badge", player) or
state.has(state.multiworld.worlds[player].extra_badges.get("Cut"), player) or
state.multiworld.worlds[player].options.badges_needed_for_hm_moves.value == 0))
def can_cut(state, world, player):
return ((state.has("HM01 Cut", player) and can_learn_hm(state, world, "Cut", player))
and (state.has("Cascade Badge", player) or state.has(world.extra_badges.get("Cut"), player) or
world.options.badges_needed_for_hm_moves.value == 0))


def can_fly(state, player):
return (((state.has("HM02 Fly", player) and can_learn_hm(state, "Fly", player)) or state.has("Flute", player)) and
(state.has("Thunder Badge", player) or state.has(state.multiworld.worlds[player].extra_badges.get("Fly"), player)
or state.multiworld.worlds[player].options.badges_needed_for_hm_moves.value == 0))
def can_fly(state, world, player):
return (((state.has("HM02 Fly", player) and can_learn_hm(state, world, "Fly", player)) or state.has("Flute", player)) and
(state.has("Thunder Badge", player) or state.has(world.extra_badges.get("Fly"), player)
or world.options.badges_needed_for_hm_moves.value == 0))


def can_strength(state, player):
return ((state.has("HM04 Strength", player) and can_learn_hm(state, "Strength", player)) or
def can_strength(state, world, player):
return ((state.has("HM04 Strength", player) and can_learn_hm(state, world, "Strength", player)) or
state.has("Titan's Mitt", player)) and (state.has("Rainbow Badge", player) or
state.has(state.multiworld.worlds[player].extra_badges.get("Strength"), player)
or state.multiworld.worlds[player].options.badges_needed_for_hm_moves.value == 0)
state.has(world.extra_badges.get("Strength"), player)
or world.options.badges_needed_for_hm_moves.value == 0)


def can_flash(state, player):
return (((state.has("HM05 Flash", player) and can_learn_hm(state, "Flash", player)) or state.has("Lamp", player))
and (state.has("Boulder Badge", player) or state.has(state.multiworld.worlds[player].extra_badges.get("Flash"),
player) or state.multiworld.worlds[player].options.badges_needed_for_hm_moves.value == 0))
def can_flash(state, world, player):
return (((state.has("HM05 Flash", player) and can_learn_hm(state, world, "Flash", player)) or state.has("Lamp", player))
and (state.has("Boulder Badge", player) or state.has(world.extra_badges.get("Flash"),
player) or world.options.badges_needed_for_hm_moves.value == 0))


def can_learn_hm(state, move, player):
for pokemon, data in state.multiworld.worlds[player].local_poke_data.items():
def can_learn_hm(state, world, move, player):
for pokemon, data in world.local_poke_data.items():
if state.has(pokemon, player) and data["tms"][6] & 1 << (["Cut", "Fly", "Surf", "Strength",
"Flash"].index(move) + 2):
return True
return False


def can_get_hidden_items(state, player):
return state.has("Item Finder", player) or not state.multiworld.worlds[player].options.require_item_finder.value
def can_get_hidden_items(state, world, player):
return state.has("Item Finder", player) or not world.options.require_item_finder.value


def has_key_items(state, count, player):
Expand All @@ -59,8 +57,8 @@ def has_key_items(state, count, player):
return key_items >= count


def can_pass_guards(state, player):
if state.multiworld.worlds[player].options.tea:
def can_pass_guards(state, world, player):
if world.options.tea:
return state.has("Tea", player)
else:
return state.has("Vending Machine Drinks", player)
Expand All @@ -71,8 +69,8 @@ def has_badges(state, count, player):
"Soul Badge", "Volcano Badge", "Earth Badge"] if state.has(item, player)]) >= count


def oaks_aide(state, count, player):
return ((not state.multiworld.worlds[player].options.require_pokedex or state.has("Pokedex", player))
def oaks_aide(state, world, count, player):
return ((not world.options.require_pokedex or state.has("Pokedex", player))
and has_pokemon(state, count, player))


Expand All @@ -97,19 +95,19 @@ def card_key(state, floor, player):
state.has("Progressive Card Key", player, floor - 1)


def rock_tunnel(state, player):
return can_flash(state, player) or not state.multiworld.worlds[player].options.dark_rock_tunnel_logic
def rock_tunnel(state, world, player):
return can_flash(state, world, player) or not world.options.dark_rock_tunnel_logic


def route_3(state, player):
if state.multiworld.worlds[player].options.route_3_condition == "defeat_brock":
def route(state, world, player):
if world.options.route_3_condition == "defeat_brock":
return state.has("Defeat Brock", player)
elif state.multiworld.worlds[player].options.route_3_condition == "defeat_any_gym":
elif world.options.route_3_condition == "defeat_any_gym":
return state.has_any(["Defeat Brock", "Defeat Misty", "Defeat Lt. Surge", "Defeat Erika", "Defeat Koga",
"Defeat Blaine", "Defeat Sabrina", "Defeat Viridian Gym Giovanni"], player)
elif state.multiworld.worlds[player].options.route_3_condition == "boulder_badge":
elif world.options.route_3_condition == "boulder_badge":
return state.has("Boulder Badge", player)
elif state.multiworld.worlds[player].options.route_3_condition == "any_badge":
elif world.options.route_3_condition == "any_badge":
return state.has_any(["Boulder Badge", "Cascade Badge", "Thunder Badge", "Rainbow Badge", "Marsh Badge",
"Soul Badge", "Volcano Badge", "Earth Badge"], player)
# open
Expand Down
12 changes: 6 additions & 6 deletions worlds/pokemon_rb/pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,21 +396,21 @@ def number_of_zones(mon):
while True:
intervene_move = None
test_state = multiworld.get_all_state(False)
if not logic.can_learn_hm(test_state, "Surf", player):
if not logic.can_learn_hm(test_state, world, "Surf", player):
intervene_move = "Surf"
elif not logic.can_learn_hm(test_state, "Strength", player):
elif not logic.can_learn_hm(test_state, world, "Strength", player):
intervene_move = "Strength"
# cut may not be needed if accessibility is minimal, unless you need all 8 badges and badgesanity is off,
# as you will require cut to access celadon gyn
elif ((not logic.can_learn_hm(test_state, "Cut", player)) and
elif ((not logic.can_learn_hm(test_state, world, "Cut", player)) and
(multiworld.accessibility[player] != "minimal" or ((not
multiworld.badgesanity[player]) and max(
multiworld.elite_four_badges_condition[player],
multiworld.route_22_gate_condition[player],
multiworld.victory_road_condition[player])
> 7) or (multiworld.door_shuffle[player] not in ("off", "simple")))):
intervene_move = "Cut"
elif ((not logic.can_learn_hm(test_state, "Flash", player))
elif ((not logic.can_learn_hm(test_state, world, "Flash", player))
and multiworld.dark_rock_tunnel_logic[player]
and (multiworld.accessibility[player] != "minimal"
or multiworld.door_shuffle[player])):
Expand All @@ -419,7 +419,7 @@ def number_of_zones(mon):
# as reachable, and if on no door shuffle or simple, fly is simply never necessary.
# We only intervene if a Pokémon is able to learn fly but none are reachable, as that would have been
# considered in door shuffle.
elif ((not logic.can_learn_hm(test_state, "Fly", player))
elif ((not logic.can_learn_hm(test_state, world, "Fly", player))
and multiworld.door_shuffle[player] not in
("off", "simple") and [world.fly_map, world.town_map_fly_map] != ["Pallet Town", "Pallet Town"]):
intervene_move = "Fly"
Expand All @@ -429,4 +429,4 @@ def number_of_zones(mon):
intervene(intervene_move, test_state)
last_intervene = intervene_move
else:
break
break
Loading

0 comments on commit 14af74b

Please sign in to comment.