Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8a4f7c62e0 | ||
|
|
60eb3c0574 | ||
|
|
dec4d5ac7a |
No files matched your search
@@ -39,6 +39,8 @@ using System.Text.RegularExpressions;
|
||||
using BetterGenshinImpact.GameTask.AutoArtifactSalvage;
|
||||
using System.Collections.ObjectModel;
|
||||
using BetterGenshinImpact.Core.Script.Dependence;
|
||||
using BetterGenshinImpact.GameTask.AutoDomain.Model;
|
||||
using BetterGenshinImpact.GameTask.Common;
|
||||
using Compunet.YoloSharp;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
@@ -182,7 +184,7 @@ public class AutoDomainTask : ISoloTask
|
||||
|
||||
// 5. 快速领取奖励并判断是否有下一轮
|
||||
Logger.LogInformation("自动秘境:{Text}", "5. 领取奖励");
|
||||
if (!GettingTreasure(_taskParam.DomainRoundNum == 9999, i == _taskParam.DomainRoundNum - 1))
|
||||
if (!await GettingTreasure(i == _taskParam.DomainRoundNum - 1))
|
||||
{
|
||||
if (i == _taskParam.DomainRoundNum - 1)
|
||||
{
|
||||
@@ -997,7 +999,7 @@ public class AutoDomainTask : ISoloTask
|
||||
Simulation.SendInput.Mouse.MoveMouseBy(moveAngle, 0);
|
||||
}
|
||||
|
||||
Sleep(100);
|
||||
Sleep(100, _ct);
|
||||
}
|
||||
|
||||
Logger.LogInformation("锁定东方向视角线程结束");
|
||||
@@ -1008,64 +1010,51 @@ public class AutoDomainTask : ISoloTask
|
||||
/// <summary>
|
||||
/// 领取奖励
|
||||
/// </summary>
|
||||
/// <param name="recognizeResin">是否识别树脂</param>
|
||||
/// <param name="isLastTurn">是否最后一轮</param>
|
||||
private bool GettingTreasure(bool recognizeResin, bool isLastTurn)
|
||||
private async Task<bool> GettingTreasure(bool isLastTurn)
|
||||
{
|
||||
// 等待窗口弹出
|
||||
Sleep(1500, _ct);
|
||||
await Delay(300, _ct);
|
||||
|
||||
// 优先使用浓缩树脂
|
||||
var retryTimes = 0;
|
||||
while (true)
|
||||
// OCR 弹出框
|
||||
bool chooseResinPrompt = await NewRetry.WaitForAction(() =>
|
||||
{
|
||||
retryTimes++;
|
||||
if (retryTimes > 3)
|
||||
{
|
||||
Logger.LogInformation("没有浓缩树脂了");
|
||||
break;
|
||||
}
|
||||
using var ra = CaptureToRectArea();
|
||||
var regionList = ra.FindMulti(RecognitionObject.Ocr(ra.Width * 0.25, ra.Height * 0.2, ra.Width * 0.5, ra.Height * 0.6));
|
||||
return regionList.Any(t => t.Text.Contains("石化古树"));
|
||||
}, _ct, 10, 500);
|
||||
Debug.WriteLine("识别到选择树脂页");
|
||||
|
||||
var useCondensedResinRa = CaptureToRectArea().Find(AutoFightAssets.Instance.UseCondensedResinRa);
|
||||
if (!useCondensedResinRa.IsEmpty())
|
||||
{
|
||||
useCondensedResinRa.Click();
|
||||
// 点两下 #224 #218
|
||||
// 解决水龙王按下左键后没松开,然后后续点击按下就没反应了
|
||||
Sleep(400, _ct);
|
||||
useCondensedResinRa.Click();
|
||||
break;
|
||||
}
|
||||
|
||||
Sleep(800, _ct);
|
||||
if (!chooseResinPrompt)
|
||||
{
|
||||
throw new NormalEndException("未检测到选取树脂界面,可能是背包物品已满。");
|
||||
}
|
||||
|
||||
|
||||
await Delay(800, _ct);
|
||||
// 弹出框
|
||||
using var ra2 = CaptureToRectArea();
|
||||
// 识别树脂状况
|
||||
var resinStatus = ResinStatus.RecogniseFromRegion(ra2);
|
||||
resinStatus.Print(Logger);
|
||||
|
||||
if (resinStatus.CondensedResinCount > 0)
|
||||
{
|
||||
PressUseResin(ra2, "浓缩树脂");
|
||||
resinStatus.CondensedResinCount -= 1;
|
||||
}
|
||||
else if (resinStatus.OriginalResinCount >= 20)
|
||||
{
|
||||
PressUseResin(ra2, "原粹树脂");
|
||||
resinStatus.OriginalResinCount -= 20;
|
||||
}
|
||||
|
||||
|
||||
Sleep(1000, _ct);
|
||||
|
||||
var hasSkip = false;
|
||||
var captureArea = TaskContext.Instance().SystemInfo.ScaleMax1080PCaptureRect;
|
||||
var assetScale = TaskContext.Instance().SystemInfo.AssetScale;
|
||||
for (var i = 0; i < 30; i++)
|
||||
{
|
||||
// 跳过领取动画
|
||||
if (!hasSkip)
|
||||
{
|
||||
TaskContext.Instance().PostMessageSimulator.LeftButtonClick(); // 先随便点一个地方使得跳过出现
|
||||
}
|
||||
|
||||
using var ra = CaptureToRectArea();
|
||||
|
||||
// OCR识别是否有跳过
|
||||
var ocrList = ra.FindMulti(RecognitionObject.Ocr(captureArea.Width - 230 * assetScale, 0,
|
||||
230 * assetScale - 5, 80 * assetScale));
|
||||
var skipTextRa = ocrList.FirstOrDefault(t => Regex.IsMatch(t.Text, this.skipLocalizedString));
|
||||
if (skipTextRa != null)
|
||||
{
|
||||
hasSkip = true;
|
||||
skipTextRa.Click(); // 有则点击
|
||||
}
|
||||
|
||||
|
||||
// 优先点击继续
|
||||
using var confirmRectArea = ra.Find(AutoFightAssets.Instance.ConfirmRa);
|
||||
if (!confirmRectArea.IsEmpty())
|
||||
@@ -1081,14 +1070,7 @@ public class AutoDomainTask : ISoloTask
|
||||
}
|
||||
}
|
||||
|
||||
if (!recognizeResin)
|
||||
{
|
||||
confirmRectArea.Click();
|
||||
return true;
|
||||
}
|
||||
|
||||
var (condensedResinCount, fragileResinCount) = GetRemainResinStatus();
|
||||
if (condensedResinCount == 0 && fragileResinCount < 20)
|
||||
if (resinStatus.CondensedResinCount <= 0 && resinStatus.OriginalResinCount < 20)
|
||||
{
|
||||
// 没有体力了退出
|
||||
var exitRectArea = ra.Find(AutoFightAssets.Instance.ExitRa);
|
||||
@@ -1112,6 +1094,50 @@ public class AutoDomainTask : ISoloTask
|
||||
throw new NormalEndException("未检测到秘境结束,可能是背包物品已满。");
|
||||
}
|
||||
|
||||
private void PressUseResin(ImageRegion ra, string resinName)
|
||||
{
|
||||
var regionList = ra.FindMulti(RecognitionObject.Ocr(ra.Width * 0.25, ra.Height * 0.2, ra.Width * 0.5, ra.Height * 0.6));
|
||||
var resinKey = regionList.FirstOrDefault(t => t.Text.Contains(resinName));
|
||||
if (resinKey != null)
|
||||
{
|
||||
// 找到树脂名称对应的按键,关键词为使用,是同一行的(高度相交)
|
||||
var useList = regionList.Where(t => t.Text.Contains("使用")).ToList();
|
||||
if (useList.Count != 0)
|
||||
{
|
||||
// 找到使用按键
|
||||
var useKey = useList.FirstOrDefault(t => t.X > ra.Width / 2 && IsHeightOverlap(t, resinKey));
|
||||
if (useKey != null)
|
||||
{
|
||||
// 点击使用
|
||||
useKey.Click();
|
||||
Logger.LogInformation("自动秘境:使用 {ResinName}", resinName);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.LogWarning("自动秘境:未找到 {ResinName} 的使用按键", resinName);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.LogWarning("自动秘境:未找到 {ResinName} 的使用按键", resinName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 判断两个区域在垂直方向上是否有重叠
|
||||
/// </summary>
|
||||
private bool IsHeightOverlap(Region region1, Region region2)
|
||||
{
|
||||
int region1Top = region1.Y;
|
||||
int region1Bottom = region1.Y + region1.Height;
|
||||
int region2Top = region2.Y;
|
||||
int region2Bottom = region2.Y + region2.Height;
|
||||
|
||||
// 检查区域是否在垂直方向上重叠
|
||||
return (region1Top <= region2Bottom && region1Bottom >= region2Top);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取剩余树脂状态
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using BetterGenshinImpact.Core.Recognition.OCR;
|
||||
using BetterGenshinImpact.GameTask.AutoFight.Assets;
|
||||
using BetterGenshinImpact.GameTask.Model.Area;
|
||||
using BetterGenshinImpact.Helpers;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using OpenCvSharp;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.AutoDomain.Model;
|
||||
|
||||
public class ResinStatus
|
||||
{
|
||||
/// <summary>
|
||||
/// 原粹树脂(1自回体)
|
||||
/// </summary>
|
||||
public int OriginalResinCount { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 脆弱树脂(60)
|
||||
/// </summary>
|
||||
public int FragileResinCount { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 浓缩树脂(40)
|
||||
/// </summary>
|
||||
public int CondensedResinCount { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 须臾树脂(60壶内购买)
|
||||
/// </summary>
|
||||
public int TransientResinCount { get; set; } = 0;
|
||||
|
||||
public static ResinStatus RecogniseFromRegion(ImageRegion region)
|
||||
{
|
||||
var status = new ResinStatus();
|
||||
|
||||
// 1. 原粹树脂 起点 w-(256+100) ~ w-256
|
||||
var captureArea = TaskContext.Instance().SystemInfo.ScaleMax1080PCaptureRect;
|
||||
var assetScale = TaskContext.Instance().SystemInfo.AssetScale;
|
||||
var originalResinTopIconRa = AutoFightAssets.Instance.OriginalResinTopIconRa;
|
||||
originalResinTopIconRa.RegionOfInterest = new Rect(captureArea.Width - (int)(356 * assetScale), (int)(37 * assetScale), (int)(100 * assetScale), (int)(21 * assetScale));
|
||||
var originalResinRes = region.Find(originalResinTopIconRa);
|
||||
if (originalResinRes.IsEmpty())
|
||||
{
|
||||
throw new Exception("未找到原粹树脂图标");
|
||||
}
|
||||
|
||||
// 找出 icon 的位置 + 30 ~ w-267 就是原粹树脂的数字
|
||||
var originalResinCountRect = new Rect(originalResinRes.X + 30, originalResinTopIconRa.RegionOfInterest.Y,
|
||||
captureArea.Width - (originalResinRes.X + 30) - (int)(267 * assetScale), originalResinTopIconRa.RegionOfInterest.Height);
|
||||
string cnt1 = OcrFactory.Paddle.OcrWithoutDetector(region.DeriveCrop(originalResinCountRect).SrcMat);
|
||||
status.OriginalResinCount = StringUtils.TryExtractPositiveInt(cnt1, 0);
|
||||
|
||||
// 2. 浓缩树脂
|
||||
var condensedResinRes = region.Find(AutoFightAssets.Instance.CondensedResinTopIconRa);
|
||||
if (condensedResinRes.IsExist())
|
||||
{
|
||||
// 找出 icon 的位置 + 25 ~ icon 的位置+45 就是浓缩树脂的数字,数字宽20
|
||||
var condensedResinCountRect = new Rect(condensedResinRes.Right + (int)(25 * assetScale), condensedResinRes.Y, (int)(20 * assetScale), condensedResinRes.Height);
|
||||
string cnt40 = OcrFactory.Paddle.OcrWithoutDetector(region.DeriveCrop(condensedResinCountRect).SrcMat);
|
||||
status.CondensedResinCount = StringUtils.TryExtractPositiveInt(cnt40, 0);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
public void Print(ILogger logger)
|
||||
{
|
||||
// logger.LogInformation("原粹树脂:{Cnt1},浓缩树脂:{Cnt2},须臾树脂:{Cnt3},脆弱树脂:{Cnt4}",
|
||||
// OriginalResinCount, CondensedResinCount, FragileResinCount, TransientResinCount);
|
||||
logger.LogInformation("原粹树脂:{Cnt1},浓缩树脂:{Cnt2}",
|
||||
OriginalResinCount, CondensedResinCount);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.0 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 456 B |
@@ -26,8 +26,11 @@ public class AutoFightAssets : BaseAssets<AutoFightAssets>
|
||||
|
||||
// 树脂状态
|
||||
public RecognitionObject CondensedResinCountRa;
|
||||
|
||||
public RecognitionObject FragileResinCountRa;
|
||||
// 自动秘境
|
||||
// public RecognitionObject LockIconRa; // 锁定辅助图标
|
||||
public RecognitionObject CondensedResinTopIconRa;
|
||||
public RecognitionObject OriginalResinTopIconRa;
|
||||
|
||||
public Dictionary<string, string> AvatarCostumeMap;
|
||||
|
||||
@@ -245,5 +248,31 @@ public class AutoFightAssets : BaseAssets<AutoFightAssets>
|
||||
RegionOfInterest = new Rect(CaptureRect.Width / 2, CaptureRect.Height / 3 * 2, CaptureRect.Width / 2, CaptureRect.Height / 3),
|
||||
DrawOnWindow = false
|
||||
}.InitTemplate();
|
||||
|
||||
// 自动秘境
|
||||
// LockIconRa = new RecognitionObject
|
||||
// {
|
||||
// Name = "LockIcon",
|
||||
// RecognitionType = RecognitionTypes.TemplateMatch,
|
||||
// TemplateImageMat = GameTaskManager.LoadAssetImage("AutoFight", "lock_icon.png"),
|
||||
// RegionOfInterest = new Rect(CaptureRect.Width - (int)(215 * AssetScale), 0, (int)(215 * AssetScale), (int)(80 * AssetScale)),
|
||||
// DrawOnWindow = false
|
||||
// }.InitTemplate();
|
||||
CondensedResinTopIconRa = new RecognitionObject
|
||||
{
|
||||
Name = "CondensedResinTopIcon",
|
||||
RecognitionType = RecognitionTypes.TemplateMatch,
|
||||
TemplateImageMat = GameTaskManager.LoadAssetImage("AutoFight", "condensed_resin_top_icon.png"),
|
||||
RegionOfInterest = new Rect((int)(1270 * AssetScale), (int)(25 * AssetScale), (int)(520 * AssetScale), (int)(45 * AssetScale)),
|
||||
DrawOnWindow = false
|
||||
}.InitTemplate();
|
||||
OriginalResinTopIconRa = new RecognitionObject
|
||||
{
|
||||
Name = "OriginalResinTopIcon",
|
||||
RecognitionType = RecognitionTypes.TemplateMatch,
|
||||
TemplateImageMat = GameTaskManager.LoadAssetImage("AutoFight", "original_resin_top_icon.png"),
|
||||
RegionOfInterest = new Rect(0, (int)(37 * AssetScale), CaptureRect.Width, (int)(21 * AssetScale)),
|
||||
DrawOnWindow = false
|
||||
}.InitTemplate();
|
||||
}
|
||||
}
|
||||
@@ -88,21 +88,21 @@ public partial class StringUtils
|
||||
return int.TryParse(text, out int result) ? result : defaultValue;
|
||||
}
|
||||
|
||||
public static int TryExtractPositiveInt(string text)
|
||||
public static int TryExtractPositiveInt(string text, int defaultValue = -1)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text))
|
||||
{
|
||||
return -1;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
text = RegexHelper.ExcludeNumberRegex().Replace(text, "");
|
||||
return int.Parse(text);
|
||||
return TryParseInt(text, defaultValue);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return -1;
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ public partial class ScriptRepoWindow
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Toast.Error($"更新失败: {ex.Message}");
|
||||
Toast.Error($"更新失败,可尝试重置仓库后重新更新。失败原因:: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user