asmrobot
2019-11-21 589ed88a5924a7494e21b95b6bbff5e46ff49ddd
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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
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 RichCreator.Utility.Maps;
using RichCreator.Utility.Skills;
using RichCreator.Dnf;
 
namespace RichCreator.Maps.Lindong
{
    /// <summary>
    /// 凛冬地图
    /// </summary>
    public class LindongMap : ShikongzhimenMapBase
    {
        public LindongMap(ZTRectangle gameRect, CancellationToken cancelToken) :base(MapType.Lingdong,gameRect,cancelToken)
        {
            this.MiniMap = new LindongMiniMap(gameRect);
        }
        
        /// <summary>
        /// 地图的所有房间
        /// NextIndex=-1,完成
        /// NextIndex=-2,出错
        /// </summary>
        private static readonly HouseInfo[] Houses = new HouseInfo[] {
            new HouseInfo (0 ,MapType.Lingdong,false,new HIDCode[] { HIDCode.A,HIDCode.D,HIDCode.X},null),
            new HouseInfo (1 ,MapType.Lingdong,false,new HIDCode[] { HIDCode.A,HIDCode.D,HIDCode.X},null),
            new HouseInfo (2 ,MapType.Lingdong,false,new HIDCode[] { HIDCode.A,HIDCode.D,HIDCode.X},null),
            new HouseInfo (3 ,MapType.Lingdong,false,new HIDCode[] { HIDCode.A,HIDCode.D,HIDCode.X},null),
            new HouseInfo (4 ,MapType.Lingdong,false,new HIDCode[] { HIDCode.A,HIDCode.D,HIDCode.X},null),
            new HouseInfo (5 ,MapType.Lingdong,false,new HIDCode[] { HIDCode.A,HIDCode.D,HIDCode.X},null),
            new HouseInfo (6 ,MapType.Lingdong,false,new HIDCode[] { HIDCode.A,HIDCode.D,HIDCode.X},null),
            new HouseInfo (7 ,MapType.Lingdong,false,new HIDCode[] { HIDCode.A,HIDCode.D,HIDCode.X},null),
            new HouseInfo (8 ,MapType.Lingdong,false,new HIDCode[] { HIDCode.A,HIDCode.D,HIDCode.X},null),
            new HouseInfo (9 ,MapType.Lingdong,false,new HIDCode[] { HIDCode.A,HIDCode.D,HIDCode.X},null),
            new HouseInfo (10,MapType.Lingdong,false,new HIDCode[] { HIDCode.A,HIDCode.D,HIDCode.X},null),
            new HouseInfo (11,MapType.Lingdong,false,new HIDCode[] { HIDCode.A,HIDCode.D,HIDCode.X},null),
            new HouseInfo (12,MapType.Lingdong,false,new HIDCode[] { HIDCode.A,HIDCode.D,HIDCode.X},null),
            new HouseInfo (13,MapType.Lingdong,false,new HIDCode[] { HIDCode.A,HIDCode.D,HIDCode.X},null),
            new HouseInfo (14,MapType.Lingdong,false,new HIDCode[] { HIDCode.A,HIDCode.D,HIDCode.X},null),
            new HouseInfo (15,MapType.Lingdong,true ,new HIDCode[] { HIDCode.A,HIDCode.D,HIDCode.X},null),
            new HouseInfo (16,MapType.Lingdong,false,new HIDCode[] { HIDCode.A,HIDCode.D,HIDCode.X},null),
            new HouseInfo (17,MapType.Lingdong,false,new HIDCode[] { HIDCode.A,HIDCode.D,HIDCode.X},null),
            new HouseInfo (18,MapType.Lingdong,false,new HIDCode[] { HIDCode.A,HIDCode.D,HIDCode.X},null),
            new HouseInfo (19,MapType.Lingdong,false,new HIDCode[] { HIDCode.A,HIDCode.D,HIDCode.X},null)
        };
        
