From 08ffb400114029569b4043b4f4c5a3f2af9b37b8 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Wed, 3 May 2023 17:25:41 -0400 Subject: Added progressive items --- ap_state.cpp | 94 +++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 51 insertions(+), 43 deletions(-) (limited to 'ap_state.cpp') diff --git a/ap_state.cpp b/ap_state.cpp index c901dce..8b7339a 100644 --- a/ap_state.cpp +++ b/ap_state.cpp @@ -4,9 +4,10 @@ #define _WEBSOCKETPP_CPP11_STRICT_ #pragma comment(lib, "crypt32") +#include + #include #include -#include #include #include #include @@ -63,11 +64,13 @@ void APState::Connect(std::string server, std::string player, has_connection_result_ = false; apclient->set_room_info_handler([this, player, password]() { + inventory_.clear(); + tracker_frame_->SetStatusMessage( "Connected to Archipelago server. Authenticating..."); apclient->ConnectSlot(player, password, ITEM_HANDLING, {"Tracker"}, - {AP_MAJOR, AP_MINOR, AP_REVISION}); + {AP_MAJOR, AP_MINOR, AP_REVISION}); }); apclient->set_location_checked_handler( @@ -81,19 +84,19 @@ void APState::Connect(std::string server, std::string player, }); apclient->set_slot_disconnected_handler([this]() { - tracker_frame_->SetStatusMessage("Disconnected from Archipelago. Attempting to reconnect..."); + tracker_frame_->SetStatusMessage( + "Disconnected from Archipelago. Attempting to reconnect..."); }); apclient->set_socket_disconnected_handler([this]() { - tracker_frame_->SetStatusMessage("Disconnected from Archipelago. Attempting to reconnect..."); + tracker_frame_->SetStatusMessage( + "Disconnected from Archipelago. Attempting to reconnect..."); }); apclient->set_items_received_handler( [this](const std::list& items) { for (const APClient::NetworkItem& item : items) { - // TODO: Progressive items. - - inventory_.insert(item.item); + inventory_[item.item]++; std::cout << "Item: " << item.item << std::endl; } @@ -110,7 +113,8 @@ void APState::Connect(std::string server, std::string player, if (painting_shuffle_ && slot_data.contains("painting_entrance_to_exit")) { painting_mapping_.clear(); - for (const auto& mapping_it : slot_data["painting_entrance_to_exit"].items()) { + for (const auto& mapping_it : + slot_data["painting_entrance_to_exit"].items()) { painting_mapping_[mapping_it.key()] = mapping_it.value(); } } @@ -119,41 +123,40 @@ void APState::Connect(std::string server, std::string player, has_connection_result_ = true; }); - apclient->set_slot_refused_handler( - [this](const std::list& errors) { - connected_ = false; - has_connection_result_ = true; - - tracker_frame_->SetStatusMessage("Disconnected from Archipelago."); - - std::vector error_messages; - error_messages.push_back("Could not connect to Archipelago."); - - for (const std::string& error : errors) { - if (error == "InvalidSlot") { - error_messages.push_back("Invalid player name."); - } else if (error == "InvalidGame") { - error_messages.push_back( - "The specified player is not playing Lingo."); - } else if (error == "IncompatibleVersion") { - error_messages.push_back( - "The Archipelago server is not the correct version for this " - "client."); - } else if (error == "InvalidPassword") { - error_messages.push_back("Incorrect password."); - } else if (error == "InvalidItemsHandling") { - error_messages.push_back( - "Invalid item handling flag. This is a bug with the tracker. " - "Please report it to the lingo-ap-tracker GitHub."); - } else { - error_messages.push_back("Unknown error."); - } - } + apclient->set_slot_refused_handler([this]( + const std::list& errors) { + connected_ = false; + has_connection_result_ = true; - std::string full_message = hatkirby::implode(error_messages, " "); + tracker_frame_->SetStatusMessage("Disconnected from Archipelago."); + + std::vector error_messages; + error_messages.push_back("Could not connect to Archipelago."); + + for (const std::string& error : errors) { + if (error == "InvalidSlot") { + error_messages.push_back("Invalid player name."); + } else if (error == "InvalidGame") { + error_messages.push_back("The specified player is not playing Lingo."); + } else if (error == "IncompatibleVersion") { + error_messages.push_back( + "The Archipelago server is not the correct version for this " + "client."); + } else if (error == "InvalidPassword") { + error_messages.push_back("Incorrect password."); + } else if (error == "InvalidItemsHandling") { + error_messages.push_back( + "Invalid item handling flag. This is a bug with the tracker. " + "Please report it to the lingo-ap-tracker GitHub."); + } else { + error_messages.push_back("Unknown error."); + } + } - wxMessageBox(full_message, "Connection failed", wxOK | wxICON_ERROR); - }); + std::string full_message = hatkirby::implode(error_messages, " "); + + wxMessageBox(full_message, "Connection failed", wxOK | wxICON_ERROR); + }); client_active_ = true; @@ -202,6 +205,10 @@ void APState::Connect(std::string server, std::string player, !ap_id_by_item_name_.count(door.group_name)) { ap_id_by_item_name_[door.group_name] = GetItemId(door.group_name); } + + for (const ProgressiveRequirement& prog_req : door.progressives) { + ap_id_by_item_name_[prog_req.item_name] = GetItemId(prog_req.item_name); + } } } @@ -239,9 +246,10 @@ bool APState::HasColorItem(LingoColor color) const { } } -bool APState::HasItem(const std::string& item) const { +bool APState::HasItem(const std::string& item, int quantity) const { if (ap_id_by_item_name_.count(item)) { - return inventory_.count(ap_id_by_item_name_.at(item)); + int64_t ap_id = ap_id_by_item_name_.at(item); + return inventory_.count(ap_id) && inventory_.at(ap_id) >= quantity; } else { return false; } -- cgit 1.4.1