feat: 连战次数选择 (#8159)

* feat: 连战次数选择

* fix: plugin初始化错误

* fix: 参数错误

* chore: set_params时检查series取值范围

* chore: 修改 series 取值范围

* chore: 剩余理智关卡连战次数设置为1
This commit is contained in:
uye
2024-02-03 00:36:13 +08:00
committed by GitHub
parent cf828efbee
commit 79b1d9da42
13 changed files with 104 additions and 14 deletions

View File

@@ -33,7 +33,7 @@ bool asst::FightTimesTaskPlugin::_run()
return false;
}
}
ProcessTask(*this, { "FightSeries-List-1" }).run();
ProcessTask(*this, { "FightSeries-List-" + std::to_string(m_series) }).run();
inited = true;
return true;

View File

@@ -9,11 +9,13 @@ namespace asst
virtual ~FightTimesTaskPlugin() override = default;
virtual bool verify(AsstMsg msg, const json::value& details) const override;
void set_series(int series) { m_series = series; }
protected:
virtual bool _run() override;
private:
bool inited = false; // 是否成功初始化为1次初始化后后续不再检测 (实现调整次数后移除此变量
int m_series = 1; // 连续战斗次数
};
}

View File

@@ -51,7 +51,7 @@ asst::FightTask::FightTask(const AsstCallback& callback, Assistant* inst)
m_dr_grandet_task_plugin_ptr = m_fight_task_ptr->register_plugin<DrGrandetTaskPlugin>();
m_dr_grandet_task_plugin_ptr->set_enable(false);
m_fight_task_ptr->register_plugin<SanityBeforeStageTaskPlugin>()->set_retry_times(3);
m_fight_task_ptr->register_plugin<FightTimesTaskPlugin>();
m_fight_times_task_plugin_prt = m_fight_task_ptr->register_plugin<FightTimesTaskPlugin>();
m_medicine_plugin = m_fight_task_ptr->register_plugin<MedicineCounterTaskPlugin>();
m_subtasks.emplace_back(m_start_up_task_ptr);
@@ -69,6 +69,11 @@ bool asst::FightTask::set_params(const json::value& params)
const int expiring_medicine = params.get("expiring_medicine", 0);
const int stone = params.get("stone", 0);
const int times = params.get("times", INT_MAX);
const int series = params.get("series", 1);
if (series < 1 || series > 6) {
Log.error("Invalid series");
return false;
}
bool enable_penguin = params.get("report_to_penguin", false);
bool enable_yituliu = params.get("report_to_yituliu", false);
std::string penguin_id = params.get("penguin_id", "");
@@ -121,6 +126,7 @@ bool asst::FightTask::set_params(const json::value& params)
.set_times_limit("StoneConfirm", stone)
.set_times_limit("StartButton1", times)
.set_times_limit("StartButton2", times);
m_fight_times_task_plugin_prt->set_series(series);
m_medicine_plugin->set_count(medicine);
m_medicine_plugin->set_use_expiring(expiring_medicine != 0);
m_medicine_plugin->set_dr_grandet(is_dr_grandet);

View File

