BotModuleAutoBattle.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using DeepCore;
  2. using DeepCore.Game3D.Slave;
  3. using DeepCore.Game3D.Slave.Layer;
  4. using DeepCore.Reflection;
  5. using System;
  6. namespace DeepMMO.Client.BotTest.Runner.Modules
  7. {
  8. public class BotModuleAutoBattle : BotModule
  9. {
  10. private Random random = new Random();
  11. public BotModuleAutoBattle(BotRunner r) : base(r)
  12. {
  13. base.Client.OnZoneActorEntered += Client_OnZoneActorEntered;
  14. }
  15. private void Client_OnZoneActorEntered(LayerPlayer obj)
  16. {
  17. obj.SendUnitGuard(base.IsEnable);
  18. obj.Parent.AddTimePeriodicMS(Config.RandomMoveIntervalMS, OnMoveTick);
  19. }
  20. protected override void OnEnableChanged(bool enable)
  21. {
  22. var obj = Client.CurrentZoneActor;
  23. if (obj != null)
  24. {
  25. obj.SendUnitGuard(base.IsEnable);
  26. }
  27. }
  28. protected override void OnUpdate(int intervalMS)
  29. {
  30. base.OnUpdate(intervalMS);
  31. }
  32. private void OnMoveTick(TimeTaskMS tick)
  33. {
  34. var obj = Client.CurrentZoneActor;
  35. if (obj != null)
  36. {
  37. obj.SendUnitGuard(base.IsEnable);
  38. if (base.IsEnable)
  39. {
  40. if (obj.Parent.Terrain3D is VoxelClientTerrain3D vt)
  41. {
  42. var pos = obj.Position;
  43. if (vt.World.Terrain.TryGetVoxelLayerByObject(ref pos, out var cell, out var layer))
  44. {
  45. int size = Math.Max(1, (int)(Config.RandomMoveDistance / vt.World.Terrain.GridCellSize));
  46. var tp = vt.World.FindNearRandomMoveableNode(random, layer, size);
  47. //if (pos != null)
  48. {
  49. //var pos = Terrain.GetUpwardCenterPos(tp);//layer.UpwardCenterPos
  50. obj.SendUnitAttackMoveTo(tp.UpwardCenterPos, false);
  51. }
  52. }
  53. }
  54. }
  55. }
  56. }
  57. [Desc("自动战斗配置")]
  58. [Expandable]
  59. public class Config : BotModuleConfig
  60. {
  61. [Desc("自动随机移动时间间隔")]
  62. public static int RandomMoveIntervalMS = 60000;
  63. [Desc("自动随机移动距离")]
  64. public static float RandomMoveDistance = 100;
  65. }
  66. }
  67. }