From f25f89101a98ad815c0ae2d25e1a8dc35d53a5dd Mon Sep 17 00:00:00 2001
From: asmrobot <asmrobot@hotmail.com>
Date: Tue, 29 Oct 2019 13:55:37 +0000
Subject: [PATCH] format state machine

---
 src/RichCreator/Maps/Lindong/LindongMap.cs |  132 +++++++++++++++++--------------------------
 1 files changed, 53 insertions(+), 79 deletions(-)

diff --git a/src/RichCreator/Maps/Lindong/LindongMap.cs b/src/RichCreator/Maps/Lindong/LindongMap.cs
index 4e0c17e..e8d4e85 100644
--- a/src/RichCreator/Maps/Lindong/LindongMap.cs
+++ b/src/RichCreator/Maps/Lindong/LindongMap.cs
@@ -24,27 +24,27 @@
         /// NextIndex=-1,完成
         /// NextIndex=-2,出错
         /// </summary>
-        internal static MapHouse[] Houses = new MapHouse[] {
-            new MapHouse (){ Index=0 ,NextIndex=1 , OpenStatusDetectIndex=1 , HouseCenterMoveLine=-250,IsEnd=false,DoorDirection=new[]{Direction.Right } },
-            new MapHouse (){ Index=1 ,NextIndex=5 , OpenStatusDetectIndex=5 , HouseCenterMoveLine=-250,IsEnd=false,DoorDirection=new[]{Direction.Bottom } },
-            new MapHouse (){ Index=2 ,NextIndex=1 , OpenStatusDetectIndex=1 , HouseCenterMoveLine=-250,IsEnd=false,DoorDirection=new[]{Direction.Left } },
-            new MapHouse (){ Index=3 ,NextIndex=2 , OpenStatusDetectIndex=2 , HouseCenterMoveLine=-250,IsEnd=false,DoorDirection=new[]{Direction.Left } },
-            new MapHouse (){ Index=4 ,NextIndex=8 , OpenStatusDetectIndex=8 , HouseCenterMoveLine=-250,IsEnd=false,DoorDirection=new[]{Direction.Bottom } },
-            new MapHouse (){ Index=5 ,NextIndex=4 , OpenStatusDetectIndex=4 , HouseCenterMoveLine=-250,IsEnd=false,DoorDirection=new[]{Direction.Left } },
-            new MapHouse (){ Index=6 ,NextIndex=5 , OpenStatusDetectIndex=5 , HouseCenterMoveLine=-250,IsEnd=false,DoorDirection=new[]{Direction.Left } },
-            new MapHouse (){ Index=7 ,NextIndex=6 , OpenStatusDetectIndex=6 , HouseCenterMoveLine=-250,IsEnd=false,DoorDirection=new[]{Direction.Left } },
-            new MapHouse (){ Index=8 ,NextIndex=12 ,OpenStatusDetectIndex=12, HouseCenterMoveLine=-148,IsEnd=false,DoorDirection=new[]{Direction.Right,Direction.Bottom } },
-            new MapHouse (){ Index=9 ,NextIndex=10, OpenStatusDetectIndex=10, HouseCenterMoveLine=-300,IsEnd=false,DoorDirection=new[]{Direction.Right,Direction.Bottom } },
-            new MapHouse (){ Index=10,NextIndex=14, OpenStatusDetectIndex=14, HouseCenterMoveLine=-250,IsEnd=false,DoorDirection=new[]{Direction.Bottom } },
-            new MapHouse (){ Index=11,NextIndex=10, OpenStatusDetectIndex=10, HouseCenterMoveLine=-250,IsEnd=false,DoorDirection=new[]{Direction.Left } },
-            new MapHouse (){ Index=12,NextIndex=13, OpenStatusDetectIndex=12, HouseCenterMoveLine=-220,IsEnd=false,DoorDirection=new[]{Direction.Right } },
-            new MapHouse (){ Index=13,NextIndex=14, OpenStatusDetectIndex=14, HouseCenterMoveLine=-320,IsEnd=false,DoorDirection=new[]{Direction.Right } },
-            new MapHouse (){ Index=14,NextIndex=15, OpenStatusDetectIndex=-1, HouseCenterMoveLine=-320,IsEnd=false,DoorDirection=new[]{Direction.Right } },
-            new MapHouse (){ Index=15,NextIndex=-1, OpenStatusDetectIndex=-1, HouseCenterMoveLine=-250,IsEnd=true, DoorDirection=new[]{Direction.Right } },
-            new MapHouse (){ Index=16,NextIndex=12, OpenStatusDetectIndex=12, HouseCenterMoveLine=-250,IsEnd=false,DoorDirection=new[]{Direction.Up } },
-            new MapHouse (){ Index=17,NextIndex=13, OpenStatusDetectIndex=13, HouseCenterMoveLine=-250,IsEnd=false,DoorDirection=new[]{Direction.Up } },
-            new MapHouse (){ Index=18,NextIndex=14, OpenStatusDetectIndex=14, HouseCenterMoveLine=-250,IsEnd=false,DoorDirection=new[]{Direction.Up } },
-            new MapHouse (){ Index=19,NextIndex=15, OpenStatusDetectIndex=15, HouseCenterMoveLine=-250,IsEnd=false,DoorDirection=new[]{Direction.Up } }
+        internal static HouseInfo[] Houses = new HouseInfo[] {
+            new HouseInfo (){ Index=0 ,NextIndex=1 , OpenStatusDetectIndex=1 , HouseCenterMoveLine=-250,IsEnd=false,DoorDirection=new[]{Direction.Right } },
+            new HouseInfo (){ Index=1 ,NextIndex=5 , OpenStatusDetectIndex=5 , HouseCenterMoveLine=-250,IsEnd=false,DoorDirection=new[]{Direction.Bottom } },
+            new HouseInfo (){ Index=2 ,NextIndex=1 , OpenStatusDetectIndex=1 , HouseCenterMoveLine=-250,IsEnd=false,DoorDirection=new[]{Direction.Left } },
+            new HouseInfo (){ Index=3 ,NextIndex=2 , OpenStatusDetectIndex=2 , HouseCenterMoveLine=-250,IsEnd=false,DoorDirection=new[]{Direction.Left } },
+            new HouseInfo (){ Index=4 ,NextIndex=8 , OpenStatusDetectIndex=8 , HouseCenterMoveLine=-250,IsEnd=false,DoorDirection=new[]{Direction.Bottom } },
+            new HouseInfo (){ Index=5 ,NextIndex=4 , OpenStatusDetectIndex=4 , HouseCenterMoveLine=-250,IsEnd=false,DoorDirection=new[]{Direction.Left } },
+            new HouseInfo (){ Index=6 ,NextIndex=5 , OpenStatusDetectIndex=5 , HouseCenterMoveLine=-250,IsEnd=false,DoorDirection=new[]{Direction.Left } },
+            new HouseInfo (){ Index=7 ,NextIndex=6 , OpenStatusDetectIndex=6 , HouseCenterMoveLine=-250,IsEnd=false,DoorDirection=new[]{Direction.Left } },
+            new HouseInfo (){ Index=8 ,NextIndex=12 ,OpenStatusDetectIndex=12, HouseCenterMoveLine=-148,IsEnd=false,DoorDirection=new[]{Direction.Right,Direction.Bottom } },
+            new HouseInfo (){ Index=9 ,NextIndex=10, OpenStatusDetectIndex=10, HouseCenterMoveLine=-300,IsEnd=false,DoorDirection=new[]{Direction.Right,Direction.Bottom } },
+            new HouseInfo (){ Index=10,NextIndex=14, OpenStatusDetectIndex=14, HouseCenterMoveLine=-250,IsEnd=false,DoorDirection=new[]{Direction.Bottom } },
+            new HouseInfo (){ Index=11,NextIndex=10, OpenStatusDetectIndex=10, HouseCenterMoveLine=-250,IsEnd=false,DoorDirection=new[]{Direction.Left } },
+            new HouseInfo (){ Index=12,NextIndex=13, OpenStatusDetectIndex=12, HouseCenterMoveLine=-220,IsEnd=false,DoorDirection=new[]{Direction.Right } },
+            new HouseInfo (){ Index=13,NextIndex=14, OpenStatusDetectIndex=14, HouseCenterMoveLine=-320,IsEnd=false,DoorDirection=new[]{Direction.Right } },
+            new HouseInfo (){ Index=14,NextIndex=15, OpenStatusDetectIndex=-1, HouseCenterMoveLine=-320,IsEnd=false,DoorDirection=new[]{Direction.Right } },
+            new HouseInfo (){ Index=15,NextIndex=-1, OpenStatusDetectIndex=-1, HouseCenterMoveLine=-250,IsEnd=true, DoorDirection=new[]{Direction.Right } },
+            new HouseInfo (){ Index=16,NextIndex=12, OpenStatusDetectIndex=12, HouseCenterMoveLine=-250,IsEnd=false,DoorDirection=new[]{Direction.Up } },
+            new HouseInfo (){ Index=17,NextIndex=13, OpenStatusDetectIndex=13, HouseCenterMoveLine=-250,IsEnd=false,DoorDirection=new[]{Direction.Up } },
+            new HouseInfo (){ Index=18,NextIndex=14, OpenStatusDetectIndex=14, HouseCenterMoveLine=-250,IsEnd=false,DoorDirection=new[]{Direction.Up } },
+            new HouseInfo (){ Index=19,NextIndex=15, OpenStatusDetectIndex=15, HouseCenterMoveLine=-250,IsEnd=false,DoorDirection=new[]{Direction.Up } }
         };
 
         static LindongMap()
@@ -172,16 +172,16 @@
         /// <summary>
         /// 小地图区域
         /// </summary>
-        public ZTPoint MinimapPoint = ZTPoint.Empty;
+        public Utility.Structs.ZTPoint MinimapPoint = Utility.Structs.ZTPoint.Empty;
 
         //小地图距游戏区域的偏移
-        private ZTPoint minimapPointOffset = new ZTPoint(1201, 47);
+        private Utility.Structs.ZTPoint minimapPointOffset = new Utility.Structs.ZTPoint(1201, 47);
 
         public CancellationToken cancellationToken { get; set; }
 
         private Int32 runningStep = RunningStep.None;
         
-        public override bool Start(ZTRectangle gameRect, CancellationToken cancelToken,Int32 runningStep)
+        public override ZTResult Start(ZTRectangle gameRect, CancellationToken cancelToken,Int32 runningStep)
         {
             this.runningStep = runningStep;
             this.GameRect = gameRect;
@@ -194,22 +194,22 @@
             {
                 if (!MoveToSunan())
                 {
-                    return false;
+                    return ZTResult.Failed;
                 }
 
                 if (!MoveToShikongzhimen())
                 {
-                    return false;
+                    return ZTResult.Failed;
                 }
 
                 if (!MoveToChoiceTaskPage())
                 {
-                    return false;
+                    return ZTResult.Failed;
                 }
 
                 if (!IntoTaskRoom())
                 {
-                    return false;
+                    return ZTResult.Failed;
                 }
 
                 G.Instance.InfoWriter("成功进入副本");
@@ -220,13 +220,13 @@
                 //重复刷,直到疲劳值不够了
                 if (this.cancellationToken.IsCancellationRequested)
                 {
-                    return false;
+                    return ZTResult.Cancel;
                 }
 
-                bool killResult = true;
+                
                 DateTime startHouse = DateTime.Now;
-                killResult = KillMonster();
-                if (killResult)
+                ZTResult killResult = KillMonster();
+                if (killResult==ZTResult.Success)
                 {
                     //捡东西
                     G.Instance.InputControl.PressKey(RandomUtils.KeyPressDuration, HIDCode.V);
@@ -250,7 +250,7 @@
                     if (pilaozhi <= 0)
                     {
                         ExitToTown();
-                        return true;
+                        return ZTResult.Success;
                     }
 
                     ReplayGame();
@@ -258,10 +258,9 @@
                 }
                 else
                 {
-                    break;
+                    return killResult;
                 }
             }
-            return false;
         }
 
         /// <summary>
@@ -270,7 +269,7 @@
         private void ExitToTown()
         {
             G.Instance.DebugWriter("返回城镇");
-            ZTPoint point = new ZTPoint(this.GameRect.End.X - 124, this.GameRect.Start.Y + 146);
+            Utility.Structs.ZTPoint point = new Utility.Structs.ZTPoint(this.GameRect.End.X - 124, this.GameRect.Start.Y + 146);
             G.Instance.InputControl.MoveToAndClick(point);
             Thread.Sleep(5000);
         }
@@ -281,7 +280,7 @@
         private void ReplayGame()
         {
             G.Instance.DebugWriter("重新挑战");
-            ZTPoint point = new ZTPoint(this.GameRect.End.X - 132, this.GameRect.Start.Y + 90);
+            Utility.Structs.ZTPoint point = new Utility.Structs.ZTPoint(this.GameRect.End.X - 132, this.GameRect.Start.Y + 90);
             G.Instance.InputControl.MoveToAndClick(point);
         }
 
@@ -289,9 +288,8 @@
         /// 刷房间
         /// </summary>
         /// <returns></returns>
-        private bool KillMonster()
+        private ZTResult KillMonster()
         {
-            Int32 result = 0;
             bool ret = false;
 
 
@@ -305,7 +303,7 @@
             if (!findResult)
             {
                 G.Instance.InfoWriter("未找到进入凛冬的文字");
-                return false;
+                return ZTResult.Failed;
             }
             G.Instance.InfoWriter("进入凛冬");
 
@@ -330,24 +328,24 @@
                 if (!ret)
                 {
                     G.Instance.InfoWriter("未找到人物所在房间");
-                    break;
+                    return ZTResult.Failed;
                 }
 
                 G.Instance.InfoWriter("进入房间->" + houseIndex.ToString());
                 
 
                 DateTime roomStartTime = DateTime.Now;
-                KillMonsterStateMachine kmsm = new KillMonsterStateMachine(Houses[houseIndex], this.MinimapPoint, this.GameRect, preHouseIndex,this.runningStep);
-                result = kmsm.Start(cancellationToken, 5 * 60 * 1000);
+                KillMonsterStateMachine kmsm = new KillMonsterStateMachine(Houses[houseIndex], this.MinimapPoint, this.GameRect, preHouseIndex,this.runningStep, cancellationToken);
+                ZTResult smresult = kmsm.Work( 5 * 60 * 1000);
                 Int32 roomTotalSecond = (Int32)(DateTime.Now - roomStartTime).TotalSeconds;
                 G.Instance.InfoWriter("房间刷完,用时:" + (roomTotalSecond / 60) + "分" + (roomTotalSecond % 60) + "秒");
                 runningStep = RunningStep.None;
-                if (result == JobResult.Success)
+                if (smresult == ZTResult.Success)
                 {
                     if (houseIndex == 15)
                     {
                         //所有房间刷完
-                        return true;
+                        return ZTResult.Success;
                     }
 
                     //刷其它房间
@@ -355,11 +353,9 @@
                 }
                 else
                 {
-                    break;
+                    return smresult;
                 }
             }
-            
-            return false;
         }
         
         /// <summary>
