adding logic to re evaluate nodes

This commit is contained in:
Flerp 2025-10-31 06:20:49 -07:00
parent 340ec5221e
commit 04802e3938

View File

@ -8,6 +8,7 @@
#include "ChatCommand.h"
#include "Player.h"
#include "GameObject.h"
#include "GameTime.h"
#include <vector>
#include <limits>
@ -30,8 +31,8 @@ namespace
189978,189979,189980,189981,195036,
};
static GameObject* FindNearestVein(Player* player, float maxRange)
{
static GameObject* FindNearestReadyVein(Player* player, float maxRange, float minDistanceFromPlayer)
{
GameObject* nearest = nullptr;
float nearestDist = std::numeric_limits<float>::infinity();
@ -40,6 +41,15 @@ namespace
if (GameObject* go = player->FindNearestGameObject(entry, maxRange))
{
float d = player->GetDistance(go);
if (d < minDistanceFromPlayer)
continue;
if (go->IsInUse())
continue;
if (go->GetLootState() != GO_READY)
continue;
if (d <= maxRange && d < nearestDist)
{
nearest = go;
@ -48,20 +58,23 @@ namespace
}
}
return nearest;
}
}
static bool DoTeleNode(Player* player)
{
{
if (!player)
return false;
if (player->IsInCombat())
{
ChatHandler(player->GetSession()).PSendSysMessage("You can't use this while in combat.");
return true; // handled
return true;
}
if (GameObject* node = FindNearestVein(player, TELEPORT_DISTANCE))
// Skip anything within ~8 yards so we don't pick the node we just mined
constexpr float kMinReTeleportDist = 8.0f;
if (GameObject* node = FindNearestReadyVein(player, TELEPORT_DISTANCE, kMinReTeleportDist))
{
player->TeleportTo(
node->GetMapId(),
@ -76,7 +89,6 @@ namespace
ChatHandler(player->GetSession()).PSendSysMessage("No mining nodes found within range.");
}
return true;
}
}
class telenode_commandscript : public CommandScript