diff options
author | Vincent_Michael <Vincent_Michael@gmx.de> | 2012-12-30 17:09:55 +0100 |
---|---|---|
committer | Vincent_Michael <Vincent_Michael@gmx.de> | 2012-12-30 17:10:54 +0100 |
commit | ee9b7dfef8059f05ab404c48dd34929283d48963 (patch) | |
tree | 56561b7274eb87f381d1a823c1ccd1c91163309f | |
parent | 3d63deca7e2396f12996e5534e834bd7b077041e (diff) |
Core/Command: Add command for near creature finding
5 files changed, 53 insertions, 1 deletions
diff --git a/sql/updates/world/2012_12_30_01_world_trinity_string.sql b/sql/updates/world/2012_12_30_01_world_trinity_string.sql new file mode 100644 index 00000000000..ce0578168f4 --- /dev/null +++ b/sql/updates/world/2012_12_30_01_world_trinity_string.sql @@ -0,0 +1,3 @@ +DELETE FROM `trinity_string` WHERE `entry`=556; +INSERT INTO `trinity_string` (`entry`, `content_default`, `content_loc1`, `content_loc2`, `content_loc3`, `content_loc4`, `content_loc5`, `content_loc6`, `content_loc7`, `content_loc8`) VALUES +(556, 'Found near creatures (distance %f): %u ', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); diff --git a/src/server/game/Miscellaneous/Language.h b/src/server/game/Miscellaneous/Language.h index 6576b470a7f..b60a2de0ab6 100644 --- a/src/server/game/Miscellaneous/Language.h +++ b/src/server/game/Miscellaneous/Language.h @@ -539,7 +539,7 @@ enum TrinityStrings LANG_NPC_SETDATA = 555, //! Old ones now free: - // LANG_HOVER_DISABLED = 556, + LANG_COMMAND_NEAR_NPC_MESSAGE = 556, LANG_YOURS_LEVEL_UP = 557, LANG_YOURS_LEVEL_DOWN = 558, diff --git a/src/server/scripts/Commands/cs_npc.cpp b/src/server/scripts/Commands/cs_npc.cpp index 115737e0dfe..b44b01d916f 100644 --- a/src/server/scripts/Commands/cs_npc.cpp +++ b/src/server/scripts/Commands/cs_npc.cpp @@ -87,6 +87,7 @@ public: static ChatCommand npcCommandTable[] = { { "info", SEC_ADMINISTRATOR, false, &HandleNpcInfoCommand, "", NULL }, + { "near", SEC_GAMEMASTER, false, &HandleNpcNearCommand, "", NULL }, { "move", SEC_GAMEMASTER, false, &HandleNpcMoveCommand, "", NULL }, { "playemote", SEC_ADMINISTRATOR, false, &HandleNpcPlayEmoteCommand, "", NULL }, { "say", SEC_MODERATOR, false, &HandleNpcSayCommand, "", NULL }, @@ -631,6 +632,52 @@ public: return true; } + static bool HandleNpcNearCommand(ChatHandler* handler, char const* args) + { + float distance = (!*args) ? 10.0f : float((atof(args))); + uint32 count = 0; + + Player* player = handler->GetSession()->GetPlayer(); + + 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); + + if (result) + { + do + { + 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); + + ++count; + } + while (result->NextRow()); + } + + handler->PSendSysMessage(LANG_COMMAND_NEAR_NPC_MESSAGE, distance, count); + + return true; + } + //move selected creature static bool HandleNpcMoveCommand(ChatHandler* handler, char const* args) { diff --git a/src/server/shared/Database/Implementation/WorldDatabase.cpp b/src/server/shared/Database/Implementation/WorldDatabase.cpp index 95c888249cd..0fc2dcfd55a 100644 --- a/src/server/shared/Database/Implementation/WorldDatabase.cpp +++ b/src/server/shared/Database/Implementation/WorldDatabase.cpp @@ -84,6 +84,7 @@ void WorldDatabaseConnection::DoPrepareStatements() PREPARE_STATEMENT(WORLD_SEL_ITEM_TEMPLATE_BY_NAME, "SELECT entry FROM item_template WHERE name = ?", CONNECTION_SYNCH); PREPARE_STATEMENT(WORLD_SEL_CREATURE_BY_ID, "SELECT guid FROM creature WHERE id = ?", CONNECTION_SYNCH); PREPARE_STATEMENT(WORLD_SEL_GAMEOBJECT_NEAREST, "SELECT guid, id, position_x, position_y, position_z, map, (POW(position_x - ?, 2) + POW(position_y - ?, 2) + POW(position_z - ?, 2)) AS order_ FROM gameobject WHERE map = ? AND (POW(position_x - ?, 2) + POW(position_y - ?, 2) + POW(position_z - ?, 2)) <= ? ORDER BY order_", CONNECTION_SYNCH); + PREPARE_STATEMENT(WORLD_SEL_CREATURE_NEAREST, "SELECT guid, id, position_x, position_y, position_z, map, (POW(position_x - ?, 2) + POW(position_y - ?, 2) + POW(position_z - ?, 2)) AS order_ FROM creature WHERE map = ? AND (POW(position_x - ?, 2) + POW(position_y - ?, 2) + POW(position_z - ?, 2)) <= ? ORDER BY order_", CONNECTION_SYNCH); PREPARE_STATEMENT(WORLD_INS_CREATURE, "INSERT INTO creature (guid, id , map, spawnMask, phaseMask, modelid, equipment_id, position_x, position_y, position_z, orientation, spawntimesecs, spawndist, currentwaypoint, curhealth, curmana, MovementType, npcflag, unit_flags, dynamicflags) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", CONNECTION_ASYNC); PREPARE_STATEMENT(WORLD_DEL_GAME_EVENT_CREATURE, "DELETE FROM game_event_creature WHERE guid = ?", CONNECTION_ASYNC); PREPARE_STATEMENT(WORLD_DEL_GAME_EVENT_MODEL_EQUIP, "DELETE FROM game_event_model_equip WHERE guid = ?", CONNECTION_ASYNC); diff --git a/src/server/shared/Database/Implementation/WorldDatabase.h b/src/server/shared/Database/Implementation/WorldDatabase.h index 31da84c5151..64269edf7e1 100644 --- a/src/server/shared/Database/Implementation/WorldDatabase.h +++ b/src/server/shared/Database/Implementation/WorldDatabase.h @@ -104,6 +104,7 @@ enum WorldDatabaseStatements WORLD_SEL_ITEM_TEMPLATE_BY_NAME, WORLD_SEL_CREATURE_BY_ID, WORLD_SEL_GAMEOBJECT_NEAREST, + WORLD_SEL_CREATURE_NEAREST, WORLD_SEL_GAMEOBJECT_TARGET, WORLD_INS_CREATURE, WORLD_DEL_GAME_EVENT_CREATURE, |