feat: 支持运行中修改刷理智设置

This commit is contained in:
MistEO
2022-06-23 23:32:23 +08:00
parent eb7cd8a491
commit d2d98903d6
4 changed files with 142 additions and 62 deletions

View File

@@ -88,15 +88,15 @@ else if (type == TASK::TaskType) { ptr = std::make_shared<TASK>(task_callback, s
if (false) {}
ASST_ASSISTANT_APPEND_TASK_FROM_STRING_IF_BRANCH(FightTask)
ASST_ASSISTANT_APPEND_TASK_FROM_STRING_IF_BRANCH(StartUpTask)
ASST_ASSISTANT_APPEND_TASK_FROM_STRING_IF_BRANCH(AwardTask)
ASST_ASSISTANT_APPEND_TASK_FROM_STRING_IF_BRANCH(VisitTask)
ASST_ASSISTANT_APPEND_TASK_FROM_STRING_IF_BRANCH(MallTask)
ASST_ASSISTANT_APPEND_TASK_FROM_STRING_IF_BRANCH(InfrastTask)
ASST_ASSISTANT_APPEND_TASK_FROM_STRING_IF_BRANCH(RecruitTask)
ASST_ASSISTANT_APPEND_TASK_FROM_STRING_IF_BRANCH(RoguelikeTask)
ASST_ASSISTANT_APPEND_TASK_FROM_STRING_IF_BRANCH(CopilotTask)
ASST_ASSISTANT_APPEND_TASK_FROM_STRING_IF_BRANCH(DepotTask)
ASST_ASSISTANT_APPEND_TASK_FROM_STRING_IF_BRANCH(StartUpTask)
ASST_ASSISTANT_APPEND_TASK_FROM_STRING_IF_BRANCH(AwardTask)
ASST_ASSISTANT_APPEND_TASK_FROM_STRING_IF_BRANCH(VisitTask)
ASST_ASSISTANT_APPEND_TASK_FROM_STRING_IF_BRANCH(MallTask)
ASST_ASSISTANT_APPEND_TASK_FROM_STRING_IF_BRANCH(InfrastTask)
ASST_ASSISTANT_APPEND_TASK_FROM_STRING_IF_BRANCH(RecruitTask)
ASST_ASSISTANT_APPEND_TASK_FROM_STRING_IF_BRANCH(RoguelikeTask)
ASST_ASSISTANT_APPEND_TASK_FROM_STRING_IF_BRANCH(CopilotTask)
ASST_ASSISTANT_APPEND_TASK_FROM_STRING_IF_BRANCH(DepotTask)
#ifdef ASST_DEBUG
ASST_ASSISTANT_APPEND_TASK_FROM_STRING_IF_BRANCH(DebugTask)
#endif
@@ -238,6 +238,7 @@ void Assistant::working_proc()
task_callback(run_msg, callback_json, this);
if (!m_thread_idle && m_tasks_list.empty()) {
callback_json["runned_tasks"] = json::array(runned_tasks);
task_callback(AsstMsg::AllTasksCompleted, callback_json, this);
runned_tasks.clear();
}

View File

@@ -10,6 +10,7 @@
// but WITHOUT ANY WARRANTY
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
@@ -59,6 +60,11 @@ namespace MeoAsstGui
[DllImport("MeoAssistant.dll")] private static extern bool AsstSetTaskParams(AsstHandle handle, TaskId id, byte[] task_params);
private static bool AsstSetTaskParams(AsstHandle handle, TaskId id, string task_params)
{
return AsstSetTaskParams(handle, id, Encoding.UTF8.GetBytes(task_params));
}
[DllImport("MeoAssistant.dll")] private static extern bool AsstStart(AsstHandle handle);
[DllImport("MeoAssistant.dll")] private static extern bool AsstStop(AsstHandle handle);
@@ -289,8 +295,8 @@ namespace MeoAsstGui
if (runned_tasks.Count == 1)
{
var unique_runned_task = (TaskId)runned_tasks[0];
if (unique_runned_task == _latestCopilotTaskId
|| unique_runned_task == _latestRecruitCalcTaskId)
if (unique_runned_task == (_latestTaskId.TryGetValue(TaskType.Copilot, out var copilotTaskId) ? copilotTaskId : 0)
|| unique_runned_task == (_latestTaskId.TryGetValue(TaskType.RecruitCalc, out var recruitCalcTaskId) ? recruitCalcTaskId : 0))
{
isMainTaskQueueAllCompleted = false;
}
@@ -309,6 +315,7 @@ namespace MeoAsstGui
//mainModel.CheckAndShutdown();
mainModel.CheckAfterComplete();
}
_latestTaskId.Clear();
break;
}
}
@@ -777,9 +784,33 @@ namespace MeoAsstGui
return AsstAppendTask(_handle, type, JsonConvert.SerializeObject(task_params));
}
private TaskId _latestFightTaskId = 0;
private bool AsstSetTaskParamsWithEncoding(TaskId id, JObject task_params = null)
{
if (id == 0)
{
return false;
}
task_params = task_params ?? new JObject();
return AsstSetTaskParams(_handle, id, JsonConvert.SerializeObject(task_params));
}
public bool AsstAppendFight(string stage, int max_medicine, int max_stone, int max_times, string drops_item_id, int drops_item_quantity)
private enum TaskType
{
StartUp,
Fight,
Recruit,
Infrast,
Visit,
Mall,
Award,
Roguelike,
RecruitCalc,
Copilot
};
private Dictionary<TaskType, TaskId> _latestTaskId = new Dictionary<TaskType, TaskId>();
private JObject serializeFightTaskParams(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;
@@ -796,51 +827,58 @@ namespace MeoAsstGui
task_params["client_type"] = settings.ClientType;
task_params["penguin_id"] = settings.PenguinId;
task_params["server"] = "CN";
_latestFightTaskId = AsstAppendTaskWithEncoding("Fight", task_params);
return _latestFightTaskId != 0;
return task_params;
}
private TaskId _latestAwardTaskId = 0;
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 = serializeFightTaskParams(stage, max_medicine, max_stone, max_times, drops_item_id, drops_item_quantity);
TaskId id = AsstAppendTaskWithEncoding("Fight", task_params);
_latestTaskId[TaskType.Fight] = id;
return id != 0;
}
public bool AsstSetFightTaskParams(string stage, int max_medicine, int max_stone, int max_times, string drops_item_id, int drops_item_quantity)
{
var task_params = serializeFightTaskParams(stage, max_medicine, max_stone, max_times, drops_item_id, drops_item_quantity);
return AsstSetTaskParamsWithEncoding(_latestTaskId.TryGetValue(TaskType.Fight, out var task_id) ? task_id : 0, task_params);
}
public bool AsstAppendAward()
{
_latestAwardTaskId = AsstAppendTaskWithEncoding("Award");
return _latestAwardTaskId != 0;
TaskId id = AsstAppendTaskWithEncoding("Award");
_latestTaskId[TaskType.Award] = id;
return id != 0;
}
private TaskId _latestStartupTaskId = 0;
public bool AsstAppendStartUp(string client_type, bool enable)
{
var task_params = new JObject();
task_params["client_type"] = client_type;
task_params["start_game_enable"] = enable;
_latestStartupTaskId = AsstAppendTaskWithEncoding("StartUp", task_params);
return _latestStartupTaskId != 0;
TaskId id = AsstAppendTaskWithEncoding("StartUp", task_params);
_latestTaskId[TaskType.StartUp] = id;
return id != 0;
}
private TaskId _latestVisitTaskId = 0;
public bool AsstAppendVisit()
{
_latestVisitTaskId = AsstAppendTaskWithEncoding("Visit");
return _latestVisitTaskId != 0;
TaskId id = AsstAppendTaskWithEncoding("Visit");
_latestTaskId[TaskType.Visit] = id;
return id != 0;
}
private TaskId _latestMallTaskId = 0;
public bool AsstAppendMall(bool with_shopping, string[] firstlist, string[] blacklist)
{
var task_params = new JObject();
task_params["shopping"] = with_shopping;
task_params["buy_first"] = new JArray { firstlist };
task_params["blacklist"] = new JArray { blacklist };
_latestMallTaskId = AsstAppendTaskWithEncoding("Mall", task_params);
return _latestMallTaskId != 0;
TaskId id = AsstAppendTaskWithEncoding("Mall", task_params);
_latestTaskId[TaskType.Mall] = id;
return id != 0;
}
private TaskId _latestRecruitTaskId = 0;
public bool AsstAppendRecruit(int max_times, int[] select_level, int required_len, int[] confirm_level, int confirm_len, bool need_refresh, bool use_expedited, bool skip_robot)
{
var task_params = new JObject();
@@ -852,12 +890,11 @@ namespace MeoAsstGui
task_params["expedite"] = use_expedited;
task_params["expedite_times"] = max_times;
task_params["skip_robot"] = skip_robot;
_latestRecruitTaskId = AsstAppendTaskWithEncoding("Recruit", task_params);
return _latestRecruitTaskId != 0;
TaskId id = AsstAppendTaskWithEncoding("Recruit", task_params);
_latestTaskId[TaskType.Recruit] = id;
return id != 0;
}
private TaskId _latestInfrastTaskId = 0;
public bool AsstAppendInfrast(int work_mode, string[] order, int order_len, string uses_of_drones, double dorm_threshold)
{
var task_params = new JObject();
@@ -866,22 +903,20 @@ namespace MeoAsstGui
task_params["drones"] = uses_of_drones;
task_params["threshold"] = dorm_threshold;
task_params["replenish"] = true;
_latestInfrastTaskId = AsstAppendTaskWithEncoding("Infrast", task_params);
return _latestInfrastTaskId != 0;
TaskId id = AsstAppendTaskWithEncoding("Infrast", task_params);
_latestTaskId[TaskType.Infrast] = id;
return id != 0;
}
private TaskId _latestRoguelikeTaskId = 0;
public bool AsstAppendRoguelike(int mode)
{
var task_params = new JObject();
task_params["mode"] = mode;
_latestRoguelikeTaskId = AsstAppendTaskWithEncoding("Roguelike", task_params);
return _latestRoguelikeTaskId != 0;
TaskId id = AsstAppendTaskWithEncoding("Roguelike", task_params);
_latestTaskId[TaskType.Roguelike] = id;
return id != 0;
}
private TaskId _latestRecruitCalcTaskId = 0;
public bool AsstStartRecruitCalc(int[] select_level, int required_len, bool set_time)
{
var task_params = new JObject();
@@ -892,20 +927,20 @@ namespace MeoAsstGui
task_params["set_time"] = true;
task_params["expedite"] = false;
task_params["expedite_times"] = 0;
_latestRecruitCalcTaskId = AsstAppendTaskWithEncoding("Recruit", task_params);
return _latestRecruitCalcTaskId != 0 && AsstStart();
TaskId id = AsstAppendTaskWithEncoding("Recruit", task_params);
_latestTaskId[TaskType.RecruitCalc] = id;
return id != 0;
}
private TaskId _latestCopilotTaskId = 0;
public bool AsstStartCopilot(string stage_name, string filename, bool formation)
{
var task_params = new JObject();
task_params["stage_name"] = stage_name;
task_params["filename"] = filename;
task_params["formation"] = formation;
_latestCopilotTaskId = AsstAppendTaskWithEncoding("Copilot", task_params);
return _latestCopilotTaskId != 0 && AsstStart();
TaskId id = AsstAppendTaskWithEncoding("Copilot", task_params);
_latestTaskId[TaskType.Copilot] = id;
return id != 0;
}
public bool AsstStart()
@@ -915,7 +950,9 @@ namespace MeoAsstGui
public bool AsstStop()
{
return AsstStop(_handle);
bool ret = AsstStop(_handle);
_latestTaskId.Clear();
return ret;
}
public void AsstDestroy()

