diff options
Diffstat (limited to 'client/Archipelago/manager.gd')
| -rw-r--r-- | client/Archipelago/manager.gd | 102 |
1 files changed, 98 insertions, 4 deletions
| diff --git a/client/Archipelago/manager.gd b/client/Archipelago/manager.gd index 35fc8e3..99cb47b 100644 --- a/client/Archipelago/manager.gd +++ b/client/Archipelago/manager.gd | |||
| @@ -13,6 +13,9 @@ var connection_history = [] | |||
| 13 | 13 | ||
| 14 | var client | 14 | var client |
| 15 | 15 | ||
| 16 | var _received_indexes = [] | ||
| 17 | var _last_new_item = -1 | ||
| 18 | |||
| 16 | signal could_not_connect | 19 | signal could_not_connect |
| 17 | signal connect_status | 20 | signal connect_status |
| 18 | signal ap_connected | 21 | signal ap_connected |
| @@ -35,6 +38,9 @@ func saveSettings(): | |||
| 35 | 38 | ||
| 36 | 39 | ||
| 37 | func connectToServer(): | 40 | func connectToServer(): |
| 41 | _received_indexes = [] | ||
| 42 | _last_new_item = -1 | ||
| 43 | |||
| 38 | client.connectToServer(ap_server, ap_user, ap_pass) | 44 | client.connectToServer(ap_server, ap_user, ap_pass) |
| 39 | 45 | ||
| 40 | 46 | ||
| @@ -62,9 +68,20 @@ func has_item(item_id): | |||
| 62 | return client.hasItem(item_id) | 68 | return client.hasItem(item_id) |
| 63 | 69 | ||
| 64 | 70 | ||
| 65 | func _process_item(item_id, _index, _player, _flags): | 71 | func _process_item(item, index, from, flags): |
| 72 | if index != null: | ||
| 73 | if _received_indexes.has(index): | ||
| 74 | # Do not re-process items. | ||
| 75 | return | ||
| 76 | |||
| 77 | _received_indexes.append(index) | ||
| 78 | |||
| 79 | var item_name = "Unknown" | ||
| 80 | if client._item_id_to_name["Lingo 2"].has(item): | ||
| 81 | item_name = client._item_id_to_name["Lingo 2"][item] | ||
| 82 | |||
| 66 | var gamedata = global.get_node("Gamedata") | 83 | var gamedata = global.get_node("Gamedata") |
| 67 | var door_id = gamedata.door_id_by_ap_id.get(item_id, null) | 84 | var door_id = gamedata.door_id_by_ap_id.get(item, null) |
| 68 | if door_id != null and gamedata.get_door_map_name(door_id) == global.map: | 85 | if door_id != null and gamedata.get_door_map_name(door_id) == global.map: |
| 69 | var receivers = gamedata.get_door_receivers(door_id) | 86 | var receivers = gamedata.get_door_receivers(door_id) |
| 70 | var scene = get_tree().get_root().get_node_or_null("scene") | 87 | var scene = get_tree().get_root().get_node_or_null("scene") |
| @@ -79,9 +96,71 @@ func _process_item(item_id, _index, _player, _flags): | |||
| 79 | if pnode != null: | 96 | if pnode != null: |
| 80 | pnode.handleTriggered() | 97 | pnode.handleTriggered() |
| 81 | 98 | ||
| 99 | # Show a message about the item if it's new. | ||
| 100 | if index != null and index > _last_new_item: | ||
| 101 | _last_new_item = index | ||
| 102 | #saveLocaldata() | ||
| 82 | 103 | ||
| 83 | func _process_message(_message): | 104 | var player_name = "Unknown" |
| 84 | pass | 105 | if client._player_name_by_slot.has(from): |
| 106 | player_name = client._player_name_by_slot[from] | ||
| 107 | |||
| 108 | var item_color = colorForItemType(flags) | ||
| 109 | |||
| 110 | var message | ||
| 111 | if from == client._slot: | ||
| 112 | message = "Found [color=%s]%s[/color]" % [item_color, item_name] | ||
| 113 | else: | ||
| 114 | message = "Received [color=%s]%s[/color] from %s" % [item_color, item_name, player_name] | ||
| 115 | |||
| 116 | global._print(message) | ||
| 117 | |||
| 118 | global.get_node("Messages").showMessage(message) | ||
| 119 | |||
| 120 | |||
| 121 | func _process_message(message): | ||
| 122 | if ( | ||
| 123 | !message.has("receiving") | ||
| 124 | or !message.has("item") | ||
| 125 | or message["item"]["player"] != client._slot | ||
| 126 | ): | ||
| 127 | return | ||
| 128 | |||
| 129 | var item_name = "Unknown" | ||
| 130 | var item_player_game = client._game_by_player[message["receiving"]] | ||
| 131 | if client._item_id_to_name[item_player_game].has(message["item"]["item"]): | ||
| 132 | item_name = client._item_id_to_name[item_player_game][message["item"]["item"]] | ||
| 133 | |||
| 134 | var location_name = "Unknown" | ||
| 135 | var location_player_game = client._game_by_player[message["item"]["player"]] | ||
| 136 | if client._location_id_to_name[location_player_game].has(message["item"]["location"]): | ||
| 137 | location_name = ( | ||
| 138 | client._location_id_to_name[location_player_game][message["item"]["location"]] | ||
| 139 | ) | ||
| 140 | |||
| 141 | var player_name = "Unknown" | ||
| 142 | if client._player_name_by_slot.has(message["receiving"]): | ||
| 143 | player_name = client._player_name_by_slot[message["receiving"]] | ||
| 144 | |||
| 145 | var item_color = colorForItemType(message["item"]["flags"]) | ||
| 146 | |||
| 147 | if message["type"] == "Hint": | ||
| 148 | var is_for = "" | ||
| 149 | if message["receiving"] != client._slot: | ||
| 150 | is_for = " for %s" % player_name | ||
| 151 | if !message.has("found") || !message["found"]: | ||
| 152 | global.get_node("Messages").showMessage( | ||
| 153 | ( | ||
| 154 | "Hint: [color=%s]%s[/color]%s is on %s" | ||
| 155 | % [item_color, item_name, is_for, location_name] | ||
| 156 | ) | ||
| 157 | ) | ||
| 158 | else: | ||
| 159 | if message["receiving"] != client._slot: | ||
| 160 | var sentMsg = "Sent [color=%s]%s[/color] to %s" % [item_color, item_name, player_name] | ||
| 161 | #if _hinted_locations.has(message["item"]["location"]): | ||
| 162 | # sentMsg += " ([color=#fafad2]Hinted![/color])" | ||
| 163 | global.get_node("Messages").showMessage(sentMsg) | ||
| 85 | 164 | ||
| 86 | 165 | ||
| 87 | func _client_could_not_connect(): | 166 | func _client_could_not_connect(): |
| @@ -98,3 +177,18 @@ func _client_connected(): | |||
| 98 | 177 | ||
| 99 | func send_location(loc_id): | 178 | func send_location(loc_id): |
| 100 | client.sendLocation(loc_id) | 179 | client.sendLocation(loc_id) |
| 180 | |||
| 181 | |||
| 182 | func colorForItemType(flags): | ||
| 183 | var int_flags = int(flags) | ||
| 184 | if int_flags & 1: # progression | ||
| 185 | if int_flags & 2: # proguseful | ||
| 186 | return "#f0d200" | ||
| 187 | else: | ||
| 188 | return "#bc51e0" | ||
| 189 | elif int_flags & 2: # useful | ||
| 190 | return "#2b67ff" | ||
| 191 | elif int_flags & 4: # trap | ||
| 192 | return "#d63a22" | ||
| 193 | else: # filler | ||
| 194 | return "#14de9e" | ||