        private Int32 runningStep = RunningStep.None;
        
        
        /// <summary>
        /// 开始
        /// </summary>
        /// <param name="gameRect"></param>
        /// <param name="cancelToken"></param>
        /// <param name="runningStep"></param>
        /// <returns></returns>
        public override ZTResult Start(Int32 runningStep)
        {
            this.runningStep = runningStep;
            
 
            WindowUtils.SetDnfToTop();
 
            if (runningStep < RunningStep.War)
            {
                if (!MoveToSunan())
                {
                    return ZTResult.Failed;
                }
 
                if (!MoveToShikongzhimen())
                {
                    return ZTResult.Failed;
                }
 
                if (!MoveToChoiceTaskPage())
                {
                    return ZTResult.Failed;
                }
 
                if (!IntoTaskRoom())
                {
                    return ZTResult.Failed;
                }
 
                G.Instance.InfoWriter("成功进入副本");
            }
            
            while (true)
            {
                //重复刷,直到疲劳值不够了
                if (this.CancelToken.IsCancellationRequested)
                {
                    return ZTResult.Cancel;
                }
 
                
                DateTime startHouse = DateTime.Now;
                ZTResult killResult = KillMonster();
                if (killResult==ZTResult.Success)
                {
                    //捡东西
                    G.Instance.InputControl.PressKey(RandomUtils.KeyPressDuration, HIDCode.V);
                    Thread.Sleep(1000);
                    for (int i = 0; i < 5; i++)
                    {
                        G.Instance.InputControl.PressKey(RandomUtils.KeyPressDuration, HIDCode.X);
                        Thread.Sleep(RandomUtils.KeyPressDuration * 3);
                    }
                    
 
                    //卖装备并关闭商店
                    SaleEquipment();
 
                    Int32 houseTotalSecond = (Int32)(DateTime.Now - startHouse).TotalSeconds;
                    G.Instance.InfoWriter("单次刷图成功,用时:"+(houseTotalSecond/60)+"分"+(houseTotalSecond%60)+"秒");
 
                    //查询疲劳值
                    Int32 pilaozhi =DnfCVHelper.GetPiLaoZhi(this.GameRect);
 
                    G.Instance.InfoWriter("疲劳值:" + pilaozhi);
                    if (pilaozhi <= 0)
                    {
                        ExitToTown();
                        return ZTResult.Success;
                    }
 
                    ReplayGame();
                    continue;
                }
                else
                {
                    return killResult;
                }
            }
        }
        
        /// <summary>
        /// 是否进入打怪地图
        /// </summary>
        /// <returns></returns>
        public override bool IsEntryMap()
        {
            //查找顶端凛冬文字
            bool findResult = FuncUtils.TimeoutCancelableWrap(2 * 60 * 1000, CancelToken, () => {
                using (Image<Rgb, byte> image = ScreenCapture.Instance.CaptureScreenReturnImage())
                {
                    return LindongCVHelper.ExistLingdongText(image, this.GameRect);
                }
            }, 10);
 
            if (!findResult)
            {
                G.Instance.InfoWriter("未找到进入凛冬的文字");
            }
            else
            {
                G.Instance.InfoWriter("进入凛冬");
            }
 
            return findResult;
        }
 
