Skip to content
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
19 changes: 10 additions & 9 deletions worlds/portal2/Locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ class Portal2Location(Location):
"Portal Carousel Completion": [button, floor_button],
"Smooth Jazz Completion": [floor_button],
"Cube Momentum Completion": [floor_button],
"Incinerator Completion": [],
"Future Starter Completion": [floor_button],
"Incinerator Completion": [weighted_cube],
# Chapter 2
"Laser Intro Completion": [portal_gun_2],
"Laser Stairs Completion": [portal_gun_2, floor_button],
Expand All @@ -233,15 +234,15 @@ class Portal2Location(Location):
"Catapult Intro Completion": [portal_gun_2, floor_button],
"Trust Fling Completion": [portal_gun_2, faith_plate, floor_button],
"Pit Flings Completion": [portal_gun_2],
"Fizzler Intro Completion": [portal_gun_2],
"Fizzler Intro Completion": [portal_gun_2, laser, laser_catcher],
# Chapter 3
"Ricochet Completion": [portal_gun_2, weighted_cube],
"Ricochet Completion": [portal_gun_2, weighted_cube, floor_button],
"Bridge Intro Completion": [portal_gun_2, floor_button],
"Bridge the Gap Completion": [weighted_cube, button, floor_button],
"Turret Intro Completion": [floor_button],
"Laser Relays Completion": [laser_relays, laser, reflection_cube],
"Turret Blocker Completion": [floor_button],
"Laser Vs. Turret Completion": [portal_gun_2, laser, laser_catcher],
"Laser Vs. Turret Completion": [portal_gun_2],
"Pull The Rug Completion": [floor_button, weighted_cube, bridge, portal_gun_2],
# Chapter 4
"Column Blocker Completion": [portal_gun_2],
Expand All @@ -259,25 +260,25 @@ class Portal2Location(Location):
"Crazy Box Completion": [portal_gun_2, old_floor_button],
# Chapter 7
"Propulsion Intro Completion": [portal_gun_2],
"Propulsion Flings Completion": [portal_gun_2, antique_cube],
"Propulsion Flings Completion": [portal_gun_2, blue_gel],
"Conversion Intro Completion": [portal_gun_2],
"Three Gels Completion": [portal_gun_2, blue_gel],
# Chapter 8
"Funnel Intro Completion": [floor_button, funnel],
"Ceiling Button Completion": [floor_button, frankenturret, button, portal_gun_2],
"Wall Button Completion": [floor_button, frankenturret, button, portal_gun_2],
"Polarity Completion": [funnel],
"Wall Button Completion": [floor_button, funnel, portal_gun_2],
"Polarity Completion": [portal_gun_2, funnel],
"Funnel Catch Completion": [portal_gun_2],
"Stop The Box Completion": [floor_button, portal_gun_2],
"Laser Catapult Completion": [portal_gun_2],
"Laser Platform Completion": [portal_gun_2, funnel],
"Propulsion Catch Completion": [button, frankenturret],
"Propulsion Catch Completion": [floor_button, funnel],
"Repulsion Polarity Completion": [turrets, button, blue_gel],
# Chapter 9
"Finale 1 Completion": [portal_gun_2, frankenturret, faith_plate],
"Finale 2 Completion": [portal_gun_2],
"Finale 3 Completion": [portal_gun_2, funnel],
"Finale 4 Completion": [portal_gun_2, potatos, blue_gel, white_gel, adventure_core, space_core, fact_core],
"Finale 4 Completion": [portal_gun_2, potatos, white_gel, adventure_core, space_core, fact_core],
}

sub_locations_in_maps: dict[str, list[str]] = {
Expand Down
2 changes: 1 addition & 1 deletion worlds/portal2/archipelago.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"game": "Portal 2",
"authors": [ "GlassToadstool" ],
"minimum_ap_version": "0.6.3",
"world_version": "0.7.1"
"world_version": "0.7.2"
}
61 changes: 52 additions & 9 deletions worlds/portal2/client/Portal2Client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@
import time
import typing

from CommonClient import CommonContext, server_loop, ClientCommandProcessor, logger, gui_enabled
tracker_loaded = False
try:
from worlds.tracker.TrackerClient import TrackerGameContext as CommonContext, TrackerCommandProcessor as ClientCommandProcessor
tracker_loaded = True
except ModuleNotFoundError:
from CommonClient import CommonContext, ClientCommandProcessor

from CommonClient import server_loop, logger, gui_enabled
from NetUtils import ClientStatus, NetworkItem
from Utils import async_start, init_logging

Expand Down Expand Up @@ -68,11 +75,19 @@ def _cmd_needed(self, *location_name):
break
self.output(message)

def _cmd_ping(self):
async def player_in_map(compro):
is_in_map = await compro.ctx.is_player_in_map()
compro.output("pong" if is_in_map else "no pong recieved from server")
loop = asyncio.get_event_loop()
loop.create_task(player_in_map(self))

class Portal2Context(CommonContext):
command_processor = Portal2CommandProcessor
game_command_sender_task: typing.Optional["asyncio.Task[None]"] = None
game_message_listener_task: typing.Optional["asyncio.Task[None]"] = None
game = "Portal 2"
tags = {"AP"}
items_handling = 0b111 # receive all items for /received

HOST = "localhost"
Expand Down Expand Up @@ -164,16 +179,27 @@ async def p2_command_sender(self):
try:
while True:
try:
reader, writer = await asyncio.open_connection(self.HOST, self.PORT)
_, writer = await asyncio.open_connection(self.HOST, self.PORT)
except ConnectionRefusedError:
self.sender_active = False
await asyncio.sleep(self.current_reconnect_delay)
continue

self.sender_active = True
next_player_check = time.time()
try:
# Keep the connection open and send queued commands without blocking the loop
while True:
# Make sure player is in map before flushing the command queue
if next_player_check < time.time():
if not await self.is_player_in_map():
logger.info("Player not in a map sleeping 10 seconds")
await asyncio.sleep(10)
continue
else:
next_player_check = time.time() + 10
logger.info(f"Player is in a map, next check at {next_player_check}")

# handle commands
if self.command_queue:
c = self.command_queue.pop(0)
Expand Down Expand Up @@ -206,6 +232,23 @@ async def p2_command_sender(self):
logger.info("Game sender closed from cancellation")
raise

async def is_player_in_map(self):
try:
reader, writer = await asyncio.open_connection(self.HOST, self.PORT)
ping = 'script printl("Pong")\n'
writer.write(ping.encode())
await writer.drain()

data = await asyncio.wait_for(reader.read(1000), timeout=0.5)
pong = data.decode(errors="ignore").replace("\'", "").split('\r\n')
writer.close()
await writer.wait_closed()
if pong and pong[0] == "Pong":
return True
return False
except:
return False

async def handle_message(self, message: str):
if message.startswith("map_name:"):
map_name = message.split(':', 1)[1]
Expand Down Expand Up @@ -358,6 +401,7 @@ def handle_slot_data(self, slot_data: dict):
self.refresh_menu()

def on_package(self, cmd, args):
super().on_package(cmd, args)
def update_item_list():
# Update item list to only include items not collected
items_received_names = [self.item_names.lookup_in_game(i.item, self.game) for i in self.items_received]
Expand Down Expand Up @@ -423,14 +467,11 @@ def update_item_remove_commands(self):

def make_gui(self):
from kvui import GameManager
ui = super().make_gui()
ui.base_title = "Portal 2 Text Client"
ui.icon = r"worlds/portal2/data/Portalpelago.png"

class Portal2TextManager(GameManager):
base_title = "Portal 2 Text Client"
def __init__(self, ctx):
super().__init__(ctx)
self.icon = r"worlds/portal2/data/Portalpelago.png"

return Portal2TextManager
return ui

async def shutdown(self):
self.server_address = ""
Expand Down Expand Up @@ -467,6 +508,8 @@ async def main(args: Namespace):
ctx.game_command_sender_task = asyncio.create_task(ctx.p2_command_sender(), name="sender loop")
ctx.game_message_listener_task = asyncio.create_task(ctx.p2_message_listener(), name="listener loop")

if tracker_loaded:
ctx.run_generator()
if gui_enabled:
ctx.run_gui()
ctx.run_cli()
Expand Down
Loading