Files
better-genshin-impact/BetterGenshinImpact/ViewModel/Pages/HotKeyPageViewModel.cs
辉鸭蛋 2135189bf6 新版本自动钓鱼 @FishmanTheMurloc (#1176)
* Revert "Revert #1059"

This reverts commit 4b65370e9f.

* natlan fish model

* 新增调整时间的功能

* test

* Feat/new fishing (#1060)

* 没有找到鱼饵时不再抛异常而是返回行为失败;细小优化;测试分支是否配置正确

* 恢复半自动钓鱼功能(仅自动拉条);将CheckFishingUserInterface方法添加到行为树,使其直接控制启停;PutRects方法增加筛选,避免画出没有高度的框框导致残留红点在画布上;去掉局部变量_currContent;钓鱼结束不再依据_noRectsCount判断

* 添加一步抛竿后检查,避免往红色靶点抛竿导致失败

* 大家终于炼出了好用的适用纳塔版本的鱼模型;实现注释描述的“选择最多鱼吃的饵料”;添加koihead鱼类,进入抛竿时忽略koi,只看koihead;Fishpond.TargetRect补上空值处理;去掉_switchBaitContinuouslyFrameNum,目前该段代码有时候会导致发呆;钓鱼结束时多等5秒,避免“获得鱼”的提示图被错误地计入下一次抛竿找鱼的预测

* 注释了AutoFishingTrigger中,FishBite和Fishing方法中的一些代码,解除了对CaptureContent.FrameRate的引用以方便开新坑;开了个新坑AutoFishingTask

* 新增全自动钓鱼独立任务的ui界面

* 封装了所有钓鱼行为,消灭了AutoFishingTrigger中大部分私有变量,剩余一些用来在行为之间传递信息的变量被丢到Blackboard中

* 代码清理:删除AutoFishingTrigger中被注释的私有变量;行为树扩展方法移动到单独的文件中

* 封装好的行为都搬家到Behaviours.cs去了;钓鱼独立任务基本完成;Blackboard添加chooseBaitUIOpening字段以避免在选择鱼饵界面时因图标被灰色遮罩而影响图像匹配;抛竿行为添加OnTerminate方法修复合并预抛竿和抛竿行为时产生的bug

* 优化VisionContext框框的代码

* AutoFishingTask加了个转圈圈找鱼的动作

* 钓鱼任务时如果有F键以及确认键,就交互一下进入钓鱼模式

* 添加供js调用的钓鱼任务方法

* 调整视角时也调整游戏角色的朝向;因为错误率较高,抛竿前找鱼时不再对右下角图标进行模板匹配检查

* 把MoveViewpointDown封装成行为了,黑板新增字段pitchReset,改进了流程中调整视角俯仰的部分;钓鱼任务中为了避免人物待机动作吃掉钓鱼F键,ChangeView方法改成始终都按S和W键

* ThrowRod行为删去对鱼群位置的校验,该段校验经常导致发呆;并将该行为更名为GetFishpond

* 对EnterFishingMode行为进行优化并修复bug;钓鱼循环修正

* 将螺旋视角找鱼的行为简化为低头转圈找,以适应路径任务完成时经常无法朝向鱼的情况;按下钓鱼键后等待界面出现时间延长至2秒

* 添加js独立任务调用自动钓鱼

* 新增`fishing`的Action用于触发钓鱼

* AutoFishingTask删去右下角ExitFishingButtonRo的模板匹配校验,因为错误的未识别有点多;添加当前焦点窗口校验

* AutoFishingTask增加设置昼夜功能,在7点和19点各钓一轮

---------

Co-authored-by: 辉鸭蛋 <huiyadanli@gmail.com>

---------

Co-authored-by: FishmanTheMurloc <162452111+FishmanTheMurloc@users.noreply.github.com>
2025-02-17 11:36:10 +08:00

668 lines
28 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using BetterGenshinImpact.Core.Config;
using BetterGenshinImpact.Core.Recorder;
using BetterGenshinImpact.Core.Script;
using BetterGenshinImpact.Core.Simulator;
using BetterGenshinImpact.GameTask;
using BetterGenshinImpact.GameTask.AutoFight;
using BetterGenshinImpact.GameTask.AutoPathing;
using BetterGenshinImpact.GameTask.AutoPathing.Handler;
using BetterGenshinImpact.GameTask.AutoTrackPath;
using BetterGenshinImpact.GameTask.Common;
using BetterGenshinImpact.GameTask.Common.BgiVision;
using BetterGenshinImpact.GameTask.Common.Job;
using BetterGenshinImpact.GameTask.Macro;
using BetterGenshinImpact.GameTask.QucikBuy;
using BetterGenshinImpact.GameTask.QuickSereniteaPot;
using BetterGenshinImpact.Helpers;
using BetterGenshinImpact.Helpers.Extensions;
using BetterGenshinImpact.Model;
using BetterGenshinImpact.Service.Interface;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging;
using CommunityToolkit.Mvvm.Messaging.Messages;
using Microsoft.Extensions.Logging;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using BetterGenshinImpact.Core.Recognition.OCR;
using BetterGenshinImpact.Core.Recognition.OpenCv;
using BetterGenshinImpact.GameTask.AutoFight.Assets;
using BetterGenshinImpact.GameTask.Model.Area;
using BetterGenshinImpact.GameTask.QuickTeleport.Assets;
using BetterGenshinImpact.View;
using OpenCvSharp;
using Vanara.PInvoke;
using HotKeySettingModel = BetterGenshinImpact.Model.HotKeySettingModel;
namespace BetterGenshinImpact.ViewModel.Pages;
public partial class HotKeyPageViewModel : ObservableObject, IViewModel
{
private readonly ILogger<HotKeyPageViewModel> _logger;
private readonly TaskSettingsPageViewModel _taskSettingsPageViewModel;
public AllConfig Config { get; set; }
[ObservableProperty]
private ObservableCollection<HotKeySettingModel> _hotKeySettingModels = [];
public HotKeyPageViewModel(IConfigService configService, ILogger<HotKeyPageViewModel> logger, TaskSettingsPageViewModel taskSettingsPageViewModel)
{
_logger = logger;
_taskSettingsPageViewModel = taskSettingsPageViewModel;
// 获取配置
Config = configService.Get();
// 构建快捷键配置列表
BuildHotKeySettingModelList();
var list = GetAllNonDirectoryHotkey(HotKeySettingModels);
foreach (var hotKeyConfig in list)
{
hotKeyConfig.RegisterHotKey();
hotKeyConfig.PropertyChanged += (sender, e) =>
{
if (sender is HotKeySettingModel model)
{
// 反射更新配置
// 更新快捷键
if (e.PropertyName == "HotKey")
{
Debug.WriteLine($"{model.FunctionName} 快捷键变更为 {model.HotKey}");
var pi = Config.HotKeyConfig.GetType().GetProperty(model.ConfigPropertyName, BindingFlags.Public | BindingFlags.Instance);
if (null != pi && pi.CanWrite)
{
var str = model.HotKey.ToString();
if (str == "< None >")
{
str = "";
}
pi.SetValue(Config.HotKeyConfig, str, null);
}
}
// 更新快捷键类型
if (e.PropertyName == "HotKeyType")
{
Debug.WriteLine($"{model.FunctionName} 快捷键类型变更为 {model.HotKeyType.ToChineseName()}");
model.HotKey = HotKey.None;
var pi = Config.HotKeyConfig.GetType().GetProperty(model.ConfigPropertyName + "Type", BindingFlags.Public | BindingFlags.Instance);
if (null != pi && pi.CanWrite)
{
pi.SetValue(Config.HotKeyConfig, model.HotKeyType.ToString(), null);
}
}
RemoveDuplicateHotKey(model);
model.UnRegisterHotKey();
model.RegisterHotKey();
}
};
}
}
/// <summary>
/// 移除重复的快捷键配置
/// </summary>
/// <param name="current"></param>
private void RemoveDuplicateHotKey(HotKeySettingModel current)
{
if (current.HotKey.IsEmpty)
{
return;
}
var list = GetAllNonDirectoryHotkey(HotKeySettingModels);
foreach (var hotKeySettingModel in list)
{
if (hotKeySettingModel.HotKey.IsEmpty)
{
continue;
}
if (hotKeySettingModel.ConfigPropertyName != current.ConfigPropertyName && hotKeySettingModel.HotKey == current.HotKey)
{
hotKeySettingModel.HotKey = HotKey.None;
}
}
}
public static List<HotKeySettingModel> GetAllNonDirectoryHotkey(IEnumerable<HotKeySettingModel> modelList)
{
var list = new List<HotKeySettingModel>();
foreach (var hotKeySettingModel in modelList)
{
if (!hotKeySettingModel.IsDirectory)
{
list.Add(hotKeySettingModel);
}
list.AddRange(GetAllNonDirectoryChildren(hotKeySettingModel));
}
return list;
}
public static List<HotKeySettingModel> GetAllNonDirectoryChildren(HotKeySettingModel model)
{
var result = new List<HotKeySettingModel>();
if (model.Children.Count == 0)
{
return result;
}
foreach (var child in model.Children)
{
if (!child.IsDirectory)
{
result.Add(child);
}
// 递归调用以获取子节点中的非目录对象
result.AddRange(GetAllNonDirectoryChildren(child));
}
return result;
}
private void BuildHotKeySettingModelList()
{
// 一级目录/快捷键
var bgiEnabledHotKeySettingModel = new HotKeySettingModel(
"启动停止 BetterGI",
nameof(Config.HotKeyConfig.BgiEnabledHotkey),
Config.HotKeyConfig.BgiEnabledHotkey,
Config.HotKeyConfig.BgiEnabledHotkeyType,
(_, _) => { WeakReferenceMessenger.Default.Send(new PropertyChangedMessage<object>(this, "SwitchTriggerStatus", "", "")); }
);
HotKeySettingModels.Add(bgiEnabledHotKeySettingModel);
var systemDirectory = new HotKeySettingModel(
"系统控制"
);
HotKeySettingModels.Add(systemDirectory);
var timerDirectory = new HotKeySettingModel(
"实时任务"
);
HotKeySettingModels.Add(timerDirectory);
var soloTaskDirectory = new HotKeySettingModel(
"独立任务"
);
HotKeySettingModels.Add(soloTaskDirectory);
var macroDirectory = new HotKeySettingModel(
"操控辅助"
);
HotKeySettingModels.Add(macroDirectory);
var devDirectory = new HotKeySettingModel(
"开发者"
);
HotKeySettingModels.Add(devDirectory);
// 二级快捷键
systemDirectory.Children.Add(new HotKeySettingModel(
"停止当前脚本/独立任务",
nameof(Config.HotKeyConfig.CancelTaskHotkey),
Config.HotKeyConfig.CancelTaskHotkey,
Config.HotKeyConfig.CancelTaskHotkeyType,
(_, _) => { CancellationContext.Instance.Cancel(); }
));
systemDirectory.Children.Add(new HotKeySettingModel(
"暂停当前脚本/独立任务",
nameof(Config.HotKeyConfig.SuspendHotkey),
Config.HotKeyConfig.SuspendHotkey,
Config.HotKeyConfig.SuspendHotkeyType,
(_, _) => { RunnerContext.Instance.IsSuspend = !RunnerContext.Instance.IsSuspend; }
));
var takeScreenshotHotKeySettingModel = new HotKeySettingModel(
"游戏截图",
nameof(Config.HotKeyConfig.TakeScreenshotHotkey),
Config.HotKeyConfig.TakeScreenshotHotkey,
Config.HotKeyConfig.TakeScreenshotHotkeyType,
(_, _) => { TaskTriggerDispatcher.Instance().TakeScreenshot(); }
);
systemDirectory.Children.Add(takeScreenshotHotKeySettingModel);
systemDirectory.Children.Add(new HotKeySettingModel(
"日志与状态窗口展示开关",
nameof(Config.HotKeyConfig.LogBoxDisplayHotkey),
Config.HotKeyConfig.LogBoxDisplayHotkey,
Config.HotKeyConfig.LogBoxDisplayHotkeyType,
(_, _) =>
{
TaskContext.Instance().Config.MaskWindowConfig.ShowLogBox = !TaskContext.Instance().Config.MaskWindowConfig.ShowLogBox;
// 与状态窗口同步
TaskContext.Instance().Config.MaskWindowConfig.ShowStatus = TaskContext.Instance().Config.MaskWindowConfig.ShowLogBox;
}
));
var autoPickEnabledHotKeySettingModel = new HotKeySettingModel(
"自动拾取开关",
nameof(Config.HotKeyConfig.AutoPickEnabledHotkey),
Config.HotKeyConfig.AutoPickEnabledHotkey,
Config.HotKeyConfig.AutoPickEnabledHotkeyType,
(_, _) =>
{
TaskContext.Instance().Config.AutoPickConfig.Enabled = !TaskContext.Instance().Config.AutoPickConfig.Enabled;
_logger.LogInformation("切换{Name}状态为[{Enabled}]", "自动拾取", ToChinese(TaskContext.Instance().Config.AutoPickConfig.Enabled));
}
);
timerDirectory.Children.Add(autoPickEnabledHotKeySettingModel);
var autoSkipEnabledHotKeySettingModel = new HotKeySettingModel(
"自动剧情开关",
nameof(Config.HotKeyConfig.AutoSkipEnabledHotkey),
Config.HotKeyConfig.AutoSkipEnabledHotkey,
Config.HotKeyConfig.AutoSkipEnabledHotkeyType,
(_, _) =>
{
TaskContext.Instance().Config.AutoSkipConfig.Enabled = !TaskContext.Instance().Config.AutoSkipConfig.Enabled;
_logger.LogInformation("切换{Name}状态为[{Enabled}]", "自动剧情", ToChinese(TaskContext.Instance().Config.AutoSkipConfig.Enabled));
}
);
timerDirectory.Children.Add(autoSkipEnabledHotKeySettingModel);
timerDirectory.Children.Add(new HotKeySettingModel(
"自动邀约开关",
nameof(Config.HotKeyConfig.AutoSkipHangoutEnabledHotkey),
Config.HotKeyConfig.AutoSkipHangoutEnabledHotkey,
Config.HotKeyConfig.AutoSkipHangoutEnabledHotkeyType,
(_, _) =>
{
TaskContext.Instance().Config.AutoSkipConfig.AutoHangoutEventEnabled = !TaskContext.Instance().Config.AutoSkipConfig.AutoHangoutEventEnabled;
_logger.LogInformation("切换{Name}状态为[{Enabled}]", "自动邀约", ToChinese(TaskContext.Instance().Config.AutoSkipConfig.AutoHangoutEventEnabled));
}
));
var autoFishingEnabledHotKeySettingModel = new HotKeySettingModel(
"自动钓鱼开关",
nameof(Config.HotKeyConfig.AutoFishingEnabledHotkey),
Config.HotKeyConfig.AutoFishingEnabledHotkey,
Config.HotKeyConfig.AutoFishingEnabledHotkeyType,
(_, _) =>
{
TaskContext.Instance().Config.AutoFishingConfig.Enabled = !TaskContext.Instance().Config.AutoFishingConfig.Enabled;
_logger.LogInformation("切换{Name}状态为[{Enabled}]", "自动钓鱼", ToChinese(TaskContext.Instance().Config.AutoFishingConfig.Enabled));
}
);
timerDirectory.Children.Add(autoFishingEnabledHotKeySettingModel);
var quickTeleportEnabledHotKeySettingModel = new HotKeySettingModel(
"快速传送开关",
nameof(Config.HotKeyConfig.QuickTeleportEnabledHotkey),
Config.HotKeyConfig.QuickTeleportEnabledHotkey,
Config.HotKeyConfig.QuickTeleportEnabledHotkeyType,
(_, _) =>
{
TaskContext.Instance().Config.QuickTeleportConfig.Enabled = !TaskContext.Instance().Config.QuickTeleportConfig.Enabled;
_logger.LogInformation("切换{Name}状态为[{Enabled}]", "快速传送", ToChinese(TaskContext.Instance().Config.QuickTeleportConfig.Enabled));
}
);
timerDirectory.Children.Add(quickTeleportEnabledHotKeySettingModel);
var quickTeleportTickHotKeySettingModel = new HotKeySettingModel(
"手动触发快速传送触发快捷键(按住起效)",
nameof(Config.HotKeyConfig.QuickTeleportTickHotkey),
Config.HotKeyConfig.QuickTeleportTickHotkey,
Config.HotKeyConfig.QuickTeleportTickHotkeyType,
(_, _) => { Thread.Sleep(100); },
true
);
timerDirectory.Children.Add(quickTeleportTickHotKeySettingModel);
var turnAroundHotKeySettingModel = new HotKeySettingModel(
"长按旋转视角 - 那维莱特转圈",
nameof(Config.HotKeyConfig.TurnAroundHotkey),
Config.HotKeyConfig.TurnAroundHotkey,
Config.HotKeyConfig.TurnAroundHotkeyType,
(_, _) => { TurnAroundMacro.Done(); },
true
);
macroDirectory.Children.Add(turnAroundHotKeySettingModel);
var enhanceArtifactHotKeySettingModel = new HotKeySettingModel(
"按下快速强化圣遗物",
nameof(Config.HotKeyConfig.EnhanceArtifactHotkey),
Config.HotKeyConfig.EnhanceArtifactHotkey,
Config.HotKeyConfig.EnhanceArtifactHotkeyType,
(_, _) => { QuickEnhanceArtifactMacro.Done(); },
true
);
macroDirectory.Children.Add(enhanceArtifactHotKeySettingModel);
macroDirectory.Children.Add(new HotKeySettingModel(
"按下快速购买商店物品",
nameof(Config.HotKeyConfig.QuickBuyHotkey),
Config.HotKeyConfig.QuickBuyHotkey,
Config.HotKeyConfig.QuickBuyHotkeyType,
(_, _) => { QuickBuyTask.Done(); },
true
));
macroDirectory.Children.Add(new HotKeySettingModel(
"按下快速进出尘歌壶",
nameof(Config.HotKeyConfig.QuickSereniteaPotHotkey),
Config.HotKeyConfig.QuickSereniteaPotHotkey,
Config.HotKeyConfig.QuickSereniteaPotHotkeyType,
(_, _) => { QuickSereniteaPotTask.Done(); }
));
soloTaskDirectory.Children.Add(new HotKeySettingModel(
"启动/停止自动七圣召唤",
nameof(Config.HotKeyConfig.AutoGeniusInvokationHotkey),
Config.HotKeyConfig.AutoGeniusInvokationHotkey,
Config.HotKeyConfig.AutoGeniusInvokationHotkeyType,
(_, _) => { SwitchSoloTask(_taskSettingsPageViewModel.SwitchAutoGeniusInvokationCommand); }
));
soloTaskDirectory.Children.Add(new HotKeySettingModel(
"启动/停止自动伐木",
nameof(Config.HotKeyConfig.AutoWoodHotkey),
Config.HotKeyConfig.AutoWoodHotkey,
Config.HotKeyConfig.AutoWoodHotkeyType,
(_, _) => { SwitchSoloTask(_taskSettingsPageViewModel.SwitchAutoWoodCommand); }
));
soloTaskDirectory.Children.Add(new HotKeySettingModel(
"启动/停止自动战斗",
nameof(Config.HotKeyConfig.AutoFightHotkey),
Config.HotKeyConfig.AutoFightHotkey,
Config.HotKeyConfig.AutoFightHotkeyType,
(_, _) => { SwitchSoloTask(_taskSettingsPageViewModel.SwitchAutoFightCommand); }
));
soloTaskDirectory.Children.Add(new HotKeySettingModel(
"启动/停止自动秘境",
nameof(Config.HotKeyConfig.AutoDomainHotkey),
Config.HotKeyConfig.AutoDomainHotkey,
Config.HotKeyConfig.AutoDomainHotkeyType,
(_, _) => { SwitchSoloTask(_taskSettingsPageViewModel.SwitchAutoDomainCommand); }
));
soloTaskDirectory.Children.Add(new HotKeySettingModel(
"启动/停止自动音游",
nameof(Config.HotKeyConfig.AutoMusicGameHotkey),
Config.HotKeyConfig.AutoMusicGameHotkey,
Config.HotKeyConfig.AutoMusicGameHotkeyType,
(_, _) => { SwitchSoloTask(_taskSettingsPageViewModel.SwitchAutoMusicGameCommand); }
));
macroDirectory.Children.Add(new HotKeySettingModel(
"快捷点击原神内确认按钮",
nameof(Config.HotKeyConfig.ClickGenshinConfirmButtonHotkey),
Config.HotKeyConfig.ClickGenshinConfirmButtonHotkey,
Config.HotKeyConfig.ClickGenshinConfirmButtonHotkeyType,
(_, _) =>
{
if (Bv.ClickConfirmButton(TaskControl.CaptureToRectArea()))
{
TaskControl.Logger.LogInformation("触发快捷点击原神内{Btn}按钮:成功", "确认");
}
else
{
TaskControl.Logger.LogInformation("触发快捷点击原神内{Btn}按钮:未找到按钮图片", "确认");
}
},
true
));
macroDirectory.Children.Add(new HotKeySettingModel(
"快捷点击原神内取消按钮",
nameof(Config.HotKeyConfig.ClickGenshinCancelButtonHotkey),
Config.HotKeyConfig.ClickGenshinCancelButtonHotkey,
Config.HotKeyConfig.ClickGenshinCancelButtonHotkeyType,
(_, _) =>
{
if (Bv.ClickCancelButton(TaskControl.CaptureToRectArea()))
{
TaskControl.Logger.LogInformation("触发快捷点击原神内{Btn}按钮:成功", "取消");
}
else
{
TaskControl.Logger.LogInformation("触发快捷点击原神内{Btn}按钮:未找到按钮图片", "取消");
}
},
true
));
macroDirectory.Children.Add(new HotKeySettingModel(
"一键战斗宏快捷键",
nameof(Config.HotKeyConfig.OneKeyFightHotkey),
Config.HotKeyConfig.OneKeyFightHotkey,
Config.HotKeyConfig.OneKeyFightHotkeyType,
null,
true)
{
OnKeyDownAction = (_, _) => { OneKeyFightTask.Instance.KeyDown(); },
OnKeyUpAction = (_, _) => { OneKeyFightTask.Instance.KeyUp(); }
});
devDirectory.Children.Add(new HotKeySettingModel(
"启动/停止键鼠录制",
nameof(Config.HotKeyConfig.KeyMouseMacroRecordHotkey),
Config.HotKeyConfig.KeyMouseMacroRecordHotkey,
Config.HotKeyConfig.KeyMouseMacroRecordHotkeyType, async (_, _) =>
{
var vm = App.GetService<KeyMouseRecordPageViewModel>();
if (vm == null)
{
_logger.LogError("无法找到 KeyMouseRecordPageViewModel 单例对象!");
return;
}
if (GlobalKeyMouseRecord.Instance.Status == KeyMouseRecorderStatus.Stop)
{
Thread.Sleep(300); // 防止录进快捷键进去
await vm.OnStartRecord();
}
else
{
vm.OnStopRecord();
}
}
));
devDirectory.Children.Add(new HotKeySettingModel(
"(开发)获取当前大地图中心点位置",
nameof(Config.HotKeyConfig.RecBigMapPosHotkey),
Config.HotKeyConfig.RecBigMapPosHotkey,
Config.HotKeyConfig.RecBigMapPosHotkeyType,
(_, _) =>
{
var p = new TpTask(new CancellationToken()).GetPositionFromBigMap();
_logger.LogInformation("大地图位置:{Position}", p);
}
));
var pathRecorder = PathRecorder.Instance;
var pathRecording = false;
devDirectory.Children.Add(new HotKeySettingModel(
"启动/停止路径记录器",
nameof(Config.HotKeyConfig.PathRecorderHotkey),
Config.HotKeyConfig.PathRecorderHotkey,
Config.HotKeyConfig.PathRecorderHotkeyType,
(_, _) =>
{
if (pathRecording)
{
pathRecorder.Save();
}
else
{
pathRecorder.Start();
}
pathRecording = !pathRecording;
}
));
devDirectory.Children.Add(new HotKeySettingModel(
"添加路径点",
nameof(Config.HotKeyConfig.AddWaypointHotkey),
Config.HotKeyConfig.AddWaypointHotkey,
Config.HotKeyConfig.AddWaypointHotkeyType,
(_, _) =>
{
if (pathRecording)
{
pathRecorder.AddWaypoint();
}
}
));
// DEBUG
if (RuntimeHelper.IsDebug)
{
var debugDirectory = new HotKeySettingModel(
"内部测试"
);
HotKeySettingModels.Add(debugDirectory);
// HotKeySettingModels.Add(new HotKeySettingModel(
// "(测试)启动/停止自动追踪",
// nameof(Config.HotKeyConfig.AutoTrackHotkey),
// Config.HotKeyConfig.AutoTrackHotkey,
// Config.HotKeyConfig.AutoTrackHotkeyType,
// (_, _) =>
// {
// // _taskSettingsPageViewModel.OnSwitchAutoTrack();
// }
// ));
// HotKeySettingModels.Add(new HotKeySettingModel(
// "(测试)地图路线录制",
// nameof(Config.HotKeyConfig.MapPosRecordHotkey),
// Config.HotKeyConfig.MapPosRecordHotkey,
// Config.HotKeyConfig.MapPosRecordHotkeyType,
// (_, _) =>
// {
// PathPointRecorder.Instance.Switch();
// }));
// HotKeySettingModels.Add(new HotKeySettingModel(
// "(测试)自动寻路",
// nameof(Config.HotKeyConfig.AutoTrackPathHotkey),
// Config.HotKeyConfig.AutoTrackPathHotkey,
// Config.HotKeyConfig.AutoTrackPathHotkeyType,
// (_, _) =>
// {
// // _taskSettingsPageViewModel.OnSwitchAutoTrackPath();
// }
// ));
debugDirectory.Children.Add(new HotKeySettingModel(
"(测试)测试",
nameof(Config.HotKeyConfig.Test1Hotkey),
Config.HotKeyConfig.Test1Hotkey,
Config.HotKeyConfig.Test1HotkeyType,
(_, _) =>
{
// var handler = new ElementalCollectHandler(ElementalType.Anemo);
// handler.RunAsync(new CancellationToken());
// var handler = new PickAroundHandler();
// handler.RunAsync(new CancellationToken());
// SwitchPartyTask switchPartyTask = new SwitchPartyTask();
// Task.Run(async () => { await switchPartyTask.Start("三保一", new CancellationToken()); });
//
// GoToAdventurersGuildTask goToAdventurersGuildTask = new GoToAdventurersGuildTask();
// Task.Run(async () => { await goToAdventurersGuildTask.Start("蒙德", new CancellationToken()); });
// ArtifactSalvageTask artifactSalvageTask = new ArtifactSalvageTask();
// Task.Run(async () => { await artifactSalvageTask.Start(4, new CancellationToken()); });
// 领取纪行奖励
// Task.Run(async () => { await new ClaimBattlePassRewardsTask().Start(new CancellationToken()); });
// 领取邮件奖励
// Task.Run(async () => { await new ClaimMailRewardsTask().Start(new CancellationToken()); });
// 拾取物品
// Task.Run(async () => { await new ScanPickTask().Start(new CancellationToken()); });
// Simulation.SendInput.Keyboard.KeyDown(false, User32.VK.VK_LMENU);
// // TaskContext.Instance().PostMessageSimulator.KeyDown(User32.VK.VK_MENU);
// Thread.Sleep(500);
// GameCaptureRegion.GameRegion1080PPosMove(200, 100);
// Thread.Sleep(500);
// // TaskContext.Instance().PostMessageSimulator.KeyUp(User32.VK.VK_MENU);
// Simulation.SendInput.Keyboard.KeyUp(false, User32.VK.VK_LMENU);
// TaskControl.Logger.LogInformation("大地图界面缩放按钮位置:{Position}", Bv.GetBigMapScale( TaskControl.CaptureToRectArea()));
// TaskControl.Logger.LogInformation($"尝试显示遮罩窗口");
// var maskWindow = MaskWindow.Instance();
// maskWindow.Invoke(() => { maskWindow.Show(); });
Task.Run(async () =>
{
for (int i = 0; i < 100; i++)
{
var imageRegion = TaskControl.CaptureToRectArea();
var eRa = imageRegion.DeriveCrop(AutoFightAssets.Instance.ECooldownRect);
var eRaWhite = OpenCvCommonHelper.InRangeHsv(eRa.SrcMat, new Scalar(0, 0, 235), new Scalar(0, 25, 255));
var text = OcrFactory.Paddle.OcrWithoutDetector(eRaWhite);
TaskControl.Logger.LogInformation("冷却时间 {Num}", StringUtils.TryParseDouble(text));
await Task.Delay(10);
}
});
}
));
debugDirectory.Children.Add(new HotKeySettingModel(
"测试测试2",
nameof(Config.HotKeyConfig.Test2Hotkey),
Config.HotKeyConfig.Test2Hotkey,
Config.HotKeyConfig.Test2HotkeyType,
(_, _) =>
{
SetTimeTask setTimeTask = new SetTimeTask();
Task.Run(async () => { await setTimeTask.Start(12, 05, new CancellationToken()); });
// var pName = SystemControl.GetActiveProcessName();
// Debug.WriteLine($"当前处于前台的程序:{pName},原神是否位于前台:{SystemControl.IsGenshinImpactActive()}");
// TaskControl.Logger.LogInformation($"当前处于前台的程序:{pName}");
}
));
debugDirectory.Children.Add(new HotKeySettingModel(
"(测试)播放内存中的路径",
nameof(Config.HotKeyConfig.ExecutePathHotkey),
Config.HotKeyConfig.ExecutePathHotkey,
Config.HotKeyConfig.ExecutePathHotkeyType,
(_, _) =>
{
// if (pathRecording)
// {
// new TaskRunner(DispatcherTimerOperationEnum.UseCacheImageWithTrigger)
// .FireAndForget(async () => await new PathExecutor(CancellationContext.Instance.Cts).Pathing(pathRecorder._pathingTask));
// }
}
));
}
}
private void SwitchSoloTask(IAsyncRelayCommand asyncRelayCommand)
{
if (asyncRelayCommand.IsRunning)
{
CancellationContext.Instance.Cancel();
}
else
{
asyncRelayCommand.Execute(null);
}
}
private string ToChinese(bool enabled)
{
return enabled.ToChinese();
}
}