From e741a62ce9467b68d8560c94798f93c71a58f543 Mon Sep 17 00:00:00 2001 From: Ahmed Samy Date: Sat, 31 Aug 2013 01:18:17 +0000 Subject: [PATCH] g_map.findItemsByid --- src/client/luafunctions.cpp | 1 + src/client/map.cpp | 22 ++++++++++++++++++++++ src/client/map.h | 2 ++ 3 files changed, 25 insertions(+) diff --git a/src/client/luafunctions.cpp b/src/client/luafunctions.cpp index 35335236..7b4fec4b 100644 --- a/src/client/luafunctions.cpp +++ b/src/client/luafunctions.cpp @@ -140,6 +140,7 @@ void Client::registerLuaFunctions() g_lua.bindSingletonFunction("g_map", "showZone", &Map::showZone, &g_map); g_lua.bindSingletonFunction("g_map", "beginGhostMode", &Map::beginGhostMode, &g_map); g_lua.bindSingletonFunction("g_map", "endGhostMode", &Map::endGhostMode, &g_map); + g_lua.bindSingletonFunction("g_map", "findItemsById", &Map::findItemsById, &g_map); g_lua.registerSingletonClass("g_minimap"); g_lua.bindSingletonFunction("g_minimap", "clean", &Minimap::clean, &g_minimap); diff --git a/src/client/map.cpp b/src/client/map.cpp index 8af4cc13..c9b3a40a 100644 --- a/src/client/map.cpp +++ b/src/client/map.cpp @@ -375,6 +375,28 @@ void Map::endGhostMode() g_painter->resetOpacity(); } +ItemVector Map::findItemsById(uint16 clientId, uint32 max) +{ + ItemVector ret; + uint32 count = 0; + for(uint8_t z = 0; z <= Otc::MAX_Z; ++z) { + for(const auto& pair : m_tileBlocks[z]) { + const TileBlock& block = pair.second; + for(const TilePtr& tile : block.getTiles()) { + for(const ItemPtr& item : tile->getItems()) { + if(item->getId() == clientId) { + ret.push_back(item); + if(++count >= max) + break; + } + } + } + } + } + + return ret; +} + void Map::addCreature(const CreaturePtr& creature) { m_knownCreatures[creature->getId()] = creature; diff --git a/src/client/map.h b/src/client/map.h index e207cf8d..98ee7cef 100644 --- a/src/client/map.h +++ b/src/client/map.h @@ -197,6 +197,8 @@ public: void beginGhostMode(float opacity); void endGhostMode(); + ItemVector findItemsById(uint16 clientId, uint32 max); + // known creature related void addCreature(const CreaturePtr& creature); CreaturePtr getCreatureById(uint32 id);