I'm trying to develop a character calculator for a RPG, and it could evolve into a turn based combat / text based RPG. One of my concerns is how to handle the equipment stats / buff system.
Currently each of my buffs / equipment object and my character object itself has a member bonusstats
, which is a struct containing a (potentially) very large amount of possible modifiers (attributes, misc_skills, protections, secondary_stats, etc and their multiplier versions).
struct BonusStats {
int attribute[8], misc_skill[30], protection[9], HP, MP, ... ;
//define constructor, operator+=, reset function
}
And everytime an actualize call is requested every stat is recomputed:
Character::Actualize() {
this->bonusstats.reset();
for /*iterate through vector of buffs and equipped items*/ {
this->bonusstats += item->getBonusStats();
}
}
While this is a rather simple approach I am concerned about two things mainly:
1.- Is it performance-wise acceptable? I get the feeling that having to sum two structs containing 100 elements just to add a buff is not a very good practice. Would there be any practical advantage in using a function like Character::ApplyStats( std::function<void(BonusStats*)> itemstats)
instead?
2.- How could I implement more complex buffs than stat modifiers? For example, reflecting x% damage when blocking a melee attack. The thing that comes to my mind is to create complex stats like percent_damage_reflected_on_melee_block
and check its value everytime conditions are met. Is it a good approach?