using RichCreator.Utility;
|
using RichCreator.Utility.Captures;
|
using RichCreator.Utility.CV;
|
using RichCreator.Utility.InputControl;
|
using RichCreator.Utility.Structs;
|
using RichCreator.Utility.Utilitys;
|
using Emgu.CV;
|
using Emgu.CV.Structure;
|
using RichCreator.Jobs;
|
using RichCreator.Jobs.StateMachines;
|
using System;
|
using System.Collections.Generic;
|
using System.Threading;
|
using static RichCreator.Utility.CV.GroupCVHelper;
|
using RichCreator.StateMachines;
|
using RichCreator.Utility.Maps;
|
using RichCreator.Dnf;
|
|
namespace RichCreator.Maps.Test
|
{
|
/// <summary>
|
/// 测试地图
|
/// </summary>
|
public class TestMap : MapInfo
|
{
|
public TestMap(ZTRectangle gameRect, CancellationToken cancelToken) :base(MapType.Test, gameRect, cancelToken)
|
{
|
|
}
|
|
private const bool isCreateGroup = true;
|
|
public override ZTResult Start(Int32 runningStep)
|
{WindowUtils.SetDnfToTop();
|
|
|
|
|
string groupName = "aabbccddee";
|
if (isCreateGroup)
|
{
|
//创建队伍
|
if (!CreateGroup(groupName))
|
{
|
G.Instance.InfoWriter("创建队伍失败");
|
return ZTResult.Failed;
|
}
|
}
|
else
|
{
|
//加入队伍
|
if (!JoinGroup(groupName))
|
{
|
G.Instance.InfoWriter("加入队伍失败");
|
return ZTResult.Failed;
|
}
|
}
|
//沉默一段时间
|
Thread.Sleep(50000000);
|
CloseAllAlertWindow(this.CancelToken, this.GameRect);
|
return ZTResult.Success;
|
}
|
|
|
|
/// <summary>
|
/// 创建队伍
|
/// </summary>
|
/// <returns></returns>
|
private bool CreateGroup(string groupName)
|
{
|
ZTRectangle mygroupButtonRect = ZTRectangle.Empty;
|
//打开队伍信息窗口
|
ZTRectangle groupWindowTextRect = ZTRectangle.Empty;
|
ZTRectangle searchButtonRect = ZTRectangle.Empty;
|
ZTRectangle createGroupButtonRect = ZTRectangle.Empty;
|
bool hasGroup = false;
|
if (!OpenGroupWindow(out groupWindowTextRect,out searchButtonRect,out createGroupButtonRect,out hasGroup))
|
{
|
G.Instance.InfoWriter("打开组队信息窗口失败");
|
return false;
|
}
|
|
if (hasGroup)
|
{
|
return true;
|
}
|
|
//打开创建队伍窗口
|
ZTRectangle createGroupWindowTextRect = ZTRectangle.Empty, okButtonRect = ZTRectangle.Empty;
|
if (!OpenCreateGroupWindow(out createGroupWindowTextRect,out okButtonRect ,createGroupButtonRect))
|
{
|
return false;
|
}
|
|
|
Utility.Structs.ZTPoint windowCenter = createGroupWindowTextRect.GetCenterPoint();
|
G.Instance.InputControl.MoveToAndClick(new Utility.Structs.ZTPoint(windowCenter.X + 50, windowCenter.Y + 80));
|
//清空文字
|
for (int i = 0; i < 15; i++)
|
{
|
G.Instance.InputControl.PressKey(false, false, false, false, false, false, false, false, HIDCode.Backspace);
|
}
|
//输入队伍名
|
G.Instance.InputControl.InputString(groupName);
|
|
//点击创建
|
G.Instance.InputControl.MoveToAndClick(okButtonRect.GetCenterPoint());
|
|
bool result = FuncUtils.TimeoutCancelableWrap(5000, this.CancelToken, () => {
|
//识别是否有我的队伍按钮
|
return GroupCVHelper.ExistsMyGroupButton(out mygroupButtonRect, this.GameRect);
|
});
|
if (result)
|
{
|
G.Instance.InfoWriter("create group ok");
|
//点击组队“确定”按钮
|
result = FuncUtils.TimeoutCancelableWrap(15 * 60 * 1000,this.CancelToken, () => {
|
Utility.Structs.ZTPoint yes = Utility.Structs.ZTPoint.Empty;
|
Utility.Structs.ZTPoint no = Utility.Structs.ZTPoint.Empty;
|
bool retFind = GroupCVHelper.FindYaoqingZuduiWindow(out yes, out no, this.GameRect);
|
if (retFind)
|
{
|
G.Instance.InputControl.MoveToAndClick(yes);
|
G.Instance.InfoWriter("other join group ok:"+ yes);
|
}
|
return retFind;
|
});
|
|
|
return result;
|
}
|
return false;
|
}
|
|
|
/// <summary>
|
/// 加入队伍
|
/// </summary>
|
/// <returns></returns>
|
private bool JoinGroup(string groupName)
|
{
|
ZTRectangle mygroupButtonRect = ZTRectangle.Empty;
|
//打开队伍信息窗口
|
ZTRectangle groupWindowTextRect = ZTRectangle.Empty;
|
ZTRectangle searchButtonRect = ZTRectangle.Empty;
|
ZTRectangle createGroupButtonRect = ZTRectangle.Empty;
|
bool hasGroup = false;
|
if (!OpenGroupWindow(out groupWindowTextRect,out searchButtonRect, out createGroupButtonRect, out hasGroup))
|
{
|
G.Instance.InfoWriter("打开组队信息窗口失败");
|
return false;
|
}
|
|
if (hasGroup)
|
{
|
return true;
|
}
|
|
ZTPoint searchButtonCenerPoint = searchButtonRect.GetCenterPoint();
|
//输入组名
|
G.Instance.InputControl.MoveToAndClick(new Utility.Structs.ZTPoint (searchButtonCenerPoint.X-80, searchButtonCenerPoint.Y));
|
DeleteAllChar(groupName.Length + 3);
|
G.Instance.InputControl.InputString(groupName);
|
|
|
//点搜索
|
G.Instance.InputControl.MoveToAndClick(searchButtonCenerPoint);
|
|
//查找组项
|
ZTRectangle groupItemRect = ZTRectangle.Empty;
|
bool result = FuncUtils.TimeoutCancelableWrap(5000, this.CancelToken, () => {
|
//识别组项
|
return GroupCVHelper.FindGroupItem(out groupItemRect, this.GameRect);
|
});
|
if (!result)
|
{
|
G.Instance.InfoWriter("group item not finded");
|
return true;
|
}
|
|
//点组名打开窗口
|
G.Instance.InputControl.MoveToAndClick(groupItemRect.GetCenterPoint());
|
|
|
//查找是否打开成员列表窗
|
ZTRectangle joinButtonRect = ZTRectangle.Empty;
|
result = FuncUtils.TimeoutCancelableWrap(5000, this.CancelToken, () => {
|
//识别是否打开成员列表窗
|
return GroupCVHelper.FindGroupMemberWindow(out joinButtonRect, this.GameRect);
|
});
|
if (!result)
|
{
|
G.Instance.InfoWriter("group member window not finded");
|
return true;
|
}
|
|
//点击加入队伍
|
G.Instance.InputControl.MoveToAndClick(joinButtonRect.GetCenterPoint());
|
|
//查找是否已经组队成功,30秒
|
result = FuncUtils.TimeoutCancelableWrap(30000, this.CancelToken, () => {
|
//识别是否有我的队伍按钮
|
return GroupCVHelper.ExistsMyGroupButton(out mygroupButtonRect, this.GameRect);
|
});
|
if (result)
|
{
|
G.Instance.InfoWriter("group ok");
|
return true;
|
}
|
|
|
return false;
|
}
|
|
|
/// <summary>
|
/// 打开组队窗
|
/// </summary>
|
/// <param name="titleRect"></param>
|
/// <param name="lvRect"></param>
|
/// <param name="upKeyRect"></param>
|
/// <param name="downKeyRect"></param>
|
/// <returns></returns>
|
private bool OpenGroupWindow(out ZTRectangle groupWindowTextRect,out ZTRectangle searchButtonRect, out ZTRectangle createGroupButton,out bool hasGroup)
|
{
|
hasGroup = false;
|
createGroupButton = ZTRectangle.Empty;
|
groupWindowTextRect = ZTRectangle.Empty;
|
searchButtonRect = ZTRectangle.Empty;
|
|
bool innerHasGroup = false;
|
ZTRectangle innerGroupWindowTextRect = ZTRectangle.Empty, innerSearchButtonRect = ZTRectangle.Empty, innerCreateGroupButton = ZTRectangle.Empty;
|
for (int i = 0; i < 2; i++)
|
{
|
CloseAllAlertWindow(this.CancelToken, this.GameRect);
|
G.Instance.InputControl.PressKey(RandomUtils.KeyPressDuration, HIDCode.RightSquarebrackets);
|
|
bool result = FuncUtils.TimeoutCancelableWrap(5000, this.CancelToken, () => {
|
//识别队伍窗
|
return GroupCVHelper.FindGroupWindow(out innerGroupWindowTextRect, out innerSearchButtonRect, out innerCreateGroupButton,out innerHasGroup, this.GameRect);
|
});
|
if (result)
|
{
|
groupWindowTextRect = innerGroupWindowTextRect;
|
searchButtonRect = innerSearchButtonRect;
|
createGroupButton = innerCreateGroupButton;
|
hasGroup = innerHasGroup;
|
return true;
|
}
|
}
|
G.Instance.InfoWriter("打开队伍信息对话框失败");
|
return false;
|
}
|
|
|
/// <summary>
|
/// 删除左右指定数量的字符
|
/// </summary>
|
/// <param name="count"></param>
|
private void DeleteAllChar(int count)
|
{
|
for (int i = 0; i < count; i++)
|
{
|
G.Instance.InputControl.PressKey(false, false, false, false, false, false, false, false, HIDCode.Delete);
|
G.Instance.InputControl.PressKey(false, false, false, false, false, false, false, false, HIDCode.Backspace);
|
}
|
}
|
|
/// <summary>
|
/// 打开创建队伍窗口
|
/// </summary>
|
/// <param name="createGroupButtonRect"></param>
|
/// <returns></returns>
|
private bool OpenCreateGroupWindow(out ZTRectangle createGroupWindowTextRect,out ZTRectangle okButtonRect,ZTRectangle createGroupButtonRect)
|
{
|
createGroupWindowTextRect = ZTRectangle.Empty;
|
okButtonRect = ZTRectangle.Empty;
|
ZTRectangle innerCreateGroupWindowTextRect = ZTRectangle.Empty, innerOkButtonRect = ZTRectangle.Empty;
|
for (int i = 0; i < 2; i++)
|
{
|
//点击创建队伍
|
G.Instance.InputControl.MoveToAndClick(createGroupButtonRect.GetCenterPoint());
|
bool result = FuncUtils.TimeoutCancelableWrap(5000, this.CancelToken, () => {
|
//识别创建队伍窗
|
return GroupCVHelper.FindCreateGroupWindow(out innerCreateGroupWindowTextRect, out innerOkButtonRect, this.GameRect);
|
});
|
if (result)
|
{
|
createGroupWindowTextRect = innerCreateGroupWindowTextRect;
|
okButtonRect = innerOkButtonRect;
|
return true;
|
}
|
}
|
G.Instance.InfoWriter("打开创建队伍信息对话框失败");
|
return false;
|
}
|
|
/// <summary>
|
/// 关闭所有弹出窗
|
/// </summary>
|
/// <param name="cancelToken"></param>
|
/// <param name="gameRect"></param>
|
/// <returns></returns>
|
private void CloseAllAlertWindow(CancellationToken cancelToken, ZTRectangle gameRect)
|
{
|
while (!cancelToken.IsCancellationRequested)
|
{
|
//G.Instance.InputControl.MoveTo(gameRect.Start.X,gameRect.Start.Y, false, false, false);
|
//Thread.Sleep(10);
|
//截图
|
Image<Rgb, byte> image = ScreenCapture.Instance.CaptureScreenReturnImage();
|
|
ZTRectangle closeButtonRect = ZTRectangle.Empty;
|
if (!DnfCVHelper.GetAlertWindow(out closeButtonRect, image, gameRect))
|
{
|
return;
|
}
|
|
G.Instance.InputControl.MoveToAndClick(closeButtonRect.GetCenterPoint());
|
Thread.Sleep(500);
|
}
|
}
|
|
}
|
}
|