@@ -5,6 +5,7 @@
namespace asst
{
class FightTimesTaskPlugin;
class ProcessTask;
class StageDropsTaskPlugin;
class StageNavigationTask;
@@ -26,6 +27,7 @@ namespace asst
std::shared_ptr<ProcessTask> m_start_up_task_ptr = nullptr;
std::shared_ptr<StageNavigationTask> m_stage_navigation_task_ptr = nullptr;
std::shared_ptr<ProcessTask> m_fight_task_ptr = nullptr;
std::shared_ptr<FightTimesTaskPlugin> m_fight_times_task_plugin_prt = nullptr;
std::shared_ptr<MedicineCounterTaskPlugin> m_medicine_plugin = nullptr;
std::shared_ptr<StageDropsTaskPlugin> m_stage_drops_plugin_ptr = nullptr;
std::shared_ptr<DrGrandetTaskPlugin> m_dr_grandet_task_plugin_ptr = nullptr;

View File

@@ -176,6 +176,7 @@ namespace MaaWpfGui.Constants
public const string UseStoneQuantity = "MainFunction.UseStone.Quantity";
public const string TimesLimited = "MainFunction.TimesLimited";
public const string TimesLimitedQuantity = "MainFunction.TimesLimited.Quantity";
public const string SeriesQuantity = "MainFunction.Series.Quantity";
public const string DropsEnable = "MainFunction.Drops.Enable";
public const string DropsItemId = "MainFunction.Drops.ItemId";
public const string DropsItemName = "MainFunction.Drops.ItemName";

View File

@@ -1615,8 +1615,15 @@ namespace MaaWpfGui.Main
private readonly Dictionary<TaskType, AsstTaskId> _latestTaskId = new();
private static JObject SerializeFightTaskParams(string stage, int maxMedicine, int maxStone, int maxTimes,
string dropsItemId, int dropsItemQuantity, bool isMainFight = true)
private static JObject SerializeFightTaskParams(
string stage,
int maxMedicine,
int maxStone,
int maxTimes,
int series,
string dropsItemId,
int dropsItemQuantity,
bool isMainFight = true)
{
var taskParams = new JObject
{
@@ -1624,6 +1631,7 @@ namespace MaaWpfGui.Main
["medicine"] = maxMedicine,
["stone"] = maxStone,
["times"] = maxTimes,
["series"] = series,
["report_to_penguin"] = Instances.SettingsViewModel.EnablePenguin,
["report_to_yituliu"] = Instances.SettingsViewModel.EnableYituliu,
};
@@ -1650,13 +1658,14 @@ namespace MaaWpfGui.Main
/// <param name="maxMedicine">最大使用理智药数量。</param>
/// <param name="maxStone">最大吃石头数量。</param>
/// <param name="maxTimes">指定次数。</param>
/// <param name="series">连战次数。</param>
/// <param name="dropsItemId">指定掉落 ID。</param>
/// <param name="dropsItemQuantity">指定掉落数量。</param>
/// <param name="isMainFight">是否是主任务决定c#侧是否记录任务id</param>
/// <returns>是否成功。</returns>
public bool AsstAppendFight(string stage, int maxMedicine, int maxStone, int maxTimes, string dropsItemId, int dropsItemQuantity, bool isMainFight = true)
public bool AsstAppendFight(string stage, int maxMedicine, int maxStone, int maxTimes, int series, string dropsItemId, int dropsItemQuantity, bool isMainFight = true)
{
var taskParams = SerializeFightTaskParams(stage, maxMedicine, maxStone, maxTimes, dropsItemId, dropsItemQuantity, isMainFight);
var taskParams = SerializeFightTaskParams(stage, maxMedicine, maxStone, maxTimes, series, dropsItemId, dropsItemQuantity, isMainFight);
AsstTaskId id = AsstAppendTaskWithEncoding("Fight", taskParams);
if (isMainFight)
{
@@ -1677,11 +1686,12 @@ namespace MaaWpfGui.Main
/// <param name="maxMedicine">最大使用理智药数量。</param>
/// <param name="maxStone">最大吃石头数量。</param>
/// <param name="maxTimes">指定次数。</param>
/// <param name="series">连战次数。</param>
/// <param name="dropsItemId">指定掉落 ID。</param>
/// <param name="dropsItemQuantity">指定掉落数量。</param>
/// <param name="isMainFight">是否是主任务决定c#侧是否记录任务id</param>
/// <returns>是否成功。</returns>
public bool AsstSetFightTaskParams(string stage, int maxMedicine, int maxStone, int maxTimes, string dropsItemId, int dropsItemQuantity, bool isMainFight = true)
public bool AsstSetFightTaskParams(string stage, int maxMedicine, int maxStone, int maxTimes, int series, string dropsItemId, int dropsItemQuantity, bool isMainFight = true)
{
var type = isMainFight ? TaskType.Fight : TaskType.FightRemainingSanity;
if (!_latestTaskId.ContainsKey(type))
@@ -1695,7 +1705,7 @@ namespace MaaWpfGui.Main
return false;
}
var taskParams = SerializeFightTaskParams(stage, maxMedicine, maxStone, maxTimes, dropsItemId, dropsItemQuantity);
var taskParams = SerializeFightTaskParams(stage, maxMedicine, maxStone, maxTimes, series, dropsItemId, dropsItemQuantity);
return AsstSetTaskParamsWithEncoding(id, taskParams);
}

View File

@@ -352,6 +352,7 @@ Other client types are not supported</system:String>
<system:String x:Key="PerformBattles">Perform Battles</system:String>
<system:String x:Key="AssignedMaterial">Material</system:String>
<system:String x:Key="Quantity">Quantity</system:String>
<system:String x:Key="Series">Series</system:String>
<system:String x:Key="StageSelect">Stage</system:String>
<system:String x:Key="StageSelect2">Alternative</system:String>
<system:String x:Key="RemainingSanityStage">Remaining Sanity</system:String>

View File

@@ -352,6 +352,7 @@ Bilibili: ログイン インターフェイスに表示されるアカウント
<system:String x:Key="PerformBattles">周回数指定</system:String>
<system:String x:Key="AssignedMaterial">素材を限定</system:String>
<system:String x:Key="Quantity">ドロップ数</system:String>
<system:String x:Key="Series">連戦回数</system:String>
<system:String x:Key="StageSelect">ステージ</system:String>
<system:String x:Key="StageSelect2">代替ステージ</system:String>
<system:String x:Key="RemainingSanityStage">余剰理性の消費</system:String>

View File

@@ -352,6 +352,7 @@ Bilibili: 로그인 인터페이스에 표시되는 계정 이름(예: 장산)
<system:String x:Key="PerformBattles">횟수 제한</system:String>
<system:String x:Key="AssignedMaterial">드롭 제한</system:String>
<system:String x:Key="Quantity">드롭 수</system:String>
<system:String x:Key="Series">연전 횟수</system:String>
<system:String x:Key="StageSelect">스테이지 선택</system:String>
<system:String x:Key="StageSelect2">대안</system:String>
<system:String x:Key="RemainingSanityStage">남은 이성</system:String>

View File

@@ -352,6 +352,7 @@
<system:String x:Key="PerformBattles">指定次数</system:String>
<system:String x:Key="AssignedMaterial">指定材料</system:String>
<system:String x:Key="Quantity">刷取数量</system:String>
<system:String x:Key="Series">连战次数</system:String>
<system:String x:Key="StageSelect">关卡选择</system:String>
<system:String x:Key="StageSelect2">备选</system:String>
<system:String x:Key="RemainingSanityStage">剩余理智</system:String>

View File

@@ -350,6 +350,7 @@
<system:String x:Key="PerformBattles">指定次數</system:String>
<system:String x:Key="AssignedMaterial">指定材料</system:String>
<system:String x:Key="Quantity">刷取數量</system:String>
<system:String x:Key="Series">連戰次數</system:String>
<system:String x:Key="StageSelect">關卡選擇</system:String>
<system:String x:Key="StageSelect2">備選</system:String>
<system:String x:Key="RemainingSanityStage">剩餘理智</system:String>

View File

@@ -1151,6 +1151,11 @@ namespace MaaWpfGui.ViewModels.UI
}
}
if (!int.TryParse(Series, out var series))
{
series = 1;
}
int dropsQuantity = 0;
if (IsSpecifiedDrops)
{
@@ -1162,7 +1167,7 @@ namespace MaaWpfGui.ViewModels.UI
string curStage = Stage;
bool mainFightRet = Instances.AsstProxy.AsstAppendFight(curStage, medicine, stone, times, DropsItemId, dropsQuantity);
bool mainFightRet = Instances.AsstProxy.AsstAppendFight(curStage, medicine, stone, times, series, DropsItemId, dropsQuantity);
if (!mainFightRet)
{
@@ -1179,14 +1184,14 @@ namespace MaaWpfGui.ViewModels.UI
continue;
}
mainFightRet = Instances.AsstProxy.AsstAppendFight(stage, medicine, 0, int.MaxValue, string.Empty, 0);
mainFightRet = Instances.AsstProxy.AsstAppendFight(stage, medicine, 0, int.MaxValue, series, string.Empty, 0);
break;
}
}
if (mainFightRet && UseRemainingSanityStage && !string.IsNullOrEmpty(RemainingSanityStage))
{
return Instances.AsstProxy.AsstAppendFight(RemainingSanityStage, 0, 0, int.MaxValue, string.Empty, 0, false);
return Instances.AsstProxy.AsstAppendFight(RemainingSanityStage, 0, 0, int.MaxValue, 1, string.Empty, 0, false);
}
return mainFightRet;
@@ -1231,6 +1236,11 @@ namespace MaaWpfGui.ViewModels.UI
}
}
if (!int.TryParse(Series, out var series))
{
series = 1;
}
int dropsQuantity = 0;
if (IsSpecifiedDrops)
{
@@ -1240,12 +1250,12 @@ namespace MaaWpfGui.ViewModels.UI
}
}
Instances.AsstProxy.AsstSetFightTaskParams(Stage, medicine, stone, times, DropsItemId, dropsQuantity);
Instances.AsstProxy.AsstSetFightTaskParams(Stage, medicine, stone, times, series, DropsItemId, dropsQuantity);
}
private void SetFightRemainingSanityParams()
{
Instances.AsstProxy.AsstSetFightTaskParams(RemainingSanityStage, 0, 0, int.MaxValue, string.Empty, 0, false);
Instances.AsstProxy.AsstSetFightTaskParams(RemainingSanityStage, 0, 0, int.MaxValue, 1, string.Empty, 0, false);
}
private void SetInfrastParams()
@@ -2258,6 +2268,11 @@ namespace MaaWpfGui.ViewModels.UI
}
*/
/// <summary>
/// Gets or private sets the list of series.
/// </summary>
public List<string> SeriesList { get; private set; } = ["1", "2", "3", "4", "5", "6"];
private ObservableCollection<CombinedData> _stageList = new();
/// <summary>
@@ -2923,6 +2938,28 @@ namespace MaaWpfGui.ViewModels.UI
}
}
private string _series = ConfigurationHelper.GetValue(ConfigurationKeys.SeriesQuantity, "1");
/// <summary>
/// Gets or sets the max number of times.
/// </summary>
// 所以为啥这玩意是 string 呢?改配置的时候把上面那些也都改成 int 吧
public string Series
{
get => _series;
set
{
if (_series == value)
{
return;
}
SetAndNotify(ref _series, value);
SetFightParams();
ConfigurationHelper.SetValue(ConfigurationKeys.SeriesQuantity, value);
}
}
#region Drops
private bool? _isSpecifiedDropsWithNull = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.DropsEnable, bool.FalseString));

