asmrobot
2019-10-29 f25f89101a98ad815c0ae2d25e1a8dc35d53a5dd
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
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
using RichCreator.Utility;
using RichCreator.Utility.InputControl;
using RichCreator.Utility.Structs;
using RichCreator.Jobs.StateMachines;
using RichCreator.Maps;
using RichCreator.Utilitys;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using static RichCreator.Jobs.StateMachines.KillMonsterStateMachine;
using Utils = RichCreator.Utilitys.Utils;
 
namespace RichCreator.StateMachines
{
    public class MoveState
    {
        private const Int32 PaddingLeft = 140;//左边框内边距
        private const Int32 PaddingRight = 140;//右边框内边距
 
        public MoveState(ZTRectangle gameRect, HouseInfo house)
        {
            this.gameRect = gameRect;
            this.house = house;
            
            minCenterLineY = this.gameRect.End.Y + this.house.HouseCenterMoveLine - centerLineErrorRange;
            maxCenterLineY = this.gameRect.End.Y + this.house.HouseCenterMoveLine + centerLineErrorRange;
        }
 
        
 
        /// <summary>
        /// 步行速度,每100毫秒
        /// </summary>
        public static readonly ZTSizeDouble SpeedOfStep = new ZTSizeDouble(0.29d, 0.24d);
 
        /// <summary>
        /// 跑速度,每100毫秒
        /// </summary>
        public static readonly ZTSizeDouble SpeedOfRun = new ZTSizeDouble(0.66d, 0);
 
        /// <summary>
        /// 开始跑的阀值
        /// </summary>
        public static readonly double RunThresold = SpeedOfStep.Width*RandomUtils.KeyPressDurationMax+SpeedOfRun.Width*RandomUtils.KeyPressDurationMax;
 
        /// <summary>
        /// 左侧随机移动距离
        /// </summary>
        public static readonly Int32 LeftRandomMoveDistance = 600;
 
        /// <summary>
        /// 左侧随机移动毫秒数
        /// </summary>
        public static readonly double LeftRandomMoveMillSecond = LeftRandomMoveDistance / SpeedOfStep.Width;
 
        /// <summary>
        /// 上边随机移动距离
        /// </summary>
        public static readonly Int32 TopRandomMoveDistance = 300;
 
        /// <summary>
        /// 上边随机移动毫秒数
        /// </summary>
        public static readonly double TopRandomMoveMillSecond = TopRandomMoveDistance / SpeedOfStep.Height;
 
        /// <summary>
        /// 右侧随机移动距离
        /// </summary>
        public static readonly Int32 RightRandomMoveDistance = 600;
 
        /// <summary>
        /// 右侧随机移动毫秒数
        /// </summary>
        public static readonly double RightRandomMoveMillSecond = RightRandomMoveDistance / SpeedOfStep.Width;
 
        /// <summary>
        /// 下边随机移动距离
        /// </summary>
        public static readonly Int32 BottomRandomMoveDistance = 300;
 
 
        /// <summary>
        /// 下边随机移动毫秒数
        /// </summary>
        public static readonly double BottomRandomMoveMillSecond = BottomRandomMoveDistance / SpeedOfStep.Height;
 
 
 
        private Int32 minCenterLineY;
        private Int32 maxCenterLineY;
        private Int32 centerLineErrorRange = 35;//中间性可允许的误差
 
        private HouseInfo house;
        private ZTRectangle gameRect = ZTRectangle.Empty;
        
        private HIDCode moveKey = HIDCode.NoEvent;
        private MoveIntent movingIntent = MoveIntent.AttackMove;//移动意图
        private MoveMethod movingMethod= MoveMethod.Vertical;//移动方式,默认垂直移动
        private ZTSize movingDistance;//移动距离
 
 
        /// <summary>
        /// 按下的键,0:横向,1:纵向
        /// </summary>
        private HIDCode[] pressKeys = new HIDCode[] { HIDCode.NoEvent, HIDCode.NoEvent };
        private bool isRuning = false;
 
 
        /// <summary>
        /// 移动方式
        /// </summary>
        public enum MoveMethod
        {
            Vertical,//默认垂直移动
            ToLeft,//左移动
            ToRight,//右移动
            Fixed//固定离动距离
        }
 
