using RichCreator.Utility;
using RichCreator.Utility.CV;
using RichCreator.Utility.InputControl;
using RichCreator.Utility.Maps;
using RichCreator.Utility.Structs;
using RichCreator.Utilitys;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace RichCreator.Dnf
{
///
/// 地图信息
///
public abstract class MapInfo
{
public MapInfo(MapType mapType, ZTRectangle gameRect, CancellationToken cancellationToken)
{
this.MapType = mapType;
this.GameRect = gameRect;
this.CancelToken = cancellationToken;
this.Role = new DnfRole(gameRect);
}
///
/// 游戏区域
///
public ZTRectangle GameRect { get; set; }
///
/// 小地图
///
public IMiniMap MiniMap { get; set; }
///
/// 取消令牌
///
public CancellationToken CancelToken { get; set; }
///
/// 地图类型
///
public MapType MapType { get; set; }
///
/// 角色
///
public DnfRole Role { get; set; }
#region Func
///
/// 关闭所有弹出窗
///
///
///
///
protected void CloseAllAlertWindowByEsc(CancellationToken cancelToken, ZTRectangle gameRect)
{
GameUtils.CloseAllAlertWindowByEsc(cancelToken, gameRect);
}
///
/// 关闭所有弹出窗
///
///
///
///
protected void CloseAllAlertWindowByX(CancellationToken cancelToken, ZTRectangle gameRect)
{
GameUtils.CloseAllAlertWindowByX(cancelToken, gameRect);
}
///
/// 点击右上角"退到城镇"文字
///
protected void ExitToTown()
{
G.Instance.DebugWriter("返回城镇");
Utility.Structs.ZTPoint point = new Utility.Structs.ZTPoint(this.GameRect.Start.X +667, this.GameRect.Start.Y + 147);
G.Instance.InputControl.MoveToAndClick(point);
Thread.Sleep(5000);
}
///
/// 点击右上角的“再次挑战”
///
protected void ReplayGame()
{
G.Instance.DebugWriter("重新挑战");
Utility.Structs.ZTPoint point = new Utility.Structs.ZTPoint(this.GameRect.Start.X+667, this.GameRect.Start.Y + 87);
G.Instance.InputControl.MoveToAndClick(point);
}
///
/// 出售装备
///
///
protected bool SaleEquipment()
{
//卖装备并关闭商店
ZTRectangle closeButtonRect = ZTRectangle.Empty;
ZTRectangle saleButtonRect = ZTRectangle.Empty;
if (!DnfCVHelper.HasSaleButton(out saleButtonRect, out closeButtonRect, this.GameRect))
{
return false;
}
//卖装备
G.Instance.InfoWriter("出售装备");
G.Instance.InputControl.MoveToAndClick(saleButtonRect.GetCenterPoint());
//得到装备文字位置
ZTRectangle equipmentTextRect = ZTRectangle.Empty;
bool result = FuncUtils.TimeoutCancelableWrap(5000, this.CancelToken, () =>
{
Int32 status = 0;
if (DnfCVHelper.GetEquipmentSelectStatus(out equipmentTextRect, out status, this.GameRect))
{
if (status == 1)
{
return true;
}
G.Instance.InputControl.MoveToAndClick(equipmentTextRect.GetCenterPoint());
}
return false;
});
if (!result)
{
G.Instance.InfoWriter("装备文字未取到");
return false;
}
//开始点,每格步进30
ZTPoint startPoint = new Utility.Structs.ZTPoint(equipmentTextRect.End.X - 30, equipmentTextRect.End.Y + 9);
List points = DnfCVHelper.GetEquipmentIndexs(startPoint);
for (int i = 0; i < points.Count; i++)
{
Int32 index = points[i];
int row = index / 8;
int col = index % 8;
int x = col * 30 + 15;
int y = row * 30 + 15;
//点窗格
G.Instance.InputControl.MoveToAndClick(new Utility.Structs.ZTPoint(startPoint.X + x, startPoint.Y + y));
Thread.Sleep(500);
//点确定
G.Instance.InputControl.Move(0, 0, true, false, false);
Thread.Sleep(RandomUtils.MouseClickDuration);
G.Instance.InputControl.Move(0, 0, false, false, false);
Thread.Sleep(RandomUtils.MouseClickDuration);
}
G.Instance.DebugWriter("equipment:" + ZTImage.Utils.ConcatString(points.ToArray(), ","));
Thread.Sleep(RandomUtils.KeyPressDuration);
G.Instance.InputControl.PressKey(RandomUtils.KeyPressDuration, HIDCode.Escape);
return true;
}
#endregion
#region abstruct func
///
/// 开始刷图
///
///
public abstract ZTResult Start(Int32 runningStep);
///
/// 是否已进入地图
///
///
public virtual bool IsEntryMap()
{
return true;
}
///
/// 进入每个房间后的前置工作
///
///
///
public virtual void EntryHousePrework(Int32 houseIndex, Int32 preHouseIndex)
{ }
#endregion
}
}