BotModuleAutoBattle.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using DeepCore;
  7. using DeepCore.Reflection;
  8. namespace DeepMMO.Client.BotTest.Runner.Modules
  9. {
  10. public class BotModuleAutoBattle : BotModule
  11. {
  12. private Random random = new Random();
  13. public BotModuleAutoBattle(BotRunner r) : base(r)
  14. {
  15. base.Client.OnZoneActorEntered += Client_OnZoneActorEntered;
  16. }
  17. private void Client_OnZoneActorEntered(DeepCore.GameSlave.ZoneActor obj)
  18. {
  19. obj.SendUnitGuard(base.IsEnable);
  20. obj.Parent.AddTimePeriodicMS(Config.RandomMoveIntervalMS, OnMoveTick);
  21. }
  22. protected override void OnEnableChanged(bool enable)
  23. {
  24. var obj = Client.CurrentZoneActor;
  25. if (obj != null)
  26. {
  27. obj.SendUnitGuard(base.IsEnable);
  28. }
  29. }
  30. protected override void OnUpdate(int intervalMS)
  31. {
  32. base.OnUpdate(intervalMS);
  33. }
  34. private void OnMoveTick(TimeTaskMS tick)
  35. {
  36. var obj = Client.CurrentZoneActor;
  37. if (obj != null)
  38. {
  39. obj.SendUnitGuard(base.IsEnable);
  40. if (base.IsEnable)
  41. {
  42. var pos = obj.Parent.PathFinderTerrain.FindNearRandomMoveableNode(random, obj.X, obj.Y, Config.RandomMoveDistance, false);
  43. if (pos != null)
  44. {
  45. obj.SendUnitAttackMoveTo(pos.x, pos.y, 0, false);
  46. }
  47. }
  48. }
  49. }
  50. [Desc("自动战斗配置")]
  51. [Expandable]
  52. public class Config : BotModuleConfig
  53. {
  54. [Desc("自动随机移动时间间隔")]
  55. public static int RandomMoveIntervalMS = 60000;
  56. [Desc("自动随机移动距离")]
  57. public static float RandomMoveDistance = 100;
  58. }
  59. }
  60. }