void ThingTypeManager::addItemType(const ItemTypePtr& itemType) { uint16 id = itemType->getServerId(); if(unlikely(id >= m_itemTypes.size())) m_itemTypes.resize(id + 1, m_nullItemType); m_itemTypes[id] = itemType; }
void ThingTypeManager::parseItemType(uint16 id, TiXmlElement* elem) { uint16 serverId = id; if(serverId > 20000 && id < 20100) { serverId -= 20000; ItemTypePtr newType(new ItemType); newType->setServerId(serverId); addItemType(newType); } ItemTypePtr itemType = getItemType(serverId); itemType->setName(elem->Attribute("name")); for(TiXmlElement* attrib = elem->FirstChildElement(); attrib; attrib = attrib->NextSiblingElement()) { if(attrib->ValueStr() != "attribute") break; if(attrib->Attribute("key") == "description") { itemType->setDesc(attrib->Attribute("value")); break; } } }
void ThingTypeManager::parseItemType(uint16 serverId, TiXmlElement* elem) { ItemTypePtr itemType = nullptr; bool s; int d; if(g_game.getProtocolVersion() < 960) { s = serverId > 20000 && serverId < 20100; d = 20000; } else { s = serverId > 30000 && serverId < 30100; d = 30000; } if(s) { serverId -= d; itemType = ItemTypePtr(new ItemType); itemType->setServerId(serverId); addItemType(itemType); } else itemType = getItemType(serverId); itemType->setName(elem->Attribute("name")); for(TiXmlElement* attrib = elem->FirstChildElement(); attrib; attrib = attrib->NextSiblingElement()) { std::string key = attrib->Attribute("key"); if(key.empty()) continue; stdext::tolower(key); if(key == "description") itemType->setDesc(attrib->Attribute("value")); else if(key == "weapontype") itemType->setCategory(ItemCategoryWeapon); else if(key == "ammotype") itemType->setCategory(ItemCategoryAmmunition); else if(key == "armor") itemType->setCategory(ItemCategoryArmor); else if(key == "charges") itemType->setCategory(ItemCategoryCharges); else if(key == "type") { std::string value = attrib->Attribute("value"); stdext::tolower(value); if(value == "key") itemType->setCategory(ItemCategoryKey); else if(value == "magicfield") itemType->setCategory(ItemCategoryMagicField); else if(value == "teleport") itemType->setCategory(ItemCategoryTeleport); else if(value == "door") itemType->setCategory(ItemCategoryDoor); } } }
void Item::unregisterType( ItemTypePtr itemType ) { if( types().find( itemType->name() ) != types().end() && types()[ itemType->name() ] == itemType ) types().erase( types().find( itemType->name() ) ); }
void Item::registerType( ItemTypePtr itemType ) { types()[ itemType->name() ] = itemType; }