mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-19 02:23:01 +08:00
refactor.改了下Status的数据类型
This commit is contained in:
@@ -9,6 +9,22 @@
|
||||
#include "Resource.h"
|
||||
#include "ProcessTask.h"
|
||||
|
||||
int asst::InfrastAbstractTask::m_face_hash_thres = 0;
|
||||
int asst::InfrastAbstractTask::m_name_hash_thres = 0;
|
||||
|
||||
asst::InfrastAbstractTask::InfrastAbstractTask(AsstCallback callback, void* callback_arg)
|
||||
: AbstractTask(callback, callback_arg)
|
||||
{
|
||||
if (m_face_hash_thres == 0) {
|
||||
m_face_hash_thres = std::dynamic_pointer_cast<MatchTaskInfo>(
|
||||
task.get("InfrastOperFaceHash"))->templ_threshold;
|
||||
}
|
||||
if (m_name_hash_thres == 0) {
|
||||
m_name_hash_thres = std::dynamic_pointer_cast<MatchTaskInfo>(
|
||||
task.get("InfrastOperNameHash"))->templ_threshold;
|
||||
}
|
||||
}
|
||||
|
||||
void asst::InfrastAbstractTask::set_work_mode(infrast::WorkMode work_mode) noexcept
|
||||
{
|
||||
m_work_mode = work_mode;
|
||||
|
||||
@@ -9,6 +9,8 @@ namespace asst
|
||||
{
|
||||
public:
|
||||
using AbstractTask::AbstractTask;
|
||||
InfrastAbstractTask(AsstCallback callback, void* callback_arg);
|
||||
|
||||
virtual ~InfrastAbstractTask() = default;
|
||||
virtual void set_work_mode(infrast::WorkMode work_mode) noexcept;
|
||||
virtual void set_mood_threshold(double mood_thres) noexcept;
|
||||
@@ -34,5 +36,8 @@ namespace asst
|
||||
infrast::WorkMode m_work_mode = infrast::WorkMode::Gentle;
|
||||
std::string m_work_mode_name = "Gentle";
|
||||
double m_mood_threshold = 0;
|
||||
|
||||
static int m_face_hash_thres;
|
||||
static int m_name_hash_thres;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -18,15 +18,15 @@ bool asst::InfrastInfoTask::_run()
|
||||
const auto& image = ctrler.get_image();
|
||||
|
||||
InfrastFacilityImageAnalyzer analyzer(image);
|
||||
analyzer.set_to_be_analyzed({ "Mfg", "Trade", "Power" });
|
||||
analyzer.set_to_be_analyzed({ "Mfg", "Trade", "Power", "Dorm" });
|
||||
if (!analyzer.analyze()) {
|
||||
return false;
|
||||
}
|
||||
for (auto&& [name, res] : analyzer.get_result()) {
|
||||
std::string key = "NumOf" + name;
|
||||
int size = static_cast<int>(res.size());
|
||||
status.set(key, size);
|
||||
log.trace("InfrastInfoTask | ", key, size);
|
||||
//int size = static_cast<int>(res.size());
|
||||
status.set(key, res.size());
|
||||
log.trace("InfrastInfoTask | ", key, res.size());
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -13,22 +13,6 @@
|
||||
#include "Resource.h"
|
||||
#include "RuntimeStatus.h"
|
||||
|
||||
int asst::InfrastProductionTask::m_face_hash_thres = 0;
|
||||
int asst::InfrastProductionTask::m_name_hash_thres = 0;
|
||||
|
||||
asst::InfrastProductionTask::InfrastProductionTask(AsstCallback callback, void* callback_arg)
|
||||
: InfrastAbstractTask(callback, callback_arg)
|
||||
{
|
||||
if (m_face_hash_thres == 0) {
|
||||
m_face_hash_thres = std::dynamic_pointer_cast<MatchTaskInfo>(
|
||||
task.get("InfrastOperFaceHash"))->templ_threshold;
|
||||
}
|
||||
if (m_name_hash_thres == 0) {
|
||||
m_name_hash_thres = std::dynamic_pointer_cast<MatchTaskInfo>(
|
||||
task.get("InfrastOperNameHash"))->templ_threshold;
|
||||
}
|
||||
}
|
||||
|
||||
bool asst::InfrastProductionTask::shift_facility_list()
|
||||
{
|
||||
LogTraceFunction;
|
||||
@@ -210,7 +194,7 @@ size_t asst::InfrastProductionTask::opers_detect()
|
||||
auto find_iter = std::find_if(
|
||||
m_all_available_opers.cbegin(), m_all_available_opers.cend(),
|
||||
[&cur_oper](const infrast::Oper& oper) -> bool {
|
||||
// 技能相同的有可能是同一个干员,比一下hash
|
||||
// 有可能是同一个干员,比一下hash
|
||||
int dist = utils::hamming(cur_oper.face_hash, oper.face_hash);
|
||||
#ifdef LOG_TRACE
|
||||
log.trace("opers_detect hash dist |", dist);
|
||||
@@ -316,12 +300,7 @@ bool asst::InfrastProductionTask::optimal_calc()
|
||||
continue;
|
||||
}
|
||||
// TODO:这里做成除了不等于,还可计算大于、小于等不同条件的
|
||||
std::any cur_any_value = status.get(cond);
|
||||
if (!cur_any_value.has_value()) {
|
||||
meet_condition = false;
|
||||
break;
|
||||
}
|
||||
int cur_value = std::any_cast<int>(cur_any_value);
|
||||
int cur_value = status.get(cond);
|
||||
if (cur_value != cond_value) {
|
||||
meet_condition = false;
|
||||
break;
|
||||
@@ -582,11 +561,7 @@ asst::InfrastProductionTask::efficient_regex_calc(
|
||||
// TODO 报错!
|
||||
}
|
||||
std::string status_key = cur_formula.substr(pos + 1, rp_pos - pos - 1);
|
||||
std::any status_any_value = status.get(status_key);
|
||||
int status_value = 0;
|
||||
if (status_any_value.has_value()) {
|
||||
status_value = std::any_cast<int>(status_any_value);
|
||||
}
|
||||
int status_value = status.get(status_key);
|
||||
cur_formula.replace(pos, rp_pos - pos + 1, std::to_string(status_value));
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace asst
|
||||
class InfrastProductionTask : public InfrastAbstractTask
|
||||
{
|
||||
public:
|
||||
InfrastProductionTask(AsstCallback callback, void* callback_arg);
|
||||
using InfrastAbstractTask::InfrastAbstractTask;
|
||||
virtual ~InfrastProductionTask() = default;
|
||||
void set_facility(std::string facility_name) noexcept
|
||||
{
|
||||
@@ -31,9 +31,6 @@ namespace asst
|
||||
infrast::SkillsComb efficient_regex_calc(
|
||||
std::unordered_set<infrast::Skill> skills) const;
|
||||
|
||||
static int m_face_hash_thres;
|
||||
static int m_name_hash_thres;
|
||||
|
||||
std::string m_facility;
|
||||
std::string m_product;
|
||||
int m_cur_num_of_lokced_opers = 0;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <any>
|
||||
//#include <any>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace asst
|
||||
@@ -18,14 +18,14 @@ namespace asst
|
||||
return unique_instance;
|
||||
}
|
||||
|
||||
std::any get(const std::string& key) const noexcept
|
||||
int get(const std::string& key) const noexcept
|
||||
{
|
||||
if (auto iter = m_data.find(key);
|
||||
iter != m_data.cend()) {
|
||||
return iter->second;
|
||||
}
|
||||
else {
|
||||
return std::any();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
bool exist(const std::string& key) const noexcept
|
||||
@@ -37,18 +37,23 @@ namespace asst
|
||||
inline void set(Args&&... args)
|
||||
{
|
||||
static_assert(
|
||||
std::is_constructible<std::unordered_map<std::string, std::any>::value_type, Args...>::value,
|
||||
"Parameter can't be used to construct a std::unordered_map<std::string, std::any>::value_type");
|
||||
std::is_constructible<decltype(m_data)::value_type, Args...>::value,
|
||||
"Parameter can't be used to construct a decltype(m_data)::value_type");
|
||||
m_data.emplace(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
void clear() noexcept
|
||||
{
|
||||
m_data.clear();
|
||||
}
|
||||
|
||||
RuntimeStatus& operator=(const RuntimeStatus& rhs) = delete;
|
||||
RuntimeStatus& operator=(RuntimeStatus&& rhs) noexcept = delete;
|
||||
|
||||
private:
|
||||
RuntimeStatus() = default;
|
||||
|
||||
std::unordered_map<std::string, std::any> m_data;
|
||||
std::unordered_map<std::string, int> m_data;
|
||||
};
|
||||
|
||||
static auto& status = RuntimeStatus::get_instance();
|
||||
|
||||
Reference in New Issue
Block a user