I’m creating an RPG which will be dealing with multiple damage types and a number of different effects that the character can gain/lose. An easy one to add is something like “bonus damage”, but the question comes how to implement it.
The most direct method I can think of is to have whatever it is that is giving the bonus damage adds it’s bonus to a centralized place where the numbers are then kept track of. Say you deal 10 fire damage and you get a skill “Hotter Flames” that gives an extra 20% to fire damage. The skill would tell a central script to multiply all fire damage by 1.2, and that is that. But what if these bonuses become more nuanced?
I recognize this becomes a bit more niche, but I like the idea of a wide variety of interesting effects to be stacked and added together to create fun builds; so in creating that system, what if the extra 20% fire damage was just for magic attacks? Well now that’s a whole other variable to track, and now we might be tracking a lot of extra things. Maybe a skill gives extra damage to specific archetypes of enemies; say goblin-kin take the extra damage. Now the effect has to figure out who is receiving the damage, what source of the damage is from, and then calculate the changes.
Again, the most direct method I could imagine is to save all this to a number of “bonusDamagePercentFor___” variables, which could get extravagantly long depending on how many different things could be affected. I’m only making a small game currently, but at some point the “dream game” I wish to make will have many such concerns. My current solution is using a list of delegates that take all the information and spit back out a modified damage value, but this turns in to a lot of calculation and overhead for an attack so I’m also figuring out a way of caching the damage whenever a change is made.
How would you tackle the issue?