mob_movement_manager.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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(Entity *mob);
  41. void RemoveMob(Entity *mob);
  42. void AddClient(Client *client);
  43. void RemoveClient(Client *client);
  44. void RotateTo(Entity *who, float to, MobMovementMode mob_movement_mode = MovementRunning);
  45. void Teleport(Entity *who, float x, float y, float z, float heading);
  46. void NavigateTo(Entity *who, float x, float y, float z, MobMovementMode mode = MovementRunning, bool overrideDistance=false);
  47. void StopNavigation(Entity *who);
  48. void DisruptNavigation(Entity* 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. return true;
  80. }
  81. private:
  82. MobMovementManager(const MobMovementManager&);
  83. MobMovementManager& operator=(const MobMovementManager&);
  84. void UpdatePath(Entity *who, float x, float y, float z, MobMovementMode mob_movement_mode);
  85. void UpdatePathGround(Entity *who, float x, float y, float z, MobMovementMode mode);
  86. void UpdatePathUnderwater(Entity *who, float x, float y, float z, MobMovementMode movement_mode);
  87. void UpdatePathBoat(Entity *who, float x, float y, float z, MobMovementMode mode);
  88. void PushTeleportTo(MobMovementEntry &ent, float x, float y, float z, float heading);
  89. void PushMoveTo(MobMovementEntry &ent, float x, float y, float z, MobMovementMode mob_movement_mode);
  90. void PushSwimTo(MobMovementEntry &ent, float x, float y, float z, MobMovementMode mob_movement_mode);
  91. void PushRotateTo(MobMovementEntry &ent, Entity *who, float to, MobMovementMode mob_movement_mode);
  92. void PushStopMoving(MobMovementEntry &mob_movement_entry);
  93. void PushEvadeCombat(MobMovementEntry &mob_movement_entry);
  94. void HandleStuckBehavior(Entity *who, float x, float y, float z, MobMovementMode mob_movement_mode);
  95. struct Implementation;
  96. std::unique_ptr<Implementation> _impl;
  97. Mutex MobListMutex;
  98. bool RunningCommandProcess;
  99. };