auto fish: support Sumeru and Fontaine fish

This commit is contained in:
huiyadanli
2024-02-14 19:07:17 +08:00
parent 9d6d621b75
commit bd366503cf
10 changed files with 79 additions and 85 deletions

View File

@@ -1,24 +0,0 @@
[
"abiding angelfish",
"aizen medaka",
"akai maou",
"betta",
"bitter pufferfish",
"brown shirakodai",
"crystalfish",
"dawncatcher",
"glaze medaka",
"golden koi",
"lunged stickleback",
"medaka",
"moonfin",
"pufferfish",
"purple shirakodai",
"raimei angelfish",
"rusty koi",
"snowstrider",
"sweet-flower medaka",
"target",
"tea-colored shirakodai",
"venomspine fish"
]

View File

@@ -93,9 +93,6 @@
<None Update="Assets\Model\Fish\bgi_fish.onnx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Assets\Model\Fish\label.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Assets\Model\PaddleOCR\ch_PP-OCRv4_det\inference.pdiparams">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
@@ -168,6 +165,15 @@
<None Update="GameTask\AutoFight\Assets\combat_avatar.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="GameTask\AutoFishing\Assets\1920x1080\bait\flashing maintenance mek bait.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="GameTask\AutoFishing\Assets\1920x1080\bait\sour bait.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="GameTask\AutoFishing\Assets\1920x1080\bait\sugardew bait.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="GameTask\AutoFishing\Assets\1920x1080\lift_rod.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>

View File

