diff --git a/src/teleport-to-node.cpp b/src/teleport-to-node.cpp index 4cb3889..54ae864 100644 --- a/src/teleport-to-node.cpp +++ b/src/teleport-to-node.cpp @@ -10,12 +10,14 @@ #include #include #include +#include using namespace Acore::ChatCommands; static constexpr float TELEPORT_DISTANCE = 250.0f; static constexpr float Z_BUMP = 1.5f; -static constexpr float MIN_RETELEPORT_DIST = 1.0f; +static constexpr float MIN_RETELEPORT_DIST = 8.0f; +static constexpr float MIN_COORD_DELTA = 6.0f; static constexpr uint32 RECHECK_DELAY_MS = 3000; static const std::vector kVeinEntries = { @@ -27,7 +29,13 @@ static const std::vector kVeinEntries = { 189978,189979,189980,189981,195036, }; -static GameObject* FindNearestReadyVeinScan(Player* player, float maxRange, uint64 guidToExclude, float minDistance) +static inline float Dist3(float ax, float ay, float az, float bx, float by, float bz) +{ + const float dx = ax - bx, dy = ay - by, dz = az - bz; + return std::sqrt(dx*dx + dy*dy + dz*dz); +} + +static GameObject* FindNearestReadyVeinScan(Player* player, float maxRange, float minDistanceFromPlayer, float excludeX, float excludeY, float excludeZ, float excludeRadius) { GameObject* nearest = nullptr; float nearestDist = std::numeric_limits::infinity(); @@ -40,15 +48,22 @@ static GameObject* FindNearestReadyVeinScan(Player* player, float maxRange, uint { if (!go || !go->IsInWorld()) continue; - if (guidToExclude && go->GetGUID().GetRawValue() == guidToExclude) - continue; if (go->getLootState() != LootState::GO_READY) continue; if (go->GetGoState() != GOState::GO_STATE_READY) continue; - float d = player->GetDistance(go); - if (d < minDistance) + + const float gx = go->GetPositionX(); + const float gy = go->GetPositionY(); + const float gz = go->GetPositionZ(); + + if (excludeRadius > 0.0f && Dist3(gx, gy, gz, excludeX, excludeY, excludeZ) < excludeRadius) continue; + + float d = player->GetDistance(go); + if (d < minDistanceFromPlayer) + continue; + if (d <= maxRange && d < nearestDist) { nearest = go; @@ -63,15 +78,15 @@ static GameObject* FindNearestReadyVeinScan(Player* player, float maxRange, uint class TeleNodeRecheckEvent : public BasicEvent { public: - TeleNodeRecheckEvent(Player* player, uint64 lastNodeGuidRaw) - : _player(player), _lastNodeGuidRaw(lastNodeGuidRaw) { } + TeleNodeRecheckEvent(Player* player, float lastX, float lastY, float lastZ) + : _player(player), _lastX(lastX), _lastY(lastY), _lastZ(lastZ) { } bool Execute(uint64, uint32) override { if (!_player || !_player->IsInWorld()) return true; - if (GameObject* node = FindNearestReadyVeinScan(_player, TELEPORT_DISTANCE, _lastNodeGuidRaw, MIN_RETELEPORT_DIST)) + if (GameObject* node = FindNearestReadyVeinScan(_player, TELEPORT_DISTANCE, MIN_RETELEPORT_DIST, _lastX, _lastY, _lastZ, MIN_COORD_DELTA)) { _player->TeleportTo( node->GetMapId(), @@ -86,7 +101,7 @@ public: private: Player* _player; - uint64 _lastNodeGuidRaw; + float _lastX, _lastY, _lastZ; }; static bool DoTeleNode(Player* player) @@ -100,20 +115,24 @@ static bool DoTeleNode(Player* player) return true; } - if (GameObject* node = FindNearestReadyVeinScan(player, TELEPORT_DISTANCE, 0, 0.0f)) + if (GameObject* node = FindNearestReadyVeinScan(player, TELEPORT_DISTANCE, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)) { - uint64 lastGuid = node->GetGUID().GetRawValue(); + const float nx = node->GetPositionX(); + const float ny = node->GetPositionY(); + const float nz = node->GetPositionZ(); player->TeleportTo( node->GetMapId(), - node->GetPositionX(), - node->GetPositionY(), - node->GetPositionZ() + Z_BUMP, + nx, + ny, + nz + Z_BUMP, node->GetOrientation() ); - player->m_Events.AddEvent(new TeleNodeRecheckEvent(player, lastGuid), - player->m_Events.CalculateTime(RECHECK_DELAY_MS)); + player->m_Events.AddEvent( + new TeleNodeRecheckEvent(player, nx, ny, nz), + player->m_Events.CalculateTime(RECHECK_DELAY_MS) + ); } else {