about summary refs log tree commit diff stats
path: root/src/ap_state.cpp
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2024-02-26 21:28:25 -0500
committerStar Rauchenberger <fefferburbia@gmail.com>2024-02-26 21:28:25 -0500
commitbe20b76ac411cc6017c4359ee36a1c9855a9f66e (patch)
treebc96ec093d6df99bb8f8968b67f215dbed19a02b /src/ap_state.cpp
parentefa0587b4399a45faecf5aa941ff75a40595a124 (diff)
parentc714f8d2a5827196ca86ed4351ae22cfce5dfce5 (diff)
downloadlingo-ap-tracker-be20b76ac411cc6017c4359ee36a1c9855a9f66e.tar.gz
lingo-ap-tracker-be20b76ac411cc6017c4359ee36a1c9855a9f66e.tar.bz2
lingo-ap-tracker-be20b76ac411cc6017c4359ee36a1c9855a9f66e.zip
Merge branch 'main' into future
Diffstat (limited to 'src/ap_state.cpp')
-rw-r--r--src/ap_state.cpp41
1 files changed, 35 insertions, 6 deletions
diff --git a/src/ap_state.cpp b/src/ap_state.cpp index ea74c93..1937597 100644 --- a/src/ap_state.cpp +++ b/src/ap_state.cpp
@@ -6,6 +6,7 @@
6 6
7#include <hkutil/string.h> 7#include <hkutil/string.h>
8 8
9#include <any>
9#include <apclient.hpp> 10#include <apclient.hpp>
10#include <apuuid.hpp> 11#include <apuuid.hpp>
11#include <chrono> 12#include <chrono>
@@ -15,6 +16,7 @@
15#include <memory> 16#include <memory>
16#include <mutex> 17#include <mutex>
17#include <set> 18#include <set>
19#include <sstream>
18#include <thread> 20#include <thread>
19#include <tuple> 21#include <tuple>
20 22
@@ -47,10 +49,11 @@ struct APState {
47 49
48 std::string data_storage_prefix; 50 std::string data_storage_prefix;
49 std::list<std::string> tracked_data_storage_keys; 51 std::list<std::string> tracked_data_storage_keys;
52 std::string victory_data_storage_key;
50 53
51 std::map<int64_t, int> inventory; 54 std::map<int64_t, int> inventory;
52 std::set<int64_t> checked_locations; 55 std::set<int64_t> checked_locations;
53 std::map<std::string, bool> data_storage; 56 std::map<std::string, std::any> data_storage;
54 57
55 DoorShuffleMode door_shuffle_mode = kNO_DOORS; 58 DoorShuffleMode door_shuffle_mode = kNO_DOORS;
56 bool color_shuffle = false; 59 bool color_shuffle = false;
@@ -121,6 +124,7 @@ struct APState {
121 inventory.clear(); 124 inventory.clear();
122 checked_locations.clear(); 125 checked_locations.clear();
123 data_storage.clear(); 126 data_storage.clear();
127 victory_data_storage_key.clear();
124 door_shuffle_mode = kNO_DOORS; 128 door_shuffle_mode = kNO_DOORS;
125 color_shuffle = false; 129 color_shuffle = false;
126 painting_shuffle = false; 130 painting_shuffle = false;
@@ -191,6 +195,10 @@ struct APState {
191 data_storage[key] = value.get<bool>(); 195 data_storage[key] = value.get<bool>();
192 TrackerLog("Data storage " + key + " retrieved as " + 196 TrackerLog("Data storage " + key + " retrieved as " +
193 (value.get<bool>() ? "true" : "false")); 197 (value.get<bool>() ? "true" : "false"));
198 } else if (value.is_number()) {
199 data_storage[key] = value.get<int>();
200 TrackerLog("Data storage " + key + " retrieved as " +
201 std::to_string(value.get<int>()));
194 } 202 }
195 } 203 }
196 204
@@ -202,11 +210,15 @@ struct APState {
202 const nlohmann::json&) { 210 const nlohmann::json&) {
203 if (value.is_boolean()) { 211 if (value.is_boolean()) {
204 data_storage[key] = value.get<bool>(); 212 data_storage[key] = value.get<bool>();
205 TrackerLog("Data storage " + key + " set to " + 213 TrackerLog("Data storage " + key + " retrieved as " +
206 (value.get<bool>() ? "true" : "false")); 214 (value.get<bool>() ? "true" : "false"));
207 215 } else if (value.is_number()) {
208 RefreshTracker(); 216 data_storage[key] = value.get<int>();
217 TrackerLog("Data storage " + key + " retrieved as " +
218 std::to_string(value.get<int>()));
209 } 219 }
220
221 RefreshTracker();
210 }); 222 });
211 223
212 apclient->set_slot_connected_handler([this]( 224 apclient->set_slot_connected_handler([this](
@@ -249,6 +261,15 @@ struct APState {
249 corrected_keys.push_back(data_storage_prefix + key); 261 corrected_keys.push_back(data_storage_prefix + key);
250 } 262 }
251 263
264 {
265 std::ostringstream vdsks;
266 vdsks << "_read_client_status_" << apclient->get_team_number() << "_"
267 << apclient->get_player_number();
268 victory_data_storage_key = vdsks.str();
269 }
270
271 corrected_keys.push_back(victory_data_storage_key);
272
252 apclient->Get(corrected_keys); 273 apclient->Get(corrected_keys);
253 apclient->SetNotify(corrected_keys); 274 apclient->SetNotify(corrected_keys);
254 }); 275 });
@@ -328,7 +349,7 @@ struct APState {
328 bool HasCheckedHuntPanel(int location_id) { 349 bool HasCheckedHuntPanel(int location_id) {
329 std::string key = 350 std::string key =
330 data_storage_prefix + "Hunt|" + std::to_string(location_id); 351 data_storage_prefix + "Hunt|" + std::to_string(location_id);
331 return data_storage.count(key) && data_storage.at(key); 352 return data_storage.count(key) && std::any_cast<bool>(data_storage.at(key));
332 } 353 }
333 354
334 bool HasItem(int item_id, int quantity) { 355 bool HasItem(int item_id, int quantity) {
@@ -337,7 +358,7 @@ struct APState {
337 358
338 bool HasAchievement(const std::string& name) { 359 bool HasAchievement(const std::string& name) {
339 std::string key = data_storage_prefix + "Achievement|" + name; 360 std::string key = data_storage_prefix + "Achievement|" + name;
340 return data_storage.count(key) && data_storage.at(key); 361 return data_storage.count(key) && std::any_cast<bool>(data_storage.at(key));
341 } 362 }
342 363
343 void RefreshTracker() { 364 void RefreshTracker() {
@@ -356,6 +377,12 @@ struct APState {
356 return ap_id; 377 return ap_id;
357 } 378 }
358 379
380 bool HasReachedGoal() {
381 return data_storage.count(victory_data_storage_key) &&
382 std::any_cast<int>(data_storage.at(victory_data_storage_key)) ==
383 30; // CLIENT_GOAL
384 }
385
359 void DestroyClient() { 386 void DestroyClient() {
360 client_active = false; 387 client_active = false;
361 apclient->reset(); 388 apclient->reset();
@@ -428,3 +455,5 @@ bool AP_HasEarlyColorHallways() { return GetState().early_color_hallways; }
428bool AP_IsPilgrimageEnabled() { return GetState().pilgrimage_enabled; } 455bool AP_IsPilgrimageEnabled() { return GetState().pilgrimage_enabled; }
429 456
430SunwarpAccess AP_GetSunwarpAccess() { return GetState().sunwarp_access; } 457SunwarpAccess AP_GetSunwarpAccess() { return GetState().sunwarp_access; }
458
459bool AP_HasReachedGoal() { return GetState().HasReachedGoal(); }