diff --git a/docs/集成文档.md b/docs/集成文档.md index c530f89a95..89978650a4 100644 --- a/docs/集成文档.md +++ b/docs/集成文档.md @@ -45,6 +45,12 @@ TaskId ASSTAPI AsstAppendTask(AsstHandle handle, const char* type, const char* p "medicine": int, // 最大使用理智药数量,可选,默认 0 "stone": int, // 最大吃石头数量,可选,默认 0 "times": int, // 指定次数,可选,默认无穷大 + "drops": { // 指定掉落数量,可选,默认不指定 + "30011": int, // key - item_id, value 数量. key 可参考 resource/item_index.json 文件 + "30062": int // 是或的关系 + }, + /* 以上全部是或的关系,即任一达到即停止任务 */ + "report_to_penguin": bool, // 是否汇报企鹅数据,可选,默认 false "penguin_id": string, // 企鹅数据汇报 id, 可选,默认为空。仅在 report_to_penguin 为 true 时有效 "server": string // 服务器,可选,默认 "CN", 会影响掉落识别及上传 diff --git a/src/MeoAssistant/FightTask.cpp b/src/MeoAssistant/FightTask.cpp index db00647062..db4ab9895f 100644 --- a/src/MeoAssistant/FightTask.cpp +++ b/src/MeoAssistant/FightTask.cpp @@ -55,6 +55,14 @@ bool asst::FightTask::set_params(const json::value& params) std::string penguin_id = params.get("penguin_id", ""); std::string server = params.get("server", "CN"); + if (params.contains("drops")) { + std::unordered_map drops; + for (const auto& [item_id, quantity] : params.at("drops").as_object()) { + drops.insert_or_assign(item_id, quantity.as_integer()); + } + m_stage_drops_plugin_ptr->set_specify_quantity(drops); + } + if (!m_runned) { if (stage.empty()) { m_start_up_task_ptr->set_enable(false); diff --git a/src/MeoAssistant/StageDropsTaskPlugin.cpp b/src/MeoAssistant/StageDropsTaskPlugin.cpp index afb5949377..e04a336bb6 100644 --- a/src/MeoAssistant/StageDropsTaskPlugin.cpp +++ b/src/MeoAssistant/StageDropsTaskPlugin.cpp @@ -61,6 +61,12 @@ bool asst::StageDropsTaskPlugin::set_server(std::string server) return true; } +bool asst::StageDropsTaskPlugin::set_specify_quantity(std::unordered_map quantity) +{ + m_specify_quantity = std::move(quantity); + return true; +} + bool asst::StageDropsTaskPlugin::_run() { LogTraceFunction; @@ -75,7 +81,9 @@ bool asst::StageDropsTaskPlugin::_run() } drop_info_callback(); - check_stage_valid(); + if (!check_stage_valid() || check_specify_quantity()) { + stop_task(); + } if (m_enable_penguid) { auto upload_future = std::async( @@ -257,12 +265,26 @@ bool asst::StageDropsTaskPlugin::check_stage_valid() info["why"] = "EX关卡"; callback(AsstMsg::SubTaskError, info); - m_cast_ptr->set_times_limit("StartButton1", 0) - .set_times_limit("StartButton2", 0) - .set_times_limit("MedicineConfirm", 0) - .set_times_limit("StoneConfirm", 0); - - return true; + return false; } return true; } + +bool asst::StageDropsTaskPlugin::check_specify_quantity() const +{ + for (const auto& [id, quantity] : m_specify_quantity) { + if (auto find_iter = m_drop_stats.find(id); + find_iter != m_drop_stats.end() && find_iter->second >= quantity) { + return true; + } + } + return false; +} + +void asst::StageDropsTaskPlugin::stop_task() +{ + m_cast_ptr->set_times_limit("StartButton1", 0) + .set_times_limit("StartButton2", 0) + .set_times_limit("MedicineConfirm", 0) + .set_times_limit("StoneConfirm", 0); +} diff --git a/src/MeoAssistant/StageDropsTaskPlugin.h b/src/MeoAssistant/StageDropsTaskPlugin.h index 716fe54efa..13a7b68a7d 100644 --- a/src/MeoAssistant/StageDropsTaskPlugin.h +++ b/src/MeoAssistant/StageDropsTaskPlugin.h @@ -24,6 +24,7 @@ namespace asst bool set_enable_penguid(bool enable); bool set_penguin_id(std::string id); bool set_server(std::string server); + bool set_specify_quantity(std::unordered_map quantity); private: virtual bool _run() override; @@ -31,6 +32,8 @@ namespace asst void drop_info_callback(); void set_startbutton_delay(); bool check_stage_valid(); + bool check_specify_quantity() const; + void stop_task(); void upload_to_penguin(); static constexpr int64_t RecognizationTimeOffset = 20; @@ -48,5 +51,6 @@ namespace asst bool m_enable_penguid = false; std::string m_penguin_id; std::string m_server = "CN"; + std::unordered_map m_specify_quantity; }; } diff --git a/src/MeoAsstGui/Helper/AsstProxy.cs b/src/MeoAsstGui/Helper/AsstProxy.cs index 79b6ea8efd..a30f4c72de 100644 --- a/src/MeoAsstGui/Helper/AsstProxy.cs +++ b/src/MeoAsstGui/Helper/AsstProxy.cs @@ -670,7 +670,7 @@ namespace MeoAsstGui return AsstAppendTask(_handle, type, JsonConvert.SerializeObject(task_params)) != 0; } - public bool AsstAppendFight(string stage, int max_medicine, int max_stone, int max_times) + public bool AsstAppendFight(string stage, int max_medicine, int max_stone, int max_times, string drops_item_id, int drops_item_quantity) { var task_params = new JObject(); task_params["stage"] = stage; @@ -678,6 +678,11 @@ namespace MeoAsstGui task_params["stone"] = max_stone; task_params["times"] = max_times; task_params["report_to_penguin"] = true; + if (drops_item_quantity != 0) + { + task_params["drops"] = new JObject(); + task_params["drops"][drops_item_id] = drops_item_quantity; + } var settings = _container.Get(); task_params["penguin_id"] = settings.PenguinId; task_params["server"] = "CN"; diff --git a/src/MeoAsstGui/UserControl/FightSettingsUserControl.xaml b/src/MeoAsstGui/UserControl/FightSettingsUserControl.xaml index 3fea7e46af..961a4c78fd 100644 --- a/src/MeoAsstGui/UserControl/FightSettingsUserControl.xaml +++ b/src/MeoAsstGui/UserControl/FightSettingsUserControl.xaml @@ -15,6 +15,7 @@ + @@ -33,15 +34,26 @@ - - - + + + + + + + - - + (); - return asstProxy.AsstAppendFight(Stage, medicine, stone, times); + return asstProxy.AsstAppendFight(Stage, medicine, stone, times, DropsItemId, drops_quantity); } private bool appendInfrast() @@ -590,25 +610,71 @@ namespace MeoAsstGui } } - private bool _hasTimesLimited; + private bool _isSpecifiedDrops = System.Convert.ToBoolean(ViewStatusStorage.Get("MainFunction.Drops.Enable", bool.FalseString)); - public bool HasTimesLimited + public bool IsSpecifiedDrops { - get { return _hasTimesLimited; } + get { return _isSpecifiedDrops; } set { - SetAndNotify(ref _hasTimesLimited, value); + SetAndNotify(ref _isSpecifiedDrops, value); + ViewStatusStorage.Set("MainFunction.Drops.Enable", value.ToString()); } } - private string _maxTimes = ViewStatusStorage.Get("MainFunction.TimesLimited.Quantity", "5"); + private static readonly string _DropsFilename = System.Environment.CurrentDirectory + "\\resource\\item_index.json"; - public string MaxTimes + public List AllDrops { get; set; } = new List(); + + private void InitDrops() { - get { return _maxTimes; } + string jsonStr = File.ReadAllText(_DropsFilename); + var reader = (JObject)JsonConvert.DeserializeObject(jsonStr); + foreach (var item in reader) + { + var val = item.Key; + if (!int.TryParse(val, out _)) // 不是数字的东西都是正常关卡不会掉的(大概吧) + { + continue; + } + var dis = item.Value["name"].ToString(); + if (dis.EndsWith("双芯片") || dis.EndsWith("寻访凭证") || dis.EndsWith("加固建材") + || dis.EndsWith("许可") || dis == "资质凭证" || dis == "高级凭证" || dis == "演习券" + || dis.Contains("源石") || dis == "D32钢" || dis == "双极纳米片" || dis == "聚合剂" || dis == "晶体电子单元") + { + continue; + } + + AllDrops.Add(new CombData { Display = dis, Value = val }); + } + AllDrops.Sort((a, b) => + { + return a.Value.CompareTo(b.Value); + }); + DropsList = new ObservableCollection(AllDrops); + } + + public ObservableCollection DropsList { get; set; } + + private string _dropsItemId = ViewStatusStorage.Get("MainFunction.Drops.ItemId", "0"); + + public string DropsItemId + { + get { return _dropsItemId; } set { - SetAndNotify(ref _maxTimes, value); + SetAndNotify(ref _dropsItemId, value); + } + } + + private string _dropsQuantity = ViewStatusStorage.Get("MainFunction.Drops.Quantity", "5"); + + public string DropsQuantity + { + get { return _dropsQuantity; } + set + { + SetAndNotify(ref _dropsQuantity, value); } } }