View File

@@ -24,6 +24,7 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
@@ -150,6 +151,32 @@
</StackPanel>
</Grid>
<Grid Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" MinWidth="100" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<StackPanel Orientation="Vertical">
<Grid Height="42">
<controls:TextBlock
Margin="6"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Text="{DynamicResource Series}"
TextAlignment="Center"
TextWrapping="Wrap" />
</Grid>
</StackPanel>
<StackPanel Grid.Column="1" Orientation="Vertical">
<ComboBox
Height="30"
Margin="6"
VerticalContentAlignment="Center"
IsHitTestVisible="{c:Binding !FightTaskRunning}"
ItemsSource="{Binding SeriesList}"
SelectedValue="{Binding Series}"/>
</StackPanel>
</Grid>
<Grid Grid.Row="3">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" MinWidth="100" />
<ColumnDefinition />
@@ -277,7 +304,7 @@
Visibility="{c:Binding 'CustomStageCode and UseRemainingSanityStage'}" />
</StackPanel>
</Grid>
<Grid Grid.Row="3" Visibility="{c:Binding 'CustomInfrastEnabled and TaskSettingVisibilities.CustomInfrastPlanShowInFightSettings'}">
<Grid Grid.Row="4" Visibility="{c:Binding 'CustomInfrastEnabled and TaskSettingVisibilities.CustomInfrastPlanShowInFightSettings'}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" MinWidth="100" />
<ColumnDefinition />