View File

@@ -4,11 +4,13 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:c="clr-namespace:CalcBinding;assembly=CalcBinding"
mc:Ignorable="d"
xmlns:c="clr-namespace:CalcBinding;assembly=CalcBinding"
xmlns:vm="clr-namespace:MeoAsstGui;assembly=MeoAsstGui"
xmlns:s="https://github.com/canton7/Stylet"
xmlns:local="clr-namespace:MeoAsstGui"
d:DataContext="{d:DesignInstance {x:Type vm:TaskQueueViewModel}}"
d:DesignHeight="200" d:DesignWidth="300">
d:DesignHeight="500" d:DesignWidth="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
@@ -17,32 +19,32 @@
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" Grid.Row="0" VerticalAlignment="Center">
<CheckBox IsChecked="{Binding UseMedicine}" IsHitTestVisible="{Binding Idle}" Content="吃理智药" Margin="10" />
<TextBox Text="{Binding MedicineNumber}" IsReadOnly="{c:Binding Path=!Idle}" TextWrapping="Wrap" Margin="10"
<CheckBox IsChecked="{Binding UseMedicine}" Content="吃理智药" Margin="10" />
<TextBox Text="{Binding MedicineNumber}" TextWrapping="Wrap" Margin="10"
Width="50" InputMethod.IsInputMethodEnabled="False" />
<TextBlock Style="{StaticResource TextBlockDefault}" Text="个" />
<!--<TextBlock Style="{StaticResource TextBlockDefaultBold}" Text="{Binding MedicineInfo}" Margin="30, 0, 0, 0" VerticalAlignment="Center" />-->
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="1" VerticalAlignment="Center">
<CheckBox IsChecked="{Binding UseStone}" IsHitTestVisible="{Binding Idle}" Content="吃石头 " Margin="10" />
<TextBox Text="{Binding StoneNumber}" IsReadOnly="{c:Binding Path=!Idle}" TextWrapping="Wrap" Margin="10"
<CheckBox IsChecked="{Binding UseStone}" Content="吃石头 " Margin="10" />
<TextBox Text="{Binding StoneNumber}" TextWrapping="Wrap" Margin="10"
Width="50" InputMethod.IsInputMethodEnabled="False" />
<TextBlock Style="{StaticResource TextBlockDefault}" Text="颗" />
<!--<TextBlock Style="{StaticResource TextBlockDefaultBold}" Text="{Binding StoneInfo}" Margin="30, 0, 0, 0" VerticalAlignment="Center" />-->
</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"
<CheckBox IsChecked="{Binding HasTimesLimited}" Content="指定次数" Margin="10" />
<TextBox Text="{Binding MaxTimes}" TextWrapping="Wrap" Margin="10"
Width="50" InputMethod.IsInputMethodEnabled="False" />
<TextBlock Style="{StaticResource TextBlockDefault}" Text="次" />
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="3" VerticalAlignment="Center">
<CheckBox IsChecked="{Binding IsSpecifiedDrops}" IsHitTestVisible="{Binding Idle}" Content="指定材料" Margin="10" />
<CheckBox IsChecked="{Binding IsSpecifiedDrops}" Content="指定材料" Margin="10" />
<ComboBox Width="120" Margin="10"
IsHitTestVisible ="{Binding Path=Idle}"
IsEditable="True"
IsTextSearchEnabled ="True"
DisplayMemberPath="Display"
@@ -54,7 +56,7 @@
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="4" VerticalAlignment="Center">
<!--<TextBlock Style="{StaticResource TextBlockDefault}" Margin="35,10,0,10" Text="掉落数 " />-->
<TextBox Text="{Binding DropsQuantity}" IsReadOnly="{c:Binding Path=!Idle}" TextWrapping="Wrap"
<TextBox Text="{Binding DropsQuantity}" TextWrapping="Wrap"
Width="95" Margin="98,10,10,10" InputMethod.IsInputMethodEnabled="False" />
<TextBlock Style="{StaticResource TextBlockDefault}" Text="个" />
</StackPanel>
@@ -68,5 +70,6 @@
SelectedValuePath="Value"
SelectedValue="{Binding Stage}" />
</StackPanel>
<Button Grid.Row="6" Command="{s:Action SetParams}" Visibility="{c:Binding !Idle}" HorizontalAlignment="Left" Content="修改" Width="50" Height="30" Margin="10" />
</Grid>
</UserControl>

View File

@@ -431,6 +431,45 @@ namespace MeoAsstGui
return asstProxy.AsstAppendFight(Stage, medicine, stone, times, DropsItemId, drops_quantity);
}
public void SetParams()
{
int medicine = 0;
if (UseMedicine)
{
if (!int.TryParse(MedicineNumber, out medicine))
{
medicine = 0;
}
}
int stone = 0;
if (UseStone)
{
if (!int.TryParse(StoneNumber, out stone))
{
stone = 0;
}
}
int times = int.MaxValue;
if (HasTimesLimited)
{
if (!int.TryParse(MaxTimes, 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>();
asstProxy.AsstSetFightTaskParams(Stage, medicine, stone, times, DropsItemId, drops_quantity);
}
private bool appendInfrast()
{
var settings = _container.Get<SettingsViewModel>();