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 "ChatCommand.h"
#include "Player.h" #include "Player.h"
#include "GameObject.h" #include "GameObject.h"
#include "GameTime.h"
#include <vector> #include <vector>
#include <limits> #include <limits>
@ -30,7 +31,7 @@ namespace
189978,189979,189980,189981,195036, 189978,189979,189980,189981,195036,
}; };
static GameObject* FindNearestVein(Player* player, float maxRange) static GameObject* FindNearestReadyVein(Player* player, float maxRange, float minDistanceFromPlayer)
{ {
GameObject* nearest = nullptr; GameObject* nearest = nullptr;
float nearestDist = std::numeric_limits<float>::infinity(); float nearestDist = std::numeric_limits<float>::infinity();
@ -40,6 +41,15 @@ namespace
if (GameObject* go = player->FindNearestGameObject(entry, maxRange)) if (GameObject* go = player->FindNearestGameObject(entry, maxRange))
{ {
float d = player->GetDistance(go); float d = player->GetDistance(go);
if (d < minDistanceFromPlayer)
continue;
if (go->IsInUse())
continue;
if (go->GetLootState() != GO_READY)
continue;
if (d <= maxRange && d < nearestDist) if (d <= maxRange && d < nearestDist)
{ {
nearest = go; nearest = go;
@ -58,10 +68,13 @@ namespace
if (player->IsInCombat()) if (player->IsInCombat())
{ {
ChatHandler(player->GetSession()).PSendSysMessage("You can't use this while in combat."); 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( player->TeleportTo(
node->GetMapId(), node->GetMapId(),
@ -77,7 +90,6 @@ namespace
} }
return true; return true;
} }
}
class telenode_commandscript : public CommandScript class telenode_commandscript : public CommandScript
{ {