rft: wpf信用任务序列化

This commit is contained in:
status102
2025-03-08 10:28:05 +08:00
parent ca702ee2fb
commit 4622f7cfbb
4 changed files with 125 additions and 53 deletions

View File

@@ -2180,38 +2180,6 @@ namespace MaaWpfGui.Main
return MaaService.AsstBackToHome(_handle);
}
/// <summary>
/// 领取信用及商店购物。
/// </summary>
/// <param name="creditFight">是否信用战斗。</param>
/// <param name="selectFormation">信用战斗选择编队</param>
/// <param name="visitFriends">是否访问好友。</param>
/// <param name="withShopping">是否购物。</param>
/// <param name="firstList">优先购买列表。</param>
/// <param name="blacklist">黑名单列表。</param>
/// <param name="forceShoppingIfCreditFull">是否在信用溢出时无视黑名单</param>
/// <param name="onlyBuyDiscount">只购买折扣信用商品(未打折的白名单物品仍会购买)。</param>
/// <param name="reserveMaxCredit">设置300以下信用点停止购买商品。</param>
/// <returns>是否成功。</returns>
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<string> order,
string usesOfDrones,

View File

@@ -0,0 +1,84 @@
// <copyright file="AsstMallTask.cs" company="MaaAssistantArknights">
// 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
// </copyright>
#nullable enable
using System.Collections.Generic;
using MaaWpfGui.Services;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace MaaWpfGui.Models.AsstTasks;
/// <summary>
/// 领取信用及商店购物。
/// </summary>
public class AsstMallTask : AsstBaseTask
{
public override AsstTaskType TaskType => AsstTaskType.Mall;
/// <summary>
/// Gets or sets a value indicating whether 是否信用战斗
/// </summary>
[JsonProperty("credit_fight")]
public bool CreditFight { get; set; }
/// <summary>
/// Gets or sets a value indicating whether 信用战斗选择编队
/// </summary>
[JsonProperty("select_formation")]
public int SelectFormation { get; set; }
/// <summary>
/// Gets or sets a value indicating whether 是否访问好友
/// </summary>
[JsonProperty("visit_friends")]
public bool VisitFriends { get; set; }
/// <summary>
/// Gets or sets a value indicating whether 是否购物
/// </summary>
[JsonProperty("shopping")]
public bool WithShopping { get; set; }
/// <summary>
/// Gets or sets a value indicating whether 优先购买列表
/// </summary>
[JsonProperty("buy_first")]
public List<string> FirstList { get; set; } = [];
/// <summary>
/// Gets or sets a value indicating whether 黑名单列表
/// </summary>
[JsonProperty("blacklist")]
public List<string> Blacklist { get; set; } = [];
/// <summary>
/// Gets or sets a value indicating whether 是否在信用溢出时无视黑名单
/// </summary>
[JsonProperty("force_shopping_if_credit_full")]
public bool ForceShoppingIfCreditFull { get; set; }
/// <summary>
/// Gets or sets a value indicating whether 只购买折扣信用商品(未打折的白名单物品仍会购买)
/// </summary>
[JsonProperty("only_buy_discount")]
public bool OnlyBuyDiscount { get; set; }
/// <summary>
/// Gets or sets a value indicating whether 300以下信用点停止购买商品
/// </summary>
[JsonProperty("reserve_max_credit")]
public bool ReserveMaxCredit { get; set; }
public override (AsstTaskType TaskType, JObject Params) Serialize() => (AsstTaskType.Mall, JObject.FromObject(this));
}

View File

@@ -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()

View File

@@ -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<string, IEnumerable<string>> _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();
/// <summary>
/// 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();
/// <summary>
/// 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();
}
}