Core/Commands: Implement .neargraveyard (find nearest graveyard from dbc).

This commit is contained in:
xjose93
2016-06-14 18:23:45 +02:00
committed by Aokromes
parent 77631a8cde
commit 882453253f
5 changed files with 71 additions and 2 deletions

View File

@@ -24,6 +24,7 @@ EndScriptData */
#include "ScriptMgr.h"
#include "ObjectMgr.h"
#include "BattlefieldMgr.h"
#include "BattlegroundMgr.h"
#include "Chat.h"
#include "Cell.h"
@@ -36,6 +37,7 @@ EndScriptData */
#include "MapManager.h"
#include <fstream>
#include <limits>
class debug_commandscript : public CommandScript
{
@@ -95,7 +97,8 @@ public:
{ "phase", rbac::RBAC_PERM_COMMAND_DEBUG_PHASE, false, &HandleDebugPhaseCommand, "" },
{ "loadcells", rbac::RBAC_PERM_COMMAND_DEBUG_LOADCELLS, false, &HandleDebugLoadCellsCommand, "" },
{ "boundary", rbac::RBAC_PERM_COMMAND_DEBUG_BOUNDARY, false, &HandleDebugBoundaryCommand, "" },
{ "raidreset", rbac::RBAC_PERM_COMMAND_INSTANCE_UNBIND, false, &HandleDebugRaidResetCommand, "" }
{ "raidreset", rbac::RBAC_PERM_COMMAND_INSTANCE_UNBIND, false, &HandleDebugRaidResetCommand, "" },
{ "neargraveyard", rbac::RBAC_PERM_COMMAND_NEARGRAVEYARD, false, &HandleDebugNearGraveyard, "" },
};
static std::vector<ChatCommand> commandTable =
{
@@ -1512,6 +1515,53 @@ public:
sInstanceSaveMgr->ForceGlobalReset(mEntry->MapID, Difficulty(difficulty));
return true;
}
static bool HandleDebugNearGraveyard(ChatHandler* handler, char const* args)
{
Player* player = handler->GetSession()->GetPlayer();
const WorldSafeLocsEntry* nearestLoc = nullptr;
if (stricmp(args, "linked"))
{
if (Battleground* bg = player->GetBattleground())
nearestLoc = bg->GetClosestGraveYard(player);
else
{
if (Battlefield* bf = sBattlefieldMgr->GetBattlefieldToZoneId(player->GetZoneId()))
nearestLoc = bf->GetClosestGraveYard(player);
else
nearestLoc = sObjectMgr->GetClosestGraveYard(player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), player->GetMapId(), player->GetTeam());
}
}
else
{
float x = player->GetPositionX();
float y = player->GetPositionY();
float z = player->GetPositionZ();
float distNearest = std::numeric_limits<float>::max();
for (uint32 i = 0; i < sWorldSafeLocsStore.GetNumRows(); ++i)
{
const WorldSafeLocsEntry* loc = sWorldSafeLocsStore.LookupEntry(i);
if (loc && loc->map_id == player->GetMapId())
{
float dist = (loc->x - x) * (loc->x - x) + (loc->y - y) * (loc->y - y) + (loc->z - z) * (loc->z - z);
if (dist < distNearest)
{
distNearest = dist;
nearestLoc = loc;
}
}
}
}
if (nearestLoc)
handler->PSendSysMessage(LANG_COMMAND_NEARGRAVEYARD, nearestLoc->ID, nearestLoc->x, nearestLoc->y, nearestLoc->z);
else
handler->PSendSysMessage(LANG_COMMAND_NEARGRAVEYARD_NOTFOUND);
return true;
}
};
void AddSC_debug_commandscript()