@@ -371,7 +367,7 @@
             bool result = FuncUtils.NoChangeRetryCallWrap(
                () =>
                {
-
+                   WindowUtils.SetDnfToTop();
                    CloseAllAlertWindow(this.cancellationToken, this.GameRect);
                    //向下走出赛丽亚的房间  ,走向素喃
                    G.Instance.InputControl.PressKey(2000, HIDCode.DownArrow);
@@ -396,24 +392,6 @@
                    return DnfCVHelper.IsInSaiLiYaHouse(this.GameRect);
                });
             return result;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-            
         }
 
         /// <summary>
@@ -422,15 +400,15 @@
         /// <returns></returns>
         private bool MoveToShikongzhimen()
         {
-            bool result=FuncUtils.NoChangeRetryCallWrap(() =>
+            bool result= FuncUtils.NoChangeRetryCallWrap(() =>
             {
                 //打开地图
-                ZTPoint mapButtonPosition = new ZTPoint(this.GameRect.End.X - 14, this.GameRect.Start.Y + 16);
+                Utility.Structs.ZTPoint mapButtonPosition = new Utility.Structs.ZTPoint(this.GameRect.End.X - 14, this.GameRect.Start.Y + 16);
                 G.Instance.InputControl.MoveToAndClick(mapButtonPosition);
                 Thread.Sleep(1000);
-                
+
                 //点到副本之前的地图
-                ZTPoint mapPrePosition = new ZTPoint(this.GameRect.Start.X + 382, this.GameRect.Start.Y + 252);
+                Utility.Structs.ZTPoint mapPrePosition = new Utility.Structs.ZTPoint(this.GameRect.Start.X + 382, this.GameRect.Start.Y + 252);
                 G.Instance.InputControl.MoveToAndClick(mapPrePosition);
 
                 //关闭地图框
@@ -561,7 +539,7 @@
                 return true; 
             }
 
-            G.Instance.InputControl.MoveToAndClick(new ZTPoint(this.GameRect.Start.X + 508, this.GameRect.Start.Y + 552));
+            G.Instance.InputControl.MoveToAndClick(new Utility.Structs.ZTPoint(this.GameRect.Start.X + 508, this.GameRect.Start.Y + 552));
             Thread.Sleep(5000);
             image = ScreenCapture.Instance.CaptureScreenReturnImage();
             if (LindongCVHelper.GetChoiceLingdongNandu(out nandu, image, this.GameRect))
@@ -646,7 +624,6 @@
 
             if (!result)
             {
-                //todo:remove
                 G.Instance.InfoWriter("装备文字未取到");
                 return false;
             }
@@ -654,7 +631,7 @@
 
 
             //开始点,每格步进30
-            ZTPoint startPoint = new ZTPoint( equipmentTextRect.End.X-30,equipmentTextRect.End.Y+9);
+            Utility.Structs.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++)
@@ -665,9 +642,9 @@
                 int col = index % 8;
                 int x = col * 30+15;
                 int y = row * 30+15;
-                
+
                 //点窗格
-                G.Instance.InputControl.MoveToAndClick(new ZTPoint(startPoint.X+x,startPoint.Y+y));
+                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);
@@ -680,8 +657,5 @@
             G.Instance.InputControl.PressKey(RandomUtils.KeyPressDuration, HIDCode.Escape);
             return true;
         }
-
-
-
     }
 }

--
Gitblit v1.9.3