@@ -5,7 +5,7 @@ namespace BetterGenshinImpact.Core.Config;
public class Global
{
public static string Version { get; } = "0.24.2";
public static string Version { get; } = "0.24.3";
public static string StartUpPath { get; private set; } = AppContext.BaseDirectory;

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

View File

@@ -86,6 +86,7 @@ namespace BetterGenshinImpact.GameTask.AutoFishing
{
return;
}
_prevExecute = DateTime.Now;
// 进入独占模式判断
@@ -104,6 +105,7 @@ namespace BetterGenshinImpact.GameTask.AutoFishing
{
return;
}
_prevExecute = DateTime.Now;
_fishBoxRect = GetFishBoxArea(content.CaptureRectArea.SrcMat);
@@ -164,7 +166,7 @@ namespace BetterGenshinImpact.GameTask.AutoFishing
_logger.LogInformation("→ {Text}", "自动钓鱼,启动!");
// 点击下面的按钮
var rc = info.CaptureAreaRect;
Simulation.SendInput
Simulation.SendInputEx
.Mouse
.MoveMouseTo(
(rc.X + srcMat.Width * 1d / 2 + rect.X + rect.Width * 1d / 2) * 65535 / info.DesktopRectArea.Width,
@@ -274,18 +276,18 @@ namespace BetterGenshinImpact.GameTask.AutoFishing
// 往左移动是正数,往右移动是负数
if (fishpond.FishpondRect.Left > centerX)
{
Simulation.SendInput.Mouse.MoveMouseBy(100, 0);
Simulation.SendInputEx.Mouse.MoveMouseBy(100, 0);
}
if (fishpond.FishpondRect.Right < centerX)
{
Simulation.SendInput.Mouse.MoveMouseBy(-100, 0);
Simulation.SendInputEx.Mouse.MoveMouseBy(-100, 0);
}
// 鱼塘尽量在上半屏幕
if (fishpond.FishpondRect.Bottom > centerY)
{
Simulation.SendInput.Mouse.MoveMouseBy(0, -100);
Simulation.SendInputEx.Mouse.MoveMouseBy(0, -100);
}
if ((fishpond.FishpondRect.Left < centerX && fishpond.FishpondRect.Right > centerX) || fishpond.FishpondRect.Width < content.SrcBitmap.Width / 4)
@@ -325,7 +327,7 @@ namespace BetterGenshinImpact.GameTask.AutoFishing
// 30s 没有上钩,重新抛竿
if (_throwRodWaitFrameNum >= content.FrameRate * TaskContext.Instance().Config.AutoFishingConfig.AutoThrowRodTimeOut)
{
Simulation.SendInput.Mouse.LeftButtonClick();
Simulation.SendInputEx.Mouse.LeftButtonClick();
_throwRodWaitFrameNum = 0;
_waitBiteContinuouslyFrameNum = 0;
Debug.WriteLine("超时自动收竿");
@@ -369,7 +371,9 @@ namespace BetterGenshinImpact.GameTask.AutoFishing
private string ChooseBait(CaptureContent content, Fishpond fishpond)
{
// 打开换饵界面
Simulation.SendInput.Mouse.RightButtonClick();
Simulation.SendInputEx.Mouse.RightButtonClick();
Sleep(100);
Simulation.SendInputEx.Mouse.MoveMouseBy(0, 200); // 鼠标移走,防止干扰
Sleep(500);
// 截图
@@ -378,12 +382,12 @@ namespace BetterGenshinImpact.GameTask.AutoFishing
_logger.LogInformation("选择鱼饵 {Text}", BaitType.FromName(_selectedBaitName).ChineseName);
// 寻找鱼饵
var ro = new RecognitionObject()
var ro = new RecognitionObject
{
Name = "ChooseBait",
RecognitionType = RecognitionTypes.TemplateMatch,
TemplateImageMat = GameTaskManager.LoadAssetImage("AutoFishing", $"bait\\{_selectedBaitName}.png"),
Threshold = 0.9,
Threshold = 0.8,
Use3Channels = true,
DrawOnWindow = false
}.InitTemplate();
@@ -400,7 +404,7 @@ namespace BetterGenshinImpact.GameTask.AutoFishing
else
{
resRa.ClickCenter();
Sleep(500);
Sleep(700);
// 可能重复点击,所以固定界面点击下
var rect = systemInfo.CaptureAreaRect;
ClickExtension.Click(rect.X + 1300 * systemInfo.AssetScale, rect.Y + 400 * systemInfo.AssetScale);
@@ -423,7 +427,7 @@ namespace BetterGenshinImpact.GameTask.AutoFishing
private void ApproachFishAndThrowRod(CaptureContent content)
{
// 预抛竿
Simulation.SendInput.Mouse.LeftButtonDown();
Simulation.SendInputEx.Mouse.LeftButtonDown();
_logger.LogInformation("长按预抛竿");
Sleep(3000);
@@ -446,29 +450,29 @@ namespace BetterGenshinImpact.GameTask.AutoFishing
{
noPlacementTimes++;
Sleep(50);
Debug.WriteLine("历次未找到鱼饵落点,随机移动");
Debug.WriteLine("历次未找到鱼饵落点");
var cX = content.SrcBitmap.Width / 2;
var cY = content.SrcBitmap.Height / 2;
var rdX = _rd.Next(0, content.SrcBitmap.Width);
var rdY = _rd.Next(0, content.SrcBitmap.Height);
var moveX = 100 * (cX - rdX) / content.SrcBitmap.Width;
var moveY = 100 * (cY - rdY) / content.SrcBitmap.Height;
Simulation.SendInput.Mouse.MoveMouseBy(moveX, moveY);
Simulation.SendInputEx.Mouse.MoveMouseBy(moveX, moveY);
if (noPlacementTimes > 50)
{
_logger.LogInformation("未找到鱼饵落点,大概率是长按失败,直接抛竿收杆重试");
Simulation.SendInput.Mouse.LeftButtonUp().Sleep(200).LeftButtonDown().Sleep(200).LeftButtonUp();
Sleep(2000);
Simulation.SendInput.Mouse.LeftButtonClick();
_selectedBaitName = string.Empty;
_isThrowRod = false;
Sleep(2000);
MoveViewpointDown();
Sleep(300);
_logger.LogInformation("未找到鱼饵落点,重试");
// Simulation.SendInputEx.Mouse.LeftButtonUp();
// // Sleep(2000);
// // Simulation.SendInputEx.Mouse.LeftButtonClick();
// _selectedBaitName = string.Empty;
// _isThrowRod = false;
// // Sleep(2000);
// // MoveViewpointDown();
// Sleep(300);
break;
}
@@ -501,17 +505,17 @@ namespace BetterGenshinImpact.GameTask.AutoFishing
noTargetFishTimes++;
//if (noTargetFishTimes == 30)
//{
// Simulation.SendInput.Mouse.MoveMouseBy(0, 100);
// Simulation.SendInputEx.Mouse.MoveMouseBy(0, 100);
//}
if (noTargetFishTimes > 80)
if (noTargetFishTimes > 70)
{
// 没有找到目标鱼,重新选择鱼饵
_logger.LogInformation("没有找到目标鱼1.直接抛竿");
Simulation.SendInput.Mouse.LeftButtonUp();
Simulation.SendInputEx.Mouse.LeftButtonUp();
Sleep(1500);
_logger.LogInformation("没有找到目标鱼2.收杆");
Simulation.SendInput.Mouse.LeftButtonClick();
Simulation.SendInputEx.Mouse.LeftButtonClick();
Sleep(1500);
_logger.LogInformation("没有找到目标鱼3.准备重新选择鱼饵");
_selectedBaitName = string.Empty;
@@ -530,11 +534,11 @@ namespace BetterGenshinImpact.GameTask.AutoFishing
VisionContext.Instance().DrawContent.PutRect("Target", fishpond.TargetRect.ToRectDrawable());
VisionContext.Instance().DrawContent.PutRect("Fish", currentFish.Rect.ToRectDrawable());
// 因为视角是斜着看向鱼的所以Y轴抛竿距离要近一点
if ((_selectedBaitName != "fruit paste bait" && min is { Item1: <= 50, Item2: <= 25 })
if ((_selectedBaitName != "fruit paste bait" && min is { Item1: <= 50, Item2: <= 25 })
|| _selectedBaitName == "fruit paste bait" && min is { Item1: <= 40, Item2: <= 25 })
{
Sleep(100);
Simulation.SendInput.Mouse.LeftButtonUp();
Simulation.SendInputEx.Mouse.LeftButtonUp();
_logger.LogInformation("尝试钓取 {Text}", currentFish.FishType.ChineseName);
_isThrowRod = true;
VisionContext.Instance().DrawContent.RemoveRect("Target");
@@ -555,9 +559,9 @@ namespace BetterGenshinImpact.GameTask.AutoFishing
if (TaskContext.Instance().Config.AutoFishingConfig.AutoThrowRodEnabled)
{
// 下移视角方便看鱼
Simulation.SendInput.Mouse.MoveMouseBy(0, 300);
Simulation.SendInputEx.Mouse.MoveMouseBy(0, 400);
Sleep(500);
Simulation.SendInput.Mouse.MoveMouseBy(0, 400);
Simulation.SendInputEx.Mouse.MoveMouseBy(0, 500);
Sleep(500);
}
}
@@ -587,14 +591,14 @@ namespace BetterGenshinImpact.GameTask.AutoFishing
{
moveY = 50;
}
if (c1.Y > c2.Y)
{
moveY = -moveY;
}
//_logger.LogInformation("移动鼠标 {X} {Y}", 0, moveY);
Simulation.SendInput.Mouse.MoveMouseBy(0, moveY);
Simulation.SendInputEx.Mouse.MoveMouseBy(0, moveY);
return (0, minDistance);
}
@@ -614,7 +618,7 @@ namespace BetterGenshinImpact.GameTask.AutoFishing
}
//_logger.LogInformation("移动鼠标 {X} {Y}", moveX, 0);
Simulation.SendInput.Mouse.MoveMouseBy(moveX, 0);
Simulation.SendInputEx.Mouse.MoveMouseBy(moveX, 0);
return (minDistance, 0);
}
@@ -635,6 +639,7 @@ namespace BetterGenshinImpact.GameTask.AutoFishing
{
moveY = 50;
}
if (c1.Y > c2.Y)
{
moveY = -moveY;
@@ -646,7 +651,7 @@ namespace BetterGenshinImpact.GameTask.AutoFishing
}
//_logger.LogInformation("移动鼠标 {X} {Y}", moveX, moveY);
Simulation.SendInput.Mouse.MoveMouseBy(moveX, moveY);
Simulation.SendInputEx.Mouse.MoveMouseBy(moveX, moveY);
return (dpX, dpY);
}
@@ -677,6 +682,7 @@ namespace BetterGenshinImpact.GameTask.AutoFishing
_logger.LogWarning("截图失败!");
throw new Exception("截图失败");
}
// 更新当前捕获内容
_currContent = new CaptureContent(bitmap, _currContent.FrameIndex, _currContent.TimerInterval, _currContent.Dispatcher);
return bitmap;
@@ -728,7 +734,7 @@ namespace BetterGenshinImpact.GameTask.AutoFishing
if (_left.X < _cur.X // cur 是游标位置, 在初始状态下cur 一定在left左边
|| _cur.Width > _left.Width // left一定比cur宽
|| _cur.X + _cur.Width > srcMat.Width / 2 // cur 一定在屏幕左侧
|| _cur.X + _cur.Width > _left.X - _left.Width/2 // cur 一定在left左侧+left的一半宽度
|| _cur.X + _cur.Width > _left.X - _left.Width / 2 // cur 一定在left左侧+left的一半宽度
|| _cur.X + _cur.Width > srcMat.Width / 2 - _left.Width // cur 一定在屏幕中轴线减去整个left的宽度的位置左侧
|| !(_left.X < srcMat.Width / 2 && _left.X + _left.Width > srcMat.Width / 2) // left肯定穿过游戏中轴线
)
@@ -800,7 +806,7 @@ namespace BetterGenshinImpact.GameTask.AutoFishing
var liftRodButtonRa = content.CaptureRectArea.Find(_autoFishingAssets.LiftRodButtonRo);
if (!liftRodButtonRa.IsEmpty())
{
Simulation.SendInput.Mouse.LeftButtonClick();
Simulation.SendInputEx.Mouse.LeftButtonClick();
_logger.LogInformation(@"┌------------------------┐");
_logger.LogInformation(" 自动提竿(图像识别)");
_isFishingProcess = true;
@@ -811,13 +817,13 @@ namespace BetterGenshinImpact.GameTask.AutoFishing
}
// OCR 提竿判断
var text = _ocrService.Ocr(new Mat(content.CaptureRectArea.SrcGreyMat,
new Rect(currentBiteWordsTips.X+ liftingWordsAreaRect.X,
currentBiteWordsTips.Y+liftingWordsAreaRect.Y,
var text = _ocrService.Ocr(new Mat(content.CaptureRectArea.SrcGreyMat,
new Rect(currentBiteWordsTips.X + liftingWordsAreaRect.X,
currentBiteWordsTips.Y + liftingWordsAreaRect.Y,
currentBiteWordsTips.Width, currentBiteWordsTips.Height)));
if (!string.IsNullOrEmpty(text) && StringUtils.RemoveAllSpace(text).Contains("上钩"))
{
Simulation.SendInput.Mouse.LeftButtonClick();
Simulation.SendInputEx.Mouse.LeftButtonClick();
_logger.LogInformation(@"┌------------------------┐");
_logger.LogInformation(" 自动提竿(OCR)");
_isFishingProcess = true;
@@ -836,7 +842,7 @@ namespace BetterGenshinImpact.GameTask.AutoFishing
if (_biteTipsExitCount >= content.FrameRate / 2d)
{
Simulation.SendInput.Mouse.LeftButtonClick();
Simulation.SendInputEx.Mouse.LeftButtonClick();
_logger.LogInformation(@"┌------------------------┐");
_logger.LogInformation(" 自动提竿(文字块)");
_isFishingProcess = true;
@@ -862,7 +868,7 @@ namespace BetterGenshinImpact.GameTask.AutoFishing
/// <param name="fishBarMat"></param>
private void Fishing(CaptureContent content, Mat fishBarMat)
{
var simulator = Simulation.SendInput;
var simulator = Simulation.SendInputEx;
var rects = AutoFishingImageRecognition.GetFishBarRect(fishBarMat);
if (rects != null && rects.Count > 0)
{
@@ -964,10 +970,8 @@ namespace BetterGenshinImpact.GameTask.AutoFishing
_logger.LogInformation(" 钓鱼结束");
_logger.LogInformation(@"└------------------------┘");
if (_prevMouseEvent == MOUSEEVENTF.MOUSEEVENTF_LEFTDOWN)
{
simulator.Mouse.LeftButtonUp();
}
// 保证鼠标松开
simulator.Mouse.LeftButtonUp();
Sleep(1000);
@@ -1010,10 +1014,10 @@ namespace BetterGenshinImpact.GameTask.AutoFishing
_logger.LogInformation("→ {Text}", "自动钓鱼,启动!");
var autoThrowRodEnabled = TaskContext.Instance().Config.AutoFishingConfig.AutoThrowRodEnabled;
_logger.LogInformation("当前自动选饵抛竿状态[{Enabled}]", autoThrowRodEnabled.ToChinese());
if (autoThrowRodEnabled)
{
_logger.LogInformation("枫丹、须弥地区暂不支持自动抛竿,如果在这两个地区钓鱼请关闭自动抛竿功能");
}
// if (autoThrowRodEnabled)
// {
// _logger.LogInformation("枫丹、须弥地区暂不支持自动抛竿,如果在这两个地区钓鱼请关闭自动抛竿功能");
// }
_switchBaitContinuouslyFrameNum = 0;
_waitBiteContinuouslyFrameNum = 0;
_noFishActionContinuouslyFrameNum = 0;

View File

@@ -27,7 +27,7 @@ public class FishType
public static readonly FishType DivdaRay = new("divda ray", "fake fly bait", "迪芙妲鳐");
public static readonly FishType FormaloRay = new("formalo ray", "fake fly bait", "佛玛洛鳐");
public static readonly FishType GoldenKoi = new("golden koi", "fake fly bait", "金赤假龙");
public static readonly FishType Pufferfish = new("pufferfish", "fake fly bait", "炮鲀2");
public static readonly FishType Pufferfish = new("pufferfish", "fake fly bait", "炮鲀");
public static readonly FishType RustyKoi = new("rusty koi", "fake fly bait", "锖假龙");
public static readonly FishType HalcyonJadeAxeMarlin = new("halcyon jade axe marlin", "sugardew bait", "翡玉斧枪鱼");
public static readonly FishType LazuriteAxeMarlin = new("lazurite axe marlin", "sugardew bait", "青金斧枪鱼");
@@ -38,10 +38,12 @@ public class FishType
public static readonly FishType TrueFruitAngler = new("true fruit angler", "sugardew bait", "真果角鲀");
public static readonly FishType BlazingHeartfeatherBass = new("blazing heartfeather bass", "sour bait", "烘烘心羽鲈");
public static readonly FishType RipplingHeartfeatherBass = new("rippling heartfeather bass", "sour bait", "波波心羽鲈");
public static readonly FishType MaintenanceMekInitialConfiguration = new("maintenance mek: initial configuration", "flashing maintenance mek bait", "维护机关·初始能力型");
public static readonly FishType MaintenanceMekPlatinumCollection = new("maintenance mek: platinum collection", "flashing maintenance mek bait", "维护机关·白金典藏型");
public static readonly FishType MaintenanceMekSituationController = new("maintenance mek: situation controller", "flashing maintenance mek bait", "维护机关·态势控制者");
public static readonly FishType MaintenanceMekWaterBodyCleaner = new("maintenance mek: water body cleaner", "flashing maintenance mek bait", "维护机关·水域清理者");
public static readonly FishType MaintenanceMekInitialConfiguration = new("maintenance mek- initial configuration", "flashing maintenance mek bait", "维护机关·初始能力型");
public static readonly FishType MaintenanceMekPlatinumCollection = new("maintenance mek- platinum collection", "flashing maintenance mek bait", "维护机关·白金典藏型");
public static readonly FishType MaintenanceMekSituationController = new("maintenance mek- situation controller", "flashing maintenance mek bait", "维护机关·态势控制者");
public static readonly FishType MaintenanceMekWaterBodyCleaner = new("maintenance mek- water body cleaner", "flashing maintenance mek bait", "维护机关·水域清理者");
public static readonly FishType MaintenanceMekWaterGoldLeader = new ("maintenance mek- gold leader", "flashing maintenance mek bait", "维护机关·澄金领队型");
public static IEnumerable<FishType> Values
{
@@ -82,6 +84,7 @@ public class FishType
yield return MaintenanceMekPlatinumCollection;
yield return MaintenanceMekSituationController;
yield return MaintenanceMekWaterBodyCleaner;
yield return MaintenanceMekWaterGoldLeader;
}
}

View File

@@ -38,6 +38,11 @@ public class Fishpond
TargetRect = new Rect(box.Bounds.X, box.Bounds.Y, box.Bounds.Width, box.Bounds.Height);
continue;
}
else if (box.Class.Name == "target-error")
{
TargetRect = new Rect(box.Bounds.X, box.Bounds.Y, box.Bounds.Width, box.Bounds.Height);
continue;
}
var fish = new OneFish(box.Class.Name, new Rect(box.Bounds.X, box.Bounds.Y, box.Bounds.Width, box.Bounds.Height));
Fishes.Add(fish);