mirror of
https://github.com/babalae/better-genshin-impact.git
synced 2026-05-17 09:26:50 +08:00
auto expedition: ui
This commit is contained in:
@@ -5,7 +5,7 @@ namespace BetterGenshinImpact.Core.Config;
|
||||
|
||||
public class Global
|
||||
{
|
||||
public static string Version = "0.12.0";
|
||||
public static string Version = "0.13.0";
|
||||
|
||||
public static string StartUpPath { get; private set; } = AppContext.BaseDirectory;
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ public class AutoSkipAssets
|
||||
RecognitionType = RecognitionTypes.TemplateMatch,
|
||||
TemplateImageMat = GameTaskManager.LoadAssetImage("AutoSkip", "icon_daily_reward.png"),
|
||||
RegionOfInterest = new Rect(info.CaptureAreaRect.Width / 2, 0, info.CaptureAreaRect.Width - info.CaptureAreaRect.Width / 2, info.CaptureAreaRect.Height),
|
||||
DrawOnWindow = true
|
||||
DrawOnWindow = false
|
||||
}.InitTemplate();
|
||||
ExploreIconRo = new RecognitionObject
|
||||
{
|
||||
@@ -58,7 +58,7 @@ public class AutoSkipAssets
|
||||
RecognitionType = RecognitionTypes.TemplateMatch,
|
||||
TemplateImageMat = GameTaskManager.LoadAssetImage("AutoSkip", "icon_explore.png"),
|
||||
RegionOfInterest = new Rect(info.CaptureAreaRect.Width / 2, 0, info.CaptureAreaRect.Width - info.CaptureAreaRect.Width / 2, info.CaptureAreaRect.Height),
|
||||
DrawOnWindow = true
|
||||
DrawOnWindow = false
|
||||
}.InitTemplate();
|
||||
|
||||
MenuRo = new RecognitionObject
|
||||
|
||||
@@ -30,5 +30,16 @@ namespace BetterGenshinImpact.GameTask.AutoSkip
|
||||
public int ChatOptionTextWidth { get; set; }= 280;
|
||||
|
||||
public int ExpeditionOptionTextWidth { get; set; } = 130;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 自动领取每日委托奖励
|
||||
/// </summary>
|
||||
[ObservableProperty] private bool _autoGetDailyRewardsEnabled = true;
|
||||
|
||||
/// <summary>
|
||||
/// 自动重新派遣
|
||||
/// </summary>
|
||||
[ObservableProperty] private bool _autoReExploreEnabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,51 +64,57 @@ public class AutoSkipTrigger : ITaskTrigger
|
||||
}
|
||||
|
||||
// 领取每日委托奖励
|
||||
var dailyRewardIconRa = content.CaptureRectArea.Find(_autoSkipAssets.DailyRewardIconRo);
|
||||
if (!dailyRewardIconRa.IsEmpty())
|
||||
if (config.AutoGetDailyRewardsEnabled)
|
||||
{
|
||||
var text = GetOrangeOptionText(content.CaptureRectArea.SrcMat, dailyRewardIconRa, (int)(config.ChatOptionTextWidth * assetScale));
|
||||
|
||||
if (text.Contains("每日委托"))
|
||||
var dailyRewardIconRa = content.CaptureRectArea.Find(_autoSkipAssets.DailyRewardIconRo);
|
||||
if (!dailyRewardIconRa.IsEmpty())
|
||||
{
|
||||
if (Math.Abs(content.FrameIndex - _prevOtherClickFrameIndex) >= 8)
|
||||
var text = GetOrangeOptionText(content.CaptureRectArea.SrcMat, dailyRewardIconRa, (int)(config.ChatOptionTextWidth * assetScale));
|
||||
|
||||
if (text.Contains("每日委托"))
|
||||
{
|
||||
_logger.LogInformation("自动选择:{Text}", text);
|
||||
if (Math.Abs(content.FrameIndex - _prevOtherClickFrameIndex) >= 8)
|
||||
{
|
||||
_logger.LogInformation("自动选择:{Text}", text);
|
||||
}
|
||||
|
||||
dailyRewardIconRa.ClickCenter();
|
||||
dailyRewardIconRa.Dispose();
|
||||
return;
|
||||
}
|
||||
|
||||
dailyRewardIconRa.ClickCenter();
|
||||
_prevOtherClickFrameIndex = content.FrameIndex;
|
||||
dailyRewardIconRa.Dispose();
|
||||
return;
|
||||
}
|
||||
|
||||
_prevOtherClickFrameIndex = content.FrameIndex;
|
||||
dailyRewardIconRa.Dispose();
|
||||
}
|
||||
|
||||
// 领取探索派遣奖励
|
||||
var exploreIconRa = content.CaptureRectArea.Find(_autoSkipAssets.ExploreIconRo);
|
||||
if (!exploreIconRa.IsEmpty())
|
||||
if (config.AutoReExploreEnabled)
|
||||
{
|
||||
var text = GetOrangeOptionText(content.CaptureRectArea.SrcMat, exploreIconRa, (int)(config.ExpeditionOptionTextWidth * assetScale));
|
||||
if (text.Contains("探索派遣"))
|
||||
var exploreIconRa = content.CaptureRectArea.Find(_autoSkipAssets.ExploreIconRo);
|
||||
if (!exploreIconRa.IsEmpty())
|
||||
{
|
||||
if (Math.Abs(content.FrameIndex - _prevOtherClickFrameIndex) >= 8)
|
||||
var text = GetOrangeOptionText(content.CaptureRectArea.SrcMat, exploreIconRa, (int)(config.ExpeditionOptionTextWidth * assetScale));
|
||||
if (text.Contains("探索派遣"))
|
||||
{
|
||||
_logger.LogInformation("自动选择:{Text}", text);
|
||||
if (Math.Abs(content.FrameIndex - _prevOtherClickFrameIndex) >= 8)
|
||||
{
|
||||
_logger.LogInformation("自动选择:{Text}", text);
|
||||
}
|
||||
|
||||
exploreIconRa.ClickCenter();
|
||||
|
||||
// 等待探索派遣界面打开
|
||||
Thread.Sleep(1000);
|
||||
new ExpeditionTask().Run(content);
|
||||
exploreIconRa.Dispose();
|
||||
return;
|
||||
}
|
||||
|
||||
exploreIconRa.ClickCenter();
|
||||
|
||||
// 等待探索派遣界面打开
|
||||
Thread.Sleep(1000);
|
||||
new ExpeditionTask().Run(content);
|
||||
_prevOtherClickFrameIndex = content.FrameIndex;
|
||||
exploreIconRa.Dispose();
|
||||
return;
|
||||
}
|
||||
|
||||
_prevOtherClickFrameIndex = content.FrameIndex;
|
||||
exploreIconRa.Dispose();
|
||||
return;
|
||||
}
|
||||
|
||||
// 找右下的对话选项按钮
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace BetterGenshinImpact.GameTask.AutoSkip;
|
||||
/// </summary>
|
||||
public class ExpeditionTask
|
||||
{
|
||||
private static readonly List<string> ExpeditionCharacterList = new() { "菲谢尔", "班尼特" };
|
||||
private static readonly List<string> ExpeditionCharacterList = new() { "菲谢尔", "班尼特", "夜兰", "申鹤", "久岐忍" };
|
||||
|
||||
//private static readonly List<string> GameAreaNames = new() { "蒙德", "璃月", "稻妻", "须弥", "枫丹" };
|
||||
|
||||
@@ -50,7 +50,7 @@ public class ExpeditionTask
|
||||
}
|
||||
else
|
||||
{
|
||||
TaskControl.Sleep(500);
|
||||
TaskControl.Sleep(800);
|
||||
content.CaptureRectArea
|
||||
.Derive(new Rect((int)(110 * assetScale), (int)((145 + 70 * i) * assetScale),
|
||||
(int)(60 * assetScale), (int)(33 * assetScale)))
|
||||
@@ -58,7 +58,7 @@ public class ExpeditionTask
|
||||
ReExplorationGameArea(content);
|
||||
}
|
||||
}
|
||||
|
||||
TaskControl.Logger.LogInformation("探索派遣:{Text}", "重新派遣完成");
|
||||
VisionContext.Instance().DrawContent.ClearAll();
|
||||
}
|
||||
|
||||
@@ -71,10 +71,12 @@ public class ExpeditionTask
|
||||
{
|
||||
var result = CaptureAndOcr(content, new Rect(0, 0, captureRect.Width - (int)(480 * assetScale), captureRect.Height));
|
||||
var rect = result.FindRectByText("探险完成");
|
||||
// TODO i>1 的时候,可以通过关键词“探索派遣限制 4 / 5 ”判断是否已经派遣完成?
|
||||
if (rect != Rect.Empty)
|
||||
{
|
||||
// 点击探险完成
|
||||
// 点击探险完成下方的人物头像
|
||||
content.CaptureRectArea.Derive(new Rect(rect.X, rect.Y + (int)(50 * assetScale), rect.Width, (int)(80 * assetScale))).ClickCenter();
|
||||
TaskControl.Sleep(500);
|
||||
// 重新截图 找领取
|
||||
result = CaptureAndOcr(content);
|
||||
rect = result.FindRectByText("领取");
|
||||
@@ -116,13 +118,18 @@ public class ExpeditionTask
|
||||
|
||||
private bool SelectCharacter(CaptureContent content)
|
||||
{
|
||||
var result = CaptureAndOcr(content);
|
||||
var captureRect = TaskContext.Instance().SystemInfo.CaptureAreaRect;
|
||||
var result = CaptureAndOcr(content, new Rect(0, 0, captureRect.Width / 2, captureRect.Height));
|
||||
if (result.RegionHasText("角色选择"))
|
||||
{
|
||||
var cards = GetCharacterCards(result);
|
||||
if (cards.Count > 0)
|
||||
{
|
||||
var card = cards.First(c => c.Idle);
|
||||
var card = cards.FirstOrDefault(c => c.Idle && c.Name != null && ExpeditionCharacterList.Contains(c.Name));
|
||||
if (card == null)
|
||||
{
|
||||
card = cards.First(c => c.Idle);
|
||||
}
|
||||
var rect = card.Rects.First();
|
||||
|
||||
using var ra = content.CaptureRectArea.Derive(rect);
|
||||
@@ -163,7 +170,7 @@ public class ExpeditionTask
|
||||
foreach (var ocrResultRect2 in ocrResultRects)
|
||||
{
|
||||
if (ocrResultRect2.Rect.Y > ocrResultRect.Rect.Y - 50 * assetScale
|
||||
&& ocrResultRect2.Rect.Y + ocrResultRect2.Rect.Height > ocrResultRect.Rect.Y)
|
||||
&& ocrResultRect2.Rect.Y + ocrResultRect2.Rect.Height < ocrResultRect.Rect.Y + ocrResultRect.Rect.Height)
|
||||
{
|
||||
if (ocrResultRect2.Text.Contains("探险完成"))
|
||||
{
|
||||
@@ -174,16 +181,23 @@ public class ExpeditionTask
|
||||
card.Name = name;
|
||||
}
|
||||
}
|
||||
else
|
||||
else if (!ocrResultRect2.Text.Contains("时间缩短") && !ocrResultRect2.Text.Contains("奖励增加") && !ocrResultRect2.Text.Contains("暂无加成"))
|
||||
{
|
||||
card.Name = ocrResultRect2.Text;
|
||||
}
|
||||
|
||||
card.Rects.Add(ocrResultRect.Rect);
|
||||
card.Rects.Add(ocrResultRect2.Rect);
|
||||
}
|
||||
}
|
||||
|
||||
cards.Add(card);
|
||||
if (!string.IsNullOrEmpty(card.Name))
|
||||
{
|
||||
cards.Add(card);
|
||||
}
|
||||
else
|
||||
{
|
||||
TaskControl.Logger.LogWarning("探索派遣:存在未找到角色命的识别内容");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,7 +212,7 @@ public class ExpeditionTask
|
||||
using var mat = bitmap.ToMat();
|
||||
Cv2.CvtColor(mat, mat, ColorConversionCodes.BGR2GRAY);
|
||||
var result = OcrFactory.Paddle.OcrResult(mat);
|
||||
VisionContext.Instance().DrawContent.PutOrRemoveRectList("OcrResultRects", result.ToRectDrawableList());
|
||||
//VisionContext.Instance().DrawContent.PutOrRemoveRectList("OcrResultRects", result.ToRectDrawableList());
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -209,7 +223,7 @@ public class ExpeditionTask
|
||||
using var mat = new Mat(bitmap.ToMat(), rect);
|
||||
Cv2.CvtColor(mat, mat, ColorConversionCodes.BGR2GRAY);
|
||||
var result = OcrFactory.Paddle.OcrResult(mat);
|
||||
VisionContext.Instance().DrawContent.PutOrRemoveRectList("OcrResultRects", result.ToRectDrawableList(_pen));
|
||||
//VisionContext.Instance().DrawContent.PutOrRemoveRectList("OcrResultRects", result.ToRectDrawableList(_pen));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -200,6 +200,62 @@
|
||||
Margin="0,0,36,0"
|
||||
IsChecked="{Binding Config.AutoSkipConfig.QuicklySkipConversationsEnabled, Mode=TwoWay}" />
|
||||
</Grid>
|
||||
<Grid Margin="16">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<ui:TextBlock
|
||||
Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
FontTypography="Body"
|
||||
TextWrapping="Wrap"
|
||||
Text="凯瑟琳 - 自动领取『每日委托』奖励" />
|
||||
<ui:TextBlock
|
||||
Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
TextWrapping="Wrap"
|
||||
Text="在与凯瑟琳对话时,会自动“领取『每日委托』奖励" />
|
||||
<ui:ToggleSwitch
|
||||
Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="1"
|
||||
Margin="0,0,36,0"
|
||||
IsChecked="{Binding Config.AutoSkipConfig.AutoGetDailyRewardsEnabled, Mode=TwoWay}" />
|
||||
</Grid>
|
||||
<Grid Margin="16">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<ui:TextBlock
|
||||
Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
FontTypography="Body"
|
||||
TextWrapping="Wrap"
|
||||
Text="凯瑟琳 - 自动重新派遣(不稳定...)" />
|
||||
<ui:TextBlock
|
||||
Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
TextWrapping="Wrap"
|
||||
Text="自动领取已完成探索的奖励,并按照配置进行重新派遣" />
|
||||
<ui:ToggleSwitch
|
||||
Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="1"
|
||||
Margin="0,0,36,0"
|
||||
IsChecked="{Binding Config.AutoSkipConfig.AutoReExploreEnabled, Mode=TwoWay}" />
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</ui:CardExpander>
|
||||
|
||||
|
||||
@@ -146,7 +146,7 @@ public partial class HomePageViewModel : ObservableObject, INavigationAware
|
||||
[RelayCommand]
|
||||
private void OnTest()
|
||||
{
|
||||
var result = OcrFactory.Paddle.OcrResult(new Mat("E:\\HuiTask\\更好的原神\\自动派遣\\Clip_20231030_235235.png", ImreadModes.Grayscale));
|
||||
var result = OcrFactory.Paddle.OcrResult(new Mat(@"E:\HuiTask\更好的原神\七圣召唤\Clip_20231105_143729.png", ImreadModes.Grayscale));
|
||||
foreach (var region in result.Regions)
|
||||
{
|
||||
Debug.WriteLine($"{region.Text}");
|
||||
|
||||
Reference in New Issue
Block a user