        /// <summary>
        /// 移动意图
        /// </summary>
        public enum MoveIntent
        {
            None,//没移动
            AttackMove,//去攻击
            FindDoorMove,//去找门
            FindRoleMove,//找主角
            PickupMove//去拾取
        }
 
        /// <summary>
        /// 是否移动中
        /// </summary>
        public bool IsMoving
        {
            get
            {
                return pressKeys[0]!=HIDCode.NoEvent||pressKeys[1]!=HIDCode.NoEvent;
            }
        }
 
        /// <summary>
        /// 是否正在攻击移动
        /// </summary>
        /// <returns></returns>
        public bool IsAttackMoving
        {
            get
            {
                if (IsMoving && movingIntent == MoveIntent.AttackMove)
                {
                    return true;
                }
                return false;
            }
        }
 
        /// <summary>
        /// 是否正在查门移动
        /// </summary>
        /// <returns></returns>
        public bool IsFindDoorMoving
        {
            get
            {
                if (IsMoving && movingIntent == MoveIntent.FindDoorMove)
                {
                    return true;
                }
                return false;
            }
        }
 
 
        /// <summary>
        /// 是否正在查找主角移动
        /// </summary>
        /// <returns></returns>
        public bool IsFindRoleMoving
        {
            get
            {
                if (IsMoving && movingIntent == MoveIntent.FindRoleMove)
                {
                    return true;
                }
                return false;
            }
        }
 
 
        /// <summary>
        /// 是否正在去拾取移动
        /// </summary>
        /// <returns></returns>
        public bool IsPickupMoving
        {
            get
            {
                if (IsMoving && movingIntent == MoveIntent.PickupMove)
                {
                    return true;
                }
                return false;
            }
        }
 
        
        /// <summary>
        /// 攻击移动
        /// </summary>
        /// <param name="moveDistance"></param>
        public void AttackMove(ZTSize moveDistance)
        {
            PutKey(moveDistance);
            movingIntent = MoveIntent.AttackMove;
        }
 
        private Int32 RandomDirRun = 0;//随机行走的方向
        private DateTime FindRoleMoveTimeout = DateTime.MinValue;//方向移动过期时间
        private DateTime FindRoleStartTimeout = DateTime.MinValue;//开始查找主角移动过期时间
        /// <summary>
        /// 查找主角移动
        /// </summary>
        /// <param name="moveDistance"></param>
        public void FindRoleMove()
        {
            if (IsMoving && !IsFindRoleMoving)
            {
                StopMove();
            }
            const Int32 FindRoleMaxDelayMillSecond = 1000;//找角色开始移动最大延迟
            bool recomputationTimeoutTime = false;
            //延迟开始找角色
            if (!IsMoving)
            {
                if (FindRoleStartTimeout == DateTime.MinValue)
                {
                    //开始计时
                    FindRoleStartTimeout = DateTime.Now.AddMilliseconds(FindRoleMaxDelayMillSecond);
                    return;
                }
 
                if (DateTime.Now < FindRoleStartTimeout)
                {
                    //未超过延迟时间
                    return;
                }
 
                //计算超时
                recomputationTimeoutTime = true;
            }
            
            if (DateTime.Now>=FindRoleMoveTimeout)
            {
                //转换方向,计算超时
                RandomDirRun++;
                recomputationTimeoutTime = true;
            }
            
            HIDCode dirKey = HIDCode.NoEvent;
            switch (RandomDirRun % 4)
            {
                case 0:
                    dirKey = HIDCode.LeftArrow;
                    if (recomputationTimeoutTime)
                    {
                        FindRoleMoveTimeout = DateTime.Now.AddMilliseconds(LeftRandomMoveMillSecond);
                    }
                    
                    //movingDistance = new ZTPoint(-MoveMonitor.LeftRandomMoveDistance, 0);
                    break;
                case 1:
                    dirKey = HIDCode.UpArrow;
                    if (recomputationTimeoutTime)
                    {
                        FindRoleMoveTimeout = DateTime.Now.AddMilliseconds(TopRandomMoveMillSecond);
                    }
                    
                    //movingDistance = new ZTPoint(0, -MoveMonitor.TopRandomMoveDistance);
                    break;
                case 2:
                    dirKey = HIDCode.RightArrow;
                    if (recomputationTimeoutTime)
                    {
                        FindRoleMoveTimeout = DateTime.Now.AddMilliseconds(RightRandomMoveMillSecond);
                    }
                    
                    //movingDistance = new ZTPoint(MoveMonitor.RightRandomMoveDistance, 0);
                    break;
                case 3:
                    dirKey = HIDCode.DownArrow;
                    if (recomputationTimeoutTime)
                    {
                        FindRoleMoveTimeout = DateTime.Now.AddMilliseconds(BottomRandomMoveMillSecond);
                    }
                    
                    //movingDistance = new ZTPoint(0, MoveMonitor.BottomRandomMoveDistance);
                    break;
            }
 
            
 
            if (!IsMoving || (IsMoving && dirKey != moveKey))
            {
                G.Instance.InputControl.PutDown(false, false, false, false, false, false, false, false, dirKey);
                moveKey = dirKey;
            }
            movingIntent = MoveIntent.FindRoleMove;
        }
        
