Просмотр исходного кода

机器人运行成功!运行步骤如下:
1 启动服务器 dotnet Server.App.dll --Process=1 --Console=1
2 启动机器人 dotnet Robot.App.dll --AppType=Robot --Process=2 --Console=1
3 机器人进程中使用命令行创建机器人 CreateRobot --Num=3 创建3个机器人

tanghai 4 лет назад
Родитель
Сommit
e9f2adb83b

+ 23 - 10
Robot/Hotfix/Robot/Console/CreateRobotConsoleHandler.cs

@@ -13,7 +13,6 @@ namespace ET
             switch (content)
             {
                 case ConsoleMode.CreateRobot:
-                    contex.Parent.RemoveComponent<ModeContex>();
                     Log.Console("CreateRobot args error!");
                     break;
                 default:
@@ -23,19 +22,33 @@ namespace ET
                             .WithParsed(o => { options = o; });
 
                     // 获取当前进程的RobotScene
-                    List<StartSceneConfig> robotSceneConfigs = StartSceneConfigCategory.Instance.GetByProcess(Game.Options.Process);
-                    // 创建机器人
-                    for (int i = 0; i < options.Num; ++i)
+                    using (ListComponent<StartSceneConfig> thisProcessRobotScenes = ListComponent<StartSceneConfig>.Create())
                     {
-                        int index = i % robotSceneConfigs.Count;
-                        StartSceneConfig robotSceneConfig = robotSceneConfigs[index];
-                        Scene robotScene = Game.Scene.Get(robotSceneConfig.Id);
-                        RobotManagerComponent robotManagerComponent = robotScene.GetComponent<RobotManagerComponent>();
-                        await robotManagerComponent.NewRobot(Game.Options.Process * 10000 + i);
+                        List<StartSceneConfig> robotSceneConfigs = StartSceneConfigCategory.Instance.Robots;
+                        foreach (StartSceneConfig robotSceneConfig in robotSceneConfigs)
+                        {
+                            if (robotSceneConfig.Process != Game.Options.Process)
+                            {
+                                continue;
+                            }
+                            thisProcessRobotScenes.List.Add(robotSceneConfig);
+                        }
+                        
+                        // 创建机器人
+                        for (int i = 0; i < options.Num; ++i)
+                        {
+                            int index = i % thisProcessRobotScenes.List.Count;
+                            StartSceneConfig robotSceneConfig = thisProcessRobotScenes.List[index];
+                            Scene robotScene = Game.Scene.Get(robotSceneConfig.Id);
+                            RobotManagerComponent robotManagerComponent = robotScene.GetComponent<RobotManagerComponent>();
+                            Scene robot = await robotManagerComponent.NewRobot(Game.Options.Process * 10000 + i);
+                            Log.Console($"create robot {robot.Zone}");
+                            await TimerComponent.Instance.WaitAsync(2000);
+                        }
                     }
                     break;
             }
-            
+            contex.Parent.RemoveComponent<ModeContex>();
             await ETTask.CompletedTask;
         }
     }

+ 4 - 1
Robot/Model/Robot/Console/CreateRobotArgs.cs

@@ -1,7 +1,10 @@
+using CommandLine;
+
 namespace ET
 {
     public class CreateRobotArgs
     {
-        public int Num;
+        [Option("Num", Required = false, Default = 1)]
+        public int Num { get; set; }
     }
 }

+ 1 - 1
Unity/Assets/Model/Core/Options.cs

@@ -13,7 +13,7 @@ namespace ET
     
     public class Options
     {
-        [Option("ServerType", Required = false, Default = AppType.Server, HelpText = "serverType enum")]
+        [Option("AppType", Required = false, Default = AppType.Server, HelpText = "serverType enum")]
         public AppType AppType { get; set; }
 
         [Option("Process", Required = false, Default = 1)]