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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
using RichCreator.Utility;
using RichCreator.Utility.Captures;
using RichCreator.Utility.CV;
using RichCreator.Utility.InputControl;
using RichCreator.Utility.Structs;
using RichCreator.Utility.Utilitys;
using Emgu.CV;
using Emgu.CV.Structure;
using RichCreator.Jobs;
using RichCreator.Jobs.StateMachines;
using System;
using System.Collections.Generic;
using System.Threading;
using static RichCreator.Utility.CV.GroupCVHelper;
using RichCreator.StateMachines;
using RichCreator.Utility.Maps;
using RichCreator.Dnf;
 
namespace RichCreator.Maps.Test
{
    /// <summary>
    /// 测试地图
    /// </summary>
    public class TestMap : MapInfo
    {
        public TestMap(ZTRectangle gameRect, CancellationToken cancelToken) :base(MapType.Test, gameRect, cancelToken)
        {
 
        }
        
        public override ZTResult Start(Int32 runningStep)
        {
            WindowUtils.SetDnfToTop();
 
            const bool isCreateGroup = true;
            string groupName = "aabbccddee";
            if (isCreateGroup)
            {
                //创建队伍
                if (!CreateGroup(groupName))
                {
                    G.Instance.InfoWriter("创建队伍失败");
                    return ZTResult.Failed;
                }
            }
            else
            {
                //加入队伍
                if (!JoinGroup(groupName))
                {
                    G.Instance.InfoWriter("加入队伍失败");
                    return ZTResult.Failed;
                }
            }
            //沉默一段时间
            Thread.Sleep(50000000);
            CloseAllAlertWindowByX(this.CancelToken, this.GameRect);
            return ZTResult.Success;
        }
        
      
 
