diff options
Diffstat (limited to 'client/Archipelago/client.gd')
| -rw-r--r-- | client/Archipelago/client.gd | 65 |
1 files changed, 52 insertions, 13 deletions
| diff --git a/client/Archipelago/client.gd b/client/Archipelago/client.gd index d394b6c..843647d 100644 --- a/client/Archipelago/client.gd +++ b/client/Archipelago/client.gd | |||
| @@ -32,20 +32,26 @@ var _players = [] | |||
| 32 | var _player_name_by_slot = {} | 32 | var _player_name_by_slot = {} |
| 33 | var _game_by_player = {} | 33 | var _game_by_player = {} |
| 34 | var _checked_locations = [] | 34 | var _checked_locations = [] |
| 35 | var _received_items = [] | 35 | var _received_indexes = [] |
| 36 | var _received_items = {} | ||
| 36 | var _slot_data = {} | 37 | var _slot_data = {} |
| 37 | 38 | ||
| 38 | signal could_not_connect | 39 | signal could_not_connect |
| 39 | signal connect_status | 40 | signal connect_status |
| 40 | signal client_connected | 41 | signal client_connected(slot_data) |
| 41 | signal item_received(item_id, index, player, flags) | 42 | signal item_received(item_id, index, player, flags, amount) |
| 42 | signal message_received(message) | 43 | signal message_received(message) |
| 44 | signal location_scout_received(item_id, location_id, player, flags) | ||
| 43 | 45 | ||
| 44 | 46 | ||
| 45 | func _init(): | 47 | func _init(): |
| 48 | set_process_mode(Node.PROCESS_MODE_ALWAYS) | ||
| 49 | |||
| 50 | _ws.inbound_buffer_size = 8388608 | ||
| 51 | |||
| 46 | global._print("Instantiated APClient") | 52 | global._print("Instantiated APClient") |
| 47 | 53 | ||
| 48 | # Read AP settings from file, if there are any | 54 | # Read AP datapackages from file, if there are any |
| 49 | if FileAccess.file_exists("user://ap_datapackages"): | 55 | if FileAccess.file_exists("user://ap_datapackages"): |
| 50 | var file = FileAccess.open("user://ap_datapackages", FileAccess.READ) | 56 | var file = FileAccess.open("user://ap_datapackages", FileAccess.READ) |
| 51 | var data = file.get_var(true) | 57 | var data = file.get_var(true) |
| @@ -74,6 +80,8 @@ func _reset_state(): | |||
| 74 | _authenticated = false | 80 | _authenticated = false |
| 75 | _try_wss = false | 81 | _try_wss = false |
| 76 | _has_connected = false | 82 | _has_connected = false |
| 83 | _received_items = {} | ||
| 84 | _received_indexes = [] | ||
| 77 | 85 | ||
| 78 | 86 | ||
| 79 | func _errored(): | 87 | func _errored(): |
| @@ -183,7 +191,7 @@ func _process(_delta): | |||
| 183 | player["slot"] | 191 | player["slot"] |
| 184 | )]["game"] | 192 | )]["game"] |
| 185 | 193 | ||
| 186 | emit_signal("client_connected") | 194 | emit_signal("client_connected", _slot_data) |
| 187 | 195 | ||
| 188 | elif cmd == "ConnectionRefused": | 196 | elif cmd == "ConnectionRefused": |
| 189 | var error_message = "" | 197 | var error_message = "" |
| @@ -219,7 +227,7 @@ func _process(_delta): | |||
| 219 | error_message = "Unknown error." | 227 | error_message = "Unknown error." |
| 220 | 228 | ||
| 221 | _initiated_disconnect = true | 229 | _initiated_disconnect = true |
| 222 | _ws.disconnect_from_host() | 230 | _ws.close() |
| 223 | 231 | ||
| 224 | emit_signal("could_not_connect", error_message) | 232 | emit_signal("could_not_connect", error_message) |
| 225 | global._print("Connection to AP refused") | 233 | global._print("Connection to AP refused") |
| @@ -228,21 +236,40 @@ func _process(_delta): | |||
| 228 | elif cmd == "ReceivedItems": | 236 | elif cmd == "ReceivedItems": |
| 229 | var i = 0 | 237 | var i = 0 |
| 230 | for item in message["items"]: | 238 | for item in message["items"]: |
| 231 | if not _received_items.has(int(item["item"])): | 239 | var index = int(message["index"] + i) |
| 232 | _received_items.append(int(item["item"])) | 240 | i += 1 |
| 241 | |||
| 242 | if _received_indexes.has(index): | ||
| 243 | # Do not re-process items. | ||
| 244 | continue | ||
| 245 | |||
| 246 | _received_indexes.append(index) | ||
| 247 | |||
| 248 | var item_id = int(item["item"]) | ||
| 249 | _received_items[item_id] = _received_items.get(item_id, 0) + 1 | ||
| 233 | 250 | ||
| 234 | emit_signal( | 251 | emit_signal( |
| 235 | "item_received", | 252 | "item_received", |
| 236 | int(item["item"]), | 253 | item_id, |
| 237 | int(message["index"]) + i, | 254 | index, |
| 238 | int(item["player"]), | 255 | int(item["player"]), |
| 239 | int(item["flags"]) | 256 | int(item["flags"]), |
| 257 | _received_items[item_id] | ||
| 240 | ) | 258 | ) |
| 241 | i += 1 | ||
| 242 | 259 | ||
| 243 | elif cmd == "PrintJSON": | 260 | elif cmd == "PrintJSON": |
| 244 | emit_signal("message_received", message) | 261 | emit_signal("message_received", message) |
| 245 | 262 | ||
| 263 | elif cmd == "LocationInfo": | ||
| 264 | for loc in message["locations"]: | ||
| 265 | emit_signal( | ||
| 266 | "location_scout_received", | ||
| 267 | int(loc["item"]), | ||
| 268 | int(loc["location"]), | ||
| 269 | int(loc["player"]), | ||
| 270 | int(loc["flags"]) | ||
| 271 | ) | ||
| 272 | |||
| 246 | elif state == WebSocketPeer.STATE_CLOSED: | 273 | elif state == WebSocketPeer.STATE_CLOSED: |
| 247 | if _has_connected: | 274 | if _has_connected: |
| 248 | _closed() | 275 | _closed() |
| @@ -284,7 +311,7 @@ func connectToServer(server, un, pw): | |||
| 284 | % err | 311 | % err |
| 285 | ) | 312 | ) |
| 286 | ) | 313 | ) |
| 287 | global._print("Could not connect to AP: " + err) | 314 | global._print("Could not connect to AP: %d" % err) |
| 288 | return | 315 | return |
| 289 | _should_process = true | 316 | _should_process = true |
| 290 | 317 | ||
| @@ -353,6 +380,10 @@ func sendLocation(loc_id): | |||
| 353 | sendMessage([{"cmd": "LocationChecks", "locations": [loc_id]}]) | 380 | sendMessage([{"cmd": "LocationChecks", "locations": [loc_id]}]) |
| 354 | 381 | ||
| 355 | 382 | ||
| 383 | func sendLocations(loc_ids): | ||
| 384 | sendMessage([{"cmd": "LocationChecks", "locations": loc_ids}]) | ||
| 385 | |||
| 386 | |||
| 356 | func setValue(key, value, operation = "replace"): | 387 | func setValue(key, value, operation = "replace"): |
| 357 | sendMessage( | 388 | sendMessage( |
| 358 | [ | 389 | [ |
| @@ -374,5 +405,13 @@ func completedGoal(): | |||
| 374 | sendMessage([{"cmd": "StatusUpdate", "status": 30}]) # CLIENT_GOAL | 405 | sendMessage([{"cmd": "StatusUpdate", "status": 30}]) # CLIENT_GOAL |
| 375 | 406 | ||
| 376 | 407 | ||
| 408 | func scoutLocations(loc_ids): | ||
| 409 | sendMessage([{"cmd": "LocationScouts", "locations": loc_ids}]) | ||
| 410 | |||
| 411 | |||
| 377 | func hasItem(item_id): | 412 | func hasItem(item_id): |
| 378 | return _received_items.has(item_id) | 413 | return _received_items.has(item_id) |
| 414 | |||
| 415 | |||
| 416 | func getItemAmount(item_id): | ||
| 417 | return _received_items.get(item_id, 0) | ||