        /// <summary>
        /// 进入每个房间前的工作
        /// </summary>
        /// <param name="houseIndex"></param>
        /// <param name="preHouseIndex"></param>
        public override void EntryHousePrework(int houseIndex, int preHouseIndex)
        {
            G.Instance.InfoWriter("in lingdong");
            //移动和发招
            switch (houseIndex)
            {
                case 2:
                    G.Instance.InputControl.PressKey(RandomUtils.KeyPressDuration, HIDCode.LeftArrow);
                    this.Role.SyncMove(new ZTPoint(-110, 0));
                    G.Instance.InputControl.PressKeys(HIDCode.LeftArrow, HIDCode.G);
 
                    break;
                case 1:
                    this.Role.SyncMove(new ZTPoint(-480, 80));
                    G.Instance.InputControl.PressKey(RandomUtils.KeyPressDuration, HIDCode.W);
                    break;
                case 5:
                    //G.Instance.InputControl.PressKey(RandomUtils.KeyPressDuration, HIDCode.RightArrow);
                    G.Instance.InputControl.PressKey(RandomUtils.KeyPressDuration, HIDCode.R);
                    Thread.Sleep(1000);
                    G.Instance.InputControl.PressKey(RandomUtils.KeyPressDuration, HIDCode.T);
                    break;
                case 4:
                    this.Role.SyncMove(new ZTPoint(-1150, -50));
                    G.Instance.InputControl.PressKey(RandomUtils.KeyPressDuration, HIDCode.RightArrow);
                    G.Instance.InputControl.PressKey(RandomUtils.KeyPressDuration, HIDCode.E);
                    //Thread.Sleep(1000);
                    //G.Instance.InputControl.PressKey(RandomUtils.KeyPressDuration, HIDCode.E);
                    break;
                case 8:
                    this.Role.SyncMove(new ZTPoint(-100, 110));
                    G.Instance.InputControl.PressKey(RandomUtils.KeyPressDuration, HIDCode.RightArrow);
                    G.Instance.InputControl.PressKey(RandomUtils.KeyPressDuration, HIDCode.G);
                    //Thread.Sleep(300);
                    //G.Instance.InputControl.PressKey(RandomUtils.KeyPressDuration, HIDCode.Z);
                    break;
                case 9:
                    this.Role.SyncMove(new ZTPoint(325, 65));
                    G.Instance.InputControl.PressKey(RandomUtils.KeyPressDuration, HIDCode.R);
                    Thread.Sleep(1000);
                    this.Role.SyncMove(new ZTPoint(300, 0));
                    G.Instance.InputControl.PressKey(RandomUtils.KeyPressDuration, HIDCode.T);
                    break;
                case 10:
                    G.Instance.InputControl.PressKey(RandomUtils.KeyPressDuration, HIDCode.Q);
                    break;
                case 12:
                    G.Instance.InputControl.PressKey(RandomUtils.KeyPressDuration, HIDCode.RightArrow);
                    G.Instance.InputControl.PressKey(RandomUtils.KeyPressDuration, HIDCode.R);
                    Thread.Sleep(1000);
                    this.Role.SyncMove(new ZTPoint(-110, 0));
                    G.Instance.InputControl.PressKey(RandomUtils.KeyPressDuration, HIDCode.T);
                    break;
                case 13:
                    if (preHouseIndex == 12)
                    {
                        this.Role.SyncMove(new ZTPoint(600, 150));
                    }
                    else
                    {
                        this.Role.SyncMove(new ZTPoint(-300, 200));
                        G.Instance.InputControl.PressKey(RandomUtils.KeyPressDuration, HIDCode.RightArrow);
                    }
                    G.Instance.InputControl.PressKey(RandomUtils.KeyPressDuration, HIDCode.Q);
                    Thread.Sleep(1000);
                    G.Instance.InputControl.PressKey(RandomUtils.KeyPressDuration, HIDCode.E);
                    break;
                case 14:
                    if (preHouseIndex == 13)
                    {
                        this.Role.SyncMove(new ZTPoint(400, 0));
                    }
                    else
                    {
                        this.Role.SyncMove(new ZTPoint(0, 100));
                    }
                    G.Instance.InputControl.PressKey(RandomUtils.KeyPressDuration, HIDCode.W);
                    break;
 
                case 15:
                    this.Role.SyncMove(new ZTPoint(600, 0));
                    G.Instance.InputControl.PressKey(RandomUtils.KeyPressDuration, HIDCode.H);
                    Thread.Sleep(5000);
                    G.Instance.InputControl.PressKey(RandomUtils.KeyPressDuration, HIDCode.Y);
                    break;
                case 18:
                    G.Instance.InputControl.PressKey(RandomUtils.KeyPressDuration, HIDCode.W);
                    break;
 
            }
        }
        
