aboutsummaryrefslogtreecommitdiff
path: root/src/server/scripts
diff options
context:
space:
mode:
authorVincent_Michael <Vincent_Michael@gmx.de>2013-03-09 23:05:27 +0100
committerVincent_Michael <Vincent_Michael@gmx.de>2013-03-09 23:05:27 +0100
commit4e789d4c5c83dd6f0f582fe24e9d49b39950fffe (patch)
treeea563fb7ad5985ec2a2b887901b74fb6ed288841 /src/server/scripts
parent65b16a97bee09e9c5114a35be7b0122987d249e1 (diff)
Core/Commands: Optimize for command .npc near
Diffstat (limited to 'src/server/scripts')
-rw-r--r--src/server/scripts/Commands/cs_npc.cpp42
1 files changed, 14 insertions, 28 deletions
diff --git a/src/server/scripts/Commands/cs_npc.cpp b/src/server/scripts/Commands/cs_npc.cpp
index 79a74b0823d..f640d257a3a 100644
--- a/src/server/scripts/Commands/cs_npc.cpp
+++ b/src/server/scripts/Commands/cs_npc.cpp
@@ -665,43 +665,29 @@ public:
static bool HandleNpcNearCommand(ChatHandler* handler, char const* args)
{
+ WorldObject* object = handler->GetSession()->GetPlayer();
float distance = (!*args) ? 10.0f : float((atof(args)));
uint32 count = 0;
- Player* player = handler->GetSession()->GetPlayer();
+ CellCoord pair(Trinity::ComputeCellCoord(object->GetPositionX(), object->GetPositionY()));
+ Cell cell(pair);
+ cell.SetNoCreate();
+
+ std::list<Creature*> creatureList;
+ Trinity::AnyUnitInObjectRangeCheck check(object, distance);
+ Trinity::CreatureListSearcher<Trinity::AnyUnitInObjectRangeCheck> search(object, creatureList, check);
+ TypeContainerVisitor<Trinity::CreatureListSearcher<Trinity::AnyUnitInObjectRangeCheck>, GridTypeMapContainer> visit(search);
- PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_CREATURE_NEAREST);
- stmt->setFloat(0, player->GetPositionX());
- stmt->setFloat(1, player->GetPositionY());
- stmt->setFloat(2, player->GetPositionZ());
- stmt->setUInt32(3, player->GetMapId());
- stmt->setFloat(4, player->GetPositionX());
- stmt->setFloat(5, player->GetPositionY());
- stmt->setFloat(6, player->GetPositionZ());
- stmt->setFloat(7, distance * distance);
- PreparedQueryResult result = WorldDatabase.Query(stmt);
+ cell.Visit(pair, visit, *(object->GetMap()), *object, distance);
- if (result)
+ if (!creatureList.empty())
{
- do
+ for (std::list<Creature*>::iterator itr = creatureList.begin(); itr != creatureList.end(); ++itr)
{
- Field* fields = result->Fetch();
- uint32 guid = fields[0].GetUInt32();
- uint32 entry = fields[1].GetUInt32();
- float x = fields[2].GetFloat();
- float y = fields[3].GetFloat();
- float z = fields[4].GetFloat();
- uint16 mapId = fields[5].GetUInt16();
-
- CreatureTemplate const* creatureTemplate = sObjectMgr->GetCreatureTemplate(entry);
- if (!creatureTemplate)
- continue;
-
- handler->PSendSysMessage(LANG_CREATURE_LIST_CHAT, guid, guid, creatureTemplate->Name.c_str(), x, y, z, mapId);
-
+ handler->PSendSysMessage(LANG_CREATURE_LIST_CHAT, (*itr)->GetGUIDLow(), (*itr)->GetGUIDLow(), (*itr)->GetName().c_str(),
+ (*itr)->GetPositionX(), (*itr)->GetPositionY(), (*itr)->GetPositionZ(), (*itr)->GetMapId());
++count;
}
- while (result->NextRow());
}
handler->PSendSysMessage(LANG_COMMAND_NEAR_NPC_MESSAGE, distance, count);