Proper way of dealing with Player Item Stats?

I’m trying to figure out the best practice when it comes to applying an items stats to a player. Let’s say I have 40 stats stored in a data table with a unique ID. A new item is then created picking a few stats at random from the data table.

Now when the player equips said item, the stats needs to be applied, but having 40 different stats that all have different logic, is… Boggling my mind a bit.

I could just do a switch on int and call it a day, but I fear it’s not performance efficient and it honestly just doesn’t look right.

Any ideas will do.

There’s no performance harm using a switch. It may look weird, but this is your best option- sorta.

Absolutely do not use a switch on int. Do not use a unique ID system- that’s just abstraction for the sake of pain.
While I’m on the “do not do” train- do not use a data table for this. From what I can tell, all you’re doing is storing names and their corresponding ID’s- an enum will suit your use much better.

The easiest way to handle this would be to use a switch on enum.

If you wanted to make this super easy to override, you should have one function that does the switch and have that switch lead to dedicated functions.


image

You can make the functions protected so they won’t be annoying whenever trying to call a different function from outside the class.
image

You can then individually override these effects in children if they should be different.

2 Likes

Thank you a lot for your reply.

I do have a few questions tho.

Isn’t switch on int and switch on enum the same in the end?

I am only using the data table for the affixes. It stores Name, Level, Type, MinValueRange, MaxValueRange, Weight and Tag. Whenever an item is created it reads the table and picks one at random based on the weight and find a value between min and max range.
This this really a wrong way to go about it?

Again thanks for your reply

Performance wise, yes. Ease-of-use wise, no. Is it easier to remember 23 is CritChance or that CritChance is CritChance?

If this is the case, using a data table is ideal. Since you’re using a data table, I suggest using a switch on string rather than switch on enum. With this, you get readability- you can use the row name as the selection.

1 Like

If this is the case, using a data table is ideal. Since you’re using a data table, I suggest using a switch on string rather than switch on enum. With this, you get readability- you can use the row name as the selection.

How was I not aware of this.

Thanks again for your insight.

1 Like