Compare commits
8 Commits
8d607c248f
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
02ac3d3dac | ||
|
|
42110c57ca | ||
|
|
4b88ac3ed6 | ||
|
|
a5a4636ac9 | ||
|
|
ba8018c0ce | ||
|
|
bc6891d443 | ||
|
|
161d29515d | ||
|
|
b1c6fabaec |
@@ -4,17 +4,18 @@
|
|||||||
#include "ChatCommand.h"
|
#include "ChatCommand.h"
|
||||||
#include "Player.h"
|
#include "Player.h"
|
||||||
#include "GameObject.h"
|
#include "GameObject.h"
|
||||||
#include "ObjectAccessor.h"
|
#include "EventProcessor.h"
|
||||||
#include "Timer.h"
|
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
using namespace Acore::ChatCommands;
|
using namespace Acore::ChatCommands;
|
||||||
|
|
||||||
static constexpr float TELEPORT_DISTANCE = 250.0f;
|
static constexpr float TELEPORT_DISTANCE = 250.0f;
|
||||||
static constexpr float Z_BUMP = 1.0f;
|
static constexpr float Z_BUMP = 1.5f;
|
||||||
static constexpr uint32 RECHECK_INTERVAL_MS = 5000;
|
static constexpr float MIN_RETELEPORT_DIST = 1.0f;
|
||||||
|
static constexpr uint32 RECHECK_DELAY_MS = 100;
|
||||||
|
|
||||||
static const std::vector<uint32> kVeinEntries = {
|
static const std::vector<uint32> kVeinEntries = {
|
||||||
324,1610,1667,1731,1732,1733,1734,2054,2055,3763,3764,19903,
|
324,1610,1667,1731,1732,1733,1734,2054,2055,3763,3764,19903,
|
||||||
@@ -25,49 +26,90 @@ static const std::vector<uint32> kVeinEntries = {
|
|||||||
189978,189979,189980,189981,195036,
|
189978,189979,189980,189981,195036,
|
||||||
};
|
};
|
||||||
|
|
||||||
static GameObject* FindNearestVein(Player* player, float maxRange)
|
static const std::vector<uint32> kHerbEntries = {
|
||||||
|
1618,1617,1619,1620,1621,2045,1622,1623,1628,1624,2041,2042,2046,2043,2044,2866,
|
||||||
|
142140,142141,142142,142143,142144,142145,176583,176584,176639,176586,176640,
|
||||||
|
176587,176641,176588,176589,181270,183044,181271,181272,183045,181277,181275,
|
||||||
|
183043,181276,181278,181279,181282,181280,181285,181281,181284,190169,190170,
|
||||||
|
189973,191019,190172,190171,190176
|
||||||
|
};
|
||||||
|
|
||||||
|
static GameObject* FindNearestReady(Player* player, float maxRange, const std::vector<uint32>& entries)
|
||||||
{
|
{
|
||||||
GameObject* nearest = nullptr;
|
GameObject* nearest = nullptr;
|
||||||
float nearestDist = std::numeric_limits<float>::infinity();
|
float nearestDist = std::numeric_limits<float>::infinity();
|
||||||
|
|
||||||
for (uint32 entry : kVeinEntries)
|
for (uint32 entry : entries)
|
||||||
{
|
{
|
||||||
if (GameObject* go = player->FindNearestGameObject(entry, maxRange))
|
if (GameObject* go = player->FindNearestGameObject(entry, maxRange))
|
||||||
{
|
{
|
||||||
float dist = player->GetDistance(go);
|
if (go->getLootState() != LootState::GO_READY)
|
||||||
if (dist <= maxRange && dist < nearestDist)
|
continue;
|
||||||
|
if (go->GetGoState() != GOState::GO_STATE_READY)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
float d = player->GetDistance(go);
|
||||||
|
if (d <= maxRange && d < nearestDist)
|
||||||
{
|
{
|
||||||
nearest = go;
|
nearest = go;
|
||||||
nearestDist = dist;
|
nearestDist = d;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nearest;
|
return nearest;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DumpNearbyNodes(Player* player)
|
class TeleRecheckEvent : public BasicEvent
|
||||||
{
|
{
|
||||||
ChatHandler(player->GetSession()).PSendSysMessage("Nearby node coordinates:");
|
public:
|
||||||
for (uint32 entry : kVeinEntries)
|
TeleRecheckEvent(Player* player, uint64 lastNodeGuidRaw, const std::vector<uint32>* entries)
|
||||||
|
: _player(player), _lastNodeGuidRaw(lastNodeGuidRaw), _entries(entries) { }
|
||||||
|
|
||||||
|
bool Execute(uint64, uint32) override
|
||||||
{
|
{
|
||||||
if (GameObject* go = player->FindNearestGameObject(entry, TELEPORT_DISTANCE))
|
if (!_player || !_player->IsInWorld())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (GameObject* node = FindNearestReady(_player, TELEPORT_DISTANCE, *_entries))
|
||||||
{
|
{
|
||||||
ChatHandler(player->GetSession()).PSendSysMessage(
|
if (node->GetGUID().GetRawValue() != _lastNodeGuidRaw)
|
||||||
"Entry %u -> Map %u X: %.2f Y: %.2f Z: %.2f",
|
{
|
||||||
entry, go->GetMapId(), go->GetPositionX(), go->GetPositionY(), go->GetPositionZ()
|
if (_player->GetDistance(node) >= MIN_RETELEPORT_DIST)
|
||||||
|
{
|
||||||
|
_player->TeleportTo(
|
||||||
|
node->GetMapId(),
|
||||||
|
node->GetPositionX(),
|
||||||
|
node->GetPositionY(),
|
||||||
|
node->GetPositionZ() + Z_BUMP,
|
||||||
|
node->GetOrientation()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static void TeleportToNearest(Player* player)
|
private:
|
||||||
|
Player* _player;
|
||||||
|
uint64 _lastNodeGuidRaw;
|
||||||
|
const std::vector<uint32>* _entries;
|
||||||
|
};
|
||||||
|
|
||||||
|
static bool DoTeleToList(Player* player, const std::vector<uint32>& entries)
|
||||||
{
|
{
|
||||||
if (!player)
|
if (!player)
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
GameObject* node = FindNearestVein(player, TELEPORT_DISTANCE);
|
if (player->IsInCombat())
|
||||||
if (node)
|
|
||||||
{
|
{
|
||||||
|
ChatHandler(player->GetSession()).PSendSysMessage("You can't use this while in combat.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GameObject* node = FindNearestReady(player, TELEPORT_DISTANCE, entries))
|
||||||
|
{
|
||||||
|
uint64 lastGuid = node->GetGUID().GetRawValue();
|
||||||
|
|
||||||
player->TeleportTo(
|
player->TeleportTo(
|
||||||
node->GetMapId(),
|
node->GetMapId(),
|
||||||
node->GetPositionX(),
|
node->GetPositionX(),
|
||||||
@@ -75,41 +117,15 @@ static void TeleportToNearest(Player* player)
|
|||||||
node->GetPositionZ() + Z_BUMP,
|
node->GetPositionZ() + Z_BUMP,
|
||||||
node->GetOrientation()
|
node->GetOrientation()
|
||||||
);
|
);
|
||||||
ChatHandler(player->GetSession()).PSendSysMessage("Teleported to nearest node.");
|
|
||||||
|
player->m_Events.AddEvent(new TeleRecheckEvent(player, lastGuid, &entries),
|
||||||
|
player->m_Events.CalculateTime(RECHECK_DELAY_MS));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ChatHandler(player->GetSession()).PSendSysMessage("No node found within range.");
|
ChatHandler(player->GetSession()).PSendSysMessage("No objects found within range.");
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TeleNodeRunnable : public BasicEvent
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit TeleNodeRunnable(Player* player) : _player(player) { }
|
|
||||||
bool Execute(uint64 /*time*/, uint32 /*diff*/) override
|
|
||||||
{
|
|
||||||
if (!_player || !_player->IsInWorld())
|
|
||||||
return true;
|
|
||||||
|
|
||||||
DumpNearbyNodes(_player);
|
|
||||||
TeleportToNearest(_player);
|
|
||||||
_player->m_Events.AddEvent(new TeleNodeRunnable(_player), _player->m_Events.CalculateTime(RECHECK_INTERVAL_MS));
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
Player* _player;
|
|
||||||
};
|
|
||||||
|
|
||||||
static bool HandleTeleNode(ChatHandler* handler)
|
|
||||||
{
|
|
||||||
Player* player = handler->GetSession()->GetPlayer();
|
|
||||||
if (!player)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
player->m_Events.AddEvent(new TeleNodeRunnable(player), player->m_Events.CalculateTime(0));
|
|
||||||
handler->PSendSysMessage("telenode started: re-evaluating every 5 seconds.");
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,10 +138,44 @@ public:
|
|||||||
{
|
{
|
||||||
static ChatCommandTable commandTable =
|
static ChatCommandTable commandTable =
|
||||||
{
|
{
|
||||||
{ "telenode", HandleTeleNode, SEC_PLAYER, Console::No },
|
{ "yaynode", HandleTeleNode, SEC_PLAYER, Console::No },
|
||||||
|
{ "yayherb", HandleTeleHerb, SEC_PLAYER, Console::No },
|
||||||
};
|
};
|
||||||
return commandTable;
|
return commandTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
static bool HandleTeleNode(ChatHandler* handler)
|
||||||
|
{
|
||||||
|
if (!handler)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
Player* player = handler->GetSession() ? handler->GetSession()->GetPlayer() : nullptr;
|
||||||
|
if (!player)
|
||||||
|
{
|
||||||
|
handler->SendSysMessage("Player only.");
|
||||||
|
handler->SetSentErrorMessage(true);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return DoTeleToList(player, kVeinEntries);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool HandleTeleHerb(ChatHandler* handler)
|
||||||
|
{
|
||||||
|
if (!handler)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
Player* player = handler->GetSession() ? handler->GetSession()->GetPlayer() : nullptr;
|
||||||
|
if (!player)
|
||||||
|
{
|
||||||
|
handler->SendSysMessage("Player only.");
|
||||||
|
handler->SetSentErrorMessage(true);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return DoTeleToList(player, kHerbEntries);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void AddSC_telenode_commandscript()
|
void AddSC_telenode_commandscript()
|
||||||
|
|||||||
Reference in New Issue
Block a user