using Emgu.CV;
|
using Emgu.CV.Structure;
|
using RichCreator.Utility.Captures;
|
using RichCreator.Utility.Structs;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading;
|
using System.Threading.Tasks;
|
|
namespace RichCreator.Dnf
|
{
|
/// <summary>
|
/// 小地图
|
/// </summary>
|
public abstract class IMiniMap
|
{
|
public ZTRectangle GameRect { get; private set; }
|
|
public ZTPoint MinimapOffset { get; private set; }
|
|
|
|
public IMiniMap(ZTRectangle gameRect,ZTPoint miniMapOffset)
|
{
|
this.GameRect = gameRect;
|
this.MinimapOffset = miniMapOffset.Add(gameRect.Start);
|
}
|
|
/// <summary>
|
/// 获取房间号
|
/// </summary>
|
/// <param name="houseIndex">房间号,以0开始</param>
|
/// <param name="image">图像,可以传空,传空则自获取</param>
|
/// <returns>true:获取成功,false:获取失败</returns>
|
public bool GetCurrentHouseIndex(out int houseIndex, Image<Rgb, byte> image)
|
{
|
if (image == null)
|
{
|
image = ScreenCapture.Instance.CaptureScreenReturnImage();
|
image = image.GetSubRect(new System.Drawing.Rectangle(this.GameRect.Start.X, this.GameRect.Start.Y, this.GameRect.End.X - this.GameRect.Start.X + 1, this.GameRect.End.Y - this.GameRect.Start.Y + 1));
|
}
|
return GetCurrentHouse(out houseIndex, image);
|
}
|
|
/// <summary>
|
/// 在超时之前获取房间号
|
/// </summary>
|
/// <param name="houseIndex">房间号,以0开始</param>
|
/// <param name="image">图像,可以传空,传空则自获取</param>
|
/// <param name="timeoutMillSecond">超时毫秒数</param>
|
/// <returns>true:获取成功,false:获取失败</returns>
|
public bool GetCurrentHouseIndexWaitTimeout(out int houseIndex, Image<Rgb, byte> image, CancellationToken cancelToken, Int32 timeoutMillSecond)
|
{
|
houseIndex = 0;
|
Int32 houseid = -1;
|
if (image != null)
|
{
|
if (GetCurrentHouse(out houseid, image))
|
{
|
houseIndex = houseid;
|
return true;
|
}
|
}
|
if (!FuncUtils.TimeoutCancelableWrap(timeoutMillSecond, cancelToken, () =>
|
{
|
using (System.Drawing.Bitmap bitmap = ScreenCapture.Instance.CaptureScreen())
|
{
|
image = new Image<Rgb, byte>(bitmap);
|
image = image.GetSubRect(new System.Drawing.Rectangle(this.GameRect.Start.X, this.GameRect.Start.Y, this.GameRect.End.X - this.GameRect.Start.X + 1, this.GameRect.End.Y - this.GameRect.Start.Y + 1));
|
return GetCurrentHouse(out houseid, image);
|
}
|
}, 50))
|
{
|
return false;
|
}
|
houseIndex = houseid;
|
return true;
|
}
|
|
/// <summary>
|
/// 计算当前房间号
|
/// </summary>
|
/// <param name="houseIndex"></param>
|
/// <param name="image"></param>
|
/// <returns></returns>
|
protected abstract bool GetCurrentHouse(out Int32 houseIndex, Image<Rgb, byte> image);
|
}
|
}
|