From 81d03738da31eafb3c160d3dc8d16d5819d21661 Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Sat, 9 Dec 2023 19:10:54 -0800 Subject: [PATCH] enable $quest to load v3 quests on ep3 --- src/ChatCommands.cc | 10 ++++++++-- src/ReceiveCommands.cc | 18 +++++++++++------- src/ReceiveCommands.hh | 2 +- src/ServerState.cc | 4 ++-- src/ServerState.hh | 2 +- 5 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/ChatCommands.cc b/src/ChatCommands.cc index 2387628d..e602ff4a 100644 --- a/src/ChatCommands.cc +++ b/src/ChatCommands.cc @@ -257,10 +257,16 @@ static void server_command_quest(shared_ptr c, const std::string& args) return; } + Version effective_version = is_ep3(c->version()) ? Version::GC_V3 : c->version(); + auto s = c->require_server_state(); auto l = c->require_lobby(); - auto q = s->quest_index_for_client(c)->get(stoul(args)); - set_lobby_quest(c->require_lobby(), q); + auto q = s->quest_index_for_version(effective_version)->get(stoul(args)); + if (!q) { + send_text_message(c, "$C6Quest not found"); + } else { + set_lobby_quest(c->require_lobby(), q, true); + } } static void server_command_qcheck(shared_ptr c, const std::string& args) { diff --git a/src/ReceiveCommands.cc b/src/ReceiveCommands.cc index 871d6632..1fc90957 100644 --- a/src/ReceiveCommands.cc +++ b/src/ReceiveCommands.cc @@ -1670,7 +1670,7 @@ static void on_09(shared_ptr c, uint16_t, uint32_t, string& data) { break; case MenuID::QUEST: { bool is_download_quest = !c->lobby.lock(); - auto quest_index = s->quest_index_for_client(c); + auto quest_index = s->quest_index_for_version(c->version()); if (!quest_index) { send_quest_info(c, "$C6Quests are not available.", is_download_quest); } else { @@ -1909,7 +1909,7 @@ static void on_quest_loaded(shared_ptr l) { } } -void set_lobby_quest(shared_ptr l, shared_ptr q) { +void set_lobby_quest(shared_ptr l, shared_ptr q, bool substitute_v3_for_ep3) { if (!l->is_game()) { throw logic_error("non-game lobby cannot accept a quest"); } @@ -1926,7 +1926,9 @@ void set_lobby_quest(shared_ptr l, shared_ptr q) { } l->quest = q; - l->episode = q->episode; + if (!is_ep3(l->base_version)) { + l->episode = q->episode; + } if (l->item_creator) { l->create_item_creator(); } @@ -1959,7 +1961,9 @@ void set_lobby_quest(shared_ptr l, shared_ptr q) { continue; } - auto vq = q->version(lc->version(), lc->language()); + Version effective_version = (substitute_v3_for_ep3 && is_ep3(lc->version())) ? Version::GC_V3 : lc->version(); + + auto vq = q->version(effective_version, lc->language()); if (!vq) { send_lobby_message_box(lc, "$C6Quest does not exist\nfor this game version."); lc->should_disconnect = true; @@ -2063,7 +2067,7 @@ static void on_10(shared_ptr c, uint16_t, uint32_t, string& data) { // always the download quest menu. (Episode 3 does actually have // online quests, but they're served via a server data request // instead of the file download paradigm that other versions use.) - auto quest_index = s->quest_index_for_client(c); + auto quest_index = s->quest_index_for_version(c->version()); const auto& categories = quest_index->categories(menu_type, Episode::EP3, c->version()); if (categories.size() == 1) { auto quests = quest_index->filter(menu_type, Episode::EP3, c->version(), categories[0]->category_id); @@ -2306,7 +2310,7 @@ static void on_10(shared_ptr c, uint16_t, uint32_t, string& data) { case MenuID::QUEST_CATEGORIES: { auto s = c->require_server_state(); - auto quest_index = s->quest_index_for_client(c); + auto quest_index = s->quest_index_for_version(c->version()); if (!quest_index) { send_lobby_message_box(c, "$C6Quests are not available."); break; @@ -2346,7 +2350,7 @@ static void on_10(shared_ptr c, uint16_t, uint32_t, string& data) { case MenuID::QUEST: { auto s = c->require_server_state(); - auto quest_index = s->quest_index_for_client(c); + auto quest_index = s->quest_index_for_version(c->version()); if (!quest_index) { send_lobby_message_box(c, "$C6Quests are not\navailable."); break; diff --git a/src/ReceiveCommands.hh b/src/ReceiveCommands.hh index 8b86229e..5da63490 100644 --- a/src/ReceiveCommands.hh +++ b/src/ReceiveCommands.hh @@ -17,7 +17,7 @@ std::shared_ptr create_game_generic( bool allow_v1 = false, std::shared_ptr watched_lobby = nullptr, std::shared_ptr battle_player = nullptr); -void set_lobby_quest(std::shared_ptr l, std::shared_ptr q); +void set_lobby_quest(std::shared_ptr l, std::shared_ptr q, bool substitute_v3_for_ep3 = false); void on_connect(std::shared_ptr c); void on_disconnect(std::shared_ptr c); diff --git a/src/ServerState.cc b/src/ServerState.cc index cb9e8a85..08e4f38b 100644 --- a/src/ServerState.cc +++ b/src/ServerState.cc @@ -1209,6 +1209,6 @@ shared_ptr> ServerState::information_contents_for_client(sh return is_v1_or_v2(c->version()) ? this->information_contents_v2 : this->information_contents_v3; } -shared_ptr ServerState::quest_index_for_client(shared_ptr c) const { - return is_ep3(c->version()) ? this->ep3_download_quest_index : this->default_quest_index; +shared_ptr ServerState::quest_index_for_version(Version version) const { + return is_ep3(version) ? this->ep3_download_quest_index : this->default_quest_index; } diff --git a/src/ServerState.hh b/src/ServerState.hh index 67879084..cdaea821 100644 --- a/src/ServerState.hh +++ b/src/ServerState.hh @@ -227,7 +227,7 @@ struct ServerState : public std::enable_shared_from_this { std::string describe_item(Version version, const ItemData& item, bool include_color_codes) const; std::shared_ptr> information_contents_for_client(std::shared_ptr c) const; - std::shared_ptr quest_index_for_client(std::shared_ptr c) const; + std::shared_ptr quest_index_for_version(Version version) const; void set_port_configuration(const std::vector& port_configs);