diff options
Diffstat (limited to 'client/Archipelago/client.gd')
| -rw-r--r-- | client/Archipelago/client.gd | 57 |
1 files changed, 47 insertions, 10 deletions
| diff --git a/client/Archipelago/client.gd b/client/Archipelago/client.gd index 4c34e91..2e080fd 100644 --- a/client/Archipelago/client.gd +++ b/client/Archipelago/client.gd | |||
| @@ -32,17 +32,21 @@ 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 | |||
| 46 | global._print("Instantiated APClient") | 50 | global._print("Instantiated APClient") |
| 47 | 51 | ||
| 48 | # Read AP datapackages from file, if there are any | 52 | # Read AP datapackages from file, if there are any |
| @@ -74,6 +78,8 @@ func _reset_state(): | |||
| 74 | _authenticated = false | 78 | _authenticated = false |
| 75 | _try_wss = false | 79 | _try_wss = false |
| 76 | _has_connected = false | 80 | _has_connected = false |
| 81 | _received_items = {} | ||
| 82 | _received_indexes = [] | ||
| 77 | 83 | ||
| 78 | 84 | ||
| 79 | func _errored(): | 85 | func _errored(): |
| @@ -183,7 +189,7 @@ func _process(_delta): | |||
| 183 | player["slot"] | 189 | player["slot"] |
| 184 | )]["game"] | 190 | )]["game"] |
| 185 | 191 | ||
| 186 | emit_signal("client_connected") | 192 | emit_signal("client_connected", _slot_data) |
| 187 | 193 | ||
| 188 | elif cmd == "ConnectionRefused": | 194 | elif cmd == "ConnectionRefused": |
| 189 | var error_message = "" | 195 | var error_message = "" |
| @@ -228,21 +234,40 @@ func _process(_delta): | |||
| 228 | elif cmd == "ReceivedItems": | 234 | elif cmd == "ReceivedItems": |
| 229 | var i = 0 | 235 | var i = 0 |
| 230 | for item in message["items"]: | 236 | for item in message["items"]: |
| 231 | if not _received_items.has(int(item["item"])): | 237 | var index = int(message["index"] + i) |
| 232 | _received_items.append(int(item["item"])) | 238 | i += 1 |
| 239 | |||
| 240 | if _received_indexes.has(index): | ||
| 241 | # Do not re-process items. | ||
| 242 | continue | ||
| 243 | |||
| 244 | _received_indexes.append(index) | ||
| 245 | |||
| 246 | var item_id = int(item["item"]) | ||
| 247 | _received_items[item_id] = _received_items.get(item_id, 0) + 1 | ||
| 233 | 248 | ||
| 234 | emit_signal( | 249 | emit_signal( |
| 235 | "item_received", | 250 | "item_received", |
| 236 | int(item["item"]), | 251 | item_id, |
| 237 | int(message["index"]) + i, | 252 | index, |
| 238 | int(item["player"]), | 253 | int(item["player"]), |
| 239 | int(item["flags"]) | 254 | int(item["flags"]), |
| 255 | _received_items[item_id] | ||
| 240 | ) | 256 | ) |
| 241 | i += 1 | ||
| 242 | 257 | ||
| 243 | elif cmd == "PrintJSON": | 258 | elif cmd == "PrintJSON": |
| 244 | emit_signal("message_received", message) | 259 | emit_signal("message_received", message) |
| 245 | 260 | ||
| 261 | elif cmd == "LocationInfo": | ||
| 262 | for loc in message["locations"]: | ||
| 263 | emit_signal( | ||
| 264 | "location_scout_received", | ||
| 265 | int(loc["item"]), | ||
| 266 | int(loc["location"]), | ||
| 267 | int(loc["player"]), | ||
| 268 | int(loc["flags"]) | ||
| 269 | ) | ||
| 270 | |||
| 246 | elif state == WebSocketPeer.STATE_CLOSED: | 271 | elif state == WebSocketPeer.STATE_CLOSED: |
| 247 | if _has_connected: | 272 | if _has_connected: |
| 248 | _closed() | 273 | _closed() |
| @@ -353,6 +378,10 @@ func sendLocation(loc_id): | |||
| 353 | sendMessage([{"cmd": "LocationChecks", "locations": [loc_id]}]) | 378 | sendMessage([{"cmd": "LocationChecks", "locations": [loc_id]}]) |
| 354 | 379 | ||
| 355 | 380 | ||
| 381 | func sendLocations(loc_ids): | ||
| 382 | sendMessage([{"cmd": "LocationChecks", "locations": loc_ids}]) | ||
| 383 | |||
| 384 | |||
| 356 | func setValue(key, value, operation = "replace"): | 385 | func setValue(key, value, operation = "replace"): |
| 357 | sendMessage( | 386 | sendMessage( |
| 358 | [ | 387 | [ |
| @@ -374,5 +403,13 @@ func completedGoal(): | |||
| 374 | sendMessage([{"cmd": "StatusUpdate", "status": 30}]) # CLIENT_GOAL | 403 | sendMessage([{"cmd": "StatusUpdate", "status": 30}]) # CLIENT_GOAL |
| 375 | 404 | ||
| 376 | 405 | ||
| 406 | func scoutLocations(loc_ids): | ||
| 407 | sendMessage([{"cmd": "LocationScouts", "locations": loc_ids}]) | ||
| 408 | |||
| 409 | |||
| 377 | func hasItem(item_id): | 410 | func hasItem(item_id): |
| 378 | return _received_items.has(item_id) | 411 | return _received_items.has(item_id) |
| 412 | |||
| 413 | |||
| 414 | func getItemAmount(item_id): | ||
| 415 | return _received_items.get(item_id, 0) | ||