        /// <summary>
        /// 拾起物品移动
        /// </summary>
        public void PickupMove(ZTPoint rolePosition,ZTPoint thingItemPosition)
        {
            ZTSize moveDistance = new ZTSize(thingItemPosition.X - rolePosition.X, thingItemPosition.Y - rolePosition.Y - 97);
            if (Math.Abs(moveDistance.Width) < 100 && Math.Abs(moveDistance.Height)<100)
            {
                //距离允许,就近距离移动并X
                G.Instance.DebugWriter("distance ok");
                SyncMove(moveDistance);
                G.Instance.InputControl.PressKey(RandomUtils.G(400, 500), HIDCode.X);
                return;
            }
 
            //G.Instance.DebugWriter("pickup distance:" + moveDistance.ToString());
            PutKey(moveDistance);
            movingIntent = MoveIntent.PickupMove;   
        }
 
        /// <summary>
        /// 找门移动
        /// </summary>
        /// <param name="rolePosition"></param>
        public void FindDoorMove(ZTPoint rolePosition)
        {
            ComputeMoveInfo(rolePosition);
 
            HIDCode dirKey = HIDCode.NoEvent;
            switch (movingMethod)
            {
                case MoveMethod.ToLeft:
                    dirKey = HIDCode.LeftArrow;
                    break;
                case MoveMethod.ToRight:
                    dirKey = HIDCode.RightArrow;
                    break;
                case MoveMethod.Vertical:
                    dirKey = movingDistance.Height > 0 ? HIDCode.DownArrow : HIDCode.UpArrow;
                    break;
                case MoveMethod.Fixed:
                    SyncMove(movingDistance);
                    ReleaseKey();
                    return;
            }
            
            PutKey(movingDistance);
            movingIntent = MoveIntent.FindDoorMove;
        }
 
 
        private ZTPoint roleLastPosition = ZTPoint.Empty;
        private bool StaticTimerIsStart = false;//静止计时是否开始
        private Int32 StaticTimerCounter = 0;//静止计时计数器
        private DateTime DetectLastNoMoveTime = DateTime.MaxValue;//最后没移动时间
        private const Int32 NoMoveMaxMillSecond = 2000;//最大未移动容忍毫秒数
 