        /// <summary>
        /// 刷房间
        /// </summary>
        /// <returns></returns>
        private ZTResult KillMonster()
        {
            bool ret = false;
            
            if (!IsEntryMap())
            {
                G.Instance.InfoWriter("未找到进入凛冬");
                return ZTResult.Failed;
            }
            G.Instance.InfoWriter("进入凛冬");
            
            Int32 preHouseIndex = -1;
            Int32 houseIndex = -1;
            
 
            //技能加成
            G.Instance.InputControl.PressKey(RandomUtils.KeyPressDuration, HIDCode.Space);
            
            //循环刷房间
            while (true)
            {
                preHouseIndex = houseIndex;
                //看房间号
                ret = this.MiniMap.GetCurrentHouseIndexWaitTimeout(out houseIndex, null, this.CancelToken, 3 * 1000);
                if (!ret)
                {
                    G.Instance.InfoWriter("未找到人物所在房间");
                    return ZTResult.Failed;
                }
 
                G.Instance.InfoWriter("进入房间->" + houseIndex.ToString());
 
                HouseInfo houseInfo = Houses[houseIndex];
                this.Role.SetHouse(houseInfo);
                DateTime startTime = DateTime.Now;
                KillMonsterStateMachine kmsm = new KillMonsterStateMachine(this, houseInfo,this.Role);
                ZTResult smresult = kmsm.Work( 5 * 60 * 1000,preHouseIndex,this.runningStep);
                Int32 roomTotalSecond = (Int32)(DateTime.Now - startTime).TotalSeconds;
                G.Instance.InfoWriter("房间刷完,用时:" + (roomTotalSecond / 60) + "分" + (roomTotalSecond % 60) + "秒");
 
                runningStep = RunningStep.None;
                if (smresult == ZTResult.Success)
                {
                    if (houseInfo.IsEnd)
                    {
                        //所有房间刷完
                        return ZTResult.Success;
                    }
 
                    //刷其它房间
                    continue;
                }
                else
                {
                    return smresult;
                }
            }
        }
 
 
        /// <summary>
        /// 进入指定房间
        /// </summary>
        /// <returns></returns>
        private bool IntoTaskRoom()
        {
 
            bool result = false;
            //选择凛冬
            G.Instance.InfoWriter("开始选择凛冬");
 
            Int32 nandu = 0;
            if (!SelectLindong(out nandu))
            {
                G.Instance.InfoWriter("选择凛冬失败");
                return false;
            }
            G.Instance.InfoWriter("选择凛冬成功,难度:" + nandu);
 
            if (nandu != 4)
            {
                G.Instance.InfoWriter("开始选择难度");
                result = SelectNandu(nandu);
                if (!result)
                {
                    G.Instance.InfoWriter("选择难度失败");
                    return false;
                }
                G.Instance.InfoWriter("选择难度成功");
            }
 
            //开始
            G.Instance.InputControl.PressKey(80, HIDCode.Space);
            return true;
        }
 
        /// <summary>
        /// 选择凛冬
        /// </summary>
        /// <returns></returns>
        private bool SelectLindong(out Int32 nandu)
        {
            Image<Rgb, byte> image = ScreenCapture.Instance.CaptureScreenReturnImage();
 
            if (LindongCVHelper.GetChoiceLingdongNandu(out nandu, image, this.GameRect))
            {
                return true; 
            }
 
            G.Instance.InputControl.MoveToAndClick(new Utility.Structs.ZTPoint(this.GameRect.Start.X + 313, this.GameRect.Start.Y + 462));
            Thread.Sleep(5000);
            image = ScreenCapture.Instance.CaptureScreenReturnImage();
            if (LindongCVHelper.GetChoiceLingdongNandu(out nandu, image, this.GameRect))
            {
                return true;
            }
 
            return false;
        }
                
        /// <summary>
        /// 选择难度
        /// </summary>
        /// <param name="rightCan"></param>
        /// <param name="leftCan"></param>
        /// <returns></returns>
        private bool SelectNandu(Int32 nandu)
        {
            Int32 count = 4 - nandu;
            for (int i = 0; i < Math.Abs(count); i++) 
            {
                if (count < 0)
                {
                    G.Instance.InputControl.PressKey(RandomUtils.KeyPressDuration, HIDCode.LeftArrow);
                }
                else
                {
                    G.Instance.InputControl.PressKey(RandomUtils.KeyPressDuration, HIDCode.RightArrow);
                }
                Thread.Sleep(400);
            }
            
            Image<Rgb, byte> image = ScreenCapture.Instance.CaptureScreenReturnImage();
            if (!LindongCVHelper.GetChoiceLingdongNandu(out nandu, image, this.GameRect))
            {
                return false;
            }
 
            if (nandu == 4)
            {
                return true;
            }
 
 
            return false;
        }
        
 
 
        
    }
}