asmrobot
2019-11-25 2aeab450471cb80b59002da7da80faf251a0c4f4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
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
{
    /// <summary>
    /// 地图信息
    /// </summary>
    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);
        }
 
        /// <summary>
        /// 游戏区域
        /// </summary>
        public ZTRectangle GameRect { get; set; }
 
        /// <summary>
        /// 小地图
        /// </summary>
        public IMiniMap MiniMap { get; set; }
 
       
 
        /// <summary>
        /// 取消令牌
        /// </summary>
        public CancellationToken CancelToken { get; set; }
 
 
        /// <summary>
        /// 地图类型
        /// </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>
        /// <returns></returns>
        public abstract ZTResult Start(Int32 runningStep);
 
 
        /// <summary>
        /// 是否已进入地图
        /// </summary>
        /// <returns></returns>
        public virtual bool IsEntryMap()
        {
            return true;
        }
 
        /// <summary>
        /// 进入每个房间后的前置工作
        /// </summary>
        /// <param name="houseIndex"></param>
        /// <param name="preHouseIndex"></param>
        public virtual void EntryHousePrework(Int32 houseIndex, Int32 preHouseIndex)
        { }
        #endregion
 
 
 
    }
}