Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/client/itemtype.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ enum ItemTypeAttr : uint8 {
ItemTypeAttrTopOrder = 43,
ItemTypeAttrWrtiable3 = 44, // deprecated
ItemTypeAttrWareId = 45,
ItemTypeAttrLast = 46
ItemTypeAttrPluralName = 46,
ItemTypeAttrLast = 47
};

enum ClientVersion
Expand Down Expand Up @@ -146,6 +147,9 @@ class ItemType : public LuaObject
void setName(const std::string& name) { m_attribs.set(ItemTypeAttrName, name); }
std::string getName() { return m_attribs.get<std::string>(ItemTypeAttrName); }

void setPluralName(const std::string& pluralName) { m_attribs.set(ItemTypeAttrPluralName, pluralName); }
std::string getPluralName() { return m_attribs.get<std::string>(ItemTypeAttrPluralName); }

void setDesc(const std::string& desc) { m_attribs.set(ItemTypeAttrDesc, desc); }
std::string getDesc() { return m_attribs.get<std::string>(ItemTypeAttrDesc); }

Expand Down
7 changes: 7 additions & 0 deletions src/client/luafunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ void Client::registerLuaFunctions()
g_lua.bindSingletonFunction("g_things", "getThingTypes", &ThingTypeManager::getThingTypes, &g_things);
g_lua.bindSingletonFunction("g_things", "findItemTypeByClientId", &ThingTypeManager::findItemTypeByClientId, &g_things);
g_lua.bindSingletonFunction("g_things", "findItemTypeByName", &ThingTypeManager::findItemTypeByName, &g_things);
g_lua.bindSingletonFunction("g_things", "findItemTypeByPluralName", &ThingTypeManager::findItemTypeByPluralName, &g_things);
g_lua.bindSingletonFunction("g_things", "findItemTypesByName", &ThingTypeManager::findItemTypesByName, &g_things);
g_lua.bindSingletonFunction("g_things", "findItemTypesByPluralName", &ThingTypeManager::findItemTypesByPluralName, &g_things);
g_lua.bindSingletonFunction("g_things", "findItemTypesByString", &ThingTypeManager::findItemTypesByString, &g_things);
g_lua.bindSingletonFunction("g_things", "findItemTypeByCategory", &ThingTypeManager::findItemTypeByCategory, &g_things);
g_lua.bindSingletonFunction("g_things", "findThingTypeByAttr", &ThingTypeManager::findThingTypeByAttr, &g_things);
Expand Down Expand Up @@ -484,6 +486,11 @@ void Client::registerLuaFunctions()
g_lua.registerClass<ItemType>();
g_lua.bindClassMemberFunction<ItemType>("getServerId", &ItemType::getServerId);
g_lua.bindClassMemberFunction<ItemType>("getClientId", &ItemType::getClientId);
g_lua.bindClassMemberFunction<ItemType>("getCategory", &ItemType::getCategory);
g_lua.bindClassMemberFunction<ItemType>("getName", &ItemType::getName);
g_lua.bindClassMemberFunction<ItemType>("getPluralName", &ItemType::getPluralName);
g_lua.bindClassMemberFunction<ItemType>("getDesc", &ItemType::getDesc);
g_lua.bindClassMemberFunction<ItemType>("isNull", &ItemType::isNull);
g_lua.bindClassMemberFunction<ItemType>("isWritable", &ItemType::isWritable);

g_lua.registerClass<ThingType>();
Expand Down
18 changes: 18 additions & 0 deletions src/client/thingtypemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ void ThingTypeManager::parseItemType(uint16 serverId, TiXmlElement* elem)
itemType = getItemType(serverId);

itemType->setName(elem->Attribute("name"));
itemType->setPluralName(elem->Attribute("plural"));
for(TiXmlElement* attrib = elem->FirstChildElement(); attrib; attrib = attrib->NextSiblingElement()) {
std::string key = attrib->Attribute("key");
if(key.empty())
Expand Down Expand Up @@ -356,6 +357,14 @@ const ItemTypePtr& ThingTypeManager::findItemTypeByName(std::string name)
return m_nullItemType;
}

const ItemTypePtr& ThingTypeManager::findItemTypeByPluralName(std::string pluralName)
{
for(const ItemTypePtr& it : m_itemTypes)
if(it->getPluralName() == pluralName)
return it;
return m_nullItemType;
}

ItemTypeList ThingTypeManager::findItemTypesByName(std::string name)
{
ItemTypeList ret;
Expand All @@ -365,6 +374,15 @@ ItemTypeList ThingTypeManager::findItemTypesByName(std::string name)
return ret;
}

ItemTypeList ThingTypeManager::findItemTypesByPluralName(std::string pluralName)
{
ItemTypeList ret;
for(const ItemTypePtr& it : m_itemTypes)
if(it->getPluralName() == pluralName)
ret.push_back(it);
return ret;
}

ItemTypeList ThingTypeManager::findItemTypesByString(std::string name)
{
ItemTypeList ret;
Expand Down
2 changes: 2 additions & 0 deletions src/client/thingtypemanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ class ThingTypeManager
void addItemType(const ItemTypePtr& itemType);
const ItemTypePtr& findItemTypeByClientId(uint16 id);
const ItemTypePtr& findItemTypeByName(std::string name);
const ItemTypePtr& findItemTypeByPluralName(std::string pluralName);
ItemTypeList findItemTypesByName(std::string name);
ItemTypeList findItemTypesByPluralName(std::string pluralName);
ItemTypeList findItemTypesByString(std::string name);

const ThingTypePtr& getNullThingType() { return m_nullThingType; }
Expand Down