void Map::saveOtcm(const std::string& fileName) { #if 0 try { g_clock.update(); FileStreamPtr fin = g_resources.createFile(fileName); fin->cache(); //TODO: compression flag with zlib uint32 flags = 0; // header fin->addU32(OTCM_SIGNATURE); fin->addU16(0); // data start, will be overwritten later fin->addU16(OTCM_VERSION); fin->addU32(flags); // version 1 header fin->addString("OTCM 1.0"); // map description fin->addU32(g_things.getDatSignature()); fin->addU16(g_game.getClientVersion()); fin->addString(g_game.getWorldName()); // go back and rewrite where the map data starts uint32 start = fin->tell(); fin->seek(4); fin->addU16(start); fin->seek(start); for(auto& pair : m_tiles) { const TilePtr& tile = pair.second; if(!tile || tile->isEmpty()) continue; Position pos = pair.first; fin->addU16(pos.x); fin->addU16(pos.y); fin->addU8(pos.z); const auto& list = tile->getThings(); auto first = std::find_if(list.begin(), list.end(), [](const ThingPtr& thing) { return thing->isItem(); }); for(auto it = first, end = list.end(); it != end; ++it) { const ThingPtr& thing = *it; if(thing->isItem()) { ItemPtr item = thing->static_self_cast<Item>(); fin->addU16(item->getId()); fin->addU8(item->getCountOrSubType()); } } // end of tile fin->addU16(0xFFFF); } // end of file Position invalidPos; fin->addU16(invalidPos.x); fin->addU16(invalidPos.y); fin->addU8(invalidPos.z); fin->flush(); fin->close(); } catch(stdext::exception& e) { g_logger.error(stdext::format("failed to save OTCM map: %s", e.what())); } #endif }
void Game::equipItem(const ItemPtr& item) { if(!canPerformGameAction()) return; m_protocolGame->sendEquipItem(item->getId(), item->getCountOrSubType()); }
void Map::saveOtcm(const std::string& fileName) { try { stdext::timer saveTimer; FileStreamPtr fin = g_resources.createFile(fileName); fin->cache(); //TODO: compression flag with zlib uint32 flags = 0; // header fin->addU32(OTCM_SIGNATURE); fin->addU16(0); // data start, will be overwritten later fin->addU16(OTCM_VERSION); fin->addU32(flags); // version 1 header fin->addString("OTCM 1.0"); // map description fin->addU32(g_things.getDatSignature()); fin->addU16(g_game.getProtocolVersion()); fin->addString(g_game.getWorldName()); // go back and rewrite where the map data starts uint32 start = fin->tell(); fin->seek(4); fin->addU16(start); fin->seek(start); for(uint8_t z = 0; z <= Otc::MAX_Z; ++z) { for(const auto& it : m_tileBlocks[z]) { const TileBlock& block = it.second; for(const TilePtr& tile : block.getTiles()) { if(!tile || tile->isEmpty()) continue; Position pos = tile->getPosition(); fin->addU16(pos.x); fin->addU16(pos.y); fin->addU8(pos.z); for(const ThingPtr& thing : tile->getThings()) { if(thing->isItem()) { ItemPtr item = thing->static_self_cast<Item>(); fin->addU16(item->getId()); fin->addU8(item->getCountOrSubType()); } } // end of tile fin->addU16(0xFFFF); } } } // end of file Position invalidPos; fin->addU16(invalidPos.x); fin->addU16(invalidPos.y); fin->addU8(invalidPos.z); fin->flush(); fin->close(); } catch(stdext::exception& e) { g_logger.error(stdext::format("failed to save OTCM map: %s", e.what())); } }
void Game::buyItem(const ItemPtr& item, int amount, bool ignoreCapacity, bool buyWithBackpack) { if(!canPerformGameAction() || !item) return; m_protocolGame->sendBuyItem(item->getId(), item->getCountOrSubType(), amount, ignoreCapacity, buyWithBackpack); }