        /// <summary>
        /// 得到循环移动的距离
        /// </summary>
        /// <returns></returns>
        private void ComputeMoveInfo(ZTPoint rolePosition)
        {
            ZTRectangle limitRect = ZTRectangle.Empty;
            
            //达到未移动阀值,可能有障碍物,先攻击,如果攻击后还是无效则上下左右移
            if (rolePosition .Equals( this.roleLastPosition))
            {
                if (StaticTimerIsStart)
                {
                    if ((DateTime.Now - DetectLastNoMoveTime).TotalMilliseconds > NoMoveMaxMillSecond)
                    {
                        G.Instance.DebugWriter($"find door not move,role position:{rolePosition.ToString()}");
                        this.StopMove();
                        if (StaticTimerCounter==0)
                        {
                            //清除障碍物                            
                            G.Instance.InputControl.PressKey(RandomUtils.KeyPressDuration, HIDCode.X);
                        }
                        else
                        {
                            //无法清除障碍物,随机移动一下
                            switch (StaticTimerCounter % 4)
                            {
                                case 0:
                                    G.Instance.DebugWriter("random up");
                                    //上
                                    movingDistance = new ZTSize(0, -TopRandomMoveDistance);
                                    break;
                                case 1:
                                    //右
                                    movingDistance = new ZTSize(RightRandomMoveDistance, 0);
                                    
                                    break;
                                case 2:
                                    //下
                                    movingDistance = new ZTSize(0, BottomRandomMoveDistance);
                                    break;
                                case 3:
                                    //左
                                    movingDistance = new ZTSize(-LeftRandomMoveDistance, 0);
                                    break;
                            }
                            
                            movingMethod = MoveMethod.Fixed;
                        }
                        StaticTimerCounter++;
                        DetectLastNoMoveTime = DateTime.Now;
                        if (StaticTimerCounter > 1)
                        {
                            return;
                        }
                    }
                    
                }
                else if (!StaticTimerIsStart)
                {
                    //没开始计时 则 开始计时
                    StaticTimerIsStart = true;
                    DetectLastNoMoveTime = DateTime.Now;
                }
            }
            else
            {
                //移动了 取消计时
                this.roleLastPosition = rolePosition;
                StaticTimerIsStart = false;
                StaticTimerCounter = 0;
            }
 
            if (!IsMoving)
            {
                //刚开始移动
                movingMethod = MoveMethod.Vertical;
            }
 
            if (movingMethod == MoveMethod.Vertical && rolePosition.Y >= minCenterLineY && rolePosition.Y <= maxCenterLineY)
            {
                //不需要上下移动,计算左右
                if (this.house.DoorDirection[0] == Direction.Left)
                {
                    movingMethod = MoveMethod.ToLeft;
                }
                else if (this.house.DoorDirection[0] == Direction.Right)
                {
                    movingMethod = MoveMethod.ToRight;
                }
                else
                {
                    //计算是向左还是右,哪边大往哪边
                    if (rolePosition.X > (this.gameRect.Start.X + (this.gameRect.End.X - this.gameRect.Start.X) / 2))
                    {
                        //左边空间大
                        movingMethod = MoveMethod.ToLeft;
                    }
                    else
                    {
                        movingMethod = MoveMethod.ToRight;
                    }
                }
            }
 
            if (movingMethod == MoveMethod.ToLeft)
            {
                //计算左边界范围 
                limitRect = new ZTRectangle(gameRect.Start.X, gameRect.Start.Y, gameRect.Start.X + PaddingLeft, gameRect.End.Y);
                //判断是否到左边界
                if (Utils.IsInRect(rolePosition, limitRect))
                {
                    //到左边界就向右走
                    movingMethod = MoveMethod.ToRight;
                    movingDistance = new ZTSize(gameRect.End.X - rolePosition.X, 0);
                }
                else
                {
                    //没到继续向左走
                    movingMethod = MoveMethod.ToLeft;
                    movingDistance = new ZTSize(limitRect.Start.X - rolePosition.X, 0);
                }
            }
            else if (movingMethod == MoveMethod.ToRight)
            {
                //计算右边界范围 
                limitRect = new ZTRectangle(gameRect.End.X - PaddingRight, gameRect.Start.Y, gameRect.End.X, gameRect.End.Y);
                //判断是否到右边界
                if (Utils.IsInRect(rolePosition, limitRect))
                {
                    //到右边界就向左走
                    G.Instance.InfoWriter($"in limit rect,role position:{rolePosition.ToString()},limit:{limitRect.ToString()}");
                    movingMethod = MoveMethod.ToLeft;
                    movingDistance = new ZTSize(gameRect.Start.X - rolePosition.X, 0);
                }
                else
                {
                    //没到继续向右走
                    movingMethod = MoveMethod.ToRight;
                    movingDistance = new ZTSize(gameRect.End.X - rolePosition.X, 0);
                }
            }
            else
            {
                //向点移动
                Int32 targetY = gameRect.End.Y + this.house.HouseCenterMoveLine;
                movingDistance = new ZTSize(0, targetY - rolePosition.Y);
            }
        }
        
