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,53 +31,64 @@ namespace
189978,189979,189980,189981,195036,
};
static GameObject* FindNearestVein(Player* player, float maxRange)
{
GameObject* nearest = nullptr;
float nearestDist = std::numeric_limits<float>::infinity();
static GameObject* FindNearestReadyVein(Player* player, float maxRange, float minDistanceFromPlayer)
{
GameObject* nearest = nullptr;
float nearestDist = std::numeric_limits<float>::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