g_map.findItemsByid

master
Ahmed Samy 11 years ago
parent 56d6ef6642
commit e741a62ce9

@ -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);

@ -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;

@ -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);

Loading…
Cancel
Save