        /// <summary>
        /// 停止移动
        /// </summary>
        public void StopMove()
        {
            if (IsMoving)
            {
                //停止
                ReleaseKey();
            }
        }
 
        /// <summary>
        /// 同步移动指定距离
        /// </summary>
        /// <param name="distance"></param>
        public void SyncMove(ZTSize distance)
        {
            HIDCode horizontal = HIDCode.NoEvent;
            HIDCode vertical = HIDCode.NoEvent;
            bool isRun = false;
            int runms, stepms;
            Int32 xsig = Math.Sign(distance.Width);
            Int32 ysig = Math.Sign(distance.Height);
            
            if (Math.Abs(distance.Width) >= RunThresold)
            {
                isRun = true;
            }
 
            if (distance.Height > 0)
            {
                vertical = HIDCode.DownArrow;
            }
 
            if (distance.Height < 0)
            {
                vertical = HIDCode.UpArrow;
            }
 
            if (distance.Width > 0)
            {
                horizontal = HIDCode.RightArrow;
            }
 
            if (distance.Width < 0)
            {
                horizontal = HIDCode.LeftArrow;
            }
 
            PutKey(out stepms, out runms, horizontal, vertical, isRun);
            if (stepms > 0)
            {
                Int32 mdistance = (Int32)(stepms * SpeedOfStep.Width);
                if (runms > 0)
                {
                    mdistance += (Int32)(runms * SpeedOfRun.Width);
                }
                distance = new ZTSize(distance.Width - xsig*mdistance, distance.Height);
            }
 
            int ytime = (Int32)(Math.Abs(distance.Height) / SpeedOfStep.Height);
            Int32 xtime = (Int32)(Math.Abs(distance.Width) / SpeedOfStep.Width);
            if (isRun)
            {
                xtime = (Int32)(Math.Abs(distance.Width) / SpeedOfRun.Width);
            }
 
 
 
            Int32 mintime = Math.Min(xtime, ytime);
            if (xtime <= 0)
            {
                mintime = ytime;
            }
            if (ytime <= 0)
            {
                mintime = xtime;
            }
            Thread.Sleep(mintime);
 
            xtime -= mintime;
            ytime -= mintime;
            if (xtime > 0)
            {
                PutKey(out stepms, out runms, horizontal, HIDCode.NoEvent, isRun);
                Thread.Sleep(xtime);
            }
            if (ytime > 0)
            {
                PutKey(out stepms, out runms, HIDCode.NoEvent, vertical, isRun);
                Thread.Sleep(ytime);
            }
            StopMove();
        }
 
