g_map.findItemsByid

This commit is contained in:
Ahmed Samy 2013-08-31 01:18:17 +00:00
parent 56d6ef6642
commit e741a62ce9
3 changed files with 25 additions and 0 deletions

View File

@ -140,6 +140,7 @@ void Client::registerLuaFunctions()
g_lua.bindSingletonFunction("g_map", "showZone", &Map::showZone, &g_map); 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", "beginGhostMode", &Map::beginGhostMode, &g_map);
g_lua.bindSingletonFunction("g_map", "endGhostMode", &Map::endGhostMode, &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.registerSingletonClass("g_minimap");
g_lua.bindSingletonFunction("g_minimap", "clean", &Minimap::clean, &g_minimap); g_lua.bindSingletonFunction("g_minimap", "clean", &Minimap::clean, &g_minimap);

View File

@ -375,6 +375,28 @@ void Map::endGhostMode()
g_painter->resetOpacity(); 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) void Map::addCreature(const CreaturePtr& creature)
{ {
m_knownCreatures[creature->getId()] = creature; m_knownCreatures[creature->getId()] = creature;

View File

@ -197,6 +197,8 @@ public:
void beginGhostMode(float opacity); void beginGhostMode(float opacity);
void endGhostMode(); void endGhostMode();
ItemVector findItemsById(uint16 clientId, uint32 max);
// known creature related // known creature related
void addCreature(const CreaturePtr& creature); void addCreature(const CreaturePtr& creature);
CreaturePtr getCreatureById(uint32 id); CreaturePtr getCreatureById(uint32 id);