BotLauncher.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 IsAuto { get; private set; }
  15. private static bool first_start = true;
  16. public static FormLauncher Start(string[] args)
  17. {
  18. var argp = DeepCore.Properties.ParseArgs(args);
  19. return Start(argp);
  20. }
  21. public static FormLauncher Start(DeepCore.Properties argp)
  22. {
  23. string b_name = argp.Get("name");
  24. string b_count = argp.Get("count");
  25. if (b_name != null && b_count != null)
  26. {
  27. BotLauncher.IsAuto = true;
  28. BotLauncher.DefaultBotPrefix = b_name;
  29. BotLauncher.DefaultBotCount = int.Parse(b_count);
  30. }
  31. else
  32. {
  33. BotLauncher.IsAuto = false;
  34. }
  35. var launcher = new FormLauncher();
  36. launcher.Shown += Launcher_Shown;
  37. launcher.OnStart += Launcher_OnStart;
  38. return launcher;
  39. }
  40. private static void Launcher_Shown(object sender, EventArgs e)
  41. {
  42. if (IsAuto && first_start)
  43. {
  44. first_start = false;
  45. (sender as FormLauncher).Start();
  46. }
  47. }
  48. private static void Launcher_OnStart(FormLauncher sender, BotConfig config)
  49. {
  50. var bot = new FormBotTest(config);
  51. bot.FormClosed += new FormClosedEventHandler((object sender2, FormClosedEventArgs e2) =>
  52. {
  53. sender.Show();
  54. });
  55. bot.Show();
  56. }
  57. public static string ArgsHelper
  58. {
  59. get
  60. {
  61. return @"name=xxx count=100";
  62. }
  63. }
  64. }
  65. }