mirror of
https://github.com/babalae/better-genshin-impact.git
synced 2026-04-16 21:09:22 +08:00
* 修改调度器任务和部分独立任务失去焦点时,强制切换回游戏窗口,如果用常规的方式无法激活窗口,则第10次会尝试最小化所有窗口后激活游戏。 * 去除未引入的类引用 * 修正战斗结束后,大概率打开队伍界面的问题 * 修复有些电脑上因未知原因,战斗0秒打断 * 把失焦激活放入了设置-通用设置-其他设置中,默认关闭。暂停恢复时,重置移动的起始时间,防止因暂停而导致超时放弃任务。 * 在调度器里面的任务之前,增加月卡处理,解决4点如果未进入任务会卡住的问题。增加了日志分析小怪详细。解决日志分析兜底结束日期不生效的问题。 * 在设置=》其他设置中 增加调度器任务传送过程中自动领取探索奖励功能配置。 * 调整自动派遣后恢复原任务的逻辑 * 自动领取派遣奖励时,跳过异常,防止整个配置组任务被打断。 * 把打开大地图方法从TpTask中抽出为公共方法,自动领取派遣代码调整到了调度器中。 * 去除了未使用的引用 * 暂停恢复逻辑增加恢复中条件和非空判断 * 增加了临时暂停自动拾取的逻辑(RunnerContext.AutoPickTriggerStopCount 为0时不限制,大于0时停止,多次暂停会累加该值,每次恢复-1),支持嵌套情况的暂停,在自动派遣(和结束后5秒)或暂停调度器任务时,同时暂停自动拾取功能。 * 调整暂停拾取方法 * 调整个日志输出 * 路径追踪复苏时,暂停拾取
180 lines
6.6 KiB
C#
180 lines
6.6 KiB
C#
using BetterGenshinImpact.Core.Config;
|
|
using BetterGenshinImpact.GameTask.AutoPathing;
|
|
using BetterGenshinImpact.GameTask.AutoPathing.Model;
|
|
using BetterGenshinImpact.GameTask.AutoSkip.Assets;
|
|
using BetterGenshinImpact.GameTask.AutoSkip;
|
|
using BetterGenshinImpact.GameTask.Common.BgiVision;
|
|
using Microsoft.Extensions.Logging;
|
|
using System;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using BetterGenshinImpact.Core.Simulator;
|
|
using BetterGenshinImpact.GameTask.AutoPick.Assets;
|
|
using BetterGenshinImpact.GameTask.Common.Element.Assets;
|
|
using Vanara.PInvoke;
|
|
using static BetterGenshinImpact.GameTask.Common.TaskControl;
|
|
using Microsoft.Extensions.Localization;
|
|
using BetterGenshinImpact.Helpers;
|
|
using System.Globalization;
|
|
|
|
namespace BetterGenshinImpact.GameTask.Common.Job;
|
|
|
|
public class GoToAdventurersGuildTask
|
|
{
|
|
public string Name => "前往冒险家协会领取奖励";
|
|
|
|
private readonly int _retryTimes = 1;
|
|
|
|
private readonly ChooseTalkOptionTask _chooseTalkOptionTask = new();
|
|
|
|
private readonly string dailyLocalizedString;
|
|
private readonly string catherineLocalizedString;
|
|
private readonly string expeditionLocalizedString;
|
|
|
|
public GoToAdventurersGuildTask()
|
|
{
|
|
IStringLocalizer<GoToAdventurersGuildTask> stringLocalizer = App.GetService<IStringLocalizer<GoToAdventurersGuildTask>>() ?? throw new NullReferenceException();
|
|
CultureInfo cultureInfo = new CultureInfo(TaskContext.Instance().Config.OtherConfig.GameCultureInfoName);
|
|
this.dailyLocalizedString = stringLocalizer.WithCultureGet(cultureInfo, "每日");
|
|
this.catherineLocalizedString = stringLocalizer.WithCultureGet(cultureInfo, "凯瑟琳");
|
|
this.expeditionLocalizedString = stringLocalizer.WithCultureGet(cultureInfo, "探索");
|
|
}
|
|
|
|
public async Task Start(string country, CancellationToken ct, string? dailyRewardPartyName = null ,bool onlyDoOnce = false)
|
|
{
|
|
Logger.LogInformation("→ {Name} 开始", Name);
|
|
for (int i = 0; i < _retryTimes; i++)
|
|
{
|
|
try
|
|
{
|
|
// 如果有好感队伍名称,先切换到好感队伍
|
|
if (!string.IsNullOrEmpty(dailyRewardPartyName))
|
|
{
|
|
await new SwitchPartyTask().Start(dailyRewardPartyName, ct);
|
|
}
|
|
|
|
if (!onlyDoOnce)
|
|
{
|
|
// F1领取奖励
|
|
await new ClaimEncounterPointsRewardsTask().Start(ct);
|
|
}
|
|
|
|
await DoOnce(country, ct);
|
|
break;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Logger.LogError("前往冒险家协会领取奖励执行异常:" + e.Message);
|
|
if (i == _retryTimes - 1)
|
|
{
|
|
// 通知失败
|
|
throw;
|
|
}
|
|
else
|
|
{
|
|
await Delay(1000, ct);
|
|
Logger.LogInformation("重试前往冒险家协会领取奖励");
|
|
}
|
|
}
|
|
}
|
|
|
|
Logger.LogInformation("→ {Name} 结束", Name);
|
|
}
|
|
|
|
public async Task DoOnce(string country, CancellationToken ct)
|
|
{
|
|
// 1. 走到冒险家协会并对话
|
|
await GoToAdventurersGuild(country, ct);
|
|
|
|
// 每日
|
|
var res = await _chooseTalkOptionTask.SingleSelectText(this.dailyLocalizedString, ct, 10, true);
|
|
if (res == TalkOptionRes.FoundAndClick)
|
|
{
|
|
Logger.LogInformation("▶ {Text}", "领取『每日委托』奖励!");
|
|
await Delay(500, ct);
|
|
await _chooseTalkOptionTask.SelectLastOptionUntilEnd(ct, null, 3); // 点几下
|
|
await Bv.WaitUntilFound(ElementAssets.Instance.PaimonMenuRo, ct);
|
|
await Delay(500, ct);
|
|
TaskContext.Instance().PostMessageSimulator.KeyPress(User32.VK.VK_ESCAPE);
|
|
await new ReturnMainUiTask().Start(ct);
|
|
|
|
// 结束后重新打开
|
|
await Delay(1200, ct);
|
|
var ra = CaptureToRectArea();
|
|
if (!Bv.FindFAndPress(ra, text: this.catherineLocalizedString))
|
|
{
|
|
throw new Exception("未找与凯瑟琳对话交互按钮");
|
|
}
|
|
}
|
|
else if (res == TalkOptionRes.FoundButNotOrange)
|
|
{
|
|
Logger.LogInformation("▶ {Text} 未完成或者已领取", "领取『每日委托』奖励");
|
|
}
|
|
else
|
|
{
|
|
Logger.LogWarning("▶ 未找到 {Text} 选项", "领取『每日委托』奖励");
|
|
}
|
|
|
|
// 探索
|
|
res = await _chooseTalkOptionTask.SingleSelectText(this.expeditionLocalizedString, ct, 10, true);
|
|
if (res == TalkOptionRes.FoundAndClick)
|
|
{
|
|
await Delay(500, ct);
|
|
new OneKeyExpeditionTask().Run(AutoSkipAssets.Instance);
|
|
}
|
|
else if (res == TalkOptionRes.FoundButNotOrange)
|
|
{
|
|
Logger.LogInformation("▶ {Text} 未探索完成或已领取", "探索派遣");
|
|
}
|
|
else
|
|
{
|
|
Logger.LogWarning("▶ 未找到 {Text} 选项", "探索派遣");
|
|
}
|
|
|
|
// 如果最后还在对话界面,选择最后一个选项退出
|
|
if (Bv.IsInTalkUi(CaptureToRectArea()))
|
|
{
|
|
await _chooseTalkOptionTask.SelectLastOptionUntilEnd(ct);
|
|
Logger.LogInformation("退出当前对话");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 前往冒险家协会
|
|
/// </summary>
|
|
/// <param name="country"></param>
|
|
/// <param name="ct"></param>
|
|
/// <returns></returns>
|
|
public async Task GoToAdventurersGuild(string country, CancellationToken ct)
|
|
{
|
|
var task = PathingTask.BuildFromFilePath(Global.Absolute(@$"GameTask\Common\Element\Assets\Json\冒险家协会_{country}.json"));
|
|
var pathingTask = new PathExecutor(ct)
|
|
{
|
|
PartyConfig = new PathingPartyConfig
|
|
{
|
|
Enabled = true,
|
|
AutoSkipEnabled = true
|
|
},
|
|
EndAction = region => Bv.FindFAndPress(region, text: this.catherineLocalizedString)
|
|
};
|
|
await pathingTask.Pathing(task);
|
|
|
|
await Delay(600, ct);
|
|
|
|
const int retryTalkTimes = 3;
|
|
for (int i = 0; i < retryTalkTimes; i++)
|
|
{
|
|
using var ra = CaptureToRectArea();
|
|
if (!Bv.IsInTalkUi(ra))
|
|
{
|
|
Simulation.SendInput.Keyboard.KeyPress(AutoPickAssets.Instance.PickVk);
|
|
await Delay(500, ct);
|
|
|
|
if (i == retryTalkTimes - 1)
|
|
{
|
|
throw new Exception("与凯瑟琳对话失败");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |