Forgottenserver: [Question] Custom item attributes.

Created on 16 Nov 2016  路  10Comments  路  Source: otland/forgottenserver

As this is in the roadmap, I would like to ask how it should be done.
I was thinking in a way that would be backward compatible (wouldn't need to change anything in the current structure used to serialize the existent attributes) and it would accept a number or a string for key and number, string, bool or double for value.

I would simply add a new attr byte to be used in the serialization of the structure of an unordered_map that had all the custom attributes in the database. We could use the item:setAttribute() and check the key to decide if its either a normal attribute key (a power of 2 or an attribute string) or a custom attribute (any other number or string). Or create a new function item:setCustomAttribute() that wouldn't need that check.

This is how I was planning to do the structure: http://pastebin.com/dzVdV3HZ
Still have plenty of things to do such as serialize, deserialize, copy methods... Anything can be changed there to fit TFS standards.

I would like to know if this would be a good approach to custom attributes or not and if not what do you think it should be like, specially @marksamman.

question

All 10 comments

Most important is that it doesn't add any memory overhead for items that don't have any custom attributes. Make use of the current ItemAttributes class and add an attribute which is a pointer to a std::unordered_map which is used for custom attributes (which sounds like what you've described, in that case you're on the right track). As long as you get that part right, I don't mind how you implement the value type of the attributes or the Lua API.

I would substitute the entire class ItemAttributes for the unordered_map. Simple items that already exist would have smaller footprint too.

@Kamenuvol The problem is if we substitute the entire class with the map, we would need to change how attributes are currently serialized and then bye bye backward compatibility (or we would need some ugly code to convert outdated db entries to new format).

@Kamenuvol You're wrong. An unordered_map probably uses twice as much memory as the ItemAttributes class. Unless you're implying we should use a pointer to an unordered_map, in which case there's no difference in terms of memory use for items without attributes, but negatively impacts other great things about the ItemAttributes class, such as quickly checking if an item has an attribute with just a bitwise AND. Iterating over a small enough forward_list may also be faster than a hash lookup.

Items with custom attributes cannot be placed in market. Any thought in changing it? @marksamman @Mkalo

@totolol123 Even if we could, would it even make sense? The players wouldn't be able to see the attribues of the offers, the server doesn't send that stuff so yea it would be pretty shitty even if possible (unless you're using OTC then you can modify your market to request this kind of data)

What exactly does this feature do if I may ask?

The market is utter shit when you have custom items like that. It simply ceases to make sense.

since we have custom attributes in tfs already, shall we consider it solved?

closed as it was implemented on https://github.com/otland/forgottenserver/pull/1997

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zeeb92 picture zeeb92  路  4Comments

mishimalisa picture mishimalisa  路  5Comments

andremiles1 picture andremiles1  路  4Comments

EPuncker picture EPuncker  路  3Comments

GoularPink picture GoularPink  路  4Comments