#1  
Old 05-22-2014, 07:42 PM
JaseMourne's Avatar
JaseMourne JaseMourne is offline
Supporter
 
Join Date: Sep 2012
Posts: 159
Default Attribute system implementation

Hi, Crate, you lovely people.

I'm very interested in the specifics of the implementation of the attribute system in GD. I'm prototyping an attribute system for a steampunk dungeon crawler. What I have in place so far does work, it does the job.

Nonetheless, I'd love to know how others do it, in detail if possible. How exactly do you add up all the attributes, how an attribute affects another attribute(s), what approach do you take this with, do you use Lua or C or pinacolada?. I'd like to improve my system to become robust and flexible, so that adding new attributes and rules is easy.

I've tried a few approaches and most of them work well. But I'm having this feeling that I might be missing something to make it that robust beast that you can safely feed any number of combos of attributes and it will do the job.

My latest iteration works like this (in Lua). I have an Attribute class that has two variables: flat and mult. 'flat' is the flat bonus that simply adds to the result, while 'mult' multiplies. The class also has a method to calculate the final result.

I have an AttributeBank class that defines and holds all attributes in the game. Skills, items and states can contain an attribute bank, so learning a new skill can passively grant you +3 Power, or a temporary buff (state) may grant you +30% Attack Speed, or an item obviously may grant you some stats.

Each character owns one native attribute bank and it can gain any number of other banks. For instance, if you equip an item, the item's bank is added to the character. Now whenever the game needs to know the resulting value of any attribute, it simply calls the evaluation method of the character's native attribute. The native attribute takes into the formula its own 'flat' and 'mult', then iterates over all attached attribute banks and add their respective flats and mults (of the same type as the native attrib, of course). And then it churns out the result.

This is all nice and dandy and works like a charm until you want an attribute affecting another attribute. This is where I would like to get some insight into how other designers (coders) do this. I have a working system, but I feel it can be better, more flexible. I fear that if we add more attributes and rules, I would have to revise the code a lot.

Some attributes are fine with using the very basic formula I described above. But some can get affected by other conditions and need to take them all into consideration. We're thinking (idea of a colleague) of using regex to make it possible to instruct an attribute to use a different formula than the default.

By the way, I don't want to write as many classes as there are attributes (or close to that number), unless that's the only way, even though that would 'easily' solve the problem.

Can you share your knowledge with a fellow game designer, bros? Of course, I'd love to hear from anyone in the community with good understanding of the problem as well.

Thank you!
__________________
Steampunk Dungeon Crawler: http://www.vaporum-game.com/
  Click here to go to the next staff post in this thread.   #2  
Old 05-22-2014, 08:17 PM
Rhis's Avatar
Rhis Rhis is offline
Crate Employee - Programmer
 
Join Date: Nov 2009
Posts: 1,771
Default

That's pretty much exactly how it's done.

In our implementation each Attribute type has it's own class which is derived from the base Attribute class, then we just override a virtual method (C++) to override the default calculation where required.
  #3  
Old 05-22-2014, 08:51 PM
JaseMourne's Avatar
JaseMourne JaseMourne is offline
Supporter
 
Join Date: Sep 2012
Posts: 159
Default

That's the answer for me. Thank you very much, Rhis.

It's a relief for me. I'm not going the wrong way about it. My thinking is: if GD uses 1 class per attribute, then I can definitely do that, too.

Just a side question that comes to mind, if I may. In GD, when you equip a new item, most stats recalculate instantly, but some take a few moments to "catch up". Why is that? Are you calling some eval functions periodically, or are some of them intentionally delayed?
__________________
Steampunk Dungeon Crawler: http://www.vaporum-game.com/
  #4  
Old 05-23-2014, 12:24 PM
Shalie's Avatar
Shalie Shalie is offline
Praetorian
 
Join Date: Jul 2012
Posts: 1,177
Default

Quote:
Originally Posted by JaseMourne View Post
We're thinking (idea of a colleague) of using regex to make it possible to instruct an attribute to use a different formula than the default.
Reminds me of:
__________________
There may be no 'I' in team, but there's a 'ME' if you look hard enough.
¡uʍop ǝpısdn sı sn ɟo ǝuo 'sıɥʇ pɐǝɹ uɐɔ noʎ ɟı

Item Database: http://gracefuldusk.appspot.com/items
  This is the last staff post in this thread.   #5  
Old 05-23-2014, 10:00 PM
Rhis's Avatar
Rhis Rhis is offline
Crate Employee - Programmer
 
Join Date: Nov 2009
Posts: 1,771
Default

Quote:
Originally Posted by JaseMourne View Post
That's the answer for me. Thank you very much, Rhis.

It's a relief for me. I'm not going the wrong way about it. My thinking is: if GD uses 1 class per attribute, then I can definitely do that, too.

Just a side question that comes to mind, if I may. In GD, when you equip a new item, most stats recalculate instantly, but some take a few moments to "catch up". Why is that? Are you calling some eval functions periodically, or are some of them intentionally delayed?
We're calling some eval functions periodically.
Closed Thread

Tags
attributes, development

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


Grim Dawn ©2018 Crate Entertainment, LLC.
vBulletin® 3.8.4 ©2000-2014, Jelsoft Enterprises Ltd.