merge feat/specify_the_drops

This commit is contained in:
MistEO
2022-06-07 01:18:28 +08:00
8 changed files with 157 additions and 30 deletions

View File

@@ -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", 会影响掉落识别及上传

View File

@@ -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<std::string, int> 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);

View File

@@ -61,6 +61,12 @@ bool asst::StageDropsTaskPlugin::set_server(std::string server)
return true;
}
bool asst::StageDropsTaskPlugin::set_specify_quantity(std::unordered_map<std::string, int> 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);
}

View File

@@ -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<std::string, int> 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<std::string, int> m_specify_quantity;
};
}

View File

@@ -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<SettingsViewModel>();
task_params["penguin_id"] = settings.PenguinId;
task_params["server"] = "CN";

View File

@@ -15,6 +15,7 @@
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" Grid.Row="0" VerticalAlignment="Center">
<CheckBox IsChecked="{Binding UseMedicine}" IsHitTestVisible="{Binding Idle}" Content="吃理智药" Margin="10" />
@@ -33,15 +34,26 @@
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="2" VerticalAlignment="Center">
<CheckBox IsChecked="{Binding HasTimesLimited}" IsHitTestVisible="{Binding Idle}" Content="指定次数" Margin="10" />
<TextBox Text="{Binding MaxTimes}" IsReadOnly="{c:Binding Path=!Idle}" TextWrapping="Wrap" Margin="10"
Width="50" InputMethod.IsInputMethodEnabled="False" />
<TextBlock Style="{StaticResource TextBlockDefault}" Text="次" />
<CheckBox IsChecked="{Binding IsSpecifiedDrops}" IsHitTestVisible="{Binding Idle}" Content="指定材料" Margin="10" />
<ComboBox Width="120" Margin="10"
IsHitTestVisible ="{Binding Path=Idle}"
IsEditable="True"
IsTextSearchEnabled ="True"
DisplayMemberPath="Display"
SelectedValuePath="Value"
ItemsSource="{Binding DropsList}"
SelectedValue="{Binding DropsItemId}" />
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="3" VerticalAlignment="Center">
<!--<TextBlock Style="{StaticResource TextBlockDefault}" Margin="35,10,0,10" Text="掉落数 " />-->
<TextBox Text="{Binding DropsQuantity}" IsReadOnly="{c:Binding Path=!Idle}" TextWrapping="Wrap"
Width="95" Margin="98,10,10,10" InputMethod.IsInputMethodEnabled="False" />
<TextBlock Style="{StaticResource TextBlockDefault}" Text="个" />
</StackPanel>
<StackPanel Grid.Row="4" Orientation="Horizontal">
<TextBlock Style="{StaticResource TextBlockDefault}" Margin="10" VerticalAlignment="Center"
Text="关卡选择" />
<ComboBox Width="110" Margin="10"
<TextBlock Style="{StaticResource TextBlockDefault}" Margin="10,10,0,10" VerticalAlignment="Center"
Text="关卡选择" FontSize="14" />
<ComboBox Width="120" Margin="31,10,10,10"
IsHitTestVisible ="{Binding Path=Idle}"
ItemsSource="{Binding StageList}"
DisplayMemberPath="Display"

View File

@@ -9,7 +9,11 @@
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY
using System.IO;
using System.Collections.ObjectModel;
using System.Windows.Controls;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace MeoAsstGui
{

View File

@@ -12,8 +12,12 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Stylet;
using StyletIoC;
@@ -129,7 +133,11 @@ namespace MeoAsstGui
new CombData { Display = "经验-6/5", Value = "LS-6" },
new CombData { Display = "红票-5", Value = "AP-5" },
new CombData { Display = "技能-5", Value = "CA-5" },
new CombData { Display = "剿灭作战", Value = "Annihilation" },
new CombData { Display = "1-7", Value = "1-7" },
// “覆潮之下” 活动关卡 //复刻活动,结束后直接删除
new CombData { Display = "SV-7", Value = "SV-7" },
new CombData { Display = "SV-8", Value = "SV-8" },
new CombData { Display = "SV-9", Value = "SV-9" },
// “愚人号” 活动关卡
//new CombData { Display = "SN-8", Value = "SN-8" },
@@ -139,7 +147,9 @@ namespace MeoAsstGui
//// “风雪过境” 活动关卡
//new CombData { Display = "BI-7", Value = "BI-7" },
//new CombData { Display = "BI-8", Value = "BI-8" }
};
};
InitDrops();
UpdateDatePrompt();
}
@@ -330,8 +340,10 @@ namespace MeoAsstGui
ViewStatusStorage.Set("MainFunction.UseMedicine.Quantity", MedicineNumber);
// 吃石头颗数
ViewStatusStorage.Set("MainFunction.UseStone.Quantity", StoneNumber);
// 指定刷关次数
ViewStatusStorage.Set("MainFunction.TimesLimited.Quantity", MaxTimes);
// 指定掉落材料
ViewStatusStorage.Set("MainFunction.Drops.ItemId", DropsItemId);
// 指定掉落材料数量
ViewStatusStorage.Set("MainFunction.Drops.Quantity", DropsQuantity);
}
private bool appendStart()
@@ -362,16 +374,24 @@ namespace MeoAsstGui
}
}
int times = int.MaxValue;
if (HasTimesLimited)
if (IsSpecifiedDrops)
{
if (!int.TryParse(MaxTimes, out times))
if (!int.TryParse(DropsQuantity, out times))
{
times = 0;
}
}
int drops_quantity = 0;
if (IsSpecifiedDrops)
{
if (!int.TryParse(DropsQuantity, out drops_quantity))
{
drops_quantity = 0;
}
}
var asstProxy = _container.Get<AsstProxy>();
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<CombData> AllDrops { get; set; } = new List<CombData>();
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<CombData>(AllDrops);
}
public ObservableCollection<CombData> 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);
}
}
}