mob_movement_manager.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #pragma once
  2. #include <memory>
  3. #include "../Entity.h"
  4. #include "../../common/Mutex.h"
  5. class Mob;
  6. class Client;
  7. struct RotateCommand;
  8. struct MovementCommand;
  9. struct MobMovementEntry;
  10. struct PlayerPositionUpdateServer_Struct;
  11. enum ClientRange : int
  12. {
  13. ClientRangeNone = 0,
  14. ClientRangeClose = 1,
  15. ClientRangeMedium = 2,
  16. ClientRangeCloseMedium = 3,
  17. ClientRangeLong = 4,
  18. ClientRangeCloseLong = 5,
  19. ClientRangeMediumLong = 6,
  20. ClientRangeAny = 7
  21. };
  22. enum MobMovementMode : int
  23. {
  24. MovementWalking = 0,
  25. MovementRunning = 1
  26. };
  27. enum MobStuckBehavior : int
  28. {
  29. RunToTarget,
  30. WarpToTarget,
  31. TakeNoAction,
  32. EvadeCombat,
  33. MaxStuckBehavior
  34. };
  35. class MobMovementManager
  36. {
  37. public:
  38. ~MobMovementManager();
  39. void Process();
  40. void AddMob(Spawn *mob);
  41. void RemoveMob(Spawn*mob);
  42. void AddClient(Client *client);
  43. void RemoveClient(Client *client);
  44. void RotateTo(Spawn *who, float to, MobMovementMode mob_movement_mode = MovementRunning);
  45. void Teleport(Spawn *who, float x, float y, float z, float heading);
  46. void NavigateTo(Spawn *who, float x, float y, float z, MobMovementMode mode = MovementRunning, bool overrideDistance=false);
  47. void StopNavigation(Spawn *who);
  48. void DisruptNavigation(Spawn *who);
  49. /*
  50. void SendCommandToClients(
  51. Entity *mob,
  52. float delta_x,
  53. float delta_y,
  54. float delta_z,
  55. float delta_heading,
  56. int anim,
  57. ClientRange range,
  58. Client* single_client = nullptr,
  59. Client* ignore_client = nullptr
  60. );*/
  61. float FixHeading(float in);
  62. void ClearStats();
  63. static MobMovementManager &Get() {
  64. static MobMovementManager inst;
  65. return inst;
  66. }
  67. MobMovementManager();
  68. bool IsRunningCommandProcess() {
  69. bool isRunning = false;
  70. MobListMutex.readlock();
  71. isRunning = RunningCommandProcess;
  72. MobListMutex.releasereadlock();
  73. return isRunning;
  74. }
  75. bool SetCommandProcess(bool status) {
  76. MobListMutex.writelock();
  77. RunningCommandProcess = status;
  78. MobListMutex.releasewritelock();
  79. }
  80. private:
  81. MobMovementManager(const MobMovementManager&);
  82. MobMovementManager& operator=(const MobMovementManager&);
  83. void UpdatePath(Spawn *who, float x, float y, float z, MobMovementMode mob_movement_mode);
  84. void UpdatePathGround(Spawn *who, float x, float y, float z, MobMovementMode mode);
  85. void UpdatePathUnderwater(Spawn *who, float x, float y, float z, MobMovementMode movement_mode);
  86. void UpdatePathBoat(Spawn *who, float x, float y, float z, MobMovementMode mode);
  87. void PushTeleportTo(MobMovementEntry &ent, float x, float y, float z, float heading);
  88. void PushMoveTo(MobMovementEntry &ent, float x, float y, float z, MobMovementMode mob_movement_mode);
  89. void PushSwimTo(MobMovementEntry &ent, float x, float y, float z, MobMovementMode mob_movement_mode);
  90. void PushRotateTo(MobMovementEntry &ent, Spawn *who, float to, MobMovementMode mob_movement_mode);
  91. void PushStopMoving(MobMovementEntry &mob_movement_entry);
  92. void PushEvadeCombat(MobMovementEntry &mob_movement_entry);
  93. void HandleStuckBehavior(Spawn *who, float x, float y, float z, MobMovementMode mob_movement_mode);
  94. struct Implementation;
  95. std::unique_ptr<Implementation> _impl;
  96. Mutex MobListMutex;
  97. bool RunningCommandProcess;
  98. };