[Suggestion] Lua-Generated Item Descriptions

GOOD?


  • Total voters
    16

Delusion

Divine Intellect
Support Team
Joined
Feb 14, 2015
Messages
5,340
Best answers
528
Reaction score
3,068
Code: otland/forgottenserver (https://github.com/otland/forgottenserver/compare/master...delusionx:lua-item-desc)

There's still some room for improvement. I'm thinking about combining the "hasX" functions into one that returns the table with all the item type "flags" on it (boolean flags), would probably make it cleaner in the source code.

I tried to test a large chunk of items and compare them to the original description generated from Item::getDescription, I've found no discrepancies thus far between the two, it should perfectly mimic the exact same description you get from the original.

Obviously, I'll have to alter more of the code to make it like the original (support ItemType descriptions and utilize the Lua-generated description in playerOnLookInShop).

Pros:
  • Flexible for new custom attributes
  • Ability to easily alter the structure, order & layout of the text
  • Shorter code (I combined the generic attributes/abilities that were added on weapons/armor into 1 function, in C++ you had to manually edit both to add a new attribute to parse)
Cons:
  • Anybody who's added new attributes in Item::getDescription will have to re-do it (maybe make it configurable?)

What do you guys think?
 
Last edited:

Animera

* * * * *
Joined
Dec 9, 2008
Messages
2,316
Best answers
4
Reaction score
465
Location
ANIMERA.ONLINE
Really great job :), these days having a upgrade system(or other system that influences items) is like the standard for every OT. it makes no sense to mess with item descriptions to check if item has x description to get y condition...

These days we should have these functions by default in tfs. Even if it is just the sake of expanding the possibilities of features we can provide as game developers...

No need for the poll if you ask me!

Just out of curiousity how much slower is it? and why (i'm trying to learn more about performance efficienty)? sounds more logical that it is faster as it saves a lot of string manipulations/calculations? Or just thrown some benchmarks?

Might implement some day when i have the time, it will make my codes much cleaner XD.

Animera
 

zxmatzx

Well-Known Member
Joined
Dec 1, 2010
Messages
194
Best answers
10
Reaction score
54
Nice release. I watched you write this code, I was thinking if you would release the code, as Animera said, with this, the upgrade systems will be much more cleaner. Thanks for sharing, your job here in Otland is great!
 
OP
Delusion

Delusion

Divine Intellect
Support Team
Joined
Feb 14, 2015
Messages
5,340
Best answers
528
Reaction score
3,068
Really great job :), these days having a upgrade system(or other system that influences items) is like the standard for every OT. it makes no sense to mess with item descriptions to check if item has x description to get y condition...

These days we should have these functions by default in tfs. Even if it is just the sake of expanding the possibilities of features we can provide as game developers...

No need for the poll if you ask me!

Just out of curiousity how much slower is it? and why (i'm trying to learn more about performance efficienty)? sounds more logical that it is faster as it saves a lot of string manipulations/calculations? Or just thrown some benchmarks?

Might implement some day when i have the time, it will make my codes much cleaner XD.

Animera
It's more just basic experience being able to tell that this would be slightly slower. For example, I wrote a my own "StringStream" to make it easier to add strings to the description & build it, which is basically just a mask for string.format. Real string streams in C++ are faster and each value is manually concatenated rather than formatted using specifiers. I don't have a percentage for how much faster/slower it would be, like I said it's just that I can pretty much tell when something will be slightly more costly in terms of performance.

Nice release. I watched you write this code, I was thinking if you would release the code, as Animera said, with this, the upgrade systems will be much more cleaner. Thanks for sharing, your job here in Otland is great!
Yeah, most of it was written that day (took me 8 hours), the rest of this time I was just lazy to clean up, but eventually I did and made this thread.
 

zbizu

Legendary OT User
Joined
Nov 22, 2010
Messages
2,628
Best answers
3
Reaction score
1,560
Location
Poland
if you manage to push needed getters into official tfs repo, I can help you doing the lua part
 

Yamaken

Pro OpenTibia Developer
Premium User
Joined
Jul 27, 2013
Messages
468
Best answers
3
Reaction score
335
I think if we are able to move things to lua without huge hacks its always a improvement in the sense that its easier to read, fix, improve and most important customize the items descriptions. The only reason to keep it at engine/c++ was the easiness to read the item properties but then its not a excuse since the lua interface should have everything.
 
OP
Delusion

Delusion

Divine Intellect
Support Team
Joined
Feb 14, 2015
Messages
5,340
Best answers
528
Reaction score
3,068
Added support for ItemType descriptions, removed the default support for onLookInShop and replaced it with the Lua-written description. The entirety of this should be finished, other than cleaning up some leftover unused C++ functions in favor of Lua, or maybe making it configurable and cleaning it up somehow to make it fitting for a PR.

Would be greatly appreciated if people could test this as well with me, I'm very skeptical that I made perfect code cause that almost never happens, I'm sure there has to be some item that has some error in formatting. All you gotta do is download the branch & compile and just look at a shit ton of different types of items to see if the description is screwed up or not.
 
Top