        /// <summary>
        /// 同步移动指定距离
        /// </summary>
        /// <param name="distance"></param>
        public void SyncMove(ZTPoint distance)
        {
            SyncMove(new ZTSize(distance.X, distance.Y));
        }
 
 
        #region 八方向移动
        /// <summary>
        /// 按下按键
        /// </summary>
        /// <param name="distance"></param>
        private void PutKey(ZTSize distance)
        {
            HIDCode horizontal = HIDCode.NoEvent;
            HIDCode vertical = HIDCode.NoEvent;
            bool isRun = false;
            if (distance.Width < 0)
            {
                horizontal = HIDCode.LeftArrow;
            }
            if (distance.Width > 0)
            {
                horizontal = HIDCode.RightArrow;
            }
 
            if (Math.Abs(distance.Width) >= RunThresold)
            {
                isRun = true;
            }
 
 
            if (distance.Height < 0)
            {
                vertical = HIDCode.UpArrow;
            }
            if (distance.Height > 0)
            {
                vertical = HIDCode.DownArrow;
            }
 
            Int32 stepms, runms;
            PutKey(out stepms,out runms,horizontal, vertical, isRun);
        }
 
 
        /// <summary>
        /// 按下按键
        /// </summary>
        /// <param name="horizontal"></param>
        /// <param name="vertical"></param>
        private void PutKey(out Int32 stepMS,out Int32 runMS,HIDCode horizontal, HIDCode vertical,bool isRun)
        {
            stepMS = 0;
            runMS = 0;
            if (horizontal == vertical)
            {
                return;
            }
            if (horizontal == pressKeys[0] && vertical == pressKeys[1])
            {
                return;
            }
 
            int keyCount = horizontal != HIDCode.NoEvent && vertical != HIDCode.NoEvent ? 2 : 1;
            Int32 tempwait = 0;
            if (isRun)
            {
                //跑
                if (!isRuning || horizontal != pressKeys[0])
                {
                    //如果之前没有跑,或跑的方向不一样,则开始跑
                    G.Instance.InputControl.PutDown(false, false, false, false, false, false, false, false, horizontal);
                    tempwait = RandomUtils.KeyPressDuration;
                    stepMS += tempwait;
                    Thread.Sleep(tempwait);
 
                    G.Instance.InputControl.PutDown(false, false, false, false, false, false, false, false);
                    Thread.Sleep(RandomUtils.KeyPressDuration);
                    G.Instance.InputControl.PutDown(false, false, false, false, false, false, false, false, horizontal);
                    isRuning = true;
                    
                    if (keyCount == 2)
                    {
                        tempwait = RandomUtils.KeyPressDuration;
                        runMS += tempwait;
                        Thread.Sleep(tempwait);
                        G.Instance.InputControl.PutDown(false, false, false, false, false, false, false, false, horizontal, vertical);
                    }
 
                }
                else
                {
                    //奔跑方向不变
                    int afterKeyCount = pressKeys[0] != HIDCode.NoEvent && pressKeys[1] != HIDCode.NoEvent ? 2 : 1;
                    if (afterKeyCount != keyCount)
                    {
                        //如果跟原来按键数量不一样
                        if (keyCount == 1)
                        {
                            G.Instance.InputControl.PutDown(false, false, false, false, false, false, false, false, horizontal);
                        }
                        else
                        {
                            G.Instance.InputControl.PutDown(false, false, false, false, false, false, false, false, horizontal, vertical);
                        }
                        
                    }
                    
                }
            }
            else
            {
                //走
                if (keyCount == 1)
                {
                    G.Instance.InputControl.PutDown(false, false, false, false, false, false, false, false, horizontal != HIDCode.NoEvent?horizontal:vertical);
                }
                else
                {
                    G.Instance.InputControl.PutDown(false, false, false, false, false, false, false, false, horizontal, vertical);
                }
                
            }
 
            pressKeys[0] = horizontal;
            pressKeys[1] = vertical;
        }
 
        /// <summary>
        /// 释放按键
        /// </summary>
        private void ReleaseKey()
        {
            G.Instance.InputControl.PutDown(false, false, false, false, false, false, false, false);
            pressKeys[0] = HIDCode.NoEvent;
            pressKeys[1] = HIDCode.NoEvent;
            isRuning = false;
        }
 
 
 
#endregion
 
        
    }
}