BotLauncher.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using System.Windows.Forms;
  6. using DeepCore.Reflection;
  7. using DeepMMO.Client.BotTest.Runner;
  8. namespace DeepMMO.Client.BotTest
  9. {
  10. public static class BotLauncher
  11. {
  12. public static string DefaultBotPrefix { get; private set; }
  13. public static int DefaultBotCount { get; private set; }
  14. public static bool NoBattleView { get; private set; } = false;
  15. public static bool IsAuto { get; private set; }
  16. private static bool first_start = true;
  17. public static FormLauncher Start(string[] args)
  18. {
  19. var argp = DeepCore.Properties.ParseArgs(args);
  20. return Start(argp);
  21. }
  22. public static FormLauncher Start(DeepCore.Properties argp)
  23. {
  24. string b_name = argp.Get("name");
  25. string b_count = argp.Get("count");
  26. if (argp.TryGetAsBool("noView", out var noView))
  27. {
  28. NoBattleView = noView;
  29. }
  30. if (b_name != null && b_count != null)
  31. {
  32. BotLauncher.IsAuto = true;
  33. BotLauncher.DefaultBotPrefix = b_name;
  34. BotLauncher.DefaultBotCount = int.Parse(b_count);
  35. }
  36. else
  37. {
  38. BotLauncher.IsAuto = false;
  39. }
  40. var launcher = new FormLauncher();
  41. launcher.Shown += Launcher_Shown;
  42. launcher.OnStart += Launcher_OnStart;
  43. return launcher;
  44. }
  45. private static void Launcher_Shown(object sender, EventArgs e)
  46. {
  47. if (IsAuto && first_start)
  48. {
  49. first_start = false;
  50. (sender as FormLauncher).Start();
  51. }
  52. }
  53. private static void Launcher_OnStart(FormLauncher sender, BotConfig config)
  54. {
  55. var bot = new FormBotTest(config);
  56. bot.FormClosed += new FormClosedEventHandler((object sender2, FormClosedEventArgs e2) =>
  57. {
  58. sender.Show();
  59. });
  60. bot.Show();
  61. }
  62. public static string ArgsHelper
  63. {
  64. get
  65. {
  66. return @"name=xxx count=100";
  67. }
  68. }
  69. }
  70. }