about summary refs log tree commit diff stats
path: root/src/ap_state.cpp
diff options
context:
space:
mode:
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 5b02ba6..fdc0219 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;
@@ -119,6 +122,7 @@ struct APState {
119 inventory.clear(); 122 inventory.clear();
120 checked_locations.clear(); 123 checked_locations.clear();
121 data_storage.clear(); 124 data_storage.clear();
125 victory_data_storage_key.clear();
122 door_shuffle_mode = kNO_DOORS; 126 door_shuffle_mode = kNO_DOORS;
123 color_shuffle = false; 127 color_shuffle = false;
124 painting_shuffle = false; 128 painting_shuffle = false;
@@ -187,6 +191,10 @@ struct APState {
187 data_storage[key] = value.get<bool>(); 191 data_storage[key] = value.get<bool>();
188 TrackerLog("Data storage " + key + " retrieved as " + 192 TrackerLog("Data storage " + key + " retrieved as " +
189 (value.get<bool>() ? "true" : "false")); 193 (value.get<bool>() ? "true" : "false"));
194 } else if (value.is_number()) {
195 data_storage[key] = value.get<int>();
196 TrackerLog("Data storage " + key + " retrieved as " +
197 std::to_string(value.get<int>()));
190 } 198 }
191 } 199 }
192 200
@@ -198,11 +206,15 @@ struct APState {
198 const nlohmann::json&) { 206 const nlohmann::json&) {
199 if (value.is_boolean()) { 207 if (value.is_boolean()) {
200 data_storage[key] = value.get<bool>(); 208 data_storage[key] = value.get<bool>();
201 TrackerLog("Data storage " + key + " set to " + 209 TrackerLog("Data storage " + key + " retrieved as " +
202 (value.get<bool>() ? "true" : "false")); 210 (value.get<bool>() ? "true" : "false"));
203 211 } else if (value.is_number()) {
204 RefreshTracker(); 212 data_storage[key] = value.get<int>();
213 TrackerLog("Data storage " + key + " retrieved as " +
214 std::to_string(value.get<int>()));
205 } 215 }
216
217 RefreshTracker();
206 }); 218 });
207 219
208 apclient->set_slot_connected_handler([this]( 220 apclient->set_slot_connected_handler([this](
@@ -242,6 +254,15 @@ struct APState {
242 corrected_keys.push_back(data_storage_prefix + key); 254 corrected_keys.push_back(data_storage_prefix + key);
243 } 255 }
244 256
257 {
258 std::ostringstream vdsks;
259 vdsks << "_read_client_status_" << apclient->get_team_number() << "_"
260 << apclient->get_player_number();
261 victory_data_storage_key = vdsks.str();
262 }
263
264 corrected_keys.push_back(victory_data_storage_key);
265
245 apclient->Get(corrected_keys); 266 apclient->Get(corrected_keys);
246 apclient->SetNotify(corrected_keys); 267 apclient->SetNotify(corrected_keys);
247 }); 268 });
@@ -321,7 +342,7 @@ struct APState {
321 bool HasCheckedHuntPanel(int location_id) { 342 bool HasCheckedHuntPanel(int location_id) {
322 std::string key = 343 std::string key =
323 data_storage_prefix + "Hunt|" + std::to_string(location_id); 344 data_storage_prefix + "Hunt|" + std::to_string(location_id);
324 return data_storage.count(key) && data_storage.at(key); 345 return data_storage.count(key) && std::any_cast<bool>(data_storage.at(key));
325 } 346 }
326 347
327 bool HasItem(int item_id, int quantity) { 348 bool HasItem(int item_id, int quantity) {
@@ -330,7 +351,7 @@ struct APState {
330 351
331 bool HasAchievement(const std::string& name) { 352 bool HasAchievement(const std::string& name) {
332 std::string key = data_storage_prefix + "Achievement|" + name; 353 std::string key = data_storage_prefix + "Achievement|" + name;
333 return data_storage.count(key) && data_storage.at(key); 354 return data_storage.count(key) && std::any_cast<bool>(data_storage.at(key));
334 } 355 }
335 356
336 void RefreshTracker() { 357 void RefreshTracker() {
@@ -349,6 +370,12 @@ struct APState {
349 return ap_id; 370 return ap_id;
350 } 371 }
351 372
373 bool HasReachedGoal() {
374 return data_storage.count(victory_data_storage_key) &&
375 std::any_cast<int>(data_storage.at(victory_data_storage_key)) ==
376 30; // CLIENT_GOAL
377 }
378
352 void DestroyClient() { 379 void DestroyClient() {
353 client_active = false; 380 client_active = false;
354 apclient->reset(); 381 apclient->reset();
@@ -417,3 +444,5 @@ bool AP_HasAchievement(const std::string& achievement_name) {
417} 444}
418 445
419bool AP_HasEarlyColorHallways() { return GetState().early_color_hallways; } 446bool AP_HasEarlyColorHallways() { return GetState().early_color_hallways; }
447
448bool AP_HasReachedGoal() { return GetState().HasReachedGoal(); }