mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-20 02:55:38 +08:00
fix: 将基建换班编组匹配的可用干员缓存移动至Status,以免多实例时发生冲突 (#6391)
This commit is contained in:
@@ -37,6 +37,8 @@ namespace asst
|
||||
Status& operator=(Status&& rhs) noexcept = delete;
|
||||
|
||||
public:
|
||||
static inline const std::string InfrastAvailableOpersForGroup = "InfrastAvailableOpersForGroup";
|
||||
|
||||
static inline const std::string RoguelikeCharElitePrefix = "RoguelikeElite-";
|
||||
static inline const std::string RoguelikeCharLevelPrefix = "RoguelikeLevel-";
|
||||
static inline const std::string RoguelikeCharRarityPrefix = "RoguelikeRarity-";
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "Common/AsstMsg.h"
|
||||
#include "Config/TaskData.h"
|
||||
#include "Controller/Controller.h"
|
||||
#include "Status.h"
|
||||
#include "Task/ProcessTask.h"
|
||||
#include "Utils/Logger.hpp"
|
||||
#include "Utils/Ranges.hpp"
|
||||
@@ -68,11 +69,6 @@ void asst::InfrastAbstractTask::clear_custom_config() noexcept
|
||||
m_custom_config.clear();
|
||||
}
|
||||
|
||||
void asst::InfrastAbstractTask::clear_opers_for_group()
|
||||
{
|
||||
m_opers_for_groups.clear();
|
||||
}
|
||||
|
||||
asst::infrast::CustomRoomConfig& asst::InfrastAbstractTask::current_room_config()
|
||||
{
|
||||
static infrast::CustomRoomConfig empty;
|
||||
@@ -96,7 +92,8 @@ bool asst::InfrastAbstractTask::match_operator_groups()
|
||||
int swipe_times = 0;
|
||||
bool pre_result_no_changes = false, retried = false;
|
||||
|
||||
if (m_opers_for_groups.size() == 0) {
|
||||
auto opers = get_available_oper_for_group();
|
||||
if (opers.size() == 0) {
|
||||
std::vector<std::string> temp, pre_temp;
|
||||
while (true) {
|
||||
if (need_exit()) {
|
||||
@@ -124,7 +121,7 @@ bool asst::InfrastAbstractTask::match_operator_groups()
|
||||
else {
|
||||
pre_result_no_changes = false;
|
||||
}
|
||||
m_opers_for_groups.insert(temp.begin(), temp.end());
|
||||
opers.insert(temp.begin(), temp.end());
|
||||
pre_temp = temp;
|
||||
swipe_of_operlist();
|
||||
swipe_times++;
|
||||
@@ -134,10 +131,9 @@ bool asst::InfrastAbstractTask::match_operator_groups()
|
||||
swipe_times = 0;
|
||||
// 筛选第一个满足要求的干员组
|
||||
for (const auto& oper_group_pair : current_room_config().operator_groups) {
|
||||
if (ranges::all_of(oper_group_pair.second,
|
||||
[](const std::string& oper) { return m_opers_for_groups.contains(oper); })) {
|
||||
if (ranges::all_of(oper_group_pair.second, [opers](const std::string& oper) { return opers.contains(oper); })) {
|
||||
|
||||
ranges::for_each(oper_group_pair.second, [](const std::string& oper) { m_opers_for_groups.erase(oper); });
|
||||
ranges::for_each(oper_group_pair.second, [&opers](const std::string& oper) { opers.erase(oper); });
|
||||
current_room_config().names.insert(current_room_config().names.end(), oper_group_pair.second.begin(),
|
||||
oper_group_pair.second.end());
|
||||
|
||||
@@ -147,6 +143,7 @@ bool asst::InfrastAbstractTask::match_operator_groups()
|
||||
break;
|
||||
}
|
||||
}
|
||||
set_available_oper_for_group(std::move(opers));
|
||||
// 匹配失败,无分组可用
|
||||
if (current_room_config().names.empty() && !current_room_config().operator_groups.empty()) {
|
||||
json::value info = basic_info_with_what("CustomInfrastRoomGroupsMatchFailed");
|
||||
@@ -161,6 +158,33 @@ bool asst::InfrastAbstractTask::match_operator_groups()
|
||||
return true;
|
||||
}
|
||||
|
||||
std::set<std::string> asst::InfrastAbstractTask::get_available_oper_for_group()
|
||||
{
|
||||
std::set<std::string> opers;
|
||||
const auto& str = status()->get_str(Status::InfrastAvailableOpersForGroup);
|
||||
if (!str) {
|
||||
return opers;
|
||||
}
|
||||
auto ret = json::parse((*str).empty() ? "[]" : *str);
|
||||
if (!ret) {
|
||||
return opers;
|
||||
}
|
||||
auto json_array = json::array(*ret);
|
||||
for (const auto& token : json_array) {
|
||||
opers.emplace(token.as_string());
|
||||
}
|
||||
return opers;
|
||||
}
|
||||
|
||||
void asst::InfrastAbstractTask::set_available_oper_for_group(std::set<std::string> opers)
|
||||
{
|
||||
json::array value;
|
||||
for (const auto& oper : opers) {
|
||||
value.emplace_back(oper);
|
||||
}
|
||||
status()->set_str(Status::InfrastAvailableOpersForGroup, value.dumps());
|
||||
}
|
||||
|
||||
bool asst::InfrastAbstractTask::on_run_fails()
|
||||
{
|
||||
LogTraceFunction;
|
||||
|
||||
@@ -20,8 +20,6 @@ namespace asst
|
||||
|
||||
void set_custom_config(infrast::CustomFacilityConfig config) noexcept;
|
||||
void clear_custom_config() noexcept;
|
||||
// 清空编组匹配用的可用干员列表
|
||||
static void clear_opers_for_group();
|
||||
|
||||
static constexpr int OperSelectRetryTimes = 3;
|
||||
static constexpr int TaskRetryTimes = 3;
|
||||
@@ -45,6 +43,10 @@ namespace asst
|
||||
infrast::CustomRoomConfig& current_room_config();
|
||||
// 将定义的干员编组解释为具体干员,每次基建换班任务的第一次调用时缓存可用干员列表
|
||||
bool match_operator_groups();
|
||||
// 编组匹配用的可用干员列表,每次基建换班任务清空
|
||||
std::set<std::string> get_available_oper_for_group();
|
||||
void set_available_oper_for_group(std::set<std::string> opers);
|
||||
|
||||
bool swipe_and_select_custom_opers(bool is_dorm_order = false);
|
||||
bool select_custom_opers(std::vector<std::string>& partial_result);
|
||||
// 扫描当前页满足心情条件的所有干员名
|
||||
@@ -75,7 +77,5 @@ namespace asst
|
||||
int m_cur_facility_index = 0;
|
||||
bool m_is_custom = false;
|
||||
infrast::CustomFacilityConfig m_custom_config;
|
||||
// 编组匹配用的可用干员列表,每次基建换班前清空。按照第一次调用match_operator_groups()时设置的心情阈值进行缓存
|
||||
inline static std::set<std::string> m_opers_for_groups;
|
||||
};
|
||||
} // namespace asst
|
||||
|
||||
@@ -29,7 +29,6 @@ asst::InfrastTask::InfrastTask(const AsstCallback& callback, Assistant* inst)
|
||||
m_dorm_task_ptr(std::make_shared<InfrastDormTask>(callback, inst, TaskType))
|
||||
{
|
||||
LogTraceFunction;
|
||||
clear_opers_for_group();
|
||||
|
||||
m_infrast_begin_task_ptr->set_tasks({ "InfrastBegin" }).set_ignore_error(true);
|
||||
m_replenish_task_ptr = m_mfg_task_ptr->register_plugin<ReplenishOriginiumShardTaskPlugin>();
|
||||
|
||||
Reference in New Issue
Block a user