Skip to content

Commit

Permalink
hint/scouting/deathlink fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilyV99 committed Jul 15, 2024
1 parent 4f829f2 commit 13446bb
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
17 changes: 11 additions & 6 deletions godot_ap/ap_files/connection_info.gd
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ signal obtained_items(items: Array[NetworkItem]) ## Emitted for each item *packe
signal refresh_items(items: Array[NetworkItem]) ## Emitted when the server re-sends ALL obtained items
signal on_hint_update(hints: Array[NetworkHint]) ## Emitted when hints relevant to this client change

signal all_scout_cached ## Emitted when a scout packet containing ALL locations is received (see `force_scout_all`)
# Outgoing server packets
var _notified_keys: Dictionary = {}
var _hint_listening: bool = false
Expand Down Expand Up @@ -132,13 +133,16 @@ func scout(location: int, create_as_hint: int, proc: Callable) -> void:
_scout_queue[location] = [proc]
else: _scout_queue[location].append(proc)
func _on_locinfo(json: Dictionary) -> void:
for loc in json.get("locations", []):
var locid = loc["location"]
var locs = json.get("locations", [])
for loc in locs:
var locid = loc["location"] as int
_scout_cache[locid] = NetworkItem.from(loc, false)
for proc in _scout_queue.get(locid, []):
proc.call(_scout_cache[locid])
_scout_queue.erase(locid)
func _force_scout_all() -> void: ## Scouts every location into the local cache
if locs.size() == slot_locations.size():
all_scout_cached.emit()
func force_scout_all() -> void: ## Scouts every location into the local cache
Archipelago.send_command("LocationScouts", {"locations": slot_locations.keys(), "create_as_hint": 0})

## Sends a `Bounce` packet with whatever information you like
Expand All @@ -160,8 +164,9 @@ func send_deathlink(cause: String = ""):
if not Archipelago.is_deathlink():
AP.log("Tried to send DeathLink while DeathLink is not enabled!")
return
var cmd: Dictionary = {}
var cmd: Dictionary = {"data": {}}
if not cause.is_empty():
cmd["cause"] = cause
cmd["source"] = get_player_name(-1, false)
cmd["data"]["cause"] = cause
cmd["data"]["source"] = get_player_name(-1, false)
cmd["data"]["time"] = Time.get_unix_time_from_system()
send_bounce(cmd, [], [], ["DeathLink"])
9 changes: 9 additions & 0 deletions godot_ap/ap_files/network_hint.gd
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,14 @@ static func update_hint_status(targ_status: Status, part: BaseConsole.TextPart):
part.text = NetworkHint.status_names.get(targ_status, "Unknown")
part.color = NetworkHint.status_colors.get(targ_status, "red")

func as_plain_string() -> String:
return "%s %s '%s' (%s) for %s at '%s'" % [
Archipelago.conn.get_player_name(item.src_player_id),
"found" if status == Status.FOUND else "will find",
item.get_name(), item.get_classification(),
Archipelago.conn.get_player_name(item.dest_player_id),
Archipelago.conn.get_gamedata_for_player(item.src_player_id).get_loc_name(item.loc_id)
]

func _to_string():
return "HINT(%d %d %d %d %d)" % [item.src_player_id,item.id,item.dest_player_id,item.loc_id,status]
2 changes: 2 additions & 0 deletions godot_ap/ap_files/network_item.gd
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ static func from_hint(json: Dictionary) -> NetworkItem:

func is_local() -> bool:
return src_player_id == dest_player_id
func is_prog() -> bool:
return flags & AP.ItemClassification.PROG

func get_name() -> String:
return Archipelago.conn.get_gamedata_for_player(dest_player_id).get_item_name(id)
Expand Down
1 change: 1 addition & 0 deletions godot_ap/autoloads/archipelago.gd
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ func send_packet(obj: Array) -> void:
_socket.send_text(s)
func _handle_command(json: Dictionary) -> void:
var command = json["cmd"]
comm_log("RECV", str(json))
match command:
"RoomInfo":
status = APStatus.CONNECTED
Expand Down

0 comments on commit 13446bb

Please sign in to comment.