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 { /// /// 小地图 /// 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); } /// /// 获取房间号 /// /// 房间号,以0开始 /// 图像,可以传空,传空则自获取 /// true:获取成功,false:获取失败 public bool GetCurrentHouseIndex(out int houseIndex, Image 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); } /// /// 在超时之前获取房间号 /// /// 房间号,以0开始 /// 图像,可以传空,传空则自获取 /// 超时毫秒数 /// true:获取成功,false:获取失败 public bool GetCurrentHouseIndexWaitTimeout(out int houseIndex, Image 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(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; } /// /// 计算当前房间号 /// /// /// /// protected abstract bool GetCurrentHouse(out Int32 houseIndex, Image image); } }