CreateRobotConsoleHandler.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. using System.Collections.Generic;
  3. using CommandLine;
  4. using NLog;
  5. namespace ET
  6. {
  7. [ConsoleHandler(ConsoleMode.CreateRobot)]
  8. public class CreateRobotConsoleHandler: IConsoleHandler
  9. {
  10. public async ETTask Run(ModeContex contex, string content)
  11. {
  12. switch (content)
  13. {
  14. case ConsoleMode.CreateRobot:
  15. contex.Parent.RemoveComponent<ModeContex>();
  16. Log.Console("CreateRobot args error!");
  17. break;
  18. default:
  19. CreateRobotArgs options = null;
  20. Parser.Default.ParseArguments<CreateRobotArgs>(content.Split(' '))
  21. .WithNotParsed(error => throw new Exception($"CreateRobotArgs error!"))
  22. .WithParsed(o => { options = o; });
  23. // 获取当前进程的RobotScene
  24. List<StartSceneConfig> robotSceneConfigs = StartSceneConfigCategory.Instance.GetByProcess(Game.Options.Process);
  25. // 创建机器人
  26. for (int i = 0; i < options.Num; ++i)
  27. {
  28. int index = i % robotSceneConfigs.Count;
  29. StartSceneConfig robotSceneConfig = robotSceneConfigs[index];
  30. Scene robotScene = Game.Scene.Get(robotSceneConfig.Id);
  31. RobotManagerComponent robotManagerComponent = robotScene.GetComponent<RobotManagerComponent>();
  32. await robotManagerComponent.NewRobot(Game.Options.Process * 10000 + i);
  33. }
  34. break;
  35. }
  36. await ETTask.CompletedTask;
  37. }
  38. }
  39. }