Skip to content

The Messenger: use the new region helpers #1687

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 16 additions & 27 deletions worlds/messenger/SubClasses.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Set, TYPE_CHECKING, Optional, Dict
from typing import TYPE_CHECKING, Optional

from BaseClasses import Region, Location, Item, ItemClassification, Entrance, CollectionState
from BaseClasses import Region, Location, Item, ItemClassification, CollectionState
from .Constants import NOTES, PROG_ITEMS, PHOBEKINS, USEFUL_ITEMS
from .Options import Goal
from .Regions import REGIONS, SEALS, MEGA_SHARDS
Expand All @@ -15,41 +15,30 @@
class MessengerRegion(Region):
def __init__(self, name: str, world: MessengerWorld) -> None:
super().__init__(name, world.player, world.multiworld)
self.add_locations(self.multiworld.worlds[self.player].location_name_to_id)
world.multiworld.regions.append(self)

def add_locations(self, name_to_id: Dict[str, int]) -> None:
for loc in REGIONS[self.name]:
self.locations.append(MessengerLocation(loc, self, name_to_id.get(loc, None)))
locations = [loc for loc in REGIONS[self.name]]
if self.name == "The Shop":
if self.multiworld.goal[self.player] > Goal.option_open_music_box:
self.locations.append(MessengerLocation("Shop Chest", self, None))
self.locations += [MessengerShopLocation(f"The Shop - {shop_loc}", self,
name_to_id[f"The Shop - {shop_loc}"])
for shop_loc in SHOP_ITEMS]
self.locations += [MessengerShopLocation(figurine, self, name_to_id[figurine])
for figurine in FIGURINES]
locations.append("Shop Chest")
shop_locations = {f"The Shop - {shop_loc}": world.location_name_to_id[f"The Shop - {shop_loc}"]
for shop_loc in SHOP_ITEMS}
shop_locations.update(**{figurine: world.location_name_to_id[figurine] for figurine in FIGURINES})
self.add_locations(shop_locations, MessengerShopLocation)
elif self.name == "Tower HQ":
self.locations.append(MessengerLocation("Money Wrench", self, name_to_id["Money Wrench"]))
locations.append("Money Wrench")
if self.multiworld.shuffle_seals[self.player] and self.name in SEALS:
self.locations += [MessengerLocation(seal_loc, self, name_to_id[seal_loc])
for seal_loc in SEALS[self.name]]
locations += [seal_loc for seal_loc in SEALS[self.name]]
if self.multiworld.shuffle_shards[self.player] and self.name in MEGA_SHARDS:
self.locations += [MessengerLocation(shard, self, name_to_id[shard])
for shard in MEGA_SHARDS[self.name]]

def add_exits(self, exits: Set[str]) -> None:
for exit in exits:
ret = Entrance(self.player, f"{self.name} -> {exit}", self)
self.exits.append(ret)
ret.connect(self.multiworld.get_region(exit, self.player))
locations += [shard for shard in MEGA_SHARDS[self.name]]
loc_dict = {loc: world.location_name_to_id[loc] if loc in world.location_name_to_id else None for loc in locations}
self.add_locations(loc_dict, MessengerLocation)
world.multiworld.regions.append(self)


class MessengerLocation(Location):
game = "The Messenger"

def __init__(self, name: str, parent: MessengerRegion, loc_id: Optional[int]) -> None:
super().__init__(parent.player, name, loc_id, parent)
def __init__(self, player: int, name: str, loc_id: Optional[int], parent: MessengerRegion) -> None:
super().__init__(player, name, loc_id, parent)
if loc_id is None:
self.place_locked_item(MessengerItem(name, parent.player, None))

Expand Down
3 changes: 2 additions & 1 deletion worlds/messenger/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ def create_items(self) -> None:
total_seals = min(len(self.multiworld.get_unfilled_locations(self.player)) - len(itempool),
self.multiworld.total_seals[self.player].value)
if total_seals < self.total_seals:
logging.warning(f"Not enough locations for total seals setting. Adjusting to {total_seals}")
logging.warning(f"Not enough locations for total seals setting "
f"({self.multiworld.total_seals[self.player].value}). Adjusting to {total_seals}")
self.total_seals = total_seals
self.required_seals = int(self.multiworld.percent_seals_required[self.player].value / 100 * self.total_seals)

Expand Down