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