From 5597c0b354f881994a75878731c3a02183e9c970 Mon Sep 17 00:00:00 2001
From: asmrobot <asmrobot@hotmail.com>
Date: Wed, 16 Oct 2019 00:58:07 +0000
Subject: [PATCH] format project
---
src/RichCreator/Jobs/DNFJob.cs | 136 +++++++++++----------------------------------
1 files changed, 33 insertions(+), 103 deletions(-)
diff --git a/src/RichCreator/Jobs/DNFJob.cs b/src/RichCreator/Jobs/DNFJob.cs
index a952eda..4b0ca69 100644
--- a/src/RichCreator/Jobs/DNFJob.cs
+++ b/src/RichCreator/Jobs/DNFJob.cs
@@ -16,6 +16,7 @@
using System.Threading;
using System.Threading.Tasks;
using ZTImage.Configuration;
+using RichCreator.StateMachines;
namespace RichCreator.Jobs
{
@@ -51,19 +52,17 @@
private Int32 runningStep = 0;
- public override bool DoWork(out bool tryAgain,CancellationToken cancellationToken, Int32 runningStep)
+ public override ZTResult Do(CancellationToken cancellationToken, Int32 runningStep)
{
this.runningStep = runningStep;
- tryAgain = true;
RunningModel runningModel = ConfigHelper.GetInstance<RunningModel>();
RichCreatorConfig config = ConfigHelper.GetInstance<RichCreatorConfig>();
-
- bool result = false;
+
ZTRectangle startGameButtonRect = ZTRectangle.Empty;
if (runningStep <= RunningStep.SelectRole)
{
//查找游戏窗口
- result = FuncUtils.TimeoutCancelableWrap(config.StartWaitSecond * 1000, cancellationToken, () =>
+ bool result = FuncUtils.TimeoutCancelableWrap(config.StartWaitSecond * 1000, cancellationToken, () =>
{
return DnfCVHelper.IsSelectRoleWindow( out startGameButtonRect);
});
@@ -71,7 +70,7 @@
if (!result)
{
G.Instance.InfoWriter("启动DNF游戏失败");
- return false;
+ return ZTResult.Failed;
}
G.Instance.InfoWriter($"已进入DNF角色界面,{startGameButtonRect.ToString()}");
}
@@ -79,6 +78,7 @@
WindowUtils.GetDnfRect(out this.GameRect);
//循环刷所有角色
+ ZTResult playResult = ZTResult.Success;
Int32 roleIndex = runningModel.RoleIndex>0? runningModel.RoleIndex - 1:0;
for (; roleIndex < config.RoleCount; roleIndex++)
{
@@ -86,35 +86,23 @@
if (cancellationToken.IsCancellationRequested)
{
- return false;
+ return ZTResult.Cancel;
}
DateTime playOneRoleStartTime = DateTime.Now;
G.Instance.InfoWriter($"Play Role:{roleIndex+1}");
- if (!PlayRole(cancellationToken, roleIndex, startGameButtonRect))
+ playResult = PlayRole(cancellationToken, roleIndex, startGameButtonRect);
+ if (playResult != ZTResult.Success)
{
- G.Instance.InfoWriter("角色刷图失败");
- break;
+ G.Instance.InfoWriter($"角色刷图失败,第{roleIndex+1}个角色");
+ return playResult;
}
Int32 playOneRoleTotalSecond = (Int32)(DateTime.Now - playOneRoleStartTime).TotalSeconds;
G.Instance.InfoWriter($"角色刷图完成,用时:{(playOneRoleTotalSecond / 60)}分{(playOneRoleTotalSecond % 60)}秒");
}
-
- if (roleIndex < config.RoleCount)
- {
- string message = $"刷图失败,第{roleIndex+1}个角色";
- G.Instance.InfoWriter(message);
- return false;
- }
- //按ESC,点退出程序
- if (ExitGame(cancellationToken))
- {
- G.Instance.InfoWriter("退出游戏失败");
- return false;
- }
-
+
RunningModel.UpdateRoleIndex(1);
- return true;
+ return ZTResult.Success;
}
/// <summary>
@@ -123,10 +111,11 @@
/// <param name="cancellationToken"></param>
/// <param name="roleIndex"></param>
/// <returns></returns>
- private bool PlayRole(CancellationToken cancellationToken, Int32 roleIndex, ZTRectangle startGameButtonRect)
+ private ZTResult PlayRole(CancellationToken cancellationToken, Int32 roleIndex, ZTRectangle startGameButtonRect)
{
bool result = true;
Int32 pilaozhi = 1;
+ RichCreatorConfig config = ConfigHelper.GetInstance<RichCreatorConfig>();
if (this.runningStep < RunningStep.War)
{
//查找游戏窗口
@@ -138,7 +127,7 @@
if (!result)
{
G.Instance.InfoWriter("非角色选择界面");
- return false;
+ return ZTResult.Failed;
}
//进入赛丽亚的房间
@@ -146,49 +135,49 @@
if (!result)
{
G.Instance.InfoWriter("未进入赛丽亚的房间");
- return false;
+ return ZTResult.Failed;
}
G.Instance.InfoWriter("进入赛丽亚的房间");
- //关闭所有弹出窗
- result = CloseAllAlertWindow(cancellationToken, this.GameRect);
- if (!result)
+ //频道选择和网络断开重试
+ ChannelStateMachine csm = new ChannelStateMachine();
+ ZTResult workResult = csm.Work(this.GameRect, config.IsGroup, cancellationToken, 5 * 60 * 1000);
+ if (workResult != ZTResult.Success)
{
- G.Instance.InfoWriter("关闭所有窗口出现问题");
- return false;
+ G.Instance.InfoWriter("切换频道没有成功," + workResult);
+ Thread.Sleep(5 * 60 * 1000);
+ return workResult;
}
- G.Instance.InfoWriter("已关闭所有弹出窗");
-
+ G.Instance.InfoWriter("切换频道成功");
+
//查询疲劳值
pilaozhi = DnfCVHelper.GetPiLaoZhi(this.GameRect);
G.Instance.InfoWriter("疲劳值:" + pilaozhi);
}
- result = true;
+ ZTResult mapResult = ZTResult.Success;
if (pilaozhi > 0)
{
//刷图,并保持在可按esc退出的状态
MapInfo map = new T();
- result = map.Start(this.GameRect, cancellationToken,this.runningStep);
+ mapResult = map.Start(this.GameRect, cancellationToken,this.runningStep);
}
runningStep = RunningStep.None;
- if (result)
+ if (mapResult==ZTResult.Success)
{
//按ESC,退到选角色界面
if (ReturnToSelectRole(cancellationToken))
{
- return true;
+ return ZTResult.Success;
}
- return false;
+ return ZTResult.Failed;
}
- else
- {
- return false;
- }
+
+ return mapResult;
}
/// <summary>
@@ -296,64 +285,5 @@
G.Instance.InfoWriter("退回选择角色界面失败");
return false;
}
-
- /// <summary>
- /// 退出游戏
- /// </summary>
- /// <param name="cancelToken"></param>
- /// <param name="gameRect"></param>
- /// <returns></returns>
- private bool ExitGame(CancellationToken cancelToken)
- {
- //打开系统菜单
- int counter = 10;
- bool result = false;
-
- WindowUtils.SetDnfToTop();
- while (counter > 0)
- {
- G.Instance.InputControl.PressKey(RandomUtils.KeyPressDuration, HIDCode.Escape);
- bool findPanelResult = FuncUtils.TimeoutCancelableWrap(3000, cancelToken, () =>
- {
- return DnfCVHelper.IsOpenSystemPanel(this.GameRect);
- });
-
- if (findPanelResult)
- {
- result = true;
- break;
- }
- counter--;
- }
-
- if (result)
- {
- //点击退出游戏783,505
- G.Instance.InputControl.MoveToAndClick(new ZTPoint(this.GameRect.Start.X + 783, this.GameRect.Start.Y + 505));
- Thread.Sleep(1000);
-
- ZTRectangle exitOkButtonRect = ZTRectangle.Empty;
- bool findExitPanelResult = FuncUtils.TimeoutCancelableWrap(3000, cancelToken, () =>
- {
- return DnfCVHelper.FindExitPanelOkButton(out exitOkButtonRect, this.GameRect);
- });
-
- if (findExitPanelResult)
- {
- //remove,现在是按查找到的按钮位置来判断的,点击确定按钮 612 379
- //G.Instance.InputControl.MoveToAndClick(new ZTPoint(this.GameRect.Start.X + 612, this.GameRect.Start.Y + 379));
- G.Instance.InputControl.MoveToAndClick(exitOkButtonRect.GetCenterPoint());
- Thread.Sleep(6000);
- return true;
- }
- }
-
- return false;
- }
-
-
-
-
-
}
}
--
Gitblit v1.9.3