extends "res://scripts/multiplayer.gd"
var queued_messages = []
var queued_messages_mutex = Mutex.new()
func _request_lobby_list():
var apclient = global.get_node("Archipelago")
Steam.addRequestLobbyListStringFilter(
"archipelago", apclient._seed, Steam.LOBBY_COMPARISON_EQUAL
)
._request_lobby_list()
func _on_lobby_created(result: int, lobby_id: int) -> void:
if result != Steam.RESULT_OK:
return
var apclient = global.get_node("Archipelago")
var _ignore = Steam.setLobbyData(lobby_id, "archipelago", apclient._seed)
._on_lobby_created(result, lobby_id)
func _on_lobby_joined(lobby_id: int, permissions: int, locked: bool, result: int) -> void:
if result != Steam.RESULT_OK:
return
var apclient = global.get_node("Archipelago")
Steam.setLobbyMemberData(lobby_id, "slot_name", apclient._player_name_by_slot[apclient._slot])
._on_lobby_joined(lobby_id, permissions, locked, result)
func _update_lobby_members():
._update_lobby_members()
if active_lobby_id == 0:
return
var lobby_size: int = Steam.getNumLobbyMembers(active_lobby_id)
for i in range(0, lobby_size):
var member_id: int = Steam.getLobbyMemberByIndex(active_lobby_id, i)
if member_id != player_steam_id and member_id in active_lobby_members:
var slot_name = Steam.getLobbyMemberData(active_lobby_id, member_id, "slot_name")
active_lobby_members[member_id].steam_name = slot_name
func say(text):
queued_messages_mutex.lock()
queued_messages.append(text)
queued_messages_mutex.unlock()
func _physics_process(_delta):
if queued_messages_mutex.try_lock() == OK:
if queued_messages.empty():
queued_messages_mutex.unlock()
else:
var messages = queued_messages.duplicate()
queued_messages = []
queued_messages_mutex.unlock()
var player = get_tree().get_root().get_node("Spatial/player")
var space_state = get_tree().get_root().get_world().direct_space_state
var nearby_members = []
for member_id in active_lobby_members.keys():
var other_member = active_lobby_members[member_id]
var ray = space_state.intersect_ray(
player.global_translation, other_member.global_translation, [player], 0b0101
)
if !("collider" in ray) or ray["collider"] == other_member:
# Visible!
nearby_members.append(member_id)
var apclient = global.get_node("Archipelago")
var player_name = apclient.get_player_name()
for member_id in nearby_members:
for msg in messages:
_send_p2p_packet(
{"solves": [{"say": msg, "from": player_name}]},
member_id,
Steam.P2P_SEND_RELIABLE,
true
)
# I'm completely hijacking this callback, since we're in ghost mode and it won't be called normally.
func _receive_solve(data):
if "say" in data:
get_tree().get_root().get_node("Spatial/AP_TextClient").parse_printjson(
"[LOCAL] [color=#fafad2]%s[/color]: %s" % [data["from"], data["say"]]
)
messages.showMessage("[color=#fafad2]%s[/color]: %s" % [data["from"], data["say"]])
func _send_hi(_discard):
pass