mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-19 02:23:01 +08:00
466 lines
14 KiB
C#
466 lines
14 KiB
C#
// <copyright file="RecognizerViewModel.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 General Public License 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>
|
||
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Threading.Tasks;
|
||
using System.Windows;
|
||
using MaaWpfGui.Constants;
|
||
using MaaWpfGui.Helper;
|
||
using MaaWpfGui.Main;
|
||
using Newtonsoft.Json.Linq;
|
||
using Stylet;
|
||
using StyletIoC;
|
||
|
||
namespace MaaWpfGui.ViewModels.UI
|
||
{
|
||
/// <summary>
|
||
/// The view model of recruit.
|
||
/// </summary>
|
||
public class RecognizerViewModel : Screen
|
||
{
|
||
private readonly IWindowManager _windowManager;
|
||
private readonly IContainer _container;
|
||
|
||
private AsstProxy _asstProxy;
|
||
|
||
/// <summary>
|
||
/// Initializes a new instance of the <see cref="RecognizerViewModel"/> class.
|
||
/// </summary>
|
||
/// <param name="container">The IoC container.</param>
|
||
/// <param name="windowManager">The window manager.</param>
|
||
public RecognizerViewModel(IContainer container, IWindowManager windowManager)
|
||
{
|
||
_container = container;
|
||
_windowManager = windowManager;
|
||
DisplayName = LocalizationHelper.GetString("IdentificationTool");
|
||
}
|
||
|
||
protected override void OnInitialActivate()
|
||
{
|
||
base.OnInitialActivate();
|
||
_asstProxy = _container.Get<AsstProxy>();
|
||
}
|
||
|
||
#region Recruit
|
||
private string _recruitInfo = LocalizationHelper.GetString("RecruitmentRecognitionTip");
|
||
|
||
/// <summary>
|
||
/// Gets or sets the recruit info.
|
||
/// </summary>
|
||
public string RecruitInfo
|
||
{
|
||
get => _recruitInfo;
|
||
set => SetAndNotify(ref _recruitInfo, value);
|
||
}
|
||
|
||
private string _recruitResult;
|
||
|
||
/// <summary>
|
||
/// Gets or sets the recruit result.
|
||
/// </summary>
|
||
public string RecruitResult
|
||
{
|
||
get => _recruitResult;
|
||
set => SetAndNotify(ref _recruitResult, value);
|
||
}
|
||
|
||
private bool _chooseLevel3 = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.ChooseLevel3, bool.FalseString));
|
||
|
||
/// <summary>
|
||
/// Gets or sets a value indicating whether to choose level 3.
|
||
/// </summary>
|
||
public bool ChooseLevel3
|
||
{
|
||
get => _chooseLevel3;
|
||
set
|
||
{
|
||
SetAndNotify(ref _chooseLevel3, value);
|
||
ConfigurationHelper.SetValue(ConfigurationKeys.ChooseLevel3, value.ToString());
|
||
}
|
||
}
|
||
|
||
private bool _chooseLevel4 = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.ChooseLevel4, bool.TrueString));
|
||
|
||
/// <summary>
|
||
/// Gets or sets a value indicating whether to choose level 4.
|
||
/// </summary>
|
||
public bool ChooseLevel4
|
||
{
|
||
get => _chooseLevel4;
|
||
set
|
||
{
|
||
SetAndNotify(ref _chooseLevel4, value);
|
||
ConfigurationHelper.SetValue(ConfigurationKeys.ChooseLevel4, value.ToString());
|
||
}
|
||
}
|
||
|
||
private bool _chooseLevel5 = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.ChooseLevel5, bool.TrueString));
|
||
|
||
/// <summary>
|
||
/// Gets or sets a value indicating whether to choose level 5.
|
||
/// </summary>
|
||
public bool ChooseLevel5
|
||
{
|
||
get => _chooseLevel5;
|
||
set
|
||
{
|
||
SetAndNotify(ref _chooseLevel5, value);
|
||
ConfigurationHelper.SetValue(ConfigurationKeys.ChooseLevel5, value.ToString());
|
||
}
|
||
}
|
||
|
||
private bool _chooseLevel6 = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.ChooseLevel6, bool.TrueString));
|
||
|
||
/// <summary>
|
||
/// Gets or sets a value indicating whether to choose level 6.
|
||
/// </summary>
|
||
public bool ChooseLevel6
|
||
{
|
||
get => _chooseLevel6;
|
||
set
|
||
{
|
||
SetAndNotify(ref _chooseLevel6, value);
|
||
ConfigurationHelper.SetValue(ConfigurationKeys.ChooseLevel6, value.ToString());
|
||
}
|
||
}
|
||
|
||
private bool _autoSetTime = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.AutoSetTime, bool.TrueString));
|
||
|
||
/// <summary>
|
||
/// Gets or sets a value indicating whether to set time automatically.
|
||
/// </summary>
|
||
public bool RecruitAutoSetTime
|
||
{
|
||
get => _autoSetTime;
|
||
set
|
||
{
|
||
SetAndNotify(ref _autoSetTime, value);
|
||
ConfigurationHelper.SetValue(ConfigurationKeys.AutoSetTime, value.ToString());
|
||
}
|
||
}
|
||
|
||
private bool _isLevel3UseShortTime = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.Level3UseShortTime, bool.FalseString));
|
||
|
||
/// <summary>
|
||
/// Gets or sets a value indicating whether to shorten the time for level 3.
|
||
/// </summary>
|
||
public bool IsLevel3UseShortTime
|
||
{
|
||
get => _isLevel3UseShortTime;
|
||
set
|
||
{
|
||
SetAndNotify(ref _isLevel3UseShortTime, value);
|
||
ConfigurationHelper.SetValue(ConfigurationKeys.Level3UseShortTime, value.ToString());
|
||
}
|
||
}
|
||
|
||
private bool _recruitCaught = false;
|
||
|
||
/// <summary>
|
||
/// Starts calculation.
|
||
/// </summary>
|
||
public async void RecruitStartCalc()
|
||
{
|
||
string errMsg = string.Empty;
|
||
RecruitInfo = LocalizationHelper.GetString("ConnectingToEmulator");
|
||
_recruitCaught = await Task.Run(() => _asstProxy.AsstConnect(ref errMsg));
|
||
if (!_recruitCaught)
|
||
{
|
||
RecruitInfo = errMsg;
|
||
return;
|
||
}
|
||
|
||
RecruitInfo = LocalizationHelper.GetString("Identifying");
|
||
RecruitResult = string.Empty;
|
||
|
||
var levelList = new List<int>();
|
||
|
||
if (ChooseLevel3)
|
||
{
|
||
levelList.Add(3);
|
||
}
|
||
|
||
if (ChooseLevel4)
|
||
{
|
||
levelList.Add(4);
|
||
}
|
||
|
||
if (ChooseLevel5)
|
||
{
|
||
levelList.Add(5);
|
||
}
|
||
|
||
if (ChooseLevel6)
|
||
{
|
||
levelList.Add(6);
|
||
}
|
||
|
||
_asstProxy.AsstStartRecruitCalc(levelList.ToArray(), RecruitAutoSetTime);
|
||
}
|
||
#endregion
|
||
|
||
#region Depot
|
||
private string _depotInfo = LocalizationHelper.GetString("DepotRecognitionTip");
|
||
|
||
/// <summary>
|
||
/// Gets or sets the depot info.
|
||
/// </summary>
|
||
public string DepotInfo
|
||
{
|
||
get => _depotInfo;
|
||
set => SetAndNotify(ref _depotInfo, value);
|
||
}
|
||
|
||
private string _depotResult;
|
||
|
||
/// <summary>
|
||
/// Gets or sets the depot result.
|
||
/// </summary>
|
||
public string DepotResult
|
||
{
|
||
get => _depotResult;
|
||
set => SetAndNotify(ref _depotResult, value);
|
||
}
|
||
|
||
/// <summary>
|
||
/// Gets or sets the ArkPlanner result.
|
||
/// </summary>
|
||
public string ArkPlannerResult { get; set; } = string.Empty;
|
||
|
||
/// <summary>
|
||
/// Gets or sets the Lolicon result.
|
||
/// </summary>
|
||
public string LoliconResult { get; set; } = string.Empty;
|
||
|
||
/// <summary>
|
||
/// parse of depot recognition result
|
||
/// </summary>
|
||
/// <param name="details">detailed json-style parameters</param>
|
||
/// <returns>Success or not</returns>
|
||
public bool DepotParse(JObject details)
|
||
{
|
||
string result = string.Empty;
|
||
int count = 0;
|
||
foreach (var item in details["arkplanner"]["object"]["items"].Cast<JObject>())
|
||
{
|
||
result += (string)item["name"] + " : " + (int)item["have"] + "\t";
|
||
if (++count == 3)
|
||
{
|
||
result += "\n";
|
||
count = 0;
|
||
}
|
||
}
|
||
|
||
DepotResult = result;
|
||
|
||
ArkPlannerResult = (string)details["arkplanner"]["data"];
|
||
LoliconResult = (string)details["lolicon"]["data"];
|
||
|
||
bool done = (bool)details["done"];
|
||
if (done)
|
||
{
|
||
DepotInfo = LocalizationHelper.GetString("IdentificationCompleted") + "\n" + LocalizationHelper.GetString("DepotRecognitionTip");
|
||
DepotDone = true;
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
private bool _depotDone = false;
|
||
|
||
/// <summary>
|
||
/// Gets or sets a value indicating whether depot info is parsed.
|
||
/// </summary>
|
||
public bool DepotDone
|
||
{
|
||
get => _depotDone;
|
||
set => SetAndNotify(ref _depotDone, value);
|
||
}
|
||
|
||
/// <summary>
|
||
/// Export depot info to ArkPlanner.
|
||
/// </summary>
|
||
public void ExportToArkplanner()
|
||
{
|
||
Clipboard.SetDataObject(ArkPlannerResult);
|
||
DepotInfo = LocalizationHelper.GetString("CopiedToClipboard");
|
||
}
|
||
|
||
/// <summary>
|
||
/// Export depot info to Lolicon.
|
||
/// </summary>
|
||
public void ExportToLolicon()
|
||
{
|
||
Clipboard.SetDataObject(LoliconResult);
|
||
DepotInfo = LocalizationHelper.GetString("CopiedToClipboard");
|
||
}
|
||
|
||
private void DepotClear()
|
||
{
|
||
DepotResult = string.Empty;
|
||
ArkPlannerResult = string.Empty;
|
||
LoliconResult = string.Empty;
|
||
DepotDone = false;
|
||
}
|
||
|
||
/// <summary>
|
||
/// Starts depot recognition.
|
||
/// </summary>
|
||
public async void StartDepot()
|
||
{
|
||
string errMsg = string.Empty;
|
||
DepotInfo = LocalizationHelper.GetString("ConnectingToEmulator");
|
||
bool caught = await Task.Run(() => _asstProxy.AsstConnect(ref errMsg));
|
||
if (!caught)
|
||
{
|
||
DepotInfo = errMsg;
|
||
return;
|
||
}
|
||
|
||
DepotInfo = LocalizationHelper.GetString("Identifying");
|
||
DepotClear();
|
||
|
||
_asstProxy.AsstStartDepot();
|
||
}
|
||
#endregion
|
||
|
||
#region Oper
|
||
|
||
/// <summary>
|
||
/// 未实装干员,但在battle_data中,
|
||
/// </summary>
|
||
private static readonly string[] VirtuallyOpers =
|
||
{
|
||
"预备干员-近战",
|
||
"预备干员-术师",
|
||
"预备干员-后勤",
|
||
"预备干员-狙击",
|
||
"预备干员-重装",
|
||
"郁金香",
|
||
"Stormeye",
|
||
"Touch",
|
||
"Pith",
|
||
"Sharp",
|
||
"阿米娅-WARRIOR",
|
||
};
|
||
|
||
private string _operInfo = LocalizationHelper.GetString("OperRecognitionTip");
|
||
|
||
public string OperInfo
|
||
{
|
||
get => _operInfo;
|
||
set => SetAndNotify(ref _operInfo, value);
|
||
}
|
||
|
||
private string _operResult;
|
||
|
||
public string OperResult
|
||
{
|
||
get => _operResult;
|
||
set => SetAndNotify(ref _operResult, value);
|
||
}
|
||
|
||
public bool OperParse(JObject details)
|
||
{
|
||
string result = string.Empty;
|
||
/*已拥有干员*/
|
||
JArray operOwn = (JArray)details["have"];
|
||
/*未拥有干员,包含预备干员等*/
|
||
JArray operNotOwn = (JArray)details["nhave"];
|
||
/*移除未实装干员*/
|
||
foreach (var name in VirtuallyOpers)
|
||
{
|
||
operNotOwn.Where(i => i.Type == JTokenType.String && (string)i == name).ToList().ForEach(i => i.Remove());
|
||
}
|
||
|
||
result = "已拥有:" + operOwn.Count.ToString() + "名,未拥有:" + operNotOwn.Count.ToString() + "名;" + "\n\n";
|
||
result += "以下干员未拥有:\n\t";
|
||
int count = 0;
|
||
foreach (var name in operNotOwn)
|
||
{
|
||
if (count++ < 3)
|
||
{
|
||
result += name + ", ";
|
||
}
|
||
else
|
||
{
|
||
result += name + "\n\t";
|
||
count = 0;
|
||
}
|
||
}
|
||
|
||
result += "\n\n以下干员已拥有:\n\n\t";
|
||
count = 0;
|
||
foreach (var name in operOwn)
|
||
{
|
||
if (count++ < 3)
|
||
{
|
||
result += name + ", ";
|
||
}
|
||
else
|
||
{
|
||
result += name + "\n\t";
|
||
count = 0;
|
||
}
|
||
}
|
||
|
||
OperResult = result;
|
||
bool done = (bool)details["done"];
|
||
if (done)
|
||
{
|
||
OperInfo = LocalizationHelper.GetString("IdentificationCompleted") + "\n" + LocalizationHelper.GetString("OperRecognitionTip");
|
||
OperDone = true;
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
private bool _operdone = false;
|
||
|
||
/// <summary>
|
||
/// Gets or sets a value indicating whether depot info is parsed.
|
||
/// </summary>
|
||
public bool OperDone
|
||
{
|
||
get => _operdone;
|
||
set => SetAndNotify(ref _operdone, value);
|
||
}
|
||
|
||
private void ClearResult()
|
||
{
|
||
OperResult = string.Empty;
|
||
OperDone = false;
|
||
}
|
||
|
||
public async void StartOper()
|
||
{
|
||
string errMsg = string.Empty;
|
||
OperInfo = LocalizationHelper.GetString("ConnectingToEmulator");
|
||
bool caught = await Task.Run(() => _asstProxy.AsstConnect(ref errMsg));
|
||
if (!caught)
|
||
{
|
||
OperInfo = errMsg;
|
||
return;
|
||
}
|
||
|
||
OperInfo = LocalizationHelper.GetString("Identifying");
|
||
ClearResult();
|
||
|
||
_asstProxy.AsstStartOper();
|
||
}
|
||
#endregion
|
||
}
|
||
}
|