        /// <summary>
        /// 创建队伍 
        /// </summary>
        /// <returns></returns>
        private bool CreateGroup(string groupName)
        {
            ZTRectangle mygroupButtonRect = ZTRectangle.Empty;
            //打开队伍信息窗口
            ZTRectangle groupWindowTextRect = ZTRectangle.Empty;
            ZTRectangle searchButtonRect = ZTRectangle.Empty;
            ZTRectangle createGroupButtonRect = ZTRectangle.Empty;
            bool hasGroup = false;
            if (!OpenGroupWindow(out groupWindowTextRect,out searchButtonRect,out createGroupButtonRect,out hasGroup))
            {
                G.Instance.InfoWriter("打开组队信息窗口失败");
                return false;
            }
 
            if (hasGroup)
            {
                return true;
            }
            
            //打开创建队伍窗口
            ZTRectangle createGroupWindowTextRect = ZTRectangle.Empty, okButtonRect = ZTRectangle.Empty;
            if (!OpenCreateGroupWindow(out createGroupWindowTextRect,out okButtonRect ,createGroupButtonRect))
            {
                return false;
            }
 
 
            Utility.Structs.ZTPoint windowCenter = createGroupWindowTextRect.GetCenterPoint();
            G.Instance.InputControl.MoveToAndClick(new Utility.Structs.ZTPoint(windowCenter.X + 50, windowCenter.Y + 80));
            //清空文字
            for (int i = 0; i < 15; i++)
            {
                G.Instance.InputControl.PressKey(false, false, false, false, false, false, false, false, HIDCode.Backspace);
            }
            //输入队伍名
            G.Instance.InputControl.InputString(groupName);
            
            //点击创建
            G.Instance.InputControl.MoveToAndClick(okButtonRect.GetCenterPoint());
            
            bool result = FuncUtils.TimeoutCancelableWrap(5000, this.CancelToken, () => {
                //识别是否有我的队伍按钮
                return GroupCVHelper.ExistsMyGroupButton(out mygroupButtonRect, this.GameRect);
            });
            if (result)
            {
                G.Instance.InfoWriter("create group ok");
                //点击组队“确定”按钮
                result = FuncUtils.TimeoutCancelableWrap(15 * 60 * 1000,this.CancelToken, () => {
                    Utility.Structs.ZTPoint yes = Utility.Structs.ZTPoint.Empty;
                    Utility.Structs.ZTPoint no = Utility.Structs.ZTPoint.Empty;
                    bool retFind = GroupCVHelper.FindYaoqingZuduiWindow(out yes, out no, this.GameRect);
                    if (retFind)
                    {
                        G.Instance.InputControl.MoveToAndClick(yes);
                        G.Instance.InfoWriter("other join group ok:"+ yes);
                    }
                    return retFind;
                });
 
 
                return result;
            }
            return false;
        }
 
 
        /// <summary>
        /// 加入队伍
        /// </summary>
        /// <returns></returns>
        private bool JoinGroup(string groupName)
        {
            ZTRectangle mygroupButtonRect = ZTRectangle.Empty;
            //打开队伍信息窗口
            ZTRectangle groupWindowTextRect = ZTRectangle.Empty;
            ZTRectangle searchButtonRect = ZTRectangle.Empty;
            ZTRectangle createGroupButtonRect = ZTRectangle.Empty;
            bool hasGroup = false;
            if (!OpenGroupWindow(out groupWindowTextRect,out searchButtonRect, out createGroupButtonRect, out hasGroup))
            {
                G.Instance.InfoWriter("打开组队信息窗口失败");
                return false;
            }
 
            if (hasGroup)
            {
                return true;
            }
 
            ZTPoint searchButtonCenerPoint = searchButtonRect.GetCenterPoint();
            //输入组名
            G.Instance.InputControl.MoveToAndClick(new Utility.Structs.ZTPoint (searchButtonCenerPoint.X-80, searchButtonCenerPoint.Y));
            DeleteAllChar(groupName.Length + 3);
            G.Instance.InputControl.InputString(groupName);
 
 
            //点搜索
            G.Instance.InputControl.MoveToAndClick(searchButtonCenerPoint);
 
            //查找组项
            ZTRectangle groupItemRect = ZTRectangle.Empty;
            bool result = FuncUtils.TimeoutCancelableWrap(5000, this.CancelToken, () => {
                //识别组项
                return GroupCVHelper.FindGroupItem(out groupItemRect, this.GameRect);
            });
            if (!result)
            {
                G.Instance.InfoWriter("group item not finded");
                return true;
            }
                       
            //点组名打开窗口
            G.Instance.InputControl.MoveToAndClick(groupItemRect.GetCenterPoint());
 
 
            //查找是否打开成员列表窗
            ZTRectangle joinButtonRect = ZTRectangle.Empty;
            result = FuncUtils.TimeoutCancelableWrap(5000, this.CancelToken, () => {
                //识别是否打开成员列表窗
                return GroupCVHelper.FindGroupMemberWindow(out joinButtonRect, this.GameRect);
            });
            if (!result)
            {
                G.Instance.InfoWriter("group member window not finded");
                return true;
            }
 
            //点击加入队伍
            G.Instance.InputControl.MoveToAndClick(joinButtonRect.GetCenterPoint());
 
            //查找是否已经组队成功,30秒
            result = FuncUtils.TimeoutCancelableWrap(30000, this.CancelToken, () => {
                //识别是否有我的队伍按钮
                return GroupCVHelper.ExistsMyGroupButton(out mygroupButtonRect, this.GameRect);
            });
            if (result)
            {
                G.Instance.InfoWriter("group ok");
                return true;
            }
 
 
            return false;
        }
 
 
        /// <summary>
        /// 打开组队窗
        /// </summary>
        /// <param name="titleRect"></param>
        /// <param name="lvRect"></param>
        /// <param name="upKeyRect"></param>
        /// <param name="downKeyRect"></param>
        /// <returns></returns>
        private bool OpenGroupWindow(out ZTRectangle groupWindowTextRect,out ZTRectangle searchButtonRect, out ZTRectangle createGroupButton,out bool hasGroup)
        {
            hasGroup = false;
            createGroupButton = ZTRectangle.Empty;
            groupWindowTextRect = ZTRectangle.Empty;
            searchButtonRect = ZTRectangle.Empty;
 
            bool innerHasGroup = false;
            ZTRectangle innerGroupWindowTextRect = ZTRectangle.Empty, innerSearchButtonRect = ZTRectangle.Empty, innerCreateGroupButton = ZTRectangle.Empty;
            for (int i = 0; i < 2; i++)
            {
                CloseAllAlertWindowByX(this.CancelToken, this.GameRect);
                G.Instance.InputControl.PressKey(RandomUtils.KeyPressDuration, HIDCode.RightSquarebrackets);
 
                bool result = FuncUtils.TimeoutCancelableWrap(5000, this.CancelToken, () => {
                    //识别队伍窗
                    return GroupCVHelper.FindGroupWindow(out innerGroupWindowTextRect, out innerSearchButtonRect, out innerCreateGroupButton,out innerHasGroup, this.GameRect);
                });
                if (result)
                {
                    groupWindowTextRect = innerGroupWindowTextRect;
                    searchButtonRect = innerSearchButtonRect;
                    createGroupButton = innerCreateGroupButton;
                    hasGroup = innerHasGroup;
                    return true;
                }
            }
            G.Instance.InfoWriter("打开队伍信息对话框失败");
            return false;
        }
 
 
        /// <summary>
        /// 删除左右指定数量的字符
        /// </summary>
        /// <param name="count"></param>
        private void DeleteAllChar(int count)
        {
            for (int i = 0; i < count; i++)
            {
                G.Instance.InputControl.PressKey(false, false, false, false, false, false, false, false, HIDCode.Delete);
                G.Instance.InputControl.PressKey(false, false, false, false, false, false, false, false, HIDCode.Backspace);
            }
        }
 
        /// <summary>
        /// 打开创建队伍窗口
        /// </summary>
        /// <param name="createGroupButtonRect"></param>
        /// <returns></returns>
        private bool OpenCreateGroupWindow(out ZTRectangle createGroupWindowTextRect,out ZTRectangle okButtonRect,ZTRectangle createGroupButtonRect)
        {
            createGroupWindowTextRect = ZTRectangle.Empty;
            okButtonRect = ZTRectangle.Empty;
            ZTRectangle innerCreateGroupWindowTextRect = ZTRectangle.Empty, innerOkButtonRect = ZTRectangle.Empty;
            for (int i = 0; i < 2; i++)
            {
                //点击创建队伍
                G.Instance.InputControl.MoveToAndClick(createGroupButtonRect.GetCenterPoint());
                bool result = FuncUtils.TimeoutCancelableWrap(5000, this.CancelToken, () => {
                    //识别创建队伍窗
                    return GroupCVHelper.FindCreateGroupWindow(out innerCreateGroupWindowTextRect, out innerOkButtonRect, this.GameRect);
                });
                if (result)
                {
                    createGroupWindowTextRect = innerCreateGroupWindowTextRect;
                    okButtonRect = innerOkButtonRect;
                    return true;
                }
            }
            G.Instance.InfoWriter("打开创建队伍信息对话框失败");
            return false;
        }
        
       
    }
}