reverting to more dumb checks

This commit is contained in:
Flerp 2025-10-31 07:11:49 -07:00
parent a5a4636ac9
commit 4b88ac3ed6

View File

@ -7,17 +7,14 @@
#include "EventProcessor.h" #include "EventProcessor.h"
#include <vector> #include <vector>
#include <list>
#include <limits> #include <limits>
#include <cstdint> #include <cstdint>
#include <cmath>
using namespace Acore::ChatCommands; using namespace Acore::ChatCommands;
static constexpr float TELEPORT_DISTANCE = 250.0f; static constexpr float TELEPORT_DISTANCE = 250.0f;
static constexpr float Z_BUMP = 1.5f; static constexpr float Z_BUMP = 1.5f;
static constexpr float MIN_RETELEPORT_DIST = 8.0f; static constexpr float MIN_RETELEPORT_DIST = 1.0f;
static constexpr float MIN_COORD_DELTA = 6.0f;
static constexpr uint32 RECHECK_DELAY_MS = 3000; static constexpr uint32 RECHECK_DELAY_MS = 3000;
static const std::vector<uint32> kVeinEntries = { static const std::vector<uint32> kVeinEntries = {
@ -29,41 +26,21 @@ static const std::vector<uint32> kVeinEntries = {
189978,189979,189980,189981,195036, 189978,189979,189980,189981,195036,
}; };
static inline float Dist3(float ax, float ay, float az, float bx, float by, float bz) static GameObject* FindNearestReadyVein(Player* player, float maxRange)
{
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; GameObject* nearest = nullptr;
float nearestDist = std::numeric_limits<float>::infinity(); float nearestDist = std::numeric_limits<float>::infinity();
for (uint32 entry : kVeinEntries) for (uint32 entry : kVeinEntries)
{ {
std::list<GameObject*> lst; if (GameObject* go = player->FindNearestGameObject(entry, maxRange))
player->GetGameObjectListWithEntryInGrid(lst, entry, maxRange);
for (GameObject* go : lst)
{ {
if (!go || !go->IsInWorld())
continue;
if (go->getLootState() != LootState::GO_READY) if (go->getLootState() != LootState::GO_READY)
continue; continue;
if (go->GetGoState() != GOState::GO_STATE_READY) if (go->GetGoState() != GOState::GO_STATE_READY)
continue; continue;
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); float d = player->GetDistance(go);
if (d < minDistanceFromPlayer)
continue;
if (d <= maxRange && d < nearestDist) if (d <= maxRange && d < nearestDist)
{ {
nearest = go; nearest = go;
@ -71,22 +48,25 @@ static GameObject* FindNearestReadyVeinScan(Player* player, float maxRange, floa
} }
} }
} }
return nearest; return nearest;
} }
class TeleNodeRecheckEvent : public BasicEvent class TeleNodeRecheckEvent : public BasicEvent
{ {
public: public:
TeleNodeRecheckEvent(Player* player, float lastX, float lastY, float lastZ) TeleNodeRecheckEvent(Player* player, uint64 lastNodeGuidRaw)
: _player(player), _lastX(lastX), _lastY(lastY), _lastZ(lastZ) { } : _player(player), _lastNodeGuidRaw(lastNodeGuidRaw) { }
bool Execute(uint64, uint32) override bool Execute(uint64, uint32) override
{ {
if (!_player || !_player->IsInWorld()) if (!_player || !_player->IsInWorld())
return true; return true;
if (GameObject* node = FindNearestReadyVeinScan(_player, TELEPORT_DISTANCE, MIN_RETELEPORT_DIST, _lastX, _lastY, _lastZ, MIN_COORD_DELTA)) if (GameObject* node = FindNearestReadyVein(_player, TELEPORT_DISTANCE))
{
if (node->GetGUID().GetRawValue() != _lastNodeGuidRaw)
{
if (_player->GetDistance(node) >= MIN_RETELEPORT_DIST)
{ {
_player->TeleportTo( _player->TeleportTo(
node->GetMapId(), node->GetMapId(),
@ -96,12 +76,14 @@ public:
node->GetOrientation() node->GetOrientation()
); );
} }
}
}
return true; return true;
} }
private: private:
Player* _player; Player* _player;
float _lastX, _lastY, _lastZ; uint64 _lastNodeGuidRaw;
}; };
static bool DoTeleNode(Player* player) static bool DoTeleNode(Player* player)
@ -115,24 +97,20 @@ static bool DoTeleNode(Player* player)
return true; return true;
} }
if (GameObject* node = FindNearestReadyVeinScan(player, TELEPORT_DISTANCE, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)) if (GameObject* node = FindNearestReadyVein(player, TELEPORT_DISTANCE))
{ {
const float nx = node->GetPositionX(); uint64 lastGuid = node->GetGUID().GetRawValue();
const float ny = node->GetPositionY();
const float nz = node->GetPositionZ();
player->TeleportTo( player->TeleportTo(
node->GetMapId(), node->GetMapId(),
nx, node->GetPositionX(),
ny, node->GetPositionY(),
nz + Z_BUMP, node->GetPositionZ() + Z_BUMP,
node->GetOrientation() node->GetOrientation()
); );
player->m_Events.AddEvent( player->m_Events.AddEvent(new TeleNodeRecheckEvent(player, lastGuid),
new TeleNodeRecheckEvent(player, nx, ny, nz), player->m_Events.CalculateTime(RECHECK_DELAY_MS));
player->m_Events.CalculateTime(RECHECK_DELAY_MS)
);
} }
else else
{ {