I have a sort of "Upgrade" system in my addon for a game. Each upgrade has a configurable set of "Requirement"s, essentially being a list of conditions that need to be met before an "Upgrade" can be purchased.
To achieve a solid, but flexible structure, I was thinking of having each requirement type implement or extend some shared "Requirement" interface/class, and then in each of the concrete "Requirement" implementations I have some sort of method that returns a boolean describing whether the requirement is met or not.
However, each requirement is unique and requires different variables, for example one might be the money a player has, another might be to check whether some in-game item has specific attributes. The list goes on...
To tackle this, I've wanted to create a sort of "Context" system, where I provide a context for a player, a context for an item, etc. I'm just not quite sure how to structure this.
Each "Upgrade" can have multiple requirements, and so to check whether all of the requirements are met, I need "multiple" contexts. I'm not sure whether I should just:
- Provide one type of context at a time, e.g. a "player context" that just has the player instance variable, then check for requirements that use that context, and then check whether the requirement was met with that specific context. Then provide the next time of context, e.g. an "item context" that has the item instance variable, then repeat the previous steps.
- OR: Have one "combined" context object, that contains all possible context variables (e.g. "player context" and "item context") then just pass that to each requirement and check whether it was met with the given context. This system seems somewhat closed off and limited as far as I can tell.
I'm not sure what to choose, or if I'm approaching this wrong entirely, any advice would be greatly appreciated, thanks ❤️