mirror of
https://github.com/babalae/better-genshin-impact.git
synced 2026-05-09 00:34:14 +08:00
* 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>
106 lines
3.6 KiB
C#
106 lines
3.6 KiB
C#
using System;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using BetterGenshinImpact.Core.Simulator;
|
|
using BetterGenshinImpact.GameTask.Model.Area;
|
|
using BetterGenshinImpact.View.Drawable;
|
|
using Microsoft.Extensions.Logging;
|
|
using Vanara.PInvoke;
|
|
using static BetterGenshinImpact.GameTask.Common.TaskControl;
|
|
|
|
namespace BetterGenshinImpact.GameTask.Common.Job;
|
|
|
|
public class SetTimeTask
|
|
{
|
|
// 圆心坐标
|
|
private const double CenterX = 1441;
|
|
private const double CenterY = 501.6;
|
|
|
|
private readonly ReturnMainUiTask _returnMainUiTask = new();
|
|
|
|
public async Task Start(int hour, int minute, CancellationToken ct)
|
|
{
|
|
try
|
|
{
|
|
await _returnMainUiTask.Start(ct);
|
|
await DoOnce(hour, minute, ct);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Logger.LogDebug(e, "拾取周边物品异常");
|
|
Logger.LogError("拾取周边物品异常: {Msg}", e.Message);
|
|
}
|
|
finally
|
|
{
|
|
VisionContext.Instance().DrawContent.ClearAll();
|
|
}
|
|
}
|
|
|
|
public async Task DoOnce(int hour, int minute, CancellationToken ct)
|
|
{
|
|
// 半径
|
|
const int r1 = 30;
|
|
const int r2 = 150;
|
|
const int r3 = 300;
|
|
const int stepDuration = 50;
|
|
int h = (int)Math.Floor(hour + minute / 60.0);
|
|
int m = hour * 60 + minute - h * 60;
|
|
h = ((h % 24) + 24) % 24;
|
|
Logger.LogInformation($"设置时间到 {h} 点 {m} 分");
|
|
Simulation.SendInput.Keyboard.KeyPress(User32.VK.VK_ESCAPE);
|
|
await Delay(1000, ct);
|
|
GameCaptureRegion.GameRegion1080PPosClick(50, 700);
|
|
await Delay(2000, ct);
|
|
await SetTime(h, m, r1, r2, r3, stepDuration, ct);
|
|
await Delay(1000, ct);
|
|
GameCaptureRegion.GameRegion1080PPosClick(1500, 1000); // 确认
|
|
await Delay(18000, ct);
|
|
Simulation.SendInput.Keyboard.KeyPress(User32.VK.VK_ESCAPE);
|
|
await Delay(2000, ct);
|
|
Simulation.SendInput.Keyboard.KeyPress(User32.VK.VK_ESCAPE);
|
|
await Delay(2000, ct);
|
|
}
|
|
|
|
double[] GetPosition(double r, double index)
|
|
{
|
|
double angle = index * Math.PI / 720;
|
|
return [CenterX + r * Math.Cos(angle), CenterY + r * Math.Sin(angle)];
|
|
}
|
|
|
|
async Task MouseClick(double x, double y, int stepDuration, CancellationToken ct)
|
|
{
|
|
GameCaptureRegion.GameRegion1080PPosMove(x, y);
|
|
await Delay(50, ct);
|
|
Simulation.SendInput.Mouse.LeftButtonDown();
|
|
await Delay(50, ct);
|
|
Simulation.SendInput.Mouse.LeftButtonUp();
|
|
await Delay(stepDuration, ct);
|
|
}
|
|
|
|
async Task MouseClickAndMove(double x1, double y1, double x2, double y2, int stepDuration, CancellationToken ct)
|
|
{
|
|
GameCaptureRegion.GameRegion1080PPosMove(x1, y1);
|
|
await Delay(50, ct);
|
|
Simulation.SendInput.Mouse.LeftButtonDown();
|
|
await Delay(50, ct);
|
|
GameCaptureRegion.GameRegion1080PPosMove(x2, y2);
|
|
await Delay(50, ct);
|
|
Simulation.SendInput.Mouse.LeftButtonUp();
|
|
await Delay(stepDuration, ct);
|
|
}
|
|
|
|
async Task SetTime(int hour, int minute, int r1, int r2, int r3, int stepDuration, CancellationToken ct)
|
|
{
|
|
int end = (hour + 6) * 60 + minute - 20;
|
|
int n = 3;
|
|
for (int i = -n + 1; i < 1; i++)
|
|
{
|
|
double[] position = GetPosition(r1, end + i * 1440.0 / n);
|
|
await MouseClick(position[0], position[1], stepDuration, ct);
|
|
}
|
|
|
|
double[] position1 = GetPosition(r2, end + 5);
|
|
double[] position2 = GetPosition(r3, end + 20 + 0.5);
|
|
await MouseClickAndMove(position1[0], position1[1], position2[0], position2[1], stepDuration, ct);
|
|
}
|
|
} |