From 19a73ef5d43db4b8c2d59037bf89dff18c29498e Mon Sep 17 00:00:00 2001
From: status102 <102887808+status102@users.noreply.github.com>
Date: Sat, 8 Mar 2025 10:28:05 +0800
Subject: [PATCH] =?UTF-8?q?rft:=20wpf=E4=BF=A1=E7=94=A8=E4=BB=BB=E5=8A=A1?=
=?UTF-8?q?=E5=BA=8F=E5=88=97=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/MaaWpfGui/Main/AsstProxy.cs | 32 -------
.../Models/AsstTasks/AsstMallTask.cs | 84 +++++++++++++++++++
.../ViewModels/UI/TaskQueueViewModel.cs | 22 +----
.../TaskQueue/MallSettingsUserControlModel.cs | 40 ++++++++-
4 files changed, 125 insertions(+), 53 deletions(-)
create mode 100644 src/MaaWpfGui/Models/AsstTasks/AsstMallTask.cs
diff --git a/src/MaaWpfGui/Main/AsstProxy.cs b/src/MaaWpfGui/Main/AsstProxy.cs
index 446bfa7d79..2467951677 100644
--- a/src/MaaWpfGui/Main/AsstProxy.cs
+++ b/src/MaaWpfGui/Main/AsstProxy.cs
@@ -2180,38 +2180,6 @@ namespace MaaWpfGui.Main
return MaaService.AsstBackToHome(_handle);
}
- ///
- /// 领取信用及商店购物。
- ///
- /// 是否信用战斗。
- /// 信用战斗选择编队
- /// 是否访问好友。
- /// 是否购物。
- /// 优先购买列表。
- /// 黑名单列表。
- /// 是否在信用溢出时无视黑名单
- /// 只购买折扣信用商品(未打折的白名单物品仍会购买)。
- /// 设置300以下信用点停止购买商品。
- /// 是否成功。
- public bool AsstAppendMall(bool creditFight, int selectFormation, bool visitFriends, bool withShopping, string[] firstList, string[] blacklist, bool forceShoppingIfCreditFull, bool onlyBuyDiscount, bool reserveMaxCredit)
- {
- var taskParams = new JObject
- {
- ["credit_fight"] = creditFight,
- ["select_formation"] = selectFormation,
- ["visit_friends"] = visitFriends,
- ["shopping"] = withShopping,
- ["buy_first"] = new JArray(firstList),
- ["blacklist"] = new JArray(blacklist),
- ["force_shopping_if_credit_full"] = forceShoppingIfCreditFull,
- ["only_buy_discount"] = onlyBuyDiscount,
- ["reserve_max_credit"] = reserveMaxCredit,
- };
- AsstTaskId id = AsstAppendTaskWithEncoding(AsstTaskType.Mall, taskParams);
- _taskStatus.Add(id, TaskType.Mall);
- return id != 0;
- }
-
public bool AsstSetInfrastTaskParams(
IEnumerable order,
string usesOfDrones,
diff --git a/src/MaaWpfGui/Models/AsstTasks/AsstMallTask.cs b/src/MaaWpfGui/Models/AsstTasks/AsstMallTask.cs
new file mode 100644
index 0000000000..a1796d4304
--- /dev/null
+++ b/src/MaaWpfGui/Models/AsstTasks/AsstMallTask.cs
@@ -0,0 +1,84 @@
+//
+// MaaWpfGui - A part of the MaaCoreArknights project
+// Copyright (C) 2021 MistEO and Contributors
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License v3.0 only as published by
+// the Free Software Foundation, either version 3 of the License, or
+// any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY
+//
+
+#nullable enable
+using System.Collections.Generic;
+using MaaWpfGui.Services;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+
+namespace MaaWpfGui.Models.AsstTasks;
+
+///
+/// 领取信用及商店购物。
+///
+public class AsstMallTask : AsstBaseTask
+{
+ public override AsstTaskType TaskType => AsstTaskType.Mall;
+
+ ///
+ /// Gets or sets a value indicating whether 是否信用战斗
+ ///
+ [JsonProperty("credit_fight")]
+ public bool CreditFight { get; set; }
+
+ ///
+ /// Gets or sets a value indicating whether 信用战斗选择编队
+ ///
+ [JsonProperty("select_formation")]
+ public int SelectFormation { get; set; }
+
+ ///
+ /// Gets or sets a value indicating whether 是否访问好友
+ ///
+ [JsonProperty("visit_friends")]
+ public bool VisitFriends { get; set; }
+
+ ///
+ /// Gets or sets a value indicating whether 是否购物
+ ///
+ [JsonProperty("shopping")]
+ public bool WithShopping { get; set; }
+
+ ///
+ /// Gets or sets a value indicating whether 优先购买列表
+ ///
+ [JsonProperty("buy_first")]
+ public List FirstList { get; set; } = [];
+
+ ///
+ /// Gets or sets a value indicating whether 黑名单列表
+ ///
+ [JsonProperty("blacklist")]
+ public List Blacklist { get; set; } = [];
+
+ ///
+ /// Gets or sets a value indicating whether 是否在信用溢出时无视黑名单
+ ///
+ [JsonProperty("force_shopping_if_credit_full")]
+ public bool ForceShoppingIfCreditFull { get; set; }
+
+ ///
+ /// Gets or sets a value indicating whether 只购买折扣信用商品(未打折的白名单物品仍会购买)
+ ///
+ [JsonProperty("only_buy_discount")]
+ public bool OnlyBuyDiscount { get; set; }
+
+ ///
+ /// Gets or sets a value indicating whether 300以下信用点停止购买商品
+ ///
+ [JsonProperty("reserve_max_credit")]
+ public bool ReserveMaxCredit { get; set; }
+
+ public override (AsstTaskType TaskType, JObject Params) Serialize() => (AsstTaskType.Mall, JObject.FromObject(this));
+}
diff --git a/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs b/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs
index 894d45364e..2285c80380 100644
--- a/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs
+++ b/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs
@@ -1741,25 +1741,9 @@ namespace MaaWpfGui.ViewModels.UI
private bool AppendMall()
{
- var buyFirst = MallTask.CreditFirstList.Split(';', ';')
- .Select(s => s.Trim());
-
- var blackList = MallTask.CreditBlackList.Split(';', ';')
- .Select(s => s.Trim());
-
- blackList = blackList.Union(_blackCharacterListMapping[SettingsViewModel.GameSettings.ClientType]);
- var fightEnable = TaskItemViewModels.Where(x => x.OriginalName == "Combat").FirstOrDefault().IsCheckedWithNull is not false;
-
- return Instances.AsstProxy.AsstAppendMall(
- fightEnable ? (!string.IsNullOrEmpty(FightTask.Stage) && MallTask.CreditFightTaskEnabled) : MallTask.CreditFightTaskEnabled,
- MallTask.CreditFightSelectFormation,
- MallTask.CreditVisitFriendsEnabled,
- MallTask.CreditShopping,
- buyFirst.ToArray(),
- blackList.ToArray(),
- MallTask.CreditForceShoppingIfCreditFull,
- MallTask.CreditOnlyBuyDiscount,
- MallTask.CreditReserveMaxCredit);
+ // 被RemoteControlService反射调用,暂不移除
+ var (type, param) = MallTask.Serialize();
+ return Instances.AsstProxy.AsstAppendTaskWithEncoding(AsstProxy.TaskType.Mall, type, param);
}
private static bool AppendAward()
diff --git a/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/MallSettingsUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/MallSettingsUserControlModel.cs
index b288af3524..78bc212e37 100644
--- a/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/MallSettingsUserControlModel.cs
+++ b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/MallSettingsUserControlModel.cs
@@ -14,10 +14,15 @@
using System;
using System.Collections.Generic;
using System.Globalization;
+using System.Linq;
using MaaWpfGui.Constants;
using MaaWpfGui.Extensions;
using MaaWpfGui.Helper;
+using MaaWpfGui.Models.AsstTasks;
+using MaaWpfGui.Services;
using MaaWpfGui.Utilities.ValueType;
+using MaaWpfGui.ViewModels.UI;
+using Newtonsoft.Json.Linq;
namespace MaaWpfGui.ViewModels.UserControl.TaskQueue;
@@ -33,6 +38,17 @@ public class MallSettingsUserControlModel : TaskViewModel
public static MallSettingsUserControlModel Instance { get; }
+ private readonly Dictionary> _blackCharacterListMapping = new()
+ {
+ { string.Empty, ["讯使", "嘉维尔", "坚雷"] },
+ { "Official", ["讯使", "嘉维尔", "坚雷"] },
+ { "Bilibili", ["讯使", "嘉维尔", "坚雷"] },
+ { "YoStarEN", ["Courier", "Gavial", "Dur-nar"] },
+ { "YoStarJP", ["クーリエ", "ガヴィル", "ジュナー"] },
+ { "YoStarKR", ["쿠리어", "가비알", "듀나"] },
+ { "txwy", ["訊使", "嘉維爾", "堅雷"] },
+ };
+
private string _lastCreditFightTaskTime = ConfigurationHelper.GetValue(ConfigurationKeys.LastCreditFightTaskTime, DateTime.UtcNow.ToYjDate().AddDays(-1).ToFormattedString());
public string LastCreditFightTaskTime
@@ -206,7 +222,7 @@ public class MallSettingsUserControlModel : TaskViewModel
}
}
- private string _creditFirstList = ConfigurationHelper.GetValue(ConfigurationKeys.CreditFirstListNew, LocalizationHelper.GetString("HighPriorityDefault"));
+ private string _creditFirstList = ConfigurationHelper.GetValue(ConfigurationKeys.CreditFirstListNew, LocalizationHelper.GetString("HighPriorityDefault")).Replace(";", ";").Trim();
///
/// Gets or sets the priority item list of credit shop.
@@ -216,12 +232,13 @@ public class MallSettingsUserControlModel : TaskViewModel
get => _creditFirstList;
set
{
+ value = value.Replace(";", ";").Trim();
SetAndNotify(ref _creditFirstList, value);
ConfigurationHelper.SetValue(ConfigurationKeys.CreditFirstListNew, value);
}
}
- private string _creditBlackList = ConfigurationHelper.GetValue(ConfigurationKeys.CreditBlackListNew, LocalizationHelper.GetString("BlacklistDefault"));
+ private string _creditBlackList = ConfigurationHelper.GetValue(ConfigurationKeys.CreditBlackListNew, LocalizationHelper.GetString("BlacklistDefault")).Replace(";", ";").Trim();
///
/// Gets or sets the blacklist of credit shop.
@@ -231,6 +248,7 @@ public class MallSettingsUserControlModel : TaskViewModel
get => _creditBlackList;
set
{
+ value = value.Replace(";", ";").Trim();
SetAndNotify(ref _creditBlackList, value);
ConfigurationHelper.SetValue(ConfigurationKeys.CreditBlackListNew, value);
}
@@ -280,4 +298,22 @@ public class MallSettingsUserControlModel : TaskViewModel
ConfigurationHelper.SetValue(ConfigurationKeys.CreditReserveMaxCredit, value.ToString());
}
}
+
+ public override (AsstTaskType Type, JObject Params) Serialize()
+ {
+ var fightEnable = Instances.TaskQueueViewModel.TaskItemViewModels.Where(x => x.OriginalName == "Combat").FirstOrDefault()?.IsCheckedWithNull is not false;
+ var task = new AsstMallTask()
+ {
+ CreditFight = fightEnable ? (!string.IsNullOrEmpty(FightSettingsUserControlModel.Instance.Stage) && CreditFightTaskEnabled) : CreditFightTaskEnabled,
+ SelectFormation = CreditFightSelectFormation,
+ VisitFriends = CreditVisitFriendsEnabled,
+ WithShopping = CreditShopping,
+ FirstList = CreditFirstList.Split(';').Select(s => s.Trim()).ToList(),
+ Blacklist = CreditBlackList.Split(';').Select(s => s.Trim()).Union(_blackCharacterListMapping[SettingsViewModel.GameSettings.ClientType]).ToList(),
+ ForceShoppingIfCreditFull = CreditForceShoppingIfCreditFull,
+ OnlyBuyDiscount = CreditOnlyBuyDiscount,
+ ReserveMaxCredit = CreditReserveMaxCredit,
+ };
+ return task.Serialize();
+ }
}