BotRunner.Module.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using DeepCore;
  2. using DeepCore.FuckPomeloClient;
  3. using DeepCore.Log;
  4. using DeepCore.Reflection;
  5. using System;
  6. namespace DeepMMO.Client.BotTest.Runner
  7. {
  8. public partial class BotRunner
  9. {
  10. private HashMap<Type, BotModule> modules = new HashMap<Type, BotModule>();
  11. internal void SetStatus(string text)
  12. {
  13. this.status.Value = text;
  14. }
  15. }
  16. //--------------------------------------------------------------------------------------------------------
  17. public abstract class BotModuleConfig
  18. {
  19. public override string ToString()
  20. {
  21. var attr = PropertyUtil.GetAttribute<DescAttribute>(GetType());
  22. return attr != null ? attr.Desc : base.ToString();
  23. }
  24. }
  25. public abstract class BotModule
  26. {
  27. //------------------------------------------------------------------------
  28. private static HashMap<Type, bool> s_SubModules = new HashMap<Type, bool>();
  29. internal static void InitRunnerModules()
  30. {
  31. foreach (var mt in BotFactory.Instance.GetModuleTypes())
  32. {
  33. s_SubModules.Add(mt, true);
  34. }
  35. }
  36. public static void SetModuleEnable(Type type, bool value)
  37. {
  38. s_SubModules[type] = value;
  39. }
  40. public static bool GetModuleEnable(Type type)
  41. {
  42. bool enable = false;
  43. if (s_SubModules.TryGetValue(type, out enable))
  44. {
  45. return enable;
  46. }
  47. return false;
  48. }
  49. //------------------------------------------------------------------------
  50. private bool m_Enable;
  51. protected RPGClient Client { get; private set; }
  52. protected PomeloClient GateClient { get { return Client.GateClient; } }
  53. protected PomeloClient GameClient { get { return Client.GameClient; } }
  54. protected BotRunner Runner { get; private set; }
  55. protected Logger log { get; private set; }
  56. public bool IsEnable { get { return m_Enable; } }
  57. public BotModule(BotRunner r)
  58. {
  59. this.Runner = r;
  60. this.Client = r.Client;
  61. this.log = r.LogEvents;
  62. this.m_Enable = GetModuleEnable(GetType());
  63. }
  64. internal void InternalUpdate(int intervalMS)
  65. {
  66. bool enable = GetModuleEnable(GetType());
  67. if (m_Enable != enable)
  68. {
  69. m_Enable = enable;
  70. this.OnEnableChanged(enable);
  71. }
  72. this.OnUpdate(intervalMS);
  73. }
  74. protected virtual void OnUpdate(int intervalMS) { }
  75. protected virtual void OnEnableChanged(bool enable) { }
  76. protected void SetStatus(string text)
  77. {
  78. this.Runner.SetStatus(text);
  79. }
  80. }
  81. }