Validating a design
Just trying to validate my idea for a design, which I want to plan out well enough before I write any code.
So far, I have a paper version of an example of this particular challenge.
So here's the scenario: I have a class representing a player character. The character gains traits from various options, most notable of which is the skill trees.
The issue: The traits are all very different across the different trees and don't adhere to strict similarities in function or input. One such area that I am now trying to formulate, is how a trait will alter base functionality of the character.
Very basic of basic, the function for taking damage. Let's say, the basic function takes damage normally and directly subtracts from the current stamina. Then say, a new trait comes in that takes half damage. I can't say "if trait x, take half damage", because then I run into a million ifs and elses.
Solution?: After writing it on paper, I considered the Strategy pattern, where each base feature is actually a strategy and when adding a new trait, it replaces the strategy object. The character could also have a "real" function to take the final result of such functions.
Posted Apr 10, 2025, 9:55 AM UTC