asmrobot
2019-11-21 589ed88a5924a7494e21b95b6bbff5e46ff49ddd
src/RichCreator/Dnf/MapInfo.cs
@@ -1,6 +1,9 @@
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;
@@ -20,6 +23,7 @@
            this.MapType = mapType;
            this.GameRect = gameRect;
            this.CancelToken = cancellationToken;
            this.Role = new DnfRole(gameRect);
        }
        /// <summary>
@@ -45,6 +49,139 @@
        /// </summary>
        public MapType MapType { get; set; }
        /// <summary>
        /// 角色
        /// </summary>
        public DnfRole Role { get; set; }
        #region Func
        /// <summary>
        /// 关闭所有弹出窗
        /// </summary>
        /// <param name="cancelToken"></param>
        /// <param name="gameRect"></param>
        /// <returns></returns>
        protected void CloseAllAlertWindowByEsc(CancellationToken cancelToken, ZTRectangle gameRect)
        {
            GameUtils.CloseAllAlertWindowByEsc(cancelToken, gameRect);
        }
        /// <summary>
        /// 关闭所有弹出窗
        /// </summary>
        /// <param name="cancelToken"></param>
        /// <param name="gameRect"></param>
        /// <returns></returns>
        protected void CloseAllAlertWindowByX(CancellationToken cancelToken, ZTRectangle gameRect)
        {
            GameUtils.CloseAllAlertWindowByX(cancelToken, gameRect);
        }
        /// <summary>
        /// 点击右上角"退到城镇"文字
        /// </summary>
        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);
        }
        /// <summary>
        /// 点击右上角的“再次挑战”
        /// </summary>
        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);
        }
        /// <summary>
        /// 出售装备
        /// </summary>
        /// <param name="saleButtonRect"></param>
        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<Int32> 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
        /// <summary>
        /// 开始刷图
        /// </summary>
@@ -68,5 +205,9 @@
        /// <param name="preHouseIndex"></param>
        public virtual void EntryHousePrework(Int32 houseIndex, Int32 preHouseIndex)
        { }
        #endregion
    }
}