make quest episode filter configurable
This commit is contained in:
+4
-11
@@ -777,14 +777,9 @@ vector<shared_ptr<const QuestCategoryIndex::Category>> QuestIndex::categories(
|
||||
Episode episode,
|
||||
Version version,
|
||||
IncludeCondition include_condition) const {
|
||||
// The episode filter should apply in normal or solo mode
|
||||
if ((menu_type != QuestMenuType::NORMAL) && (menu_type != QuestMenuType::SOLO)) {
|
||||
episode = Episode::NONE;
|
||||
}
|
||||
|
||||
vector<shared_ptr<const QuestCategoryIndex::Category>> ret;
|
||||
for (const auto& cat : this->category_index->categories) {
|
||||
if (cat->check_flag(menu_type) && !this->filter(menu_type, episode, version, cat->category_id, include_condition, 1).empty()) {
|
||||
if (cat->check_flag(menu_type) && !this->filter(episode, version, cat->category_id, include_condition, 1).empty()) {
|
||||
ret.emplace_back(cat);
|
||||
}
|
||||
}
|
||||
@@ -792,15 +787,13 @@ vector<shared_ptr<const QuestCategoryIndex::Category>> QuestIndex::categories(
|
||||
}
|
||||
|
||||
vector<pair<QuestIndex::IncludeState, shared_ptr<const Quest>>> QuestIndex::filter(
|
||||
QuestMenuType menu_type,
|
||||
Episode episode,
|
||||
Version version,
|
||||
uint32_t category_id,
|
||||
IncludeCondition include_condition,
|
||||
size_t limit) const {
|
||||
if ((menu_type != QuestMenuType::NORMAL) && (menu_type != QuestMenuType::SOLO)) {
|
||||
episode = Episode::NONE;
|
||||
}
|
||||
auto cat = this->category_index->at(category_id);
|
||||
Episode effective_episode = cat->enable_episode_filter() ? episode : Episode::NONE;
|
||||
|
||||
vector<pair<IncludeState, shared_ptr<const Quest>>> ret;
|
||||
auto category_it = this->quests_by_category_id_and_number.find(category_id);
|
||||
@@ -808,7 +801,7 @@ vector<pair<QuestIndex::IncludeState, shared_ptr<const Quest>>> QuestIndex::filt
|
||||
return ret;
|
||||
}
|
||||
for (auto it : category_it->second) {
|
||||
if (((episode == Episode::NONE) || (it.second->episode == episode)) &&
|
||||
if (((effective_episode == Episode::NONE) || (it.second->episode == effective_episode)) &&
|
||||
it.second->has_version_any_language(version)) {
|
||||
IncludeState state = include_condition ? include_condition(it.second) : IncludeState::AVAILABLE;
|
||||
if (state == IncludeState::HIDDEN) {
|
||||
|
||||
+4
-1
@@ -31,6 +31,7 @@ enum class QuestMenuType {
|
||||
GOVERNMENT = 4,
|
||||
DOWNLOAD = 5,
|
||||
EP3_DOWNLOAD = 6,
|
||||
// 7 can't be used as a menu type (it enables the per-episode filter)
|
||||
};
|
||||
|
||||
struct QuestCategoryIndex {
|
||||
@@ -46,6 +47,9 @@ struct QuestCategoryIndex {
|
||||
[[nodiscard]] inline bool check_flag(QuestMenuType menu_type) const {
|
||||
return this->enabled_flags & (1 << static_cast<uint8_t>(menu_type));
|
||||
}
|
||||
[[nodiscard]] inline bool enable_episode_filter() const {
|
||||
return this->enabled_flags & 0x80;
|
||||
}
|
||||
};
|
||||
|
||||
std::vector<std::shared_ptr<Category>> categories;
|
||||
@@ -151,7 +155,6 @@ struct QuestIndex {
|
||||
Version version,
|
||||
IncludeCondition include_condition = nullptr) const;
|
||||
std::vector<std::pair<QuestIndex::IncludeState, std::shared_ptr<const Quest>>> filter(
|
||||
QuestMenuType menu_type,
|
||||
Episode episode,
|
||||
Version version,
|
||||
uint32_t category_id,
|
||||
|
||||
+4
-24
@@ -2228,7 +2228,7 @@ static void on_10(shared_ptr<Client> c, uint16_t, uint32_t, string& data) {
|
||||
auto quest_index = s->quest_index(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);
|
||||
auto quests = quest_index->filter(Episode::EP3, c->version(), categories[0]->category_id);
|
||||
send_quest_menu(c, quests, true);
|
||||
break;
|
||||
}
|
||||
@@ -2491,32 +2491,12 @@ static void on_10(shared_ptr<Client> c, uint16_t, uint32_t, string& data) {
|
||||
|
||||
shared_ptr<Lobby> l = c->lobby.lock();
|
||||
Episode episode = l ? l->episode : Episode::NONE;
|
||||
QuestMenuType menu_type = QuestMenuType::NORMAL;
|
||||
QuestIndex::IncludeCondition include_condition = nullptr;
|
||||
if (!l) {
|
||||
// Assume the menu to be sent is the download quest menu if the client
|
||||
// is not in any lobby
|
||||
menu_type = is_ep3(c->version()) ? QuestMenuType::EP3_DOWNLOAD : QuestMenuType::DOWNLOAD;
|
||||
} else {
|
||||
auto cat = quest_index->category_index->at(item_id);
|
||||
static const std::array<QuestMenuType, 4> menu_types({
|
||||
QuestMenuType::GOVERNMENT,
|
||||
QuestMenuType::CHALLENGE,
|
||||
QuestMenuType::BATTLE,
|
||||
QuestMenuType::SOLO,
|
||||
});
|
||||
for (QuestMenuType check_menu_type : menu_types) {
|
||||
if (cat->check_flag(check_menu_type)) {
|
||||
menu_type = check_menu_type;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!c->license->check_flag(License::Flag::DISABLE_QUEST_REQUIREMENTS)) {
|
||||
include_condition = l->quest_include_condition();
|
||||
}
|
||||
if (l && !c->license->check_flag(License::Flag::DISABLE_QUEST_REQUIREMENTS)) {
|
||||
include_condition = l->quest_include_condition();
|
||||
}
|
||||
|
||||
const auto& quests = quest_index->filter(menu_type, episode, c->version(), item_id, include_condition);
|
||||
const auto& quests = quest_index->filter(episode, c->version(), item_id, include_condition);
|
||||
send_quest_menu(c, quests, !l);
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user