From 04802e39383bd84f324d88629afbf3ecdc2d4af1 Mon Sep 17 00:00:00 2001 From: Flerp Date: Fri, 31 Oct 2025 06:20:49 -0700 Subject: [PATCH] adding logic to re evaluate nodes --- src/teleport-to-node.cpp | 86 +++++++++++++++++++++++----------------- 1 file changed, 49 insertions(+), 37 deletions(-) diff --git a/src/teleport-to-node.cpp b/src/teleport-to-node.cpp index bc26410..5d4892b 100644 --- a/src/teleport-to-node.cpp +++ b/src/teleport-to-node.cpp @@ -8,6 +8,7 @@ #include "ChatCommand.h" #include "Player.h" #include "GameObject.h" +#include "GameTime.h" #include #include @@ -30,53 +31,64 @@ namespace 189978,189979,189980,189981,195036, }; - static GameObject* FindNearestVein(Player* player, float maxRange) - { - GameObject* nearest = nullptr; - float nearestDist = std::numeric_limits::infinity(); + static GameObject* FindNearestReadyVein(Player* player, float maxRange, float minDistanceFromPlayer) +{ + GameObject* nearest = nullptr; + float nearestDist = std::numeric_limits::infinity(); - for (uint32 entry : kVeinEntries) + for (uint32 entry : kVeinEntries) + { + if (GameObject* go = player->FindNearestGameObject(entry, maxRange)) { - 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) { - float d = player->GetDistance(go); - if (d <= maxRange && d < nearestDist) - { - nearest = go; - nearestDist = d; - } + nearest = go; + nearestDist = d; } } - return nearest; } + return nearest; +} - static bool DoTeleNode(Player* player) + static bool DoTeleNode(Player* player) +{ + if (!player) + return false; + + if (player->IsInCombat()) { - if (!player) - return false; - - if (player->IsInCombat()) - { - ChatHandler(player->GetSession()).PSendSysMessage("You can't use this while in combat."); - return true; // handled - } - - if (GameObject* node = FindNearestVein(player, TELEPORT_DISTANCE)) - { - player->TeleportTo( - node->GetMapId(), - node->GetPositionX(), - node->GetPositionY(), - node->GetPositionZ() + Z_BUMP, - node->GetOrientation() - ); - } - else - { - ChatHandler(player->GetSession()).PSendSysMessage("No mining nodes found within range."); - } + ChatHandler(player->GetSession()).PSendSysMessage("You can't use this while in combat."); return true; } + + // 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(), + node->GetPositionX(), + node->GetPositionY(), + node->GetPositionZ() + Z_BUMP, + node->GetOrientation() + ); + } + else + { + ChatHandler(player->GetSession()).PSendSysMessage("No mining nodes found within range."); + } + return true; } class telenode_commandscript : public CommandScript